-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
457 lines (392 loc) · 19.1 KB
/
Form1.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ZleceniaMalarnia
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int selectedID;
bool PrzyciskSzukaj = false;
string SumaCalkowita = "pusty";
string SumaZaplaconych = "pusty";
string SumaNieZaplaconych = "pusty";
MalarniaDBDataSetTableAdapters.ZleceniaTableAdapter TabelaZlecenia = new MalarniaDBDataSetTableAdapters.ZleceniaTableAdapter();
MalarniaDBDataSetTableAdapters.ProduktyTableAdapter ProduktyTable = new MalarniaDBDataSetTableAdapters.ProduktyTableAdapter();
private void Form1_Load(object sender, EventArgs e)
{
OdswierzDaneWtabeli();
szukajCBox.SelectedIndex = 0;
}
private void noweZlButton_Click(object sender, EventArgs e)
{
if (System.Windows.Forms.Application.OpenForms["ListaKlientowForm"] as ListaKlientowForm != null)
{
MessageBox.Show("Zakończ wybór klienta");
return;
}
if (System.Windows.Forms.Application.OpenForms["Form2"] as Form2 != null)
{
MessageBox.Show("Zakończ dodawanie nowych produktów");
return;
}
if (System.Windows.Forms.Application.OpenForms["LKlientForm"] as LKlientForm != null)
{
MessageBox.Show("Zamknij listę klientów");
return;
}
if (System.Windows.Forms.Application.OpenForms["Form2"] as Form2 == null && System.Windows.Forms.Application.OpenForms["ListaKlientowForm"] as ListaKlientowForm == null && System.Windows.Forms.Application.OpenForms["LKlientForm"] as LKlientForm == null)
{
var form3 = new ListaKlientowForm();
form3.Show();
}
}
public string utworzNoweZlecenie(string Klient, int idKlienta)
{
DateTime obecznyczas = DateTime.Now;
zleceniaTableAdapter.InsertQueryZlecenia(Klient, obecznyczas.ToString(), 0, 0, "", idKlienta, NadajNrZlecenia());
string ostatnieID = zleceniaTableAdapter.getOstatnieId().ToString();
Debug.WriteLine("Aktualne Id FORM1:" + ostatnieID);
//NadajNrZlecenia();
return ostatnieID;
}
private void usunButton_Click(object sender, EventArgs e)
{
int selectedRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);
if (selectedRowCount > 0 && selectedID > 0)
{
DialogResult dialogResult = MessageBox.Show("Czy napewno usunąć?", "Usuń", MessageBoxButtons.YesNo);//tu mozna jescze dodac ikone okienka, po message box buttons
if (dialogResult == DialogResult.Yes)
{
string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
Int32.TryParse(id, out selectedID);
TabelaZlecenia.DeleteQueryZlecenia(selectedID);
ProduktyTable.DeleteQueryProduktyNrZlecenia(selectedID);
SprawdzCzyByloCosWyszukiwane();
}
else if (dialogResult == DialogResult.No)
{
SprawdzCzyByloCosWyszukiwane();
return;
}
}
}
private void dataGridCellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1) // ignore header row and any column
return;
string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
Int32.TryParse(id, out selectedID);
}
private void EdytujZlecenieDoubleCellClickEvent(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1) // ignore header row and any column
return;
string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
Int32.TryParse(id, out selectedID);
int? idKlienta = TabelaZlecenia.getIdKlientaZlecenia(selectedID);
Debug.WriteLine("idKlienta:" + idKlienta + "IdZlecenia" + selectedID);
var EdytujZlecenieForm = new EdytujZlecenieForm();
EdytujZlecenieForm.Show();
var EdytujZlecenieOpenForm = Application.OpenForms.OfType<EdytujZlecenieForm>().FirstOrDefault();
EdytujZlecenieOpenForm.SetKlientaINrZlecenia(idKlienta, selectedID);
}
public void OdswierzDaneWtabeli()
{
dataGridView1.DataSource = TabelaZlecenia.GetData();
if (PrzyciskSzukaj)
{
dataGridView1.Sort(dataGridView1.Columns[5], ListSortDirection.Ascending);
}
else
{
dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Descending);
}
KolorujWiersze();
}
private void KolorujWiersze()
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (Convert.ToInt32(row.Cells[5].Value) == 10)
{
row.DefaultCellStyle.BackColor = Color.Green;
}
if (Convert.ToInt32(row.Cells[5].Value) == 5)
{
row.DefaultCellStyle.BackColor = Color.Orange;
}
}
}
private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
KolorujWiersze();
}
private void button1_Click(object sender, EventArgs e)//ListaKlientow Button
{
if (System.Windows.Forms.Application.OpenForms["LKlientForm"] as LKlientForm != null)
{
MessageBox.Show("Zamknij listę klientów");
return;
}
if (System.Windows.Forms.Application.OpenForms["Form2"] as Form2 == null && System.Windows.Forms.Application.OpenForms["ListaKlientowForm"] as ListaKlientowForm == null && System.Windows.Forms.Application.OpenForms["LKlientForm"] as LKlientForm == null)
{
var Lkientow = new LKlientForm();
Lkientow.Show();
}
}
private void zakonczButton_Click(object sender, EventArgs e)
{
TabelaZlecenia.SetStatusZlecenia(10, selectedID);
SprawdzCzyByloCosWyszukiwane();
}
private void trwaButton_Click(object sender, EventArgs e)
{
TabelaZlecenia.SetStatusZlecenia(0, selectedID);
SprawdzCzyByloCosWyszukiwane();
}
private void WZButton_Click(object sender, EventArgs e)
{
if (selectedID > 0)
{
if (System.Windows.Forms.Application.OpenForms["Form4"] as Form4 != null)
{
MessageBox.Show("Zamknij aktualna WZ");
return;
}
if (System.Windows.Forms.Application.OpenForms["Form2"] as Form2 == null && System.Windows.Forms.Application.OpenForms["ListaKlientowForm"] as ListaKlientowForm == null && System.Windows.Forms.Application.OpenForms["LKlientForm"] as LKlientForm == null)
{
DateTime obecznyczas = DateTime.Now;
TabelaZlecenia.SetDataZakonczeniaZlecenia(obecznyczas.ToString(), selectedID);
SprawdzCzyByloCosWyszukiwane();
var form4 = new Form4();
form4.Show();
var wzForm = Application.OpenForms.OfType<Form4>().FirstOrDefault();
wzForm.utworzWZ(selectedID);
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (szukajCBox.SelectedItem.ToString() == "Klient")
{
dataGridView1.DataSource = TabelaZlecenia.GetDataBySzukajKlient('%' + textBox1.Text + '%');
SumaCalkowita = TabelaZlecenia.GetSumaKlient('%' + textBox1.Text + '%').ToString();
SumaZaplaconych = TabelaZlecenia.GetSumaKlientZaplacone('%' + textBox1.Text + '%').ToString();
SumaNieZaplaconych = TabelaZlecenia.GetSumaKlientNieZaplaconych('%' + textBox1.Text + '%').ToString();
}
if (szukajCBox.SelectedItem.ToString() == "Data Przyjęcia")
{
dataGridView1.DataSource = TabelaZlecenia.GetSzukajDataPrzyjecia('%' + textBox1.Text + '%');
SumaCalkowita = TabelaZlecenia.GetSumaDataPrzyjecia('%' + textBox1.Text + '%').ToString();
SumaZaplaconych = TabelaZlecenia.GetSumaDataPrzyjeciaZaplacone('%' + textBox1.Text + '%').ToString();
SumaNieZaplaconych = TabelaZlecenia.GetSumaDataPrzyjeciaNieZaplaconych('%' + textBox1.Text + '%').ToString();
}
if (szukajCBox.SelectedItem.ToString() == "Data Zakończenia")
{
dataGridView1.DataSource = TabelaZlecenia.GetSzukajDataZakonczenia('%' + textBox1.Text + '%');
SumaCalkowita = TabelaZlecenia.GetSumaDataZakonczenia('%' + textBox1.Text + '%').ToString();
SumaZaplaconych = TabelaZlecenia.GetSumaDataZakonczeniaZaplacone('%' + textBox1.Text + '%').ToString();
SumaNieZaplaconych = TabelaZlecenia.GetSumaDataZakonczeniaNieZaplaconych('%' + textBox1.Text + '%').ToString();
}
if (szukajCBox.SelectedItem.ToString() == "ID")
{
int ID;
if (Int32.TryParse(textBox1.Text, out ID))
{
dataGridView1.DataSource = TabelaZlecenia.GetSzukajID(ID);
}
}
if (szukajCBox.SelectedItem.ToString() == "Nr Zlecenia")
{
dataGridView1.DataSource = TabelaZlecenia.GetSzukajNrZlecenia('%' + textBox1.Text + '%');
SumaCalkowita = TabelaZlecenia.GetSumaNrZlecenia('%' + textBox1.Text + '%').ToString();
SumaZaplaconych = TabelaZlecenia.GetSumaNrZleceniaZaplacone('%' + textBox1.Text + '%').ToString();
SumaNieZaplaconych = TabelaZlecenia.GetSumaNrZleceniaNieZaplaconych('%' + textBox1.Text + '%').ToString();
}
if (String.IsNullOrWhiteSpace(textBox1.Text))
{
OdswierzDaneWtabeli();
}
SzukajNieZaplaconychOnOff(false);
KolorujWiersze();
}
private void rachunekButton_Click(object sender, EventArgs e)
{
if (selectedID > 0)
{
if (System.Windows.Forms.Application.OpenForms["RachunekForm"] as RachunekForm != null)
{
MessageBox.Show("Zamknij aktualny Rachunek");
return;
}
if (System.Windows.Forms.Application.OpenForms["Form2"] as Form2 == null && System.Windows.Forms.Application.OpenForms["ListaKlientowForm"] as ListaKlientowForm == null && System.Windows.Forms.Application.OpenForms["LKlientForm"] as LKlientForm == null)
{
DateTime obecznyczas = DateTime.Now;
TabelaZlecenia.SetDataZakonczeniaZlecenia(obecznyczas.ToString(), selectedID);
SprawdzCzyByloCosWyszukiwane();
var rachunekForm = new RachunekForm();
rachunekForm.Show();
var rachunekForm1 = Application.OpenForms.OfType<RachunekForm>().FirstOrDefault();
rachunekForm.utworzRachunek(selectedID);
}
}
}
private string NadajNrZlecenia()
{
string rok = DateTime.Now.Year.ToString();
string miesiac = DateTime.Now.Month.ToString();
Debug.WriteLine("Czas Rok i Miesiac: " + rok + miesiac);
int? LiczbaZlecen = zleceniaTableAdapter.CountNrZlecenia('%' + rok + "/" + miesiac + '%');
Debug.WriteLine("Liczba zlecen pierwsze sprawdzenie: " + LiczbaZlecen);
if (LiczbaZlecen == 0 || LiczbaZlecen == null)
{
string nrZlecenia = "ZL/" + rok + "/" + miesiac + "/1";
Debug.WriteLine("Brak innych zlecen: " + nrZlecenia);
return nrZlecenia;
//zleceniaTableAdapter.InsertNRZlecenia("ZL/" + rok + "/" + miesiac + "/1");
}
else
{
string NrZlecenia = "ZL/" + rok + "/" + miesiac + "/" + LiczbaZlecen;
Debug.WriteLine("Liczba zlecen wieksza od 0 i nie null: " + LiczbaZlecen);
//zleceniaTableAdapter.InsertNRZlecenia(NrZlecenia);
int? licznik = zleceniaTableAdapter.CountNrZlecenia('%' + NrZlecenia + '%');
int? tester = LiczbaZlecen;
while (licznik >= 1)
{
Debug.WriteLine("Pętla ucruchomiona: " + tester);
tester++;
NrZlecenia = "ZL/" + rok + "/" + miesiac + "/" + tester;
//zleceniaTableAdapter.InsertNRZlecenia(NrZlecenia);
licznik = zleceniaTableAdapter.CountNrZlecenia('%' + NrZlecenia + '%');
}
return NrZlecenia;
}
}
private void SzukajNiezaplaconychButton_Click(object sender, EventArgs e)
{
if (!PrzyciskSzukaj)
{
SzukajNieZaplaconychOnOff(true);
KolorujWiersze();
}
else
{
SzukajNieZaplaconychOnOff(false);
SprawdzCzyByloCosWyszukiwane();
}
}
private void fakturaButton_Click(object sender, EventArgs e)
{
TabelaZlecenia.SetStatusZlecenia(5, selectedID);
SprawdzCzyByloCosWyszukiwane();
}
public void SprawdzCzyByloCosWyszukiwane()
{
if (string.IsNullOrWhiteSpace(textBox1.Text))
{
OdswierzDaneWtabeli();
}
else
{
//OdswierzDaneWtabeli();
if (szukajCBox.SelectedItem.ToString() == "Klient")
{
dataGridView1.DataSource = TabelaZlecenia.GetDataBySzukajKlient('%' + textBox1.Text + '%');
SumaCalkowita = TabelaZlecenia.GetSumaKlient('%' + textBox1.Text + '%').ToString();
SumaZaplaconych = TabelaZlecenia.GetSumaKlientZaplacone('%' + textBox1.Text + '%').ToString();
SumaNieZaplaconych = TabelaZlecenia.GetSumaKlientNieZaplaconych('%' + textBox1.Text + '%').ToString();
}
if (szukajCBox.SelectedItem.ToString() == "Data Przyjęcia")
{
dataGridView1.DataSource = TabelaZlecenia.GetSzukajDataPrzyjecia('%' + textBox1.Text + '%');
SumaCalkowita = TabelaZlecenia.GetSumaDataPrzyjecia('%' + textBox1.Text + '%').ToString();
SumaZaplaconych = TabelaZlecenia.GetSumaDataPrzyjeciaZaplacone('%' + textBox1.Text + '%').ToString();
SumaNieZaplaconych = TabelaZlecenia.GetSumaDataPrzyjeciaNieZaplaconych('%' + textBox1.Text + '%').ToString();
}
if (szukajCBox.SelectedItem.ToString() == "Data Zakończenia")
{
dataGridView1.DataSource = TabelaZlecenia.GetSzukajDataZakonczenia('%' + textBox1.Text + '%');
SumaCalkowita = TabelaZlecenia.GetSumaDataZakonczenia('%' + textBox1.Text + '%').ToString();
SumaZaplaconych = TabelaZlecenia.GetSumaDataZakonczeniaZaplacone('%' + textBox1.Text + '%').ToString();
SumaNieZaplaconych = TabelaZlecenia.GetSumaDataZakonczeniaNieZaplaconych('%' + textBox1.Text + '%').ToString();
}
if (szukajCBox.SelectedItem.ToString() == "ID")
{
int ID;
if (Int32.TryParse(textBox1.Text, out ID))
{
dataGridView1.DataSource = TabelaZlecenia.GetSzukajID(ID);
}
}
if (szukajCBox.SelectedItem.ToString() == "Nr Zlecenia")
{
dataGridView1.DataSource = TabelaZlecenia.GetSzukajNrZlecenia('%' + textBox1.Text + '%');
SumaCalkowita = TabelaZlecenia.GetSumaNrZlecenia('%' + textBox1.Text + '%').ToString();
SumaZaplaconych = TabelaZlecenia.GetSumaNrZleceniaZaplacone('%' + textBox1.Text + '%').ToString();
SumaNieZaplaconych = TabelaZlecenia.GetSumaNrZleceniaNieZaplaconych('%' + textBox1.Text + '%').ToString();
}
if (PrzyciskSzukaj)
{
dataGridView1.Sort(dataGridView1.Columns[5], ListSortDirection.Ascending);
KolorujWiersze();
}
else
{
dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Descending);
KolorujWiersze();
}
}
}
private void raportButton_Click(object sender, EventArgs e)
{
if (selectedID > 0)
{
if (System.Windows.Forms.Application.OpenForms["Form5"] as Form5 != null)
{
MessageBox.Show("Zamknij aktualny Raport");
return;
}
if (System.Windows.Forms.Application.OpenForms["Form2"] as Form2 == null && System.Windows.Forms.Application.OpenForms["ListaKlientowForm"] as ListaKlientowForm == null && System.Windows.Forms.Application.OpenForms["LKlientForm"] as LKlientForm == null)
{
if (string.IsNullOrWhiteSpace(textBox1.Text))
{
SumaCalkowita = TabelaZlecenia.GetSumaWszystkichZlecen().ToString();
SumaNieZaplaconych = TabelaZlecenia.GetSumaWszystkichZleNieZaplaconych().ToString();
SumaZaplaconych = TabelaZlecenia.GetSumaWszystkichZleZaplaconych().ToString();
}
var form5 = new Form5();
form5.Show();
var form5Open = Application.OpenForms.OfType<Form5>().FirstOrDefault();
form5Open.UtworzRaport(SumaCalkowita, SumaZaplaconych, SumaNieZaplaconych);
}
}
}
private void SzukajNieZaplaconychOnOff(bool wlacz)
{
if (wlacz)
{
dataGridView1.Sort(dataGridView1.Columns[5], ListSortDirection.Ascending);
SzukajNiezaplaconychButton.Image = Properties.Resources.szukajWcisniete;
PrzyciskSzukaj = true;
}
else if (!wlacz)
{
SzukajNiezaplaconychButton.Image = Properties.Resources.szukajOff;
dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Descending);
PrzyciskSzukaj = false;
}
}
}
}