Option Strict Off
Option Explicit On
Imports NorthwindDatabase
Imports System.Windows.Forms
Friend Class frmSuppliers
Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
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
Public ToolTip1 As System.Windows.Forms.ToolTip
Public WithEvents cmdDelete As System.Windows.Forms.Button
Public WithEvents cmdNew As System.Windows.Forms.Button
Public WithEvents cmdRename As System.Windows.Forms.Button
Public WithEvents cmdClose As System.Windows.Forms.Button
Public WithEvents lstSuppliers As System.Windows.Forms.ListBox
'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.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.cmdDelete = New System.Windows.Forms.Button
Me.cmdNew = New System.Windows.Forms.Button
Me.cmdRename = New System.Windows.Forms.Button
Me.cmdClose = New System.Windows.Forms.Button
Me.lstSuppliers = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'cmdDelete
'
Me.cmdDelete.BackColor = System.Drawing.SystemColors.Control
Me.cmdDelete.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdDelete.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdDelete.ForeColor = System.Drawing.SystemColors.ControlText
Me.cmdDelete.Location = New System.Drawing.Point(188, 404)
Me.cmdDelete.Name = "cmdDelete"
Me.cmdDelete.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdDelete.Size = New System.Drawing.Size(81, 24)
Me.cmdDelete.TabIndex = 3
Me.cmdDelete.Text = "Delete"
'
'cmdNew
'
Me.cmdNew.BackColor = System.Drawing.SystemColors.Control
Me.cmdNew.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdNew.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdNew.ForeColor = System.Drawing.SystemColors.ControlText
Me.cmdNew.Location = New System.Drawing.Point(12, 404)
Me.cmdNew.Name = "cmdNew"
Me.cmdNew.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdNew.Size = New System.Drawing.Size(81, 24)
Me.cmdNew.TabIndex = 1
Me.cmdNew.Text = "&New"
'
'cmdRename
'
Me.cmdRename.BackColor = System.Drawing.SystemColors.Control
Me.cmdRename.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdRename.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdRename.ForeColor = System.Drawing.SystemColors.ControlText
Me.cmdRename.Location = New System.Drawing.Point(100, 404)
Me.cmdRename.Name = "cmdRename"
Me.cmdRename.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdRename.Size = New System.Drawing.Size(81, 24)
Me.cmdRename.TabIndex = 2
Me.cmdRename.Text = "&Rename"
'
'cmdClose
'
Me.cmdClose.BackColor = System.Drawing.SystemColors.Control
Me.cmdClose.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdClose.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.cmdClose.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdClose.ForeColor = System.Drawing.SystemColors.ControlText
Me.cmdClose.Location = New System.Drawing.Point(328, 404)
Me.cmdClose.Name = "cmdClose"
Me.cmdClose.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdClose.Size = New System.Drawing.Size(81, 24)
Me.cmdClose.TabIndex = 4
Me.cmdClose.Text = "&Close"
'
'lstSuppliers
'
Me.lstSuppliers.BackColor = System.Drawing.SystemColors.Window
Me.lstSuppliers.Cursor = System.Windows.Forms.Cursors.Default
Me.lstSuppliers.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lstSuppliers.ForeColor = System.Drawing.SystemColors.WindowText
Me.lstSuppliers.ItemHeight = 14
Me.lstSuppliers.Location = New System.Drawing.Point(12, 12)
Me.lstSuppliers.Name = "lstSuppliers"
Me.lstSuppliers.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.lstSuppliers.Size = New System.Drawing.Size(397, 382)
Me.lstSuppliers.TabIndex = 0
'
'frmSuppliers
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.Control
Me.CancelButton = Me.cmdClose
Me.ClientSize = New System.Drawing.Size(420, 435)
Me.Controls.Add(Me.cmdDelete)
Me.Controls.Add(Me.cmdNew)
Me.Controls.Add(Me.cmdRename)
Me.Controls.Add(Me.cmdClose)
Me.Controls.Add(Me.lstSuppliers)
Me.Cursor = System.Windows.Forms.Cursors.Default
Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Location = New System.Drawing.Point(3, 29)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frmSuppliers"
Me.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.ShowInTaskbar = False
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "Suppliers"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub LoadSuppliers()
Dim objSupplier As Supplier
With Me.lstSuppliers
.Items.Clear()
'To use the For Each enumerator see the GetEnumerator function in the Suppliers class
For Each objSupplier In NorthwindDB.Suppliers
.Items.Add(objSupplier.Name)
Next
''Alternatively you can interate using the ObjectByOrdinal
'Dim intIndex As Integer
'For intIndex = 0 To NorthwindDB.Suppliers.Count - 1
' .Items.Add(NorthwindDB.Suppliers(intIndex).Name)
'Next
End With
End Sub
Private Sub cmdNew_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdNew.Click
Dim objSupplier As Supplier
Dim strNewSupplierName As String
strNewSupplierName = InputDialog.InputBox("Please enter the name of the new supplier:", "", "")
If strNewSupplierName <> Nothing Then
If NorthwindDB.Suppliers.Exists(strNewSupplierName) Then
MessageBox.Show("Supplier '" & strNewSupplierName & "' already exists.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
objSupplier = New Supplier
objSupplier.Name = strNewSupplierName
objSupplier.Save()
LoadSuppliers()
End If
End If
End Sub
Private Sub cmdRename_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRename.Click
Dim strNewSupplierName As String
Dim objSupplier As Supplier
If Me.lstSuppliers.SelectedIndex >= 0 Then
objSupplier = NorthwindDB.Suppliers(Me.lstSuppliers.Text)
strNewSupplierName = InputDialog.InputBox("Please enter the new supplier name for '" & objSupplier.Name & "'.", "", objSupplier.Name).Trim
If strNewSupplierName <> Nothing Then
'if the new name is the same as the old name then do nothing
If String.Compare(strNewSupplierName, objSupplier.Name, ignorecase:=True) = 0 Then
ElseIf NorthwindDB.Suppliers.Exists(strNewSupplierName) Then
MessageBox.Show("This supplier name already exists.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
objSupplier.Name = strNewSupplierName
objSupplier.Save()
LoadSuppliers()
End If
End If
Else
MessageBox.Show("Please select a supplier to rename.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub cmdDelete_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdDelete.Click
Dim objSupplier As Supplier
If Me.lstSuppliers.SelectedIndex >= 0 Then
objSupplier = NorthwindDB.Suppliers(Me.lstSuppliers.Text)
If objSupplier.IsDeletable Then
If MessageBox.Show("Are you sure you want to delete supplier '" & objSupplier.Name & "'.", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
NorthwindDB.Suppliers.Delete(objSupplier)
LoadSuppliers()
End If
Else
MessageBox.Show("Supplier '" & objSupplier.Name & "' cannot be deleted, because it is a supplier of an existing product.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Else
MessageBox.Show("Please select a supplier to delete.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub frmSuppliers_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
LoadSuppliers()
End Sub
Private Sub cmdClose_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClose.Click
Me.Close()
End Sub
End Class