SVN r436
SVN-Revision: r436
This commit is contained in:
@@ -263,18 +263,32 @@ namespace Lskj.Control
|
||||
/// <exception cref="System.NotImplementedException"></exception>
|
||||
public void OnGridViewRowCellStyle(object sender, RowCellStyleEventArgs e)
|
||||
{
|
||||
var view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
|
||||
|
||||
if (view.IsCellSelected(e.RowHandle, e.Column))
|
||||
{
|
||||
return; // 如果当前单元格被选中,则不应用自定义样式
|
||||
}
|
||||
|
||||
if (e.RowHandle >= 0 && this.GridRowColorsTable != null && this.GridRowColorsTable.Rows.Count > 0)
|
||||
{
|
||||
// 渲染界面数据量过多界面刷新会很慢
|
||||
//DataTable table = this.gridControl.DataSourceTable();
|
||||
//DataRow gridRow = table.Rows[e.RowHandle];
|
||||
DataRow gridRow = this.GridView.GetDataRow(e.RowHandle);
|
||||
DataRow gridRow = view.GetDataRow(e.RowHandle);
|
||||
// 获取行的最大日期值
|
||||
DateTime? maxDateForRow = GetMaxDateFromColumnNames(gridRow);
|
||||
foreach (DataRow item in this.GridRowColorsTable.Rows)
|
||||
{
|
||||
string 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
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(cond) && ReplaceHelper.EvalCond(cond))
|
||||
if (!string.IsNullOrWhiteSpace(cond) && ReplaceHelper.EvalCond(cond) && (!string.IsNullOrEmpty(e.CellValue + "")|| isLaterDatePresent))
|
||||
{
|
||||
GridRowColorModel model = new GridRowColorModel(item);
|
||||
if (!string.IsNullOrWhiteSpace(model.BackColor))
|
||||
@@ -287,21 +301,58 @@ namespace Lskj.Control
|
||||
}
|
||||
|
||||
FontStyle fontStyle = new FontStyle();
|
||||
if (model.IsBold) fontStyle = fontStyle | FontStyle.Bold;
|
||||
if (model.IsItalic) fontStyle = fontStyle | FontStyle.Italic;
|
||||
if (model.IsStrickOut) fontStyle = fontStyle | FontStyle.Strikeout;
|
||||
if (model.IsUnderLine) fontStyle = fontStyle | FontStyle.Underline;
|
||||
if (model.IsBold) fontStyle |= FontStyle.Bold;
|
||||
if (model.IsItalic) fontStyle |= FontStyle.Italic;
|
||||
if (model.IsStrickOut) fontStyle |= FontStyle.Strikeout;
|
||||
if (model.IsUnderLine) fontStyle |= FontStyle.Underline;
|
||||
|
||||
e.Appearance.Font = new Font(e.Appearance.Font, fontStyle);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
//LogHelper.Instance.WriteLog("GridView RowCellStyle Error. Condition:" + model.Condition + ";EvalCondtion:" + cond);
|
||||
// 考虑增加错误日志记录
|
||||
// LogHelper.Instance.WriteLog("GridView RowCellStyle Error. Condition:" + item["condition"] + "; EvalCondtion:" + cond, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 解析列名是否为日期模式
|
||||
/// </summary>
|
||||
/// <param name="fieldName"></param>
|
||||
/// <param name="date"></param>
|
||||
/// <returns></returns>
|
||||
private bool IsDateColumn(string fieldName, out DateTime date)
|
||||
{
|
||||
// 通过正则表达式或其他方法来解析字段名是否包含日期,并尝试解析日期
|
||||
return DateTime.TryParse(fieldName, out date); // 示例,实际应根据实际字段名解析逻辑
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取行中最大的有效日期
|
||||
/// </summary>
|
||||
/// <param name="row"></param>
|
||||
/// <returns></returns>
|
||||
private DateTime? GetMaxDateFromColumnNames(DataRow row)
|
||||
{
|
||||
DateTime? maxDate = null;
|
||||
foreach (DataColumn column in row.Table.Columns)
|
||||
{
|
||||
DateTime date;
|
||||
if (IsDateColumn(column.ColumnName, out date))
|
||||
{
|
||||
if (!maxDate.HasValue || date > maxDate.Value)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(row[column.ColumnName]+""))
|
||||
{
|
||||
maxDate = date;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return maxDate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:设置只读列</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
|
||||
Reference in New Issue
Block a user