-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_details.aspx.vb
486 lines (401 loc) · 20.9 KB
/
task_details.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
Imports System.Data.SqlClient
Imports Telerik.Web.UI
Imports System.Data
Partial Class manager_task_details
Inherits MyBaseClass
Dim isLocked As Boolean = False
Private Const ItemsPerRequest As Integer = 100
Protected Sub rcbResources_ItemsRequested(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles rcbResources.ItemsRequested
' define whereby clause
Dim whereBy As String = ""
Select Case rcbSearchType.SelectedValue
Case 2
' resource exists in current project
whereBy += " AND Resource.id IN (" & _
" SELECT DISTINCT TaskResource.resourceId" & _
" FROM TaskResource " & _
" LEFT JOIN Task ON TaskResource.taskId = Task.id " & _
" LEFT JOIN BuildElement ON Task.buildElementId = BuildElement.id " & _
" WHERE BuildElement.projectId = @projectId" & _
")"
Case 3
' all resource used by this user in any of their projects
whereBy += " AND Resource.id IN (" & _
" SELECT DISTINCT TaskResource.resourceId " & _
" FROM TaskResource " & _
" LEFT JOIN Task ON TaskResource.taskId = Task.id " & _
" LEFT JOIN BuildElement ON Task.buildElementId = BuildElement.id " & _
" LEFT JOIN Project ON BuildElement.projectId = Project.id " & _
" WHERE Project.userId = @userId" & _
") "
End Select
Dim txt_array As Array = e.Text.Split(" ")
Dim searchTerms As String = ""
For Each item As String In txt_array
If searchTerms = "" Then
searchTerms += " (resourceName LIKE '%" + item + "%' OR keywords LIKE '%" + item + "%' OR manufacturer LIKE '%" + item + "%')"
Else
searchTerms += " AND (resourceName LIKE '%" + item + "%' OR keywords LIKE '%" + item + "%' OR manufacturer LIKE '%" + item + "%')"
End If
Next
Dim sqlSelectCommand As String = "SELECT TOP 1000 Resource.id, unitId, resourceName, manufacturer, partId FROM Resource " & _
"WHERE " & searchTerms & _
" AND resourceTypeId = " + rblResourceType.SelectedValue + "" & _
whereBy & _
" ORDER BY resourceName"
Try
Dim adapter As New SqlDataAdapter(sqlSelectCommand, System.Configuration.ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
adapter.SelectCommand.Parameters.AddWithValue("@projectId", Request.QueryString("pid"))
adapter.SelectCommand.Parameters.AddWithValue("@userId", Session("userId"))
Dim dataTable As New DataTable()
adapter.Fill(dataTable)
Dim itemOffset As Integer = e.NumberOfItems
Dim endOffset As Integer = Math.Min(itemOffset + ItemsPerRequest, dataTable.Rows.Count)
For i As Integer = itemOffset To endOffset - 1
' check item exists
If Not dataTable.Rows.Item(i) Is Nothing Then
Dim item As New RadComboBoxItem()
item.Text = Server.HtmlDecode(dataTable.Rows.Item(i)("resourceName").ToString)
item.Value = dataTable.Rows.Item(i)("id").ToString
item.Attributes.Add("manufacturer", dataTable.Rows.Item(i)("manufacturer").ToString)
item.Attributes.Add("partId", dataTable.Rows.Item(i)("partId").ToString)
rcbResources.Items.Add(item)
item.DataBind()
End If
Next
If dataTable.Rows.Count <= 0 Then
e.Message = "No resources were found"
Else
Dim maxpage As Integer = Math.Min(itemOffset + ItemsPerRequest, dataTable.Rows.Count)
e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", maxpage, dataTable.Rows.Count)
End If
Catch ex As Exception
Trace.Write(ex.ToString)
End Try
End Sub
Protected Sub Validate_Edit()
Page.Validate("editGroup")
End Sub
Protected Sub fvTaskAdjustments_DataBound(sender As Object, e As System.EventArgs) Handles fvTaskAdjustments.DataBound
Dim taskQty As Object = DirectCast(fvTaskAdjustments.DataItem, DataRowView)("qty")
If taskQty > 0 Then
pRequiresTaskQty.Visible = False
pCurrentResources.Visible = True
Else
pRequiresTaskQty.Visible = True
pCurrentResources.Visible = False
End If
End Sub
Protected Sub fvTaskAdjustments_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs) Handles fvTaskAdjustments.ItemUpdated
fvTaskTotals.DataBind()
rgResources.DataBind()
nextStepInTour()
End Sub
Protected Sub nextStepInTour()
If Session("tourPhase") = 4 Then
Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri)
End If
End Sub
Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
checkPermissions("Project")
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim hlAddResources As HyperLink = CType(fvDefaultResources.FindControl("hlAddResources"), HyperLink)
Dim activeLink As HyperLink = CType(Master.FindControl("hlProjects"), HyperLink)
activeLink.CssClass = "active"
hlBack.NavigateUrl = String.Format(hlBack.NavigateUrl, Request.QueryString("pid"))
hlBack2.NavigateUrl = String.Format(hlBack2.NavigateUrl, Request.QueryString("pid"), Request.QueryString("rid"))
' check for lockstate of the project
isLocked = checkLockState()
If isLocked Then
pAddResources.Visible = False
pAddAdditions.Visible = False
hlAddResources.Visible = False
panelIsLocked.Visible = True
Else
pAddResources.Visible = True
pAddAdditions.Visible = True
hlAddResources.Visible = True
panelIsLocked.Visible = False
End If
End Sub
Protected Function checkLockState() As Boolean
'taskDataSource
Dim returnVal As Boolean
Dim dvSql As DataView = DirectCast(taskDataSource.Select(DataSourceSelectArguments.Empty), DataView)
For Each drvSql As DataRowView In dvSql
returnVal = Convert.ToBoolean(drvSql("isLocked"))
Next
Return returnVal
End Function
Protected Sub setDefaultResources(ByVal sender As Object, ByVal e As System.EventArgs)
' create and execute sql commandresourceId
Dim dbCon As New SqlConnection(ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
dbCon.Open()
Dim cmd As New SqlCommand("setDefaultTaskResources", dbCon)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@userId", Session("userId"))
cmd.Parameters.AddWithValue("@taskId", Request.QueryString("tid"))
' bind to data adapter
Dim adapter As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable
adapter.Fill(dt)
dbCon.Close()
fvDefaultResources.DataBind()
End Sub
Private Sub insertResource(ByVal resourceId As String)
' create and execute sql command
Dim dbCon As New SqlConnection(ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
dbCon.Open()
Dim cmd As New SqlCommand("insertTaskResource", dbCon)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@taskId", Request.QueryString("tid"))
cmd.Parameters.AddWithValue("@projectId", Request.QueryString("pid"))
cmd.Parameters.AddWithValue("@resourceId", resourceId)
cmd.Parameters.AddWithValue("@uses", rntbUses.Value)
cmd.Parameters.AddWithValue("@qty", rntbQty.Value)
cmd.Parameters.AddWithValue("@userId", Session("userId"))
' bind to data adapter
Dim adapter As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable
adapter.Fill(dt)
dbCon.Close()
rgResources.DataBind()
rebindSiblingData()
movetoPhaseSix()
End Sub
Protected Sub btnAddResources_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddResources.Click
' grab the resourceid
Dim resourceid As String = rcbResources.SelectedValue
If IsNumeric(resourceid) Then
' if resourceid exists, insert resource
insertResource(resourceid)
' reset the add resource form
rntbUses.Text = 0
rntbQty.Text = 1
rcbResources.ClearSelection()
rcbResources.Text = ""
End If
End Sub
Protected Sub rebindSiblingData()
fvTaskTotals.DataBind()
fvTaskAdjustments.DataBind()
End Sub
Protected Sub rblResourceType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rblResourceType.SelectedIndexChanged
rcbResources.Text = ""
End Sub
Protected Sub rgResources_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgResources.ItemCommand
If (e.CommandName = "deleteResource") Then
' create and execute sql command
Dim dbCon As New SqlConnection(ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
dbCon.Open()
Dim cmd As New SqlCommand("sp_TaskResource_DELETE", dbCon)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@id", e.CommandArgument)
' bind to data adapter
Dim adapter As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable
adapter.Fill(dt)
dbCon.Close()
rebindSiblingData()
End If
End Sub
Private total As Decimal
Protected Sub rgResources_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgResources.ItemDataBound
Select Case e.Item.ItemType
Case GridItemType.Item, GridItemType.AlternatingItem
' Get the total for each row and get a total to be used later.
Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
' Row total
Dim rowTotal As String = dataItem("cost").Text
If IsNumeric(rowTotal) Then total += rowTotal
' check for a locked stack resource
'Dim isStackLocked As Boolean = dataItem("isStackLocked").Text
'If isStackLocked Or isLocked Then
' dataItem("resourceName").Controls(1).Visible = True
' dataItem("resourceName").Controls(3).Visible = True
' dataItem("resourceName").Controls(5).Visible = False
' 'dataItem("resourceNameLink").Visible = False
' dataItem("DeleteColumn").Visible = False
'Else
' dataItem("resourceName").Controls(1).Visible = False
' dataItem("resourceName").Controls(3).Visible = False
' dataItem("resourceName").Controls(5).Visible = True
' 'dataItem("resourceNameLink").Visible = True
' dataItem("DeleteColumn").Visible = True
'End If
Case GridItemType.Footer
If total > 0 Then
rgResources.MasterTableView.ShowFooter = True
' Calculate the grand total and display this value in the footer
Dim footer As GridFooterItem = CType(e.Item, GridFooterItem)
footer("waste").HorizontalAlign = HorizontalAlign.Right
footer("waste").Controls.Add(New LiteralControl("Total:"))
footer("cost").HorizontalAlign = HorizontalAlign.Right
Dim lbl As Label = New Label
lbl.Text = String.Format("{0:c}", total)
footer("cost").Controls.Add(lbl)
Else
rgResources.MasterTableView.ShowFooter = False
End If
End Select
End Sub
Protected Sub rgResources_ItemUpdated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridUpdatedEventArgs) Handles rgResources.ItemUpdated
rebindSiblingData()
End Sub
Protected Sub rgResources_ItemInserted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridInsertedEventArgs) Handles rgResources.ItemInserted
rebindSiblingData()
End Sub
Protected Sub movetoPhaseSix()
If Session("tourPhase") = 5 Then
Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri)
End If
End Sub
Protected Sub rgResources_ItemDeleted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDeletedEventArgs) Handles rgResources.ItemDeleted
rebindSiblingData()
End Sub
Dim adhoctotal As Decimal
Protected Sub rgAdditions_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgAdditions.ItemDataBound
If TypeOf e.Item Is GridDataItem Then
' Get the total for each row and get a total to be used later.
Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
' Row total
Dim rowTotal As String = dataItem("total").Text
If IsNumeric(rowTotal) Then adhoctotal += rowTotal
ElseIf TypeOf e.Item Is GridFooterItem Then
If adhoctotal > 0 Then
rgAdditions.MasterTableView.ShowFooter = True
' Calculate the grand total and display this value in the footer
Dim footer As GridFooterItem = CType(e.Item, GridFooterItem)
footer("description").HorizontalAlign = HorizontalAlign.Right
footer("description").Controls.Add(New LiteralControl("Total:"))
footer("total").HorizontalAlign = HorizontalAlign.Right
Dim lbl As Label = New Label
lbl.Text = String.Format("{0:c}", adhoctotal)
footer("total").Controls.Add(lbl)
Else
rgAdditions.MasterTableView.ShowFooter = False
End If
End If
End Sub
Protected Sub rgAdditions_ItemDeleted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDeletedEventArgs) Handles rgAdditions.ItemDeleted
rebindSiblingData()
End Sub
Protected Sub rgAdditions_ItemUpdated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridUpdatedEventArgs) Handles rgAdditions.ItemUpdated
rebindSiblingData()
End Sub
Protected Sub rgAdditions_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgAdditions.PreRender
If (rgAdditions.EditItems.Count > 0) Then
For Each item As GridDataItem In rgAdditions.MasterTableView.Items
If (item Is rgAdditions.EditItems(0)) Then
item.Visible = False
End If
Next
End If
' prevent /editdelete of additions
If isLocked Then
rgAdditions.MasterTableView.Columns(0).Visible = False
rgAdditions.MasterTableView.Columns(1).Visible = True
rgAdditions.MasterTableView.Columns(3).Visible = False
Else
rgAdditions.MasterTableView.Columns(0).Visible = True
rgAdditions.MasterTableView.Columns(1).Visible = False
rgAdditions.MasterTableView.Columns(3).Visible = True
End If
End Sub
Protected Sub rgResources_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgResources.PreRender
If (rgResources.EditItems.Count > 0) Then
For Each item As GridDataItem In rgResources.MasterTableView.Items
If (item Is rgResources.EditItems(0)) Then
item.Visible = False
End If
Next
End If
' prevent delete/edit of resources
If isLocked Then
rgResources.MasterTableView.Columns(0).Visible = False
rgResources.MasterTableView.Columns(1).Visible = True
rgResources.MasterTableView.Columns(5).Visible = False
Else
rgResources.MasterTableView.Columns(0).Visible = True
rgResources.MasterTableView.Columns(1).Visible = False
rgResources.MasterTableView.Columns(5).Visible = True
End If
End Sub
Private calctotal As Decimal = 0
Protected Sub rgCalculator_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgCalculator.ItemDataBound
If TypeOf e.Item Is GridDataItem Then
' Get the total for each row and get a total to be used later.
Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
' Row total
Dim rowTotal As String = FormatNumber(dataItem("total").Text, 2)
If IsNumeric(rowTotal) Then
calctotal += rowTotal
End If
ElseIf TypeOf e.Item Is GridFooterItem Then
' Calculate the grand total and display this value in the footer
Dim footer As GridFooterItem = CType(e.Item, GridFooterItem)
footer("multiplier").HorizontalAlign = HorizontalAlign.Right
footer("multiplier").Controls.Add(New LiteralControl("<b>Total:</b><br />"))
footer("multiplier").HorizontalAlign = HorizontalAlign.Right
footer("total").HorizontalAlign = HorizontalAlign.Center
footer("total").Controls.Add(New LiteralControl(calctotal))
qtyTotal.Value = calctotal
End If
End Sub
Protected Sub rgCalculator_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgCalculator.PreRender
' hide the currently editable item - iterate through each row
For Each item As GridDataItem In rgCalculator.Items
' hide the row if it is being edited
If item.Edit Then
item.Visible = False
End If
Next
End Sub
Protected Sub btnUpdateQty_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdateQty.Click
' Find main form quantity container and update the value
Dim rntbQuantity As RadNumericTextBox = CType(fvTaskAdjustments.Row.FindControl("rntbQuantity"), RadNumericTextBox)
rntbQuantity.Value = qtyTotal.Value
End Sub
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
fvAddCalc.Visible = True
btnAdd.Visible = False
End Sub
Protected Sub btnCancel_Click()
fvAddCalc.Visible = False
btnAdd.Visible = True
End Sub
Protected Sub lbClose_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Calculator As Panel = fvTaskAdjustments.FindControl("Calculator")
Calculator.Visible = False
End Sub
Protected Sub fvAddCalc_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles fvAddCalc.ItemInserted
fvAddCalc.Visible = False
btnAdd.Visible = True
rgCalculator.DataBind()
End Sub
Protected Sub rcbSearchType_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles rcbSearchType.SelectedIndexChanged
rcbResources.Text = ""
End Sub
Protected Sub rcbResources_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles rcbResources.SelectedIndexChanged
' get the unit of the current resource
Dim sqlSelectCommand As String = "SELECT unit FROM Resource "
sqlSelectCommand += "LEFT JOIN ResourceUnit ON ResourceUnit.id = unitId WHERE Resource.id = @resourceId"
Dim adapter As New SqlDataAdapter(sqlSelectCommand, System.Configuration.ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
adapter.SelectCommand.Parameters.AddWithValue("@resourceId", e.Value)
Dim dataTable As New DataTable()
adapter.Fill(dataTable)
' check item exists
If dataTable.Rows.Count >= 1 Then
Label14.Text = "Usage (" + dataTable.Rows.Item(0)("unit").ToString + "):"
End If
End Sub
Protected Sub fvAddAdhoc_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles fvAddAdhoc.ItemInserted
fvAddAdhoc.DataBind()
fvTaskTotals.DataBind()
End Sub
Protected Sub additionsDataSource_Inserted(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles additionsDataSource.Inserted
rgAdditions.DataBind()
fvTaskTotals.DataBind()
End Sub
End Class