-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleFormat.cs
More file actions
63 lines (61 loc) · 2.97 KB
/
Copy pathSimpleFormat.cs
File metadata and controls
63 lines (61 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using DevExpress.Blazor;
using DevExpress.Data.Filtering;
namespace ConditionalFormatSelector.Data {
public enum ConditionType {
Filter,
GreaterThanTotalSummary,
LessThanTotalSummary
}
public class SimpleFormat {
public SimpleFormat(string columnFieldName, ConditionInfo condition, FormatStyleInfo? style) {
FormatId = Guid.NewGuid().ToString();
ColumnFieldName = columnFieldName;
Condition = condition;
Style = style;
}
public string FormatId { get; }
public ConditionInfo Condition { get; set; }
public FormatStyleInfo? Style { get; set; }
public string ColumnFieldName { get; set; }
public void ApplyStyle(GridCustomizeElementEventArgs args) {
bool isTargetDataCell = args.ElementType == GridElementType.DataCell && args.Column is IGridDataColumn column && column.FieldName == ColumnFieldName;
if(isTargetDataCell) {
bool shouldApply = ConditionalFormatHelper.Evaluate(this, args);
if(shouldApply) {
if(!string.IsNullOrEmpty(args.CssClass))
args.CssClass += " ";
if(Style != null)
args.CssClass += Style.CssClassName;
}
}
}
public static List<SimpleFormat> GenerateTestFormats(string columnFieldName, int min, string minStyleName, int max, string maxStyleName) {
List<SimpleFormat> formats = new List<SimpleFormat>();
List<FormatStyleInfo> styles = ConditionalFormatHelper.GetFormatStyles();
formats.Add(
new SimpleFormat(
columnFieldName,
new FilterConditionInfo("Filter", CriteriaOperator.Parse($"[{columnFieldName}] > {max}")),
styles.First(s => s.FormatName == maxStyleName)
)
);
formats.Add(
new SimpleFormat(
columnFieldName,
new FilterConditionInfo("Filter", CriteriaOperator.Parse($"[{columnFieldName}] < {min}")),
styles.First(s => s.FormatName == minStyleName)
)
);
return formats;
}
public override string ToString() {
if(Condition is FilterConditionInfo filter)
return $"Condition: {filter.FilterCriteria} - Style: {Style?.FormatName}";
if(Condition is SummaryConditionInfo summary && Condition.ConditionType == ConditionType.GreaterThanTotalSummary)
return $"Condition: Greater than Total Summary in {ColumnFieldName} - Style: {Style?.FormatName}";
if(Condition is SummaryConditionInfo summary2 && Condition.ConditionType == ConditionType.LessThanTotalSummary)
return $"Condition: Less than Total Summary in {ColumnFieldName} - Style: {Style?.FormatName}";
return "Unsupported Condition type";
}
}
}