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

📄 frmsjjy.vb

📁 简单的VFP 图书管理系统
💻 VB
字号:
Imports System.Data.SqlClient
Public Class frmSjJy
    Inherits System.Windows.Forms.Form
    Dim conn As New SqlConnection("server=.; database=ViBook;integrated security=sspi")
    Dim comm As New SqlCommand
    Dim ds As New DataSet
    Dim da As New SqlDataAdapter
#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    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

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents DataGrid2 As System.Windows.Forms.DataGrid
    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 Button2 As System.Windows.Forms.Button
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents Label4 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.DataGrid2 = New System.Windows.Forms.DataGrid
        Me.Button3 = New System.Windows.Forms.Button
        Me.Button4 = New System.Windows.Forms.Button
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.Label4 = New System.Windows.Forms.Label
        Me.GroupBox1.SuspendLayout()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Button2)
        Me.GroupBox1.Controls.Add(Me.Button1)
        Me.GroupBox1.Controls.Add(Me.TextBox1)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Top
        Me.GroupBox1.Location = New System.Drawing.Point(0, 0)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(672, 80)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(496, 24)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(160, 24)
        Me.Label3.TabIndex = 5
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(432, 24)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(64, 24)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "当前日期:"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(336, 24)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(72, 24)
        Me.Button2.TabIndex = 3
        Me.Button2.Text = "取消"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(240, 24)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(72, 24)
        Me.Button1.TabIndex = 2
        Me.Button1.Text = "确定"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(88, 24)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(128, 21)
        Me.TextBox1.TabIndex = 1
        Me.TextBox1.Text = ""
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "读者编号:"
        '
        'DataGrid1
        '
        Me.DataGrid1.CaptionVisible = False
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Left
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(0, 80)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.ReadOnly = True
        Me.DataGrid1.Size = New System.Drawing.Size(272, 350)
        Me.DataGrid1.TabIndex = 1
        '
        'DataGrid2
        '
        Me.DataGrid2.CaptionVisible = False
        Me.DataGrid2.DataMember = ""
        Me.DataGrid2.Dock = System.Windows.Forms.DockStyle.Right
        Me.DataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid2.Location = New System.Drawing.Point(384, 80)
        Me.DataGrid2.Name = "DataGrid2"
        Me.DataGrid2.ReadOnly = True
        Me.DataGrid2.Size = New System.Drawing.Size(288, 350)
        Me.DataGrid2.TabIndex = 2
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(288, 152)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(80, 24)
        Me.Button3.TabIndex = 3
        Me.Button3.Text = "借阅>>"
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(288, 232)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(80, 24)
        Me.Button4.TabIndex = 4
        Me.Button4.Text = "<<归还"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(120, 56)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(472, 16)
        Me.Label4.TabIndex = 6
        Me.Label4.Text = "请先输入读者编号,确定后再借书,初始编号为1,2,3,4,5"
        '
        'frmSjJy
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(672, 430)
        Me.Controls.Add(Me.Button4)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.DataGrid2)
        Me.Controls.Add(Me.DataGrid1)
        Me.Controls.Add(Me.GroupBox1)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmSjJy"
        Me.Text = "图书借阅"
        Me.GroupBox1.ResumeLayout(False)
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub frmSjJy_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If conn.State = ConnectionState.Closed Then
            conn.Open()
        End If
        comm.Connection = conn
        comm.CommandType = CommandType.Text
        comm.CommandText = "select * from 图书信息表"
        da.SelectCommand = comm
        da.Fill(ds, "图书信息表")
        DataGrid1.DataSource = ds.Tables("图书信息表")
        If conn.State = ConnectionState.Open Then
            conn.Close()
        End If
        Label3.Text = Now.ToString
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim ds1 As New DataSet
        ds1.Clear()
        Dim id As String
        id = Me.TextBox1.Text
        If conn.State = ConnectionState.Closed Then
            conn.Open()
        End If
        comm.Connection = conn
        comm.CommandType = CommandType.Text
        comm.CommandText = "select 读者编号,图书编号,借书日期,应还书日期 from 读者借阅表 where 读者编号 ='" & id & "'"
        da.SelectCommand = comm
        da.Fill(ds1, "读者借阅表")
        DataGrid2.DataSource = ds1.Tables("读者借阅表")
        If conn.State = ConnectionState.Open Then
            conn.Close()
        End If
    End Sub

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

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If conn.State = ConnectionState.Closed Then
            conn.Open()
        End If
            Dim tsbh As String
            tsbh = ds.Tables("图书信息表").Rows(DataGrid1.CurrentRowIndex).Item(0)
            Dim borrowdate, returndate As Date
            borrowdate = Now.Date
            returndate = DateAdd(DateInterval.Day, 90, Now.Date)
            Dim str As String
            str = "insert into 读者借阅表(读者编号,图书编号,借书日期,应还书日期) values('" & TextBox1.Text & "','" & tsbh & "','" & borrowdate & "','" & returndate & "')"
            comm.Connection = conn
            comm.CommandType = CommandType.Text
            comm.CommandText = str
            da.SelectCommand = comm
            da.Fill(ds, "读者借阅表")
            If Me.ds.Tables.Count <> 0 Then
                Dim ds1 As New DataSet
                ds1.Clear()
                Dim id As String
                id = Me.TextBox1.Text
                If conn.State = ConnectionState.Closed Then
                    conn.Open()
                End If
                comm.Connection = conn
                comm.CommandType = CommandType.Text
                comm.CommandText = "select 读者编号,图书编号,借书日期,应还书日期 from 读者借阅表 where 读者编号 ='" & id & "'"
                da.SelectCommand = comm
                da.Fill(ds1, "读者借阅表")
                DataGrid2.DataSource = ds1.Tables("读者借阅表")
                MessageBox.Show("图书借阅成功", "提示信息")
            Else
            End If
        If conn.State = ConnectionState.Open Then
            conn.Close()
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If conn.State = ConnectionState.Closed Then
            conn.Open()
        End If
        Dim ds1 As New DataSet
        Dim bh As String
        comm.Connection = conn
        comm.CommandType = CommandType.Text
        comm.CommandText = "select 读者编号,图书编号,借书日期,应还书日期 from 读者借阅表 "
        da.SelectCommand = comm
        da.Fill(ds1, "读者借阅表")
        bh = ds1.Tables("读者借阅表").Rows(DataGrid2.CurrentRowIndex).Item(1)
        Dim str As String
        str = "delete  from 读者借阅表 where 图书编号='" & bh & "'"
        comm.Connection = conn
        comm.CommandType = CommandType.Text
        comm.CommandText = str
        da.SelectCommand = comm
        da.Fill(ds, "读者借阅表")
        If Me.ds.Tables.Count <> 0 Then
            'Dim ds1 As New DataSet
            ds1.Clear()
            Dim id As String
            id = Me.TextBox1.Text
            If conn.State = ConnectionState.Closed Then
                conn.Open()
            End If
            comm.Connection = conn
            comm.CommandType = CommandType.Text
            comm.CommandText = "select 读者编号,图书编号,借书日期,应还书日期 from 读者借阅表 where 读者编号 ='" & id & "'"
            da.SelectCommand = comm
            da.Fill(ds1, "读者借阅表")
            DataGrid2.DataSource = ds1.Tables("读者借阅表")
            MessageBox.Show("图书归还成功", "提示信息")
        Else
        End If
        If conn.State = ConnectionState.Open Then
            conn.Close()
        End If
    End Sub
End Class

⌨️ 快捷键说明

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