Imports System.Windows.Forms Public Class frmEditInstrumentation Inherits BaseEditForm Private mobjDetailInstrumentation As New clsInstrumentation #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents lblInstrumentationName As Windows.Forms.Label Friend WithEvents txtInstrumentationName As Windows.Forms.TextBox Private Sub InitializeComponent() Me.lblInstrumentationName = New Windows.Forms.Label Me.txtInstrumentationName = New Windows.Forms.TextBox Me.fraAddEdit.SuspendLayout() Me.SuspendLayout() ' 'fraAddEdit ' Me.fraAddEdit.Controls.Add(Me.txtInstrumentationName) Me.fraAddEdit.Controls.Add(Me.lblInstrumentationName) Me.fraAddEdit.Location = New System.Drawing.Point(8, 417) Me.fraAddEdit.Size = New System.Drawing.Size(1072, 111) Me.fraAddEdit.Controls.SetChildIndex(Me.lblInstrumentationName, 0) Me.fraAddEdit.Controls.SetChildIndex(Me.txtInstrumentationName, 0) ' 'lblInstrumentationName ' Me.lblInstrumentationName.Location = New System.Drawing.Point(16, 24) Me.lblInstrumentationName.Name = "lblInstrumentationName" Me.lblInstrumentationName.Size = New System.Drawing.Size(96, 16) Me.lblInstrumentationName.TabIndex = 3 Me.lblInstrumentationName.Text = "Instrumentation" ' 'txtInstrumentationName ' Me.txtInstrumentationName.Location = New System.Drawing.Point(112, 24) Me.txtInstrumentationName.Name = "txtInstrumentationName" Me.txtInstrumentationName.Size = New System.Drawing.Size(448, 20) Me.txtInstrumentationName.TabIndex = 4 ' 'frmEditInstrumentation ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(1088, 534) Me.Name = "frmEditInstrumentation" Me.StartPosition = Windows.Forms.FormStartPosition.Manual Me.Text = "Edit Instrumentation" Me.fraAddEdit.ResumeLayout(False) Me.fraAddEdit.PerformLayout() Me.ResumeLayout(False) End Sub #End Region Protected Overrides Sub LoadExistingItemsList() Dim lobjInstrumentation As clsInstrumentation Dim lobjInstrumentations As System.Collections.Generic.List(Of clsInstrumentation) SetUpExistingItemsHeaders() lobjInstrumentations = clsInstrumentation.GetAllInstrumentations Me.ExistingItemsListSuspendLayout() For Each lobjInstrumentation In lobjInstrumentations Me.ExistingObjectsListItems.Add(ConvertInstrumentationToListViewItem(lobjInstrumentation)) Next Me.ExistingItemsListResumeLayout() End Sub Private Sub SetUpExistingItemsHeaders() Me.ExistingObjectsListColumns.Add("Instrumentation Name", 800, HorizontalAlignment.Left) 'Me.ExistingObjectsListColumns.Add("Column2", 0, HorizontalAlignment.Left) 'Me.ExistingObjectsListColumns.Add("Column3", 200, HorizontalAlignment.Left) 'Set up sorting rules Dim lobjBaseEditFormColumnSortRules(0) As clsGridColumnSortRule lobjBaseEditFormColumnSortRules(0) = New clsGridColumnSortRule(clsGridColumnSortRule.enumSortType.SortAsString) MyBaseEditFormColumnSortRules = lobjBaseEditFormColumnSortRules End Sub Protected Overrides Sub InitializeDetailControls() 'Load data to detail controls here at form load time txtInstrumentationName.MaxLength = MyGlobals.INSTRUMENTATION_NAME_SIZE End Sub Protected Overrides Sub SetFocusToFirstDetailControlForEdit() txtInstrumentationName.Focus() End Sub Protected Overrides Function DetailControlsHaveDifferentDataThanExistingData(ByVal lstvwExistingItem As Windows.Forms.ListViewItem) As Boolean Dim lobjSavedInstrumentation As clsInstrumentation Dim lblnReturnValue As Boolean = False lobjSavedInstrumentation = CType(lstvwExistingItem.Tag, clsInstrumentation) mobjDetailInstrumentation.InstrumentationName = txtInstrumentationName.Text If lobjSavedInstrumentation.StateIsIdentical(mobjDetailInstrumentation) Then Return False Else Return True End If End Function Protected Overrides Function DetailControlsHaveSignificantData() As Boolean If txtInstrumentationName.Text.Trim.Length > 0 Then Return True End If Return False End Function Protected Overrides Sub EmptyOutDetailControls() txtInstrumentationName.Text = "" mobjDetailInstrumentation = New clsInstrumentation End Sub Protected Overrides Function LoadExistingDataToDetailControls(ByVal lstvwExistingItem As Windows.Forms.ListViewItem) As Boolean Dim lobjInstrumentation As clsInstrumentation Dim lblnReturnValue As Boolean = False lobjInstrumentation = CType(lstvwExistingItem.Tag, clsInstrumentation) txtInstrumentationName.Text = lobjInstrumentation.InstrumentationName mobjDetailInstrumentation = CType(lobjInstrumentation.Clone(), clsInstrumentation) Return True End Function Protected Overrides Function ConfirmOKToDeleteExistingItem(ByVal lstvwItemToDelete As Windows.Forms.ListViewItem) As Boolean Dim lobjInstrumentation As clsInstrumentation Dim lstrReferencedBy As String = "" lobjInstrumentation = CType(lstvwItemToDelete.Tag, clsInstrumentation) If Not lobjInstrumentation.OKToDelete(lstrReferencedBy) Then MessageBox.Show("Can't delete Instrumentation: " + lobjInstrumentation.InstrumentationName + ". Currently used by " + lstrReferencedBy + ".", "Unable to delete", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Return False End If Dim ldrDialogResult As DialogResult = MessageBox.Show("Are you sure you want to delete Instrumentation: " + lobjInstrumentation.InstrumentationName + "?", "Delete confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) If ldrDialogResult = Windows.Forms.DialogResult.No Then Return False End If Return True End Function Protected Overrides Function DeleteExistingItem(ByVal lstvwItemToDelete As Windows.Forms.ListViewItem) As Boolean Dim lobjInstrumentation As clsInstrumentation lobjInstrumentation = CType(lstvwItemToDelete.Tag, clsInstrumentation) Return lobjInstrumentation.Delete() End Function Protected Overrides Function SaveNewItem() As Boolean Dim lstrErrorString As String = "" mobjDetailInstrumentation.InstrumentationName = txtInstrumentationName.Text If Not mobjDetailInstrumentation.Validate(lstrErrorString) Then MessageBox.Show(lstrErrorString, "Edit Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Return False End If If Not mobjDetailInstrumentation.Save() Then Return False End If Me.ExistingObjectsListItems.Add(ConvertInstrumentationToListViewItem(mobjDetailInstrumentation)) Return True End Function Protected Overrides Sub UserRequestedToExit() Me.Close() End Sub Protected Overrides Sub EditOrAddStarting() CType(Me.ParentForm, frmMain).DisableMenus() End Sub Protected Overrides Sub EditOrAddCompleted() CType(Me.ParentForm, frmMain).EnableMenus() End Sub Private Function ConvertInstrumentationToListViewItem(ByVal lobjInstrumentation As clsInstrumentation) As ListViewItem Dim lobjItem As ListViewItem lobjItem = New ListViewItem(lobjInstrumentation.InstrumentationName) 'lobjItem.SubItems.Add("Item1Col2") 'lobjItem.SubItems.Add("Item1Col3") lobjItem.Tag = lobjInstrumentation Return lobjItem End Function Protected Overrides Function SaveNewDataForExistingItem(ByVal lstvwExistingItem As Windows.Forms.ListViewItem) As Boolean Dim lstrErrorString As String = "" mobjDetailInstrumentation.InstrumentationName = txtInstrumentationName.Text If Not mobjDetailInstrumentation.Validate(lstrErrorString) Then MessageBox.Show(lstrErrorString, "Edit Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Return False End If If Not mobjDetailInstrumentation.Save() Then Return False End If Me.ExistingObjectsListItems.Remove(lstvwExistingItem) Me.ExistingObjectsListItems.Add(ConvertInstrumentationToListViewItem(mobjDetailInstrumentation)) Return True End Function Private Sub txtInstrumentationName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInstrumentationName.TextChanged MyBase.DetailDataHasChanged() End Sub End Class