Bonjour à tous,

J'ai un UltraGrid qui contient des colonnes dont certaines sont de type Bool (checkboxe).
Ces checkboxes sont initialisées via une web methode en Java qui elle, communique avec la BDD et envoie les données au .NET.
Bref, quand je lance l'application je peux cocher/déchocher des cases. Je voudrais savoir quelles sont les lignes qui ont été modifiées. Actuellement, j'ai quelque chose qui me permet d'avoir le statut de toutes les checkboxes qu'elles aient été modifiées ou pas. Ce qui n'est pas terrible pour une mise à jour en BDD par la suite...

Voici le code, la méthode GetStatusForRow récupère le statut des cases d'une ligne. La méthode GetStatusCheckboxes appelle la précédent méthode en bouclant dessus selon le nombre de champ et ensuite j'écris le résultat en console

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
public partial class FrmCVault : Form
{
	#region Properties
 
	/// <summary>
	/// Base filter lists
	/// </summary>
	//TODO: Change to a CVaultConfiguration Class
	public List<BASEFILTER> lBaseFilters { get; private set; }
	public List<SITE> lSites { get; private set; }
	public List<CONFIGURE> lConfigures{ get; private set; }
 
	#endregion
 
	#region Constructors
 
	/// <summary>
	/// Constructor
	/// </summary>
	public FrmCVault()
	{
		InitializeComponent();
		this.lBaseFilters = null;
		this.lSites = null;
		this.lConfigures = null;
	}
 
	#endregion
 
	#region Private methods
 
	#region Compare byte[]
 
	/// <summary>
	/// Compare two byte[]
	/// </summary>
	/// <param name="b1"></param>
	/// <param name="b2"></param>
	/// <returns></returns>
	private bool Compare(byte[] b1, byte[] b2)
	{
	   // return Encoding.ASCII.GetString(b1) == Encoding.ASCII.GetString(b2);
		return b1.SequenceEqual(b2);
	}
	#endregion
 
	#region Fill the table with Basefilter data
 
	/// <summary>
	/// Fill the table with Basefilter data
	/// </summary>
	private void retrieveData()
	{
		EVPTProviderBase provider = DataRepository.EVPTProvider;
 
		ObjectDataSet ds = provider.GetBaseFilter();
 
		if (ds != null)
		{
			this.lBaseFilters = ds.arBASEFILTER.ToList();
			this.lSites = ds.arSITE.ToList();
			this.lConfigures = ds.arCONFIGURE.ToList();
		}
	}
 
	#endregion
 
	#region Load Base filter data from DB
	/// <summary>
	/// Load data from the database 
	/// </summary>
	private void LoadDataSource()
	{
		CVaultDataSource.Rows.Clear();
 
		if (this.lBaseFilters != null)
		{
			var filters = from filterBase in this.lBaseFilters
						  orderby filterBase.EVPTCODE
						  select new { Id = filterBase.ID, cvault = filterBase.CVAULTCODE, evpt = filterBase.EVPTCODE, desc = filterBase.EVPTDESIGNATION, duration = filterBase.DURATION, time = filterBase.ETDTIME };
 
			var sitesDB = from sites in this.lSites
						  orderby sites.KEY
						  select new { SiteKey = sites.KEY, SiteId = sites.ID };
 
			var configs = from config in this.lConfigures
						  select new { site = config.SITE_ID, baseF = config.BASEFILTER_ID };
 
			object[][] table = new object[filters.Count()][];
			int i = 0;
 
			foreach (var item in filters)
			{
				int j = 0;
				table[i] = new object[5 + sitesDB.Count()];
				table[i][j++] = item.cvault;
				table[i][j++] = item.evpt;
				table[i][j++] = item.desc;
				table[i][j++] = item.duration;
				table[i][j++] = item.time;
				foreach (var site in sitesDB)
				{
					table[i][j] = false;
 
					foreach (var conf in configs)
					{
						if (Compare(site.SiteId, conf.site) && Compare(conf.baseF, item.Id))
						{
							table[i][j] = true;
							break;
						}
					}
					j++;
				}
				i++;
			}
			foreach (var item in table)
			{
				CVaultDataSource.Rows.Add(item);
			}
		}
	}
 
	#endregion
 
	#region Add column sites
 
	/// <summary>
	/// Add columns in table according to the sites stored in DB
	/// </summary>
	/// <remarks>The action is used to create site column</remarks>
	private void AddColumnSites()
	{
		const string siteCol = "SITE_COL";
 
		var addNewSite = new Action<string>(site =>
		{
			if (siteCol != "OTHER") 
			{
				var ultraGridBand = this.CVaultGrid.DisplayLayout.Bands[0];
 
				var gridDataColumn = new UltraDataColumn(site);
				gridDataColumn.DataType = typeof(bool);
				gridDataColumn.Tag = siteCol;
				gridDataColumn.DataType = typeof(bool);
				gridDataColumn.DefaultValue = false;
 
				this.CVaultDataSource.Band.Columns.AddRange(new object[] {
					gridDataColumn
				});
			}
		});
 
		for (int i = this.CVaultDataSource.Band.Columns.Count-1; i >= 0 ; i--)
		{
			if (this.CVaultDataSource.Band.Columns[i].Tag == siteCol)
			{
				this.CVaultDataSource.Band.Columns.RemoveAt(i);
			}
		}
 
		var sitesDB = from sites in this.lSites
					  orderby sites.KEY
					  select  sites.KEY ;
 
		foreach (var item in sitesDB)
		{
			addNewSite(item);
		}
	}
 
	#endregion
 
	#region Retrieve status of checkboxes
	/// <summary>
	/// Retrieve the checkboxes's status of  the last row selected
	/// </summary>
	/// <param name="b"></param>
	/// <param name="row"></param>
	/// <returns></returns>
	private Dictionary<string, bool> GetStatusForRow(UltraDataBand b, UltraDataRow row)
	{
		Dictionary<string, bool> statusChecked = new Dictionary<string, bool>();
		foreach (UltraDataColumn col in b.Columns.Cast<UltraDataColumn>()
										 .Where(x => x.Tag != null &&
												x.Tag.ToString() == "SITE_COL"))
		{
			statusChecked.Add(col.Key, Convert.ToBoolean(row.GetCellValue(col)));
		}
		return statusChecked;
	}
 
	#endregion
 
	#region Retrieve status of hours columns
 
	private Dictionary<string, string> GetStatusHoursForRow(UltraDataBand b, UltraGridRow row)
	{
		Dictionary<string, string> statusChecked = new Dictionary<string, string>();
		foreach (UltraDataColumn col in b.Columns.Cast<UltraDataColumn>()
										 .Where(x => x.Tag != null &&
												x.Tag.ToString() == "SITE_COL"))
		{
			//statusChecked.Add(,);
		}
		return statusChecked;
	}
 
	#endregion
 
	#endregion
 
	#region Form Events
 
	/// <summary>
	/// Form loading event
	/// </summary>
	/// <param name="sender">Form</param>
	/// <param name="e">Arguments (empty)</param>
	private void FrmCVault_Load(object sender, EventArgs e)
	{            
		this.retrieveData();
		this.AddColumnSites();
		this.LoadDataSource();
		CVaultGrid.DataBind();
	}
 
	private void ultraButton2_Click(object sender, EventArgs e)
	{
		CVaultGrid.ActiveRow.Update();
		CVaultGrid.DisplayLayout.Bands[0].AddNew();
	}
 
	private void FrmCVault_Shown(object sender, EventArgs e)
	{
		CVaultGrid.DisplayLayout.Bands[0].AddNew();
	}
 
	private void vl_ItemNotInList(object sender, ValidationErrorEventArgs e)
	{
		var ultrCombo = sender as UltraComboEditor;
		e.RetainFocus = true;
 
		if (e.LastValidValue != null)
			ultrCombo.Value = e.LastValidValue;
		else if (ultrCombo.Items.Count>0)
			ultrCombo.SelectedItem = ultrCombo.Items[0];
	}
 
	private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
	{
		if (e.KeyData == Keys.Enter)
		{
			CVaultGrid.UpdateData();
		}
	}
 
	private void Cancel_Click(object sender, EventArgs e)
	{
		this.Close();
	}
 
	private void SAVE_Click(object sender, System.EventArgs e)
	{
		this.GetStatusCheckboxes();
		this.GetStatusHours();
	}
 
	/// <summary>
	/// Get the status of checkboxes which have been changed (check or uncheck)
	/// </summary>
	private void GetStatusCheckboxes()
	{
		var statusChecked = new Dictionary<string, Dictionary<string, bool>>();
		foreach (UltraDataRow row in CVaultDataSource.Rows)
		{
			statusChecked.Add(row.GetCellValue(0).ToString(), GetStatusForRow(CVaultDataSource.Band, row));
		}
 
		foreach (KeyValuePair<string, Dictionary<string, bool>> kvp in statusChecked)
		{
			foreach (var sr in kvp.Value)
			{
				Console.WriteLine(string.Format("[{0}] Status site: {1} is {2}", kvp.Key, sr.Key, sr.Value));    
			}
		}
 
		Console.WriteLine("\r\n");
	}
 
	/// <summary>
	/// Get back the hour which have been updated
	/// From the column DURATION or ETD
	/// </summary>
	private void GetStatusHours()
	{
		//GetStatusHoursForRow(CVaultDataSource.Band, CVaultGrid.ActiveRow);
		//Dictionary<string, bool> statusChecked = GetStatusForRow(CVaultDataSource.Band, CVaultGrid.ActiveRow);
		//foreach (KeyValuePair<string, bool> kvp in statusChecked)
		//    Console.WriteLine("Status site:" + kvp.Key + " is " + kvp.Value.ToString());
		//Console.WriteLine("\r\n");
	}
 
	#endregion
 
	private void CVaultGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
	{
 
	}
}
Si vous avez besoin de plus d'informations ou que ce soit, dites moi le
Merci !