-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSale.cs
310 lines (259 loc) · 10.8 KB
/
Sale.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
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 Varsity_Phamarcy
{
public partial class Sale : Form
{
private const decimal V = (decimal) 0.15;
private int Qty = 0;
private int count = 0;
private decimal Total;
private string products; //prices;
List<int> product1 = new List<int>();
List<int> quantityy = new List<int>();
List<decimal> pricee = new List<decimal>();
Login log = new Login();
public Sale()
{
InitializeComponent();
}
private void Sale_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'varsityPharmacyDataSet2.Sale_item' table. You can move, or remove it, as needed.
this.sale_itemTableAdapter1.Fill(this.varsityPharmacyDataSet2.Sale_item);
// TODO: This line of code loads data into the 'varsityPharmacyDataSet.Sale_Item2' table. You can move, or remove it, as needed.
this.sale_Item2TableAdapter.Fill(this.varsityPharmacyDataSet.Sale_Item2);
// TODO: This line of code loads data into the 'varsityPharmacyDataSet.Sale_item' table. You can move, or remove it, as needed.
this.sale_itemTableAdapter1.Fill(this.varsityPharmacyDataSet2.Sale_item);
// TODO: This line of code loads data into the 'varsityPharmacyDataSet.Products' table. You can move, or remove it, as needed.
this.productsTableAdapter.Fill(this.varsityPharmacyDataSet.Products);
// TODO: This line of code loads data into the 'varsityPharmacyDataSet.Customers' table. You can move, or remove it, as needed.
this.customersTableAdapter.Fill(this.varsityPharmacyDataSet.Customers);
// TODO: This line of code loads data into the 'varsityPharmacyDataSet.Sale_Item2' table. You can move, or remove it, as needed.
this.sale_Item2TableAdapter.Fill(this.varsityPharmacyDataSet.Sale_Item2);
// TODO: This line of code loads data into the 'varsityPharmacyDataSet.Sale_item' table. You can move, or remove it, as needed.
this.sale_itemTableAdapter1.Fill(this.varsityPharmacyDataSet2.Sale_item);
// TODO: This line of code loads data into the 'varsityPharmacyDataSet.Products' table. You can move, or remove it, as needed.
this.productsTableAdapter.Fill(this.varsityPharmacyDataSet.Products);
// TODO: This line of code loads data into the 'varsityPharmacyDataSet.Customers' table. You can move, or remove it, as needed.
this.customersTableAdapter.Fill(this.varsityPharmacyDataSet.Customers);
// TODO: This line of code loads data into the 'varsityPharmacyDataSet.Sale_Item2' table. You can move, or remove it, as needed.
this.sale_Item2TableAdapter.Fill(this.varsityPharmacyDataSet.Sale_Item2);
// TODO: This line of code loads data into the 'varsityPharmacyDataSet2.Sale_item' table. You can move, or remove it, as needed.
}
private void dataGridView4_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//custName.Text = dataGridView4.CurrentRow.Cells[0].Value.ToString();
}
private void dataGridView5_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//staffName.Text = dataGridView5.CurrentRow.Cells[1].Value.ToString();
}
private void dataGridView2_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
int loc = 0 ;
int Q, ID;
pricee.Add(0);
product1.Add(0);
quantityy.Add(0);
Price.Text = dataGridView2.CurrentRow.Cells[2].Value.ToString();
productName.Text = dataGridView2.CurrentRow.Cells[0].Value.ToString();
quant.Text = dataGridView2.CurrentRow.Cells[1].Value.ToString();
Q = int.Parse(quant.Text);
ID = int.Parse(dataGridView2.CurrentRow.Cells[3].Value.ToString());
Q -= 1;
textBox1.Text =(dataGridView2.CurrentRow.Cells[2].Value.ToString());
textBox2.Text =(dataGridView2.CurrentRow.Cells[2].Value.ToString());
int temp = int.Parse(textBox1.Text);
decimal temp2 = decimal.Parse(textBox2.Text);
for (int i = 0; i < product1.Count; i++)
{
if (temp == product1[i])
loc = i;
//break;
}
if(loc != 0)
{
product1[loc] = int.Parse(textBox1.Text);
quantityy[loc]++;
pricee[loc] = pricee[loc] + temp2;
}
else
{
product1.Add(int.Parse(textBox1.Text));
quantityy.Add(1);
pricee.Add(temp2);
}
if (Q <= 0){
Q = 0;
MessageBox.Show("No Products Available");
}else{
products += count+1 + "." + productName.Text + " ---> R" + Price.Text + "| \r\n";
count += 1;
Total += decimal.Parse(Price.Text);
total.Text = Total.ToString();
Qty += 1;
QtyBox.Text = Qty.ToString();
list.Text += " \r\n " + count + ") === " + productName.Text + " ---> R" + Price.Text + " \r\n ";
productsTableAdapter.UpdateQuery2(productName.Text, Q, decimal.Parse(Price.Text), ID, ID);
productsTableAdapter.Fill(this.varsityPharmacyDataSet.Products);
if (Q < 6)
{
MessageBox.Show("Less Than 6 products available !!!");
}
}
}
private void button7_Click(object sender, EventArgs e)
{
try
{
list2.Text = list.Text;
totalQty.Text = Qty.ToString();
totalPrice.Text = Total.ToString();
tabControl1.SelectedTab = tabPage2;
}
catch
{
MessageBox.Show("Some Error has Occurred");
}
}
private void button1_Click(object sender, EventArgs e)
{
string Customer = custName.Text;
string Staff = log.getUserName();
string product = products;
decimal price = decimal.Parse(this.Price.Text);
int quantity = int.Parse(quant.Text);
decimal amount = decimal.Parse(Tendered.Text);
DateTime date = DateTime.Now;
DayOfWeek wk = DateTime.Now.DayOfWeek;
string Day = wk.ToString("d");
switch(Int32.Parse(Day)){
case 1 :
Day = "Monday";
break;
case 2 :
Day = "Tuesday";
break;
case 3 :
Day = "Wednesday";
break;
case 4:
Day = "Thursday";
break;
case 5:
Day = "Friday";
break;
case 6:
Day = "Saturday";
break;
case 0:
Day = "Sunday";
break;
}
if (amount < (decimal)Total )
{
MessageBox.Show("Insufficient Funds");
}
else
{
decimal change = (amount - Total);
changeBox.Text = "R " + change.ToString();
decimal VAT = ((decimal)Total * V);
sale_itemTableAdapter1.InsertQuery(Customer, Staff, products, (decimal)price, Qty, (decimal)amount, (decimal)Total, (decimal)change,(decimal) VAT, date, Day);
this.sale_itemTableAdapter1.Fill(this.varsityPharmacyDataSet2.Sale_item);
products = "";
}
}
private void button3_Click(object sender, EventArgs e)
{
MainMenu menu = new MainMenu();
this.Hide();
menu.Show();
}
private void button9_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage1;
}
private void search_TextChanged(object sender, EventArgs e)
{
try
{
string prodName = "%" + search.Text + "%";
this.productsTableAdapter.FillBy(this.varsityPharmacyDataSet.Products, prodName);
}
catch
{
MessageBox.Show(productName, "NOT FOUND");
}
}
private void button8_Click(object sender, EventArgs e)
{
MainMenu menu = new MainMenu();
this.Hide();
menu.Show();
}
private void button10_Click(object sender, EventArgs e)
{
product1.Clear();
pricee.Clear();
quantityy.Clear();
custName.Text = "";
textBox1.Text = "";
productName.Text = "";
Price.Text = "";
Total = 0;
quant.Text = "";
Tendered.Text = "";
changeBox.Text = "";
totalPrice.Text = "";
totalQty.Text = "";
total.Text = "";
QtyBox.Text = "";
list.Text = "";
list2.Text = "";
products = "";
Qty = 0;
count = 0;
}
private void button2_Click(object sender, EventArgs e)
{
button10_Click(sender, e);
}
private void button13_Click(object sender, EventArgs e)
{
Customer cust = new Customer();
this.Hide();
cust.Show();
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
try
{
string custName = "%" + textBox4.Text + "%";
this.customersTableAdapter.FillBy(this.varsityPharmacyDataSet.Customers, custName);
}
catch
{
MessageBox.Show(custName, "NOT FOUND");
}
}
private void button5_Click_1(object sender, EventArgs e)
{
Suppliers suppliers = new Suppliers();
this.Hide();
suppliers.Show();
}
private void dataGridView4_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
custName.Text = dataGridView4.CurrentRow.Cells[0].Value.ToString();
}
}
}