-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStart.cs
2140 lines (1818 loc) · 80.1 KB
/
Start.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 System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using Vet_Clinic;
using Vet_Clinic.vetclinicDataSetTableAdapters;
namespace Project1
{
public partial class Start : Form
{
// mysql connection string
MySqlConnection connection = new MySqlConnection(utils.MyConString);
// end connection string
public static bool vacExp = false;
public static bool purchaseDates = false;
public static bool customerPurchase = false;
public static bool ramatYohanan = false;
// fill listbox with lase 20 visitors
public void FillNames()
{
listBox1.Items.Clear();
int[] lastCustomers = new int[20];
int i = 0;
MySqlCommand command2 = connection.CreateCommand();
MySqlDataReader Reader2;
command2.CommandText = "SELECT distinct custNum FROM tblvisit ORDER BY vDate desc LIMIT 20";
connection.Open();
Reader2 = command2.ExecuteReader();
while (Reader2.Read())
{
lastCustomers[i] = Reader2.GetInt32(0);
i++;
}
connection.Close();
for (int n = 0; n < 20; n++)
{
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select distinct firstName, lastName, custNum from tblcustomer WHERE custNum = @custNum";
command.Parameters.Add("@custNum", lastCustomers[n]);
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string thisrow = "";
for (int m = 0; m < Reader.FieldCount; m++)
thisrow += Reader.GetValue(m).ToString() + " ";
listBox1.Items.Add(thisrow);
}
connection.Close();
}
}
// fill listbox with all names who has animals
public void FillNames2()
{
listBox1.Items.Clear();
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select distinct firstName, lastName, C.custNum from tblcustomer C INNER JOIN tblanimal A ON C.custNum = A.custNum";
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
listBox1.Items.Add(thisrow);
}
connection.Close();
}
// fill listbox with all names who has animals
public void FillProducts()
{
listBox7.Items.Clear();
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select name from tblProducts";
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
listBox7.Items.Add(thisrow);
}
connection.Close();
}
// removes all tabs but main search tab
public void CloseAllButSearchTab()
{
tabControl1.TabPages.Remove(tabPage2);
tabControl1.TabPages.Remove(tabPage4);
tabControl1.TabPages.Remove(tabPage5);
}
public void ClearSelection()
{
if (comboBox1.Text != "" || textBox3.Text != "" || checkBox1.Checked == true || textBox8.Text != "" || textBox9.Text != "")
{
if (MessageBox.Show("?קיימים נתוני ביקור לא שמורים, האם אתה בטוח שברצונך לצאת", "",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign) == DialogResult.No)
return;
else
{
SwitchCust();
}
}
else
{
SwitchCust();
}
}
public void GetNotifications()
{
textBox11.Text = "";
DateTime today = DateTime.Today;
string formatForMySql = today.ToString("yyyy-MM-dd hh:mm:ss");
this.tblnotificationsTableAdapter.FillByCurrent(this.vetclinicDataSet.tblnotifications, formatForMySql);
}
public Start()
{
utils.StartService("MySQL55", 30000);
checkConn();
InitializeComponent();
FillNames();
CloseAllButSearchTab();
GetNotifications();
label24.Text = DateTime.Today.Date.ToShortDateString();
FillProducts();
}
private void יציאהToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void listBox1_Click(object sender, EventArgs e)
{
label36.Text = "לא נבחרה חיה";
listBox2.Items.Clear();
string custNum = null;
string custName = null;
try
{
custNum = utils.ExtractNumbers(listBox1.SelectedItem.ToString());
label63.Text = custNum;
custName = utils.RemoveDigits(listBox1.SelectedItem.ToString());
label35.Text = custName;
this.tblcustomerTableAdapter.FillByCustNum(this.vetclinicDataSet.tblcustomer, int.Parse(label63.Text));
}
catch (Exception exc)
{
// MessageBox.Show("חובה לבחור לקוח", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
CloseAllButSearchTab();
if (listBox1.SelectedIndex != -1)
tabControl1.TabPages.Add(tabPage4);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select aName from tblanimal where custNum = '" + custNum + "'";
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
listBox2.Items.Add(thisrow);
}
connection.Close();
}
private void button1_Click(object sender, EventArgs e)
{
ClearSelection();
}
// Search by costumer number
private void textBox5_TextChanged(object sender, EventArgs e)
{
textBox7.Text = "";
textBox6.Text = "";
textBox2.Text = "";
textBox1.Text = "";
textBox4.Text = "";
listBox2.Items.Clear();
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select firstName, lastName, custNum from tblcustomer where custNum LIKE @param";
command.Parameters.AddWithValue("@param", textBox5.Text + "%");
connection.Open();
Reader = command.ExecuteReader();
listBox1.Items.Clear();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
listBox1.Items.Add(thisrow);
}
connection.Close();
}
// search by costumer first name
private void textBox1_TextChanged(object sender, EventArgs e)
{
listBox2.Items.Clear();
if (textBox2.Text == "")
{
textBox7.Text = "";
textBox6.Text = "";
textBox5.Text = "";
textBox2.Text = "";
textBox4.Text = "";
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select firstName, lastName, custNum from tblcustomer where firstName LIKE @param";
command.Parameters.AddWithValue("@param", textBox1.Text + "%");
connection.Open();
Reader = command.ExecuteReader();
listBox1.Items.Clear();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
listBox1.Items.Add(thisrow);
}
connection.Close();
}
else
{
textBox7.Text = "";
textBox6.Text = "";
textBox5.Text = "";
textBox4.Text = "";
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select firstName, lastName, custNum from tblcustomer where firstName LIKE @param and lastName like @param2";
command.Parameters.AddWithValue("@param", textBox1.Text + "%");
command.Parameters.AddWithValue("@param2", textBox2.Text + "%");
connection.Open();
Reader = command.ExecuteReader();
listBox1.Items.Clear();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
listBox1.Items.Add(thisrow);
}
connection.Close();
}
}
// search by street name
private void textBox4_TextChanged(object sender, EventArgs e)
{
listBox2.Items.Clear();
textBox7.Text = "";
textBox6.Text = "";
textBox5.Text = "";
textBox2.Text = "";
textBox1.Text = "";
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select firstName, lastName, custNum from tblcustomer where address LIKE @param";
command.Parameters.AddWithValue("@param", "%" + textBox4.Text + "%");
connection.Open();
Reader = command.ExecuteReader();
listBox1.Items.Clear();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
listBox1.Items.Add(thisrow);
}
connection.Close();
}
// search by phone number (either cell or home is ok)
private void textBox6_TextChanged(object sender, EventArgs e)
{
listBox2.Items.Clear();
textBox7.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox2.Text = "";
textBox1.Text = "";
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select firstName, lastName, custNum from tblcustomer where homePhone LIKE @param or cellPhone like @param";
command.Parameters.AddWithValue("@param", textBox6.Text + "%");
connection.Open();
Reader = command.ExecuteReader();
listBox1.Items.Clear();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
listBox1.Items.Add(thisrow);
}
connection.Close();
}
//search by last name
private void textBox2_TextChanged(object sender, EventArgs e)
{
listBox2.Items.Clear();
if (textBox1.Text == "")
{
textBox7.Text = "";
textBox6.Text = "";
textBox5.Text = "";
textBox4.Text = "";
textBox1.Text = "";
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select firstName, lastName, custNum from tblcustomer where lastName LIKE @param";
command.Parameters.AddWithValue("@param", textBox2.Text + "%");
connection.Open();
Reader = command.ExecuteReader();
listBox1.Items.Clear();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
listBox1.Items.Add(thisrow);
}
connection.Close();
}
else
{
textBox7.Text = "";
textBox6.Text = "";
textBox5.Text = "";
textBox4.Text = "";
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select firstName, lastName, custNum from tblcustomer where firstName LIKE @param and lastName like @param2";
command.Parameters.AddWithValue("@param", textBox1.Text + "%");
command.Parameters.AddWithValue("@param2", textBox2.Text + "%");
connection.Open();
Reader = command.ExecuteReader();
listBox1.Items.Clear();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
listBox1.Items.Add(thisrow);
}
connection.Close();
}
}
private void textBox7_TextChanged(object sender, EventArgs e)
{
tabControl1.TabPages.Remove(tabPage2);
tabPage2.Refresh();
tabControl1.TabPages.Remove(tabPage4);
listBox1.Items.Clear();
label35.Text = "";
label63.Text = "";
textBox2.Text = "";
textBox6.Text = "";
textBox5.Text = "";
textBox4.Text = "";
textBox1.Text = "";
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select distinct aName from tblanimal where chipNum LIKE @param";
command.Parameters.AddWithValue("@param", textBox7.Text + "%");
connection.Open();
Reader = command.ExecuteReader();
listBox2.Items.Clear();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString();
listBox2.Items.Add(thisrow);
}
connection.Close();
}
private void listBox2_Click(object sender, EventArgs e)
{
try
{
if (label36.Text != null)
label36.Text = listBox2.SelectedItem.ToString();
tabControl1.TabPages.Remove(tabPage2);
if (listBox1.SelectedIndex != -1)
tabControl1.TabPages.Add(tabPage2);
}
catch (Exception exc)
{
// MessageBox.Show("חובה לבחור חיה", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (listBox1.SelectedIndex == -1)
{
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select custNum from tblanimal where chipNum LIKE @param and aName = @param2";
command.Parameters.AddWithValue("@param", textBox7.Text + "%");
command.Parameters.AddWithValue("@param2", listBox2.SelectedItem);
connection.Open();
List<String> custNum = new List<String>();
Reader = command.ExecuteReader();
listBox1.Items.Clear();
while (Reader.Read())
{
for (int i = 0; i < Reader.FieldCount; i++)
custNum.Add(Reader.GetValue(i).ToString());
}
connection.Close();
MySqlCommand command2 = connection.CreateCommand();
MySqlDataReader Reader2;
listBox1.Items.Clear();
for (int j = 0; j < custNum.Count; j++)
{
connection.Open();
command2.CommandText = "select firstName, lastName, custNum from tblcustomer where custNum = '" +
custNum[j] + "'";
Reader2 = command2.ExecuteReader();
while (Reader2.Read())
{
string thisrow = "";
for (int i = 0; i < Reader2.FieldCount; i++)
thisrow += Reader2.GetValue(i).ToString() + " ";
listBox1.Items.Add(thisrow);
}
connection.Close();
}
}
else
{
if (label63.Text != "לא נבחר לקוח" && label63.Text != "")
{
// TODO: This line of code loads data into the 'vetclinicDataSet.tblanimal' table. You can move, or remove it, as needed.
this.tblanimalTableAdapter.FillByDetails(this.vetclinicDataSet.tblanimal, int.Parse(label63.Text), label36.Text);
this.tblvisitTableAdapter.FillByCustAnimal(this.vetclinicDataSet.tblvisit, int.Parse(label63.Text), label36.Text);
//vDetailsTextBox.Enabled = false;
getInsDate();
checkBox1.CheckState = CheckState.Unchecked;
lastVacs lv = new lastVacs(Int32.Parse(label63.Text), label36.Text, this);
lv.Close();
if (label36.Text != "לא נבחרה חיה" && label36.Text != "")
{
updateAge();
vetclinicDataSet.tblanimalRow custRow;
custRow = vetclinicDataSet.tblanimal.FindBycustNumaName(int.Parse(label63.Text), label36.Text);
if (custRow.dateNeu.ToShortDateString() == "01/01/1950")
dateNeuDateTimePicker.Hide();
else dateNeuDateTimePicker.Visible = true;
}
}
}
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
if (listBox1.SelectedIndex != -1)
tabControl1.SelectedTab = tabPage4;
}
private void button6_Click(object sender, EventArgs e)
{
ClearSelection();
if (edit)
{
button9.Text = "שמירה";
edit = false;
}
}
private void button5_Click(object sender, EventArgs e)
{
EditCostumer ec = new EditCostumer(this, int.Parse(label63.Text));
ec.Visible = true;
}
private void listBox2_DoubleClick(object sender, EventArgs e)
{
if (listBox2.SelectedIndex != -1)
tabControl1.SelectedTab = tabPage2;
}
private void checkConn() //checks if the connection is ok
{
try
{
connection.Open();
}
catch (Exception exc)
{
MessageBox.Show("לא ניתן להתחבר לבסיס הנתונים", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(0);
}
finally
{
connection.Close();
}
}
private void button3_Click(object sender, EventArgs e)
{
ClearSelection();
textBox7.Text = "";
textBox6.Text = "";
textBox5.Text = "";
textBox2.Text = "";
textBox1.Text = "";
textBox4.Text = "";
listBox2.Items.Clear();
CloseAllButSearchTab();
FillNames();
}
private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
{
long maxVisit = 0;
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "SELECT MAX(vNum) as lastV FROM tblVisit";
connection.Open();
String temp = command.ExecuteScalar().ToString();
if (temp == "")
maxVisit = 1;
else
maxVisit = Int64.Parse(temp) + 1;
connection.Close();
maxVisit++;
vNumLabel1.Text = maxVisit.ToString();
}
public void clearVisit()
{
comboBox1.SelectedIndex = -1;
textBox3.Text = "";
checkBox1.Checked = false;
textBox8.Text = "";
textBox9.Text = "";
}
private void button4_Click(object sender, EventArgs e)
{
if (edit)
{
edit = false;
bindingNavigatorMoveNextItem1.Enabled = true;
bindingNavigatorMovePreviousItem1.Enabled = true;
bindingNavigatorMoveFirstItem1.Enabled = true;
bindingNavigatorMoveLastItem1.Enabled = true;
}
clearVisit();
EnableSearch();
button9.Text = "שמירה";
}
private void button9_Click(object sender, EventArgs e)
{
string errors = ":שגיאה! פרטים שגויים או חסרים פרטים";
errors += "\n";
Boolean errorFound = false;
double result;
if (comboBox1.SelectedIndex == -1)
{
errors += "\n";
errors += "חובה לבחור סיבה לביקור";
errorFound = true;
}
//if (textBox9.Text == "")
//{
// errors += "\n";
// errors += "חובה להזין פרטי טיפול";
// errorFound = true;
//}
if (textBox8.Text != "")
{
if (!double.TryParse(textBox8.Text, out result))
{
errors += "\n";
errors += "מחיר חייב להיות מספר";
errorFound = true;
}
}
if (textBox3.Text != "")
{
if (double.TryParse(textBox3.Text, out result))
if (double.Parse(textBox3.Text) > 99 || double.Parse(textBox3.Text) < 0)
{
errors += "\n";
errors += "משקל לא תקין";
errorFound = true;
}
}
if (textBox3.Text != "")
{
if (!double.TryParse(textBox3.Text, out result))
{
errors += "\n";
errors += "משקל חייב להיות מספר";
errorFound = true;
}
}
if (errorFound)
MessageBox.Show(errors);
else
{
if (!edit)
{
long maxVisit = 0;
MySqlCommand command2 = connection.CreateCommand();
MySqlDataReader Reader;
command2.CommandText = "SELECT MAX(vNum) as lastV FROM tblVisit";
connection.Open();
String temp = command2.ExecuteScalar().ToString();
if (temp == "")
maxVisit = 1;
else
maxVisit = Int64.Parse(temp) + 1;
connection.Close();
double weight;
if (textBox3.Text == "")
weight = 0;
else
weight = double.Parse(textBox3.Text);
double price;
if (textBox8.Text == "")
price = 0;
else
price = double.Parse(textBox8.Text);
MySqlCommand command = connection.CreateCommand();
command.CommandText = "INSERT INTO tblVisit (Vnum, custNum, aName, vDate, vDetails, vaccine, weight, paymentStatus, reason, price) Values (@vNum, @custNum, @aName, @vDate, @vDetails, @vaccine, @weight, @paymentStatus, @reason, @price)";
command.Parameters.AddWithValue("@vNum", maxVisit);
command.Parameters.AddWithValue("@custNum", label63.Text);
command.Parameters.AddWithValue("@aName", label36.Text);
command.Parameters.AddWithValue("@vDate", DateTime.Now);
command.Parameters.AddWithValue("@vDetails", textBox9.Text);
command.Parameters.AddWithValue("@vaccine", checkBox1.Checked);
command.Parameters.AddWithValue("@weight", weight);
command.Parameters.AddWithValue("@paymentStatus", 0);
command.Parameters.AddWithValue("@reason", comboBox1.Text);
command.Parameters.AddWithValue("@price", price);
connection.Open();
command.ExecuteReader();
connection.Close();
clearVisit();
EnableSearch();
this.tblvisitTableAdapter.FillByCustAnimal(this.vetclinicDataSet.tblvisit, int.Parse(label63.Text), label36.Text);
OpenBasket(int.Parse(label63.Text));
}
else
{
edit = false;
double weight2;
if (textBox3.Text == "")
weight2 = 0;
else
weight2 = double.Parse(textBox3.Text);
double price2;
if (textBox8.Text == "")
price2 = 0;
else
price2 = double.Parse(textBox8.Text);
vetclinicDataSet.tblvisitRow upVis;
upVis = vetclinicDataSet.tblvisit.FindByvNumcustNumaName(Int64.Parse(vNumLabel1.Text),
int.Parse(label63.Text), label36.Text);
upVis.reason = comboBox1.Text;
upVis.weight = weight2;
upVis.vaccine = checkBox1.Checked;
upVis.price = price2;
upVis.vDetails = textBox9.Text;
this.tblvisitTableAdapter.Update(this.vetclinicDataSet.tblvisit);
button9.Text = "שמירה";
clearVisit();
EnableSearch();
bindingNavigatorMoveNextItem1.Enabled = true;
bindingNavigatorMovePreviousItem1.Enabled = true;
bindingNavigatorMoveFirstItem1.Enabled = true;
bindingNavigatorMoveLastItem1.Enabled = true;
label52.Text = this.tblvisitTableAdapter.ScalarQueryTreatPay(int.Parse(label63.Text)).ToString();
this.tblvisitTableAdapter.FillByCustAnimal(this.vetclinicDataSet.tblvisit, int.Parse(label63.Text), label36.Text);
}
}
}
//adds a vaccine to tblgivenvaccine
private void addVac(string vacType, long maxVisit)
{
MySqlCommand command4 = connection.CreateCommand();
command4.CommandText =
"INSERT INTO tblgivenvaccine (aName, Vnum, custNum, type, dateGiven) Values (@aName, @vNum, @custNum, @type, @dateGiven)";
command4.Parameters.AddWithValue("@aName", label36.Text);
command4.Parameters.AddWithValue("@vNum", maxVisit);
command4.Parameters.AddWithValue("@custNum", label63.Text);
command4.Parameters.AddWithValue("@type", vacType);
command4.Parameters.AddWithValue("@dateGiven", DateTime.Now);
connection.Open();
command4.ExecuteReader();
connection.Close();
this.tblgivenvaccineTableAdapter.FillByvNum(this.vetclinicDataSet.tblgivenvaccine, maxVisit);
}
private void pictureBox2_Click(object sender, EventArgs e)
{
}
private void button10_Click(object sender, EventArgs e)
{
if (label63.Text == "לא נבחר לקוח" || label63.Text == "")
MessageBox.Show("חובה לבחור לקוח", "שגיאה");
else
{
AddAnimal aa = new AddAnimal(int.Parse(label63.Text), this);
aa.Visible = true;
}
}
private void button2_Click(object sender, EventArgs e)
{
editAnimal ea = new editAnimal(int.Parse(label63.Text), label36.Text, this);
ea.Visible = true;
}
private void button11_Click(object sender, EventArgs e)
{
addCustomer ac = new addCustomer(this);
ac.Visible = true;
}
private void button13_Click(object sender, EventArgs e)
{
if (vNumLabel1.Text != "" && vNumLabel1.Text != "label6")
{
viewVac vv = new viewVac(long.Parse(vNumLabel1.Text));
vv.Visible = true;
}
}
private void button14_Click(object sender, EventArgs e)
{
if (MessageBox.Show("?האם להזין חבילת בריאות", "",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
else
{
MySqlCommand command = connection.CreateCommand();
command.CommandText =
"INSERT INTO tblinsurance Values (@custNum, @aName, @fromDate, @toDate)";
command.Parameters.AddWithValue("@custNum", int.Parse(label63.Text));
command.Parameters.AddWithValue("@aName", label36.Text);
command.Parameters.AddWithValue("@fromDate", DateTime.Now);
command.Parameters.AddWithValue("@toDate", DateTime.Now.AddYears(1));
connection.Open();
command.ExecuteReader();
connection.Close();
MessageBox.Show("חבילה הוזנה בהצלחה");
getInsDate();
}
}
//gets the date when the insurance expires
public void getInsDate()
{
label11.Text = "";
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select MAX(toDate) from tblinsurance where custNum = @custNum AND aName = @aName";
command.Parameters.AddWithValue("@custNum", int.Parse(label63.Text));
command.Parameters.AddWithValue("@aName", label36.Text);
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
if (thisrow != " ")
{
DateTime theDate = DateTime.Parse(thisrow);
string theShortDate = theDate.ToShortDateString();
label11.Text = theShortDate;
if (theDate < DateTime.Now)
label11.Visible = false;
else
{
label11.Visible = true;
label11.ForeColor = Color.Navy;
}
}
}
connection.Close();
}
private void יציאהToolStripMenuItem_Click_1(object sender, EventArgs e)
{
utils.StopService("MySQL55", 20000);
this.Close();
}
private void button15_Click(object sender, EventArgs e)
{
enterVac2 ev2 = new enterVac2(Int32.Parse(label63.Text), label36.Text, this);
ev2.Visible = true;
checkBox1.Checked = true;
}
private void button3_Click_1(object sender, EventArgs e)
{
lastVacs lv = new lastVacs(Int32.Parse(label63.Text), label36.Text, this);
lv.Visible = true;
}
private void דוחללקוחToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void כלבתToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void רשיוןלכלבToolStripMenuItem_Click(object sender, EventArgs e)
{
if (label63.Text == "לא נבחר לקוח" || label36.Text == "לא נבחרה חיה")
{
MessageBox.Show("חובה לבחור לקוח וחיה", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
CrystalDecisions.CrystalReports.Engine.ReportDocument report =
new CrystalDecisions.CrystalReports.Engine.ReportDocument();
report.Load(@"" + utils.crys + "rabies.rpt");
CrystalDecisions.Shared.ParameterField parameterField;
parameterField = report.ParameterFields["custNum"];
parameterField.CurrentValues.AddValue(label63.Text);
CrystalDecisions.Shared.ParameterField parameterField2;
parameterField2 = report.ParameterFields["aName"];
parameterField2.CurrentValues.AddValue(label36.Text);
kalevetRpt kr = new kalevetRpt();
kr.setReport(report);
kr.ShowDialog();
}
}
public void updateAge()
{
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "SELECT dateOfBirth FROM tblAnimal WHERE custNum = @cNum AND aName = @aName";
command.Parameters.AddWithValue("cNum", label63.Text);
command.Parameters.AddWithValue("aName", label36.Text);
connection.Open();
String temp = command.ExecuteScalar().ToString();
DateTime DOB = DateTime.Parse(temp);
DateTime now = DateTime.Now;
int age = now.Year - DOB.Year;
if (now < DOB.AddYears(age)) age--;
label18.Text = age.ToString();
connection.Close();
}
private void tabPage2_Click(object sender, EventArgs e)
{
}
private void מחיקתתיקלקוחToolStripMenuItem_Click(object sender, EventArgs e)
{
if (label63.Text == "לא נבחר לקוח")
{
MessageBox.Show("חובה לבחור לקוח", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string text = "האם אתה בטוח שברצונך למחוק את לקוח מספר ";
text += label63.Text;
text += " מהמערכת?";
text += "\n";
text += "פעולה זאת לא ניתנת לביטול";
if (MessageBox.Show(text, "",
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign) == DialogResult.No)
return;
else
{
vetclinicDataSet.tblcustomerRow custRow;
custRow = vetclinicDataSet.tblcustomer.FindBycustNum(int.Parse(label63.Text));
custRow.Delete();
this.tblcustomerTableAdapter.Update(this.vetclinicDataSet.tblcustomer);
string text2 = "לקוח מספר ";
text2 += label63.Text;
text2 += " נמחק בהצלחה מהמערכת";
MessageBox.Show(text2);
ClearSelection();