-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoad.cs
292 lines (263 loc) · 15 KB
/
Load.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
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 Load : MetroFramework.Forms.MetroForm
{
public Load(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 Load_FormClosing(object sender, FormClosingEventArgs e)
{
Dashboard obj = new Dashboard(UN);
obj.Show();
}
private void btn_search_Click(object sender, EventArgs e)
{
try
{
if (txt_search.Text.Length != 0)
metroGrid_Ld.DataSource = FurDB.getData("select Load_No as [Load No],St_ID as [Store No],Store_Name as [Store Name] from Load,Store where St_ID=Store_No and Load_No like '" + txt_search.Text + "%'");
if (txt_search.Text.Length == 0)
metroGrid_Ld.DataSource = FurDB.getData("select Load_No as [Load No],St_ID as [Store No],Store_Name as [Store Name] from Load,Store where St_ID=Store_No");
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void Load_Load(object sender, EventArgs e)
{
try
{
cmb_Store_No.DataSource = FurDB.getValue("select Store_No from Store").Tables[0];
cmb_Store_No.ValueMember = "Store_No";
cmb_Store_No.Enabled = true;
cmb_Store_No.SelectedIndex = -1;
cmb_Store_No_Edit.DataSource = FurDB.getValue("select Store_No from Store").Tables[0];
cmb_Store_No_Edit.ValueMember = "Store_No";
cmb_Store_No_Edit.Enabled = true;
cmb_Store_No_Edit.SelectedIndex = -1;
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void btn_AddLoad_Click(object sender, EventArgs e)
{
try
{
if ((txt_LoadNo.Text.Length != 0) && (cmb_Store_No.SelectedIndex != -1))
{
if (FurDB.Insert_Update_Delete("insert into Load values ('" + txt_LoadNo.Text + "', '" + cmb_Store_No.Text + "')") == 1)
{
MetroFramework.MetroMessageBox.Show(this, "Store Added Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_LoadNo.Clear(); cmb_Store_No.SelectedIndex = -1;
}
else
MetroFramework.MetroMessageBox.Show(this, "Load Cannot Add!", "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_AddLoad_Click(object sender, EventArgs e)
{
txt_LoadNo.Clear(); cmb_Store_No.SelectedIndex = -1;
}
private void btn_search2_Click(object sender, EventArgs e)
{
try
{
if (txt_search2.Text.Length != 0)
metroGrid_Ld_Edit.DataSource = FurDB.getData("select Load_No as [Load No],St_ID as [Store No],Store_Name as [Store Name] from Load,Store where St_ID=Store_No and Load_No like '" + txt_search2.Text + "%'");
if (txt_search2.Text.Length == 0)
metroGrid_Ld_Edit.DataSource = FurDB.getData("select Load_No as [Load No],St_ID as [Store No],Store_Name as [Store Name] from Load,Store where St_ID=Store_No");
}
catch (Exception)
{
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_Load_No_Edit.Text.Length != 0) && (cmb_Store_No_Edit.SelectedIndex != -1))
if (FurDB.Insert_Update_Delete("update Load set St_ID='" + cmb_Store_No_Edit.Text + "' where Load_No='"+ txt_Load_No_Edit.Text+"'") == 1)
{
MetroFramework.MetroMessageBox.Show(this, "Updated successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_Load_No_Edit.Clear(); cmb_Store_No_Edit.SelectedIndex = -1; txt_search2.Clear(); metroGrid_Ld_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_remove_Click(object sender, EventArgs e)
{
try
{
if ((txt_Load_No_Edit.Text.Length != 0) && (cmb_Store_No_Edit.SelectedIndex != -1))
if ((FurDB.readData("select * from Load_Items where L_ID='" + txt_Load_No_Edit.Text + "'") == true))
MetroFramework.MetroMessageBox.Show(this, "This Load has Items remaining!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
if (MetroFramework.MetroMessageBox.Show(this, "Do you want to remove?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
if (FurDB.Insert_Update_Delete("delete from Load where Load_No='" + txt_Load_No_Edit.Text + "'") == 1)
{
MetroFramework.MetroMessageBox.Show(this, "Load removed successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_Load_No_Edit.Clear(); cmb_Store_No_Edit.SelectedIndex = -1; txt_search2.Clear(); metroGrid_Ld_Edit.DataSource = null;
}
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_clear_Edit_Click(object sender, EventArgs e)
{
txt_Load_No_Edit.Clear(); cmb_Store_No_Edit.SelectedIndex = -1; txt_search2.Clear(); metroGrid_Ld_Edit.DataSource = null;
}
private void metroGrid_Ld_Edit_CellClick(object sender, DataGridViewCellEventArgs e)
{
txt_Load_No_Edit.Text = metroGrid_Ld_Edit.CurrentRow.Cells[0].Value.ToString();
}
private void btn_search_Load_Item_Click(object sender, EventArgs e)
{
try
{
if (txt_Load_No.Text.Length != 0)
metroGrid_Ld_Itm.DataSource = FurDB.getData("select L_ID as [Load No],Itm_ID as [Item No],Item_Name as [Item Name],Price as [Price],Quantity as [Load Quantity] from Load_Items,Item where Itm_ID=Item_Code and L_ID like '" + txt_Load_No.Text + "%'");
if (txt_Load_No.Text.Length == 0)
metroGrid_Ld_Itm.DataSource = FurDB.getData("select L_ID as [Load No],Itm_ID as [Item No],Item_Name as [Item Name],Price as [Price],Quantity as [Load Quantity] from Load_Items,Item where Itm_ID=Item_Code");
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void btn_search3_Click(object sender, EventArgs e)
{
try
{
if (txt_search3.Text.Length != 0)
metroGrid_Up_Ld_Itm.DataSource = FurDB.getData("select L_ID as [Load No],Itm_ID as [Item No],Item_Name as [Item Name],Price as [Price],Quantity as [Load Quantity] from Load_Items,Item where Itm_ID=Item_Code and L_ID like '" + txt_search3.Text + "%'");
if (txt_search3.Text.Length == 0)
metroGrid_Up_Ld_Itm.DataSource = FurDB.getData("select L_ID as [Load No],Itm_ID as [Item No],Item_Name as [Item Name],Price as [Price],Quantity as [Load Quantity] from Load_Items,Item where Itm_ID=Item_Code");
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void txt_Update_Click(object sender, EventArgs e)
{
try
{
if ((txt_Load_No_Update.Text.Length != 0) && (txt_Item_No_Update.Text.Length != 0) && (txt_Quantity.Text.Length != 0) && (txt_Quantity.Text.Any(char.IsDigit)) && !(txt_Quantity.Text.StartsWith("-")) && (txt_New_Quantity.Text.Length != 0) && (txt_New_Quantity.Text.Any(char.IsDigit)) && ((Convert.ToDouble(txt_New_Quantity.Text))!=0))
{
string str = FurDB.readData("select St_ID from Load where Load_No = '" + txt_Load_No_Update.Text + "'", "St_ID", "");
double StQan = FurDB.readData("select Quantity from Store_Items where Stor_ID = '"+ str + "' and Item_CD='"+txt_Item_No_Update.Text+"'", "Quantity");
double LdQan = Convert.ToDouble(txt_Quantity.Text);
if ((Convert.ToDouble(txt_New_Quantity.Text)) > StQan)
{
MetroFramework.MetroMessageBox.Show(this, "No Balance in the Store!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
double New_LdQan = Convert.ToDouble(txt_New_Quantity.Text) + LdQan; StQan = StQan - Convert.ToDouble(txt_New_Quantity.Text);
if ((FurDB.Insert_Update_Delete("update Load_Items set Quantity='" + New_LdQan + "' where L_ID='" + txt_Load_No_Update.Text + "' and Itm_ID='" + txt_Item_No_Update.Text + "'") == 1) && (FurDB.Insert_Update_Delete("update Store_Items set Quantity='" + StQan + "' where Item_CD='" + txt_Item_No_Update.Text + "' and Stor_ID='"+str+"'") == 1))
{
MetroFramework.MetroMessageBox.Show(this, "Updated successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_Load_No_Update.Clear(); txt_Item_No_Update.Clear(); txt_Quantity.Clear(); txt_search3.Clear(); metroGrid_Up_Ld_Itm.DataSource = null; txt_New_Quantity.Clear();
}
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_remove_Ld_Itm_Click(object sender, EventArgs e)
{
try
{
if ((txt_Load_No_Update.Text.Length != 0) && (txt_Item_No_Update.Text.Length != 0) && (txt_Quantity.Text.Length != 0) && (txt_Quantity.Text.Any(char.IsDigit)) && !(txt_Quantity.Text.StartsWith("-")))
if (FurDB.Insert_Update_Delete("delete from Load_Items where L_ID='" + txt_Load_No_Update.Text + "' and Itm_ID='" + txt_Item_No_Update.Text + "'") == 1)
{
MetroFramework.MetroMessageBox.Show(this, "Item removed successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_Load_No_Update.Clear(); txt_Item_No_Update.Clear(); txt_Quantity.Clear(); txt_search3.Clear(); metroGrid_Up_Ld_Itm.DataSource = null; txt_New_Quantity.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_clear_Update_Load_Click(object sender, EventArgs e)
{
txt_Load_No_Update.Clear(); txt_Item_No_Update.Clear(); txt_Quantity.Clear(); txt_search3.Clear(); metroGrid_Up_Ld_Itm.DataSource = null; txt_New_Quantity.Clear();
}
private void metroGrid_Up_Ld_Itm_CellClick(object sender, DataGridViewCellEventArgs e)
{
txt_Load_No_Update.Text = metroGrid_Up_Ld_Itm.CurrentRow.Cells[0].Value.ToString();
txt_Item_No_Update.Text = metroGrid_Up_Ld_Itm.CurrentRow.Cells[1].Value.ToString();
txt_Quantity.Text = metroGrid_Up_Ld_Itm.CurrentRow.Cells[4].Value.ToString();
}
}
}