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.pl_main = new DevExpress.XtraEditors.PanelControl();
this.splitMainControl = new DevExpress.XtraEditors.SplitContainerControl(); this.splitMainControl = new DevExpress.XtraEditors.SplitContainerControl();
this.splitLeftControl = new DevExpress.XtraEditors.SplitContainerControl(); this.splitLeftControl = new DevExpress.XtraEditors.SplitContainerControl();
this.bandGcBottom = new Lskj.Control.BandedGridControlEx(); this.pltopmain = new DevExpress.XtraEditors.PanelControl();
this.gcRight = new Lskj.Control.GridControlEx(); this.treebandGcTop = new Lskj.Control.TreeBandedGridControlEx();
this.bandGcTop = new Lskj.Control.BandedGridControlEx();
this.pl_mainSearch = new DevExpress.XtraEditors.PanelControl(); this.pl_mainSearch = new DevExpress.XtraEditors.PanelControl();
this.pl_search = new DevExpress.XtraEditors.PanelControl(); this.pl_search = new DevExpress.XtraEditors.PanelControl();
this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
this.btnSave = new DevExpress.XtraEditors.SimpleButton(); 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(); ((System.ComponentModel.ISupportInitialize)(this.pl_main)).BeginInit();
this.pl_main.SuspendLayout(); this.pl_main.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitMainControl)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitMainControl)).BeginInit();
this.splitMainControl.SuspendLayout(); this.splitMainControl.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitLeftControl)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitLeftControl)).BeginInit();
this.splitLeftControl.SuspendLayout(); this.splitLeftControl.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pltopmain)).BeginInit();
this.pltopmain.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pl_mainSearch)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pl_mainSearch)).BeginInit();
this.pl_mainSearch.SuspendLayout(); this.pl_mainSearch.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pl_search)).BeginInit(); ((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.Location = new System.Drawing.Point(0, 0);
this.splitLeftControl.Margin = new System.Windows.Forms.Padding(2); this.splitLeftControl.Margin = new System.Windows.Forms.Padding(2);
this.splitLeftControl.Name = "splitLeftControl"; 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.Controls.Add(this.pl_mainSearch);
this.splitLeftControl.Panel1.Text = "Panel1"; this.splitLeftControl.Panel1.Text = "Panel1";
this.splitLeftControl.Panel2.Controls.Add(this.bandGcBottom); this.splitLeftControl.Panel2.Controls.Add(this.bandGcBottom);
@@ -96,27 +100,38 @@ namespace Lskj.ProductiSched
this.splitLeftControl.TabIndex = 7; this.splitLeftControl.TabIndex = 7;
this.splitLeftControl.Text = "splitContainerControl2"; this.splitLeftControl.Text = "splitContainerControl2";
// //
// bandGcBottom // pltopmain
// //
this.bandGcBottom.AdapterObj = null; this.pltopmain.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
this.bandGcBottom.Dock = System.Windows.Forms.DockStyle.Fill; this.pltopmain.Controls.Add(this.treebandGcTop);
this.bandGcBottom.Location = new System.Drawing.Point(0, 0); this.pltopmain.Controls.Add(this.bandGcTop);
this.bandGcBottom.Margin = new System.Windows.Forms.Padding(4); this.pltopmain.Dock = System.Windows.Forms.DockStyle.Fill;
this.bandGcBottom.Name = "bandGcBottom"; this.pltopmain.Location = new System.Drawing.Point(0, 0);
this.bandGcBottom.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum; this.pltopmain.Name = "pltopmain";
this.bandGcBottom.Size = new System.Drawing.Size(997, 321); this.pltopmain.Size = new System.Drawing.Size(997, 320);
this.bandGcBottom.TabIndex = 12; this.pltopmain.TabIndex = 22;
// //
// gcRight // treebandGcTop
// //
this.gcRight.AdapterObj = null; this.treebandGcTop.AdapterObj = null;
this.gcRight.Dock = System.Windows.Forms.DockStyle.Fill; this.treebandGcTop.Dock = System.Windows.Forms.DockStyle.Fill;
this.gcRight.Location = new System.Drawing.Point(0, 0); this.treebandGcTop.Location = new System.Drawing.Point(0, 0);
this.gcRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.treebandGcTop.Margin = new System.Windows.Forms.Padding(4);
this.gcRight.Name = "gcRight"; this.treebandGcTop.Name = "treebandGcTop";
this.gcRight.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum; this.treebandGcTop.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
this.gcRight.Size = new System.Drawing.Size(315, 679); this.treebandGcTop.Size = new System.Drawing.Size(997, 320);
this.gcRight.TabIndex = 11; 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 // pl_mainSearch
// //
@@ -166,16 +181,27 @@ namespace Lskj.ProductiSched
this.btnSave.TabIndex = 40; this.btnSave.TabIndex = 40;
this.btnSave.Text = "保存(&S)"; this.btnSave.Text = "保存(&S)";
// //
// bandGcTop // bandGcBottom
// //
this.bandGcTop.AdapterObj = null; this.bandGcBottom.AdapterObj = null;
this.bandGcTop.Dock = System.Windows.Forms.DockStyle.Fill; this.bandGcBottom.Dock = System.Windows.Forms.DockStyle.Fill;
this.bandGcTop.Location = new System.Drawing.Point(0, 0); this.bandGcBottom.Location = new System.Drawing.Point(0, 0);
this.bandGcTop.Margin = new System.Windows.Forms.Padding(4); this.bandGcBottom.Margin = new System.Windows.Forms.Padding(4);
this.bandGcTop.Name = "bandGcTop"; this.bandGcBottom.Name = "bandGcBottom";
this.bandGcTop.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum; this.bandGcBottom.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
this.bandGcTop.Size = new System.Drawing.Size(997, 320); this.bandGcBottom.Size = new System.Drawing.Size(997, 321);
this.bandGcTop.TabIndex = 13; 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 // FrmProductSched
// //
@@ -189,4 +215,8 @@ namespace Lskj.ProductiSched
((System.ComponentModel.ISupportInitialize)(this.splitMainControl)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.splitMainControl)).EndInit();
this.splitMainControl.ResumeLayout(false); this.splitMainControl.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitLeftControl)).EndInit(); ((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.
+618 -54
View File
@@ -5,6 +5,9 @@ using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.BandedGrid; using DevExpress.XtraGrid.Views.BandedGrid;
using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.Nodes;
using Lskj.Business.Impl; using Lskj.Business.Impl;
using Lskj.Control; using Lskj.Control;
using Lskj.Control.Model; using Lskj.Control.Model;
@@ -31,6 +34,7 @@ namespace Lskj.ProductiSched
public partial class FrmProductSched : UserControl public partial class FrmProductSched : UserControl
{ {
public bool TreeMultiHeader;
public ProductDataModel DataModel; public ProductDataModel DataModel;
public FrmProductSched() public FrmProductSched()
{ {
@@ -62,7 +66,14 @@ namespace Lskj.ProductiSched
DataModel.TopRowColors = BaseModuleImpl.GetBaseGridRowColors(DataModel.TopModuleModel.FormKey); DataModel.TopRowColors = BaseModuleImpl.GetBaseGridRowColors(DataModel.TopModuleModel.FormKey);
DataModel.TopSearchTab = BaseModuleImpl.GetCustomQueryFields(DataModel.TopModuleModel.CondKey); DataModel.TopSearchTab = BaseModuleImpl.GetCustomQueryFields(DataModel.TopModuleModel.CondKey);
DataModel.TopSchemesTable = BaseModuleImpl.GetSchemesList(DataModel.TopSysModel.ModuleId); DataModel.TopSchemesTable = BaseModuleImpl.GetSchemesList(DataModel.TopSysModel.ModuleId);
if (DataModel.TopModuleModel.TreeAutoMultiHeader == 1)
{
DataModel.TopSearchObj = new MyControl(DataModel.TopModuleModel.MenuSql, treebandGcTop);
}
else
{
DataModel.TopSearchObj = new MyControl(DataModel.TopModuleModel.MenuSql, bandGcTop); DataModel.TopSearchObj = new MyControl(DataModel.TopModuleModel.MenuSql, bandGcTop);
}
DataModel.TopSearchObj.Model = DataModel.TopSysModel; DataModel.TopSearchObj.Model = DataModel.TopSysModel;
DataTable detailsTab = BaseModuleImpl.GetBaseDetailPages(DataModel.TopSysModel.ModuleCode); DataTable detailsTab = BaseModuleImpl.GetBaseDetailPages(DataModel.TopSysModel.ModuleCode);
if (detailsTab != null) if (detailsTab != null)
@@ -119,17 +130,39 @@ namespace Lskj.ProductiSched
{ {
//搜索控件 //搜索控件
bool fixedQuery = DataModel.TopSearchTab == null || DataModel.TopSearchTab.Rows.Count == 0; bool fixedQuery = DataModel.TopSearchTab == null || DataModel.TopSearchTab.Rows.Count == 0;
TreeMultiHeader = DataModel.TopModuleModel.TreeAutoMultiHeader == 1;
if (!fixedQuery) if (!fixedQuery)
{ {
this.pl_mainSearch.Height = DataModel.TopSearchObj.InitSearchControl(DataModel.TopSearchTab, this.pl_search, true, DataModel.TopSchemesTable, DataModel.TopSysModel); 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; this.pl_search.Width = DataModel.TopSearchObj.ParentPanel.Controls.Cast<System.Windows.Forms.Control>().Max(n => n.Location.X + n.Width) + 5;
} }
//构建树表格
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.Model = DataModel.TopSysModel;
bandGcTop.SetEditColumns(DataModel.TopGridColumns, GridCustomColumnStruct.BaseMainGridView + DataModel.TopModuleModel.FormKey); bandGcTop.SetEditColumns(DataModel.TopGridColumns, GridCustomColumnStruct.BaseMainGridView + DataModel.TopModuleModel.FormKey);
bandGcTop.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(DataModel.TopModuleModel.ModeCode), DataModel.TopSysModel); bandGcTop.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(DataModel.TopModuleModel.ModeCode), DataModel.TopSysModel);
bandGcTop.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(DataModel.TopModuleModel.ModeCode)); bandGcTop.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(DataModel.TopModuleModel.ModeCode));
treebandGcTop.Visible = false;
}
if (TreeMultiHeader)
{
AddDataColumns(treebandGcTop);
}
else
{
AddDataColumns(bandGcTop); AddDataColumns(bandGcTop);
}
if (DataModel.TopModuleModel.HasReport) if (DataModel.TopModuleModel.HasReport)
{ {
flowLayoutPanel.Visible = false; flowLayoutPanel.Visible = false;
@@ -151,8 +184,15 @@ namespace Lskj.ProductiSched
} }
} }
bandGcBottom.BandedView.OptionsBehavior.Editable = false; bandGcBottom.BandedView.OptionsBehavior.Editable = false;
if (TreeMultiHeader)
{
OnBandedViewColumnWidthChanged(treebandGcTop.TreeListObj, null);
} else
{
OnBandedViewColumnWidthChanged(bandGcTop.BandedView, null); OnBandedViewColumnWidthChanged(bandGcTop.BandedView, null);
} }
}
else else
{ {
splitLeftControl.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Panel1; splitLeftControl.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Panel1;
@@ -171,20 +211,36 @@ namespace Lskj.ProductiSched
/// </summary> /// </summary>
public void InitControlEvents() public void InitControlEvents()
{ {
splitLeftControl.SplitterPositionChanged += OnSplitContainerPositionChanged; splitLeftControl.SplitterPositionChanged += OnBandedViewColumnWidthChanged;
splitMainControl.SplitterPositionChanged += OnSplitContainerPositionChanged; splitMainControl.SplitterPositionChanged += OnSplitContainerPositionChanged;
DataModel.TopSearchObj.OnDataSourceBindCallBack += OnDataSourceBindCallBack; DataModel.TopSearchObj.OnDataSourceBindCallBack += OnDataSourceBindCallBack;
DataModel.TopSearchObj.OnSearchAfterCallBack += OnSearchAfterCallBack; DataModel.TopSearchObj.OnSearchAfterCallBack += OnSearchAfterCallBack;
bandGcBottom.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged;
bandGcBottom.BandedView.CustomDrawColumnHeader += OnCustomDrawColumnHeader;
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.BandWidthChanged += OnBandedViewColumnWidthChanged;
bandGcTop.BandedView.ColumnWidthChanged += OnBandedViewColumnWidthChanged; bandGcTop.BandedView.ColumnWidthChanged += OnBandedViewColumnWidthChanged;
bandGcTop.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged; bandGcTop.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged;
bandGcBottom.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged;
bandGcTop.BandedView.RowCellClick += OnBandedViewRowCellClick; bandGcTop.BandedView.RowCellClick += OnBandedViewRowCellClick;
bandGcTop.BandedView.KeyDown += OnBandedViewKeyDown; bandGcTop.BandedView.KeyDown += OnBandedViewKeyDown;
bandGcTop.BandedView.CustomDrawFooterCell += OnCustomDrawFooterCell; bandGcTop.BandedView.CustomDrawFooterCell += OnCustomDrawFooterCell;
bandGcTop.BandedView.CustomDrawColumnHeader += OnCustomDrawColumnHeader; bandGcTop.BandedView.CustomDrawColumnHeader += OnCustomDrawColumnHeader;
bandGcBottom.BandedView.CustomDrawColumnHeader += OnCustomDrawColumnHeader; bandGcTop.BandedView.ShowingEditor += OnShowingEditor;
bandGcTop.BandedView.ShowingEditor += OnshowingEditor; }
btnSave.Click += OnBtnSaveClick; btnSave.Click += OnBtnSaveClick;
} }
/// <summary> /// <summary>
@@ -192,15 +248,17 @@ namespace Lskj.ProductiSched
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void OnshowingEditor(object sender, CancelEventArgs e) private void OnShowingEditor(object sender, CancelEventArgs e)
{ {
BandedGridView view = sender as BandedGridView; BandedGridView view = sender as BandedGridView;
if (view == null) return; if (view == null) return;
string billDocumentId = view.GetRowCellValue(view.FocusedRowHandle, DataModel.TopModuleModel.ParmaryKey) +""; 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 是否在字典中 // 检查该行的 billdocument_id 是否在字典中
if (DataModel.nonEditableCells.ContainsKey(billDocumentId)) if (DataModel.nonEditableCells.ContainsKey(billDocumentId))
{ {
@@ -212,7 +270,32 @@ namespace Lskj.ProductiSched
e.Cancel = true; // 取消编辑,单元格变灰 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; return false;
} }
List<BaseSaveModel> mList = new List<BaseSaveModel>(); 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 .Rows
.Cast<DataRow>() .Cast<DataRow>()
.Where(x => x.RowState == DataRowState.Modified || x.RowState == DataRowState.Added) .Where(x => x.RowState == DataRowState.Modified || x.RowState == DataRowState.Added)
@@ -401,7 +485,7 @@ namespace Lskj.ProductiSched
typeDate = labelAutoTextEdit.EditValue; typeDate = labelAutoTextEdit.EditValue;
} }
// 获取主数据源,假设已绑定到 gridControl1 // 获取主数据源,假设已绑定到 gridControl1
DataTable mainDataSource = bandGcTop.BandedView.GridControl.DataSourceTable(); DataTable mainDataSource = TreeMultiHeader ? treebandGcTop.GetGridViewDataSource():bandGcTop.BandedView.GridControl.DataSourceTable();
if (mainDataSource == null) if (mainDataSource == null)
{ {
return true; return true;
@@ -564,6 +648,58 @@ namespace Lskj.ProductiSched
Console.WriteLine(ex.Message); 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> /// <summary>
/// 获取查询sql /// 获取查询sql
/// </summary> /// </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 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; string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : DataModel.RightModuleModel.MenuSql;
sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue); sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue);
DataRow row = bandGcTop.GetViewFocusedDataRow(); DataRow row = TreeMultiHeader ? treebandGcTop.GetViewFocusedDataRow(): bandGcTop.GetViewFocusedDataRow();
if (row != null && isLeft) if (row != null && isLeft)
{ {
//先替换左侧选中行,在替换主表 //先替换左侧选中行,在替换主表
@@ -597,15 +733,17 @@ namespace Lskj.ProductiSched
return sqlValue; return sqlValue;
} }
/// <summary> /// <summary>
/// 宽度改变 /// 宽度改变事件处理,兼容BandedGridView和TreeList
/// </summary> /// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnBandedViewColumnWidthChanged(object sender, EventArgs e) private void OnBandedViewColumnWidthChanged(object sender, EventArgs e)
{ {
if (sender == bandGcTop.BandedView && bandGcBottom.Visible) if (bandGcBottom.Visible)
{ {
int allWidth = 0; int allWidth = 0;
// 如果sender为原有的BandedView类型
if (sender == bandGcTop.BandedView)
{
foreach (GridBand gridBand in bandGcTop.BandedView.Bands) foreach (GridBand gridBand in bandGcTop.BandedView.Bands)
{ {
if (gridBand.Columns.Count == 1 && gridBand.Columns[0].Name.Contains("DDay_")) if (gridBand.Columns.Count == 1 && gridBand.Columns[0].Name.Contains("DDay_"))
@@ -617,7 +755,29 @@ namespace Lskj.ProductiSched
allWidth += gridBand.Width; 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) foreach (GridBand gridBand in bandGcBottom.BandedView.Bands)
{ {
if (gridBand.Columns.Count == 1 && gridBand.Columns[0].Name.Contains("DDay_")) if (gridBand.Columns.Count == 1 && gridBand.Columns[0].Name.Contains("DDay_"))
@@ -626,19 +786,24 @@ namespace Lskj.ProductiSched
} }
else 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; int perWidth = allWidth / bottomColumnList.Count;
foreach (BandedGridColumn bandedGridColumn in bandedColumnList) foreach (BandedGridColumn bandedGridColumn in bottomColumnList)
{ {
bandedGridColumn.Width = perWidth; bandedGridColumn.Width = perWidth;
} }
} }
} }
} }
/// <summary> /// <summary>
/// 水平滚动条改变时 /// 水平滚动条改变时
/// </summary> /// </summary>
@@ -646,15 +811,30 @@ namespace Lskj.ProductiSched
/// <param name="e"></param> /// <param name="e"></param>
private void OnBandedViewLeftCoordChanged(object sender, EventArgs e) private void OnBandedViewLeftCoordChanged(object sender, EventArgs e)
{ {
if (!bandGcBottom.Visible) return;
if (sender == bandGcTop.BandedView) if (sender == bandGcTop.BandedView)
{ {
bandGcBottom.BandedView.LeftCoord = bandGcTop.BandedView.LeftCoord; 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) else if (sender == bandGcBottom.BandedView)
{
if (TreeMultiHeader)
{
treebandGcTop.TreeListObj.LeftCoord = bandGcBottom.BandedView.LeftCoord;
}
else
{ {
bandGcTop.BandedView.LeftCoord = bandGcBottom.BandedView.LeftCoord; bandGcTop.BandedView.LeftCoord = bandGcBottom.BandedView.LeftCoord;
} }
} }
}
/// <summary> /// <summary>
/// 搜索条件绑定完成后 /// 搜索条件绑定完成后
/// </summary> /// </summary>
@@ -675,8 +855,14 @@ namespace Lskj.ProductiSched
{ {
LabelDateEdit labelDateEdit = baseUserControl as LabelDateEdit; LabelDateEdit labelDateEdit = baseUserControl as LabelDateEdit;
DateTime dateTime = labelDateEdit.TextEdit.DateTime; DateTime dateTime = labelDateEdit.TextEdit.DateTime;
UpdateDynamicColumns(bandGcTop, dateTime, typeDate);
UpdateDynamicColumns(bandGcBottom, dateTime, typeDate); UpdateDynamicColumns(bandGcBottom, dateTime, typeDate);
if (TreeMultiHeader)
{
UpdateDynamicColumns(treebandGcTop, dateTime, typeDate);
}
else {
UpdateDynamicColumns(bandGcTop, dateTime, typeDate);
}
} }
} }
/// <summary> /// <summary>
@@ -705,7 +891,14 @@ namespace Lskj.ProductiSched
labelDateEdit.TextEdit.DateTime = weekStart; labelDateEdit.TextEdit.DateTime = weekStart;
} }
DateTime dateTime = labelDateEdit.TextEdit.DateTime; DateTime dateTime = labelDateEdit.TextEdit.DateTime;
if (TreeMultiHeader)
{
UpdateDynamicColumns(treebandGcTop, dateTime, typeDate);
}
else
{
UpdateDynamicColumns(bandGcTop, dateTime, typeDate); UpdateDynamicColumns(bandGcTop, dateTime, typeDate);
}
UpdateDynamicColumns(bandGcBottom, dateTime, typeDate); UpdateDynamicColumns(bandGcBottom, dateTime, typeDate);
DataTable dataMain = bandGcTop.GridControl.DataSourceTable().Copy(); DataTable dataMain = bandGcTop.GridControl.DataSourceTable().Copy();
DataTable dataDetail = bandGcTop.GridControl.DataSourceTable().Copy(); DataTable dataDetail = bandGcTop.GridControl.DataSourceTable().Copy();
@@ -798,7 +991,7 @@ namespace Lskj.ProductiSched
} }
foreach (GridBand gridBand in bandedGridControlEx.BandedView.Bands) 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++) for (int i = 0; i < 93; i++)
{ {
@@ -829,7 +1022,7 @@ namespace Lskj.ProductiSched
gridColumn.Visible = false; gridColumn.Visible = false;
if (bandedGridControlEx == bandGcTop) if (bandedGridControlEx == bandGcTop)
{ {
gridColumn.SummaryItem.SummaryType = SummaryItemType.Sum; gridColumn.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
gridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}"; gridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}";
} }
gridBand.Columns.Add(gridColumn); gridBand.Columns.Add(gridColumn);
@@ -864,12 +1057,178 @@ namespace Lskj.ProductiSched
gridColumn.Visible = false; gridColumn.Visible = false;
if (bandedGridControlEx == bandGcTop) if (bandedGridControlEx == bandGcTop)
{ {
gridColumn.SummaryItem.SummaryType = SummaryItemType.Sum; gridColumn.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
gridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}"; gridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}";
} }
gridBand.Columns.Add(gridColumn); 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 #region
/// <summary> /// <summary>
/// 构建带日期或周期 /// 构建带日期或周期
@@ -896,6 +1255,28 @@ namespace Lskj.ProductiSched
bandedGridControlEx.BandedView.EndUpdate(); 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>
/// 按照周结构生成列 /// 按照周结构生成列
/// </summary> /// </summary>
@@ -929,10 +1310,8 @@ namespace Lskj.ProductiSched
// 设置列的宽度 // 设置列的宽度
weekColumn.Width = 140; weekColumn.Width = 140;
// 设置该列的Tag为周的开始日期(便于后续操作) // 设置该列的Tag为周的开始日期(便于后续操作)
weekColumn.Tag = weekStart; DataModel.columnDateMapping[weekColumn] = weekStart;
// 设置是否允许编辑 // 设置是否允许编辑
if (weekEnd >= DateTime.Today) 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> /// <summary>
/// 获取给定日期所在周的开始日期(周一)。 /// 获取给定日期所在周的开始日期(周一)。
@@ -1032,7 +1466,8 @@ namespace Lskj.ProductiSched
gridColumn.FieldName = dateForColumn.ToString("yyyy-MM-dd"); gridColumn.FieldName = dateForColumn.ToString("yyyy-MM-dd");
gridColumn.Caption = GetChineseWeekDayNumber(dateForColumn); gridColumn.Caption = GetChineseWeekDayNumber(dateForColumn);
gridColumn.Width = 70; gridColumn.Width = 70;
gridColumn.Tag = dateForColumn; // 新优化方式(使用字典存储)
DataModel.columnDateMapping[gridColumn] = dateForColumn;
if (grid == bandGcTop) if (grid == bandGcTop)
{ {
if (dateForColumn.Date < DateTime.Now.Date) 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 #endregion
@@ -1371,6 +1876,14 @@ namespace Lskj.ProductiSched
{ {
e.Appearance.TextOptions.HAlignment = HorzAlignment.Center; 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>
/// 表头颜色设置 /// 表头颜色设置
/// </summary> /// </summary>
@@ -1379,13 +1892,15 @@ namespace Lskj.ProductiSched
private void OnCustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e) private void OnCustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
{ {
// 判断列的Tag是否为 DateTime // 判断列的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("第")) if (e.Column.Caption.StartsWith("第"))
{ {
return; // 跳过周列 return; // 跳过周列
} }
DateTime dateTime;
if (DataModel.columnDateMapping.TryGetValue(e.Column, out dateTime))
{
// 判断日期是否为周末(星期六或星期日) // 判断日期是否为周末(星期六或星期日)
if (dateTime.DayOfWeek == DayOfWeek.Saturday || dateTime.DayOfWeek == DayOfWeek.Sunday) if (dateTime.DayOfWeek == DayOfWeek.Saturday || dateTime.DayOfWeek == DayOfWeek.Sunday)
@@ -1395,7 +1910,33 @@ namespace Lskj.ProductiSched
} }
} }
} }
}
/// <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>
/// 按键点击事件 /// 按键点击事件
/// </summary> /// </summary>
@@ -1422,14 +1963,21 @@ namespace Lskj.ProductiSched
{ {
foreach (GridCell gridCell in SelectCells) foreach (GridCell gridCell in SelectCells)
{ {
if (gridCell.Column.Tag != null && gridCell.Column.Tag is DateTime dateTime) // 判断列的Tag是否为 DateTime
if (gridCell.Column != null)
{ {
DateTime dateTime;
if (DataModel.columnDateMapping.TryGetValue(gridCell.Column, out dateTime))
{
// 判断日期是否为周末(星期六或星期日)
if (dateTime.Date >= DateTime.Now.Date) if (dateTime.Date >= DateTime.Now.Date)
{ {
bandedGridView.SetRowCellValue(gridCell.RowHandle, gridCell.Column, obj); bandedGridView.SetRowCellValue(gridCell.RowHandle, gridCell.Column, obj);
} }
} }
} }
}
bandedGridView.PostEditor(); bandedGridView.PostEditor();
e.Handled = true; e.Handled = true;
} }
@@ -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>
/// 构建下方数据 /// 构建下方数据
/// </summary> /// </summary>
@@ -1496,28 +2084,4 @@ namespace Lskj.ProductiSched
decimal coefficient = kvp.Value.Coefficient; decimal coefficient = kvp.Value.Coefficient;
List<string> keyValues = kvp.Value.KeyValues; 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> <HintPath>C:\Program Files (x86)\DevExpress 15.2\Components\Bin\Framework\DevExpress.XtraEditors.v15.2.dll</HintPath>
</Reference> </Reference>
<Reference Include="DevExpress.XtraGrid.v15.2, Version=15.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" /> <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"> <Reference Include="Lskj.Core, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Debug\Lskj.Core.dll</HintPath> <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 Lskj.Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -8,4 +9,7 @@ using System.Text;
namespace Lskj.ProductiSched namespace Lskj.ProductiSched
{ {
public class P public class ProductDataModel
{
// 在你的类内部定义此字典(一次定义,长期复用)
public Dictionary<object, DateTime> columnDateMapping = new Dictionar