⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 创建Pocket PC应用程序BuildingApplicationsforthePocketPCv11_Demo.zip
💻 VB
字号:
Imports System.Data.SqlServerCe

Public Class Form1
    Inherits System.Windows.Forms.Form
    Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
    Friend WithEvents Registration As System.Windows.Forms.TabPage
    Friend WithEvents FlightDetail As System.Windows.Forms.TabPage
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu

    Private cn As SqlCeConnection
    Private local_DatabaseFile As String
    Private local_ConnString As String

#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 Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents txtDestination As System.Windows.Forms.TextBox
    Friend WithEvents txtDestinationStatus As System.Windows.Forms.TextBox
    Friend WithEvents txtFlownMiles As System.Windows.Forms.TextBox
    Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.TabControl1 = New System.Windows.Forms.TabControl
        Me.Registration = New System.Windows.Forms.TabPage
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.FlightDetail = New System.Windows.Forms.TabPage
        Me.txtFlownMiles = New System.Windows.Forms.TextBox
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.txtDestination = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.txtDestinationStatus = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        '
        'TabControl1
        '
        Me.TabControl1.Controls.Add(Me.Registration)
        Me.TabControl1.Controls.Add(Me.FlightDetail)
        Me.TabControl1.SelectedIndex = 0
        Me.TabControl1.Size = New System.Drawing.Size(240, 264)
        '
        'Registration
        '
        Me.Registration.Controls.Add(Me.Button1)
        Me.Registration.Controls.Add(Me.TextBox1)
        Me.Registration.Controls.Add(Me.Label1)
        Me.Registration.Controls.Add(Me.PictureBox1)
        Me.Registration.Location = New System.Drawing.Point(4, 4)
        Me.Registration.Size = New System.Drawing.Size(232, 238)
        Me.Registration.Text = "注册"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(56, 176)
        Me.Button1.Size = New System.Drawing.Size(96, 24)
        Me.Button1.Text = "查找成员"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(120, 136)
        Me.TextBox1.Size = New System.Drawing.Size(104, 20)
        Me.TextBox1.Text = "3"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 136)
        Me.Label1.Text = "成员数量:"
        '
        'PictureBox1
        '
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
        Me.PictureBox1.Size = New System.Drawing.Size(232, 120)
        '
        'FlightDetail
        '
        Me.FlightDetail.Controls.Add(Me.txtFlownMiles)
        Me.FlightDetail.Controls.Add(Me.ListView1)
        Me.FlightDetail.Controls.Add(Me.txtDestination)
        Me.FlightDetail.Controls.Add(Me.Label2)
        Me.FlightDetail.Controls.Add(Me.txtDestinationStatus)
        Me.FlightDetail.Controls.Add(Me.Label3)
        Me.FlightDetail.Controls.Add(Me.Label4)
        Me.FlightDetail.Location = New System.Drawing.Point(4, 4)
        Me.FlightDetail.Size = New System.Drawing.Size(232, 238)
        Me.FlightDetail.Text = "航班信息"
        '
        'txtFlownMiles
        '
        Me.txtFlownMiles.Location = New System.Drawing.Point(120, 200)
        Me.txtFlownMiles.Size = New System.Drawing.Size(96, 20)
        Me.txtFlownMiles.Text = ""
        '
        'ListView1
        '
        Me.ListView1.Location = New System.Drawing.Point(16, 128)
        Me.ListView1.Size = New System.Drawing.Size(200, 64)
        '
        'txtDestination
        '
        Me.txtDestination.Location = New System.Drawing.Point(8, 40)
        Me.txtDestination.Size = New System.Drawing.Size(216, 20)
        Me.txtDestination.Text = ""
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 8)
        Me.Label2.Size = New System.Drawing.Size(216, 24)
        Me.Label2.Text = "今天目的地"
        '
        'txtDestinationStatus
        '
        Me.txtDestinationStatus.Location = New System.Drawing.Point(8, 72)
        Me.txtDestinationStatus.Size = New System.Drawing.Size(216, 20)
        Me.txtDestinationStatus.Text = ""
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(8, 104)
        Me.Label3.Size = New System.Drawing.Size(216, 24)
        Me.Label3.Text = "成员详细信息"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(8, 200)
        Me.Label4.Size = New System.Drawing.Size(112, 24)
        Me.Label4.Text = "里程积分合计:"
        '
        'Form1
        '
        Me.Controls.Add(Me.TabControl1)
        Me.Menu = Me.MainMenu1
        Me.MinimizeBox = False
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Click

    End Sub

    Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
        'Reference the SIP control
        Dim oSIP As New Microsoft.WindowsCE.Forms.InputPanel
        ' Raise SIP
        oSIP.Enabled = True

    End Sub

    Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
        'Reference the SIP control
        Dim oSIP As New Microsoft.WindowsCE.Forms.InputPanel
        ' Lower SIP
        oSIP.Enabled = False
    End Sub

    Sub CheckDB()
        Try
            If Not System.IO.File.Exists _
            ("\my documents\SQLCECFLab.sdf") Then
                'Create SQL Server CE Engine object 
                Dim en As New SqlCeEngine _
                ("data source=\my documents\SQLCECFLab.sdf")
                'Create blank database
                en.CreateDatabase()
                Synch()
            End If
        Catch err As SqlCeException
            ShowErrors(err)
        Catch err As Exception
            MsgBox("There was an error: " & err.ToString())
        End Try
    End Sub

    Sub Synch()
        Try
            ' create merge replication object
            Dim cerepl As New SqlCeReplication
            With cerepl
                .Publisher = "SQLCESDELab"
                .PublisherDatabase = "CFLab"
                .PublisherLogin = "sa"
                .PublisherPassword = "password"
                .Publication = "CFLab"
                .Subscriber = "SQLCENETCFLab"
                .SubscriberConnectionString = _
                "Provider=Microsoft.SQLServer.OLEDB.CE.2.0;Data Source=\my documents\SQLCECFLab.sdf"
                .InternetUrl = _
                "http://msft-maqi/sqlce/sscesa20.dll"
                'Bring down initial subscription
                .Synchronize()
            End With
        Catch err As SqlCeException
            ShowErrors(err)
        End Try
    End Sub

    Sub ErrorDisplay(ByRef err As SqlCeException)
        MessageBox.Show(err.ToString())
    End Sub

    Sub ShowErrors(ByVal expSQL As SqlCeException)
        Dim errSQL As SqlCeError
        For Each errSQL In expSQL.Errors
            MsgBox(errSQL.NativeError.ToString() & " " & _
            errSQL.Source & " " & errSQL.HResult.ToString() & " " & _
            errSQL.Message)
        Next
    End Sub

    Sub Connect()
        CheckDB()
        Synch()

        local_DatabaseFile = "\my documents\SQLCECFLab.sdf"
        'Construct the local connecting string.
        local_ConnString = "Data Source= " & local_DatabaseFile
        cn = New SqlCeConnection(local_ConnString)
    End Sub

    Sub Disconnect()
        If cn.State = ConnectionState.Open Then
            cn.Close()
        End If
    End Sub

    Function CheckMembershipDatabase(ByVal strMembershipNumber)
        Dim strDestination As String
        Dim lngMiles As Long
        Dim dtmDate As Date
        Dim strSQL As String
        Dim dr As SqlCeDataReader
        'connect to the local database
        Connect()

        'This SQL statement checks field f1 for the value passed into the function
        strSQL = "SELECT M.MemberId, MemberName, Destination, FlightStatus, ArrivalDate, FlownMiles FROM MemberShipData M INNER JOIN FlightData F ON F.MemberId = M.MemberId AND M.MemberId = "
        strSQL &= strMembershipNumber & ";"

        Try
            Dim cmd As New SqlServerCe.SqlCeCommand(strSQL, cn)
            dr = cmd.ExecuteReader()
        Catch err As SqlCeException
            ShowErrors(err)
        Catch err As Exception
            MsgBox("There was an error: " & err.ToString())
        End Try
        If dr.Read = True Then
            'we have data, fill the text boxes and also the listview

            'rows in database, return true
            CheckMembershipDatabase = True
            'rest the listview
            Me.ListView1.Clear()
            ' Set the view to show details.
            ListView1.View = View.Details
            ' Display grid lines.
            'Set up the columns of the listview
            ListView1.Columns.Add("Date     ", -2, HorizontalAlignment.Left)
            ListView1.Columns.Add("Destination", -2, HorizontalAlignment.Left)
            ListView1.Columns.Add("Miles    ", -2, HorizontalAlignment.Left)

            'Load Text boxes
            txtDestination.Text = dr.Item("Destination")
            txtDestinationStatus.Text = dr.Item("FlightStatus")

            Dim iFlownMiles As Integer = dr.Item("FlownMiles")
            strDestination = dr.Item("Destination")
            lngMiles = dr.Item("FlownMiles")
            dtmDate = dr.Item("ArrivalDate")

            Dim item1 As New ListViewItem(dtmDate)
            Dim subItem1 As New ListViewItem.ListViewSubItem
            Dim subItem2 As New ListViewItem.ListViewSubItem

            subItem1.Text = strDestination
            subItem2.Text = lngMiles

            item1.SubItems.Add(subItem1)
            item1.SubItems.Add(subItem2)
            ListView1.Items.Add(item1)

            item1 = Nothing
            subItem1 = Nothing
            subItem2 = Nothing
            While dr.Read()
                iFlownMiles += dr.Item("FlownMiles")
                strDestination = dr.Item("Destination")
                lngMiles = dr.Item("FlownMiles")
                dtmDate = dr.Item("ArrivalDate")

                item1 = New ListViewItem(dtmDate)
                subItem1 = New ListViewItem.ListViewSubItem
                subItem2 = New ListViewItem.ListViewSubItem

                subItem1.Text = strDestination
                subItem2.Text = lngMiles

                item1.SubItems.Add(subItem1)
                item1.SubItems.Add(subItem2)
                ListView1.Items.Add(item1)

                item1 = Nothing
                subItem1 = Nothing
                subItem2 = Nothing
            End While
            txtFlownMiles.Text = System.Convert.ToString(iFlownMiles)
        Else
            'no rows in the database
            CheckMembershipDatabase = False
        End If
        dr.Close()
        Disconnect()
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CheckMembershipDatabase(TextBox1.Text)
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -