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

📄 formmain.vb

📁 Programming the .NET Compact Framework with vb 源代码
💻 VB
字号:
' -----------------------------------------------------------------------------
' Code from _Programming the .NET Compact Framework with VB_
' and _Programming the .NET Compact Framework with C#_
' (c) Copyright 2002-2004 Paul Yao and David Durant. 
' All rights reserved.
' -----------------------------------------------------------------------------

Imports System
Imports System.IO
Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Windows.Forms
Imports UtilData

Public Class FormMain
   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()

      '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 MenuMain As MainMenu
   Friend WithEvents mitemFile As MenuItem
   Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
   Friend WithEvents mitemBuildDS As System.Windows.Forms.MenuItem
   Friend WithEvents mitemExit As System.Windows.Forms.MenuItem
   Friend WithEvents dgridParent As System.Windows.Forms.DataGrid
   Friend WithEvents dgridChild As System.Windows.Forms.DataGrid
   Friend WithEvents mitemWriteXML As System.Windows.Forms.MenuItem
   Private Sub InitializeComponent()
      Me.MenuMain = New System.Windows.Forms.MainMenu
      Me.mitemFile = New System.Windows.Forms.MenuItem
      Me.mitemExit = New System.Windows.Forms.MenuItem
      Me.MenuItem1 = New System.Windows.Forms.MenuItem
      Me.mitemBuildDS = New System.Windows.Forms.MenuItem
      Me.mitemWriteXML = New System.Windows.Forms.MenuItem
      Me.dgridParent = New System.Windows.Forms.DataGrid
      Me.dgridChild = New System.Windows.Forms.DataGrid
      '
      'MenuMain
      '
      Me.MenuMain.MenuItems.Add(Me.mitemFile)
      Me.MenuMain.MenuItems.Add(Me.MenuItem1)
      '
      'mitemFile
      '
      Me.mitemFile.MenuItems.Add(Me.mitemExit)
      Me.mitemFile.Text = "File"
      '
      'mitemExit
      '
      Me.mitemExit.Text = "Exit"
      '
      'MenuItem1
      '
      Me.MenuItem1.MenuItems.Add(Me.mitemBuildDS)
      Me.MenuItem1.MenuItems.Add(Me.mitemWriteXML)
      Me.MenuItem1.Text = "DataSet"
      '
      'mitemBuildDS
      '
      Me.mitemBuildDS.Text = "Build DS"
      '
      'mitemWriteXML
      '
      Me.mitemWriteXML.Text = "Write as XML"
      '
      'dgridParent
      '
      Me.dgridParent.Size = New System.Drawing.Size(240, 104)
      Me.dgridParent.Text = "Parent"
      '
      'dgridChild
      '
      Me.dgridChild.Location = New System.Drawing.Point(0, 160)
      Me.dgridChild.Size = New System.Drawing.Size(240, 104)
      Me.dgridChild.Text = "Child"
      '
      'FormMain
      '
      Me.Controls.Add(Me.dgridChild)
      Me.Controls.Add(Me.dgridParent)
      Me.Menu = Me.MenuMain
      Me.MinimizeBox = False
      Me.Text = "FormMain"

   End Sub

#End Region

   '  The dataset
   Private dsetDB As DataSet

   '  The database file.
   Private strDBFile As String = "My Documents\ourProduceCo.sdf"

   '  The connection string.
   Private strConn As String = "Data Source=" & strDBFile

   '  The XML file.
   Private strXMLFile As String = "My Documents\ourProduceCo.xml"


   Private Sub FormMain_Load(ByVal sender As Object, _
                             ByVal e As EventArgs _
                             ) _
                             Handles MyBase.Load

      '  Let the form present itself.
      Application.DoEvents()

      '  Ensure that the database exists.
      If Not File.Exists(strDBFile) Then
         MessageBox.Show( _
               "Database not found.  Run the CreateDatabase " & _
               "program for this chapter first.  Then run " & _
               "this program.")
      End If
   End Sub


   Private Sub mitemBuildDS_Click(ByVal sender As Object, _
                             ByVal e As EventArgs _
                             ) _
                             Handles mitemBuildDS.Click

      '  Build the DataSet from the Database.
      dsetDB = UtilSqlCE.BuildDataSet(strDBFile)

      '  Display the first table in the Parent datagrid control.
      With Me.dgridParent
         .DataSource = dsetDB.Tables(0)
         .Text = dsetDB.Tables(0).TableName
      End With
   End Sub

   Private Sub mitemWriteXML_Click(ByVal sender As Object, _
                             ByVal e As EventArgs _
                             ) _
                             Handles mitemWriteXML.Click

      '  Write the dataset as XML to a file.
      If File.Exists(strXMLFile) Then File.Delete(strXMLFile)
      dsetDB.WriteXml(strXMLFile)
      MessageBox.Show( _
               "XML File written to 'My Documents' directory")
   End Sub

   Private Sub mitemExit_Click(ByVal sender As Object, _
                             ByVal e As EventArgs _
                             ) _
                             Handles mitemExit.Click
      Application.Exit()
   End Sub

End Class

⌨️ 快捷键说明

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