-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddNewCategory.aspx.vb
163 lines (120 loc) · 5.08 KB
/
AddNewCategory.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
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 AddNewCategory
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 btnUpdtCategory_Click(sender As Object, e As EventArgs) Handles btnUpdtCategory.Click
CheckCategory()
End Sub
Private Sub CheckCategory()
Try
Dim querry As String = "SELECT * FROM SHOPLIFYMENUTYPE WHERE MENUCATEGORYNAME = @MENUCATEGORYNAME"
cmd.CommandText = querry
cmd.Connection = cn
cmd.Parameters.AddWithValue("@MENUCATEGORYNAME", txtCategoryName.Text)
cn.Open()
Dim lrd As SqlDataReader = cmd.ExecuteReader()
If lrd.HasRows = True Then
While lrd.Read()
Me.lblerrorMenu.Text = "This Menu " & Me.txtCategoryName.Text & " is already register!"
End While
Else
Me.lblerrorMenu.Text = ""
AddNewMenuCategory()
End If
Catch ex As Exception
cn.Close()
End Try
End Sub
Private Sub AddNewMenuCategory()
Dim CONVERTDATE As Date = Date.Now.ToString()
Try
Dim xSQL As New System.Text.StringBuilder
xSQL.AppendLine("INSERT INTO SHOPLIFYMENUTYPE")
xSQL.AppendLine("(MENUCATEGORYNAME, MENUCATEGORYADDBY, MENUCATEGORYADDDATE)")
xSQL.AppendLine("VALUES")
xSQL.AppendLine("(@MENUCATEGORYNAME, @MENUCATEGORYADDBY, @MENUCATEGORYADDDATE)")
Using cn As New SqlConnection(ConString)
cn.Open()
Dim cmd As New SqlCommand(xSQL.ToString, cn)
cmd.Parameters.AddWithValue("@MENUCATEGORYNAME", Me.txtCategoryName.Text.Trim)
cmd.Parameters.AddWithValue("@MENUCATEGORYADDBY", Session("ssUserFullName"))
cmd.Parameters.AddWithValue("@MENUCATEGORYADDDATE", CONVERTDATE)
cmd.ExecuteNonQuery()
cn.Close()
End Using
mp_done_category.Show()
Catch ex As Exception
lbl_errorCategory.Text = ex.GetBaseException().ToString()
mp_errorCategory.Show()
End Try
End Sub
Protected Sub btnOK_Click(sender As Object, e As EventArgs)
Response.Redirect("AddNewCategory.aspx")
End Sub
Private Sub GridView1_RowDeleted(sender As Object, e As GridViewDeletedEventArgs) Handles GridView1.RowDeleted
If e.Exception Is Nothing Then
If e.AffectedRows = 1 Then
MyMsgBox("Category deleted successfully.")
Else
MyMsgBox("An error occurred during the delete operation.")
End If
Else
MyMsgBox("Category cannot be deleted because there is item in this category. Please delete first all item in this category to continue this operation.")
e.ExceptionHandled = True
End If
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 btnaddnewmenu_Click(sender As Object, e As EventArgs) Handles btnaddnewmenu.Click
Response.Redirect("~/AddNewMenu.aspx")
End Sub
Private Sub btnadddeletecategory_Click(sender As Object, e As EventArgs) Handles btnadddeletecategory.Click
Response.Redirect("~/AddNewCategory.aspx")
End Sub
Private Sub btneditmenu_Click(sender As Object, e As EventArgs) Handles btneditmenu.Click
Response.Redirect("~/ManageMenu.aspx")
End Sub
Private Sub btnenabledisbalemenu_Click(sender As Object, e As EventArgs) Handles btnenabledisbalemenu.Click
Response.Redirect("~/MenuActivation.aspx")
End Sub
End Class