-
Notifications
You must be signed in to change notification settings - Fork 0
/
suppliers.aspx.vb
164 lines (135 loc) · 6.12 KB
/
suppliers.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
Imports System.Data
Imports Telerik.Web.UI
Imports System.Data.SqlClient
Partial Class manager_Default
Inherits System.Web.UI.Page
Protected Sub rgSuppliers_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgSuppliers.ItemCommand
' change Suppliers order of priority
If (e.CommandName = "MoveUp") Or (e.CommandName = "MoveDown") Then
If (TypeOf e.Item Is GridItem) Then
Dim item As GridItem = DirectCast(e.Item, GridItem)
Dim position As String = e.CommandArgument
Dim id As String = CType(item.FindControl("hiddenId"), HiddenField).Value
' check for direction of movement
Dim direction As Boolean = True
If (e.CommandName = "MoveUp") Then direction = False
changePosition(id, position, direction)
End If
End If
End Sub
Protected Sub changePosition(ByVal id As Integer, ByVal position As String, ByVal direction As Boolean)
Dim connString As String = System.Configuration.ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString
Dim myConn As New SqlConnection(connString)
Dim cmd As New SqlCommand
cmd.Parameters.Clear()
cmd.CommandText = "updateSupplierPriority"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = myConn
cmd.Parameters.AddWithValue("@id", id)
cmd.Parameters.AddWithValue("@direction", direction)
cmd.Parameters.AddWithValue("@position", position)
cmd.Parameters.AddWithValue("@userId", Session("userId"))
Try
myConn.Open()
cmd.ExecuteScalar()
Catch ex As Exception
Trace.Write(ex.ToString)
myConn.Close()
End Try
rgSuppliers.DataBind()
End Sub
Protected Sub rgSuppliers_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles rgSuppliers.ItemDataBound
' hide delete option for build elements that were created before variation mode
If (TypeOf (e.Item) Is GridDataItem) Then
'Get the instance of the right type
Dim item As GridDataItem = e.Item
Dim deleteColumn = item("DeleteColumn")
Dim isLocked = item("isLocked").Text
' hide unresourced
Dim supplierId = item("supplierId").Text
Dim supplierName = item("supplierName").Text
Dim supplier = item("supplier")
Dim hlSupplier As HyperLink = supplier.FindControl("hlSupplier")
Dim lblSupplier As Label = supplier.FindControl("lblSupplier")
hlSupplier.Text = supplierName
hlSupplier.NavigateUrl = String.Format("~/supplier_details.aspx?id={0}", supplierId)
hlSupplier.Visible = True
lblSupplier.Visible = False
' don't allow user to delete themselves from the supplier list
' indicate their supplier
If isLocked Then
deleteColumn.Visible = False
End If
' check for last or first item
Dim itemIndex = e.Item.DataSetIndex
If (itemIndex = 0) Then
' first item
Dim lbUp As LinkButton = DirectCast(item("position").FindControl("lbUp"), LinkButton)
lbUp.Visible = False
ElseIf (itemIndex = e.Item.OwnerTableView.DataSourceCount - 1) Then
' last item
Dim lbDown As LinkButton = DirectCast(item("position").FindControl("lbDown"), LinkButton)
lbDown.Visible = False
End If
End If
End Sub
Protected Sub rgSuppliers_ItemDeleted(source As Object, e As Telerik.Web.UI.GridDeletedEventArgs) Handles rgSuppliers.ItemDeleted
rcbSuppliers.DataBind()
End Sub
Protected Sub rcbSuppliers_DataBound(sender As Object, e As System.EventArgs) Handles rcbSuppliers.DataBound
If rcbSuppliers.Items.Count = 0 Then
pNewSuppliers.Visible = False
Else
pNewSuppliers.Visible = True
End If
End Sub
Protected Sub btnAddSupplier_Click(sender As Object, e As System.EventArgs) Handles btnAddSupplier.Click
Trace.Write("FOOO")
btnAddSupplier.Enabled = False
Dim supplierId = rcbSuppliers.SelectedValue
If supplierId > 0 Then
AddSupplierToPriorityList(supplierId)
End If
rcbSuppliers.DataBind()
rgSuppliers.DataBind()
btnAddSupplier.Enabled = True
End Sub
Protected Sub AddSupplierToPriorityList(ByVal supplierId As String)
Dim connString As String = System.Configuration.ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString
Dim myConn As New SqlConnection(connString)
Dim cmd As New SqlCommand
cmd.Parameters.Clear()
cmd.CommandText = "insertSupplierPriority"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = myConn
cmd.Parameters.AddWithValue("@supplierId", supplierId)
cmd.Parameters.AddWithValue("@userId", Session("userId"))
Try
myConn.Open()
cmd.ExecuteScalar()
Catch ex As Exception
Trace.Write(ex.ToString)
myConn.Close()
End Try
End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim activeLink As HyperLink = CType(Master.FindControl("hlSuppliers"), HyperLink)
activeLink.CssClass = "active"
addSupplierShortcut()
End Sub
Protected Sub addSupplierShortcut()
Dim action As String = Request.QueryString("action")
If action = "add_supplier" Then
addSupplierScript.Visible = True
End If
End Sub
Protected Sub fvSupplierInsert_ItemInserted(sender As Object, e As FormViewInsertedEventArgs) Handles fvSupplierInsert.ItemInserted
rgSuppliers.DataBind()
moveTourPhase()
End Sub
Protected Sub moveTourPhase()
If Session("tourPhase") = 7 Then
Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri)
End If
End Sub
End Class