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

📄 wchange.vb

📁 vb。net 2003数据库设计整套源代码
💻 VB
字号:
Public Class wchange
    Inherits System.Windows.Forms.Form

    Dim Mydb As DAO.Database
    '定义一个DAO.Database数据库对象
    Dim MyWs As DAO.Workspace
    '定义一个工作空间DAO.Workspace
    Dim MySql As String
    '定义一个字符串用来存放SQL查询语言
    Dim Myrec As DAO.Recordset
    '定义一个数据项DAO.Recordset
    Dim de As DAO.DBEngine = New DAO.DBEngine()
    '定义一个数据引擎DAO.DBEngine()
    Public Function OpenDb() As Short
        '定义一个数据打开函数
        Dim dbstr As String
        '定义一个字符串来存放数据库所在目录
        dbstr = Application.StartupPath & "\depot.mdb"
        '取得数据库所在目录
        MyWs = de.Workspaces(0)
        '建立一个工作空间
        Mydb = MyWs.OpenDatabase(dbstr, False, False)
        '打开数据库存放于Mydb
        dbstr = "select * from worker"
        '设置SQL打开方式
        Myrec = Mydb.OpenRecordset(dbstr, DAO.RecordsetTypeEnum.dbOpenDynaset)
        '打开数据项
    End Function

#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
        Dim myResult As Short
        myResult = OpenDb()

    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 txtsno As System.Windows.Forms.TextBox
    Friend WithEvents txtage As System.Windows.Forms.TextBox
    Friend WithEvents txttitle As System.Windows.Forms.TextBox
    Friend WithEvents txtwno As System.Windows.Forms.TextBox
    Friend WithEvents txtwname As System.Windows.Forms.TextBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents butdel As System.Windows.Forms.Button
    Friend WithEvents btadd As System.Windows.Forms.Button
    Friend WithEvents btclose As System.Windows.Forms.Button
    Friend WithEvents btedit As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.txtsno = New System.Windows.Forms.TextBox()
        Me.txtage = New System.Windows.Forms.TextBox()
        Me.txttitle = New System.Windows.Forms.TextBox()
        Me.txtwno = New System.Windows.Forms.TextBox()
        Me.txtwname = New System.Windows.Forms.TextBox()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.butdel = New System.Windows.Forms.Button()
        Me.btadd = New System.Windows.Forms.Button()
        Me.btedit = New System.Windows.Forms.Button()
        Me.btclose = New System.Windows.Forms.Button()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        '
        'txtsno
        '
        Me.txtsno.Location = New System.Drawing.Point(80, 104)
        Me.txtsno.Name = "txtsno"
        Me.txtsno.Size = New System.Drawing.Size(80, 21)
        Me.txtsno.TabIndex = 20
        Me.txtsno.Text = ""
        '
        'txtage
        '
        Me.txtage.Location = New System.Drawing.Point(224, 64)
        Me.txtage.Name = "txtage"
        Me.txtage.Size = New System.Drawing.Size(80, 21)
        Me.txtage.TabIndex = 19
        Me.txtage.Text = ""
        '
        'txttitle
        '
        Me.txttitle.Location = New System.Drawing.Point(80, 64)
        Me.txttitle.Name = "txttitle"
        Me.txttitle.Size = New System.Drawing.Size(80, 21)
        Me.txttitle.TabIndex = 18
        Me.txttitle.Text = ""
        '
        'txtwno
        '
        Me.txtwno.Location = New System.Drawing.Point(224, 16)
        Me.txtwno.Name = "txtwno"
        Me.txtwno.Size = New System.Drawing.Size(80, 21)
        Me.txtwno.TabIndex = 17
        Me.txtwno.Text = ""
        '
        'txtwname
        '
        Me.txtwname.Location = New System.Drawing.Point(80, 16)
        Me.txtwname.Name = "txtwname"
        Me.txtwname.Size = New System.Drawing.Size(80, 21)
        Me.txtwname.TabIndex = 16
        Me.txtwname.Text = ""
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(32, 64)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(40, 21)
        Me.Label6.TabIndex = 15
        Me.Label6.Text = "职称"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(176, 64)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(80, 23)
        Me.Label5.TabIndex = 14
        Me.Label5.Text = "年龄"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(16, 104)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(56, 21)
        Me.Label4.TabIndex = 13
        Me.Label4.Text = "所在仓库"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(176, 16)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(72, 23)
        Me.Label2.TabIndex = 12
        Me.Label2.Text = "工号"
        '
        'Label1
        '
        Me.Label1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.Label1.Location = New System.Drawing.Point(32, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(0, 21)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "姓名"
        '
        'butdel
        '
        Me.butdel.Location = New System.Drawing.Point(16, 136)
        Me.butdel.Name = "butdel"
        Me.butdel.Size = New System.Drawing.Size(64, 23)
        Me.butdel.TabIndex = 21
        Me.butdel.Text = "删除"
        '
        'btadd
        '
        Me.btadd.Location = New System.Drawing.Point(94, 136)
        Me.btadd.Name = "btadd"
        Me.btadd.Size = New System.Drawing.Size(64, 23)
        Me.btadd.TabIndex = 22
        Me.btadd.Text = "添加"
        '
        'btedit
        '
        Me.btedit.Location = New System.Drawing.Point(172, 136)
        Me.btedit.Name = "btedit"
        Me.btedit.Size = New System.Drawing.Size(60, 23)
        Me.btedit.TabIndex = 23
        Me.btedit.Text = "修改"
        '
        'btclose
        '
        Me.btclose.Location = New System.Drawing.Point(246, 136)
        Me.btclose.Name = "btclose"
        Me.btclose.Size = New System.Drawing.Size(58, 23)
        Me.btclose.TabIndex = 24
        Me.btclose.Text = "退出"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(32, 16)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(40, 21)
        Me.Label3.TabIndex = 25
        Me.Label3.Text = "姓名"
        '
        'wchange
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.Window
        Me.ClientSize = New System.Drawing.Size(320, 181)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.btclose, Me.btedit, Me.btadd, Me.butdel, Me.txtsno, Me.txtage, Me.txttitle, Me.txtwno, Me.txtwname, Me.Label6, Me.Label5, Me.Label4, Me.Label2, Me.Label1})
        Me.Name = "wchange"
        Me.Text = "人员变动"
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Sub btadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btadd.Click
        Dim dbstr As String
        '建立一个字符串变量
        dbstr = "select * from worker where wno='" & txtwno.Text & "'"
        '建立SQL查询
        Myrec = Mydb.OpenRecordset(dbstr, DAO.RecordsetTypeEnum.dbOpenDynaset)
        '执SQL查询
        If txtwno.Text = "" Or txtwno.Text = "" Or txtwname.Text = "" Or txtage.Text = "" Or txttitle.Text = "" Or txtsno.Text = "" Then
            MsgBox("请输入完整的职工信息。", Microsoft.VisualBasic.MsgBoxStyle.OKOnly)
        ElseIf Myrec.EOF Then
            '判断是否存在当前记录,如果不存在进行如下操作
            Myrec.AddNew()
            '增加新记录
            Myrec.Fields(0).Value = txtwno.Text
            '给myrec.Fields(0)赋值
            Myrec.Fields(1).Value = txtwname.Text
            '给myrec.Fields(1)赋值
            Myrec.Fields(2).Value = txttitle.Text
            '给myrec.Fields(3)赋值
            Myrec.Fields(3).Value = Val(txtage.Text)
            '给myrec.Fields(2)赋值,val类型转化
            Myrec.Fields(4).Value = txtsno.Text
            '给myrec.Fields(2)赋值
            Myrec.Update()
            '保存数据
            '以下清空文本框
            txtwno.Text = ""
            txtwname.Text = ""
            txtage.Text = ""
            txttitle.Text = ""
            txtsno.Text = ""
        Else
            '判断是否存在当前记录,如果存在进行如下操作
            MsgBox("这个工号已经存在了,请重新输入。", Microsoft.VisualBasic.MsgBoxStyle.OKOnly, )
            '以下清空文本框
            txtwno.Text = ""
            txtwname.Text = ""
            txtage.Text = ""
            txttitle.Text = ""
            txtsno.Text = ""
        End If
      
    End Sub

    Private Sub btedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btedit.Click
        Dim dbstr As String
        '建立一个字符串变量
        dbstr = "select * from worker where wno='" & txtwno.Text & "'or wname='" & txtwname.Text & "'"
        '建立SQL查询
        Myrec = Mydb.OpenRecordset(dbstr, DAO.RecordsetTypeEnum.dbOpenDynaset)
        '执SQL查询
        If Myrec.EOF Then
            '判断是否存在当前记录,如果存在进行如下操作
            MsgBox("这个工号不存在,如果你想新增,请输入之后选择新增。", Microsoft.VisualBasic.MsgBoxStyle.OKOnly)
        
        Else
            Myrec.Edit()
            '编辑当前记录
            Myrec.Fields(0).Value = txtwno.Text
            '给myrec.Fields(0)赋值
            Myrec.Fields(1).Value = txtwname.Text
            '给myrec.Fields(1)赋值
            Myrec.Fields(2).Value = txttitle.Text
            '给myrec.Fields(3)赋值
            Myrec.Fields(3).Value = Val(txtage.Text)
            '给myrec.Fields(2)赋值,val类型转化
            Myrec.Fields(4).Value = txtsno.Text
            '给myrec.Fields(2)赋值
            Myrec.Update()
            '保存数据
            '以下清空文本框
            txtwno.Text = ""
            txtwname.Text = ""
            txtage.Text = ""
            txttitle.Text = ""
            txtsno.Text = ""
        End If
    
      
    End Sub

    Private Sub btclose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btclose.Click
        Me.Close()
        '退出程序
    End Sub

    Private Sub butdel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butdel.Click
        Dim dbstr As String
        '建立一个字符串变量
        dbstr = "select * from worker where wno='" & txtwno.Text & "' or wname='" & txtwname.Text & "'"
        '建立SQL查询
        Myrec = Mydb.OpenRecordset(dbstr, DAO.RecordsetTypeEnum.dbOpenDynaset)

        '执SQL查询
        If Myrec.EOF Then
            '判断是否存在当前记录,如果存在进行如下操作
            MsgBox("这个工号已经不存在。", Microsoft.VisualBasic.MsgBoxStyle.OKOnly, "信息框")
        ElseIf MessageBox.Show("您即将删除" & txtwno.Text & "," & txtwname.Text & "的资料", "My Application", _
         MessageBoxButtons.YesNo, MessageBoxIcon.Question) _
         = DialogResult.Yes Then
            Myrec.Delete()
            txtwno.Text = ""
            txtwname.Text = ""
            txtage.Text = ""
            txttitle.Text = ""
            txtsno.Text = ""
        Else
            txtwno.Text = ""
            txtwname.Text = ""
            txtage.Text = ""
            txttitle.Text = ""
            txtsno.Text = ""
            Exit Sub

        End If


    End Sub
End Class

⌨️ 快捷键说明

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