SVN-Revision: r380
This commit is contained in:
tdx
2025-03-24 12:37:03 +00:00
parent 188e0914a7
commit 527587929b
4 changed files with 717 additions and 118 deletions
+62 -32
View File
@@ -32,19 +32,23 @@ namespace Lskj.ProductiSched
this.pl_main = new DevExpress.XtraEditors.PanelControl();
this.splitMainControl = new DevExpress.XtraEditors.SplitContainerControl();
this.splitLeftControl = new DevExpress.XtraEditors.SplitContainerControl();
this.bandGcBottom = new Lskj.Control.BandedGridControlEx();
this.gcRight = new Lskj.Control.GridControlEx();
this.pltopmain = new DevExpress.XtraEditors.PanelControl();
this.treebandGcTop = new Lskj.Control.TreeBandedGridControlEx();
this.bandGcTop = new Lskj.Control.BandedGridControlEx();
this.pl_mainSearch = new DevExpress.XtraEditors.PanelControl();
this.pl_search = new DevExpress.XtraEditors.PanelControl();
this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
this.btnSave = new DevExpress.XtraEditors.SimpleButton();
this.bandGcTop = new Lskj.Control.BandedGridControlEx();
this.bandGcBottom = new Lskj.Control.BandedGridControlEx();
this.gcRight = new Lskj.Control.GridControlEx();
((System.ComponentModel.ISupportInitialize)(this.pl_main)).BeginInit();
this.pl_main.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitMainControl)).BeginInit();
this.splitMainControl.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitLeftControl)).BeginInit();
this.splitLeftControl.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pltopmain)).BeginInit();
this.pltopmain.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pl_mainSearch)).BeginInit();
this.pl_mainSearch.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pl_search)).BeginInit();
@@ -86,7 +90,7 @@ namespace Lskj.ProductiSched
this.splitLeftControl.Location = new System.Drawing.Point(0, 0);
this.splitLeftControl.Margin = new System.Windows.Forms.Padding(2);
this.splitLeftControl.Name = "splitLeftControl";
this.splitLeftControl.Panel1.Controls.Add(this.bandGcTop);
this.splitLeftControl.Panel1.Controls.Add(this.pltopmain);
this.splitLeftControl.Panel1.Controls.Add(this.pl_mainSearch);
this.splitLeftControl.Panel1.Text = "Panel1";
this.splitLeftControl.Panel2.Controls.Add(this.bandGcBottom);
@@ -96,27 +100,38 @@ namespace Lskj.ProductiSched
this.splitLeftControl.TabIndex = 7;
this.splitLeftControl.Text = "splitContainerControl2";
//
// bandGcBottom
// pltopmain
//
this.bandGcBottom.AdapterObj = null;
this.bandGcBottom.Dock = System.Windows.Forms.DockStyle.Fill;
this.bandGcBottom.Location = new System.Drawing.Point(0, 0);
this.bandGcBottom.Margin = new System.Windows.Forms.Padding(4);
this.bandGcBottom.Name = "bandGcBottom";
this.bandGcBottom.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
this.bandGcBottom.Size = new System.Drawing.Size(997, 321);
this.bandGcBottom.TabIndex = 12;
this.pltopmain.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
this.pltopmain.Controls.Add(this.treebandGcTop);
this.pltopmain.Controls.Add(this.bandGcTop);
this.pltopmain.Dock = System.Windows.Forms.DockStyle.Fill;
this.pltopmain.Location = new System.Drawing.Point(0, 0);
this.pltopmain.Name = "pltopmain";
this.pltopmain.Size = new System.Drawing.Size(997, 320);
this.pltopmain.TabIndex = 22;
//
// gcRight
// treebandGcTop
//
this.gcRight.AdapterObj = null;
this.gcRight.Dock = System.Windows.Forms.DockStyle.Fill;
this.gcRight.Location = new System.Drawing.Point(0, 0);
this.gcRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.gcRight.Name = "gcRight";
this.gcRight.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
this.gcRight.Size = new System.Drawing.Size(315, 679);
this.gcRight.TabIndex = 11;
this.treebandGcTop.AdapterObj = null;
this.treebandGcTop.Dock = System.Windows.Forms.DockStyle.Fill;
this.treebandGcTop.Location = new System.Drawing.Point(0, 0);
this.treebandGcTop.Margin = new System.Windows.Forms.Padding(4);
this.treebandGcTop.Name = "treebandGcTop";
this.treebandGcTop.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
this.treebandGcTop.Size = new System.Drawing.Size(997, 320);
this.treebandGcTop.TabIndex = 19;
//
// bandGcTop
//
this.bandGcTop.AdapterObj = null;
this.bandGcTop.Dock = System.Windows.Forms.DockStyle.Fill;
this.bandGcTop.Location = new System.Drawing.Point(0, 0);
this.bandGcTop.Margin = new System.Windows.Forms.Padding(4);
this.bandGcTop.Name = "bandGcTop";
this.bandGcTop.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
this.bandGcTop.Size = new System.Drawing.Size(997, 320);
this.bandGcTop.TabIndex = 17;
//
// pl_mainSearch
//
@@ -166,16 +181,27 @@ namespace Lskj.ProductiSched
this.btnSave.TabIndex = 40;
this.btnSave.Text = "保存(&S)";
//
// bandGcTop
// bandGcBottom
//
this.bandGcTop.AdapterObj = null;
this.bandGcTop.Dock = System.Windows.Forms.DockStyle.Fill;
this.bandGcTop.Location = new System.Drawing.Point(0, 0);
this.bandGcTop.Margin = new System.Windows.Forms.Padding(4);
this.bandGcTop.Name = "bandGcTop";
this.bandGcTop.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
this.bandGcTop.Size = new System.Drawing.Size(997, 320);
this.bandGcTop.TabIndex = 13;
this.bandGcBottom.AdapterObj = null;
this.bandGcBottom.Dock = System.Windows.Forms.DockStyle.Fill;
this.bandGcBottom.Location = new System.Drawing.Point(0, 0);
this.bandGcBottom.Margin = new System.Windows.Forms.Padding(4);
this.bandGcBottom.Name = "bandGcBottom";
this.bandGcBottom.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
this.bandGcBottom.Size = new System.Drawing.Size(997, 321);
this.bandGcBottom.TabIndex = 12;
//
// gcRight
//
this.gcRight.AdapterObj = null;
this.gcRight.Dock = System.Windows.Forms.DockStyle.Fill;
this.gcRight.Location = new System.Drawing.Point(0, 0);
this.gcRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.gcRight.Name = "gcRight";
this.gcRight.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
this.gcRight.Size = new System.Drawing.Size(315, 679);
this.gcRight.TabIndex = 11;
//
// FrmProductSched
//
@@ -189,4 +215,8 @@ namespace Lskj.ProductiSched
((System.ComponentModel.ISupportInitialize)(this.splitMainControl)).EndInit();
this.splitMainControl.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitLeftControl)).EndInit();
this.splitLeftControl.ResumeLayout(f
this.splitLeftControl.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pltopmain)).EndInit();
this.pltopmain.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pl_mainSearch)).EndInit();
this.pl_mainSearch.
+648 -84
View File
@@ -5,6 +5,9 @@ using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.BandedGrid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.Nodes;
using Lskj.Business.Impl;
using Lskj.Control;
using Lskj.Control.Model;
@@ -31,6 +34,7 @@ namespace Lskj.ProductiSched
public partial class FrmProductSched : UserControl
{
public bool TreeMultiHeader;
public ProductDataModel DataModel;
public FrmProductSched()
{
@@ -62,7 +66,14 @@ namespace Lskj.ProductiSched
DataModel.TopRowColors = BaseModuleImpl.GetBaseGridRowColors(DataModel.TopModuleModel.FormKey);
DataModel.TopSearchTab = BaseModuleImpl.GetCustomQueryFields(DataModel.TopModuleModel.CondKey);
DataModel.TopSchemesTable = BaseModuleImpl.GetSchemesList(DataModel.TopSysModel.ModuleId);
DataModel.TopSearchObj = new MyControl(DataModel.TopModuleModel.MenuSql, bandGcTop);
if (DataModel.TopModuleModel.TreeAutoMultiHeader == 1)
{
DataModel.TopSearchObj = new MyControl(DataModel.TopModuleModel.MenuSql, treebandGcTop);
}
else
{
DataModel.TopSearchObj = new MyControl(DataModel.TopModuleModel.MenuSql, bandGcTop);
}
DataModel.TopSearchObj.Model = DataModel.TopSysModel;
DataTable detailsTab = BaseModuleImpl.GetBaseDetailPages(DataModel.TopSysModel.ModuleCode);
if (detailsTab != null)
@@ -119,17 +130,39 @@ namespace Lskj.ProductiSched
{
//搜索控件
bool fixedQuery = DataModel.TopSearchTab == null || DataModel.TopSearchTab.Rows.Count == 0;
TreeMultiHeader = DataModel.TopModuleModel.TreeAutoMultiHeader == 1;
if (!fixedQuery)
{
this.pl_mainSearch.Height = DataModel.TopSearchObj.InitSearchControl(DataModel.TopSearchTab, this.pl_search, true, DataModel.TopSchemesTable, DataModel.TopSysModel);
this.pl_search.Width = DataModel.TopSearchObj.ParentPanel.Controls.Cast<System.Windows.Forms.Control>().Max(n => n.Location.X + n.Width) + 5;
}
//上方表格
bandGcTop.Model = DataModel.TopSysModel;
bandGcTop.SetEditColumns(DataModel.TopGridColumns, GridCustomColumnStruct.BaseMainGridView + DataModel.TopModuleModel.FormKey);
bandGcTop.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(DataModel.TopModuleModel.ModeCode), DataModel.TopSysModel);
bandGcTop.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(DataModel.TopModuleModel.ModeCode));
AddDataColumns(bandGcTop);
//构建树表格
if (TreeMultiHeader)//若为多表头树表格模式
{
treebandGcTop.Model = DataModel.TopSysModel;
treebandGcTop.moduleModel = DataModel.TopModuleModel;
treebandGcTop.SetEditColumns(DataModel.TopGridColumns, GridCustomColumnStruct.BaseMainGridView + DataModel.TopModuleModel.FormKey);
treebandGcTop.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(DataModel.TopModuleModel.ModeCode), DataModel.TopSysModel);
treebandGcTop.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(DataModel.TopModuleModel.ModeCode));
bandGcTop.Visible = false;
}
else
{
//上方表格
bandGcTop.Model = DataModel.TopSysModel;
bandGcTop.SetEditColumns(DataModel.TopGridColumns, GridCustomColumnStruct.BaseMainGridView + DataModel.TopModuleModel.FormKey);
bandGcTop.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(DataModel.TopModuleModel.ModeCode), DataModel.TopSysModel);
bandGcTop.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(DataModel.TopModuleModel.ModeCode));
treebandGcTop.Visible = false;
}
if (TreeMultiHeader)
{
AddDataColumns(treebandGcTop);
}
else
{
AddDataColumns(bandGcTop);
}
if (DataModel.TopModuleModel.HasReport)
{
flowLayoutPanel.Visible = false;
@@ -151,7 +184,14 @@ namespace Lskj.ProductiSched
}
}
bandGcBottom.BandedView.OptionsBehavior.Editable = false;
OnBandedViewColumnWidthChanged(bandGcTop.BandedView, null);
if (TreeMultiHeader)
{
OnBandedViewColumnWidthChanged(treebandGcTop.TreeListObj, null);
} else
{
OnBandedViewColumnWidthChanged(bandGcTop.BandedView, null);
}
}
else
{
@@ -171,20 +211,36 @@ namespace Lskj.ProductiSched
/// </summary>
public void InitControlEvents()
{
splitLeftControl.SplitterPositionChanged += OnSplitContainerPositionChanged;
splitLeftControl.SplitterPositionChanged += OnBandedViewColumnWidthChanged;
splitMainControl.SplitterPositionChanged += OnSplitContainerPositionChanged;
DataModel.TopSearchObj.OnDataSourceBindCallBack += OnDataSourceBindCallBack;
DataModel.TopSearchObj.OnSearchAfterCallBack += OnSearchAfterCallBack;
bandGcTop.BandedView.BandWidthChanged += OnBandedViewColumnWidthChanged;
bandGcTop.BandedView.ColumnWidthChanged += OnBandedViewColumnWidthChanged;
bandGcTop.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged;
bandGcBottom.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged;
bandGcTop.BandedView.RowCellClick += OnBandedViewRowCellClick;
bandGcTop.BandedView.KeyDown += OnBandedViewKeyDown;
bandGcTop.BandedView.CustomDrawFooterCell += OnCustomDrawFooterCell;
bandGcTop.BandedView.CustomDrawColumnHeader += OnCustomDrawColumnHeader;
bandGcBottom.BandedView.CustomDrawColumnHeader += OnCustomDrawColumnHeader;
bandGcTop.BandedView.ShowingEditor += OnshowingEditor;
if (TreeMultiHeader)
{
// 改为TreeList的事件绑定
treebandGcTop.TreeListObj.BandWidthChanged += OnBandedViewColumnWidthChanged;
treebandGcTop.TreeListObj.ColumnWidthChanged += OnBandedViewColumnWidthChanged; // 宽度改变事件
treebandGcTop.TreeListObj.LeftCoordChanged += OnBandedViewLeftCoordChanged; // 水平滚动事件
treebandGcTop.TreeListObj.FocusedNodeChanged += OnFocusedNodeChanged; // 单元格点击事件
treebandGcTop.TreeListObj.KeyDown += OnTreeListKeyDown; // 键盘事件
treebandGcTop.TreeListObj.CustomDrawFooterCell += OnTreeListCustomDrawFooterCell; // 自定义绘制Footer事件
treebandGcTop.TreeListObj.CustomDrawColumnHeader += OnTreeListCustomDrawColumnHeader; // 自定义绘制列头事件
treebandGcTop.TreeListObj.ShowingEditor += OnTreeListShowingEditor; // 编辑器显示前事件
}
else
{
bandGcTop.BandedView.BandWidthChanged += OnBandedViewColumnWidthChanged;
bandGcTop.BandedView.ColumnWidthChanged += OnBandedViewColumnWidthChanged;
bandGcTop.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged;
bandGcTop.BandedView.RowCellClick += OnBandedViewRowCellClick;
bandGcTop.BandedView.KeyDown += OnBandedViewKeyDown;
bandGcTop.BandedView.CustomDrawFooterCell += OnCustomDrawFooterCell;
bandGcTop.BandedView.CustomDrawColumnHeader += OnCustomDrawColumnHeader;
bandGcTop.BandedView.ShowingEditor += OnShowingEditor;
}
btnSave.Click += OnBtnSaveClick;
}
/// <summary>
@@ -192,15 +248,17 @@ namespace Lskj.ProductiSched
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnshowingEditor(object sender, CancelEventArgs e)
private void OnShowingEditor(object sender, CancelEventArgs e)
{
BandedGridView view = sender as BandedGridView;
if (view == null) return;
string billDocumentId = view.GetRowCellValue(view.FocusedRowHandle, DataModel.TopModuleModel.ParmaryKey) +"";
if (view.FocusedColumn.Tag is DateTime dateTimeTag)
// 新方式 (精准替代原有取值方式)
DateTime date;
if (DataModel.columnDateMapping.TryGetValue(view.FocusedColumn, out date))
{
string columnName = dateTimeTag.ToString("yyyy-MM-dd");
string columnName = date.ToString("yyyy-MM-dd");
// 检查该行的 billdocument_id 是否在字典中
if (DataModel.nonEditableCells.ContainsKey(billDocumentId))
{
@@ -212,7 +270,32 @@ namespace Lskj.ProductiSched
e.Cancel = true; // 取消编辑,单元格变灰
}
}
}
}
/// <summary>
/// 判断TreeList单元格是否可以编辑(精准适配原BandedGridView逻辑)
/// </summary>
private void OnTreeListShowingEditor(object sender, CancelEventArgs e)
{
TreeList treeList = sender as TreeList;
if (treeList == null || treeList.FocusedNode == null) return;
string billDocumentId = treeList.FocusedNode.GetValue(DataModel.TopModuleModel.ParmaryKey)?.ToString() ?? "";
DateTime date;
if (DataModel.columnDateMapping.TryGetValue(treeList.FocusedColumn, out date))
{
string columnName = date.ToString("yyyy-MM-dd");
// 检查该行的 billdocument_id 是否在字典中
if (DataModel.nonEditableCells.ContainsKey(billDocumentId))
{
HashSet<string> showDays = DataModel.nonEditableCells[billDocumentId];
// 如果列名(日期)在 showday_list 里,则禁用编辑
if (showDays.Contains(columnName))
{
e.Cancel = true; // 取消编辑,单元格变灰
}
}
}
}
@@ -247,7 +330,8 @@ namespace Lskj.ProductiSched
return false;
}
List<BaseSaveModel> mList = new List<BaseSaveModel>();
DataRow[] modifiedRows = (bandGcTop.BandedView.GridControl.DataSource as DataTable)
DataTable dataTable = TreeMultiHeader? treebandGcTop.GetGridViewDataSource(): bandGcTop.BandedView.GridControl.DataSource as DataTable;
DataRow[] modifiedRows = dataTable
.Rows
.Cast<DataRow>()
.Where(x => x.RowState == DataRowState.Modified || x.RowState == DataRowState.Added)
@@ -401,7 +485,7 @@ namespace Lskj.ProductiSched
typeDate = labelAutoTextEdit.EditValue;
}
// 获取主数据源,假设已绑定到 gridControl1
DataTable mainDataSource = bandGcTop.BandedView.GridControl.DataSourceTable();
DataTable mainDataSource = TreeMultiHeader ? treebandGcTop.GetGridViewDataSource():bandGcTop.BandedView.GridControl.DataSourceTable();
if (mainDataSource == null)
{
return true;
@@ -564,6 +648,58 @@ namespace Lskj.ProductiSched
Console.WriteLine(ex.Message);
}
}
/// <summary>
/// TreeList聚焦节点改变刷新当前行数据(精确移植原点击事件逻辑)
/// </summary>
private void OnFocusedNodeChanged(object sender, FocusedNodeChangedEventArgs e)
{
try
{
GridDetailModel model = DataModel.RightDetailModel;
if (e.Node != null)
{
DataRow rowItem = (treebandGcTop.TreeListObj.GetDataRecordByNode(e.Node) as DataRowView)?.Row;
if (rowItem != null)
{
BaseUserControl baseUserControl = DataModel.TopSearchObj.ParentPanel.Controls
.Cast<BaseUserControl>()
.FirstOrDefault(n => n is LabelDateEdit);
BaseUserControl dataTypeControl = DataModel.TopSearchObj.ParentPanel.Controls
.Cast<System.Windows.Forms.Control>()
.FirstOrDefault(n => n is LabelComboxEdit) as BaseUserControl;
string typeDate = "0";
LabelDateEdit labelDateEdit = baseUserControl as LabelDateEdit;
if (dataTypeControl != null && dataTypeControl is LabelComboxEdit labelAutoTextEdit)
{
typeDate = labelAutoTextEdit.EditValue;
}
if (labelDateEdit == null) return;
string searchSql = this.GetSearchSql(model, rowItem, false);
string isweekcond = DataModel.TopModuleModel.HasReport ? "" : $"and isWeek='{typeDate}'";
searchSql = $"{ReplaceHelper.ReplaceWhereCond(searchSql)} and day >= '{labelDateEdit.TextEdit.DateTime:yyyy-MM-dd}' {isweekcond}";
gcRight.SetGridViewDataSource(BaseImpl.GetDataTableResult(searchSql));
// 更新行数据逻辑
DateTime dateTime = labelDateEdit.TextEdit.DateTime;
DataTable dataDayPlan = gcRight.GridControl.DataSourceTable().Copy();
UpdateRowWithDayPlan(rowItem, dataDayPlan, dateTime);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
/// <summary>
/// 获取查询sql
/// </summary>
@@ -576,7 +712,7 @@ namespace Lskj.ProductiSched
string fieldName = !string.IsNullOrEmpty(model.UnionParentField) && rowItem.Table.Columns.Contains(model.UnionParentField) ? model.UnionParentField : DataModel.TopModuleModel.ParmaryKey;
string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : DataModel.RightModuleModel.MenuSql;
sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue);
DataRow row = bandGcTop.GetViewFocusedDataRow();
DataRow row = TreeMultiHeader ? treebandGcTop.GetViewFocusedDataRow(): bandGcTop.GetViewFocusedDataRow();
if (row != null && isLeft)
{
//先替换左侧选中行,在替换主表
@@ -597,27 +733,51 @@ namespace Lskj.ProductiSched
return sqlValue;
}
/// <summary>
/// 宽度改变
/// 宽度改变事件处理,兼容BandedGridView和TreeList
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnBandedViewColumnWidthChanged(object sender, EventArgs e)
{
if (sender == bandGcTop.BandedView && bandGcBottom.Visible)
if (bandGcBottom.Visible)
{
int allWidth = 0;
foreach (GridBand gridBand in bandGcTop.BandedView.Bands)
// 如果sender为原有的BandedView类型
if (sender == bandGcTop.BandedView)
{
if (gridBand.Columns.Count == 1 && gridBand.Columns[0].Name.Contains("DDay_"))
foreach (GridBand gridBand in bandGcTop.BandedView.Bands)
{
break;
}
else
{
allWidth += gridBand.Width;
if (gridBand.Columns.Count == 1 && gridBand.Columns[0].Name.Contains("DDay_"))
{
break;
}
else
{
allWidth += gridBand.Width;
}
}
}
List<BandedGridColumn> bandedColumnList = new List<BandedGridColumn>();
// 如果sender为TreeList类型
else if (sender is TreeList treeListSender)
{
foreach (TreeListBand band in treeListSender.Bands)
{
if (band.Columns.Count == 1 && band.Columns[0].FieldName.Contains("DDay_"))
{
break;
}
else
{
allWidth += band.Width;
}
}
}
else
{
return; // 非预期sender类型时直接退出
}
// 调整底部bandGcBottom的列宽(始终为BandedGridView类型)
List<BandedGridColumn> bottomColumnList = new List<BandedGridColumn>();
foreach (GridBand gridBand in bandGcBottom.BandedView.Bands)
{
if (gridBand.Columns.Count == 1 && gridBand.Columns[0].Name.Contains("DDay_"))
@@ -626,19 +786,24 @@ namespace Lskj.ProductiSched
}
else
{
bandedColumnList.AddRange(gridBand.Columns.Cast<BandedGridColumn>());
bottomColumnList.AddRange(gridBand.Columns.Cast<BandedGridColumn>());
}
}
if (bandedColumnList.Count > 0)
// 按计算好的宽度均分调整
if (bottomColumnList.Count > 0)
{
int perWidth = allWidth / bandedColumnList.Count;
foreach (BandedGridColumn bandedGridColumn in bandedColumnList)
int perWidth = allWidth / bottomColumnList.Count;
foreach (BandedGridColumn bandedGridColumn in bottomColumnList)
{
bandedGridColumn.Width = perWidth;
}
}
}
}
/// <summary>
/// 水平滚动条改变时
/// </summary>
@@ -646,15 +811,30 @@ namespace Lskj.ProductiSched
/// <param name="e"></param>
private void OnBandedViewLeftCoordChanged(object sender, EventArgs e)
{
if (!bandGcBottom.Visible) return;
if (sender == bandGcTop.BandedView)
{
bandGcBottom.BandedView.LeftCoord = bandGcTop.BandedView.LeftCoord;
}
else if (sender is TreeList treeListSender)
{
// 使用TreeList的LeftCoord属性同步BandedView的LeftCoord
bandGcBottom.BandedView.LeftCoord = treeListSender.LeftCoord;
}
else if (sender == bandGcBottom.BandedView)
{
bandGcTop.BandedView.LeftCoord = bandGcBottom.BandedView.LeftCoord;
if (TreeMultiHeader)
{
treebandGcTop.TreeListObj.LeftCoord = bandGcBottom.BandedView.LeftCoord;
}
else
{
bandGcTop.BandedView.LeftCoord = bandGcBottom.BandedView.LeftCoord;
}
}
}
/// <summary>
/// 搜索条件绑定完成后
/// </summary>
@@ -675,8 +855,14 @@ namespace Lskj.ProductiSched
{
LabelDateEdit labelDateEdit = baseUserControl as LabelDateEdit;
DateTime dateTime = labelDateEdit.TextEdit.DateTime;
UpdateDynamicColumns(bandGcTop, dateTime, typeDate);
UpdateDynamicColumns(bandGcBottom, dateTime, typeDate);
if (TreeMultiHeader)
{
UpdateDynamicColumns(treebandGcTop, dateTime, typeDate);
}
else {
UpdateDynamicColumns(bandGcTop, dateTime, typeDate);
}
}
}
/// <summary>
@@ -705,7 +891,14 @@ namespace Lskj.ProductiSched
labelDateEdit.TextEdit.DateTime = weekStart;
}
DateTime dateTime = labelDateEdit.TextEdit.DateTime;
UpdateDynamicColumns(bandGcTop, dateTime, typeDate);
if (TreeMultiHeader)
{
UpdateDynamicColumns(treebandGcTop, dateTime, typeDate);
}
else
{
UpdateDynamicColumns(bandGcTop, dateTime, typeDate);
}
UpdateDynamicColumns(bandGcBottom, dateTime, typeDate);
DataTable dataMain = bandGcTop.GridControl.DataSourceTable().Copy();
DataTable dataDetail = bandGcTop.GridControl.DataSourceTable().Copy();
@@ -798,7 +991,7 @@ namespace Lskj.ProductiSched
}
foreach (GridBand gridBand in bandedGridControlEx.BandedView.Bands)
{
gridBand.Fixed = FixedStyle.Left;
gridBand.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left;
}
for (int i = 0; i < 93; i++)
{
@@ -829,7 +1022,7 @@ namespace Lskj.ProductiSched
gridColumn.Visible = false;
if (bandedGridControlEx == bandGcTop)
{
gridColumn.SummaryItem.SummaryType = SummaryItemType.Sum;
gridColumn.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
gridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}";
}
gridBand.Columns.Add(gridColumn);
@@ -864,12 +1057,178 @@ namespace Lskj.ProductiSched
gridColumn.Visible = false;
if (bandedGridControlEx == bandGcTop)
{
gridColumn.SummaryItem.SummaryType = SummaryItemType.Sum;
gridColumn.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
gridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}";
}
gridBand.Columns.Add(gridColumn);
}
}
/// <summary>
/// 添加多表头树结构模式的虚拟日期列(基于TreeList)
/// </summary>
/// <summary>
/// 添加虚拟日期列(树的多表头模式)
/// </summary>
/// <summary>
/// 添加虚拟日期列(树的多表头模式)
/// </summary>
private void AddDataColumns(TreeBandedGridControlEx bandedGridControlEx)
{
// 核心优化代码:暂停数据源绑定和界面刷新
bandedGridControlEx.TreeListObj.BeginUpdate();
bandedGridControlEx.TreeListObj.LockReloadNodes(); // 阻止节点数据重载(关键优化)
try
{
if (bandedGridControlEx == treebandGcTop)
{
bandedGridControlEx.TreeListObj.OptionsView.ShowSummaryFooter = true;
}
foreach (TreeListBand fixedBand in bandedGridControlEx.TreeListObj.Bands)
{
fixedBand.Fixed = DevExpress.XtraTreeList.Columns.FixedStyle.Left;
}
// 添加93个日列
for (int i = 0; i < 93; i++)
{
TreeListBand dayBand = new TreeListBand
{
Name = $"Day_{i}",
Caption = "",
OptionsBand = { AllowMove = false, AllowSize = false },
AppearanceHeader = {
Options = { UseFont = true, UseTextOptions = true },
Font = new Font("宋体", 9, FontStyle.Bold),
TextOptions = { HAlignment = HorzAlignment.Center }
}
};
bandedGridControlEx.TreeListObj.Bands.Add(dayBand);
TreeListColumn dayColumn = new TreeListColumn
{
FieldName = $"DDay_{i}",
Width = 70,
Visible = false,
OptionsColumn = {
AllowMove = false,
AllowSize = false,
AllowSort = false,
AllowEdit = false
},
AppearanceCell = { TextOptions = { HAlignment = HorzAlignment.Center }, Options = { UseTextOptions = true } },
AppearanceHeader = { TextOptions = { HAlignment = HorzAlignment.Center }, Options = { UseTextOptions = true } },
Format = { FormatType = FormatType.Numeric, FormatString = "{0:#,##0.####}" }
};
if (bandedGridControlEx == treebandGcTop)
{
dayColumn.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Sum;
dayColumn.SummaryFooterStrFormat = "{0:#,##0.####}";
}
dayBand.Columns.Add(dayColumn);
bandedGridControlEx.TreeListObj.Columns.Add(dayColumn);
}
// 添加15个周列
for (int i = 93; i < 108; i++)
{
TreeListBand weekBand = new TreeListBand
{
Name = $"Week_{i - 93}",
Caption = "",
OptionsBand = { AllowMove = false, AllowSize = false },
AppearanceHeader = {
Options = { UseFont = true, UseTextOptions = true },
Font = new Font("宋体", 9, FontStyle.Bold),
TextOptions = { HAlignment = HorzAlignment.Center }
}
};
bandedGridControlEx.TreeListObj.Bands.Add(weekBand);
TreeListColumn weekColumn = new TreeListColumn
{
FieldName = $"WWeek_{i - 93}",
Width = 140,
Visible = false,
OptionsColumn = {
AllowMove = false,
AllowSize = false,
AllowSort = false,
AllowEdit = false
},
AppearanceCell = { TextOptions = { HAlignment = HorzAlignment.Center }, Options = { UseTextOptions = true } },
AppearanceHeader = { TextOptions = { HAlignment = HorzAlignment.Center }, Options = { UseTextOptions = true } },
Format = { FormatType = FormatType.Numeric, FormatString = "{0:#,##0.####}" }
};
if (bandedGridControlEx == treebandGcTop)
{
weekColumn.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Sum;
weekColumn.SummaryFooterStrFormat = "{0:#,##0.####}";
}
weekBand.Columns.Add(weekColumn);
//bandedGridControlEx.TreeListObj.Columns.Add(weekColumn);
}
}
finally
{
bandedGridControlEx.TreeListObj.UnlockReloadNodes(); // 重新允许节点加载数据
bandedGridControlEx.TreeListObj.EndUpdate(); // 一次性完成所有刷新
}
}
/// <summary>
/// 创建TreeList统一的列
/// </summary>
private TreeListColumn CreateTreeListColumn(string fieldName, int width)
{
var column = new TreeListColumn
{
Name = $"col_{fieldName}",
FieldName = fieldName,
Caption = fieldName,
Width = width,
Visible = true,
OptionsColumn =
{
AllowMove = false,
AllowSize = false,
AllowSort = false,
AllowEdit = false
},
AppearanceHeader =
{
TextOptions = { HAlignment = HorzAlignment.Center },
Font = new Font("宋体", 9, FontStyle.Bold)
},
AppearanceCell =
{
TextOptions = { HAlignment = HorzAlignment.Center }
},
Format =
{
FormatType = FormatType.Numeric,
FormatString = "{0:#,##0.####}"
}
};
return column;
}
/// <summary>
/// 配置列的汇总项
/// </summary>
private void SetupColumnSummary(TreeListColumn column)
{
column.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Sum;
column.SummaryFooterStrFormat = "{0:#,##0.####}";
}
#region
/// <summary>
/// 构建带日期或周期
@@ -896,6 +1255,28 @@ namespace Lskj.ProductiSched
bandedGridControlEx.BandedView.EndUpdate();
}
}
/// <summary>
/// 更新TreeList控件的动态列
/// </summary>
private void UpdateDynamicColumns(TreeBandedGridControlEx bandedGridControlEx, DateTime currentDate, string typeDate = "0")
{
try
{
if (typeDate == "1")
{
UpdateWeeklyColumns(bandedGridControlEx, currentDate);
}
else
{
UpdateDailyColumns(bandedGridControlEx, currentDate);
}
}
finally
{
}
}
/// <summary>
/// 按照周结构生成列
/// </summary>
@@ -929,10 +1310,8 @@ namespace Lskj.ProductiSched
// 设置列的宽度
weekColumn.Width = 140;
// 设置该列的Tag为周的开始日期(便于后续操作)
weekColumn.Tag = weekStart;
DataModel.columnDateMapping[weekColumn] = weekStart;
// 设置是否允许编辑
if (weekEnd >= DateTime.Today)
{
@@ -972,6 +1351,61 @@ namespace Lskj.ProductiSched
}
}
}
/// <summary>
/// 更新TreeList控件的周列
/// </summary>
private void UpdateWeeklyColumns(TreeBandedGridControlEx grid, DateTime currentDate)
{
DateTime endDate = currentDate.AddMonths(3).AddDays(-1);
int weekIndex = 0;
DateTime weekStart = GetStartOfWeek(currentDate);
while (weekStart <= endDate && weekIndex < 15)
{
DateTime weekEnd = weekStart.AddDays(6);
string bandTitle = $"Week_{weekIndex}";
TreeListBand weekBand = grid.TreeListObj.Bands.Cast<TreeListBand>()
.FirstOrDefault(b => b.Name == bandTitle);
if (weekBand != null && weekBand.Columns.Count > 0)
{
TreeListColumn weekColumn = weekBand.Columns[0];
weekBand.Visible = true;
weekBand.Caption = $"{weekStart:MM-dd}至{weekEnd:MM-dd}";
weekColumn.FieldName = weekStart.ToString("yyyy-MM-dd");
weekColumn.Caption = $"第{GetWeekOfYear(weekStart)}周";
weekColumn.Width = 140;
// 新优化方式(使用字典存储)
DataModel.columnDateMapping[weekColumn] = weekStart;
weekColumn.OptionsColumn.AllowEdit = weekEnd >= DateTime.Today;
weekColumn.Visible = true;
}
weekStart = weekEnd.AddDays(1);
weekIndex++;
}
foreach (int i in Enumerable.Range(weekIndex, 15 - weekIndex))
{
TreeListBand band = grid.TreeListObj.Bands.Cast<TreeListBand>()
.FirstOrDefault(b => b.Name == $"Week_{i}");
if (band != null) band.Visible = false;
}
foreach (var band in grid.TreeListObj.Bands.Cast<TreeListBand>())
{
if (band.Name.StartsWith("Day_"))
{
band.Visible = false;
foreach (TreeListColumn column in band.Columns)
{
column.Visible = false;
}
}
}
}
/// <summary>
/// 获取给定日期所在周的开始日期(周一)。
@@ -1032,7 +1466,8 @@ namespace Lskj.ProductiSched
gridColumn.FieldName = dateForColumn.ToString("yyyy-MM-dd");
gridColumn.Caption = GetChineseWeekDayNumber(dateForColumn);
gridColumn.Width = 70;
gridColumn.Tag = dateForColumn;
// 新优化方式(使用字典存储)
DataModel.columnDateMapping[gridColumn] = dateForColumn;
if (grid == bandGcTop)
{
if (dateForColumn.Date < DateTime.Now.Date)
@@ -1065,6 +1500,76 @@ namespace Lskj.ProductiSched
}
}
}
/// <summary>
/// 更新TreeList控件的日列
/// </summary>
private void UpdateDailyColumns(TreeBandedGridControlEx grid, DateTime currentDate)
{
DateTime endDate = currentDate.AddMonths(3).AddDays(-1);
// 核心优化代码:暂停数据源绑定和界面刷新
grid.TreeListObj.BeginUpdate();
grid.TreeListObj.LockReloadNodes(); // 阻止节点数据重载(关键优化)
try
{
for (int i = 0; i < 93; i++)
{
string bandTitle = $"Day_{i}";
TreeListBand treeListBand = grid.TreeListObj.Bands.Cast<TreeListBand>().FirstOrDefault(x => x.Name == bandTitle);
if (treeListBand == null)
continue;
TreeListColumn treeListColumn = treeListBand.Columns.Count > 0 ? treeListBand.Columns[0] : null;
if (treeListColumn == null)
continue;
DateTime dateForColumn = currentDate.AddDays(i);
if (dateForColumn <= endDate)
{
treeListBand.Caption = dateForColumn.ToString("MM-dd");
treeListBand.Visible = true;
treeListColumn.FieldName = dateForColumn.ToString("yyyy-MM-dd"); // 保留原逻辑不变
treeListColumn.Caption = GetChineseWeekDayNumber(dateForColumn);
treeListColumn.Width = 70;
// 关键优化:改为外部字典缓存
DataModel.columnDateMapping[treeListColumn] = dateForColumn;
//treeListColumn.Tag = dateForColumn;
if (grid == treebandGcTop)
{
treeListColumn.OptionsColumn.AllowEdit = dateForColumn.Date >= DateTime.Now.Date;
}
treeListColumn.Visible = true;
}
else
{
treeListBand.Visible = false;
treeListColumn.Visible = false;
}
}
foreach (var band in grid.TreeListObj.Bands.Cast<TreeListBand>())
{
if (band.Name.StartsWith("Week_"))
{
band.Visible = false;
foreach (TreeListColumn column in band.Columns)
{
column.Visible = false;
}
}
}
}
finally
{
grid.TreeListObj.UnlockReloadNodes(); // 重新允许节点加载数据
grid.TreeListObj.EndUpdate(); // 一次性完成所有刷新
}
}
#endregion
@@ -1371,6 +1876,14 @@ namespace Lskj.ProductiSched
{
e.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
}
/// <summary>
/// TreeList合计行单元格居中显示
/// </summary>
private void OnTreeListCustomDrawFooterCell(object sender, DevExpress.XtraTreeList.CustomDrawFooterCellEventArgs e)
{
e.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
}
/// <summary>
/// 表头颜色设置
/// </summary>
@@ -1379,23 +1892,51 @@ namespace Lskj.ProductiSched
private void OnCustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
{
// 判断列的Tag是否为 DateTime
if (e.Column != null && e.Column.Tag != null && e.Column.Tag is DateTime dateTime)
if (e.Column != null)
{
// 判断是否为周列,如果是周列则跳过标红
if (e.Column.Caption.StartsWith("第"))
{
return; // 跳过周列
}
// 判断日期是否为周末(星期六或星期日)
if (dateTime.DayOfWeek == DayOfWeek.Saturday || dateTime.DayOfWeek == DayOfWeek.Sunday)
DateTime dateTime;
if (DataModel.columnDateMapping.TryGetValue(e.Column, out dateTime))
{
// 设置表头文字颜色为红色
e.Appearance.ForeColor = Color.Red;
// 判断日期是否为周末(星期六或星期日)
if (dateTime.DayOfWeek == DayOfWeek.Saturday || dateTime.DayOfWeek == DayOfWeek.Sunday)
{
// 设置表头文字颜色为红色
e.Appearance.ForeColor = Color.Red;
}
}
}
}
/// <summary>
/// TreeList表头颜色自定义绘制(精准适配原BandedGridView逻辑)
/// </summary>
private void OnTreeListCustomDrawColumnHeader(object sender, DevExpress.XtraTreeList.CustomDrawColumnHeaderEventArgs e)
{
// 判断列的Tag是否为 DateTime
if (e.Column != null)
{
if (e.Column.Caption.StartsWith("第"))
{
return; // 跳过周列
}
DateTime dateTime;
if (DataModel.columnDateMapping.TryGetValue(e.Column, out dateTime))
{
// 判断日期是否为周末(星期六或星期日)
if (dateTime.DayOfWeek == DayOfWeek.Saturday || dateTime.DayOfWeek == DayOfWeek.Sunday)
{
// 设置表头文字颜色为红色
e.Appearance.ForeColor = Color.Red;
}
}
}
}
/// <summary>
/// 按键点击事件
/// </summary>
@@ -1422,11 +1963,18 @@ namespace Lskj.ProductiSched
{
foreach (GridCell gridCell in SelectCells)
{
if (gridCell.Column.Tag != null && gridCell.Column.Tag is DateTime dateTime)
// 判断列的Tag是否为 DateTime
if (gridCell.Column != null)
{
if (dateTime.Date >= DateTime.Now.Date)
DateTime dateTime;
if (DataModel.columnDateMapping.TryGetValue(gridCell.Column, out dateTime))
{
bandedGridView.SetRowCellValue(gridCell.RowHandle, gridCell.Column, obj);
// 判断日期是否为周末(星期六或星期日)
if (dateTime.Date >= DateTime.Now.Date)
{
bandedGridView.SetRowCellValue(gridCell.RowHandle, gridCell.Column, obj);
}
}
}
}
@@ -1439,6 +1987,46 @@ namespace Lskj.ProductiSched
}
}
}
/// <summary>
/// TreeList按键事件处理,精准移植原BandedGridView的F7快速填充逻辑
/// </summary>
private void OnTreeListKeyDown(object sender, KeyEventArgs e)
{
TreeList treeList = sender as TreeList;
if (treeList == null || !treeList.OptionsBehavior.Editable) return;
if (e.KeyCode == Keys.F7)
{
TreeListColumn column = treeList.FocusedColumn;
if (column != null && column.OptionsColumn.AllowEdit && treeList.AllNodesCount > 0)
{
// 获取当前聚焦单元格的值
object focusedValue = treeList.FocusedNode?.GetValue(column);
if (focusedValue != null && MessageUtil.Show("是否替换所选单元格值?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
WaitForm.ShowForm("数据填充中");
foreach (TreeListNode node in treeList.Selection)
{
DateTime dateTime;
if (DataModel.columnDateMapping.TryGetValue(column, out dateTime))
{
if (dateTime.Date >= DateTime.Now.Date)
{
node.SetValue(column, focusedValue);
}
}
}
treeList.PostEditor();
e.Handled = true;
WaitForm.HideForm();
}
}
}
}
/// <summary>
/// 构建下方数据
/// </summary>
@@ -1496,28 +2084,4 @@ namespace Lskj.ProductiSched
decimal coefficient = kvp.Value.Coefficient;
List<string> keyValues = kvp.Value.KeyValues;
DataRow newRow = dtC.NewRow();
newRow["产地"] = origin;
newRow["总产能"] = totalCapacity;
// 对每个动态日期列,从 dtPlan 中查找 billdocument_id 在 keyValues 内,
// 且 ShowDay 等于当前列名的记录,将 amount 累加后再乘以系数
foreach (string dateCol in dateColumns)
{
decimal sumAmount = planRows
.Where(pr => keyValues.Contains(pr.BillId) && pr.ShowDay == dateCol)
.Sum(pr => pr.Amount);
// 乘以系数得到实际值
newRow[dateCol] = sumAmount * coefficient;
}
dtC.Rows.Add(newRow);
}
return dtC;
}
catch (Exception)
{
return default;
}
}
}
}
@@ -42,6 +42,7 @@
<HintPath>C:\Program Files (x86)\DevExpress 15.2\Components\Bin\Framework\DevExpress.XtraEditors.v15.2.dll</HintPath>
</Reference>
<Reference Include="DevExpress.XtraGrid.v15.2, Version=15.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.XtraTreeList.v15.2, Version=15.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<Reference Include="Lskj.Core, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Debug\Lskj.Core.dll</HintPath>
@@ -1,4 +1,5 @@
using Lskj.Control.Model;
using DevExpress.XtraTreeList.Columns;
using Lskj.Control.Model;
using Lskj.Model;
using System;
using System.Collections.Generic;
@@ -8,4 +9,7 @@ using System.Text;
namespace Lskj.ProductiSched
{
public class P
public class ProductDataModel
{
// 在你的类内部定义此字典(一次定义,长期复用)
public Dictionary<object, DateTime> columnDateMapping = new Dictionar