SVN-Revision: r305
This commit is contained in:
tdx
2025-03-07 09:59:41 +00:00
parent 4d3cf3affc
commit e5c3dd9c75
2 changed files with 486 additions and 54 deletions
+15 -39
View File
@@ -35,13 +35,11 @@ namespace Lskj.ProductiSched
this.bandGcTop = new Lskj.Control.BandedGridControlEx(); this.bandGcTop = new Lskj.Control.BandedGridControlEx();
this.bandGcBottom = new Lskj.Control.BandedGridControlEx(); this.bandGcBottom = new Lskj.Control.BandedGridControlEx();
this.pl_mainSearch = new DevExpress.XtraEditors.PanelControl(); this.pl_mainSearch = new DevExpress.XtraEditors.PanelControl();
this.pl_flowRightBtn = new System.Windows.Forms.FlowLayoutPanel();
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.btnColse = new DevExpress.XtraEditors.SimpleButton();
this.btnSave = new DevExpress.XtraEditors.SimpleButton();
this.gcRight = new Lskj.Control.GridControlEx(); this.gcRight = new Lskj.Control.GridControlEx();
this.pl_left = new DevExpress.XtraEditors.PanelControl(); this.pl_left = new DevExpress.XtraEditors.PanelControl();
this.btnSave = new DevExpress.XtraEditors.SimpleButton();
((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();
@@ -128,7 +126,6 @@ namespace Lskj.ProductiSched
this.pl_mainSearch.Appearance.BackColor = System.Drawing.Color.Transparent; this.pl_mainSearch.Appearance.BackColor = System.Drawing.Color.Transparent;
this.pl_mainSearch.Appearance.Options.UseBackColor = true; this.pl_mainSearch.Appearance.Options.UseBackColor = true;
this.pl_mainSearch.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder; this.pl_mainSearch.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
this.pl_mainSearch.Controls.Add(this.pl_flowRightBtn);
this.pl_mainSearch.Controls.Add(this.pl_search); this.pl_mainSearch.Controls.Add(this.pl_search);
this.pl_mainSearch.Controls.Add(this.flowLayoutPanel); this.pl_mainSearch.Controls.Add(this.flowLayoutPanel);
this.pl_mainSearch.Dock = System.Windows.Forms.DockStyle.Top; this.pl_mainSearch.Dock = System.Windows.Forms.DockStyle.Top;
@@ -138,15 +135,6 @@ namespace Lskj.ProductiSched
this.pl_mainSearch.Size = new System.Drawing.Size(997, 33); this.pl_mainSearch.Size = new System.Drawing.Size(997, 33);
this.pl_mainSearch.TabIndex = 11; this.pl_mainSearch.TabIndex = 11;
// //
// pl_flowRightBtn
//
this.pl_flowRightBtn.Dock = System.Windows.Forms.DockStyle.Left;
this.pl_flowRightBtn.Location = new System.Drawing.Point(221, 0);
this.pl_flowRightBtn.Name = "pl_flowRightBtn";
this.pl_flowRightBtn.Size = new System.Drawing.Size(340, 33);
this.pl_flowRightBtn.TabIndex = 15;
this.pl_flowRightBtn.WrapContents = false;
//
// pl_search // pl_search
// //
this.pl_search.Appearance.BackColor = System.Drawing.Color.Transparent; this.pl_search.Appearance.BackColor = System.Drawing.Color.Transparent;
@@ -161,36 +149,15 @@ namespace Lskj.ProductiSched
// //
// flowLayoutPanel // flowLayoutPanel
// //
this.flowLayoutPanel.Controls.Add(this.btnColse);
this.flowLayoutPanel.Controls.Add(this.btnSave); this.flowLayoutPanel.Controls.Add(this.btnSave);
this.flowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Right; this.flowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Right;
this.flowLayoutPanel.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft; this.flowLayoutPanel.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft;
this.flowLayoutPanel.Location = new System.Drawing.Point(859, 0); this.flowLayoutPanel.Location = new System.Drawing.Point(825, 0);
this.flowLayoutPanel.Name = "flowLayoutPanel"; this.flowLayoutPanel.Name = "flowLayoutPanel";
this.flowLayoutPanel.Size = new System.Drawing.Size(138, 33); this.flowLayoutPanel.Size = new System.Drawing.Size(172, 33);
this.flowLayoutPanel.TabIndex = 13; this.flowLayoutPanel.TabIndex = 13;
this.flowLayoutPanel.WrapContents = false; this.flowLayoutPanel.WrapContents = false;
// //
// btnColse
//
this.btnColse.Appearance.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnColse.Appearance.Options.UseFont = true;
this.btnColse.Location = new System.Drawing.Point(81, 3);
this.btnColse.Name = "btnColse";
this.btnColse.Size = new System.Drawing.Size(54, 24);
this.btnColse.TabIndex = 48;
this.btnColse.Text = "关闭";
//
// btnSave
//
this.btnSave.Appearance.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnSave.Appearance.Options.UseFont = true;
this.btnSave.Location = new System.Drawing.Point(25, 3);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(50, 24);
this.btnSave.TabIndex = 47;
this.btnSave.Text = "保存";
//
// gcRight // gcRight
// //
this.gcRight.AdapterObj = null; this.gcRight.AdapterObj = null;
@@ -214,6 +181,17 @@ namespace Lskj.ProductiSched
this.pl_left.Size = new System.Drawing.Size(315, 38); this.pl_left.Size = new System.Drawing.Size(315, 38);
this.pl_left.TabIndex = 10; this.pl_left.TabIndex = 10;
// //
// btnSave
//
this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnSave.Appearance.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnSave.Appearance.Options.UseFont = true;
this.btnSave.Location = new System.Drawing.Point(97, 3);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(72, 26);
this.btnSave.TabIndex = 40;
this.btnSave.Text = "保存(&S)";
//
// FrmProductSched // FrmProductSched
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
@@ -228,6 +206,4 @@ namespace Lskj.ProductiSched
((System.ComponentModel.ISupportInitialize)(this.splitLeftControl)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.splitLeftControl)).EndInit();
this.splitLeftControl.ResumeLayout(false); this.splitLeftControl.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pl_mainSearch)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pl_mainSearch)).EndInit();
this.pl_mainSearch.ResumeLayout(false); this.pl_mainSearch.ResumeLayout(fals
((System.ComponentModel.ISupportInitialize)(this.pl_search)).EndInit();
this.flowLayoutPanel.ResumeLayou
+471 -15
View File
@@ -3,9 +3,12 @@ using DevExpress.Utils;
using DevExpress.XtraGrid; using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.BandedGrid; using DevExpress.XtraGrid.Views.BandedGrid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using Lskj.Business.Impl; using Lskj.Business.Impl;
using Lskj.Control; using Lskj.Control;
using Lskj.Control.Model; using Lskj.Control.Model;
using Lskj.Data;
using Lskj.Model; using Lskj.Model;
using Lskj.ProductSched; using Lskj.ProductSched;
using Lskj.Util; using Lskj.Util;
@@ -14,9 +17,12 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Data.SqlClient;
using System.Drawing; using System.Drawing;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@@ -49,6 +55,7 @@ namespace Lskj.ProductiSched
DataModel.TopSysModel = mainModel; DataModel.TopSysModel = mainModel;
DataRow topSysRow = MainImpl.GetSystemdllTab(DataModel.TopSysModel.ModuleCode); DataRow topSysRow = MainImpl.GetSystemdllTab(DataModel.TopSysModel.ModuleCode);
DataModel.TopModuleModel = new ModuleModel(topSysRow); DataModel.TopModuleModel = new ModuleModel(topSysRow);
DataModel.TopModuleModel.ParmaryKey = BaseImpl.GetBasePrimaryKey(DataModel.TopSysModel.ModuleCode);
DataModel.TopGridColumns = BaseModuleImpl.GetBaseGridColumns(DataModel.TopSysModel.ModuleCode); DataModel.TopGridColumns = BaseModuleImpl.GetBaseGridColumns(DataModel.TopSysModel.ModuleCode);
DataModel.TopRightMenus = BaseModuleImpl.GetBaseGridRightMenus(DataModel.TopModuleModel.FormKey); DataModel.TopRightMenus = BaseModuleImpl.GetBaseGridRightMenus(DataModel.TopModuleModel.FormKey);
DataModel.TopRowColors = BaseModuleImpl.GetBaseGridRowColors(DataModel.TopModuleModel.FormKey); DataModel.TopRowColors = BaseModuleImpl.GetBaseGridRowColors(DataModel.TopModuleModel.FormKey);
@@ -124,6 +131,7 @@ namespace Lskj.ProductiSched
bandedGridColumn.OptionsColumn.AllowSize = false; bandedGridColumn.OptionsColumn.AllowSize = false;
} }
} }
bandGcBottom.BandedView.OptionsBehavior.Editable = false;
OnBandedViewColumnWidthChanged(bandGcTop.BandedView, null); OnBandedViewColumnWidthChanged(bandGcTop.BandedView, null);
} }
//右侧表格 //右侧表格
@@ -149,6 +157,292 @@ namespace Lskj.ProductiSched
bandGcTop.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged; bandGcTop.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged;
bandGcBottom.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged; bandGcBottom.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged;
bandGcTop.BandedView.FocusedRowObjectChanged += OnBandedTopFocusedRowObjectChanged; bandGcTop.BandedView.FocusedRowObjectChanged += OnBandedTopFocusedRowObjectChanged;
bandGcTop.BandedView.KeyDown += OnBandedViewKeyDown;
bandGcTop.BandedView.CustomDrawFooterCell += OnCustomDrawFooterCell;
bandGcTop.BandedView.CustomDrawColumnHeader += OnCustomDrawColumnHeader;
bandGcBottom.BandedView.CustomDrawColumnHeader += OnCustomDrawColumnHeader;
btnSave.Click += OnBtnSaveClick;
}
/// <summary>
/// 保存按钮点击时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnBtnSaveClick(object sender, EventArgs e)
{
if (SaveGridRecord())
{
if (SaveDatePlanRecord())
{
DataModel.TopSearchObj.ButtonObj.PerformClick();
}
}
}
/// <summary>
/// 保存主表数据
/// </summary>
/// <param name="isErrorTips"></param>
public bool SaveGridRecord()
{
string tableName = DataModel.TopModuleModel.MenuTable;
string Autogrowcolumn = BaseImpl.GetResult(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", tableName)) + "";
DataTable DatabasePropertySheet = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", tableName));//数据库属性表
string SaveErrorMessage = "失败列表:\r\n";
if (string.IsNullOrEmpty(tableName))
{
MessageUtil.Show(ResourceKeys.MenuTableNameIsNull);
return false;
}
List<BaseSaveModel> mList = new List<BaseSaveModel>();
DataRow[] modifiedRows = (bandGcTop.BandedView.GridControl.DataSource as DataTable)
.Rows
.Cast<DataRow>()
.Where(x => x.RowState == DataRowState.Modified || x.RowState == DataRowState.Added)
.ToArray();
if (modifiedRows == null || modifiedRows.Length == 0)
{
MessageUtil.Show(ResourceKeys.UnUpdateData);
return false;
}
else
{
DataColumnCollection columns = BaseImpl.GetTableColumns(tableName).Columns;
foreach (DataRow row in modifiedRows)
{
string updateSql = "update {0} set {1} where {2}='{3}';";
string insertSql = "insert into {0}({1}) values({2});";
string updateFields = string.Empty;
string insertFields = string.Empty;
string insertValues = string.Empty;
BaseSaveModel model = new BaseSaveModel()
{
MenuCode = DataModel.TopSysModel.ModuleCode,
TableName = tableName,
KeyField = DataModel.TopModuleModel.ParmaryKey,
NewVer = DataModel.TopModuleModel.NewVer
};
foreach (DataColumn col in columns)
{
// 区分大小写匹配列
DataRow hasContainRow = DataModel.TopGridColumns.Rows.Cast<DataRow>().FirstOrDefault(x => (x["fieldname"] + "").ToLower() == col.ColumnName.ToLower());
if (hasContainRow != null && col.ColumnName != DataModel.TopModuleModel.ParmaryKey && !col.ColumnName.Equals("id") && Autogrowcolumn.ToLower() != col.ColumnName.ToLower())
{
if (row.RowState == DataRowState.Modified && string.IsNullOrEmpty(DataModel.TopModuleModel.CustomColumnSQL))
{
string newValue = row[col.ColumnName, DataRowVersion.Current] + "";
string oldValue = row[col.ColumnName, DataRowVersion.Original] + "";
//如果是修改状态,没有改变的值就不拼接,以免造成多人同时修改同一行不同列的值混乱情况
if (oldValue != newValue)
{
if ((col.DataType == typeof(DateTime)) && (row[col.ColumnName] + "" == ""))
{
updateFields += string.Format("[{0}]=null,", col.ColumnName);
}
else
{
if (col.DataType == typeof(Decimal) && string.IsNullOrWhiteSpace((row[col.ColumnName] + "").Replace("'", "''")))
{
updateFields += string.Format("[{0}]='{1}',", col.ColumnName, 0);
}
else
{
updateFields += string.Format("[{0}]=N'{1}',", col.ColumnName, (row[col.ColumnName] + "").Replace("'", "''"));
}
}
}
}
else if (row.RowState == DataRowState.Added || (row.RowState == DataRowState.Modified && !string.IsNullOrEmpty(DataModel.TopModuleModel.CustomColumnSQL)))
{
// 动态生成列,保存时默认全部为新增
string fieldValue = (row[col.ColumnName] + "").Replace("'", "''");
insertFields += "[" + col.ColumnName + "],";
if (!string.IsNullOrWhiteSpace(fieldValue))
{
insertValues += col.DataType == typeof(DateTime) ? "'" + Convert.ToDateTime(fieldValue).ToString("yyyy-MM-dd HH:mm:ss") + "'," : "N'" + fieldValue + "',";
}
else
{
if (col.DataType == typeof(Decimal) || col.DataType == typeof(Int32))
insertValues += "0,";
else if (col.DataType == typeof(DateTime))
insertValues += "NULL,";
else
insertValues += "'',";
}
}
SaveErrorMessage = SaveErrorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DataModel.TopGridColumns, DatabasePropertySheet, row, col, (row[col.ColumnName] + "").Replace("'", "''"));
}
}
// 检查是否保存主键字段
if (row.RowState == DataRowState.Added && !insertFields.Contains(DataModel.TopModuleModel.ParmaryKey) && !"ID".Equals(DataModel.TopModuleModel.ParmaryKey, StringComparison.OrdinalIgnoreCase))
{
// 跳过自动增长列处理
if (Autogrowcolumn.ToLower() != DataModel.TopModuleModel.ParmaryKey.ToLower())
{
insertFields += DataModel.TopModuleModel.ParmaryKey + ",";
insertValues += "N'" + row[DataModel.TopModuleModel.ParmaryKey] + "',";
}
}
updateFields = updateFields.TrimEnd(',');
insertFields = insertFields.TrimEnd(',');
insertValues = insertValues.TrimEnd(',');
if (!string.IsNullOrEmpty(updateFields))
{
model.FieldValue = row[DataModel.TopModuleModel.ParmaryKey] + "";
model.BaseSaveType = SaveType.Update;
model.BaseSql = string.Format(updateSql, tableName, updateFields, DataModel.TopModuleModel.ParmaryKey, row[DataModel.TopModuleModel.ParmaryKey]);
}
if (!string.IsNullOrEmpty(insertFields))
{
model.BaseSaveType = SaveType.Add;
model.FieldValue = row[DataModel.TopModuleModel.ParmaryKey] + "";
model.BaseSql = string.Format(insertSql, tableName, insertFields, insertValues);
}
if (!string.IsNullOrWhiteSpace(model.BaseSql)) mList.Add(model);
}
try
{
if (mList.Count == 0)
{
return true;
}
string retuenMsg = "";
string apiRetMsg = "";
// 批量保存数据
if (BaseModuleImpl.SaveBaseGridData(mList, out retuenMsg, out apiRetMsg))
{
return true;
}
else
{
StringBuilder builder = new StringBuilder();
builder.Append("失败列表\r\n");
foreach (BaseSaveModel item in mList)
{
if (!string.IsNullOrEmpty(item.FaultMsg))
SaveErrorMessage += item.FaultMsg + "\r\n";
}
LogHelper.Instance.WriteLog(builder.ToString());
MessageUtil.Show(SaveErrorMessage);
return false;
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
return false;
}
}
}
/// <summary>
/// 保存日期数据
/// </summary>
private bool SaveDatePlanRecord()
{
// 获取主数据源,假设已绑定到 gridControl1
DataTable mainDataSource = bandGcTop.BandedView.GridControl.DataSourceTable();
if (mainDataSource == null)
{
return true;
}
// 当前操作用户(例如从全局获取)
string currentUser = ERPInfo.Instance.UserName;
DataTable tvp = new DataTable();
tvp.Columns.Add("billdocument_id", typeof(string));
tvp.Columns.Add("showday", typeof(string));
tvp.Columns.Add("amount", typeof(decimal));
tvp.Columns.Add("operatorname", typeof(string));
// 遍历主数据源所有行,仅处理已修改行
foreach (DataRow row in mainDataSource.Rows)
{
if (row.RowState == DataRowState.Modified)
{
// 获取关联的 keyvalue(用于匹配 mps_dayplantab.billdocument_id
string key = row["keyvalue"].ToString();
// 遍历每个列,处理虚拟列(列名格式必须为 "yyyy-MM-dd"
foreach (DataColumn col in mainDataSource.Columns)
{
// 忽略固定字段
if (col.ColumnName == "ID" || col.ColumnName == "keyvalue" || col.ColumnName == "Name")
continue;
// 仅处理列名符合完整日期格式的虚拟列
if (!Regex.IsMatch(col.ColumnName, @"^\d{4}-\d{2}-\d{2}$"))
continue;
// 比较原始值和当前值
object originalValue = row[col, DataRowVersion.Original];
object currentValue = row[col, DataRowVersion.Current];
if (!object.Equals(originalValue, currentValue))
{
decimal newAmount = 0m;
if (row[col] != DBNull.Value && !string.IsNullOrWhiteSpace(row[col].ToString()))
{
decimal.TryParse(row[col].ToString(), out newAmount);
}
DataRow dr = tvp.NewRow();
dr["billdocument_id"] = key;
dr["showday"] = col.ColumnName; // 列名如 "2025-03-06"
dr["amount"] = newAmount;
dr["operatorname"] = currentUser;
tvp.Rows.Add(dr);
}
}
}
}
if (tvp.Rows.Count == 0)
{
return true;
}
// 调用存储过程保存变更数据
string msg;
int ret = SaveDayPlanChanges(tvp, out msg);
if (ret == 1)
{
MessageUtil.Show("保存成功:" + msg);
return true;
}
else
{
MessageUtil.Show("保存失败:" + msg);
return false;
}
}
/// <summary>
/// 保存日计划变更数据(批量保存)。
/// 调用存储过程 usp_MergeDayPlanChanges,将所有变更记录一次性提交到数据库。
/// 通过 TVP 参数传递数据,同时捕获输出参数 @msg 和返回值。
/// </summary>
/// <param name="tvp">包含所有变更记录的 DataTable,必须与 dbo.DayPlanChangeType 定义一致</param>
/// <param name="message">输出提示信息,存储过程执行后的返回消息</param>
/// <returns>存储过程返回值,成功返回 1,失败返回 0</returns>
public int SaveDayPlanChanges(DataTable tvp, out string message)
{
// 创建输出参数 @msg
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000)
{
Direction = ParameterDirection.Output
};
// 创建返回值参数 @return
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int)
{
Direction = ParameterDirection.ReturnValue
};
// 创建 TVP 参数,名称必须与存储过程参数一致
SqlParameter tvpParam = new SqlParameter("@DayPlanChanges", SqlDbType.Structured)
{
TypeName = "dbo.DayPlanChangeType",
Value = tvp
};
// 构造参数数组
SqlParameter[] parameters = new SqlParameter[] { tvpParam, pMsg, returnValue };
// 执行存储过程,此处调用 ExecuteNonQuery 即可,不需要返回数据集
// 请确保 DBUtil.ExecuteNonQuery 方法能够传递参数并执行存储过程
BaseImpl.ExecProcedure("usp_MergeDayPlanChanges", parameters);
// 获取输出参数 @msg 中的提示信息
message = pMsg.Value.ToString();
// 获取存储过程的返回值
int result = Convert.ToInt32(returnValue.Value);
return result;
} }
/// <summary> /// <summary>
/// 选中行改变时 /// 选中行改变时
@@ -280,11 +574,16 @@ namespace Lskj.ProductiSched
DateTime dateTime = labelDateEdit.TextEdit.DateTime; DateTime dateTime = labelDateEdit.TextEdit.DateTime;
UpdateDynamicColumns(bandGcTop, dateTime); UpdateDynamicColumns(bandGcTop, dateTime);
UpdateDynamicColumns(bandGcBottom, dateTime); UpdateDynamicColumns(bandGcBottom, dateTime);
DataTable dataMain = bandGcTop.GridControl.DataSourceTable(); DataTable dataMain = bandGcTop.GridControl.DataSourceTable().Copy();
DataTable dataDetail = bandGcTop.GridControl.DataSourceTable().Copy();
bandGcTop.GridControl.DataSource = null;
string sqlValue = DataModel.RightModuleModel.MenuSql; string sqlValue = DataModel.RightModuleModel.MenuSql;
sqlValue = $"{ReplaceHelper.ReplaceWhereCond(sqlValue)} and day >= '{dateTime.ToString("yyyy-MM-dd")}'"; sqlValue = $"{ReplaceHelper.ReplaceWhereCond(sqlValue)} and day >= '{dateTime.ToString("yyyy-MM-dd")}'";
DataTable dataDayPlan = BaseImpl.GetDataTableResult(sqlValue); DataTable dataDayPlan = BaseImpl.GetDataTableResult(sqlValue);
MergeMainDataWithDayPlan(dataMain, dataDayPlan, dateTime); MergeMainDataWithDayPlan(dataMain, dataDayPlan, dateTime);
bandGcTop.BandedView.GridControl.DataSource = dataMain;
DataTable bottomTab = BuildCTable(dataDetail, dataDayPlan, dateTime, 93);
bandGcBottom.BandedView.GridControl.DataSource = bottomTab;
} }
} }
/// <summary> /// <summary>
@@ -356,8 +655,13 @@ namespace Lskj.ProductiSched
BandedGridColumn gridColumn = new BandedGridColumn(); BandedGridColumn gridColumn = new BandedGridColumn();
gridColumn.AppearanceCell.Options.UseTextOptions = true; gridColumn.AppearanceCell.Options.UseTextOptions = true;
gridColumn.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center; gridColumn.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
gridColumn.AppearanceHeader.Options.UseTextOptions = true;
gridColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
gridColumn.OptionsColumn.AllowMove = false; gridColumn.OptionsColumn.AllowMove = false;
gridColumn.OptionsColumn.AllowSize = false; gridColumn.OptionsColumn.AllowSize = false;
gridColumn.OptionsFilter.AllowFilter = false;
gridColumn.OptionsColumn.AllowMerge = DefaultBoolean.False;
gridColumn.OptionsColumn.AllowSort = DefaultBoolean.False;
gridColumn.FieldName = $"DDay_{i}"; gridColumn.FieldName = $"DDay_{i}";
gridColumn.Width = 70; gridColumn.Width = 70;
gridColumn.DisplayFormat.FormatType = FormatType.Numeric; gridColumn.DisplayFormat.FormatType = FormatType.Numeric;
@@ -365,10 +669,8 @@ namespace Lskj.ProductiSched
gridColumn.Visible = false; gridColumn.Visible = false;
if (bandedGridControlEx == bandGcTop) if (bandedGridControlEx == bandGcTop)
{ {
GridColumnSummaryItem gridColumnSummaryItem = gridColumn.Summary.Add(); gridColumn.SummaryItem.SummaryType = SummaryItemType.Sum;
gridColumnSummaryItem.FieldName = gridColumn.FieldName; gridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}";
gridColumnSummaryItem.DisplayFormat = "{0:#,##0.####}";
gridColumnSummaryItem.SummaryType = SummaryItemType.Sum;
} }
gridBand.Columns.Add(gridColumn); gridBand.Columns.Add(gridColumn);
} }
@@ -403,14 +705,23 @@ namespace Lskj.ProductiSched
DateTime dateForColumn = currentDate.AddDays(i); DateTime dateForColumn = currentDate.AddDays(i);
if (dateForColumn <= endDate) if (dateForColumn <= endDate)
{ {
gridBand.Caption = dateForColumn.ToString("MM-dd");
gridBand.Visible = true; gridBand.Visible = true;
gridColumn.Visible = true; gridColumn.FieldName = dateForColumn.ToString("yyyy-MM-dd");
// 父列标题:上行为日期(MM-dd),下行为中文星期(完整格式)
string bandCaption = dateForColumn.ToString("MM-dd");
gridBand.Caption = bandCaption;
// 子列标题只显示中文星期数字,例如:如果是周三,则显示“3”对应的“三”
gridColumn.Caption = GetChineseWeekDayNumber(dateForColumn); gridColumn.Caption = GetChineseWeekDayNumber(dateForColumn);
gridColumn.FieldName = bandCaption; gridColumn.Tag = dateForColumn;
if (bandedGridControlEx == bandGcTop)
{
if (dateForColumn.Date < DateTime.Now.Date)
{
gridColumn.OptionsColumn.AllowEdit = false;
}
else
{
gridColumn.OptionsColumn.AllowEdit = true;
}
}
gridColumn.Visible = true;
} }
else else
{ {
@@ -448,7 +759,7 @@ namespace Lskj.ProductiSched
// **2. 预构建主数据的列** // **2. 预构建主数据的列**
for (DateTime dt = startDate; dt <= endDate; dt = dt.AddDays(1)) for (DateTime dt = startDate; dt <= endDate; dt = dt.AddDays(1))
{ {
string colName = dt.ToString("MM-dd"); string colName = dt.ToString("yyyy-MM-dd");
if (!dataMain.Columns.Contains(colName)) if (!dataMain.Columns.Contains(colName))
{ {
dataMain.Columns.Add(colName, typeof(decimal)); // 确保列存在 dataMain.Columns.Add(colName, typeof(decimal)); // 确保列存在
@@ -471,8 +782,7 @@ namespace Lskj.ProductiSched
if (dayRow["day"] != DBNull.Value) if (dayRow["day"] != DBNull.Value)
{ {
DateTime dayValue = Convert.ToDateTime(dayRow["day"]); DateTime dayValue = Convert.ToDateTime(dayRow["day"]);
string colName = dayValue.ToString("MM-dd"); string colName = dayValue.ToString("yyyy-MM-dd");
if (dayValue >= startDate && dayValue <= endDate && dataMain.Columns.Contains(colName)) if (dayValue >= startDate && dayValue <= endDate && dataMain.Columns.Contains(colName))
{ {
dataMap[key][colName] = Convert.ToDecimal(dayRow["amount"]); dataMap[key][colName] = Convert.ToDecimal(dayRow["amount"]);
@@ -529,4 +839,150 @@ namespace Lskj.ProductiSched
string splitMainWidth = IniHelper.Read(string.Format("ProductSched_SplitMain_{0}", DataModel.TopSysModel.ModuleCode)); string splitMainWidth = IniHelper.Read(string.Format("ProductSched_SplitMain_{0}", DataModel.TopSysModel.ModuleCode));
if (!string.IsNullOrEmpty(splitMainWidth)) if (!string.IsNullOrEmpty(splitMainWidth))
{ {
splitMainControl.SplitterPosition = Convert.To splitMainControl.SplitterPosition = Convert.ToInt32(splitMainWidth);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
/// <summary>
/// 分隔条位置改变时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnSplitContainerPositionChanged(object sender, EventArgs e)
{
try
{
if (DataModel.TopSysModel != null)
{
IniHelper.Write(string.Format("ProductSched_SplitLeft_{0}", DataModel.TopSysModel.ModuleCode), splitLeftControl.SplitterPosition + "");
IniHelper.Write(string.Format("ProductSched_SplitMain_{0}", DataModel.TopSysModel.ModuleCode), splitMainControl.SplitterPosition + "");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
/// <summary>
/// 合计显示居中设置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnCustomDrawFooterCell(object sender, FooterCellCustomDrawEventArgs e)
{
e.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
}
/// <summary>
/// 表头颜色设置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnCustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
{
if (e.Column != null && e.Column.Tag != null && e.Column.Tag is DateTime dateTime)
{
if (dateTime.DayOfWeek == DayOfWeek.Saturday || dateTime.DayOfWeek == DayOfWeek.Sunday)
{
e.Appearance.ForeColor = Color.Red;
}
}
}
/// <summary>
/// 按键点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnBandedViewKeyDown(object sender, KeyEventArgs e)
{
BandedGridView bandedGridView = (BandedGridView)sender;
if (e.KeyCode == Keys.F7)
{
GridColumn column = bandedGridView.FocusedColumn;
GridColumnModel model = column.Tag as GridColumnModel;
if (column != null && column.OptionsColumn.AllowEdit && bandedGridView.RowCount > 0 && bandedGridView.OptionsBehavior.Editable)
{
// 允许操作
GridCell[] SelectCells = bandedGridView.GetSelectedCells();
if (SelectCells.Length > 0)
{
object obj = bandedGridView.GetRowCellValue(SelectCells[0].RowHandle, SelectCells[0].Column);
if (MessageUtil.Show("是否替换所选单元格值?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
WaitForm.ShowForm("数据填充中");
if (obj != null)
{
foreach (GridCell gridCell in SelectCells)
{
bandedGridView.SetRowCellValue(gridCell.RowHandle, gridCell.Column, obj);
}
bandedGridView.PostEditor();
e.Handled = true;
}
WaitForm.HideForm();
}
}
}
}
}
/// <summary>
/// 构建下方数据
/// </summary>
/// <param name="dtA"></param>
/// <param name="dtPlan"></param>
/// <param name="startDate"></param>
/// <param name="daysCount"></param>
/// <returns></returns>
public DataTable BuildCTable(DataTable dtA, DataTable dtPlan, DateTime startDate, int daysCount)
{
try
{
// 1. 按“产地”分组
// key: 产地; value: Tuple(总产能, 系数, keyvalue集合)
var groupDict = dtA.AsEnumerable()
.GroupBy(r => r.Field<string>("产地"))
.ToDictionary(
g => g.Key,
g => new
{
TotalCapacity = g.First().Field<decimal>("总产能"),
Coefficient = g.First().Field<decimal>("系数"),
KeyValues = g.Select(r => r.Field<string>("keyvalue")).Distinct().ToList()
}
);
// 2. 构建 C 表结构:固定字段“产地”、“产能”,以及动态日期列(格式 "yyyy-MM-dd"
DataTable dtC = new DataTable();
dtC.Columns.Add("产地", typeof(string));
dtC.Columns.Add("总产能", typeof(decimal));
List<string> dateColumns = new List<string>();
for (int i = 0; i < daysCount; i++)
{
DateTime d = startDate.AddDays(i);
string colName = d.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
dtC.Columns.Add(colName, typeof(decimal));
dateColumns.Add(colName);
}
// 3. 预处理 dtPlan:转换 day 字段为 "yyyy-MM-dd" 字符串,方便后续匹配
var planRows = dtPlan.AsEnumerable()
.Select(r => new
{
BillId = r.Field<string>("billdocument_id"),
ShowDay = r.Field<DateTime>("day").ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
Amount = r.Field<decimal>("amount")
})
.ToList();
// 4. 遍历每个分组,构造 C 表行数据
foreach (var kvp in groupDict)
{
string origin = kvp.Key;
decimal totalCapacity = kvp.Value.TotalCapacity;
decimal coefficient = kvp.Value.Coefficient;
List<string> keyValues = kvp.Value.KeyValues;