-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManageOrderKitchen.aspx.vb
598 lines (406 loc) · 21 KB
/
ManageOrderKitchen.aspx.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
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.UI
Imports System.Web.Security
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Drawing
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Imports System.Net.Mail
Imports System.Net
'Imports FireSharp.Config
'Imports FireSharp.Interfaces
'Imports FireSharp.Response
Partial Class ManageOrderKitchen
Inherits System.Web.UI.Page
Public cn As New SqlConnection
Public cmd As New SqlCommand
Public da As SqlDataAdapter
Public dr As SqlDataReader
Public ds As DataSet = New DataSet
Public ConString As String = System.Configuration.ConfigurationManager.ConnectionStrings("dbconn").ConnectionString
'Dim config As IFirebaseConfig = New FirebaseConfig()
' Dim client As IFirebaseClient
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
MyCn()
CheckLogin()
' With config
'.AuthSecret = "qouNheeugeH8zlglwzrrBAiGUGsaoIwroLTxiwI6"
' .BasePath = "https://shoplifymagicx.firebaseio.com/"
' End With
' client = New FireSharp.FirebaseClient(config)
End Sub
Public Sub MyCn()
If cn.State = Data.ConnectionState.Open Then cn.Close()
cn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("dbconn").ConnectionString
End Sub
Protected Sub CheckLogin()
If Session("ssUserName") = "" Then
Me.Response.Redirect("Default.aspx")
End If
End Sub
Private Sub ListView1_PreRender(sender As Object, e As EventArgs) Handles ListView1.PreRender
Try
Dim dli As ListViewItem
Dim previousOrderNum As String = ""
Dim currOrderNum As String = ""
Dim orderstatus As String = ""
Dim orderid As Integer = 0
For Each dli In ListView1.Items
currOrderNum = DirectCast(dli.FindControl("orderNum"), Label).Text
orderid = DirectCast(dli.FindControl("ORDERIDLabel"), Label).Text
If currOrderNum = previousOrderNum Then
dli.FindControl("orderNum").Visible = False
dli.FindControl("ORDERTAKEBYLabel").Visible = False
dli.FindControl("ORDERTAKETIMELabel").Visible = False
dli.FindControl("FINALORDERSTATUSLabel").Visible = False
dli.FindControl("ORDERTABLELabel").Visible = False
dli.FindControl("TOTALMENUORDERLabel").Visible = False
dli.FindControl("Tablelbl").Visible = False
dli.FindControl("Totalqtylbl").Visible = False
dli.FindControl("Takebylbl").Visible = False
dli.FindControl("hr1").Visible = False
dli.FindControl("ordernumttl").Visible = False
End If
orderstatus = DirectCast(dli.FindControl("ORDERSTATUSLabel"), Label).Text
If orderstatus = "SUBMIT TO KITCHEN" Then
dli.FindControl("btnrevertorder").Visible = False
dli.FindControl("btnfinishorder").Visible = False
ElseIf orderstatus = "PROCESSING" Then
dli.FindControl("btnstartorder").Visible = False
dli.FindControl("btnrejectorder").Visible = False
ElseIf orderstatus = "FINISH COOK" Then
dli.FindControl("btnstartorder").Visible = False
dli.FindControl("btnrejectorder").Visible = False
dli.FindControl("btnrevertorder").Visible = False
dli.FindControl("btnfinishorder").Visible = False
ElseIf orderstatus = "REJECT" Then
dli.FindControl("btnstartorder").Visible = False
dli.FindControl("btnrejectorder").Visible = False
dli.FindControl("btnrevertorder").Visible = False
dli.FindControl("btnfinishorder").Visible = False
End If
Dim finalorderstatus As String = DirectCast(dli.FindControl("FINALORDERSTATUSLabel"), Label).Text
If finalorderstatus = "PROCESSING" Then
Dim myLi As Label = CType(dli.FindControl("FINALORDERSTATUSLabel"), Label)
myLi.Attributes.Add("class", myLi.Attributes("class").ToString() & "label label-danger font-weight-bold font-16")
dli.FindControl("finalstatusspinner").Visible = True
If currOrderNum = previousOrderNum Then
dli.FindControl("finalstatusspinner").Visible = False
End If
Else
dli.FindControl("finalstatusspinner").Visible = False
End If
Dim orderstatuseach As String = DirectCast(dli.FindControl("ORDERSTATUSLabel"), Label).Text
If orderstatuseach = "SUBMIT TO KITCHEN" Then
Dim myLi As Label = CType(dli.FindControl("ORDERSTATUSLabel"), Label)
myLi.Attributes.Add("class", myLi.Attributes("class").ToString() & "label label-warning font-weight-bold font-16")
dli.FindControl("eachstatusspinner").Visible = False
ElseIf orderstatuseach = "PROCESSING" Then
Dim myLi As Label = CType(dli.FindControl("ORDERSTATUSLabel"), Label)
myLi.Attributes.Add("class", myLi.Attributes("class").ToString() & "label label-danger font-weight-bold font-16")
dli.FindControl("eachstatusspinner").Visible = True
ElseIf orderstatuseach = "FINISH COOK" Then
Dim myLi As Label = CType(dli.FindControl("ORDERSTATUSLabel"), Label)
myLi.Attributes.Add("class", myLi.Attributes("class").ToString() & "label label-success font-weight-bold font-16")
dli.FindControl("eachstatusspinner").Visible = False
ElseIf orderstatuseach = "REJECT" Then
Dim myLi As Label = CType(dli.FindControl("ORDERSTATUSLabel"), Label)
myLi.Attributes.Add("class", myLi.Attributes("class").ToString() & "label label-danger font-weight-bold font-16")
dli.FindControl("eachstatusspinner").Visible = False
Else
dli.FindControl("eachstatusspinner").Visible = False
End If
Dim countfinishcook As Integer = 0
Dim totalmenuorder As Integer = 0
Try
cmd.Parameters.Clear()
MyCn()
cn.Open()
cmd.Connection = cn
cmd.CommandText = "SELECT ORDERQUANTITY FROM SHOPLIFYORDER WHERE ORDERSTATUS = @ORDERSTATUS AND ORDERFINALNUMBER = @ORDERFINALNUMBER"
cmd.Parameters.AddWithValue("@ORDERSTATUS", "FINISH COOK")
cmd.Parameters.AddWithValue("@ORDERFINALNUMBER", currOrderNum)
Dim lrd4 As SqlDataReader = cmd.ExecuteReader()
If lrd4.HasRows = True Then
While lrd4.Read()
countfinishcook = countfinishcook + lrd4.Item("ORDERQUANTITY")
End While
End If
cn.Close()
Catch ex As Exception
MyMsgBox("11th Try" + ex.GetBaseException().ToString())
End Try
Try
cmd.Parameters.Clear()
MyCn()
cn.Open()
cmd.Connection = cn
cmd.CommandText = "SELECT TOTALMENUORDER FROM SHOPLIFYORDERTOTAL WHERE ORDERFINALNUM = @ORDERFINALNUM"
cmd.Parameters.AddWithValue("@ORDERFINALNUM", currOrderNum)
Dim lrd As SqlDataReader = cmd.ExecuteReader()
If lrd.HasRows = True Then
While lrd.Read()
totalmenuorder = lrd.Item("TOTALMENUORDER")
End While
End If
cn.Close()
Catch ex As Exception
MyMsgBox("12th Try" + ex.GetBaseException().ToString())
End Try
If totalmenuorder = countfinishcook Then
Try
cmd.Parameters.Clear()
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE SHOPLIFYORDERTOTAL")
xSQL.AppendLine("SET")
xSQL.AppendLine("FINALORDERSTATUS = @FINALORDERSTATUS")
xSQL.AppendLine("WHERE ORDERFINALNUM = @ORDERFINALNUM")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
cmd.Parameters.AddWithValue("@FINALORDERSTATUS", "FINISH COOK")
cmd.Parameters.AddWithValue("@ORDERFINALNUM", currOrderNum)
cmd.ExecuteNonQuery()
cn.Close()
End Using
Catch ex As Exception
MyMsgBox("13th Try" + ex.GetBaseException().ToString())
End Try
End If
previousOrderNum = currOrderNum
Next
Catch ex As Exception
MyMsgBox("First Try" + ex.GetBaseException().ToString())
End Try
End Sub
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
ListView1.DataBind()
End Sub
Private Sub ListView1_ItemCommand(sender As Object, e As ListViewCommandEventArgs) Handles ListView1.ItemCommand
If e.CommandName = "STARTORDER" Then
'Start Manage Order for Button Start
Dim itemIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim OrderID As String = ListView1.DataKeys(itemIndex).Values(0).ToString()
Dim OrderNum As String = ListView1.DataKeys(itemIndex).Values(1).ToString()
Try
cmd.Parameters.Clear()
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE SHOPLIFYORDER")
xSQL.AppendLine("SET")
xSQL.AppendLine("ORDERSTATUS = @ORDERSTATUS")
xSQL.AppendLine("WHERE ORDERID = @ORDERID AND ORDERFINALNUMBER = @ORDERFINALNUMBER")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
cmd.Parameters.AddWithValue("@ORDERSTATUS", "PROCESSING")
cmd.Parameters.AddWithValue("@ORDERID", OrderID)
cmd.Parameters.AddWithValue("@ORDERFINALNUMBER", OrderNum)
cmd.ExecuteNonQuery()
cn.Close()
End Using
Catch ex As Exception
MyMsgBox("Second Try" + ex.GetBaseException().ToString())
End Try
Try
cmd.Parameters.Clear()
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE SHOPLIFYORDERTOTAL")
xSQL.AppendLine("SET")
xSQL.AppendLine("FINALORDERSTATUS = @FINALORDERSTATUS")
xSQL.AppendLine("WHERE ORDERFINALNUM = @ORDERFINALNUM")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
cmd.Parameters.AddWithValue("@FINALORDERSTATUS", "PROCESSING")
cmd.Parameters.AddWithValue("@ORDERFINALNUM", OrderNum)
cmd.ExecuteNonQuery()
cn.Close()
End Using
Catch ex As Exception
MyMsgBox("Third Try" + ex.GetBaseException().ToString())
End Try
ListView1.DataBind()
'End Manage Order for Button Start
End If
If e.CommandName = "REVERTORDER" Then
'Start Manage Order for Button Revert
Dim itemIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim OrderID As String = ListView1.DataKeys(itemIndex).Values(0).ToString()
Dim OrderNum As String = ListView1.DataKeys(itemIndex).Values(1).ToString()
Try
cmd.Parameters.Clear()
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE SHOPLIFYORDER")
xSQL.AppendLine("SET")
xSQL.AppendLine("ORDERSTATUS = @ORDERSTATUS")
xSQL.AppendLine("WHERE ORDERID = @ORDERID AND ORDERFINALNUMBER = @ORDERFINALNUMBER")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
cmd.Parameters.AddWithValue("@ORDERSTATUS", "SUBMIT TO KITCHEN")
cmd.Parameters.AddWithValue("@ORDERID", OrderID)
cmd.Parameters.AddWithValue("@ORDERFINALNUMBER", OrderNum)
cmd.ExecuteNonQuery()
cn.Close()
End Using
Catch ex As Exception
MyMsgBox("4th Try" + ex.GetBaseException().ToString())
End Try
'Try
' cmd.Parameters.Clear()
'Dim xSQL As New System.Text.StringBuilder
' xSQL.AppendLine("UPDATE SHOPLIFYORDERTOTAL")
' xSQL.AppendLine("SET")
'xSQL.AppendLine("FINALORDERSTATUS = @FINALORDERSTATUS")
'xSQL.AppendLine("WHERE ORDERFINALNUM = @ORDERFINALNUM")
'Using cn As New SqlConnection(ConString)
'cn.Open()
'Dim cmd As New SqlCommand(xSQL.ToString, cn)
'cmd.Parameters.AddWithValue("@FINALORDERSTATUS", "SUBMIT TO KITCHEN")
'cmd.Parameters.AddWithValue("@ORDERFINALNUM", OrderNum)
'cmd.ExecuteNonQuery()
'cn.Close()
'End Using
'Catch ex As Exception
'MyMsgBox("5th Try" + ex.GetBaseException().ToString())
'End Try
ListView1.DataBind()
'End Manage Order for Button Revert
End If
'Start Manage Order for Button Finish
If e.CommandName = "FINISHORDER" Then
'Start Manage Order for Button Revert
Dim itemIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim OrderID As String = ListView1.DataKeys(itemIndex).Values(0).ToString()
Dim OrderNum As String = ListView1.DataKeys(itemIndex).Values(1).ToString()
Try
cmd.Parameters.Clear()
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE SHOPLIFYORDER")
xSQL.AppendLine("SET")
xSQL.AppendLine("ORDERSTATUS = @ORDERSTATUS")
xSQL.AppendLine("WHERE ORDERID = @ORDERID AND ORDERFINALNUMBER = @ORDERFINALNUMBER")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
cmd.Parameters.AddWithValue("@ORDERSTATUS", "FINISH COOK")
cmd.Parameters.AddWithValue("@ORDERID", OrderID)
cmd.Parameters.AddWithValue("@ORDERFINALNUMBER", OrderNum)
cmd.ExecuteNonQuery()
cn.Close()
End Using
Catch ex As Exception
MyMsgBox("6th Try" + ex.GetBaseException().ToString())
End Try
ListView1.DataBind()
End If
'End Manage Order for Button Finish
'Start Manage Order for Button Reject
If e.CommandName = "REJECTORDER" Then
Dim itemIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim OrderID As String = ListView1.DataKeys(itemIndex).Values(0).ToString()
Dim OrderNum As String = ListView1.DataKeys(itemIndex).Values(1).ToString()
Dim TotalMenuReject As Integer = 0
Dim TotalMenuOrder As Integer = 0
Dim TotalOrderPrice As Decimal = 0
Dim OrderPrice As Integer = 0
Dim OrderQuantity As Integer = 0
Try
cmd.Parameters.Clear()
MyCn()
cn.Open()
cmd.Connection = cn
cmd.CommandText = "SELECT TOTALMENUORDER, TOTALMENUREJECT, ORDERTOTALPRICE FROM SHOPLIFYORDERTOTAL WHERE ORDERFINALNUM = @ORDERFINALNUM"
cmd.Parameters.AddWithValue("@ORDERFINALNUM", OrderNum)
Dim lrd2 As SqlDataReader = cmd.ExecuteReader()
If lrd2.HasRows = True Then
While lrd2.Read()
TotalMenuReject = lrd2.Item("TOTALMENUREJECT")
TotalMenuOrder = lrd2.Item("TOTALMENUORDER")
TotalOrderPrice = lrd2.Item("ORDERTOTALPRICE")
End While
End If
Catch ex As Exception
MyMsgBox("7th Try" + ex.GetBaseException().ToString())
End Try
Try
cmd.Parameters.Clear()
MyCn()
cn.Open()
cmd.Connection = cn
cmd.CommandText = "SELECT ORDERTOTALPRICE, ORDERQUANTITY FROM SHOPLIFYORDER WHERE ORDERFINALNUMBER = @ORDERFINALNUMBER AND ORDERID = @ORDERID"
cmd.Parameters.AddWithValue("@ORDERFINALNUMBER", OrderNum)
cmd.Parameters.AddWithValue("@ORDERID", OrderID)
Dim lrd2 As SqlDataReader = cmd.ExecuteReader()
If lrd2.HasRows = True Then
While lrd2.Read()
OrderPrice = lrd2.Item("ORDERTOTALPRICE")
OrderQuantity = lrd2.Item("ORDERQUANTITY")
End While
End If
Catch ex As Exception
MyMsgBox("8th Try" + ex.GetBaseException().ToString())
End Try
Try
cmd.Parameters.Clear()
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE SHOPLIFYORDERTOTAL")
xSQL.AppendLine("SET")
xSQL.AppendLine("ORDERTOTALPRICE = @ORDERTOTALPRICE, TOTALMENUORDER = @TOTALMENUORDER, TOTALMENUREJECT = @TOTALMENUREJECT")
xSQL.AppendLine("WHERE ORDERFINALNUM = @ORDERFINALNUM")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
TotalMenuReject = TotalMenuReject + OrderQuantity
TotalMenuOrder = TotalMenuOrder - OrderQuantity
TotalOrderPrice = TotalOrderPrice - OrderPrice
cmd.Parameters.AddWithValue("@ORDERTOTALPRICE", TotalOrderPrice)
cmd.Parameters.AddWithValue("@TOTALMENUREJECT", TotalMenuReject)
cmd.Parameters.AddWithValue("@TOTALMENUORDER", TotalMenuOrder)
cmd.Parameters.AddWithValue("@ORDERFINALNUM", OrderNum)
cmd.ExecuteNonQuery()
cn.Close()
End Using
Catch ex As Exception
MyMsgBox("9th Try" + ex.GetBaseException().ToString())
End Try
Try
cmd.Parameters.Clear()
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE SHOPLIFYORDER")
xSQL.AppendLine("SET")
xSQL.AppendLine("ORDERSTATUS = @ORDERSTATUS")
xSQL.AppendLine("WHERE ORDERID = @ORDERID AND ORDERFINALNUMBER = @ORDERFINALNUMBER")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
cmd.Parameters.AddWithValue("@ORDERSTATUS", "REJECT")
cmd.Parameters.AddWithValue("@ORDERID", OrderID)
cmd.Parameters.AddWithValue("@ORDERFINALNUMBER", OrderNum)
cmd.ExecuteNonQuery()
cn.Close()
End Using
Catch ex As Exception
MyMsgBox("10th Try" + ex.GetBaseException().ToString())
End Try
ListView1.DataBind()
End If
'End Manage Order for Button Reject
End Sub
Protected Sub MyMsgBox(ByVal tcMessage As String)
Dim lcScript As String
tcMessage = Replace(tcMessage, vbCrLf, "\n")
tcMessage = Replace(tcMessage, """", "")
lcScript = "<script language=""javascript"">" &
"alert(""" & tcMessage & """);" & vbCrLf &
"</script>"
Page.ClientScript.RegisterStartupScript(GetType(String), "PopUp", lcScript)
End Sub
End Class