SVN r329
SVN-Revision: r329
This commit is contained in:
@@ -4389,10 +4389,61 @@ namespace Lskj.PubBill
|
||||
bool saveResult = false;
|
||||
if (this.ControlObj.VerifyNull())
|
||||
{
|
||||
//若存在分配则优先保存数据
|
||||
DataTable tvp = new DataTable();//虚构一个保存存储过程
|
||||
//更新前进行数据源筛选
|
||||
if (DateColumnList.Count > 0)
|
||||
{
|
||||
SaveDatePlanRecord();
|
||||
// 创建临时表
|
||||
tvp.Columns.Add("lblOrderNo", typeof(string)); // 固定主键
|
||||
tvp.Columns.Add("billdocument_id", typeof(string)); // 固定主键
|
||||
tvp.Columns.Add("showday", typeof(string));
|
||||
tvp.Columns.Add("amount", typeof(decimal));
|
||||
|
||||
// 获取主数据源
|
||||
DataTable mainDataSource = gcMain.GridControl.DataSourceTable();
|
||||
|
||||
// 遍历主数据源
|
||||
foreach (DataRow row in mainDataSource.Rows)
|
||||
{
|
||||
if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Added)
|
||||
{
|
||||
// 提取 billdocument_id
|
||||
string key = row["bom_rdl_productid"].ToString();
|
||||
|
||||
// 遍历列并处理虚拟列
|
||||
foreach (DataColumn col in mainDataSource.Columns)
|
||||
{
|
||||
if (!Regex.IsMatch(col.ColumnName, @"^\d{4}-\d{2}-\d{2}$"))
|
||||
continue;
|
||||
|
||||
// 检查值是否发生变化
|
||||
bool isVerifyupd = true;
|
||||
if (row.RowState == DataRowState.Modified)
|
||||
{
|
||||
object originalValue = row[col, DataRowVersion.Original];
|
||||
object currentValue = row[col, DataRowVersion.Current];
|
||||
isVerifyupd = !object.Equals(originalValue, currentValue);
|
||||
}
|
||||
|
||||
if (isVerifyupd)
|
||||
{
|
||||
// 解析金额
|
||||
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;
|
||||
tvp.Rows.Add(dr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 保存之前先进行表格更新
|
||||
@@ -4466,8 +4517,18 @@ namespace Lskj.PubBill
|
||||
this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo)));
|
||||
saveResult = true;
|
||||
SaveRefreshSource();
|
||||
|
||||
RefreshPrindMenu();
|
||||
//保存完成后所有数据源进行拼接执行保存
|
||||
if (tvp!=null&& tvp.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dataRow in tvp.Rows)
|
||||
{
|
||||
dataRow["lblOrderNo"] = billNo;
|
||||
}
|
||||
// 调用存储过程保存变更数据
|
||||
string msg;
|
||||
int ret = SaveDayPlanChanges(tvp, out msg);
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
// 继续执行保存
|
||||
@@ -5021,77 +5082,6 @@ namespace Lskj.PubBill
|
||||
}
|
||||
}
|
||||
|
||||
private bool SaveDatePlanRecord()
|
||||
{
|
||||
// 获取主数据源,假设已绑定到 gridControl1
|
||||
DataTable mainDataSource = gcMain.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));
|
||||
// 遍历主数据源所有行,仅处理已修改行
|
||||
foreach (DataRow row in mainDataSource.Rows)
|
||||
{
|
||||
if (row.RowState == DataRowState.Modified|| row.RowState == DataRowState.Added)
|
||||
{
|
||||
// 获取关联的 keyvalue(用于匹配 mps_dayplantab.billdocument_id)
|
||||
string key = row["bom_rdl_productid"].ToString();
|
||||
// 遍历每个列,处理虚拟列(列名格式必须为 "yyyy-MM-dd")
|
||||
foreach (DataColumn col in mainDataSource.Columns)
|
||||
{
|
||||
// 忽略固定字段
|
||||
if (col.ColumnName == "ID" || col.ColumnName == "key" || col.ColumnName == "Name")
|
||||
continue;
|
||||
// 仅处理列名符合完整日期格式的虚拟列
|
||||
if (!Regex.IsMatch(col.ColumnName, @"^\d{4}-\d{2}-\d{2}$"))
|
||||
continue;
|
||||
bool isVerifyupd =true ;
|
||||
if (row.RowState == DataRowState.Modified)
|
||||
{
|
||||
// 比较原始值和当前值
|
||||
object originalValue = row[col, DataRowVersion.Original];
|
||||
object currentValue = row[col, DataRowVersion.Current];
|
||||
isVerifyupd=!object.Equals(originalValue, currentValue);
|
||||
}
|
||||
if (isVerifyupd)
|
||||
{
|
||||
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;
|
||||
tvp.Rows.Add(dr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tvp.Rows.Count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// 调用存储过程保存变更数据
|
||||
string msg;
|
||||
int ret = SaveDayPlanChanges(tvp, out msg);
|
||||
if (ret == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存日计划变更数据(批量保存)。
|
||||
/// 调用存储过程 usp_MergeDayPlanChanges,将所有变更记录一次性提交到数据库。
|
||||
|
||||
Reference in New Issue
Block a user