0% found this document useful (0 votes)
21 views10 pages

Reading Management System Code

The document is a C# code file for a Windows Forms application named 'OnlineDataUpload'. It contains a class 'ReadingManagement' that manages reading data from a database, including functionalities to load meter reader data, handle user interactions, and update consumer information. The code utilizes asynchronous programming for database operations and includes error handling and UI updates based on user actions.

Uploaded by

Kunal Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views10 pages

Reading Management System Code

The document is a C# code file for a Windows Forms application named 'OnlineDataUpload'. It contains a class 'ReadingManagement' that manages reading data from a database, including functionalities to load meter reader data, handle user interactions, and update consumer information. The code utilizes asynchronous programming for database operations and includes error handling and UI updates based on user actions.

Uploaded by

Kunal Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

...nlineDataUpload\OnlineDataUpload\ReadingManagement.

cs 1
1 using System;
2 using [Link];
3 using [Link];
4 using [Link];
5 using [Link];
6 using [Link];
7 using [Link];
8 using [Link];
9 using [Link];
10 using static
[Link];
11
12 namespace OnlineDataUpload
13 {
14 public partial class ReadingManagement : Form
15 {
16 private DataSet ds;
17 private Reading myServerClass;
18 private SqlClass myLocalClass;
19 private string sql;
20 public ReadingManagement()
21 {
22 InitializeComponent();
23 }
24
25 private void ReadingManagement_Load(object sender, EventArgs e)
26 {
27
28 }
29
30 private async void cmdGetMeterReader_Click(object sender,
EventArgs e)
31 {
32
33 string msg = "";
34 ds = new DataSet();
35 using (WaitForm waitForm = new WaitForm())
36 {
37 [Link]();
38
39 await [Link](() =>
40 {
41 sql = "SELECT pkUserID, UserID, DivCode, SdoCode FROM
mstUser WHERE isActive=1 order by DivCode, SdoCode";
42 try
43 {
44 myServerClass = new Reading("1");
45 ds = [Link](ds, sql, "tmp");
...nlineDataUpload\OnlineDataUpload\[Link] 2
46
47 msg = "Done!";
48 }
49 catch (Exception ex)
50 {
51 msg = [Link]();
52 }
53
54 });
55 [Link]();
56 [Link]();
57
58 }
59 if (msg == "Done!")
60 {
61 [Link] = false;
62 [Link] = [Link]["tmp"].DefaultView;
63 }
64 [Link](msg);
65 }
66
67
68 private async void grdMeterReader_CellClick(object sender,
DataGridViewCellEventArgs e)
69 {
70 [Link] = "";
71 [Link] = "";
72 [Link] = "";
73 [Link] = "";
74 [Link] = "";
75 [Link] = "";
76 [Link] = "";
77 [Link] = "";
78
79 string ConsDetailTable = "ConsDetail";
80 string ReadinglTable = "Reading";
81 string userID = [Link][[Link]].Cells
[0].[Link]();
82 string divCode= [Link][[Link]].Cells
[2].[Link]();
83
84 [Link]= userID;
85 [Link]= [Link][[Link]].Cells
[1].[Link]();
86 [Link]= divCode;
87 [Link]= [Link][[Link]].Cells
[3].[Link]();
88
89 ConsDetailTable += divCode;
...nlineDataUpload\OnlineDataUpload\[Link] 3
90 ReadinglTable+= divCode;
91
92 string msg = "";
93 sql = @"SELECT c.chk_no, c.GRUP_CODE, COUNT(c.chk_no) AS
TotalConsumer,
94 SUM(CASE WHEN c.GRUP_CODE IN (1, 3, 5, 7, 9, 11, 13,
15) OR c.bill_type = 'M' THEN 1 ELSE 0 END) AS Total,
95 SUM(CASE WHEN (c.GRUP_CODE IN (1, 3, 5, 7, 9, 11, 13,
15) OR c.bill_type = 'M')
96 AND r.OLD_CURR_STTS IN ('NR', 'SR', '', NULL)
THEN 1 ELSE 0 END) AS Readable,
97 SUM(CASE WHEN [Link] = "+ userID+ @" THEN 1 ELSE 0
END) AS Reading
98 FROM " + ConsDetailTable + @" c INNER JOIN " +
ReadinglTable + @" r ON [Link] = [Link]
99 WHERE c.stts_code = 'OK' AND [Link] = "+ userID+ @"
GROUP BY c.chk_no, c.GRUP_CODE ORDER BY c.chk_no,
c.GRUP_CODE;";
100 ds=new DataSet();
101
102 using (WaitForm waitForm = new WaitForm())
103 {
104 [Link]();
105
106 await [Link](() =>
107 {
108 try
109 {
110 myServerClass = new Reading("1");
111 ds = [Link](ds, sql, "summary");
112
113 msg = "Done!";
114 }
115 catch (Exception ex)
116 {
117 msg = [Link]();
118 }
119
120 });
121 [Link]();
122 [Link]();
123
124 }
125 if (msg == "Done!")
126 {
127 [Link] = false;
128 [Link] = [Link]["summary"].DefaultView;
129
130 Int32 Total, Current, Valid, Reading;
...nlineDataUpload\OnlineDataUpload\[Link] 4
131 Total = 0; Current = 0; Valid = 0; Reading =0;
132 foreach(DataRow dr in [Link]["summary"].Rows)
133 {
134 Total += Convert.ToInt32(dr["TotalConsumer"].ToString
());
135 Current += Convert.ToInt32(dr["Total"].ToString());
136 Valid += Convert.ToInt32(dr["Readable"].ToString());
137 Reading += Convert.ToInt32(dr["Reading"].ToString());
138 }
139 [Link] = [Link]();
140 [Link] = [Link]();
141 [Link] = [Link]();
142 [Link] = [Link]();
143 [Link]("summary");
144
145 }
146 [Link](msg);
147 }
148
149 private void grdMeterReader_CellContentClick(object sender,
DataGridViewCellEventArgs e)
150 {
151
152 }
153
154 private async void cmdFillData_Click(object sender, EventArgs e)
155 {
156 string ConsDetailTable = "ConsDetail";
157 string ReadinglTable = "Reading";
158
159 if ([Link]() != "")
160 {
161 ConsDetailTable += [Link];
162 ReadinglTable += [Link];
163 }
164 else
165 {
166 [Link]("Please enter Division COde");
167 return;
168 }
169 string SubDivision = "";
170 SubDivision = [Link];
171 if (SubDivision == "")
172 {
173 [Link]("Please enter Sub Division COde");
174 return;
175 }
176
177 string msg = "";
...nlineDataUpload\OnlineDataUpload\[Link] 5
178 sql = @"SELECT c.chk_no, c.GRUP_CODE, COUNT(c.chk_no) AS
TotalConsumer,
179 SUM(CASE WHEN c.GRUP_CODE IN (1, 3, 5, 7, 9, 11, 13,
15) OR c.bill_type = 'M' THEN 1 ELSE 0 END) AS Total,
180 SUM(CASE WHEN (c.GRUP_CODE IN (1, 3, 5, 7, 9, 11, 13,
15) OR c.bill_type = 'M')
181 AND r.OLD_CURR_STTS IN ('NR', 'SR', '', NULL)
THEN 1 ELSE 0 END) AS Readable, [Link]

182 FROM " + ConsDetailTable + @" c INNER JOIN " +


ReadinglTable + @" r ON [Link] = [Link]
183 LEFT JOIN mstUser m on [Link]=[Link]
184 WHERE c.stts_code = 'OK' and c.sdo_code=" + SubDivision +
" GROUP BY c.chk_no, c.GRUP_CODE, [Link] ORDER BY
c.chk_no, c.GRUP_CODE;";
185 ds = new DataSet();
186
187 using (WaitForm waitForm = new WaitForm())
188 {
189 [Link]();
190
191 await [Link](() =>
192 {
193 try
194 {
195 myServerClass = new Reading("1");
196 ds = [Link](ds, sql, "user");
197
198 msg = "Done!";
199 }
200 catch (Exception ex)
201 {
202 msg = [Link]();
203 }
204
205 });
206 [Link]();
207 [Link]();
208
209 }
210 if (msg == "Done!")
211 {
212 [Link] = false;
213 [Link] = [Link]["user"].DefaultView;
214 [Link]("user");
215 SetNewTotal();
216
217 }
218 [Link](msg);
...nlineDataUpload\OnlineDataUpload\[Link] 6
219 }
220
221 private void SetNewTotal()
222 {
223 int total = 0, totalCurrent = 0, totalValid = 0;
224
225 foreach (DataGridViewRow row in [Link])
226 {
227 DataGridViewCheckBoxCell checkBoxCell = [Link]
["selectChk"] as DataGridViewCheckBoxCell;
228
229 // Check if the checkbox is checked
230 if ([Link]["user"].Value != null)
231 {
232 if ([Link]["user"].[Link]() ==
[Link])
233 {
234 [Link] = true;
235 total += Convert.ToInt32([Link]
["TotalConsumer"].[Link]());
236 totalCurrent += Convert.ToInt32([Link]
["Total"].[Link]());
237 totalValid += Convert.ToInt32([Link]
["Readable"].[Link]());
238 }
239 }
240 }
241
242 [Link] = [Link]();
243 [Link] = [Link]();
244 [Link] = [Link]();
245 }
246
247 private void grdAddConsumer_CellContentClick(object sender,
DataGridViewCellEventArgs e)
248 {
249 if ([Link] == [Link][0].Index)
250 {
251 [Link]
([Link]);
252 }
253 }
254
255 private void grdAddConsumer_CellValueChanged(object sender,
DataGridViewCellEventArgs e)
256 {
257 if ([Link] == 0)
258 {
259 int total = 0, totalCurrent = 0, totalValid = 0;
...nlineDataUpload\OnlineDataUpload\[Link] 7
260
261 foreach (DataGridViewRow row in [Link])
262 {
263 DataGridViewCheckBoxCell checkBoxCell = [Link][0]
as DataGridViewCheckBoxCell;
264
265 // Check if the checkbox is checked
266 if (checkBoxCell != null && [Link] != null
&& (bool)[Link])
267 {
268 total += Convert.ToInt32([Link]
["TotalConsumer"].[Link]());
269 totalCurrent += Convert.ToInt32([Link]
["Total"].[Link]());
270 totalValid += Convert.ToInt32([Link]
["Readable"].[Link]());
271 }
272 }
273
274 [Link] = [Link]();
275 [Link] = [Link]();
276 [Link] = [Link]();
277 }
278 }
279
280 private void cmdUpdate_Click(object sender, EventArgs e)
281 {
282 string ConsDetailTable = "ConsDetail";
283 string SubDivision = "";
284 string UserID = "";
285
286 if ([Link]() != "")
287 ConsDetailTable += [Link];
288 else
289 {
290 [Link]("Please select any User");
291 return;
292 }
293
294 SubDivision = [Link];
295 if (SubDivision == "")
296 {
297 [Link]("Please enter Sub Division COde");
298 return;
299 }
300 UserID = [Link];
301 if (UserID == "")
302 {
303 [Link]("Please enter Meter Reader");
...nlineDataUpload\OnlineDataUpload\[Link] 8
304 return;
305 }
306
307 sql ="";
308 if([Link] > 0)
309 {
310 string chkNO = "", Grup = "";
311 foreach (DataGridViewRow row in [Link])
312 {
313 DataGridViewCheckBoxCell checkBoxCell = [Link][0]
as DataGridViewCheckBoxCell;
314
315 // Check if the checkbox is checked
316 if (checkBoxCell != null && [Link] != null
&& (bool)[Link])
317 {
318 chkNO = [Link][1].[Link]();
319 Grup = [Link][2].[Link]();
320 sql += " update " + ConsDetailTable + " set
fkUserID=" + UserID + " where chk_no='" + chkNO
321 + "' and GRUP_CODE=" + Grup + " and sdo_code="
+ SubDivision + "; ";
322 }
323 }
324 int RowsEffected = 0;
325 string msg;
326 try
327 {
328 myServerClass = new Reading("1");
329 RowsEffected= [Link]
(sql);
330 msg = "Total " + [Link]() + " Consumer
Added !";
331 }
332 catch (Exception ex)
333 {
334 msg = [Link]();
335 }
336
337 [Link](msg);
338 }
339 }
340
341 private void cmdRemoveConsumer_Click(object sender, EventArgs e)
342 {
343 string ConsDetailTable = "ConsDetail";
344 string SubDivision = "";
345 string UserID = "";
346
...nlineDataUpload\OnlineDataUpload\[Link] 9
347 if ([Link]() != "")
348 ConsDetailTable += [Link];
349 else
350 {
351 [Link]("Please select any User");
352 return;
353 }
354
355 SubDivision = [Link];
356 if (SubDivision == "")
357 {
358 [Link]("Please enter Sub Division COde");
359 return;
360 }
361 UserID = [Link];
362 if (UserID == "")
363 {
364 [Link]("Please enter Meter Reader");
365 return;
366 }
367
368 sql = "";
369 if ([Link] > 0)
370 {
371 string chkNO = "", Grup = "";
372 foreach (DataGridViewRow row in [Link])
373 {
374 DataGridViewCheckBoxCell checkBoxCell = [Link][0]
as DataGridViewCheckBoxCell;
375
376 // Check if the checkbox is checked
377 if (checkBoxCell != null && [Link] != null
&& (bool)[Link])
378 {
379 chkNO = [Link][1].[Link]();
380 Grup = [Link][2].[Link]();
381 sql += " update " + ConsDetailTable + " set
fkUserID=0 where chk_no='" + chkNO
382 + "' and GRUP_CODE=" + Grup + " and sdo_code="
+ SubDivision + "; ";
383 }
384 }
385 int RowsEffected = 0;
386 string msg;
387 try
388 {
389 myServerClass = new Reading("1");
390 RowsEffected = [Link]
(sql);
...nlineDataUpload\OnlineDataUpload\[Link] 10
391 msg = "Total " + [Link]() + " Consumer
Removed !";
392 }
393 catch (Exception ex)
394 {
395 msg = [Link]();
396 }
397
398 [Link](msg);
399 }
400 }
401
402 private void chkSelectAll_CheckedChanged(object sender, EventArgs
e)
403 {
404 if([Link]==[Link])
405 {
406 foreach (DataGridViewRow row in [Link])
407 {
408 DataGridViewCheckBoxCell checkBoxCell = [Link][0]
as DataGridViewCheckBoxCell;
409 [Link] = [Link];
410 }
411 }
412 }
413
414 private void chkDeselect_CheckedChanged(object sender, EventArgs
e)
415 {
416 if ([Link] == [Link])
417 {
418 foreach (DataGridViewRow row in [Link])
419 {
420 DataGridViewCheckBoxCell checkBoxCell = [Link][0]
as DataGridViewCheckBoxCell;
421 [Link] = false;
422 }
423 }
424 }
425 }
426 }
427

You might also like