-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculable.cs
163 lines (137 loc) · 5.52 KB
/
Calculable.cs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using Rsx.Dumb;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace Rsx.DGV
{
/// <summary>
/// The kind of column that shows wether the system is Busy calculating or a calculation needs to
/// be performed based on the red-green and orange scheme in traffic lights
/// </summary>
public class CalculableColumn : DataGridViewTextBoxColumn
{
public CalculableColumn()
: base()
{
CellTemplate = new CalculableCell();
}
}
/// <summary>
/// The kind of cell that shows wether the system is Busy calculating or a calculation needs to
/// be performed based on the red-green and orange scheme in traffic lights
/// </summary>
public class CalculableCell : DataGridViewTextBoxCell
{
protected override void OnMouseDoubleClick(DataGridViewCellMouseEventArgs e)
{
// if (this.OwningRow.Index < 0) return;
ICalculableRow Icalc = GetICalculable(e.RowIndex);
if (Icalc != null)
{
Icalc.ToDo = !Icalc.ToDo;
}
base.DataGridView.NotifyCurrentCellDirty(true);
base.DataGridView.ClearSelection();
base.OnMouseDoubleClick(e);
}
/// <summary>
/// Paints red, green and orange based on the ToDo and IsBusy conditionals
/// </summary>
/// <param name="graphics"> </param>
/// <param name="clipBounds"> </param>
/// <param name="cellBounds"> </param>
/// <param name="rowIndex"> </param>
/// <param name="cellState"> </param>
/// <param name="value"> </param>
/// <param name="formattedValue"> </param>
/// <param name="errorText"> </param>
/// <param name="cellStyle"> </param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"> </param>
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
setDefaultCellStyle();
//if (this.OwningRow.Index < 0) return;
//changed is not used
//but could be used
ICalculableRow Icalc = GetICalculable(rowIndex);
bool? todo = Icalc?.ToDo;
bool? isBusy = Icalc?.IsBusy;
Color colr = getColor(todo, isBusy);
bool changed = hasChanged(ref cellStyle, ref colr);
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
// base.DataGridView.NotifyCurrentCellDirty(true);
// base.DataGridView.ClearSelection();
}
/// <summary>
/// Gets the ICalculableRow Interface to the Row that this DGV cell is binded to
/// </summary>
/// <returns></returns>
public ICalculableRow GetICalculable(int rowIndex)
{
ICalculableRow Icalc = null;
if (rowIndex <= -1) return Icalc;
DataGridViewRow r = this.DataGridView.Rows[rowIndex];
DataRowView v = r?.DataBoundItem as DataRowView;
DataRow u = (v?.Row) as DataRow;
if (!EC.IsNuDelDetch(u))
{
Icalc = u as ICalculableRow;
}
return Icalc;
}
/// <summary>
/// after color change this return wether a change was performed
/// </summary>
/// <param name="cellStyle"></param>
/// <param name="colr"> </param>
/// <returns></returns>
private static bool hasChanged(ref DataGridViewCellStyle cellStyle, ref Color colr)
{
bool changed = false;
if (colr != cellStyle.BackColor)
{
cellStyle.BackColor = colr;
cellStyle.ForeColor = colr;
changed = true;
}
return changed;
}
/// <summary>
/// gets the color to fill the cell
/// </summary>
/// <param name="todo"> </param>
/// <param name="isBusy"></param>
/// <returns></returns>
private static Color getColor(bool? todo, bool? isBusy)
{
Color colr = Color.PaleGreen;
if (todo != null && todo == true)
{
if (isBusy != null)
{
if (isBusy == true) colr = Color.Orange;
else colr = Color.Coral;
}
}
return colr;
}
/// <summary>
/// The kind of cell that shows wether the system is Busy calculating or a calculation needs
/// to be performed based on the red-green and orange scheme in traffic lights
/// </summary>
public CalculableCell() : base()
{
setDefaultCellStyle();
}
private void setDefaultCellStyle()
{
Color defaultColor = Color.Transparent;
Color defaultColor2 = Color.Transparent;
Style.SelectionBackColor = defaultColor;
Style.SelectionForeColor = defaultColor2;
Style.BackColor = defaultColor;
Style.ForeColor = defaultColor;
}
}
}