-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf_main_client.cs
2647 lines (2413 loc) · 115 KB
/
f_main_client.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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Aiche_Bois
{
public partial class f_main_client : Form
{
/// <summary>
/// this code form move panel
/// </summary>
[DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
private extern static void ReleaseCapture();
[DllImport("user32.DLL", EntryPoint = "SendMessage")]
private extern static void SendMessage(System.IntPtr hwnd, int wmsg,
int wparam, int lparam);
/*
* ================ Panel Add ================
*/
/// <summary>
/// c'est l'access a extereiur Client data base
/// </summary>
private readonly OleDbConnection connectionClient = new OleDbConnection();
/// <summary>
/// c'est la list qui stocker les donnes de Facture
/// </summary>
private readonly List<Facture> factures = new List<Facture>();
/// <summary>
/// this instance from form message to show message error
/// </summary>
private f_message message;
/// <summary>
/// verify les donnée si enregistre ou non
/// </summary>
bool verifyForm = false;
/// <summary>
/// prendre id client de data grid a partir de ligne selecionnees
/// </summary>
private String[] idClient;
/// <summary>
/// stocker les client a liste des clients
/// </summary>
DataTable dtb_client = new DataTable();
/*
* =========================== Panel Add Edit Method ===========================
*/
/// <summary>
/// method qui charger la base de donnees
/// </summary>
/// <param name="idFacture"></param>
private void loadDataEdit(long idFacture)
{
try
{
connectionClient.Open();
ViderTxtBox();
//client
var commandClient = new OleDbCommand
{
Connection = connectionClient,
CommandText =
"SELECT (sum(f.prixtotalmesure) + sum(prixtotalpvc)) AS total, " +
"IIF((sum(f.prixtotalmesure) + sum(prixtotalpvc)) = prixTotalAvance, 0, (sum(f.prixtotalmesure) + sum(prixtotalpvc)) - prixTotalAvance) AS rest, " +
"c.nomClient, c.prixTotalAvance, c.idClient " +
"FROM client AS c INNER JOIN facture AS f ON f.idClient = c.idClient " +
"WHERE c.idClient = @idClient " +
"GROUP BY nomClient, prixTotalAvance, c.idClient"
};
commandClient.Parameters.AddWithValue("@idClient", idClient[1]);
OleDbDataReader readerClient = commandClient.ExecuteReader();
while (readerClient.Read())
{
t_nom_client.Text = readerClient["nomClient"].ToString();
}
readerClient = null;
commandClient = null;
String pvc = "";
//facture
var commandFacture = new OleDbCommand
{
Connection = connectionClient,
CommandText = "SELECT * FROM FACTURE WHERE idFacture = @idFacture"
};
commandFacture.Parameters.AddWithValue("@idFacture", idFacture);
OleDbDataReader readerFacture = commandFacture.ExecuteReader();
while (readerFacture.Read())
{
dp_date_facture.Value = Convert.ToDateTime(readerFacture["dtDateFacture"]);
ck_seul_pvc.Checked = Convert.ToBoolean(readerFacture["checkPVC"].ToString());
if (!ck_seul_pvc.Checked)
{
t_categorie.Text = readerFacture["categorie"].ToString();
t_metrage_feuille.Text = readerFacture["metrage"].ToString();
cb_type_metres.SelectedItem = readerFacture["typeMetres"].ToString();
t_prix_metre_mesure.Text = readerFacture["prixMetres"].ToString();
t_total_size_mesure.Text = readerFacture["totalMesure"].ToString();
txtPrixTotalMesure.Text = readerFacture["prixTotalMesure"].ToString();
}
//pvc
pvc = readerFacture["typePVC"].ToString();
dp_date_facture.Value = DateTime.Parse(readerFacture["dtDateFacture"].ToString());
t_type_Bois.Text = readerFacture["typeDeBois"].ToString();
cb_type_pvc.SelectedItem = (pvc == "---" ? null : readerFacture["typePVC"].ToString());
t_size_pvc.Text = readerFacture["tailleCanto"].ToString();
t_total_size_pvc.Text = readerFacture["totalTaillPVC"].ToString();
t_prix_metre_linear_pvc.Text = readerFacture["prixMitresLinear"].ToString();
t_prix_total_pvc.Text = readerFacture["prixTotalPVC"].ToString();
}
readerFacture = null;
commandFacture = null;
if (!cb_type_metres.SelectedItem.Equals("m"))
{
//Mesure
if (!ck_seul_pvc.Checked)
{
var commandMesure = new OleDbCommand
{
Connection = connectionClient,
CommandText = "SELECT quantite, largeur, longueur, eppaiseur FROM MESURE WHERE idFacture = @idFacture"
};
commandMesure.Parameters.AddWithValue("@idFacture", idFacture);
OleDbDataReader readerMesure = commandMesure.ExecuteReader();
// clear data grid mesure
dg_mesure.Rows.Clear();
while (readerMesure.Read())
{
if (cb_type_metres.SelectedItem.Equals("m3"))
{
dg_mesure.Rows.Add(
readerMesure["quantite"].ToString(),
readerMesure["largeur"].ToString(),
readerMesure["longueur"].ToString(),
readerMesure["eppaiseur"].ToString());
}
else
{
dg_mesure.Rows.Add(
readerMesure["quantite"].ToString(),
readerMesure["largeur"].ToString(),
readerMesure["longueur"].ToString());
}
}
readerMesure = null;
commandMesure = null;
}
// pvc
if (pvc != "---")
{
var commandPVC = new OleDbCommand
{
Connection = connectionClient,
CommandText = "SELECT quantite, largeur, longueur, orientation FROM PVC WHERE idFacture = @idFacture"
};
commandPVC.Parameters.AddWithValue("@idFacture", idFacture);
OleDbDataReader readerPVC = commandPVC.ExecuteReader();
dg_pvc.Rows.Clear();
while (readerPVC.Read())
{
dg_pvc.Rows.Add(
readerPVC["quantite"].ToString(),
readerPVC["largeur"].ToString(),
readerPVC["longueur"].ToString(),
readerPVC["orientation"].ToString());
}
readerPVC = null;
commandPVC = null;
}
else
{
dg_pvc.Rows.Clear();
}
// desable field depend by check seul
checkSeulPVC(ck_seul_pvc.Checked);
}
else
{
dg_pvc.Rows.Clear();
dg_mesure.Rows.Clear();
}
// close connection
connectionClient.Close();
}
catch (Exception ex)
{
connectionClient.Close();
LogFile.Message(ex);
}
}
/// <summary>
/// desabled field text depend on checked button seul
/// </summary>
/// <param name="ft"></param>
private void checkSeulPVC(bool ft)
{
t_prix_metre_mesure.Enabled = t_metrage_feuille.Enabled = t_categorie.Enabled =
t_search_client.Enabled = t_quantity_mesure.Enabled = t_largeur_mesure.Enabled = t_longueur_mesure.Enabled =
t_epaisseur_mesure.Enabled = b_add_mesure.Enabled = b_delete_mesure.Enabled = b_export_csv.Enabled =
b_import_pvc.Enabled = !ft;
b_add_seul_pvc.Enabled = b_delete_seul_pvc.Enabled = t_quantity_pvc.Enabled = t_largeur_pvc.Enabled =
t_longueur_pvc.Enabled = cb_orientation_pvc.Enabled = ft;
if (ft)
{
t_prix_metre_mesure.Text = t_total_size_mesure.Text = txtPrixTotalMesure.Text = "0.00";
t_metrage_feuille.Text = t_categorie.Text = "---";
dg_mesure.Rows.Clear();
}
}
/// <summary>
/// clear textBox and datagrid
/// </summary>
private void ViderTxtBox()
{
/*vider les objet*/
t_total_size_pvc.Text = t_type_Bois.Text = "";
t_quantity_mesure.Clear();
t_largeur_mesure.Clear();
t_longueur_mesure.Clear();
t_epaisseur_mesure.Clear();
t_total_size_mesure.Clear();
t_prix_total_pvc.Text = txtPrixTotalMesure.Text = "0.00";
t_metrage_feuille.Clear();
cb_type_pvc.SelectedItem = null;
cb_type_metres.SelectedItem = "feuille";
t_size_pvc.Clear();
t_prix_metre_linear_pvc.Clear();
//mesures.Clear();
//pvcs.Clear();
dg_mesure.Rows.Clear();
dg_pvc.Rows.Clear();
ck_seul_pvc.Checked = false;
checkSeulPVC(ck_seul_pvc.Checked);
lt_type_bois.Focus();
}
/// <summary>
/// calculate datagride when click on button save
/// </summary>
public void btnSaveCalculPvc()
{
if (dg_pvc.Rows.Count == 0)
{
message = new f_message("Importer les valeurs des mesures", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
return;
}
// check if already there this numbers
for (int i = 0; i < dg_pvc.Rows.Count; i++)
{
if (dg_pvc.Rows[i].Cells[3].Value == null)
{
message = new f_message("sélection l'orientation de ligne " + (i + 1), "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
return;
}
}
//pvcs.Clear();
double total = 0;
for (int i = 0; i < dg_pvc.Rows.Count; i++)
{
String ss = (dg_pvc.Rows[i].Cells[3] as DataGridViewComboBoxCell).FormattedValue.ToString();
if (String.IsNullOrEmpty(ss))
ss = "0";
double qt = double.Parse(dg_pvc.Rows[i].Cells[0].Value.ToString());
double lar = double.Parse(dg_pvc.Rows[i].Cells[1].Value.ToString());
double lon = double.Parse(dg_pvc.Rows[i].Cells[2].Value.ToString());
/*
* horizontal
* largeur
*
* vertical
* longueur
*/
switch (ss)
{
/*horizontal = 0, vertical = 0*/
case "0":
total += (lar / 100) * 0 * qt + (lon / 100) * 0 * qt;
break;
/*horizontal = 1, vertical = 0*/
case "h*1":
total += (lar / 100) * 1 * qt + (lon / 100) * 0 * qt;
break;
/*horizontal = 0, vertical = 1*/
case "v*1":
total += (lar / 100) * 0 * qt + (lon / 100) * 1 * qt;
break;
/*horizontal = 2, vertical = 0*/
case "h*2":
total += (lar / 100) * 2 * qt + (lon / 100) * 0 * qt;
break;
/*horizontal = 0, vertical = 2*/
case "v*2":
total += (lar / 100) * 0 * qt + (lon / 100) * 2 * qt;
break;
/*horizontal = 2, vertical = 2*/
case "4":
total += (lar / 100) * 2 * qt + (lon / 100) * 2 * qt;
break;
/*horizontal = 1, vertical = 2*/
case "h*1+v*2":
total += (lar / 100) * 1 * qt + (lon / 100) * 2 * qt;
break;
/*horizontal = 2, vertical = 1*/
case "h*2+v*1":
total += (lar / 100) * 2 * qt + (lon / 100) * 1 * qt;
break;
/*horizontal = 1, vertical = 1*/
case "h*1+v*1":
total += (lar / 100) * 1 * qt + (lon / 100) * 1 * qt;
break;
}
}
t_total_size_pvc.Text = total.ToString("F2");
total = 0;
}
/// <summary>
/// this method return true or false for Empty textBox
/// </summary>
/// <returns></returns>
private bool checkIsNullOrEmpty()
{
if (string.IsNullOrEmpty(t_nom_client.Text))
{
message = new f_message(t_nom_client.Tag + " est vide", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
t_nom_client.Focus();
return false;
}
if (string.IsNullOrEmpty(t_type_Bois.Text))
{
message = new f_message(t_type_Bois.Tag + " est vide", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
lt_type_bois.Focus();
return false;
}
if (string.IsNullOrEmpty(t_prix_metre_mesure.Text))
{
message = new f_message(t_prix_metre_mesure.Tag + " est vide", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
t_prix_metre_mesure.Focus();
return false;
}
if (string.IsNullOrEmpty(t_total_size_mesure.Text))
{
message = new f_message(t_total_size_mesure.Tag + " est vide", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
t_total_size_mesure.Focus();
return false;
}
if (string.IsNullOrEmpty(txtPrixTotalMesure.Text))
{
message = new f_message(txtPrixTotalMesure.Tag + " est vide", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
txtPrixTotalMesure.Focus();
return false;
}
if (string.IsNullOrEmpty(t_metrage_feuille.Text))
{
message = new f_message(t_metrage_feuille.Tag + " est vide", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
t_metrage_feuille.Focus();
return false;
}
if (string.IsNullOrEmpty(t_categorie.Text))
{
message = new f_message(t_categorie.Tag + " est vide", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
t_categorie.Focus();
return false;
}
if (!string.IsNullOrEmpty(cb_type_pvc.Text))
{
if (string.IsNullOrEmpty(t_total_size_pvc.Text))
{
message = new f_message(t_total_size_pvc.Tag + " est vide", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
t_total_size_pvc.Focus();
return false;
}
if (string.IsNullOrEmpty(t_size_pvc.Text))
{
message = new f_message(t_size_pvc.Tag + " est vide", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
t_size_pvc.Focus();
return false;
}
if (string.IsNullOrEmpty(t_prix_metre_linear_pvc.Text))
{
message = new f_message(t_prix_metre_linear_pvc.Tag + " est vide", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog(); t_prix_metre_linear_pvc.Focus();
return false;
}
if (dg_mesure.Rows.Count != dg_pvc.Rows.Count && !ck_seul_pvc.Checked && cb_type_pvc.SelectedText != null)
{
message = new f_message("Exporter les mesures vers le menu Pvc", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
return false;
}
}
return true;
}
/// <summary>
/// this method disable/enable mesures
/// </summary>
/// <param name="b"></param>
private void enabledMesure(bool b)
{
t_quantity_mesure.Enabled = t_largeur_mesure.Enabled = t_longueur_mesure.Enabled = t_epaisseur_mesure.Enabled = b;
}
/// <summary>
/// initialise l'identificateur de facture
/// </summary>
private void idFacture()
{
cb_id_facture.Text = "Facture Numéro: " + (factures.Count + 1).ToString("D2");
}
/// <summary>
/// remplir comboBox PVC de dataBase
/// </summary>
private void RemplirComboBxPvc()
{
cb_type_pvc.Items.Clear();
try
{
connectionClient.Open();
var command = new OleDbCommand
{
Connection = connectionClient,
CommandText = "select Libelle from PVC_C"
};
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
cb_type_pvc.Items.Add(reader["Libelle"].ToString());
}
reader = null;
command = null;
connectionClient.Close();
}
catch (Exception ex)
{
connectionClient.Close();
LogFile.Message(ex);
}
}
/// <summary>
/// remplir listeBox MDF, LATTE, STD de dataBase
/// </summary>
/// <param name="typeBois"></param>
DataTable tb_Type = new DataTable();
private void remplirListe(string typeBois)
{
lt_type_bois.Items.Clear();
tb_Type.Rows.Clear();
try
{
connectionClient.Open();
var command = new OleDbCommand
{
Connection = connectionClient,
CommandText = "SELECT Libelle FROM " + typeBois
};
tb_Type.Load(command.ExecuteReader());
command = null;
connectionClient.Close();
for (int i = 0; i < tb_Type.Rows.Count; i++)
{
lt_type_bois.Items.Add(tb_Type.Rows[i][0].ToString());
}
lt_type_bois.SelectedIndex = lt_type_bois.Items.Count - 1;
}
catch (Exception ex)
{
connectionClient.Close();
LogFile.Message(ex);
}
}
/// <summary>
/// method qui calcul data grid view mesure
/// </summary>
private void RemplirDataMesure()
{
double totale = 0;
for (int i = 0; i < dg_mesure.Rows.Count; i++)
{
if (cb_type_metres.SelectedItem.Equals("m3"))
{
totale +=
((Convert.ToDouble(dg_mesure.Rows[i].Cells[1].Value) / 100) *
(Convert.ToDouble(dg_mesure.Rows[i].Cells[2].Value) / 100) *
(Convert.ToDouble(dg_mesure.Rows[i].Cells[3].Value) / 1000)) *
Convert.ToDouble(dg_mesure.Rows[i].Cells[0].Value);
}
else
{
totale +=
((Convert.ToDouble(dg_mesure.Rows[i].Cells[1].Value) / 100) *
(Convert.ToDouble(dg_mesure.Rows[i].Cells[2].Value) / 100)) *
Convert.ToDouble(dg_mesure.Rows[i].Cells[0].Value);
}
}
if (!cb_type_metres.SelectedItem.Equals("feuille"))
{
t_total_size_mesure.Text = totale.ToString();
}
}
/// <summary>
/// validate data on database mode desconnect
/// </summary>
private void saveDataClient()
{
try
{
connectionClient.Open();
int idCLIENT = 0;
int idFACTURE = 0;
var commandClient = new OleDbCommand
{
Connection = connectionClient,
CommandText = "INSERT INTO " +
"client(nomClient, dateClient, prixTotalAvance) " +
"VALUES(@nomClient, @dateClient, @prixTotalAvance)"
};
commandClient.Parameters.AddWithValue("@nomClient", t_nom_client.Text);
commandClient.Parameters.AddWithValue("@dateClient", DateTime.Now.ToString());
commandClient.Parameters.AddWithValue("@prixTotalAvance", 0.0);
commandClient.ExecuteNonQuery();
commandClient = null;
/*get idClient from database*/
var commandIdClient = new OleDbCommand
{
Connection = connectionClient,
CommandText = "SELECT TOP 1 idClient FROM client ORDER BY idClient DESC"
};
OleDbDataReader readerIdClient = commandIdClient.ExecuteReader();
while (readerIdClient.Read())
{
idCLIENT = Convert.ToInt32(readerIdClient["idClient"]);
}
readerIdClient = null;
commandIdClient = null;
/*facture*/
foreach (var fct in factures)
{
var commandFacture = new OleDbCommand
{
Connection = connectionClient,
CommandText = "INSERT INTO " +
"facture(idClient, dtDateFacture, typeDeBois, " +
"metrage, categorie, totalMesure, typeMetres, prixMetres, typePVC, checkPVC, tailleCanto, " +
"totalTaillPVC, prixMitresLinear, prixTotalPVC, prixTotalMesure) " +
"VALUES(@idClient, @dtDateFacture, @typeDeBois, " +
"@metrage, @categorie, @totalMesure, @typeMetres, @prixMetres, @typePVC, @checkPVC, " +
"@tailleCanto, @totalTaillPVC, @prixMitresLinear, @prixTotalPVC, @prixTotalMesure)"
};
commandFacture.Parameters.AddWithValue("@idClient", idCLIENT);
commandFacture.Parameters.AddWithValue("@dtDateFacture", fct.DateFacture.ToString());
commandFacture.Parameters.AddWithValue("@typeDeBois", fct.TypeDeBois);
commandFacture.Parameters.AddWithValue("@metrage", fct.Metrage);
commandFacture.Parameters.AddWithValue("@categorie", fct.Categorie);
commandFacture.Parameters.AddWithValue("@totalMesure", fct.TotalMesure);
commandFacture.Parameters.AddWithValue("@typeMetres", fct.TypeMetres);
commandFacture.Parameters.AddWithValue("@prixMetres", fct.PrixMetres);
commandFacture.Parameters.AddWithValue("@typePVC", fct.TypePVC);
commandFacture.Parameters.AddWithValue("@checkPVC", fct.CheckPVC);
commandFacture.Parameters.AddWithValue("@tailleCanto", fct.TailleCanto);
commandFacture.Parameters.AddWithValue("@totalTaillPVC", fct.TotalTaillPVC);
commandFacture.Parameters.AddWithValue("@prixMitresLinear", fct.PrixMitresLinear);
commandFacture.Parameters.AddWithValue("@prixTotalPVC", fct.PrixTotalPVC);
commandFacture.Parameters.AddWithValue("@prixTotalMesure", fct.PrixTotalMesure);
commandFacture.ExecuteNonQuery();
commandFacture = null;
/*get idClient from database*/
var commandIdFacture = new OleDbCommand
{
Connection = connectionClient,
CommandText = "SELECT TOP 1 idFacture FROM facture ORDER BY idFacture DESC"
};
OleDbDataReader readerIdFacture = commandIdFacture.ExecuteReader();
while (readerIdFacture.Read())
{
idFACTURE = Convert.ToInt32(readerIdFacture["idFacture"]);
}
readerIdFacture = null;
commandIdFacture = null;
// insert datagride pvc
foreach (var pvc in fct.Pvcs)
{
var commandPvc = new OleDbCommand
{
Connection = connectionClient,
CommandText = "INSERT INTO " +
"pvc(idFacture, quantite, largeur, longueur, orientation) " +
"VALUES(@idFacture, @quantite, @largeur, @longueur, @orientation)"
};
commandPvc.Parameters.AddWithValue("@idFacture", idFACTURE);
commandPvc.Parameters.AddWithValue("@quantite", pvc.Qte);
commandPvc.Parameters.AddWithValue("@largeur", pvc.Largr);
commandPvc.Parameters.AddWithValue("@longueur", pvc.Longr);
commandPvc.Parameters.AddWithValue("@orientation", pvc.Ortn);
commandPvc.ExecuteNonQuery();
commandPvc = null;
}
// insert datagride mesure
foreach (var msr in fct.Mesures)
{
var commandMesure = new OleDbCommand
{
Connection = connectionClient,
CommandText = "INSERT INTO " +
"mesure(idFacture, quantite, largeur, longueur, eppaiseur) " +
"VALUES(@idFacture, @quantite, @largeur, @longueur, @eppaiseu)"
};
commandMesure.Parameters.AddWithValue("@idFacture", idFACTURE);
commandMesure.Parameters.AddWithValue("@quantite", msr.Quantite);
commandMesure.Parameters.AddWithValue("@largeur", msr.Largeur);
commandMesure.Parameters.AddWithValue("@longueur", msr.Longueur);
commandMesure.Parameters.AddWithValue("@eppaiseu", msr.Epaisseur);
commandMesure.ExecuteNonQuery();
commandMesure = null;
}
}
factures.Clear();
//pvcs.Clear();
//mesures.Clear();
// close connection and desplay message
connectionClient.Close();
}
catch (Exception ex)
{
connectionClient.Close();
LogFile.Message(ex);
}
}
/*
* =========================== End Panel Add Edit Method ===========================
*/
/// <summary>
/// c'est le design du formulaire et l'initialisation de connecter a la base de donnees
/// </summary>
[Obsolete]
public f_main_client()
{
connectionClient.ConnectionString = Program.Path;
InitializeComponent();
}
/// <summary>
/// fiil data gride clients
/// </summary>
private void fill_dt_grid_client(DataTable dataTable)
{
dg_client.Rows.Clear();
// fill datagride
for (int i = 0; i < dataTable.Rows.Count; i++)
{
dg_client.Rows.Add(
String.Format("N{0:D4}", long.Parse(dtb_client.Rows[i][0].ToString())),
dtb_client.Rows[i][1].ToString(),
String.Format("{0}", dtb_client.Rows[i][2].ToString()),
dtb_client.Rows[i][3].ToString(),
"",
dtb_client.Rows[i][4].ToString(),
dtb_client.Rows[i][5].ToString(),
dtb_client.Rows[i][6].ToString(),
dtb_client.Rows[i][7].ToString());
}
}
/// <summary>
/// fill datagride client from database
/// </summary>
private void remplissageDtGridClient()
{
try
{
connectionClient.Open();
dtb_client.Rows.Clear();
dg_client.Rows.Clear();
//clients.Clear();
var commandClient = new OleDbCommand
{
Connection = connectionClient,
CommandText =
"SELECT c.idClient, c.nomClient, dateClient, count(idFacture) AS nbFacture, " +
"IIF(ROUND((sum(f.prixtotalmesure) + sum(prixtotalpvc)), 2) = ROUND((prixTotalAvance), 2), 'true', 'false') AS cavance, " +
"c.prixTotalAvance, " +
"IIF(ROUND((sum(f.prixtotalmesure) + sum(prixtotalpvc)), 2) = ROUND(prixTotalAvance, 2), 0, ROUND((sum(f.prixtotalmesure) + sum(prixtotalpvc)), 2) - ROUND(prixTotalAvance, 2)) AS rest, " +
"ROUND((sum(f.prixtotalmesure) + sum(prixtotalpvc)), 2) AS total " +
"FROM client AS c INNER JOIN facture AS f ON f.idClient = c.idClient " +
"GROUP BY c.idClient, nomClient, dateClient, prixTotalAvance " +
"ORDER BY c.idClient DESC;"
};
dtb_client.Load(commandClient.ExecuteReader());
commandClient = null;
connectionClient.Close();
// fill datagride
fill_dt_grid_client(dtb_client);
// remove selected row
if (dg_client.Rows.Count != 0)
dg_client.Rows[0].Selected = false;
}
catch (Exception ex)
{
connectionClient.Close();
LogFile.Message(ex);
return;
}
}
/// <summary>
/// c'est l'affichage du formulaire client
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
/*remplissage data grid view*/
remplissageDtGridClient();
}
/// <summary>
/// c'est event traitment du button click id pour envoyer ca a l'autre formulaire
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dtGridFacture_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dg_client.Rows.Count <= 0 || e.RowIndex < 0)
return;
idClient = dg_client.Rows[e.RowIndex].Cells[0].Value.ToString().Split('N');
if (e.ColumnIndex == 4 && e.RowIndex < dg_client.Rows.Count)
{
f_avance avance = new f_avance(idClient[1]);
avance.ShowDialog();
// fill datagride
remplissageDtGridClient();
idClient = null;
}
}
/// <summary>
/// c'est button pour imprimer les factures
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[Obsolete]
private void btnPrintFacture_Click(object sender, EventArgs e)
{
if (dg_client.Rows.Count <= 0 || idClient == null)
{
message = new f_message("sélectionner une ligne š'il vous plaît", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
return;
}
//pvc_mesure(idClient[1], indxFacture);
f_print print = new f_print(idClient[1], "null", "btnPrintClient", false);
print.ShowDialog();
// initilize id client
idClient = null;
// remove select row
dg_client.Rows[dg_client.CurrentRow.Index].Selected = false;
}
/// <summary>
/// c'est event chercher a client a partir du date, nom ou id client
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtSearch_TextChanged(object sender, EventArgs e)
{
//txtSearch.CharacterCasing = CharacterCasing.Upper;
if (!string.IsNullOrEmpty(t_search_client.Text))
{
dg_client.Rows.Clear();
for (int i = 0; i < dtb_client.Rows.Count; i++)
{
String id = String.Format("N{0:D4}", long.Parse(dtb_client.Rows[i][0].ToString()));
String dt = String.Format("{0}", dtb_client.Rows[i][2].ToString());
if (dtb_client.Rows[i][1].ToString().Contains(value: t_search_client.Text.ToUpper()) ||
id.Contains(value: t_search_client.Text) ||
dt.Contains(value: t_search_client.Text))
dg_client.Rows.Add(
String.Format("N{0:D4}", long.Parse(dtb_client.Rows[i][0].ToString())),
dtb_client.Rows[i][1].ToString(),
String.Format("{0}", dtb_client.Rows[i][2].ToString()),
dtb_client.Rows[i][3].ToString(),
"",
dtb_client.Rows[i][4].ToString(),
dtb_client.Rows[i][5].ToString(),
dtb_client.Rows[i][6].ToString(),
dtb_client.Rows[i][7].ToString());
}
}
else
{
// fill datagride
fill_dt_grid_client(dtb_client);
}
}
/// <summary>
/// c'est le button qui modifier les factures du client
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void e_Edit_Factures_Click(object sender, EventArgs e)
{
if (checkIsNullOrEmpty())
{
try
{
connectionClient.Open();
var commandF = new OleDbCommand
{
Connection = connectionClient,
CommandText = "UPDATE facture SET " +
" typeDeBois = @typeDeBois" +
", metrage = @metrage" +
", categorie = @categorie" +
", totalMesure = @totalMesure" +
", typeMetres = @typeMetres" +
", prixMetres = @prixMetres" +
", typePVC = @typePVC" +
", checkPVC = @checkPVC" +
", tailleCanto = @tailleCanto" +
", totalTaillPVC = @totalTaillPVC" +
", prixMitresLinear = @prixMitresLinear" +
", prixTotalPVC = @prixTotalPVC" +
", prixTotalMesure = @prixTotalMesure" +
" WHERE idFacture = @idFacture"
};
commandF.Parameters.AddWithValue("@typeDeBois", t_type_Bois.Text);
commandF.Parameters.AddWithValue("@metrage", t_metrage_feuille.Text);
commandF.Parameters.AddWithValue("@categorie", t_categorie.Text);
commandF.Parameters.AddWithValue("@totalMesure", (string.IsNullOrEmpty(t_total_size_mesure.Text) ? 0 : double.Parse(t_total_size_mesure.Text)));
commandF.Parameters.AddWithValue("@typeMetres", cb_type_metres.SelectedItem.ToString());
commandF.Parameters.AddWithValue("@prixMetres", (string.IsNullOrEmpty(t_prix_metre_mesure.Text) ? 0 : double.Parse(t_prix_metre_mesure.Text)));
commandF.Parameters.AddWithValue("@typePVC", (cb_type_pvc.SelectedItem == null ? "---" : cb_type_pvc.SelectedItem));
commandF.Parameters.AddWithValue("@checkPVC", ck_seul_pvc.Checked);
commandF.Parameters.AddWithValue("@tailleCanto", (string.IsNullOrEmpty(t_size_pvc.Text) ? 0 : double.Parse(t_size_pvc.Text)));
commandF.Parameters.AddWithValue("@totalTaillPVC", (string.IsNullOrEmpty(t_total_size_pvc.Text) ? 0 : double.Parse(t_total_size_pvc.Text)));
commandF.Parameters.AddWithValue("@prixMitresLinear", (string.IsNullOrEmpty(t_prix_metre_linear_pvc.Text) ? 0 : double.Parse(t_prix_metre_linear_pvc.Text)));
commandF.Parameters.AddWithValue("@prixTotalPVC", (string.IsNullOrEmpty(t_prix_total_pvc.Text) ? 0 : double.Parse(t_prix_total_pvc.Text)));
commandF.Parameters.AddWithValue("@prixTotalMesure", (string.IsNullOrEmpty(txtPrixTotalMesure.Text) ? 0 : double.Parse(txtPrixTotalMesure.Text)));
commandF.Parameters.AddWithValue("@idFacture", cb_id_facture.Text);
commandF.ExecuteNonQuery();
if (!ck_seul_pvc.Checked && dg_mesure.Rows.Count > 0)
{
var commandMD = new OleDbCommand
{
Connection = connectionClient,
CommandText = "DELETE * FROM mesure WHERE idFacture = @idFacture"
};
commandMD.Parameters.AddWithValue("@idFacture", cb_id_facture.Text);
commandMD.ExecuteNonQuery();
commandMD = null;
for (int i = 0; i < dg_mesure.Rows.Count; i++)
{
var commandM = new OleDbCommand
{
Connection = connectionClient,
CommandText = "INSERT INTO " +
"mesure(idFacture, quantite, largeur, longueur, eppaiseur) " +
"VALUES(@idFacture, @quantite, @largeur, @longueur, @eppaiseur)"
};
commandM.Parameters.AddWithValue("@idFacture", cb_id_facture.Text);
commandM.Parameters.AddWithValue("@quantite", dg_mesure.Rows[i].Cells[0].Value.ToString());
commandM.Parameters.AddWithValue("@largeur", dg_mesure.Rows[i].Cells[1].Value.ToString());
commandM.Parameters.AddWithValue("@longueur", dg_mesure.Rows[i].Cells[2].Value.ToString());
commandM.Parameters.AddWithValue("@eppaiseur", cb_type_metres.SelectedItem.Equals("m3") ? dg_mesure.Rows[i].Cells[3].Value.ToString() : 0.ToString());
commandM.ExecuteNonQuery();
commandM = null;
}
}
if (!String.IsNullOrEmpty(cb_type_pvc.Text))
{
var commandPD = new OleDbCommand
{
Connection = connectionClient,
CommandText = "DELETE * FROM pvc WHERE idFacture = @idFacture"
};
commandPD.Parameters.AddWithValue("@idFacture", cb_id_facture.Text);
commandPD.ExecuteNonQuery();
commandPD = null;
for (int i = 0; i < dg_pvc.Rows.Count; i++)
{
var commandP = new OleDbCommand
{
Connection = connectionClient,
CommandText = "INSERT INTO " +
"pvc(idFacture, quantite, largeur, longueur, orientation) " +
"VALUES(@idFacture, @quantite, @largeur, @longueur, @orientation)"
};
commandP.Parameters.AddWithValue("@idFacture", cb_id_facture.Text);
commandP.Parameters.AddWithValue("@quantite", dg_pvc.Rows[i].Cells[0].Value.ToString());
commandP.Parameters.AddWithValue("@largeur", dg_pvc.Rows[i].Cells[1].Value.ToString());
commandP.Parameters.AddWithValue("@longueur", dg_pvc.Rows[i].Cells[2].Value.ToString());
commandP.Parameters.AddWithValue("@orientation", dg_pvc.Rows[i].Cells[3].Value.ToString());
commandP.ExecuteNonQuery();
commandP = null;
}
}
connectionClient.Close();
// fill edit panel by id facture
loadDataEdit(long.Parse(cb_id_facture.Text));
}
catch (Exception ex)
{
connectionClient.Close();
LogFile.Message(ex);
}
}
}
/// <summary>
/// closing the application
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FormClient_FormClosing(object sender, FormClosingEventArgs e)
{