Windows Form File /FormEditConnections.vb (VB.NET)
1: Option Strict Off
2: Option Explicit On
3: Friend Class FormEditConnections
4: Inherits System.Windows.Forms.Form
5: #Region "Windows Form Designer generated code "
6: Public Sub New()
7: MyBase.New()
8: If m_vb6FormDefInstance Is Nothing Then
9: If m_InitializingDefInstance Then
10: m_vb6FormDefInstance = Me
11: Else
12: Try
13: 'For the start-up form, the first instance created is the default instance.
14: If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
15: m_vb6FormDefInstance = Me
16: End If
17: Catch
18: End Try
19: End If
20: End If
21: 'This call is required by the Windows Form Designer.
22: InitializeComponent()
23: End Sub
24: 'Form overrides dispose to clean up the component list.
25: Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
26: If Disposing Then
27: If Not components Is Nothing Then
28: components.Dispose()
29: End If
30: End If
31: MyBase.Dispose(Disposing)
32: End Sub
33: 'Required by the Windows Form Designer
34: Private components As System.ComponentModel.IContainer
35: Public ToolTip1 As System.Windows.Forms.ToolTip
36: Public WithEvents CommandAddConnection As System.Windows.Forms.Button
37: Public WithEvents CommandEditConnection As System.Windows.Forms.Button
38: Public WithEvents CommandDeleteConnection As System.Windows.Forms.Button
39: Public WithEvents ListConnections As System.Windows.Forms.ListBox
40: Public WithEvents FrameConnections As System.Windows.Forms.GroupBox
41: Public WithEvents CommandOK As System.Windows.Forms.Button
42: Public WithEvents CommandCancel As System.Windows.Forms.Button
43: 'NOTE: The following procedure is required by the Windows Form Designer
44: 'It can be modified using the Windows Form Designer.
45: 'Do not modify it using the code editor.
46: <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
47: Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FormEditConnections))
48: Me.components = New System.ComponentModel.Container()
49: Me.ToolTip1 = New System.Windows.Forms.ToolTip(components)
50: Me.ToolTip1.Active = True
51: Me.FrameConnections = New System.Windows.Forms.GroupBox
52: Me.CommandAddConnection = New System.Windows.Forms.Button
53: Me.CommandEditConnection = New System.Windows.Forms.Button
54: Me.CommandDeleteConnection = New System.Windows.Forms.Button
55: Me.ListConnections = New System.Windows.Forms.ListBox
56: Me.CommandOK = New System.Windows.Forms.Button
57: Me.CommandCancel = New System.Windows.Forms.Button
58: Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
59: Me.Text = "Edit Database Connections"
60: Me.ClientSize = New System.Drawing.Size(312, 165)
61: Me.Location = New System.Drawing.Point(3, 22)
62: Me.Icon = CType(resources.GetObject("FormEditConnections.Icon"), System.Drawing.Icon)
63: Me.MaximizeBox = False
64: Me.MinimizeBox = False
65: Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
66: Me.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
67: Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
68: Me.BackColor = System.Drawing.SystemColors.Control
69: Me.ControlBox = True
70: Me.Enabled = True
71: Me.KeyPreview = False
72: Me.Cursor = System.Windows.Forms.Cursors.Default
73: Me.RightToLeft = System.Windows.Forms.RightToLeft.No
74: Me.ShowInTaskbar = True
75: Me.HelpButton = False
76: Me.WindowState = System.Windows.Forms.FormWindowState.Normal
77: Me.Name = "FormEditConnections"
78: Me.FrameConnections.Text = "Database Connections"
79: Me.FrameConnections.Size = New System.Drawing.Size(297, 121)
80: Me.FrameConnections.Location = New System.Drawing.Point(8, 8)
81: Me.FrameConnections.TabIndex = 2
82: Me.FrameConnections.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
83: Me.FrameConnections.BackColor = System.Drawing.SystemColors.Control
84: Me.FrameConnections.Enabled = True
85: Me.FrameConnections.ForeColor = System.Drawing.SystemColors.ControlText
86: Me.FrameConnections.RightToLeft = System.Windows.Forms.RightToLeft.No
87: Me.FrameConnections.Visible = True
88: Me.FrameConnections.Name = "FrameConnections"
89: Me.CommandAddConnection.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
90: Me.CommandAddConnection.Text = "Add New"
91: Me.CommandAddConnection.Size = New System.Drawing.Size(73, 25)
92: Me.CommandAddConnection.Location = New System.Drawing.Point(216, 16)
93: Me.CommandAddConnection.TabIndex = 6
94: Me.ToolTip1.SetToolTip(Me.CommandAddConnection, "Add a new database connection")
95: Me.CommandAddConnection.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
96: Me.CommandAddConnection.BackColor = System.Drawing.SystemColors.Control
97: Me.CommandAddConnection.CausesValidation = True
98: Me.CommandAddConnection.Enabled = True
99: Me.CommandAddConnection.ForeColor = System.Drawing.SystemColors.ControlText
100: Me.CommandAddConnection.Cursor = System.Windows.Forms.Cursors.Default
101: Me.CommandAddConnection.RightToLeft = System.Windows.Forms.RightToLeft.No
102: Me.CommandAddConnection.TabStop = True
103: Me.CommandAddConnection.Name = "CommandAddConnection"
104: Me.CommandEditConnection.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
105: Me.CommandEditConnection.Text = "Edit"
106: Me.CommandEditConnection.Size = New System.Drawing.Size(73, 25)
107: Me.CommandEditConnection.Location = New System.Drawing.Point(216, 48)
108: Me.CommandEditConnection.TabIndex = 5
109: Me.ToolTip1.SetToolTip(Me.CommandEditConnection, "Edit the selected database connection")
110: Me.CommandEditConnection.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
111: Me.CommandEditConnection.BackColor = System.Drawing.SystemColors.Control
112: Me.CommandEditConnection.CausesValidation = True
113: Me.CommandEditConnection.Enabled = True
114: Me.CommandEditConnection.ForeColor = System.Drawing.SystemColors.ControlText
115: Me.CommandEditConnection.Cursor = System.Windows.Forms.Cursors.Default
116: Me.CommandEditConnection.RightToLeft = System.Windows.Forms.RightToLeft.No
117: Me.CommandEditConnection.TabStop = True
118: Me.CommandEditConnection.Name = "CommandEditConnection"
119: Me.CommandDeleteConnection.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
120: Me.CommandDeleteConnection.Text = "Delete"
121: Me.CommandDeleteConnection.Size = New System.Drawing.Size(73, 25)
122: Me.CommandDeleteConnection.Location = New System.Drawing.Point(216, 80)
123: Me.CommandDeleteConnection.TabIndex = 4
124: Me.ToolTip1.SetToolTip(Me.CommandDeleteConnection, "Delete the selected database connection")
125: Me.CommandDeleteConnection.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
126: Me.CommandDeleteConnection.BackColor = System.Drawing.SystemColors.Control
127: Me.CommandDeleteConnection.CausesValidation = True
128: Me.CommandDeleteConnection.Enabled = True
129: Me.CommandDeleteConnection.ForeColor = System.Drawing.SystemColors.ControlText
130: Me.CommandDeleteConnection.Cursor = System.Windows.Forms.Cursors.Default
131: Me.CommandDeleteConnection.RightToLeft = System.Windows.Forms.RightToLeft.No
132: Me.CommandDeleteConnection.TabStop = True
133: Me.CommandDeleteConnection.Name = "CommandDeleteConnection"
134: Me.ListConnections.Size = New System.Drawing.Size(201, 98)
135: Me.ListConnections.Location = New System.Drawing.Point(8, 16)
136: Me.ListConnections.TabIndex = 3
137: Me.ToolTip1.SetToolTip(Me.ListConnections, "Shows the available database connections")
138: Me.ListConnections.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
139: Me.ListConnections.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
140: Me.ListConnections.BackColor = System.Drawing.SystemColors.Window
141: Me.ListConnections.CausesValidation = True
142: Me.ListConnections.Enabled = True
143: Me.ListConnections.ForeColor = System.Drawing.SystemColors.WindowText
144: Me.ListConnections.IntegralHeight = True
145: Me.ListConnections.Cursor = System.Windows.Forms.Cursors.Default
146: Me.ListConnections.SelectionMode = System.Windows.Forms.SelectionMode.One
147: Me.ListConnections.RightToLeft = System.Windows.Forms.RightToLeft.No
148: Me.ListConnections.Sorted = False
149: Me.ListConnections.TabStop = True
150: Me.ListConnections.Visible = True
151: Me.ListConnections.MultiColumn = False
152: Me.ListConnections.Name = "ListConnections"
153: Me.CommandOK.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
154: Me.CommandOK.Text = "OK"
155: Me.CommandOK.Size = New System.Drawing.Size(73, 25)
156: Me.CommandOK.Location = New System.Drawing.Point(152, 136)
157: Me.CommandOK.TabIndex = 1
158: Me.ToolTip1.SetToolTip(Me.CommandOK, "Save changes")
159: Me.CommandOK.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
160: Me.CommandOK.BackColor = System.Drawing.SystemColors.Control
161: Me.CommandOK.CausesValidation = True
162: Me.CommandOK.Enabled = True
163: Me.CommandOK.ForeColor = System.Drawing.SystemColors.ControlText
164: Me.CommandOK.Cursor = System.Windows.Forms.Cursors.Default
165: Me.CommandOK.RightToLeft = System.Windows.Forms.RightToLeft.No
166: Me.CommandOK.TabStop = True
167: Me.CommandOK.Name = "CommandOK"
168: Me.CommandCancel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
169: Me.CancelButton = Me.CommandCancel
170: Me.CommandCancel.Text = "Cancel"
171: Me.CommandCancel.Size = New System.Drawing.Size(73, 25)
172: Me.CommandCancel.Location = New System.Drawing.Point(232, 136)
173: Me.CommandCancel.TabIndex = 0
174: Me.ToolTip1.SetToolTip(Me.CommandCancel, "Cancel the changes")
175: Me.CommandCancel.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
176: Me.CommandCancel.BackColor = System.Drawing.SystemColors.Control
177: Me.CommandCancel.CausesValidation = True
178: Me.CommandCancel.Enabled = True
179: Me.CommandCancel.ForeColor = System.Drawing.SystemColors.ControlText
180: Me.CommandCancel.Cursor = System.Windows.Forms.Cursors.Default
181: Me.CommandCancel.RightToLeft = System.Windows.Forms.RightToLeft.No
182: Me.CommandCancel.TabStop = True
183: Me.CommandCancel.Name = "CommandCancel"
184: Me.Controls.Add(FrameConnections)
185: Me.Controls.Add(CommandOK)
186: Me.Controls.Add(CommandCancel)
187: Me.FrameConnections.Controls.Add(CommandAddConnection)
188: Me.FrameConnections.Controls.Add(CommandEditConnection)
189: Me.FrameConnections.Controls.Add(CommandDeleteConnection)
190: Me.FrameConnections.Controls.Add(ListConnections)
191: End Sub
192: #End Region
193: #Region "Upgrade Support "
194: Private Shared m_vb6FormDefInstance As FormEditConnections
195: Private Shared m_InitializingDefInstance As Boolean
196: Public Shared Property DefInstance() As FormEditConnections
197: Get
198: If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
199: m_InitializingDefInstance = True
200: m_vb6FormDefInstance = New FormEditConnections()
201: m_InitializingDefInstance = False
202: End If
203: DefInstance = m_vb6FormDefInstance
204: End Get
205: Set
206: m_vb6FormDefInstance = Value
207: End Set
208: End Property
209: #End Region
210: Private Sub CommandAddConnection_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandAddConnection.Click
211: CurrentAction = "ADD CONNECTION"
212: 'UPGRADE_ISSUE: Load statement is not supported. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1039"'
213: Load(FormConnection)
214: FormConnection.DefInstance.Visible = True
215: End Sub
216:
217: Private Sub CommandCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandCancel.Click
218: FormEditConnections.DefInstance.Close()
219: FormEditConnections.DefInstance.Visible = False
220: FormMain.DefInstance.Enabled = True
221: End Sub
222:
223: Public Sub UpdateFormSettings()
224:
225: Dim DataStore As New DataStoreClass
226: Dim SQL As String
227: Dim i As Integer
228:
229: ListConnections.Items.Clear()
230: DataStore.SetConnectionString((ApplicationDataStoreConnectionString))
231: ConnectionsDictionary.RemoveAll()
232:
233:
234: 'Dim ProjectsRecordSet As ADODB.Recordset
235: SQL = "SELECT * FROM t_Connections ORDER BY DatabaseServer"
236:
237: 'Set ProjectsRecordSet = DataStore.GetRecordSet(SQL)
238: Dim ConnectionsRecordSet As ADOR.Recordset
239:
240: ConnectionsRecordSet = DataStore.GetRecordSet(SQL)
241: 'ProjectsRecordSet.Open
242: i = 0
243:
244: System.Diagnostics.Debug.WriteLine(ConnectionsRecordSet.State)
245:
246:
247: If ConnectionsRecordSet.EOF = True Then
248:
249: CommandEditConnection.Enabled = False
250: CommandDeleteConnection.Enabled = False
251:
252: Else
253:
254: Do While Not ConnectionsRecordSet.EOF
255:
256: ListConnections.Items.Add(ConnectionsRecordSet.Fields("DatabaseServer").Value)
257: ConnectionsDictionary.Add(i, ConnectionsRecordSet.Fields("ConnectionID").Value)
258: i = i + 1
259: ConnectionsRecordSet.MoveNext()
260:
261: Loop
262:
263: End If
264:
265: End Sub
266:
267: Private Sub CommandDeleteConnection_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandDeleteConnection.Click
268: Dim Result As Object
269: 'Delete this connection from the datastore
270:
271: Dim DataStore As New DataStoreClass
272: DataStore.SetConnectionString((ApplicationDataStoreConnectionString))
273: Dim ConnectionsRecordSet As ADOR.Recordset
274: Dim ProjectsRecordSet As ADOR.Recordset
275: Dim SQLResult As Boolean
276: Dim SQL As String
277: Dim ConnectionInUse As Boolean
278: Dim ConnectionUsage As String
279: Dim ConnectionUsageDatabaseName As String
280: Dim ConnectionUsageProjectName As String
281:
282: Dim SelectedConnectionKey As Integer
283: Dim SelectedConnectionID As Integer
284: SelectedConnectionKey = ListConnections.SelectedIndex
285: 'UPGRADE_WARNING: Couldn't resolve default property of object ConnectionsDictionary(). Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
286: SelectedConnectionID = ConnectionsDictionary(SelectedConnectionKey)
287: ConnectionInUse = False
288: ConnectionUsage = "This connection cannot be deleted because it is in use by these project connections: " & vbCrLf & vbCrLf
289:
290: 'Check that this connection is not being used by a project
291: SQL = "SELECT t_Databases.DatabaseName, "
292: SQL = SQL & "t_Projects.ProjectName "
293: SQL = SQL & "FROM t_Databases "
294: SQL = SQL & "INNER JOIN t_Projects ON t_Databases.fk_ProjectID = t_Projects.ProjectID "
295: SQL = SQL & "WHERE t_Databases.fk_ConnectionID = " & SelectedConnectionID
296: SQL = SQL & ""
297:
298: ProjectsRecordSet = DataStore.GetRecordSet(SQL)
299:
300: Do While Not ProjectsRecordSet.EOF
301:
302: ConnectionInUse = True
303: ConnectionUsageDatabaseName = ProjectsRecordSet.Fields("DatabaseName").Value
304: ConnectionUsageProjectName = ProjectsRecordSet.Fields("ProjectName").Value
305:
306: ConnectionUsage = ConnectionUsage & " Database '" & ConnectionUsageDatabaseName & "' in project "
307: ConnectionUsage = ConnectionUsage & "'" & ConnectionUsageProjectName & "'" & vbCrLf
308:
309: ProjectsRecordSet.MoveNext()
310: Loop
311:
312: ConnectionUsage = ConnectionUsage & vbCrLf & "You will need to delete these projects before the connection can be deleted."
313:
314: 'If the connection is being used then prevent it from being deleted
315: If ConnectionInUse Then
316: 'UPGRADE_WARNING: Couldn't resolve default property of object Result. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
317: Result = MsgBox(ConnectionUsage, MsgBoxStyle.Critical, ApplicationName)
318: If Result = MsgBoxResult.OK Then Exit Sub
319:
320: End If
321:
322:
323: 'Confirm the deletion
324: 'UPGRADE_WARNING: Couldn't resolve default property of object Result. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
325: Result = MsgBox("Are you sure you want to remove this database connection?", MsgBoxStyle.OKCancel, ApplicationName)
326: If Result = MsgBoxResult.Cancel Then Exit Sub
327:
328:
329: SQL = "DELETE FROM t_Connections WHERE ConnectionID = " & SelectedConnectionID
330:
331: SQLResult = DataStore.ExecuteSQL(SQL)
332:
333: Call UpdateFormSettings()
334:
335:
336: End Sub
337:
338: Private Sub CommandEditConnection_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandEditConnection.Click
339: CurrentAction = "EDIT CONNECTION"
340: 'UPGRADE_ISSUE: Load statement is not supported. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1039"'
341: Load(FormConnection)
342: FormConnection.DefInstance.Visible = True
343: End Sub
344:
345: Private Sub CommandOK_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandOK.Click
346: FormEditConnections.DefInstance.Visible = False
347: FormEditConnections.DefInstance.Close()
348: FormMain.DefInstance.Enabled = True
349:
350: End Sub
351:
352: Private Sub FormEditConnections_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
353: Call UpdateFormSettings()
354: FormMain.DefInstance.Enabled = False
355: End Sub
356: End Class