-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.cs
366 lines (335 loc) · 19 KB
/
Item.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Furniture_System
{
public partial class Item : MetroFramework.Forms.MetroForm
{
public Item(string un)
{
InitializeComponent();
UN = un;
}
FurnitureDB FurDB = new FurnitureDB();
string UN;
private void btn_Back_Click(object sender, EventArgs e)
{
this.Hide();
Dashboard obj = new Dashboard(UN);
obj.Show();
}
private void btn_search_Click(object sender, EventArgs e)
{
try
{
if (txt_search.Text.Length != 0)
metroGrid_Itm.DataSource = FurDB.getData("select Item_Code as [Item Code],Item_Name as [Item name],Price as [Item Price] from Item where Item_Code like '" + txt_search.Text + "%'");
if (txt_search.Text.Length == 0)
metroGrid_Itm.DataSource = FurDB.getData("select Item_Code as [Item Code],Item_Name as [Item name],Price as [Item Price] from Item");
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void Item_FormClosed(object sender, FormClosedEventArgs e)
{
Dashboard obj = new Dashboard(UN);
obj.Show();
}
private void btn_Clear_AddItem_Click(object sender, EventArgs e)
{
txt_ItemCode.Clear(); txt_ItemName.Clear(); txt_Price.Clear();
}
private void btn_AddItem_Click(object sender, EventArgs e)
{
try
{
if ((txt_ItemCode.Text.Length != 0) && (txt_ItemName.Text.Length != 0) && (txt_Price.Text.Length != 0) && (txt_Price.Text.Any(char.IsDigit)) && !(txt_Price.Text.StartsWith("-")) && txt_ItemName.Text.All(char.IsLetter))
{
if (FurDB.Insert_Update_Delete("insert into Item values ('" + txt_ItemCode.Text + "', '" + txt_ItemName.Text + "', '" + Convert.ToDouble(txt_Price.Text) + "')") == 1)
{
MetroFramework.MetroMessageBox.Show(this, "Item Added Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_ItemCode.Clear(); txt_ItemName.Clear(); txt_Price.Clear();
}
else
MetroFramework.MetroMessageBox.Show(this, "Item Cannot Add!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MetroFramework.MetroMessageBox.Show(this, "Please enter all fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void btn_update_Click(object sender, EventArgs e)
{
try
{
if ((txt_Item_Code_Edit.Text.Length != 0) && (txt_Item_Name_Edit.Text.Length != 0) && (txt_Item_Price_Edit.Text.Any(char.IsDigit)) && !(txt_Item_Price_Edit.Text.StartsWith("-")) && txt_Item_Name_Edit.Text.All(char.IsLetter))
{
if ((FurDB.Insert_Update_Delete("update Item set Item_Name='" + txt_Item_Name_Edit.Text + "',Price='" + Convert.ToDouble(txt_Item_Price_Edit.Text) + "' where Item_Code='" + txt_Item_Code_Edit.Text + "'") == 1))
{
MetroFramework.MetroMessageBox.Show(this, "Updated successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_Item_Code_Edit.Clear(); txt_Item_Name_Edit.Clear(); txt_Item_Price_Edit.Clear(); metroGrid_Itm_Edit.DataSource = null;
}
else
MetroFramework.MetroMessageBox.Show(this, "Data cannot update!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MetroFramework.MetroMessageBox.Show(this, "Please enter all fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void btn_clear_Edit_Click(object sender, EventArgs e)
{
txt_Item_Code_Edit.Clear(); txt_Item_Name_Edit.Clear(); txt_Item_Price_Edit.Clear(); metroGrid_Itm_Edit.DataSource = null; txt_search2.Clear();
}
private void btn_remove_Click(object sender, EventArgs e)
{
try
{
if ((txt_Item_Code_Edit.Text.Length != 0) && (txt_Item_Name_Edit.Text.Length != 0) && (txt_Item_Price_Edit.Text.Any(char.IsDigit)) && !(txt_Item_Price_Edit.Text.StartsWith("-")))
{
if (MetroFramework.MetroMessageBox.Show(this, "Do you want to remove?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
if (FurDB.readData("select * from Item_Bought_Full where FItm_Code='" + txt_Item_Code_Edit.Text + "'") == true || FurDB.readData("select * from Item_Bought_Ins where IItm_Code='" + txt_Item_Code_Edit.Text + "'") == true)
MetroFramework.MetroMessageBox.Show(this, "Item already bought by a Customer!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
if (FurDB.readData("select * from Load_Items where Itm_ID='" + txt_Item_Code_Edit.Text + "'")==true)
MetroFramework.MetroMessageBox.Show(this, "Item already in a Load!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
if (FurDB.readData("select * from Store_Items where Item_CD='" + txt_Item_Code_Edit.Text + "'") == true)
MetroFramework.MetroMessageBox.Show(this, "Item already in a Store!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
if ((FurDB.Insert_Update_Delete("delete from Item where Item_Code='" + txt_Item_Code_Edit.Text + "'") == 1))
{
MetroFramework.MetroMessageBox.Show(this, "Item removed successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_Item_Code_Edit.Clear(); txt_Item_Name_Edit.Clear(); txt_Item_Price_Edit.Clear(); metroGrid_Itm_Edit.DataSource = null; txt_search2.Clear();
}
else
MetroFramework.MetroMessageBox.Show(this, "Data cannot remove!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
else
MetroFramework.MetroMessageBox.Show(this, "Please enter all fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void btn_search2_Click(object sender, EventArgs e)
{
try
{
if (txt_search2.Text.Length != 0)
metroGrid_Itm_Edit.DataSource = FurDB.getData("select Item_Code as [Item Code],Item_Name as [Item name],Price as [Item Price] from Item where Item_Code like '" + txt_search2.Text + "%'");
if (txt_search2.Text.Length == 0)
metroGrid_Itm_Edit.DataSource = FurDB.getData("select Item_Code as [Item Code],Item_Name as [Item name],Price as [Item Price] from Item");
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void metroGrid_Itm_Edit_CellClick(object sender, DataGridViewCellEventArgs e)
{
txt_Item_Code_Edit.Text = metroGrid_Itm_Edit.CurrentRow.Cells[0].Value.ToString();
txt_Item_Name_Edit.Text = metroGrid_Itm_Edit.CurrentRow.Cells[1].Value.ToString();
txt_Item_Price_Edit.Text = metroGrid_Itm_Edit.CurrentRow.Cells[2].Value.ToString();
}
private void Item_Load(object sender, EventArgs e)
{
try
{
//cmb_Store.Items.Insert(0, "Store No");
cmb_Store.DataSource = FurDB.getValue("select Store_No from Store").Tables[0];
cmb_Store.ValueMember = "Store_No";
cmb_Store.Enabled = true;
cmb_Store.SelectedIndex = -1;
cmb_Load_No.DataSource = FurDB.getValue("select Load_No from Load").Tables[0];
cmb_Load_No.ValueMember = "Load_No";
cmb_Load_No.Enabled = true;
cmb_Load_No.SelectedIndex = -1;
cmb_Item_Code_Item_Store.DataSource = FurDB.getValue("select Item_Code from Item").Tables[0];
cmb_Item_Code_Item_Store.ValueMember = "Item_Code";
cmb_Item_Code_Item_Store.Enabled = true;
cmb_Item_Code_Item_Store.SelectedIndex = -1;
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void btn_clear_Item_Store_Click(object sender, EventArgs e)
{
cmb_Item_Code_Item_Store.SelectedIndex = -1; txt_quantity.Clear(); cmb_Store.SelectedIndex = -1;
}
private void btn_Add_to_Store_Click(object sender, EventArgs e)
{
try
{
if ((cmb_Item_Code_Item_Store.SelectedIndex != -1) && (txt_quantity.Text.Length != 0) && (txt_quantity.Text.Any(char.IsDigit)) && !(txt_quantity.Text.StartsWith("-")) && (cmb_Store.SelectedIndex != -1))
{
if ((FurDB.readData("select * from Item where Item_Code='" + cmb_Item_Code_Item_Store.Text + "'") == true) && (FurDB.readData("select * from Store where Store_No='" + cmb_Store.Text + "'") == true))
{
if (FurDB.Insert_Update_Delete("insert into Store_Items values ('" + cmb_Store.Text + "','" + cmb_Item_Code_Item_Store.Text + "','" + Convert.ToInt32(txt_quantity.Text) + "')") == 1)
{
MetroFramework.MetroMessageBox.Show(this, "Items Added to Store Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmb_Item_Code_Item_Store.SelectedIndex = -1; txt_quantity.Clear(); cmb_Store.SelectedIndex = -1;
}
else
MetroFramework.MetroMessageBox.Show(this, "Items cannot be Addded!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MetroFramework.MetroMessageBox.Show(this, "Details not Found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MetroFramework.MetroMessageBox.Show(this, "Please enter all fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception)
{
//MessageBox.Show(ex.Message);
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void btn_Add_to_Load_Click(object sender, EventArgs e)
{
try
{
if ((cmb_Load_No.SelectedIndex != -1) && (cmb_Store_No.SelectedIndex != -1) && (cmb_Item_No.SelectedIndex != -1) && (txt_Load_Quantity.Text.Length != 0) && (txt_Load_Quantity.Text.Any(char.IsDigit)) && !(txt_Load_Quantity.Text.StartsWith("-")))
{
if ((FurDB.readData("select * from Load where Load_No='" + cmb_Load_No.Text + "'") == true) && (FurDB.readData("select * from Store_Items where Stor_ID='" + cmb_Store_No.Text + "' and Item_CD='" + cmb_Item_No.Text + "'") == true))
{
if (FurDB.readData("select Quantity from Store_Items where Stor_ID='" + cmb_Store_No.Text + "' and Item_CD='" + cmb_Item_No.Text + "'", "Quantity") != 0)
{
double q = FurDB.readData("select Quantity from Store_Items where Stor_ID='" + cmb_Store_No.Text + "' and Item_CD='"+ cmb_Item_No.Text+ "'", "Quantity");
double ql = q - Convert.ToDouble(txt_Load_Quantity.Text);
if (ql < 0)
MetroFramework.MetroMessageBox.Show(this, "No Balance in the Store!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
if ((FurDB.Insert_Update_Delete("insert into Load_Items values('" + cmb_Load_No.Text + "','" + cmb_Item_No.Text + "','" + Convert.ToDouble(txt_Load_Quantity.Text) + "')") == 1)&&(FurDB.Insert_Update_Delete("update Store_Items set Quantity='"+ql+"' where Stor_ID='"+ cmb_Store_No.Text+ "' and Item_CD='"+ cmb_Item_No.Text+ "'")==1))
{
MetroFramework.MetroMessageBox.Show(this, "Items Added to Store Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmb_Load_No.SelectedIndex = -1; cmb_Store_No.SelectedIndex = -1; cmb_Item_No.SelectedIndex = -1; txt_Load_Quantity.Clear();
}
else
MetroFramework.MetroMessageBox.Show(this, "Items cannot be Addded!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
MetroFramework.MetroMessageBox.Show(this, "No Balance in the Store!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MetroFramework.MetroMessageBox.Show(this, "Details not Found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MetroFramework.MetroMessageBox.Show(this, "Please enter all fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception)
{
//MessageBox.Show(ex.Message);
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void btn_clear_Load_Click(object sender, EventArgs e)
{
cmb_Load_No.SelectedIndex = -1; cmb_Store_No.SelectedIndex = -1; cmb_Item_No.SelectedIndex = -1; txt_Load_Quantity.Clear(); lbl_IStr.Text = "";
}
private void cmb_Load_No_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
cmb_Store_No.DataSource = FurDB.getValue("select St_ID from Load where Load_No='" + cmb_Load_No.Text + "'").Tables[0];
cmb_Store_No.ValueMember = "St_ID";
cmb_Store_No.Enabled = true;
cmb_Store_No.SelectedIndex = -1;
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void cmb_Store_No_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
cmb_Item_No.DataSource = FurDB.getValue("select Item_CD from Store_Items where Stor_ID='" + cmb_Store_No.Text + "'").Tables[0];
cmb_Item_No.ValueMember = "Item_CD";
cmb_Item_No.Enabled = true;
cmb_Item_No.SelectedIndex = -1;
lbl_IStr.Text = FurDB.readData("select Store_Name from Store where Store_No='" + cmb_Store_No.Text + "'", "Store_Name", "");
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void cmb_Store_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
lbl_Str_Name.Text = FurDB.readData("select Store_Name from Store where Store_No='" + cmb_Store.Text + "'", "Store_Name", "");
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void cmb_Item_Code_Item_Store_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
lbl_Itm_Name.Text = FurDB.readData("select Item_Name from Item where Item_Code='" + cmb_Item_Code_Item_Store.Text + "'", "Item_Name", "");
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void cmb_Item_No_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
lbl_IItm.Text = FurDB.readData("select Item_Name from Item where Item_Code='" + cmb_Item_No.Text + "'", "Item_Name", "");
lbl_IQuan.Text = FurDB.readData("select Quantity from Store_Items where Stor_ID='" + cmb_Store_No.Text + "' and Item_CD='" + cmb_Item_No.Text + "'", "Quantity", "");
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
}
}