-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfrmOrder.vb
412 lines (381 loc) · 20.6 KB
/
frmOrder.vb
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
Imports System.Data.OleDb
Public Class frmOrder
Dim iTax = 0.2
Dim isSave = False
'LOAD TABLES FUNCTION
Private Sub LoadTables(Optional ByVal q As String = "")
Try
If con.State = ConnectionState.Closed Then
OpenCon()
End If
query.Connection = con
query.CommandText = "SELECT * FROM tblOrders"
adapter.SelectCommand = query
dt.Clear()
adapter.Fill(dt)
DataGridView1.DataSource = dt
con.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
con.Close()
End Sub
'CASHIER ID FUNCTION
Private Sub cashierID(Optional ByVal q As String = "")
If con.State = ConnectionState.Closed Then
OpenCon()
End If
Try
Dim strsql As String
strsql = "SELECT * FROM tblUsers WHERE Username = '" & frmLogin.txtUsername.Text & "'"
Dim cmd As New OleDbCommand(strsql, con)
Dim myReader As OleDbDataReader
myReader = cmd.ExecuteReader
myReader.Read()
txtCashierID.Text = myReader("ID")
con.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
con.Close()
End Sub
'RECEIPT DATA FUNCTION
Private Sub receiptData(Optional ByVal q As String = "")
If con.State = ConnectionState.Closed Then
OpenCon()
End If
Dim strsql As String
strsql = "SELECT * FROM tblOrders WHERE Customer_ID = " & txtCustomerID.Text & ""
Dim cmd As New OleDbCommand(strsql, con)
Dim myReader As OleDbDataReader
myReader = cmd.ExecuteReader
myReader.Read()
txtCustname.Text = myReader("Customer_Name")
txtCustphone.Text = myReader("Customer_Phone")
txtRef.Text = myReader("Order_Ref_No")
txtOrderdate.Text = myReader("Order_Date")
txtOrdertime.Text = myReader("Order_Time")
txtQ1.Text = myReader("Qty_Spaghetti")
txtQ2.Text = myReader("Qty_Burger")
txtQ3.Text = myReader("Qty_Fries")
txtQ4.Text = myReader("Qty_Cola")
txtQ5.Text = myReader("Qty_Rice")
txtP1.Text = myReader("Price_Spaghetti")
txtP2.Text = myReader("Price_Burger")
txtP3.Text = myReader("Price_Fries")
txtP4.Text = myReader("Price_Cola")
txtP5.Text = myReader("Price_Rice")
txtST1.Text = myReader("Sub_Total_Spag")
txtST2.Text = myReader("Sub_Total_Burg")
txtST3.Text = myReader("Sub_Total_Fries")
txtST4.Text = myReader("Sub_Total_Cola")
txtST5.Text = myReader("Sub_Total_Rice")
txtOST.Text = myReader("Order_Sub_Total")
txtTx.Text = myReader("Tax")
txtTtl.Text = myReader("Total")
End Sub
'INSERT TBLLOGS FUNCTION
Private Sub InserttblLogs(Optional ByVal q As String = "")
Try
query.Connection = con
query.CommandText = "INSERT INTO tblLogs(Cashier, Customer_Name, Customer_Phone, Order_Date, Order_Time, Order_Ref_No, Qty_Spaghetti, Qty_Burger, Qty_Fries, Qty_Cola, Qty_Rice, Price_Spaghetti, Price_Burger, Price_Fries, Price_Cola, Price_Rice, Sub_Total_Spag, Sub_Total_Burg, Sub_Total_Fries, Sub_Total_Cola, Sub_Total_Rice, Order_Sub_Total, Tax, Total) VALUES('" & frmMain.lblUsername.Text & "', '" &
txtCustname.Text & "', '" & txtCustphone.Text & "', '" & txtOrderdate.Text & "', '" & txtOrdertime.Text & "', '" & txtRef.Text & "', '" & txtQ1.Text & "', '" & txtQ2.Text & "', '" & txtQ3.Text & "', '" & txtQ4.Text & "', '" _
& txtQ5.Text & "', '" & txtP1.Text & "', '" & txtP2.Text & "', '" & txtP3.Text & "', '" & txtP4.Text & "', '" & txtP5.Text & "', '" & txtST1.Text & "', '" & txtST2.Text & "', '" & txtST3.Text & "', '" & txtST4.Text & "', '" _
& txtST5.Text & "', '" & txtOST.Text & "', '" & txtTx.Text & "', '" & txtTtl.Text & "')"
query.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
'PRINT PAGE FUNCTION
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawString(txtReceipt.Text, Font, Brushes.Black, 140, 140)
e.Graphics.DrawImage(frmDashboard.PictureBox2.Image, 120, 130, frmDashboard.PictureBox2.Width - 60, frmDashboard.PictureBox2.Height)
End Sub
'LOADER
Private Sub frmOrder_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TabPage3.Enabled = False
Call LoadTables()
Call cashierID()
'ITEM TEXTBOX PRICES
txtPrice1.Text = "$50.00"
txtPrice2.Text = "$30.00"
txtPrice3.Text = "$20.00"
txtPrice4.Text = "$15.00"
txtPrice5.Text = "$10.00"
'REMAINING TEXTBOX
txtRefno.Text = "0"
txtQty1.Text = "0"
txtSubTotal1.Text = "0"
txtQty2.Text = "0"
txtSubTotal2.Text = "0"
txtQty3.Text = "0"
txtSubTotal3.Text = "0"
txtQty4.Text = "0"
txtSubTotal4.Text = "0"
txtQty5.Text = "0"
txtSubTotal5.Text = "0"
txtOrderSubTotal.Text = "0"
txtTax.Text = "0"
txtTotal.Text = "0"
End Sub
'BUTTON REFRESH
Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click
Call LoadTables()
End Sub
'BUTTON RESET
Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
TabControl1.SelectedTab = TabPage1
txtCustomerID.Text = ""
txtQty1.Text = "0"
txtQty2.Text = "0"
txtQty3.Text = "0"
txtQty4.Text = "0"
txtQty5.Text = "0"
txtSubTotal1.Text = "0"
txtSubTotal2.Text = "0"
txtSubTotal3.Text = "0"
txtSubTotal4.Text = "0"
txtSubTotal5.Text = "0"
txtOrderSubTotal.Text = "0"
txtTax.Text = "0"
txtTotal.Text = "0"
txtRefno.Text = "0"
'PRINT TAB
txtCustname.Text = ""
txtCustphone.Text = ""
txtRef.Text = ""
txtOrderdate.Text = ""
txtOrdertime.Text = ""
txtQ1.Text = ""
txtQ2.Text = ""
txtQ3.Text = ""
txtQ4.Text = ""
txtQ5.Text = ""
txtP1.Text = ""
txtP2.Text = ""
txtP3.Text = ""
txtP4.Text = ""
txtP5.Text = ""
txtST1.Text = ""
txtST2.Text = ""
txtST3.Text = ""
txtST4.Text = ""
txtST5.Text = ""
txtOST.Text = ""
txtTx.Text = ""
txtTtl.Text = ""
'RECEIPT
txtReceipt.Text = ""
End Sub
'BUTTON TOTAL
Private Sub btnTotal_Click(sender As Object, e As EventArgs) Handles btnTotal.Click
If con.State = ConnectionState.Closed Then
OpenCon()
End If
If txtQty1.Text = "0" And txtQty2.Text = "0" And txtQty3.Text = "0" And txtQty4.Text = "0" And txtQty5.Text = "0" Then
MessageBox.Show("Please Add Order!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Try
txtRefno.Text = (Rnd() * Rnd() * 32676)
'FORMULA TO MULTIPLY VALUE OF PRICE TO THE QUANTITY
txtSubTotal1.Text = txtPrice1.Text * txtQty1.Text
txtSubTotal2.Text = txtPrice2.Text * txtQty2.Text
txtSubTotal3.Text = txtPrice3.Text * txtQty3.Text
txtSubTotal4.Text = txtPrice4.Text * txtQty4.Text
txtSubTotal5.Text = txtPrice5.Text * txtQty5.Text
'GROUPBOX 3 - Order_Sub_Total, Tax, & Total TEXTBOXES
txtOrderSubTotal.Text = Val(txtSubTotal1.Text) + Val(txtSubTotal2.Text) + Val(txtSubTotal3.Text) + Val(txtSubTotal4.Text) + Val(txtSubTotal5.Text)
txtTax.Text = (txtOrderSubTotal.Text * iTax)
txtTotal.Text = Val(txtTax.Text) + Val(txtOrderSubTotal.Text)
'FORMAT CURRENCY
txtPrice1.Text = FormatCurrency(txtPrice1.Text)
txtPrice2.Text = FormatCurrency(txtPrice2.Text)
txtPrice3.Text = FormatCurrency(txtPrice3.Text)
txtPrice4.Text = FormatCurrency(txtPrice4.Text)
txtPrice5.Text = FormatCurrency(txtPrice5.Text)
txtSubTotal1.Text = FormatCurrency(txtSubTotal1.Text)
txtSubTotal2.Text = FormatCurrency(txtSubTotal2.Text)
txtSubTotal3.Text = FormatCurrency(txtSubTotal3.Text)
txtSubTotal4.Text = FormatCurrency(txtSubTotal4.Text)
txtSubTotal5.Text = FormatCurrency(txtSubTotal5.Text)
txtOrderSubTotal.Text = FormatCurrency(txtOrderSubTotal.Text)
txtTax.Text = FormatCurrency(txtTax.Text)
txtTotal.Text = FormatCurrency(txtTotal.Text)
con.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
con.Close()
End If
End Sub
'BUTTON SAVE
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
If con.State = ConnectionState.Closed Then
OpenCon()
End If
If txtCustomerID.Text = "" Then
MessageBox.Show("Please input a Customer ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtRefno.Text = "0" Then
MessageBox.Show("Please Click Total First", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtQty1.Text = "0" And txtQty2.Text = "0" And txtQty3.Text = "0" And txtQty4.Text = "0" And txtQty5.Text = "0" Then
MessageBox.Show("Please Add Order First!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Try
TabControl1.SelectedTab = TabPage1
Using cmd As New OleDbCommand("SELECT COUNT(*) FROM tblOrders WHERE [Customer_ID] = @Customer_ID", con)
cmd.Parameters.AddWithValue("@Customer_ID", OleDbType.VarChar).Value = txtCustomerID.Text.Trim
Dim count = Convert.ToInt32(cmd.ExecuteScalar())
If count > 0 Then
query.Connection = con
query.CommandText = "UPDATE tblOrders SET Order_Ref_No = '" & txtRefno.Text & "', Order_Date = '" & Today & "', Order_Time = '" & TimeOfDay & "', Qty_Spaghetti = '" & txtQty1.Text & "', Qty_Burger = '" & txtQty2.Text & "', Qty_Fries = '" & txtQty3.Text & "', Qty_Cola = '" & txtQty4.Text & "', Qty_Rice = '" & txtQty5.Text & "', Price_Spaghetti = '" & txtPrice1.Text & "', Price_Burger = '" & txtPrice2.Text & "', Price_Fries = '" & txtPrice3.Text & "', Price_Cola = '" & txtPrice4.Text & "', Price_Rice = '" & txtPrice5.Text & "', Sub_Total_Spag = '" & txtSubTotal1.Text & "', Sub_Total_Burg = '" & txtSubTotal2.Text & "', Sub_Total_Fries = '" & txtSubTotal3.Text & "', Sub_Total_Cola = '" & txtSubTotal4.Text & "', Sub_Total_Rice = '" & txtSubTotal5.Text & "', Order_Sub_Total = '" & txtOrderSubTotal.Text & "', Tax = '" & txtTax.Text & "', Total = '" & txtTotal.Text & "' WHERE Customer_ID = " & txtCustomerID.Text & ""
query.ExecuteNonQuery()
MessageBox.Show("Successfully Registered!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
isSave = True
con.Close()
Call LoadTables()
Exit Sub
Else
MessageBox.Show("Customer ID is not Registered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Using
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
con.Close()
Call LoadTables()
End If
End Sub
'BUTTON DELIVERED
Private Sub btnDelivered_Click(sender As Object, e As EventArgs) Handles btnDelivered.Click
If con.State = ConnectionState.Closed Then
OpenCon()
End If
Call receiptData()
If txtCustomerID.Text = "" Then
MessageBox.Show("Please input a Customer ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtQ1.Text = "" Then
MessageBox.Show("Customer Does not have any order", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Try
Using cmd As New OleDbCommand("Select COUNT(*) FROM tblOrders WHERE [Customer_ID] = @Customer_ID", con)
cmd.Parameters.AddWithValue("@Customer_ID", OleDbType.VarChar).Value = txtCustomerID.Text.Trim
Dim count = Convert.ToInt32(cmd.ExecuteScalar())
If count > 0 Then
TabControl1.SelectedTab = TabPage1
query.Connection = con
Call InserttblLogs()
query.CommandText = "UPDATE tblOrders SET Order_Ref_No = '" & Nothing & "', Qty_Spaghetti = '" & Nothing & "', Qty_Burger = '" & Nothing & "', Qty_Fries = '" & Nothing & "', Qty_Cola = '" & Nothing & "', Qty_Rice = '" & Nothing & "', Price_Spaghetti = '" & Nothing & "', Price_Burger = '" & Nothing & "', Price_Fries = '" & Nothing & "', Price_Cola = '" & Nothing & "', Price_Rice = '" & Nothing & "', Sub_Total_Spag = '" & Nothing & "', Sub_Total_Burg = '" & Nothing & "', Sub_Total_Fries = '" & Nothing & "', Sub_Total_Cola = '" & Nothing & "', Sub_Total_Rice = '" & Nothing & "', Order_Sub_Total = '" & Nothing & "', Tax = '" & Nothing & "', Total = '" & Nothing & "' WHERE Customer_ID = " & txtCustomerID.Text & ""
query.ExecuteNonQuery()
MessageBox.Show("Successfully Delivered!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
con.Close()
Call LoadTables()
Exit Sub
Else
MessageBox.Show("Customer ID is not Registered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Using
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
con.Close()
Call LoadTables()
End If
End Sub
'BUTTON ADD CART
Private Sub btnAddcart_Click(sender As Object, e As EventArgs) Handles btnAddcart.Click
If txtCustomerID.Text = "" Then
MessageBox.Show("Please input a Customer ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf isSave = False Then
MessageBox.Show("Save Order First!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Try
TabControl1.SelectedTab = TabPage3
Call receiptData()
TabPage3.Enabled = True
isSave = False
con.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End If
End Sub
'BUTTON CHECK
Private Sub btnCheck_Click(sender As Object, e As EventArgs) Handles btnCheck.Click
If con.State = ConnectionState.Closed Then
OpenCon()
End If
If txtCustomerID.Text = "" Then
MessageBox.Show("Please input a Customer ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
' ElseIf txt Then
Else
Try
txtReceipt.Clear()
Using cmd As New OleDbCommand("Select COUNT(*) FROM tblOrders WHERE [Customer_ID] = @Customer_ID", con)
cmd.Parameters.AddWithValue("@Customer_ID", OleDbType.VarChar).Value = txtCustomerID.Text.Trim
Dim count = Convert.ToInt32(cmd.ExecuteScalar())
If count > 0 Then
TabControl1.SelectedTab = TabPage2
txtOrdertime.Text = TimeOfDay
txtReceipt.AppendText("" + vbNewLine)
txtReceipt.AppendText("" + vbNewLine)
txtReceipt.AppendText("" + vbNewLine)
txtReceipt.AppendText("" + vbNewLine)
txtReceipt.AppendText("" + vbNewLine)
txtReceipt.AppendText(vbTab + vbTab + vbTab + vbTab + vbTab & "ITERY ORDERING SYSTEM" + vbNewLine)
txtReceipt.AppendText(vbTab + vbTab + vbTab + vbTab & " Your Convenient Online Ordering System" + vbNewLine)
txtReceipt.AppendText(vbNewLine + vbTab + vbTab + vbTab + vbTab & " Trojan Building, Plaza Limaco, Poblacion" + vbNewLine)
txtReceipt.AppendText(vbTab + vbTab + vbTab + vbTab & " 4024, Binan City, Laguna" + vbNewLine)
txtReceipt.AppendText(vbTab + vbTab + vbTab + vbTab & " TIN#: 978-971-134309-5" + vbNewLine)
txtReceipt.AppendText(vbTab + vbTab + vbTab + vbTab & " Cashier Name: " & frmMain.lblUsername.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + "===============================================================================================" + vbNewLine)
txtReceipt.AppendText("" + vbNewLine)
txtReceipt.AppendText("Cashier Name: " & frmMain.lblUsername.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + "Customer Name: " & txtCustname.Text + vbTab + vbTab + vbTab + "Phone No: " & txtCustphone.Text + vbTab +
vbTab + vbTab + "Ref No: " & txtRef.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + "Order Date: " & txtOrderdate.Text + vbTab + vbTab + "Order Time: " & txtOrdertime.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + "Item " + vbTab + vbTab & " Quantity: " + vbTab + vbTab + vbTab & "Price: " + vbTab + vbTab + vbTab & "Sub Total: " + vbNewLine)
txtReceipt.AppendText(vbNewLine + "Spaghetti: " + vbTab + vbTab & txtQ1.Text + vbTab + vbTab + vbTab & txtP1.Text + vbTab +
vbTab + vbTab & txtST1.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + "Burger: " + vbTab + vbTab + vbTab & txtQ2.Text + vbTab + vbTab + vbTab & txtP2.Text + vbTab +
vbTab + vbTab & txtST2.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + "Fries: " + vbTab + vbTab + vbTab & txtQ3.Text + vbTab + vbTab + vbTab & txtP3.Text + vbTab +
vbTab + vbTab & txtST3.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + "Cola: " + vbTab + vbTab + vbTab & txtQ4.Text + vbTab + vbTab + vbTab & txtP4.Text + vbTab +
vbTab + vbTab & txtST4.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + "Rice: " + vbTab + vbTab + vbTab & txtQ5.Text + vbTab + vbTab + vbTab & txtP5.Text + vbTab +
vbTab + vbTab & txtST5.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + vbTab + vbTab + vbTab + vbTab + vbTab & "Order Sub Total: " + vbTab & txtOST.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + vbTab + vbTab + vbTab + vbTab + vbTab & "Tax On Order: " + vbTab & txtTx.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + vbTab + vbTab + vbTab + vbTab + vbTab & "Net Total: " + vbTab & txtTtl.Text + vbNewLine)
txtReceipt.AppendText(vbNewLine + "===============================================================================================" + vbNewLine)
txtReceipt.AppendText(vbNewLine + vbTab + vbTab + vbTab + vbTab + vbTab & "ITERY ORDERS RECEIPT" + vbNewLine)
TabPage3.Enabled = False
con.Close()
Exit Sub
Else
MessageBox.Show("Customer ID is not Registered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Using
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
con.Close()
End If
con.Close()
End Sub
'BUTTON PRINT
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
PrintPreviewDialog1.ShowDialog()
End Sub
'BUTTON BACK
Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
Me.Hide()
frmMain.Show()
End Sub
'BUTTON ADD CUSTOMER INSTEAD
Private Sub btnCustomerIns_Click(sender As Object, e As EventArgs) Handles btnCustomerIns.Click
Me.Hide()
frmCustomer.Show()
End Sub
End Class