SVN-Revision: r743
This commit is contained in:
tdx
2025-06-16 02:19:08 +00:00
parent 82b1254ad8
commit 1f3e3500e9
+49 -49
View File
@@ -1552,79 +1552,79 @@ namespace Lskj.ProductiSched
}
}
/// <summary>
/// 按周结构生成列
/// 按周结构生成列(跨月后从第 1 周重新计)
/// </summary>
/// <param name="grid"></param>
/// <param name="currentDate"></param>
private void UpdateWeeklyColumns(BandedGridControlEx grid, DateTime currentDate)
{
DateTime endDate = currentDate.AddMonths(3).AddDays(-1); // 计算结束日期
int weekIndex = 0;
DateTime weekStart = GetStartOfWeek(currentDate); // 获取本周的周一日期
DateTime endDate = currentDate.AddMonths(3).AddDays(-1); // 3 个月窗口
DateTime weekStart = GetStartOfWeek(currentDate); // 本周周一
int weekIndex = 0; // Week_0 ~ Week_14
// 查找并更新15个虚拟的周列
while (weekStart <= endDate && weekIndex < 15)
{
DateTime weekEnd = weekStart.AddDays(6); // 周日的日期是周一 + 6 天
DateTime weekEnd = weekStart.AddDays(6); // 本周周日
DateTime pivotDate = weekStart.AddDays(3); // —— 周四 —— 归属月份基准
int monthKey = pivotDate.Month; // 本周归属的「月份」
// 查找现有的虚拟周列(Week_0, Week_1, ..., Week_14
string bandTitle = $"Week_{weekIndex}";
GridBand weekBand = grid.BandedView.Bands.Cast<GridBand>()
.FirstOrDefault(b => b.Name == bandTitle);
/* ---------- 计算“几月第几周” ---------- */
DateTime monthFirstDay = new DateTime(pivotDate.Year, pivotDate.Month, 1); // 当月1号
DateTime firstWeekStart = GetStartOfWeek(monthFirstDay); // 先找周一
// 若周四不在同月,则循环向后推 1 周,直到周四落在目标月
while (firstWeekStart.AddDays(3).Month != monthKey)
firstWeekStart = firstWeekStart.AddDays(7);
int weekOfMonth = ((weekStart - firstWeekStart).Days / 7) + 1; // 1 起算
/* ---------- 设置 Week_i Band ---------- */
string bandName = $"Week_{weekIndex}";
GridBand weekBand = grid.BandedView.Bands
.Cast<GridBand>()
.FirstOrDefault(b => b.Name == bandName);
if (weekBand != null && weekBand.Columns.Count > 0)
{
BandedGridColumn weekColumn = weekBand.Columns[0];
weekBand.Visible = true;
// 设置周列表头:例如 "03-01至03-07"
weekBand.Caption = $"{weekStart:MM-dd}至{weekEnd:MM-dd}";
weekColumn.FieldName = weekStart.ToString("yyyy-MM-dd");
// 使用修改后的方法设置 Caption
weekColumn.Caption = $"{weekEnd.Month}月第{GetWeekOfMonth(weekEnd)}周";
// 设置列的宽度
weekColumn.Width = 140;
// 设置该列的Tag为周的开始日期(便于后续操作)
DataModel.columnDateMapping[weekColumn] = weekStart;
// 设置是否允许编辑
if (weekEnd >= DateTime.Today)
{
weekColumn.OptionsColumn.AllowEdit = true;
}
else
{
weekColumn.OptionsColumn.AllowEdit = false;
}
weekColumn.Visible = true; // 显示该列
weekBand.Visible = true;
weekBand.Caption = $"{weekStart:MM-dd}至{weekEnd:MM-dd}"; // 父 Band:日期范围
weekColumn.FieldName = weekStart.ToString("yyyy-MM-dd"); // 字段名:周一
weekColumn.Caption = $"{pivotDate.Month}月第{weekOfMonth}周"; // 列标题:几月第几周
weekColumn.Width = 140;
DataModel.columnDateMapping[weekColumn] = weekStart;
weekColumn.OptionsColumn.AllowEdit = weekEnd >= DateTime.Today; // 仅未来可编辑
weekColumn.Visible = true;
}
// 更新到下一周
weekStart = weekEnd.AddDays(1); // 下一周的周一
/* ---------- 移到下一周 ---------- */
weekStart = weekEnd.AddDays(1); // 下周一
weekIndex++;
}
// 隐藏多余的周列(超过15周的列)
foreach (int i in Enumerable.Range(weekIndex, 15 - weekIndex))
/* ---------- 隐藏多余 Week_i BandweekIndex ~ 14 ---------- */
for (int i = weekIndex; i < 15; i++)
{
GridBand band = grid.BandedView.Bands.Cast<GridBand>()
.FirstOrDefault(b => b.Name == $"Week_{i}");
GridBand band = grid.BandedView.Bands
.Cast<GridBand>()
.FirstOrDefault(b => b.Name == $"Week_{i}");
if (band != null) band.Visible = false;
}
// 隐藏所有包含 Day_ 的列
foreach (var band in grid.BandedView.Bands.Cast<GridBand>())
/* ---------- 隐藏所有 Day_* 列 ---------- */
foreach (GridBand band in grid.BandedView.Bands.Cast<GridBand>())
{
if (band.Name.StartsWith("Day_"))
{
band.Visible = false;
foreach (BandedGridColumn column in band.Columns)
{
column.Visible = false;
}
}
if (!band.Name.StartsWith("Day_")) continue;
band.Visible = false;
foreach (BandedGridColumn col in band.Columns)
col.Visible = false;
}
}
/// <summary>
/// 更新TreeList控件的周列
/// </summary>
@@ -1872,7 +1872,7 @@ namespace Lskj.ProductiSched
private DataTable MergeMainDataWithDayPlan(DataTable dataMain, DataTable dataDayPlan, DateTime startDate, string typeDate = "0")
{
string rightPrimaryKey = DataModel.RightModuleModel.ParmaryKey;
string topPrimaryKey = DataModel.TopModuleModel.ParmaryKey;
string topPrimaryKey = "keyvalue";// DataModel.TopModuleModel.ParmaryKey;
DateTime endDate = startDate.AddMonths(3).AddDays(-1); // 计算结束日期
// **1. 预索引 dataDayPlan 数据(billdocument_id -> 该 key 相关的所有行)**