-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormOrderPage.vb
278 lines (240 loc) · 11.1 KB
/
FormOrderPage.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
Imports System.Windows.Forms.VisualStyles.VisualStyleElement
Imports System.Data.SqlClient
Imports System.Net
Imports System.Text.RegularExpressions
Public Class FormOrderPage
'sql variables
Dim conn As New SqlConnection
Dim cmd As New SqlCommand
Dim paymentMode As String 'variable to payment mode selected
Dim orderDate As Date 'variable to store the date of order
Dim deliveryDays As Integer 'variable to store the number of days of delivery
Dim deliveryDate As Date 'to store the delivery date
Dim uid As Integer
Private Sub FormOrderPage_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FormCardList.Close()
FormRegister.Close()
FormLogin.Hide()
Dim states() As String = {"Andhra Pradesh", "Arunachal Pradesh", "Assam", "Bihar", "Chhattisgarh", "Goa", "Gujarat", "Haryana", "Himachal Pradesh", "Jharkhand", "Karnataka", "Kerala", "Madhya Pradesh", "Maharashtra", "Manipur", "Meghalaya", "Mizoram", "Nagaland", "Odisha", "Punjab", "Rajasthan", "Sikkim", "Tamil Nadu", "Telangana", "Tripura", "Uttar Pradesh", "Uttarakhand", "West Bengal"}
' Add each state to the ComboBox control
For Each state As String In states
ComboBoxState.Items.Add(state)
Next
'initially setting to text box and label of upi and Gift details false
LabelUPIOrCard.Visible = False
TextBox1UPIOrCard.Visible = False
'setting all error images to false initially
PictureBoxErrorName.Visible = False
PictureBoxErrorPhone.Visible = False
PictureBoxErrorState.Visible = False
PictureBoxErrorCity.Visible = False
PictureBoxErrorAddress.Visible = False
PictureBoxErrorLandmark.Visible = False
PictureBoxErrorPincode.Visible = False
PictureBoxErrorPaymentMode.Visible = False
PictureBoxErrorUPI.Visible = False
'calculating the days of delivery
deliveryDays = CInt(Int((7 * Rnd()) + 3))
TimerDeliveryDate.Enabled = True
LabelMRP.Text = costprice
LabelDiscountedPrice.Text = totalAmount
LabelDeliveryCharge.Text = CInt(Int((50 * Rnd()) + 30))
LabelPayableAmount.Text = totalAmount + LabelDeliveryCharge.Text
'sql connection and query to get the name and phone no of the customer
conn.ConnectionString = "Data Source=LAPTOP-G773S8H7;Initial Catalog=SE-PROJECT;Integrated Security=True;"
conn.Open()
cmd = New SqlCommand("SELECT Name, Phone FROM TableUser WHERE Email = @email", conn)
cmd.Parameters.AddWithValue("@email", logedInEmail)
cmd.ExecuteNonQuery()
Dim reader As SqlDataReader = cmd.ExecuteReader
reader.Read()
'setting the name and phone text box
TextBoxName.Text = reader.Item("Name")
TextBoxPhoneNo.Text = reader.Item("Phone")
conn.Close()
End Sub
'confirm order details
Private Sub ButtonConfirmOrder_Click(sender As Object, e As EventArgs) Handles ButtonConfirmOrder.Click
'setting the error alert images to false
PictureBoxErrorName.Visible = False
PictureBoxErrorPhone.Visible = False
PictureBoxErrorState.Visible = False
PictureBoxErrorCity.Visible = False
PictureBoxErrorAddress.Visible = False
PictureBoxErrorLandmark.Visible = False
PictureBoxErrorPincode.Visible = False
PictureBoxErrorPaymentMode.Visible = False
PictureBoxErrorUPI.Visible = False
'checking if all the fields are entered correctly
If (checkName() And
checkPhoneNo() And
checkState() And
checkCity() And
checkAddress() And
checkPincode() And
checkLandmark() And
checkPaymentMode() And
checkUPIorCard()) Then
'setting sql server and inserting data in the table order
conn.ConnectionString = "Data Source=LAPTOP-G773S8H7;Initial Catalog=SE-PROJECT;Integrated Security=True;"
conn.Open()
cmd = New SqlCommand("INSERT INTO TableOrder VALUES ((SELECT ISNULL(MAX(OrderId) + 1, 1) FROM TableOrder), @state, @city, @addLine, @pincode, @landmark, @email, @cId, @quantity, @totalCost, @deliveryDate, @pMode, @name, @phone)", conn)
cmd.Parameters.AddWithValue("@state", ComboBoxState.SelectedItem)
cmd.Parameters.AddWithValue("@city", TextBoxCity.Text)
cmd.Parameters.AddWithValue("@addLine", TextBoxAddress.Text)
cmd.Parameters.AddWithValue("@pincode", TextBoxPincode.Text)
cmd.Parameters.AddWithValue("@landmark", TextBoxLandmark.Text)
cmd.Parameters.AddWithValue("@email", logedInEmail)
cmd.Parameters.AddWithValue("@cId", selectCardUid)
cmd.Parameters.AddWithValue("@quantity", quantitySelected)
cmd.Parameters.AddWithValue("@totalCost", LabelPayableAmount.Text)
cmd.Parameters.AddWithValue("@deliveryDate", deliveryDate)
cmd.Parameters.AddWithValue("@pMode", paymentMode)
cmd.Parameters.AddWithValue("@name", TextBoxName.Text)
cmd.Parameters.AddWithValue("@phone", TextBoxPhoneNo.Text)
cmd.ExecuteNonQuery()
'updating the inventory table
cmd = New SqlCommand("UPDATE TableInventory Set Quantity = ((SELECT Quantity FROM TableInventory WHERE GiftId = @id) - @qSet) WHERE GiftId = @id", conn)
cmd.Parameters.AddWithValue("@id", selectCardUid)
cmd.Parameters.AddWithValue("@qSet", quantitySelected)
cmd.ExecuteNonQuery()
conn.Close()
'message box gor order confirmation
MessageBox.Show("Your transaction of ₹" + LabelPayableAmount.Text + " is succesful." + vbCrLf + "Your order will be deliverd on " + deliveryDate + vbCrLf + "Thank You for shopping")
Me.Close()
FormCardList.Show()
End If
End Sub
Private Sub RadioButtonCard_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButtonCard.CheckedChanged
LabelUPIOrCard.Visible = True
LabelUPIOrCard.Text = "Card No."
TextBox1UPIOrCard.Visible = True
TextBox1UPIOrCard.Text = ""
paymentMode = "Card"
End Sub
Private Sub RadioButtonUPI_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButtonUPI.CheckedChanged
LabelUPIOrCard.Visible = True
LabelUPIOrCard.Text = "UPI Id"
TextBox1UPIOrCard.Visible = True
TextBox1UPIOrCard.Text = ""
paymentMode = "UPI"
End Sub
Private Sub RadioButtonPOD_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButtonPOD.CheckedChanged
paymentMode = "POD"
LabelUPIOrCard.Visible = False
TextBox1UPIOrCard.Visible = False
End Sub
Private Sub TimerDeliveryDate_Tick(sender As Object, e As EventArgs) Handles TimerDeliveryDate.Tick
orderDate = Date.Now.ToString("dd MMM yyyy")
deliveryDate = orderDate.AddDays(deliveryDays)
End Sub
'to check only numbers are being enterd in the pincode text box
Private Sub TextBoxPincode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBoxPincode.KeyPress
If Not Char.IsNumber(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.Handled = True
End If
End Sub
'to check only numbers are being enterd in the phoneno text box
Private Sub TextBoxPhoneNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBoxPhoneNo.KeyPress
If Not Char.IsNumber(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.Handled = True
End If
End Sub
Private Sub TextBox1UPIOrCard_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1UPIOrCard.KeyPress
If paymentMode = "Card" Then
If Not Char.IsNumber(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.Handled = True
End If
End If
End Sub
'checking if the name is entered
Private Function checkName() As Boolean
If (TextBoxName.Text = "") Then
PictureBoxErrorName.Visible = True
Return False
End If
Return True
End Function
'checking if the phoneno is entered correctly
Private Function checkPhoneNo() As Boolean
'checking if the phone no is of length of 10
Dim phone = TextBoxPhoneNo.Text
If (phone.Length <> 10) Then
PictureBoxErrorPhone.Visible = True
Return False
End If
Return True
End Function
'checking if the state is being entered
Private Function checkState() As Boolean
If (ComboBoxState.SelectedIndex = -1) Then
PictureBoxErrorState.Visible = True
Return False
End If
Return True
End Function
'checking if the city is entered
Private Function checkCity() As Boolean
If (TextBoxCity.Text = "") Then
PictureBoxErrorCity.Visible = True
Return False
End If
Return True
End Function
'checking if the address is being entered
Private Function checkAddress() As Boolean
If (TextBoxAddress.Text = "") Then
PictureBoxErrorAddress.Visible = True
Return False
End If
Return True
End Function
'checking if the landmark is entered
Private Function checkLandmark() As Boolean
If (TextBoxLandmark.Text = "") Then
PictureBoxErrorLandmark.Visible = True
Return False
End If
Return True
End Function
'checking if the pincode is enterd correctly
Private Function checkPincode() As Boolean
'checking if the phone no is of length of 10
Dim pin = TextBoxPincode.Text
If (pin.Length <> 6) Then
PictureBoxErrorPincode.Visible = True
Return False
End If
Return True
End Function
'checking if the payment mode is set
Private Function checkPaymentMode() As Boolean
If (paymentMode = "") Then
PictureBoxErrorPaymentMode.Visible = True
Return False
End If
Return True
End Function
'to check upi id or card no is entered correctly
Private Function checkUPIorCard() As Boolean
If paymentMode = "UPI" Then
If (TextBox1UPIOrCard.Text = "") Then
PictureBoxErrorUPI.Visible = True
Return False
End If
If Not (Regex.IsMatch(TextBox1UPIOrCard.Text, "[a-zA-Z0-9.\-_]{2,256}@[a-zA-Z]{2,64}")) Then
PictureBoxErrorUPI.Visible = True
Return False
End If
ElseIf paymentMode = "Card" Then
If Not TextBox1UPIOrCard.Text.ToString().Length = 12 Then
PictureBoxErrorUPI.Visible = True
Return False
End If
End If
Return True
End Function
Private Sub FormOrderPage_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
FormCardPage.Show()
End Sub
End Class