Bonjour à tous,
Mon problème est le suivant : je veux récupérer le statut de toutes mes cases à cocher.
Seulement, je ne récupère le statut que de la dernière ligne qui a été sélectionné.
Voici le code de ma classe qui gère tout ceci :
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
/// <summary>
/// Form for CVault Administration
/// </summary>
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 =>
		{
			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);
		}
	}
 
	/// <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,
											 UltraGridRow 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.Cells[col.Key].Value));
 
		}
		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()
	{
		GetStatusForRow(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());
	}
 
	/// <summary>
	/// Get back the hour which have been updated
	/// From the column DURATION or ETD
	/// </summary>
	private void GetStatusHours()
	{
 
	}
 
	#endregion
}
Et voici un aperçu de l'IHM :

Nom : TABLE.png
Affichages : 194
Taille : 63,8 Ko

Le but étant de récupérer toutes les valeurs des checkboxes et de mettre à jour la BDD en conséquence.
Je ne m'y connais pas trop trop en C#, donc je ne sais pas ce qui serait le plus intéressant, regarder toutes les checkboxes lorsque on appuie sur "Save" ou bien avoir une sorte de Event Listenner sur les checkboxes pour ne transmettre que celles qui ont été modifié.
Dans un second temps je devrais également récupérer les champs de dates, mais ça je verrais un peu plus tard.
Donc j'utilise Infragistic 2015 et si vous avez besoin d'informations complémentaires demandez moi

EDIT : Il se peut que je n'appelle pas là méthode là où il faut ou quelque chose du genre...

Merci !