-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCashierPayment.aspx.vb
350 lines (232 loc) · 12.2 KB
/
CashierPayment.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
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
Partial Class CashierPayment
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
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
MyCn()
CheckLogin()
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
Dim dli As ListViewItem
Dim currenttablestatus As String = ""
Dim currentpaymentstatus As String = ""
For Each dli In ListView1.Items
currenttablestatus = DirectCast(dli.FindControl("CURRENTTABLESTATUSlbl"), Label).Text
currentpaymentstatus = DirectCast(dli.FindControl("CURRENTPAYMENTSTATUSlbl"), Label).Text
If currenttablestatus = "AVAILABLE" Then
dli.FindControl("imgtableavailable").Visible = True
dli.FindControl("imgtablenotpaid").Visible = False
dli.FindControl("imgtabledonepaid").Visible = False
Dim myLi As Button = CType(dli.FindControl("Button1"), Button)
myLi.Attributes.Add("class", myLi.Attributes("class").ToString() & "btn btn-block btn-lg btn-secondary font-weight-bold")
ElseIf currenttablestatus = "OCCUPIED" And currentpaymentstatus = "NOT PAID" Then
dli.FindControl("imgtableavailable").Visible = False
dli.FindControl("imgtablenotpaid").Visible = True
dli.FindControl("imgtabledonepaid").Visible = False
Dim myLi As Button = CType(dli.FindControl("Button1"), Button)
myLi.Attributes.Add("class", myLi.Attributes("class").ToString() & "btn btn-block btn-lg btn-danger font-weight-bold")
ElseIf currenttablestatus = "OCCUPIED" And currentpaymentstatus = "PAID" Then
dli.FindControl("imgtableavailable").Visible = False
dli.FindControl("imgtablenotpaid").Visible = False
dli.FindControl("imgtabledonepaid").Visible = True
Dim myLi As Button = CType(dli.FindControl("Button1"), Button)
myLi.Attributes.Add("class", myLi.Attributes("class").ToString() & "btn btn-block btn-lg btn-success font-weight-bold")
End If
Next
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
Private Sub ListView1_ItemCommand(sender As Object, e As ListViewCommandEventArgs) Handles ListView1.ItemCommand
If e.CommandName = "VIEWORDER" Then
Dim itemIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim ordernumber As String
Dim tablenumber As String
Dim paymentstatus As String
ordernumber = ListView1.DataKeys(itemIndex).Values(0).ToString()
tablenumber = ListView1.DataKeys(itemIndex).Values(1).ToString()
paymentstatus = ListView1.DataKeys(itemIndex).Values(2).ToString()
Try
cmd.Parameters.Clear()
MyCn()
cn.Open()
cmd.Connection = cn
cmd.CommandText = "SELECT SHOPLIFYORDER.ORDERMENUCODE, SHOPLIFYORDER.ORDERQUANTITY, SHOPLIFYORDER.ORDERDESCRIPTION, SHOPLIFYORDER.ORDERTOTALPRICE, SHOPLIFYMENUMASTER.MENUNAME, SHOPLIFYMENUMASTER.MENUPRICE, SHOPLIFYORDERTOTAL.TOTALMENUORDER, SHOPLIFYORDERTOTAL.ORDERTOTALPRICE AS Expr1, SHOPLIFYORDERTOTAL.ORDERFINALNUM, SHOPLIFYORDERTOTAL.TABLENUM, SHOPLIFYORDERTOTAL.PAYMENT FROM SHOPLIFYORDER INNER JOIN SHOPLIFYORDERTOTAL ON SHOPLIFYORDER.ORDERNUM = SHOPLIFYORDERTOTAL.ORDERNUM INNER JOIN SHOPLIFYMENUMASTER ON SHOPLIFYORDER.ORDERMENUCODE = SHOPLIFYMENUMASTER.MENUCODE WHERE SHOPLIFYORDERTOTAL.TABLENUM = '" & tablenumber & "' AND SHOPLIFYORDERTOTAL.CURRENTTABLESTATUS = 'OCCUPIED' "
GridView1.DataSource = cmd.ExecuteReader
Session("cashierOrderNum") = ordernumber
Session("cashiertablenum") = tablenumber
If paymentstatus = "NOT PAID" Then
btnavailabletable.Visible = False
btnconfirmpay.Visible = True
ElseIf paymentstatus = "PAID" Then
btnconfirmpay.Visible = False
btnavailabletable.Visible = True
Else
btnconfirmpay.Visible = False
btnavailabletable.Visible = False
End If
GridView1.DataBind()
For i As Integer = GridView1.Rows.Count - 1 To 1 Step -1
Dim row As GridViewRow = GridView1.Rows(i)
Dim previousRow As GridViewRow = GridView1.Rows(i - 1)
For j As Integer = 0 To row.Cells.Count - 1
If j <> 2 Then
If j <> 3 Then
If j <> 4 Then
If j <> 5 Then
If j <> 7 Then
If j <> 10 Then
If row.Cells(j).Text = previousRow.Cells(j).Text Then
If previousRow.Cells(j).RowSpan = 0 Then
If row.Cells(j).RowSpan = 0 Then
previousRow.Cells(j).RowSpan += 2
Else
previousRow.Cells(j).RowSpan = row.Cells(j).RowSpan + 1
End If
row.Cells(j).Visible = False
End If
End If
End If
End If
End If
End If
End If
End If
Next
Next
UpdatePanel1.Update()
cn.Close()
Catch ex As Exception
MyMsgBox("First Try" + ex.GetBaseException().ToString())
End Try
UpdatePanel2.UpdateMode = UpdatePanelUpdateMode.Conditional
UpdatePanel2.Update()
mp_viewInvoice.Show()
End If
End Sub
Private Sub btnconfirmpay_Click(sender As Object, e As EventArgs) Handles btnconfirmpay.Click
Try
cmd.Parameters.Clear()
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE SHOPLIFYORDERTOTAL")
xSQL.AppendLine("SET")
xSQL.AppendLine("PAYMENT = @PAYMENT,PAYMENTTYPE = @PAYMENTTYPE, PAYMENTMADEUSING = @PAYMENTMADEUSING")
xSQL.AppendLine("WHERE TABLENUM = @TABLENUM AND CURRENTTABLESTATUS = @CURRENTTABLESTATUS")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
cmd.Parameters.AddWithValue("@PAYMENT", "PAID")
cmd.Parameters.AddWithValue("@PAYMENTTYPE", "ONSITE")
cmd.Parameters.AddWithValue("@PAYMENTMADEUSING", "Cash")
cmd.Parameters.AddWithValue("@TABLENUM", Session("cashiertablenum"))
cmd.Parameters.AddWithValue("@CURRENTTABLESTATUS", "OCCUPIED")
cmd.ExecuteNonQuery()
cn.Close()
End Using
Catch ex As Exception
MyMsgBox("2nd Try" + ex.GetBaseException().ToString())
End Try
Try
cmd.Parameters.Clear()
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE SHOPLIFYRESTAURANTTABLE")
xSQL.AppendLine("SET")
xSQL.AppendLine("CURRENTTABLESTATUS = @CURRENTTABLESTATUS, CURRENTPAYMENTSTATUS = @CURRENTPAYMENTSTATUS")
xSQL.AppendLine("WHERE TABLENUM = @TABLENUM")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
cmd.Parameters.AddWithValue("@CURRENTTABLESTATUS", "OCCUPIED")
cmd.Parameters.AddWithValue("@CURRENTPAYMENTSTATUS", "PAID")
cmd.Parameters.AddWithValue("@TABLENUM", Session("cashiertablenum"))
cmd.ExecuteNonQuery()
cn.Close()
End Using
Catch ex As Exception
MyMsgBox("3rd Try" + ex.GetBaseException().ToString())
End Try
ListView1.DataBind()
GridView1.DataBind()
End Sub
Private Sub btnavailabletable_Click(sender As Object, e As EventArgs) Handles btnavailabletable.Click
Try
cmd.Parameters.Clear()
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE SHOPLIFYORDERTOTAL")
xSQL.AppendLine("SET")
xSQL.AppendLine("CURRENTTABLESTATUS = @CURRENTTABLESTATUS")
xSQL.AppendLine("WHERE TABLENUM = @TABLENUM AND PAYMENT = @PAYMENT")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
cmd.Parameters.AddWithValue("@CURRENTTABLESTATUS", "AVAILABLE")
cmd.Parameters.AddWithValue("@PAYMENT", "PAID")
cmd.Parameters.AddWithValue("@TABLENUM", Session("cashiertablenum"))
cmd.ExecuteNonQuery()
cn.Close()
End Using
Catch ex As Exception
MyMsgBox("4rd Try" + ex.GetBaseException().ToString())
End Try
Try
cmd.Parameters.Clear()
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("UPDATE SHOPLIFYRESTAURANTTABLE")
xSQL.AppendLine("SET")
xSQL.AppendLine("CURRENTTABLESTATUS = @CURRENTTABLESTATUS,CURRENTMENUORDER = @CURRENTMENUORDER,CURRENTPAYMENTSTATUS = @CURRENTPAYMENTSTATUS")
xSQL.AppendLine("WHERE TABLENUM = @TABLENUM")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
cmd.Parameters.AddWithValue("@CURRENTTABLESTATUS", "AVAILABLE")
cmd.Parameters.AddWithValue("@CURRENTMENUORDER", DBNull.Value)
cmd.Parameters.AddWithValue("@CURRENTPAYMENTSTATUS", DBNull.Value)
cmd.Parameters.AddWithValue("@TABLENUM", Session("cashiertablenum"))
cmd.ExecuteNonQuery()
cn.Close()
End Using
Catch ex As Exception
MyMsgBox("5th Try" + ex.GetBaseException().ToString())
End Try
ListView1.DataBind()
GridView1.DataBind()
End Sub
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
ListView1.DataBind()
End Sub
End Class