BaseFormTemplate.vb

 'BaseFormTemplate
'---------------------------------------------------------------------
'You an use these library to quickly create projects, due to its easy
'to code structure. (Look at Customers Form in TestTemplate Project)
'---------------------------------------------------------------------
'Author : Carlos A. Vara Pedroza
'Last Modified : Sep. 13 2005
'

Imports System.Drawing
Imports System.IO
Imports System.Data.SqlClient
Imports System.Reflection
Imports System.ComponentModel
Imports System.Windows.Forms
Public Class BaseFormTemplate
  Inherits System.Windows.Forms.Form

#Region "Local Variable declarations and events"

  Public Enum enmStatusTransaction
NormalMode
AddMode
EditMode
DeleteMode
'ErrorMode
  End Enum

  Public Enum enmGridFieldType
grdText
grdBoolean
  End Enum

  Public Enum enmDataType
typText
typNumeric
typDate
typBoolean

  End Enum
  Private Structure ParameterControlUpdate
Public Name As String
Public ValueOwner As Object
Public DefaultValue As Object
Public DataType As enmDataType
Public Key As Boolean
Public Function GetValue() As Object
  If ValueOwner Is Nothing Then
Return DefaultValue
  Else
Select Case ValueOwner.GetType.Name.ToUpper
  Case Is = "TEXTBOX"
Return CType(ValueOwner, TextBox).Text
  Case Is = "COMBOBOX"
Return CType(ValueOwner, ComboBox).SelectedValue
End Select
  End If
End Function
  End Structure

  Private m_UpdateValues As Collection
  Private m_Status As enmStatusTransaction
  Private m_OldStatus As enmStatusTransaction

  Private m_GridTable As String = Nothing
  Private m_GridHeight As Integer
  Private m_GridVisible As Boolean

  Private m_DBCnn As SqlConnection


  Private Shared WithEvents dsData As DataSet
  Private Shared WithEvents daData As SqlDataAdapter

  Private m_Tables() As String
  Private m_grdTableStyle As New DataGridTableStyle  'Table Style del Grid

  Private drIndex As Integer
  Private drFounded() As DataRow

  Private OldAcceptButton As IButtonControl

  Private m_grdContextMenu As ContextMenu

  Public CM As CurrencyManager

  Public Event StatusHasChanged(ByVal NewStatus As enmStatusTransaction)





#End Region

#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

m_DBCnn = New SqlConnection

dsData = New DataSet
daData = New SqlDataAdapter

cboOperator.SelectedIndex = 0

m_UpdateValues = New Collection

  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 imgIconos As System.Windows.Forms.ImageList
  Friend WithEvents mnuPrincipal As System.Windows.Forms.MenuItem
  Friend WithEvents MainMenu As System.Windows.Forms.MainMenu
  Friend WithEvents mnuSep01 As System.Windows.Forms.MenuItem
  Friend WithEvents tbrTools As System.Windows.Forms.ToolBar
  Friend WithEvents btnIni As System.Windows.Forms.ToolBarButton
  Friend WithEvents btnPrev As System.Windows.Forms.ToolBarButton
  Friend WithEvents btnGoto As System.Windows.Forms.ToolBarButton
  Friend WithEvents btnNext As System.Windows.Forms.ToolBarButton
  Friend WithEvents btnEnd As System.Windows.Forms.ToolBarButton
  Friend WithEvents lblSearch01 As System.Windows.Forms.Label
  Friend WithEvents txtToSearch As System.Windows.Forms.TextBox
  Friend WithEvents lblSearch02 As System.Windows.Forms.Label
  Friend WithEvents btnCloseSearch As System.Windows.Forms.Button
  Friend WithEvents btnSearch As System.Windows.Forms.Button
  Friend WithEvents pnlControles As System.Windows.Forms.Panel
  Friend WithEvents pnlSearch As System.Windows.Forms.Panel
  Public WithEvents grdInfo As System.Windows.Forms.DataGrid
  Friend WithEvents lblInfo As System.Windows.Forms.Label
  Friend WithEvents pnlGridControls As System.Windows.Forms.Panel
  Friend WithEvents pnlInfo As System.Windows.Forms.Panel
  Friend WithEvents pnlToolbar As System.Windows.Forms.Panel
  Friend WithEvents pnlGrid As System.Windows.Forms.Panel
  Friend WithEvents Label1 As System.Windows.Forms.Label
  Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
  Friend WithEvents txtNumRecord As System.Windows.Forms.TextBox
  Friend WithEvents btnGotoRecord As System.Windows.Forms.Button
  Friend WithEvents pnlGotoRecord As System.Windows.Forms.Panel
  Friend WithEvents btnCloseGoto As System.Windows.Forms.Button
  Friend WithEvents btnSep01 As System.Windows.Forms.ToolBarButton
  Friend WithEvents btnFind As System.Windows.Forms.ToolBarButton
  Friend WithEvents btnSearchNext As System.Windows.Forms.Button
  Friend WithEvents chkExactSearch As System.Windows.Forms.CheckBox
  Friend WithEvents btnFilter As System.Windows.Forms.ToolBarButton
  Friend WithEvents pnlFilter As System.Windows.Forms.Panel
  Friend WithEvents btnApplyFilters As System.Windows.Forms.Button
  Friend WithEvents btnCloseFilters As System.Windows.Forms.Button
  Friend WithEvents lstFilters As System.Windows.Forms.ListBox
  Friend WithEvents Label2 As System.Windows.Forms.Label
  Friend WithEvents Label3 As System.Windows.Forms.Label
  Friend WithEvents Label4 As System.Windows.Forms.Label
  Friend WithEvents cboGridColumn02 As System.Windows.Forms.ComboBox
  Friend WithEvents cboGridColumn01 As System.Windows.Forms.ComboBox
  Friend WithEvents btnAddFilter As System.Windows.Forms.Button
  Friend WithEvents cboOperator As System.Windows.Forms.ComboBox
  Friend WithEvents txtCriteria As System.Windows.Forms.TextBox
  Friend WithEvents btnRemoveFilters As System.Windows.Forms.Button
  Friend WithEvents mnuNew As System.Windows.Forms.MenuItem
  Friend WithEvents mnuEdit As System.Windows.Forms.MenuItem
  Friend WithEvents mnuSave As System.Windows.Forms.MenuItem
  Friend WithEvents mnuCancel As System.Windows.Forms.MenuItem
  Friend WithEvents mnuClose As System.Windows.Forms.MenuItem
  Friend WithEvents mnuPrint As System.Windows.Forms.MenuItem
  Friend WithEvents mnuPreview As System.Windows.Forms.MenuItem
  Friend WithEvents mnuGoTo As System.Windows.Forms.MenuItem
  Friend WithEvents mnuSearch As System.Windows.Forms.MenuItem
  Friend WithEvents mnuFilter As System.Windows.Forms.MenuItem
  Friend WithEvents mnuRefresh As System.Windows.Forms.MenuItem
  Friend WithEvents mnuView As System.Windows.Forms.MenuItem
  Friend WithEvents mnuViewGrid As System.Windows.Forms.MenuItem
  Friend WithEvents mnuViewNavTool As System.Windows.Forms.MenuItem
  Friend WithEvents mnuSep02 As System.Windows.Forms.MenuItem
  Friend WithEvents mnuSep03 As System.Windows.Forms.MenuItem
  Friend WithEvents mnuSep04 As System.Windows.Forms.MenuItem
  Friend WithEvents mnuSep05 As System.Windows.Forms.MenuItem
  Friend WithEvents mnuSep06 As System.Windows.Forms.MenuItem
  Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
  Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
  Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
  Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
  Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
  Friend WithEvents mnuDelete As System.Windows.Forms.MenuItem
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(BaseFormTemplate))
Me.imgIconos = New System.Windows.Forms.ImageList(Me.components)
Me.MainMenu = New System.Windows.Forms.MainMenu
Me.mnuPrincipal = New System.Windows.Forms.MenuItem
Me.mnuNew = New System.Windows.Forms.MenuItem
Me.mnuEdit = New System.Windows.Forms.MenuItem
Me.mnuDelete = New System.Windows.Forms.MenuItem
Me.mnuSep01 = New System.Windows.Forms.MenuItem
Me.mnuSave = New System.Windows.Forms.MenuItem
Me.mnuCancel = New System.Windows.Forms.MenuItem
Me.mnuSep02 = New System.Windows.Forms.MenuItem
Me.mnuPrint = New System.Windows.Forms.MenuItem
Me.mnuPreview = New System.Windows.Forms.MenuItem
Me.mnuSep03 = New System.Windows.Forms.MenuItem
Me.mnuSearch = New System.Windows.Forms.MenuItem
Me.mnuFilter = New System.Windows.Forms.MenuItem
Me.mnuSep04 = New System.Windows.Forms.MenuItem
Me.mnuView = New System.Windows.Forms.MenuItem
Me.mnuViewGrid = New System.Windows.Forms.MenuItem
Me.mnuViewNavTool = New System.Windows.Forms.MenuItem
Me.MenuItem4 = New System.Windows.Forms.MenuItem
Me.MenuItem7 = New System.Windows.Forms.MenuItem
Me.MenuItem5 = New System.Windows.Forms.MenuItem
Me.mnuGoTo = New System.Windows.Forms.MenuItem
Me.MenuItem6 = New System.Windows.Forms.MenuItem
Me.MenuItem8 = New System.Windows.Forms.MenuItem
Me.mnuSep05 = New System.Windows.Forms.MenuItem
Me.mnuRefresh = New System.Windows.Forms.MenuItem
Me.mnuSep06 = New System.Windows.Forms.MenuItem
Me.mnuClose = New System.Windows.Forms.MenuItem
Me.pnlControles = New System.Windows.Forms.Panel
Me.pnlGridControls = New System.Windows.Forms.Panel
Me.pnlGrid = New System.Windows.Forms.Panel
Me.grdInfo = New System.Windows.Forms.DataGrid
Me.pnlSearch = New System.Windows.Forms.Panel
Me.btnSearchNext = New System.Windows.Forms.Button
Me.chkExactSearch = New System.Windows.Forms.CheckBox
Me.txtToSearch = New System.Windows.Forms.TextBox
Me.btnSearch = New System.Windows.Forms.Button
Me.btnCloseSearch = New System.Windows.Forms.Button
Me.cboGridColumn01 = New System.Windows.Forms.ComboBox
Me.lblSearch02 = New System.Windows.Forms.Label
Me.lblSearch01 = New System.Windows.Forms.Label
Me.pnlGotoRecord = New System.Windows.Forms.Panel
Me.txtNumRecord = New System.Windows.Forms.TextBox
Me.btnGotoRecord = New System.Windows.Forms.Button
Me.btnCloseGoto = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.pnlFilter = New System.Windows.Forms.Panel
Me.btnRemoveFilters = New System.Windows.Forms.Button
Me.btnAddFilter = New System.Windows.Forms.Button
Me.txtCriteria = New System.Windows.Forms.TextBox
Me.cboOperator = New System.Windows.Forms.ComboBox
Me.cboGridColumn02 = New System.Windows.Forms.ComboBox
Me.lstFilters = New System.Windows.Forms.ListBox
Me.btnApplyFilters = New System.Windows.Forms.Button
Me.btnCloseFilters = New System.Windows.Forms.Button
Me.Label4 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.tbrTools = New System.Windows.Forms.ToolBar
Me.btnIni = New System.Windows.Forms.ToolBarButton
Me.btnPrev = New System.Windows.Forms.ToolBarButton
Me.btnGoto = New System.Windows.Forms.ToolBarButton
Me.btnNext = New System.Windows.Forms.ToolBarButton
Me.btnEnd = New System.Windows.Forms.ToolBarButton
Me.btnSep01 = New System.Windows.Forms.ToolBarButton
Me.btnFind = New System.Windows.Forms.ToolBarButton
Me.btnFilter = New System.Windows.Forms.ToolBarButton
Me.pnlInfo = New System.Windows.Forms.Panel
Me.pnlToolbar = New System.Windows.Forms.Panel
Me.lblInfo = New System.Windows.Forms.Label
Me.Splitter1 = New System.Windows.Forms.Splitter
Me.pnlControles.SuspendLayout()
Me.pnlGridControls.SuspendLayout()
Me.pnlGrid.SuspendLayout()
CType(Me.grdInfo, System.ComponentModel.ISupportInitialize).BeginInit()
Me.pnlSearch.SuspendLayout()
Me.pnlGotoRecord.SuspendLayout()
Me.pnlFilter.SuspendLayout()
Me.pnlInfo.SuspendLayout()
Me.pnlToolbar.SuspendLayout()
Me.SuspendLayout()
'
'imgIconos
'
Me.imgIconos.ImageSize = New System.Drawing.Size(16, 16)
Me.imgIconos.ImageStream = CType(resources.GetObject("imgIconos.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.imgIconos.TransparentColor = System.Drawing.Color.Transparent
'
'MainMenu
'
Me.MainMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuPrincipal})
'
'mnuPrincipal
'
Me.mnuPrincipal.DefaultItem = True
Me.mnuPrincipal.Index = 0
Me.mnuPrincipal.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuNew, Me.mnuEdit, Me.mnuDelete, Me.mnuSep01, Me.mnuSave, Me.mnuCancel, Me.mnuSep02, Me.mnuPrint, Me.mnuPreview, Me.mnuSep03, Me.mnuSearch, Me.mnuFilter, Me.mnuSep04, Me.mnuView, Me.MenuItem4, Me.mnuSep05, Me.mnuRefresh, Me.mnuSep06, Me.mnuClose})
Me.mnuPrincipal.MergeType = System.Windows.Forms.MenuMerge.Replace
Me.mnuPrincipal.Text = "&Actions"
'
'mnuNew
'
Me.mnuNew.Index = 0
Me.mnuNew.Text = "&New"
'
'mnuEdit
'
Me.mnuEdit.Index = 1
Me.mnuEdit.Text = "&Edit"
'
'mnuDelete
'
Me.mnuDelete.Index = 2
Me.mnuDelete.Text = "&Delete"
'
'mnuSep01
'
Me.mnuSep01.Index = 3
Me.mnuSep01.Text = "-"
'
'mnuSave
'
Me.mnuSave.Index = 4
Me.mnuSave.Text = "&Save"
'
'mnuCancel
'
Me.mnuCancel.Index = 5
Me.mnuCancel.Text = "C&ancel"
'
'mnuSep02
'
Me.mnuSep02.Index = 6
Me.mnuSep02.Text = "-"
'
'mnuPrint
'
Me.mnuPrint.Index = 7
Me.mnuPrint.Text = "&Print..."
'
'mnuPreview
'
Me.mnuPreview.Index = 8
Me.mnuPreview.Text = "Pre&view..."
'
'mnuSep03
'
Me.mnuSep03.Index = 9
Me.mnuSep03.Text = "-"
'
'mnuSearch
'
Me.mnuSearch.Index = 10
Me.mnuSearch.Shortcut = System.Windows.Forms.Shortcut.F3
Me.mnuSearch.Text = "&Search..."
'
'mnuFilter
'
Me.mnuFilter.Index = 11
Me.mnuFilter.Text = "&Filter..."
'
'mnuSep04
'
Me.mnuSep04.Index = 12
Me.mnuSep04.Text = "-"
'
'mnuView
'
Me.mnuView.Index = 13
Me.mnuView.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuViewGrid, Me.mnuViewNavTool})
Me.mnuView.Text = "View"
'
'mnuViewGrid
'
Me.mnuViewGrid.Checked = True
Me.mnuViewGrid.Index = 0
Me.mnuViewGrid.Text = "Grid"
'
'mnuViewNavTool
'
Me.mnuViewNavTool.Checked = True
Me.mnuViewNavTool.Index = 1
Me.mnuViewNavTool.Text = "Navigation Toolbar"
'
'MenuItem4
'
Me.MenuItem4.Index = 14
Me.MenuItem4.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem7, Me.MenuItem5, Me.mnuGoTo, Me.MenuItem6, Me.MenuItem8})
Me.MenuItem4.Text = "Record"
'
'MenuItem7
'
Me.MenuItem7.Index = 0
Me.MenuItem7.Text = "Go Top"
'
'MenuItem5
'
Me.MenuItem5.Index = 1
Me.MenuItem5.Text = "Previous"
'
'mnuGoTo
'
Me.mnuGoTo.Index = 2
Me.mnuGoTo.Text = "&Go to..."
'
'MenuItem6
'
Me.MenuItem6.Index = 3
Me.MenuItem6.Text = "Next"
'
'MenuItem8
'
Me.MenuItem8.Index = 4
Me.MenuItem8.Text = "Go Bottom"
'
'mnuSep05
'
Me.mnuSep05.Index = 15
Me.mnuSep05.Text = "-"
'
'mnuRefresh
'
Me.mnuRefresh.Index = 16
Me.mnuRefresh.Shortcut = System.Windows.Forms.Shortcut.F5
Me.mnuRefresh.Text = "&Refresh"
'
'mnuSep06
'
Me.mnuSep06.Index = 17
Me.mnuSep06.Text = "-"
'
'mnuClose
'
Me.mnuClose.Index = 18
Me.mnuClose.Text = "&Close"
'
'pnlControles
'
Me.pnlControles.BackColor = System.Drawing.SystemColors.AppWorkspace
Me.pnlControles.Controls.Add(Me.pnlGridControls)
Me.pnlControles.Dock = System.Windows.Forms.DockStyle.Top
Me.pnlControles.Location = New System.Drawing.Point(0, 24)
Me.pnlControles.Name = "pnlControles"
Me.pnlControles.Size = New System.Drawing.Size(640, 176)
Me.pnlControles.TabIndex = 13
'
'pnlGridControls
'
Me.pnlGridControls.Controls.Add(Me.pnlGrid)
Me.pnlGridControls.Controls.Add(Me.pnlSearch)
Me.pnlGridControls.Controls.Add(Me.pnlGotoRecord)
Me.pnlGridControls.Controls.Add(Me.pnlFilter)
Me.pnlGridControls.Dock = System.Windows.Forms.DockStyle.Fill
Me.pnlGridControls.Location = New System.Drawing.Point(0, 0)
Me.pnlGridControls.Name = "pnlGridControls"
Me.pnlGridControls.Size = New System.Drawing.Size(640, 176)
Me.pnlGridControls.TabIndex = 17
'
'pnlGrid
'
Me.pnlGrid.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.pnlGrid.Controls.Add(Me.grdInfo)
Me.pnlGrid.Dock = System.Windows.Forms.DockStyle.Fill
Me.pnlGrid.Location = New System.Drawing.Point(448, 0)
Me.pnlGrid.Name = "pnlGrid"
Me.pnlGrid.Size = New System.Drawing.Size(192, 176)
Me.pnlGrid.TabIndex = 2
'
'grdInfo
'
Me.grdInfo.AlternatingBackColor = System.Drawing.SystemColors.Info
Me.grdInfo.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.grdInfo.CaptionVisible = False
Me.grdInfo.DataMember = ""
Me.grdInfo.Dock = System.Windows.Forms.DockStyle.Fill
Me.grdInfo.FlatMode = True
Me.grdInfo.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.grdInfo.Location = New System.Drawing.Point(0, 0)
Me.grdInfo.Name = "grdInfo"
Me.grdInfo.Size = New System.Drawing.Size(188, 172)
Me.grdInfo.TabIndex = 0
'
'pnlSearch
'
Me.pnlSearch.AutoScroll = True
Me.pnlSearch.BackColor = System.Drawing.Color.Gainsboro
Me.pnlSearch.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.pnlSearch.Controls.Add(Me.btnSearchNext)
Me.pnlSearch.Controls.Add(Me.chkExactSearch)
Me.pnlSearch.Controls.Add(Me.txtToSearch)
Me.pnlSearch.Controls.Add(Me.btnSearch)
Me.pnlSearch.Controls.Add(Me.btnCloseSearch)
Me.pnlSearch.Controls.Add(Me.cboGridColumn01)
Me.pnlSearch.Controls.Add(Me.lblSearch02)
Me.pnlSearch.Controls.Add(Me.lblSearch01)
Me.pnlSearch.Dock = System.Windows.Forms.DockStyle.Left
Me.pnlSearch.ForeColor = System.Drawing.SystemColors.Control
Me.pnlSearch.Location = New System.Drawing.Point(312, 0)
Me.pnlSearch.Name = "pnlSearch"
Me.pnlSearch.Size = New System.Drawing.Size(136, 176)
Me.pnlSearch.TabIndex = 1
Me.pnlSearch.Visible = False
'
'btnSearchNext
'
Me.btnSearchNext.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnSearchNext.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnSearchNext.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnSearchNext.Image = CType(resources.GetObject("btnSearchNext.Image"), System.Drawing.Image)
Me.btnSearchNext.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.btnSearchNext.Location = New System.Drawing.Point(4, 148)
Me.btnSearchNext.Name = "btnSearchNext"
Me.btnSearchNext.Size = New System.Drawing.Size(112, 20)
Me.btnSearchNext.TabIndex = 6
Me.btnSearchNext.Text = "Search &Next"
Me.btnSearchNext.Visible = False
'
'chkExactSearch
'
Me.chkExactSearch.BackColor = System.Drawing.Color.Transparent
Me.chkExactSearch.ForeColor = System.Drawing.SystemColors.ControlText
Me.chkExactSearch.Location = New System.Drawing.Point(4, 104)
Me.chkExactSearch.Name = "chkExactSearch"
Me.chkExactSearch.Size = New System.Drawing.Size(124, 16)
Me.chkExactSearch.TabIndex = 4
Me.chkExactSearch.Text = "Match whole word"
'
'txtToSearch
'
Me.txtToSearch.Location = New System.Drawing.Point(4, 80)
Me.txtToSearch.Name = "txtToSearch"
Me.txtToSearch.Size = New System.Drawing.Size(124, 21)
Me.txtToSearch.TabIndex = 3
Me.txtToSearch.Text = ""
'
'btnSearch
'
Me.btnSearch.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnSearch.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnSearch.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnSearch.Image = CType(resources.GetObject("btnSearch.Image"), System.Drawing.Image)
Me.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.btnSearch.Location = New System.Drawing.Point(4, 124)
Me.btnSearch.Name = "btnSearch"
Me.btnSearch.Size = New System.Drawing.Size(68, 20)
Me.btnSearch.TabIndex = 5
Me.btnSearch.Text = "&Search"
'
'btnCloseSearch
'
Me.btnCloseSearch.BackColor = System.Drawing.Color.Gainsboro
Me.btnCloseSearch.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnCloseSearch.Font = New System.Drawing.Font("Wingdings 2", 6.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(2, Byte))
Me.btnCloseSearch.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnCloseSearch.Location = New System.Drawing.Point(112, 4)
Me.btnCloseSearch.Name = "btnCloseSearch"
Me.btnCloseSearch.Size = New System.Drawing.Size(16, 16)
Me.btnCloseSearch.TabIndex = 7
Me.btnCloseSearch.Text = "Ï"
Me.btnCloseSearch.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'cboGridColumn01
'
Me.cboGridColumn01.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboGridColumn01.Location = New System.Drawing.Point(4, 36)
Me.cboGridColumn01.Name = "cboGridColumn01"
Me.cboGridColumn01.Size = New System.Drawing.Size(124, 21)
Me.cboGridColumn01.TabIndex = 1
'
'lblSearch02
'
Me.lblSearch02.AutoSize = True
Me.lblSearch02.BackColor = System.Drawing.Color.Transparent
Me.lblSearch02.ForeColor = System.Drawing.SystemColors.WindowText
Me.lblSearch02.Location = New System.Drawing.Point(4, 64)
Me.lblSearch02.Name = "lblSearch02"
Me.lblSearch02.Size = New System.Drawing.Size(87, 17)
Me.lblSearch02.TabIndex = 2
Me.lblSearch02.Text = "Value to Search:"
'
'lblSearch01
'
Me.lblSearch01.AutoSize = True
Me.lblSearch01.BackColor = System.Drawing.Color.Transparent
Me.lblSearch01.ForeColor = System.Drawing.SystemColors.WindowText
Me.lblSearch01.Location = New System.Drawing.Point(4, 20)
Me.lblSearch01.Name = "lblSearch01"
Me.lblSearch01.Size = New System.Drawing.Size(58, 17)
Me.lblSearch01.TabIndex = 0
Me.lblSearch01.Text = "Search in :"
'
'pnlGotoRecord
'
Me.pnlGotoRecord.AutoScroll = True
Me.pnlGotoRecord.BackColor = System.Drawing.Color.Gainsboro
Me.pnlGotoRecord.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.pnlGotoRecord.Controls.Add(Me.txtNumRecord)
Me.pnlGotoRecord.Controls.Add(Me.btnGotoRecord)
Me.pnlGotoRecord.Controls.Add(Me.btnCloseGoto)
Me.pnlGotoRecord.Controls.Add(Me.Label1)
Me.pnlGotoRecord.Dock = System.Windows.Forms.DockStyle.Left
Me.pnlGotoRecord.ForeColor = System.Drawing.SystemColors.Control
Me.pnlGotoRecord.Location = New System.Drawing.Point(232, 0)
Me.pnlGotoRecord.Name = "pnlGotoRecord"
Me.pnlGotoRecord.Size = New System.Drawing.Size(80, 176)
Me.pnlGotoRecord.TabIndex = 0
Me.pnlGotoRecord.Visible = False
'
'txtNumRecord
'
Me.txtNumRecord.Location = New System.Drawing.Point(4, 36)
Me.txtNumRecord.Name = "txtNumRecord"
Me.txtNumRecord.Size = New System.Drawing.Size(68, 21)
Me.txtNumRecord.TabIndex = 2
Me.txtNumRecord.Text = ""
'
'btnGotoRecord
'
Me.btnGotoRecord.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnGotoRecord.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnGotoRecord.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnGotoRecord.Image = CType(resources.GetObject("btnGotoRecord.Image"), System.Drawing.Image)
Me.btnGotoRecord.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.btnGotoRecord.Location = New System.Drawing.Point(4, 64)
Me.btnGotoRecord.Name = "btnGotoRecord"
Me.btnGotoRecord.Size = New System.Drawing.Size(64, 20)
Me.btnGotoRecord.TabIndex = 3
Me.btnGotoRecord.Text = "&Go"
'
'btnCloseGoto
'
Me.btnCloseGoto.BackColor = System.Drawing.Color.Gainsboro
Me.btnCloseGoto.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnCloseGoto.Font = New System.Drawing.Font("Wingdings 2", 6.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(2, Byte))
Me.btnCloseGoto.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnCloseGoto.Location = New System.Drawing.Point(56, 4)
Me.btnCloseGoto.Name = "btnCloseGoto"
Me.btnCloseGoto.Size = New System.Drawing.Size(16, 16)
Me.btnCloseGoto.TabIndex = 0
Me.btnCloseGoto.Text = "Ï"
Me.btnCloseGoto.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.BackColor = System.Drawing.Color.Transparent
Me.Label1.ForeColor = System.Drawing.SystemColors.WindowText
Me.Label1.Location = New System.Drawing.Point(4, 20)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(59, 17)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Record N°:"
'
'pnlFilter
'
Me.pnlFilter.AutoScroll = True
Me.pnlFilter.BackColor = System.Drawing.Color.Gainsboro
Me.pnlFilter.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.pnlFilter.Controls.Add(Me.btnRemoveFilters)
Me.pnlFilter.Controls.Add(Me.btnAddFilter)
Me.pnlFilter.Controls.Add(Me.txtCriteria)
Me.pnlFilter.Controls.Add(Me.cboOperator)
Me.pnlFilter.Controls.Add(Me.cboGridColumn02)
Me.pnlFilter.Controls.Add(Me.lstFilters)
Me.pnlFilter.Controls.Add(Me.btnApplyFilters)
Me.pnlFilter.Controls.Add(Me.btnCloseFilters)
Me.pnlFilter.Controls.Add(Me.Label4)
Me.pnlFilter.Controls.Add(Me.Label3)
Me.pnlFilter.Controls.Add(Me.Label2)
Me.pnlFilter.Dock = System.Windows.Forms.DockStyle.Left
Me.pnlFilter.ForeColor = System.Drawing.SystemColors.Control
Me.pnlFilter.Location = New System.Drawing.Point(0, 0)
Me.pnlFilter.Name = "pnlFilter"
Me.pnlFilter.Size = New System.Drawing.Size(232, 176)
Me.pnlFilter.TabIndex = 3
Me.pnlFilter.Visible = False
'
'btnRemoveFilters
'
Me.btnRemoveFilters.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnRemoveFilters.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnRemoveFilters.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnRemoveFilters.Image = CType(resources.GetObject("btnRemoveFilters.Image"), System.Drawing.Image)
Me.btnRemoveFilters.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.btnRemoveFilters.Location = New System.Drawing.Point(120, 148)
Me.btnRemoveFilters.Name = "btnRemoveFilters"
Me.btnRemoveFilters.Size = New System.Drawing.Size(104, 20)
Me.btnRemoveFilters.TabIndex = 16
Me.btnRemoveFilters.Text = "&Remove"
'
'btnAddFilter
'
Me.btnAddFilter.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnAddFilter.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnAddFilter.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnAddFilter.Image = CType(resources.GetObject("btnAddFilter.Image"), System.Drawing.Image)
Me.btnAddFilter.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.btnAddFilter.Location = New System.Drawing.Point(204, 36)
Me.btnAddFilter.Name = "btnAddFilter"
Me.btnAddFilter.Size = New System.Drawing.Size(20, 20)
Me.btnAddFilter.TabIndex = 15
'
'txtCriteria
'
Me.txtCriteria.Location = New System.Drawing.Point(156, 36)
Me.txtCriteria.Name = "txtCriteria"
Me.txtCriteria.Size = New System.Drawing.Size(44, 21)
Me.txtCriteria.TabIndex = 14
Me.txtCriteria.Text = ""
'
'cboOperator
'
Me.cboOperator.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboOperator.Items.AddRange(New Object() {"=", ">", "<", "<>", ">=", "<=", "%"})
Me.cboOperator.Location = New System.Drawing.Point(108, 36)
Me.cboOperator.Name = "cboOperator"
Me.cboOperator.Size = New System.Drawing.Size(44, 21)
Me.cboOperator.TabIndex = 12
'
'cboGridColumn02
'
Me.cboGridColumn02.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboGridColumn02.Location = New System.Drawing.Point(4, 36)
Me.cboGridColumn02.Name = "cboGridColumn02"
Me.cboGridColumn02.Size = New System.Drawing.Size(100, 21)
Me.cboGridColumn02.TabIndex = 10
'
'lstFilters
'
Me.lstFilters.Location = New System.Drawing.Point(4, 60)
Me.lstFilters.Name = "lstFilters"
Me.lstFilters.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple
Me.lstFilters.Size = New System.Drawing.Size(220, 82)
Me.lstFilters.TabIndex = 8
'
'btnApplyFilters
'
Me.btnApplyFilters.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnApplyFilters.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnApplyFilters.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnApplyFilters.Image = CType(resources.GetObject("btnApplyFilters.Image"), System.Drawing.Image)
Me.btnApplyFilters.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.btnApplyFilters.Location = New System.Drawing.Point(4, 148)
Me.btnApplyFilters.Name = "btnApplyFilters"
Me.btnApplyFilters.Size = New System.Drawing.Size(112, 20)
Me.btnApplyFilters.TabIndex = 5
Me.btnApplyFilters.Text = "Apply &Filter(s)"
'
'btnCloseFilters
'
Me.btnCloseFilters.BackColor = System.Drawing.Color.Gainsboro
Me.btnCloseFilters.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnCloseFilters.Font = New System.Drawing.Font("Wingdings 2", 6.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(2, Byte))
Me.btnCloseFilters.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnCloseFilters.Location = New System.Drawing.Point(208, 4)
Me.btnCloseFilters.Name = "btnCloseFilters"
Me.btnCloseFilters.Size = New System.Drawing.Size(16, 16)
Me.btnCloseFilters.TabIndex = 7
Me.btnCloseFilters.Text = "Ï"
Me.btnCloseFilters.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.BackColor = System.Drawing.Color.Transparent
Me.Label4.ForeColor = System.Drawing.SystemColors.WindowText
Me.Label4.Location = New System.Drawing.Point(156, 20)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(36, 17)
Me.Label4.TabIndex = 13
Me.Label4.Text = "Value:"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.BackColor = System.Drawing.Color.Transparent
Me.Label3.ForeColor = System.Drawing.SystemColors.WindowText
Me.Label3.Location = New System.Drawing.Point(108, 20)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(26, 17)
Me.Label3.TabIndex = 11
Me.Label3.Text = "Op.:"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.BackColor = System.Drawing.Color.Transparent
Me.Label2.ForeColor = System.Drawing.SystemColors.WindowText
Me.Label2.Location = New System.Drawing.Point(4, 20)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(46, 17)
Me.Label2.TabIndex = 9
Me.Label2.Text = "Column:"
'
'tbrTools
'
Me.tbrTools.Appearance = System.Windows.Forms.ToolBarAppearance.Flat
Me.tbrTools.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.btnIni, Me.btnPrev, Me.btnGoto, Me.btnNext, Me.btnEnd, Me.btnSep01, Me.btnFind, Me.btnFilter})
Me.tbrTools.Divider = False
Me.tbrTools.Dock = System.Windows.Forms.DockStyle.None
Me.tbrTools.DropDownArrows = True
Me.tbrTools.ImageList = Me.imgIconos
Me.tbrTools.Location = New System.Drawing.Point(0, 0)
Me.tbrTools.Name = "tbrTools"
Me.tbrTools.ShowToolTips = True
Me.tbrTools.Size = New System.Drawing.Size(289, 26)
Me.tbrTools.TabIndex = 0
Me.tbrTools.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right
'
'btnIni
'
Me.btnIni.ImageIndex = 0
Me.btnIni.Tag = "Top"
Me.btnIni.ToolTipText = "Go Top"
'
'btnPrev
'
Me.btnPrev.ImageIndex = 1
Me.btnPrev.Tag = "Prev"
Me.btnPrev.ToolTipText = "Previous"
'
'btnGoto
'
Me.btnGoto.ImageIndex = 2
Me.btnGoto.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
Me.btnGoto.Tag = "Go"
Me.btnGoto.ToolTipText = "Goto"
'
'btnNext
'
Me.btnNext.ImageIndex = 3
Me.btnNext.Tag = "Next"
Me.btnNext.ToolTipText = "Next"
'
'btnEnd
'
Me.btnEnd.ImageIndex = 4
Me.btnEnd.Tag = "Bottom"
Me.btnEnd.ToolTipText = "Go Bottom"
'
'btnSep01
'
Me.btnSep01.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
'
'btnFind
'
Me.btnFind.ImageIndex = 5
Me.btnFind.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
Me.btnFind.Tag = "Find"
Me.btnFind.ToolTipText = "Search"
'
'btnFilter
'
Me.btnFilter.ImageIndex = 6
Me.btnFilter.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
Me.btnFilter.Tag = "Filter"
Me.btnFilter.ToolTipText = "Filter"
'
'pnlInfo
'
Me.pnlInfo.Controls.Add(Me.pnlToolbar)
Me.pnlInfo.Controls.Add(Me.lblInfo)
Me.pnlInfo.Dock = System.Windows.Forms.DockStyle.Top
Me.pnlInfo.Location = New System.Drawing.Point(0, 0)
Me.pnlInfo.Name = "pnlInfo"
Me.pnlInfo.Size = New System.Drawing.Size(640, 24)
Me.pnlInfo.TabIndex = 18
'
'pnlToolbar
'
Me.pnlToolbar.BackColor = System.Drawing.SystemColors.Control
Me.pnlToolbar.Controls.Add(Me.tbrTools)
Me.pnlToolbar.Dock = System.Windows.Forms.DockStyle.Fill
Me.pnlToolbar.Location = New System.Drawing.Point(0, 0)
Me.pnlToolbar.Name = "pnlToolbar"
Me.pnlToolbar.Size = New System.Drawing.Size(288, 24)
Me.pnlToolbar.TabIndex = 15
'
'lblInfo
'
Me.lblInfo.BackColor = System.Drawing.SystemColors.Control
Me.lblInfo.Dock = System.Windows.Forms.DockStyle.Right
Me.lblInfo.Enabled = False
Me.lblInfo.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblInfo.Location = New System.Drawing.Point(288, 0)
Me.lblInfo.Name = "lblInfo"
Me.lblInfo.Size = New System.Drawing.Size(352, 24)
Me.lblInfo.TabIndex = 1
Me.lblInfo.Text = "Info"
Me.lblInfo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Splitter1
'
Me.Splitter1.Dock = System.Windows.Forms.DockStyle.Top
Me.Splitter1.Location = New System.Drawing.Point(0, 200)
Me.Splitter1.Name = "Splitter1"
Me.Splitter1.Size = New System.Drawing.Size(640, 3)
Me.Splitter1.TabIndex = 0
Me.Splitter1.TabStop = False
'
'BaseFormTemplate
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
Me.BackColor = System.Drawing.SystemColors.Control
Me.ClientSize = New System.Drawing.Size(640, 369)
Me.Controls.Add(Me.Splitter1)
Me.Controls.Add(Me.pnlControles)
Me.Controls.Add(Me.pnlInfo)
Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
Me.KeyPreview = True
Me.Menu = Me.MainMenu
Me.MinimumSize = New System.Drawing.Size(420, 325)
Me.Name = "BaseFormTemplate"
Me.pnlControles.ResumeLayout(False)
Me.pnlGridControls.ResumeLayout(False)
Me.pnlGrid.ResumeLayout(False)
CType(Me.grdInfo, System.ComponentModel.ISupportInitialize).EndInit()
Me.pnlSearch.ResumeLayout(False)
Me.pnlGotoRecord.ResumeLayout(False)
Me.pnlFilter.ResumeLayout(False)
Me.pnlInfo.ResumeLayout(False)
Me.pnlToolbar.ResumeLayout(False)
Me.ResumeLayout(False)

  End Sub

#End Region

#Region "Form Properties"

  Public Property Status() As enmStatusTransaction
Get
  Return m_Status
End Get
Set(ByVal Value As enmStatusTransaction)
  m_Status = Value
  RaiseEvent StatusHasChanged(m_Status)
End Set
  End Property

  Public WriteOnly Property DBConnection() As SqlConnection
Set(ByVal Value As SqlConnection)
  m_DBCnn = Value
End Set
  End Property

  Public ReadOnly Property DataSet() As DataSet
Get
  Return dsData
End Get
  End Property

  Public Property GridHeight() As Integer
Get
  Return m_GridHeight
End Get
Set(ByVal Value As Integer)
  m_GridHeight = Value
  pnlGrid.Height = m_GridHeight
End Set
  End Property
  Public Property GridVisible() As Boolean
Get
  Return m_GridVisible
End Get
Set(ByVal Value As Boolean)
  m_GridVisible = Value
  pnlGrid.Visible = m_GridVisible
  If m_GridVisible Then
pnlToolbar.Visible = False
  Else
pnlToolbar.Visible = True
  End If
End Set
  End Property

  Public ReadOnly Property FormMainMenu() As MenuItem
Get
  Return mnuPrincipal
End Get
  End Property

#End Region

#Region "Methods and Functions"

  Public Overridable Sub NewRecord()

Try
  m_Status = enmStatusTransaction.AddMode
  CType(grdInfo.DataSource, DataView).AllowNew = True
  CM.AddNew()
  CType(grdInfo.DataSource, DataView).AllowNew = False
  CM.Position = Me.BindingContext(grdInfo.DataSource).Count - 1
  grdInfo.Enabled = False

Catch ex As Exception
  MessageBox.Show(ex.GetBaseException.ToString, "Error in " & ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
Finally
  RaiseEvent StatusHasChanged(m_Status)
End Try
  End Sub

  Public Overridable Sub EditRecord()

Try
  m_Status = enmStatusTransaction.EditMode
  grdInfo.Enabled = False

Catch ex As Exception
  MessageBox.Show(ex.GetBaseException.ToString, "Error in " & ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
Finally
  RaiseEvent StatusHasChanged(m_Status)
End Try

  End Sub

  Public Overridable Sub DeleteRecord()
Try
  DeleteData()
Catch ex As Exception
  MessageBox.Show(ex.GetBaseException.ToString, "Error in " & ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
End Try

  End Sub

  Public Overridable Sub CancelTransaction()

Try
  If m_Status = enmStatusTransaction.AddMode Then
CM.RemoveAt(CM.Position)
  End If
  m_Status = enmStatusTransaction.NormalMode
  CM.CancelCurrentEdit()
  grdInfo.Enabled = True
Catch ex As Exception
  MessageBox.Show(ex.GetBaseException.ToString, "Error in " & ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
Finally
  RaiseEvent StatusHasChanged(m_Status)
End Try
  End Sub

  Public Overridable Sub SaveRecord()
Try
  CM.EndCurrentEdit()
  Select Case m_Status
Case Is = enmStatusTransaction.AddMode
  InsertData()
Case Is = enmStatusTransaction.EditMode
  UpdateData()
  End Select
  m_Status = enmStatusTransaction.NormalMode
  grdInfo.Enabled = True
Catch ex As Exception
  MessageBox.Show(ex.GetBaseException.ToString, "Error in " & ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
Finally
  RaiseEvent StatusHasChanged(m_Status)
End Try
  End Sub

  Public Overridable Sub Print()
m_Status = enmStatusTransaction.NormalMode
  End Sub

  Public Overridable Sub PrintPreview()
m_Status = enmStatusTransaction.NormalMode
  End Sub

  Public Sub AddGridColumn(ByVal CampoClave As String, ByVal Text As String, ByVal Width As Integer, ByVal Format As String, Optional ByVal Alineacion As HorizontalAlignment = HorizontalAlignment.Left, Optional ByVal FieldType As enmGridFieldType = enmGridFieldType.grdText)
Try
  Select Case FieldType
Case Is = enmGridFieldType.grdText
  Dim Col As New DataGridTextBoxColumn
  Col.MappingName = CampoClave
  Col.HeaderText = Text
  Col.Format = Format
  Col.Width = Width
  Col.Alignment = Alineacion
  col.TextBox.BackColor = grdInfo.BackColor
  col.ReadOnly = True
  col.NullText = "-"
  m_grdTableStyle.GridColumnStyles.Add(Col)
Case Is = enmGridFieldType.grdBoolean
  Dim Col As New DataGridBoolColumn
  Col.MappingName = CampoClave
  Col.HeaderText = Text
  Col.Width = Width
  Col.Alignment = Alineacion
  col.ReadOnly = True
  col.NullText = "-"
  m_grdTableStyle.GridColumnStyles.Add(Col)
  End Select
Catch ex As Exception
  Throw New Exception(ex.Message)
End Try

  End Sub

  Public Sub AddDataRelation(ByVal Name As String, ByVal FromTable As String, ByVal FromField As String, ByVal ToTable As String, ByVal ToField As String)

Try
  Dim FromColumn As DataColumn
  Dim ToColumn As DataColumn
  Dim dr As DataRelation
  If dsData.Tables.Count > 1 Then
FromColumn = dsData.Tables(FromTable).Columns(FromField)
ToColumn = dsData.Tables(ToTable).Columns(ToField)
dr = dsData.Relations.Add(Name, FromColumn, ToColumn)
  Else
Throw New Exception("Must have at least two Tables to add a relation.")
  End If
Catch ex As Exception
  Throw New Exception(ex.Message)
End Try

  End Sub

  Public Sub LoadDatabaseData(ByVal ParamArray Tables() As String)
Dim Cmd As SqlCommand
Dim strTables As String
Dim i As Integer

Try

  If m_DBCnn.State = ConnectionState.Closed Then
m_DBCnn.Open()
  End If

  For i = 0 To Tables.GetUpperBound(0)
strTables &= "Select * From " & Tables(i) & ";"
  Next i

  Cmd = New SqlCommand
  Cmd.CommandTimeout = 30
  Cmd.CommandText = strTables.Remove(strTables.Length - 1, 1)
  Cmd.Connection = m_DBCnn

  daData = New SqlDataAdapter(Cmd)
  dsData = New DataSet

  For i = 0 To Tables.GetUpperBound(0)
Dim n As String = IIf(i > 0, i, "").ToString.Trim
daData.TableMappings.Add("Table" & n, Tables(i))
  Next i

  daData.Fill(dsData)

  m_Tables = Tables

Catch ex As SqlException
  Throw New Exception("Can't execute the command, impossible to open database.")

Catch ex As Exception
  Throw New Exception(ex.Message)

Finally
  If Not Cmd Is Nothing Then Cmd.Dispose()
End Try

  End Sub

  Public Sub FillGrid(ByVal Table As String)
Dim i As Integer

Try

  Dim dv As DataView

  dsData.Tables(Table).BeginLoadData()
  dv = New DataView(dsData.Tables(Table))
  dsData.Tables(Table).EndLoadData()
  dv.AllowNew = False
  grdInfo.DataSource = dv

  m_grdTableStyle.AlternatingBackColor = grdInfo.AlternatingBackColor
  m_grdTableStyle.RowHeadersVisible = False
  m_grdTableStyle.MappingName = Table

  grdInfo.TableStyles.Add(m_grdTableStyle)

  m_GridTable = Table

Catch ex As Exception
  Throw New Exception(ex.Message)

End Try
  End Sub

  Private Sub Search(ByVal ColumnName As String, ByVal SearchText As String)
Dim i As Integer
Dim IntKey As Integer

Try

  CType(grdInfo.DataSource, DataView).Sort = ColumnName
  If chkExactSearch.Checked Then
drFounded = DirectCast(grdInfo.DataSource, DataView).Table.Select(ColumnName & " = '" & SearchText.ToUpper.Trim & "'")
  Else
drFounded = DirectCast(grdInfo.DataSource, DataView).Table.Select(ColumnName & " Like '%" & SearchText.ToUpper.Trim & "%'")
  End If

  drIndex = 0

  SearchNext(drIndex)
  If drFounded.GetUpperBound(0) >= 0 Then
MessageBox.Show(drFounded.Length.ToString.Trim & " Records Founded.", "Finished Search", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
lblInfo.Text = String.Format("Records Found {0}", drFounded.Length)
  Else
MessageBox.Show("The data searched was not found.", "Finished Search", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
  End If

  If drFounded.GetUpperBound(0) >= 0 Then
btnSearchNext.Visible = True
Me.AcceptButton = btnSearchNext
  Else
btnSearchNext.Visible = False
Me.AcceptButton = btnSearch
  End If

Catch ex As Exception
  Throw New Exception(ex.Message)
End Try

  End Sub

  Private Sub SearchNext(ByVal StartIndex As Integer)
Dim i As Integer
Dim intKey As Integer
Dim ColumnName As String = CType(cboGridColumn01.SelectedItem, DataGridColumnStyle).MappingName
Try
  If drIndex > drFounded.GetUpperBound(0) Then
drIndex = 0
  End If
  For i = drIndex To drFounded.GetUpperBound(0)
intKey = DirectCast(grdInfo.DataSource, DataView).Find(drFounded(i)(ColumnName))
If intKey > -1 Then
  CM.Position = intKey
  Exit For
End If
  Next
  drIndex = i + 1
  grdInfo.Focus()
Catch ex As Exception
  MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
End Try

  End Sub

  Private Sub ApplyFilters()
Dim i As Integer
Dim RowFilter As String
For i = 0 To lstFilters.Items.Count - 1
  RowFilter &= CType(lstFilters.Items(i), String) & " And "
Next
Try
  If Not RowFilter Is Nothing AndAlso RowFilter.Length > 0 Then
CType(grdInfo.DataSource, DataView).RowFilter = RowFilter.Remove(RowFilter.Length - 5, 5)
  Else
CType(grdInfo.DataSource, DataView).RowFilter = Nothing
  End If
Catch ex As Exception
  MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
End Try

  End Sub

  Private Sub SetColumnsDataSource()
If cboGridColumn01.DataSource Is Nothing Or cboGridColumn02.DataSource Is Nothing Then
  cboGridColumn01.DataSource = grdInfo.TableStyles(0).GridColumnStyles
  cboGridColumn02.DataSource = grdInfo.TableStyles(0).GridColumnStyles
  cboGridColumn01.DisplayMember = "HeaderText"
  cboGridColumn02.DisplayMember = "HeaderText"
End If
  End Sub

  Private Sub GridPositionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
lblInfo.Text = String.Format("Record {0} of {1}", (CM.Position + 1), CM.Count)
  End Sub

  Public Sub AddParameterControl(ByVal ParameterName As String, ByVal Control As Object, ByVal DefaultValue As Object, ByVal DataType As enmDataType, Optional ByVal isKey As Boolean = False)
Dim p As New ParameterControlUpdate

p.Name = ParameterName
p.ValueOwner = Control
p.DefaultValue = DefaultValue
p.DataType = DataType
p.Key = isKey

m_UpdateValues.Add(p)

  End Sub

  Private Sub InsertData()

Dim p As ParameterControlUpdate
Dim TableForInsert As String = m_grdTableStyle.MappingName
Dim Cmd As SqlCommand

Try
  Cmd = New SqlCommand
  Cmd.CommandText = "INSERT INTO " & TableForInsert & " ("
  For Each p In m_UpdateValues
Cmd.CommandText &= p.Name.Trim(Char.Parse("@")) & ", "
  Next
  Cmd.CommandText = Cmd.CommandText.Remove(Cmd.CommandText.Length - 2, 2)
  Cmd.CommandText &= ") VALUES ("
  For Each p In m_UpdateValues
Cmd.CommandText &= p.Name & ", "
  Next
  Cmd.CommandText = Cmd.CommandText.Remove(Cmd.CommandText.Length - 2, 2) & ")"

  For Each p In m_UpdateValues
Cmd.Parameters.Add(p.Name, p.GetValue)
  Next
  Cmd.Connection = m_DBCnn
  daData.InsertCommand = Cmd
  daData.Update(dsData.Tables(TableForInsert))

  Cmd.Dispose()

Catch ex As Exception
  Throw New Exception(ex.Message)
End Try
  End Sub

  Private Sub UpdateData()

Dim p As ParameterControlUpdate
Dim TableToUpdate As String = m_grdTableStyle.MappingName
Dim Cmd As SqlCommand

Try
  Cmd = New SqlCommand
  Cmd.CommandText = "UPDATE " & TableToUpdate & " SET "
  For Each p In m_UpdateValues
If Not p.Key Then
  Cmd.CommandText &= p.Name.Trim(Char.Parse("@")) & " = " & p.Name & ", "
End If
  Next
  Cmd.CommandText = Cmd.CommandText.Remove(Cmd.CommandText.Length - 2, 2)
  Cmd.CommandText &= " WHERE "
  For Each p In m_UpdateValues
If p.Key Then
  Select Case p.DataType
Case Is = enmDataType.typText, enmDataType.typDate
  Cmd.CommandText &= p.Name.Trim(Char.Parse("@")) & "='" & CType(p.GetValue, String) & "' And "
Case Is = enmDataType.typNumeric, enmDataType.typBoolean
  Cmd.CommandText &= p.Name.Trim(Char.Parse("@")) & "=" & CType(p.GetValue, String) & " And "
  End Select
End If
  Next
  Cmd.CommandText = Cmd.CommandText.Remove(Cmd.CommandText.Length - 5, 5)

  For Each p In m_UpdateValues
Cmd.Parameters.Add(p.Name, p.GetValue)
  Next
  Cmd.Connection = m_DBCnn

  daData.UpdateCommand = Cmd
  daData.Update(dsData.Tables(TableToUpdate))

  Cmd.Dispose()

Catch ex As Exception
  Throw New Exception(ex.Message)
End Try
  End Sub

  Private Sub DeleteData()

'This method can work correctly, it don't throw any error and can't
'delete the record "I Need help with it" if some one can help me I will appreciate it a lot.

Dim p As ParameterControlUpdate
Dim TableForDelete As String = m_grdTableStyle.MappingName
Dim Cmd As SqlCommand

Try

  Cmd = New SqlCommand
  Cmd.CommandText = "Delete From " & TableForDelete & " "
  Cmd.CommandText &= "WHERE "
  For Each p In m_UpdateValues
If p.Key Then
  Cmd.CommandText &= p.Name.Trim(Char.Parse("@")) & " = " & p.Name & " And "
End If
  Next
  Cmd.CommandText = Cmd.CommandText.Remove(Cmd.CommandText.Length - 5, 5)

  For Each p In m_UpdateValues
If p.Key Then
  Cmd.Parameters.Add(p.Name, p.GetValue)
End If
  Next

  Cmd.Connection = m_DBCnn
  daData.DeleteCommand = Cmd
  daData.Update(dsData.Tables(TableForDelete))

  Cmd.Dispose()

Catch ex As Exception
  Throw New Exception(ex.Message)
End Try
  End Sub

#End Region

  Private Sub frmBaseCatalogo_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Me.Status <> enmStatusTransaction.NormalMode Then
  If MessageBox.Show("Currently performing some kind of action. Are you sure you want to leave this form?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) = DialogResult.No Then
e.Cancel = True
  Else
If Not CM Is Nothing Then
  RemoveHandler Me.BindingContext(grdInfo.DataSource).PositionChanged, AddressOf GridPositionChanged
End If
  End If
End If
  End Sub

  Private Sub tbrTools_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles tbrTools.ButtonClick
Select Case e.Button.Tag
  Case Is = "Top"
Me.BindingContext(grdInfo.DataSource).Position = 0
  Case Is = "Prev"
If Me.BindingContext(grdInfo.DataSource).Position > 0 Then
  Me.BindingContext(grdInfo.DataSource).Position -= 1
End If
  Case Is = "Go"
mnuGoTo_Click(Nothing, Nothing)
  Case Is = "Next"
If Me.BindingContext(grdInfo.DataSource).Position < (Me.BindingContext(grdInfo.DataSource).Count - 1) Then
  Me.BindingContext(grdInfo.DataSource).Position += 1
End If
  Case Is = "Bottom"
Me.BindingContext(grdInfo.DataSource).Position = Me.BindingContext(grdInfo.DataSource).Count - 1

  Case Is = "Find"
mnuSearch_Click(Nothing, Nothing)

  Case Is = "Filter"
mnuFilter_Click(Nothing, Nothing)

End Select
grdInfo.Focus()
  End Sub

  Private Sub btnCloseSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCloseSearch.Click
tbrTools.Buttons(6).Pushed = False
pnlSearch.Visible = False
Me.AcceptButton = OldAcceptButton
  End Sub

  Private Sub btnCloseFilters_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCloseFilters.Click
tbrTools.Buttons(7).Pushed = False
pnlFilter.Visible = False
Me.AcceptButton = OldAcceptButton
  End Sub

  Private Sub btnCloseGoto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCloseGoto.Click
tbrTools.Buttons(2).Pushed = False
pnlGotoRecord.Visible = False
Me.AcceptButton = OldAcceptButton
  End Sub

  Private Sub Customers_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
If CM Is Nothing Then
  AddHandler Me.BindingContext(grdInfo.DataSource).PositionChanged, AddressOf GridPositionChanged
  CM = CType(Me.BindingContext(grdInfo.DataSource), CurrencyManager)
End If
GridPositionChanged(sender, e)
  End Sub

  Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Try
  If txtToSearch.Text = "" Then
MessageBox.Show("Text to search is needed.", "Invalid Data", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
txtToSearch.Focus()
  Else
Dim ColumnName As String = CType(cboGridColumn01.SelectedItem, DataGridColumnStyle).MappingName
Dim SearchText As String = txtToSearch.Text
Search(ColumnName, SearchText)
  End If
Catch ex As Exception
  MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
End Try
  End Sub

  Private Sub btnGotoRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGotoRecord.Click
Try
  If Integer.Parse(txtNumRecord.Text) < Me.BindingContext(grdInfo.DataSource).Count - 1 Or Integer.Parse(txtNumRecord.Text) > Me.BindingContext(grdInfo.DataSource).Count - 1 Then
CM.Position = Integer.Parse(txtNumRecord.Text) - 1
  End If
  grdInfo.Focus()

Catch ex As Exception
  Throw New Exception(ex.Message)
End Try
  End Sub

  Private Sub btnSearchNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchNext.Click
SearchNext(drIndex)
  End Sub

  Private Sub btnAddFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddFilter.Click
Dim Criteria As String = "'" & txtCriteria.Text & "'"
If Criteria.Length > 0 Then
  If IsNumeric(txtCriteria.Text) Then
Criteria = txtCriteria.Text
  End If
  If cboOperator.SelectedIndex = 6 Then
Criteria = "Like '%" & txtCriteria.Text & "%'"
lstFilters.Items.Add(CType(cboGridColumn02.SelectedItem, DataGridColumnStyle).MappingName & " " & Criteria)
  Else
lstFilters.Items.Add(CType(cboGridColumn02.SelectedItem, DataGridColumnStyle).MappingName.ToString & " " & CType(cboOperator.SelectedItem, String) & " " & Criteria)
  End If
  cboGridColumn02.SelectedIndex = 0
  cboOperator.SelectedIndex = 0
  txtCriteria.Text = Nothing
End If
  End Sub

  Private Sub btnApplyFilters_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApplyFilters.Click
If CType(btnApplyFilters.Tag, Byte) = 1 Then 'if Tag = 1 then Filter was used
  btnApplyFilters.Tag = 0
  ApplyFilters()
Else
  btnApplyFilters.Tag = 1
  ApplyFilters()
End If
  End Sub

  Private Sub btnRemoveFilters_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveFilters.Click
Dim i As Integer
If lstFilters.Items.Count > -1 Then
  For i = lstFilters.Items.Count - 1 To i Step -1
If lstFilters.GetSelected(i) = True Then
  lstFilters.Items.RemoveAt(i)
End If
  Next
  btnApplyFilters.PerformClick()
End If
  End Sub

  Private Sub lstFilters_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstFilters.KeyDown
If e.KeyData = Keys.Delete Then
  lstFilters.Items.RemoveAt(lstFilters.SelectedIndex)
  btnApplyFilters.PerformClick()
End If
  End Sub

  Private Sub mnuNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNew.Click
Me.NewRecord()
  End Sub

  Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click
Me.SaveRecord()
  End Sub

  Private Sub mnuDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuDelete.Click
Me.DeleteRecord()
  End Sub

  Private Sub mnuCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCancel.Click
Me.CancelTransaction()
  End Sub

  Private Sub mnuClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClose.Click
Me.Close()
  End Sub

  Private Sub mnuGoTo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuGoTo.Click
pnlGotoRecord.Visible = Not pnlGotoRecord.Visible
OldAcceptButton = Me.AcceptButton
Me.AcceptButton = btnGotoRecord
  End Sub

  Private Sub mnuSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSearch.Click
SetColumnsDataSource()
pnlSearch.Visible = Not pnlSearch.Visible
OldAcceptButton = Me.AcceptButton
Me.AcceptButton = btnSearch
  End Sub

  Private Sub mnuEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEdit.Click
Me.EditRecord()
  End Sub

  Private Sub mnuFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuFilter.Click
SetColumnsDataSource()
pnlFilter.Visible = Not pnlFilter.Visible
OldAcceptButton = Me.AcceptButton
Me.AcceptButton = btnApplyFilters
  End Sub

  Private Sub Splitter1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Splitter1.MouseEnter
Splitter1.BackColor = Color.FromKnownColor(KnownColor.ControlDark)
  End Sub

  Private Sub Splitter1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Splitter1.MouseLeave
Splitter1.BackColor = Color.FromKnownColor(KnownColor.Control)
  End Sub

  Private Sub grdInfo_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdInfo.MouseDown
If e.Button = MouseButtons.Right Then
  If m_grdContextMenu Is Nothing Then
m_grdContextMenu = New ContextMenu

m_grdContextMenu.MenuItems.Add(mnuView.CloneMenu)
  End If
  grdInfo.ContextMenu = m_grdContextMenu
End If
  End Sub

  Private Sub mnuViewGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewGrid.Click
mnuViewGrid.Checked = Not mnuViewGrid.Checked
pnlControles.Visible = mnuViewGrid.Checked
Splitter1.Visible = mnuViewGrid.Checked
  End Sub

  Private Sub mnuViewNavTool_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewNavTool.Click
mnuViewNavTool.Checked = Not mnuViewNavTool.Checked
pnlToolbar.Visible = mnuViewNavTool.Checked
pnlInfo.Visible = mnuViewNavTool.Checked
  End Sub

  Private Sub grdInfo_EnabledChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdInfo.EnabledChanged
tbrTools.Enabled = grdInfo.Enabled
  End Sub

  Private Shared Sub daData_RowUpdated(ByVal sender As Object, ByVal e As System.Data.SqlClient.SqlRowUpdatedEventArgs) Handles daData.RowUpdated
MessageBox.Show("Rows Affected :" & e.RecordsAffected.ToString, e.Status.ToString)
  End Sub

End Class

Project Homepage: