📄 frmmain.vb
字号:
'~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~
'Author: N.Abdul Rasheed
'Date : 29 Jan 2004
'Description: This is the main class used to pull data from SQL server
' and list it in the list view
'~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~ ~_~
Imports System.Data.SqlServerCe
Imports System.Data.SqlServerCe.SqlCeException
Imports System.Reflection
Imports System.io
Imports System.text
Public Class frmMain
Inherits System.Windows.Forms.Form
Friend WithEvents lsvFavList As System.Windows.Forms.ListView
Dim oDBConfig As New DatabaseConfig '//To get the configuration information
Dim oMyFav As New clsMyFavourite '//All the Quries related to this form will be placed here
Dim oDBAccess As New DBAccess '//Database Access like connection and execution will be placed here
Dim oUtil As New Utility '//Additional functions will be placed here
#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)
MyBase.Dispose(disposing)
End Sub
'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 MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents mnuSyncHost As System.Windows.Forms.MenuItem
Friend WithEvents mnuUpdateHost As System.Windows.Forms.MenuItem
Friend WithEvents mnuExit As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents mnuNew As System.Windows.Forms.MenuItem
Friend WithEvents mnuEdit As System.Windows.Forms.MenuItem
Friend WithEvents mnuDelete As System.Windows.Forms.MenuItem
Friend WithEvents mnuView As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Private Sub InitializeComponent()
Me.lsvFavList = New System.Windows.Forms.ListView
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.mnuSyncHost = New System.Windows.Forms.MenuItem
Me.mnuUpdateHost = New System.Windows.Forms.MenuItem
Me.mnuExit = New System.Windows.Forms.MenuItem
Me.MenuItem2 = 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.mnuView = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
'
'lsvFavList
'
Me.lsvFavList.FullRowSelect = True
Me.lsvFavList.Location = New System.Drawing.Point(4, 0)
Me.lsvFavList.Size = New System.Drawing.Size(232, 256)
Me.lsvFavList.View = System.Windows.Forms.View.Details
'
'MainMenu1
'
Me.MainMenu1.MenuItems.Add(Me.MenuItem1)
Me.MainMenu1.MenuItems.Add(Me.MenuItem2)
'
'MenuItem1
'
Me.MenuItem1.MenuItems.Add(Me.mnuSyncHost)
Me.MenuItem1.MenuItems.Add(Me.mnuUpdateHost)
Me.MenuItem1.MenuItems.Add(Me.mnuExit)
Me.MenuItem1.Text = "File"
'
'mnuSyncHost
'
Me.mnuSyncHost.Text = "Sync To Host"
'
'mnuUpdateHost
'
Me.mnuUpdateHost.Text = "Sync From Host"
'
'mnuExit
'
Me.mnuExit.Text = "Exit"
'
'MenuItem2
'
Me.MenuItem2.MenuItems.Add(Me.mnuNew)
Me.MenuItem2.MenuItems.Add(Me.mnuEdit)
Me.MenuItem2.MenuItems.Add(Me.mnuDelete)
Me.MenuItem2.MenuItems.Add(Me.MenuItem3)
Me.MenuItem2.MenuItems.Add(Me.mnuView)
Me.MenuItem2.Text = "Transaction"
'
'mnuNew
'
Me.mnuNew.Text = "New"
'
'mnuEdit
'
Me.mnuEdit.Text = "Edit"
'
'mnuDelete
'
Me.mnuDelete.Text = "Delete"
'
'mnuView
'
Me.mnuView.Text = "View"
'
'MenuItem3
'
Me.MenuItem3.Text = "-"
'
'frmMain
'
Me.ClientSize = New System.Drawing.Size(240, 263)
Me.Controls.Add(Me.lsvFavList)
Me.Menu = Me.MainMenu1
Me.Text = "My Favourite"
End Sub
#End Region
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Initialise the controls
InitControls()
'Check the database is available in Pocket PC (SQLCE) if not probpt the user to sync to the Host database
If Not File.Exists(oDBConfig.LocalDBLocation & oDBConfig.LocalDBName) Then
MsgBox("Database Dose not exist... sync with Host", MsgBoxStyle.Information)
MainMenu1.MenuItems(1).Enabled = False
Exit Sub
Else
DataView()
End If
End Sub
#Region "File Menu"
'To Handle all file Menu events
Private Sub mnuSyncHost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSyncHost.Click
Dim Reader As SqlCeDataReader
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Try
'Check the Database is available in Pocket PC other wise create it
oDBAccess.CreateDB()
'PopulateData()
Reader = oDBAccess.SyncHost
DataView()
Reader = Nothing
MainMenu1.MenuItems(1).Enabled = True
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
Catch err As SqlCeException
MsgBox(oUtil.ComposeSqlErrorMessage(err))
If File.Exists(oDBConfig.LocalDBLocation & oDBConfig.LocalDBName) Then
File.Delete(oDBConfig.LocalDBLocation & oDBConfig.LocalDBName)
End If
Finally
End Try
End Sub
Private Sub mnuUpdateHost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuUpdateHost.Click
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
oDBAccess.UpdateHost()
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
End Sub
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
Application.Exit()
End Sub
#End Region
#Region "Transaction Menu"
'To Handle all transaction Menu events
Private Sub mnuNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNew.Click
'//To add new item or transaction
Dim oObj As New frmFavourite
oObj.Init(1, -1)
oObj = Nothing
Me.Hide()
End Sub
Private Sub mnuEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEdit.Click
'//To Edit an item or transaction
Dim oObj As New frmFavourite
Dim iId As Integer
Dim i As Integer
Try
i = lsvFavList.SelectedIndices.Item(0)
Catch ex As Exception
MsgBox("Selected any item from the list", MsgBoxStyle.Exclamation)
Return
End Try
iId = lsvFavList.Items.Item(i).Text
oObj.Init(2, iId)
oObj = Nothing
Me.Hide()
End Sub
Private Sub mnuDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDelete.Click
'//To delete a selected item
Dim oObj As New frmFavourite
Dim iId As Integer
Dim i As Integer
Try
i = lsvFavList.SelectedIndices.Item(0)
Catch ex As Exception
MsgBox("Selected any item from the list", MsgBoxStyle.Exclamation)
Return
End Try
iId = lsvFavList.Items.Item(i).Text
oObj.Init(3, iId)
oObj = Nothing
Me.Hide()
End Sub
Private Sub mnuView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuView.Click
'//To view the information about the selected item
Dim oObj As New frmFavourite
Dim iId As Integer
Dim i As Integer
Try
i = lsvFavList.SelectedIndices.Item(0)
Catch ex As Exception
MsgBox("Selected any item from the list", MsgBoxStyle.Exclamation)
Return
End Try
iId = lsvFavList.Items.Item(i).Text
oObj.Init(4, iId)
oObj = Nothing
Me.Hide()
End Sub
#End Region
#Region "General function"
'Common Functions used in the form
Private Sub InitControls()
lsvFavList.Clear()
lsvFavList.Columns.Add("Id", 0, _
HorizontalAlignment.Left)
lsvFavList.Columns.Add("Favourite", 100, _
HorizontalAlignment.Left)
lsvFavList.Columns.Add("URL", 100, _
HorizontalAlignment.Left)
lsvFavList.Columns.Add("Updated On", 100, _
HorizontalAlignment.Left)
End Sub
Public Sub DataView()
Dim Reader As SqlCeDataReader
Try
Reader = oMyFav.Request("LIST")
'Finally, add the record to the ListView control:
InitControls()
While Reader.Read
Dim ls As New ListViewItem(Reader.Item("Id").ToString)
ls.SubItems.Add(Trim(Reader.Item("Caption").ToString))
ls.SubItems.Add(Trim(Reader.Item("URL").ToString))
ls.SubItems.Add(FormatDateTime(Reader.Item("UpdatedOn"), DateFormat.ShortDate))
lsvFavList.Items.Add(ls)
End While
Reader.Close()
Catch err As Exception
MsgBox(err.ToString)
Finally
End Try
End Sub
#End Region
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -