Windows Form File /FormEditDatabase.vb (VB.NET)
1: Option Strict Off  
2: Option Explicit On  
3: Friend Class FormEditDatabase  
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 CommandEditProject As System.Windows.Forms.Button  
37:     Public WithEvents CommandCancel As System.Windows.Forms.Button  
38:     Public WithEvents ComboConnection As System.Windows.Forms.ComboBox  
39:     Public WithEvents TextDatabaseName As System.Windows.Forms.TextBox  
40:     Public WithEvents LabelConnection As System.Windows.Forms.Label  
41:     Public WithEvents LabelDatabaseName As System.Windows.Forms.Label  
42:     Public WithEvents FrameEditDatabase As System.Windows.Forms.GroupBox  
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(FormEditDatabase))  
48:         Me.components = New System.ComponentModel.Container()  
49:         Me.ToolTip1 = New System.Windows.Forms.ToolTip(components)  
50:         Me.ToolTip1.Active = True  
51:         Me.CommandEditProject = New System.Windows.Forms.Button  
52:         Me.CommandCancel = New System.Windows.Forms.Button  
53:         Me.FrameEditDatabase = New System.Windows.Forms.GroupBox  
54:         Me.ComboConnection = New System.Windows.Forms.ComboBox  
55:         Me.TextDatabaseName = New System.Windows.Forms.TextBox  
56:         Me.LabelConnection = New System.Windows.Forms.Label  
57:         Me.LabelDatabaseName = New System.Windows.Forms.Label  
58:         Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle  
59:         Me.Text = "Edit Database"  
60:         Me.ClientSize = New System.Drawing.Size(367, 134)  
61:         Me.Location = New System.Drawing.Point(3, 22)  
62:         Me.Icon = CType(resources.GetObject("FormEditDatabase.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 = "FormEditDatabase"  
78:         Me.CommandEditProject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter  
79:         Me.CommandEditProject.Text = "Update"  
80:         Me.CommandEditProject.Size = New System.Drawing.Size(73, 25)  
81:         Me.CommandEditProject.Location = New System.Drawing.Point(208, 104)  
82:         Me.CommandEditProject.TabIndex = 6  
83:         Me.ToolTip1.SetToolTip(Me.CommandEditProject, "Update the database settings")  
84:         Me.CommandEditProject.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))  
85:         Me.CommandEditProject.BackColor = System.Drawing.SystemColors.Control  
86:         Me.CommandEditProject.CausesValidation = True  
87:         Me.CommandEditProject.Enabled = True  
88:         Me.CommandEditProject.ForeColor = System.Drawing.SystemColors.ControlText  
89:         Me.CommandEditProject.Cursor = System.Windows.Forms.Cursors.Default  
90:         Me.CommandEditProject.RightToLeft = System.Windows.Forms.RightToLeft.No  
91:         Me.CommandEditProject.TabStop = True  
92:         Me.CommandEditProject.Name = "CommandEditProject"  
93:         Me.CommandCancel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter  
94:         Me.CancelButton = Me.CommandCancel  
95:         Me.CommandCancel.Text = "Cancel"  
96:         Me.CommandCancel.Size = New System.Drawing.Size(73, 25)  
97:         Me.CommandCancel.Location = New System.Drawing.Point(288, 104)  
98:         Me.CommandCancel.TabIndex = 5  
99:         Me.ToolTip1.SetToolTip(Me.CommandCancel, "Cancel the changes")  
100:         Me.CommandCancel.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))  
101:         Me.CommandCancel.BackColor = System.Drawing.SystemColors.Control  
102:         Me.CommandCancel.CausesValidation = True  
103:         Me.CommandCancel.Enabled = True  
104:         Me.CommandCancel.ForeColor = System.Drawing.SystemColors.ControlText  
105:         Me.CommandCancel.Cursor = System.Windows.Forms.Cursors.Default  
106:         Me.CommandCancel.RightToLeft = System.Windows.Forms.RightToLeft.No  
107:         Me.CommandCancel.TabStop = True  
108:         Me.CommandCancel.Name = "CommandCancel"  
109:         Me.FrameEditDatabase.Text = "Database Details"  
110:         Me.FrameEditDatabase.Size = New System.Drawing.Size(353, 89)  
111:         Me.FrameEditDatabase.Location = New System.Drawing.Point(8, 8)  
112:         Me.FrameEditDatabase.TabIndex = 0  
113:         Me.FrameEditDatabase.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))  
114:         Me.FrameEditDatabase.BackColor = System.Drawing.SystemColors.Control  
115:         Me.FrameEditDatabase.Enabled = True  
116:         Me.FrameEditDatabase.ForeColor = System.Drawing.SystemColors.ControlText  
117:         Me.FrameEditDatabase.RightToLeft = System.Windows.Forms.RightToLeft.No  
118:         Me.FrameEditDatabase.Visible = True  
119:         Me.FrameEditDatabase.Name = "FrameEditDatabase"  
120:         Me.ComboConnection.Size = New System.Drawing.Size(225, 21)  
121:         Me.ComboConnection.Location = New System.Drawing.Point(120, 56)  
122:         Me.ComboConnection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList  
123:         Me.ComboConnection.TabIndex = 4  
124:         Me.ToolTip1.SetToolTip(Me.ComboConnection, "Select the database connection associated with this database")  
125:         Me.ComboConnection.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))  
126:         Me.ComboConnection.BackColor = System.Drawing.SystemColors.Window  
127:         Me.ComboConnection.CausesValidation = True  
128:         Me.ComboConnection.Enabled = True  
129:         Me.ComboConnection.ForeColor = System.Drawing.SystemColors.WindowText  
130:         Me.ComboConnection.IntegralHeight = True  
131:         Me.ComboConnection.Cursor = System.Windows.Forms.Cursors.Default  
132:         Me.ComboConnection.RightToLeft = System.Windows.Forms.RightToLeft.No  
133:         Me.ComboConnection.Sorted = False  
134:         Me.ComboConnection.TabStop = True  
135:         Me.ComboConnection.Visible = True  
136:         Me.ComboConnection.Name = "ComboConnection"  
137:         Me.TextDatabaseName.AutoSize = False  
138:         Me.TextDatabaseName.Size = New System.Drawing.Size(225, 25)  
139:         Me.TextDatabaseName.Location = New System.Drawing.Point(120, 24)  
140:         Me.TextDatabaseName.TabIndex = 1  
141:         Me.ToolTip1.SetToolTip(Me.TextDatabaseName, "The name of the database")  
142:         Me.TextDatabaseName.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))  
143:         Me.TextDatabaseName.AcceptsReturn = True  
144:         Me.TextDatabaseName.TextAlign = System.Windows.Forms.HorizontalAlignment.Left  
145:         Me.TextDatabaseName.BackColor = System.Drawing.SystemColors.Window  
146:         Me.TextDatabaseName.CausesValidation = True  
147:         Me.TextDatabaseName.Enabled = True  
148:         Me.TextDatabaseName.ForeColor = System.Drawing.SystemColors.WindowText  
149:         Me.TextDatabaseName.HideSelection = True  
150:         Me.TextDatabaseName.ReadOnly = False  
151:         Me.TextDatabaseName.Maxlength = 0  
152:         Me.TextDatabaseName.Cursor = System.Windows.Forms.Cursors.IBeam  
153:         Me.TextDatabaseName.MultiLine = False  
154:         Me.TextDatabaseName.RightToLeft = System.Windows.Forms.RightToLeft.No  
155:         Me.TextDatabaseName.ScrollBars = System.Windows.Forms.ScrollBars.None  
156:         Me.TextDatabaseName.TabStop = True  
157:         Me.TextDatabaseName.Visible = True  
158:         Me.TextDatabaseName.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D  
159:         Me.TextDatabaseName.Name = "TextDatabaseName"  
160:         Me.LabelConnection.Text = "Database Connection:"  
161:         Me.LabelConnection.Size = New System.Drawing.Size(113, 25)  
162:         Me.LabelConnection.Location = New System.Drawing.Point(8, 56)  
163:         Me.LabelConnection.TabIndex = 3  
164:         Me.LabelConnection.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))  
165:         Me.LabelConnection.TextAlign = System.Drawing.ContentAlignment.TopLeft  
166:         Me.LabelConnection.BackColor = System.Drawing.SystemColors.Control  
167:         Me.LabelConnection.Enabled = True  
168:         Me.LabelConnection.ForeColor = System.Drawing.SystemColors.ControlText  
169:         Me.LabelConnection.Cursor = System.Windows.Forms.Cursors.Default  
170:         Me.LabelConnection.RightToLeft = System.Windows.Forms.RightToLeft.No  
171:         Me.LabelConnection.UseMnemonic = True  
172:         Me.LabelConnection.Visible = True  
173:         Me.LabelConnection.AutoSize = False  
174:         Me.LabelConnection.BorderStyle = System.Windows.Forms.BorderStyle.None  
175:         Me.LabelConnection.Name = "LabelConnection"  
176:         Me.LabelDatabaseName.Text = "Database Name:"  
177:         Me.LabelDatabaseName.Size = New System.Drawing.Size(89, 17)  
178:         Me.LabelDatabaseName.Location = New System.Drawing.Point(8, 28)  
179:         Me.LabelDatabaseName.TabIndex = 2  
180:         Me.LabelDatabaseName.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))  
181:         Me.LabelDatabaseName.TextAlign = System.Drawing.ContentAlignment.TopLeft  
182:         Me.LabelDatabaseName.BackColor = System.Drawing.SystemColors.Control  
183:         Me.LabelDatabaseName.Enabled = True  
184:         Me.LabelDatabaseName.ForeColor = System.Drawing.SystemColors.ControlText  
185:         Me.LabelDatabaseName.Cursor = System.Windows.Forms.Cursors.Default  
186:         Me.LabelDatabaseName.RightToLeft = System.Windows.Forms.RightToLeft.No  
187:         Me.LabelDatabaseName.UseMnemonic = True  
188:         Me.LabelDatabaseName.Visible = True  
189:         Me.LabelDatabaseName.AutoSize = False  
190:         Me.LabelDatabaseName.BorderStyle = System.Windows.Forms.BorderStyle.None  
191:         Me.LabelDatabaseName.Name = "LabelDatabaseName"  
192:         Me.Controls.Add(CommandEditProject)  
193:         Me.Controls.Add(CommandCancel)  
194:         Me.Controls.Add(FrameEditDatabase)  
195:         Me.FrameEditDatabase.Controls.Add(ComboConnection)  
196:         Me.FrameEditDatabase.Controls.Add(TextDatabaseName)  
197:         Me.FrameEditDatabase.Controls.Add(LabelConnection)  
198:         Me.FrameEditDatabase.Controls.Add(LabelDatabaseName)  
199:     End Sub  
200: #End Region  
201: #Region "Upgrade Support "  
202:     Private Shared m_vb6FormDefInstance As FormEditDatabase  
203:     Private Shared m_InitializingDefInstance As Boolean  
204:     Public Shared Property DefInstance() As FormEditDatabase  
205:         Get  
206:             If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then  
207:                 m_InitializingDefInstance = True  
208:                 m_vb6FormDefInstance = New FormEditDatabase()  
209:                 m_InitializingDefInstance = False  
210:             End If  
211:             DefInstance = m_vb6FormDefInstance  
212:         End Get  
213:         Set  
214:             m_vb6FormDefInstance = Value  
215:         End Set  
216:     End Property  
217: #End Region  
218:     Private SelectedDatabaseID As Integer  
219:     Private SelectedDatabaseKey As Integer  
220:     Private SelectedDatabaseName As String  
221:     Private SelectedConnectionID As Integer  
222:     Private SelectedConnectionKey As Integer  
223:     Private SelectedConnectionName As String  
224:       
225:     Private Sub CommandCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandCancel.Click  
226:         FormEditDatabase.DefInstance.Visible = False  
227:         FormEditDatabase.DefInstance.Close()  
228:           
229:     End Sub  
230:       
231:     Private Sub CommandEditProject_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandEditProject.Click  
232:           
233:         Dim DataStore As New DataStoreClass  
234:         DataStore.SetConnectionString((ApplicationDataStoreConnectionString))  
235:           
236:         Dim SQL As String  
237:         Dim SQLResult As Boolean  
238:         SelectedDatabaseName = TextDatabaseName.Text  
239:         SelectedDatabaseName = Replace(SelectedDatabaseName, "'", "''")  
240:           
241:         'UPGRADE_WARNING: Couldn't resolve default property of object ConnectionsDictionary(). Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'  
242:         SelectedConnectionID = ConnectionsDictionary(ComboConnection.SelectedIndex)  
243:           
244:         'Editing an existing database  
245:         If CurrentAction = "EDIT DATABASE" Then  
246:             SQL = "UPDATE t_Databases "  
247:             SQL = SQL & "SET "  
248:             SQL = SQL & "DatabaseName = '" & SelectedDatabaseName & "', "
249:             SQL = SQL & "fk_ConnectionID = '" & SelectedConnectionID & "' "
250:             SQL = SQL & "WHERE DatabaseID = " & SelectedDatabaseID  
251:               
252:             SQLResult = DataStore.ExecuteSQL(SQL)  
253:         End If  
254:           
255:         'Adding a new database  
256:         If CurrentAction = "ADD DATABASE" Then  
257:             SQL = "INSERT INTO t_Databases "  
258:             SQL = SQL & "( "  
259:             SQL = SQL & "DatabaseName, "  
260:             SQL = SQL & "fk_ProjectID, "  
261:             SQL = SQL & "fk_ConnectionID "  
262:             SQL = SQL & ") "  
263:             SQL = SQL & "VALUES "  
264:             SQL = SQL & "( "  
265:             SQL = SQL & "'" & SelectedDatabaseName & "', "  
266:             SQL = SQL & CurrentProjectID & ", "  
267:             SQL = SQL & SelectedConnectionID  
268:             SQL = SQL & ") "  
269:               
270:             SQLResult = DataStore.ExecuteSQL(SQL)  
271:         End If  
272:           
273:         FormEditProject.DefInstance.CommandEditProject.Enabled = True  
274:         Call FormEditProject.DefInstance.UpdateFormSettings()  
275:         Me.Visible = False  
276:         FormEditDatabase.DefInstance.Close()  
277:           
278:           
279:     End Sub  
280:       
281:     Private Sub FormEditDatabase_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load  
282:         Dim Key As Object  
283:           
284:           
285:         'Action specifics  
286:         If CurrentAction = "EDIT DATABASE" Then  
287:             CommandEditProject.Text = "Update"  
288:         End If  
289:           
290:         If CurrentAction = "ADD DATABASE" Then  
291:             CommandEditProject.Text = "Add"  
292:         End If  
293:         '  
294:           
295:           
296:         Dim DataStore As New DataStoreClass  
297:         Dim SQL As String  
298:         'Dim SelectedDatabaseID As Long  
299:         'Dim SelectedDatabaseKey As Long  
300:         'Dim SelectedDatabaseName As String  
301:         ConnectionsDictionary.RemoveAll()  
302:         ComboConnection.Items.Clear()  
303:           
304:         DataStore.SetConnectionString((ApplicationDataStoreConnectionString))  
305:         Dim ConnectionsRecordSet As ADOR.Recordset  
306:           
307:         'Dim ProjectsRecordSet As ADODB.Recordset  
308:         SQL = "SELECT ConnectionID, DatabaseServer FROM t_Connections ORDER BY DatabaseServer"  
309:           
310:         Dim i As Integer  
311:           
312:         i = 0  
313:           
314:         ConnectionsRecordSet = DataStore.GetRecordSet(SQL)  
315:         'ProjectsRecordSet.Open  
316:         Do While Not ConnectionsRecordSet.EOF  
317:               
318:             ComboConnection.Items.Add(ConnectionsRecordSet.Fields("DatabaseServer").Value)  
319:             ConnectionsDictionary.Add(i, ConnectionsRecordSet.Fields("ConnectionID").Value)  
320:             i = i + 1  
321:             ConnectionsRecordSet.MoveNext()  
322:               
323:         Loop  
324:           
325:         'Set ProjectsRecordSet = DataStore.GetRecordSet(SQL)  
326:           
327:           
328:         'Database is being edited  
329:         If CurrentAction = "EDIT DATABASE" Then  
330:               
331:             SelectedDatabaseKey = FormEditProject.DefInstance.ListDatabases.SelectedIndex  
332:             'UPGRADE_WARNING: Couldn't resolve default property of object DatabasesDictionary(). Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'  
333:             SelectedDatabaseID = DatabasesDictionary(SelectedDatabaseKey)  
334:               
335:             'Get database name  
336:             SQL = "SELECT DatabaseName FROM t_Databases WHERE DatabaseID = " & SelectedDatabaseID  
337:             SelectedDatabaseName = DataStore.ExecuteSQLReturnSingleValue(SQL, "DatabaseName")  
338:             TextDatabaseName.Text = SelectedDatabaseName  
339:               
340:             'Get connection  
341:             SQL = "SELECT fk_ConnectionID FROM t_Databases WHERE DatabaseID = " & SelectedDatabaseID  
342:             SelectedConnectionID = CInt(DataStore.ExecuteSQLReturnSingleValue(SQL, "fk_ConnectionID"))  
343:             'SelectedConnectionKey = ConnectionsDictionary(SelectedConnectionID)  
344:               
345:             'Find key associated with connection  
346:             For    Each Key In ConnectionsDictionary.Keys  
347:                   
348:                 'UPGRADE_WARNING: Couldn't resolve default property of object ConnectionsDictionary(Key). Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'  
349:                 If ConnectionsDictionary(Key) = SelectedConnectionID Then  
350:                     'UPGRADE_WARNING: Couldn't resolve default property of object Key. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'  
351:                     SelectedConnectionKey = Key  
352:                 End If  
353:                   
354:             Next Key  
355:               
356:             ComboConnection.SelectedIndex = SelectedConnectionKey  
357:               
358:               
359:         End If  
360:           
361:           
362:           
363:           
364:           
365:           
366:     End Sub  
367: End Class