SVN-Revision: r452
This commit is contained in:
tdx
2025-04-07 05:35:11 +00:00
parent ee1e8ed97d
commit be16632732
+41 -18
View File
@@ -42,11 +42,14 @@ using DevExpress.XtraEditors.Controls;
namespace Lskj.Control namespace Lskj.Control
{ {
/// <summary> /// <summary>
/// 多表头表格 /// 多表头表格
/// </summary> /// </summary>
public partial class BandedGridControlEx : GridControlEx public partial class BandedGridControlEx : GridControlEx
{ {
// 创建Dictionary存储行号为Key,有效日期格式列名数组为Value
public Dictionary<int, List<DateTime>> rowDateValues = new Dictionary<int, List<DateTime>>();
/// <summary> /// <summary>
/// 获取模块配置 /// 获取模块配置
/// </summary> /// </summary>
@@ -264,7 +267,7 @@ namespace Lskj.Control
public void OnGridViewRowCellStyle(object sender, RowCellStyleEventArgs e) public void OnGridViewRowCellStyle(object sender, RowCellStyleEventArgs e)
{ {
var view = sender as DevExpress.XtraGrid.Views.Grid.GridView; var view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
bool isLaterDatePresent = false;
if (view.IsCellSelected(e.RowHandle, e.Column)) if (view.IsCellSelected(e.RowHandle, e.Column))
{ {
return; // 如果当前单元格被选中,则不应用自定义样式 return; // 如果当前单元格被选中,则不应用自定义样式
@@ -275,11 +278,22 @@ namespace Lskj.Control
DataRow gridRow = view.GetDataRow(e.RowHandle); DataRow gridRow = view.GetDataRow(e.RowHandle);
// 获取行的最大日期值 // 获取行的最大日期值
DateTime? maxDateForRow = null; DateTime? maxDateForRow = null;
if (gridRow.Table.Columns.Contains("PrecomputedMaxDate") && gridRow["PrecomputedMaxDate"] != null && gridRow["PrecomputedMaxDate"].ToString() != "") if (gridRow.Table.Columns.Contains("PrecomputedMaxDate"))
{ {
if (DateTime.TryParse(gridRow["PrecomputedMaxDate"].ToString(), out DateTime parsedDate)) bool isFieldDate= DateTime.TryParse(e.Column.FieldName, out DateTime FieldDate);
bool isMaxDate = DateTime.TryParse(gridRow["PrecomputedMaxDate"].ToString(), out DateTime parsedDate);
if (isMaxDate && isFieldDate)
{ {
maxDateForRow = parsedDate; maxDateForRow = parsedDate;
if (FieldDate< parsedDate)
{
isLaterDatePresent = true;
}
}
else if(isFieldDate)
{
return; // 如果当前是日期框模式且没有定义最大值则直接跳过
} }
} }
//DateTime? maxDateForRow = GetMaxDateFromColumnNames(gridRow); //DateTime? maxDateForRow = GetMaxDateFromColumnNames(gridRow);
@@ -299,14 +313,6 @@ namespace Lskj.Control
{ {
cond = ReplaceHelper.ReplaceRowParam(gridRow, item["condition"] + "").ReplaceColumnParam(e.Column.Name, e.Column.Caption, e.CellValue + ""); cond = ReplaceHelper.ReplaceRowParam(gridRow, item["condition"] + "").ReplaceColumnParam(e.Column.Name, e.Column.Caption, e.CellValue + "");
} }
bool isLaterDatePresent = false;
// 检查当前列是否为日期类型并获取日期
DateTime currentDate;
if (IsDateColumn(e.Column.FieldName, out currentDate) && maxDateForRow.HasValue && currentDate < maxDateForRow.Value)
{
// 如果当前日期小于行的最大日期,则跳过当前迭代
isLaterDatePresent = true;
}
try try
{ {
if (!string.IsNullOrWhiteSpace(cond) && ReplaceHelper.EvalCond(cond) && (!string.IsNullOrEmpty(e.CellValue + "")|| isLaterDatePresent)) if (!string.IsNullOrWhiteSpace(cond) && ReplaceHelper.EvalCond(cond) && (!string.IsNullOrEmpty(e.CellValue + "")|| isLaterDatePresent))
@@ -1368,22 +1374,39 @@ namespace Lskj.Control
{ {
try try
{ {
GridView gridView = this.gridControl.MainView as GridView; GridView gridView = this.gridControl.MainView as GridView;
DataTable dataTable = this.gridControl.DataSourceTable(); DataTable dataTable = this.gridControl.DataSourceTable();
if (dataTable != null&& dataTable.Columns.Contains("PrecomputedMaxDate")) if (dataTable != null&&dataTable.Columns.Contains("PrecomputedMaxDate"))
{ {
DataRow HandleRow = this.bandedGridView.GetDataRow(e.RowHandle); DataRow HandleRow = this.bandedGridView.GetDataRow(e.RowHandle);
DateTime? maxDate = null; // 初始化为 null,表示尚未找到有效日期 DateTime? maxDate = null; // 初始化为 null,表示尚未找到有效日期
if (DateTime.TryParse(e.Column.FieldName, out DateTime tempDate) && DateTime.TryParse(HandleRow["PrecomputedMaxDate"] + "", out DateTime newDate)) bool isdatefile= DateTime.TryParse(e.Column.FieldName, out DateTime tempDate);//获取改变当前列日期
bool isMaxDatefile = rowDateValues.TryGetValue(e.RowHandle, out List<DateTime> currentRowDateColumns);//获取记录日期
if (isdatefile)
{ {
if (tempDate > maxDate) // 只有在找到更大的日期时才更新 if (isMaxDatefile&& currentRowDateColumns.Count>0)
{ {
HandleRow["PrecomputedMaxDate"] = tempDate; List<DateTime> validDateColumns= rowDateValues[e.RowHandle];
if (tempDate > currentRowDateColumns.Max()) // 只有在找到更大的日期时才更新
{
validDateColumns.Add(tempDate);
HandleRow["PrecomputedMaxDate"] = tempDate.ToString("yyyy-MM-dd");
} }
} else if (string.IsNullOrEmpty(HandleRow["PrecomputedMaxDate"]+"")) else if (tempDate == currentRowDateColumns.Max() && string.IsNullOrEmpty(e.Value + ""))
{ {
rowDateValues[e.RowHandle].Remove(tempDate);
HandleRow["PrecomputedMaxDate"] = tempDate; HandleRow["PrecomputedMaxDate"] = currentRowDateColumns.Max().ToString("yyyy-MM-dd");
}
else
{
if(!validDateColumns.Contains(tempDate)) validDateColumns.Add(tempDate);
}
}
else {
rowDateValues[e.RowHandle].Add(tempDate);
HandleRow["PrecomputedMaxDate"] = tempDate.ToString("yyyy-MM-dd");
}
} }
} }
if (e.Column.Tag == null) return; if (e.Column.Tag == null) return;