SVN r634
SVN-Revision: r634
This commit is contained in:
@@ -1228,6 +1228,7 @@ namespace Lskj.PubBill
|
|||||||
gridColumn.Visible = false;
|
gridColumn.Visible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -5428,80 +5429,93 @@ namespace Lskj.PubBill
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建带日期的数据源
|
/// 计划明细与主数据合并:
|
||||||
|
/// 1) 按 <paramref name="startDate"/> 起算 7 天动态生成列;
|
||||||
|
/// 2) 把 dataDayPlan 中对应日期的 amount 值填入主表;
|
||||||
|
/// 3) 计算行级合计写入 “heji” 列。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dataMain"></param>
|
private DataTable MergeMainDataWithDayPlan(
|
||||||
/// <param name="dataDayPlan"></param>
|
DataTable dataMain,
|
||||||
/// <param name="startDate"></param>
|
DataTable dataDayPlan,
|
||||||
/// <returns></returns>
|
DateTime startDate)
|
||||||
private DataTable MergeMainDataWithDayPlan(DataTable dataMain, DataTable dataDayPlan, DateTime startDate)
|
|
||||||
{
|
{
|
||||||
string rightPrimaryKey = "billdocument_id";
|
const string rightPrimaryKey = "billdocument_id"; // dataDayPlan 主键
|
||||||
string dateField = "showday";
|
const string dateField = "showday";
|
||||||
string amountField = "amount";
|
const string amountField = "amount";
|
||||||
string topPrimaryKey = BillModel.DetailUUIDKey;
|
string topPrimaryKey = BillModel.DetailUUIDKey; // dataMain 主键
|
||||||
DateTime endDate = startDate.AddDays(7); // 计算结束日期
|
|
||||||
// **1. 预索引 dataDayPlan 数据(billdocument_id -> 该 key 相关的所有行)**
|
DateTime endDate = startDate.AddDays(7);
|
||||||
Dictionary<string, List<DataRow>> dayPlanMap = new Dictionary<string, List<DataRow>>();
|
|
||||||
|
// ---------- 1. 预索引 dataDayPlan:billdocument_id -> List<DataRow> ----------
|
||||||
|
var dayPlanMap = new Dictionary<string, List<DataRow>>();
|
||||||
foreach (DataRow row in dataDayPlan.Rows)
|
foreach (DataRow row in dataDayPlan.Rows)
|
||||||
{
|
{
|
||||||
string billId = row[rightPrimaryKey].ToString();
|
string billId = row[rightPrimaryKey].ToString();
|
||||||
if (!dayPlanMap.ContainsKey(billId))
|
if (!dayPlanMap.TryGetValue(billId, out var list))
|
||||||
{
|
{
|
||||||
dayPlanMap[billId] = new List<DataRow>();
|
list = new List<DataRow>();
|
||||||
|
dayPlanMap[billId] = list;
|
||||||
}
|
}
|
||||||
dayPlanMap[billId].Add(row);
|
list.Add(row);
|
||||||
}
|
}
|
||||||
// **2. 预构建主数据的列**
|
|
||||||
for (DateTime dt = startDate; dt <= endDate; dt = dt.AddDays(1))
|
// ---------- 2. 为主表添加日期列和合计列 ----------
|
||||||
|
for (DateTime d = startDate; d <= endDate; d = d.AddDays(1))
|
||||||
{
|
{
|
||||||
string colName = dt.ToString("yyyy-MM-dd");
|
string colName = d.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)); // 确保列存在
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// **3. 预构建数据填充映射表**
|
if (!dataMain.Columns.Contains("heji"))
|
||||||
Dictionary<string, Dictionary<string, decimal>> dataMap = new Dictionary<string, Dictionary<string, decimal>>();
|
dataMain.Columns.Add("heji", typeof(decimal));
|
||||||
foreach (DataRow row in dataMain.Rows)
|
|
||||||
|
// ---------- 3. 预构建填充映射:主键 -> (日期列名, 金额) ----------
|
||||||
|
var dataMap = new Dictionary<string, Dictionary<string, decimal>>();
|
||||||
|
foreach (DataRow mainRow in dataMain.Rows)
|
||||||
{
|
{
|
||||||
string key = row[topPrimaryKey].ToString();
|
string key = mainRow[topPrimaryKey].ToString();
|
||||||
if (!dataMap.ContainsKey(key))
|
var inner = new Dictionary<string, decimal>();
|
||||||
|
dataMap[key] = inner;
|
||||||
|
|
||||||
|
if (dayPlanMap.TryGetValue(key, out var rows))
|
||||||
{
|
{
|
||||||
dataMap[key] = new Dictionary<string, decimal>();
|
foreach (DataRow dayRow in rows)
|
||||||
}
|
|
||||||
// **查找 key 关联的时间数据**
|
|
||||||
if (dayPlanMap.ContainsKey(key))
|
|
||||||
{
|
|
||||||
foreach (DataRow dayRow in dayPlanMap[key])
|
|
||||||
{
|
{
|
||||||
if (dayRow[dateField] != DBNull.Value)
|
if (dayRow[dateField] == DBNull.Value) continue;
|
||||||
{
|
|
||||||
DateTime dayValue = Convert.ToDateTime(dayRow[dateField]);
|
DateTime d = Convert.ToDateTime(dayRow[dateField]);
|
||||||
string colName = dayValue.ToString("yyyy-MM-dd");
|
if (d < startDate || d > endDate) continue;
|
||||||
if (dayValue >= startDate && dayValue <= endDate && dataMain.Columns.Contains(colName))
|
|
||||||
{
|
string col = d.ToString("yyyy-MM-dd");
|
||||||
decimal.TryParse(dayRow[amountField] + "", out decimal amountValue);
|
if (!dataMain.Columns.Contains(col)) continue;
|
||||||
dataMap[key][colName] = amountValue;
|
|
||||||
}
|
if (decimal.TryParse(dayRow[amountField]?.ToString(), out decimal amt))
|
||||||
}
|
inner[col] = amt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// **4. 一次性填充 DataTable(避免逐行赋值带来的性能问题)**
|
|
||||||
foreach (DataRow row in dataMain.Rows)
|
// ---------- 4. 一次性填充并计算行合计 ----------
|
||||||
|
foreach (DataRow mainRow in dataMain.Rows)
|
||||||
{
|
{
|
||||||
string key = row[topPrimaryKey].ToString();
|
string key = mainRow[topPrimaryKey].ToString();
|
||||||
if (dataMap.ContainsKey(key))
|
decimal rowSum = 0m;
|
||||||
|
|
||||||
|
if (dataMap.TryGetValue(key, out var inner))
|
||||||
{
|
{
|
||||||
foreach (var col in dataMap[key])
|
foreach (var kv in inner)
|
||||||
{
|
{
|
||||||
row[col.Key] = col.Value;
|
mainRow[kv.Key] = kv.Value;
|
||||||
|
rowSum += kv.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mainRow["heji"] = rowSum; // 行汇总
|
||||||
}
|
}
|
||||||
|
|
||||||
return dataMain;
|
return dataMain;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建带日期的数据源
|
/// 构建带日期的数据源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user