-
Notifications
You must be signed in to change notification settings - Fork 2
/
Default.aspx.vb
118 lines (101 loc) · 4.23 KB
/
Default.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
Imports DevExpress.Web
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace E2636
Partial Public Class [Default]
Inherits System.Web.UI.Page
Private fieldNames() As String = { "CategoryID", "CategoryName", "Description" }
Private rowValues As List(Of Object) = Nothing
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub TargetGrid_CustomCallback(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewCustomCallbackEventArgs)
rowValues = New List(Of Object)()
Select Case e.Parameters
Case "addSelectedRows"
rowValues = SourceGrid.GetSelectedFieldValues(fieldNames)
Dim categoryIDs = New StringBuilder()
For i As Integer = 0 To rowValues.Count() - 1
Dim categoryID = (TryCast(rowValues(i), Object()))(0)
If i < rowValues.Count() - 1 Then
categoryIDs.AppendFormat("{0}, ", categoryID)
Else
categoryIDs.Append(categoryID)
End If
Next i
If categoryIDs.Length > 0 Then
SourceDS.DeleteCommand = String.Format("DELETE FROM [Categories] WHERE [CategoryID] IN ({0})", categoryIDs)
SourceDS.Delete()
For Each rowValue As Object() In rowValues
TargetDS.InsertCommand = String.Format("INSERT INTO [CategoriesUpdated] ([CategoryID], [CategoryName], [Description]) VALUES ({0}, '{1}', '{2}')", rowValue(0), rowValue(1), rowValue(2))
TargetDS.Insert()
Next rowValue
TargetGrid.DataBind()
End If
Case "addAllRows"
For i As Integer = 0 To SourceGrid.VisibleRowCount - 1
rowValues.Add(SourceGrid.GetRowValues(i, fieldNames))
Next i
If rowValues.Count > 0 Then
SourceDS.DeleteCommand = "DELETE * FROM [Categories]"
SourceDS.Delete()
For Each rowValue As Object() In rowValues
TargetDS.InsertCommand = String.Format("INSERT INTO [CategoriesUpdated] ([CategoryID], [CategoryName], [Description]) VALUES ({0}, '{1}', '{2}')", rowValue(0), rowValue(1), rowValue(2))
TargetDS.Insert()
Next rowValue
TargetGrid.DataBind()
End If
End Select
End Sub
Protected Sub SourceGrid_CustomCallback(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewCustomCallbackEventArgs)
rowValues = New List(Of Object)()
Select Case e.Parameters
Case "removeSelectedRows"
rowValues = TargetGrid.GetSelectedFieldValues(fieldNames)
Dim categoryIDs = New StringBuilder()
For i As Integer = 0 To rowValues.Count() - 1
Dim categoryID = (TryCast(rowValues(i), Object()))(0)
If i < rowValues.Count() - 1 Then
categoryIDs.AppendFormat("{0}, ", categoryID)
Else
categoryIDs.Append(categoryID)
End If
Next i
If categoryIDs.Length > 0 Then
TargetDS.DeleteCommand = String.Format("DELETE FROM [CategoriesUpdated] WHERE [CategoryID] IN ({0})", categoryIDs)
TargetDS.Delete()
For Each rowValue As Object() In rowValues
SourceDS.InsertCommand = String.Format("INSERT INTO [Categories] ([CategoryID], [CategoryName], [Description]) VALUES ({0}, '{1}', '{2}')", rowValue(0), rowValue(1), rowValue(2))
SourceDS.Insert()
Next rowValue
SourceGrid.DataBind()
End If
Case "removeAllRows"
For i As Integer = 0 To TargetGrid.VisibleRowCount - 1
rowValues.Add(TargetGrid.GetRowValues(i, fieldNames))
Next i
If rowValues.Count > 0 Then
TargetDS.DeleteCommand = "DELETE * FROM [CategoriesUpdated]"
TargetDS.Delete()
For Each rowValue As Object() In rowValues
SourceDS.InsertCommand = String.Format("INSERT INTO [Categories] ([CategoryID], [CategoryName], [Description]) VALUES ({0}, '{1}', '{2}')", rowValue(0), rowValue(1), rowValue(2))
SourceDS.Insert()
Next rowValue
SourceGrid.DataBind()
End If
End Select
End Sub
Protected Sub btnRestore_Click(ByVal sender As Object, ByVal e As EventArgs)
File.Copy(Server.MapPath("~/App_Data/nwindNew_backup.mdb"), Server.MapPath("~/App_Data/nwindNew.mdb"), True)
SourceGrid.DataBind()
SourceGrid.Selection.UnselectAll()
TargetGrid.DataBind()
TargetGrid.Selection.UnselectAll()
End Sub
End Class
End Namespace