📄 frm_addnewcharges.vb
字号:
Imports System.Data.OleDb
Imports System.DateTime
Imports System.Math
Public Class frm_AddNewCharges
Inherits System.Windows.Forms.Form
Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Library.mdb")
Dim MyCommand
Dim e As Exception
Dim MyCommand2
Dim MyReader As OleDbDataReader
Dim MyReader2 As OleDbDataReader
Dim dbset As New DataSet
Dim dataA
Dim currentDate As Date
Dim lockedUser 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)
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 Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frm_AddNewCharges))
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(43, 26)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(120, 25)
Me.Label1.TabIndex = 0
Me.Label1.Text = "费用编号"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(43, 69)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(120, 25)
Me.Label2.TabIndex = 1
Me.Label2.Text = "费用描述"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.TextBox3)
Me.GroupBox1.Controls.Add(Me.Label3)
Me.GroupBox1.Controls.Add(Me.TextBox2)
Me.GroupBox1.Controls.Add(Me.TextBox1)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Location = New System.Drawing.Point(10, 9)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(364, 155)
Me.GroupBox1.TabIndex = 2
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "书籍费用信息"
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(154, 112)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(192, 21)
Me.TextBox3.TabIndex = 5
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(65, 112)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(120, 25)
Me.Label3.TabIndex = 4
Me.Label3.Text = "费用"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(154, 69)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(192, 21)
Me.TextBox2.TabIndex = 3
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(154, 26)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(192, 21)
Me.TextBox1.TabIndex = 2
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(49, 177)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(96, 34)
Me.Button1.TabIndex = 3
Me.Button1.Text = "添加"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(145, 177)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(96, 34)
Me.Button2.TabIndex = 4
Me.Button2.Text = "重置"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(241, 177)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(96, 34)
Me.Button3.TabIndex = 5
Me.Button3.Text = "退出"
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(528, 78)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(120, 21)
Me.TextBox4.TabIndex = 6
'
'frm_AddNewCharges
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(397, 224)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.GroupBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frm_AddNewCharges"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "添加书籍费用信息"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
Function addCharges()
MyConnection.Open()
MyCommand = New OleDbCommand("INSERT INTO Charges VALUES('" & TextBox1.Text & "','" & TextBox2.Text & "', '" & TextBox3.Text & "')", MyConnection)
MyCommand.ExecuteNonQuery()
MyConnection.Close()
MyCommand.dispose()
End Function
Function checkTextbox(ByVal t As TextBox) As Boolean
If t.Text = "" Then
Return (False)
Else
Return True
End If
End Function
Function displayMsg(ByVal myMsgText As String)
MsgBox(myMsgText, MsgBoxStyle.Information, "图书馆管理系统")
End Function
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TextBox1) = False Then
displayMsg("Please fill in the textbox")
Else
If checkTextbox(TextBox1) = True Then
TextBox2.Focus()
End If
End If
Case Else
'do nothing
End Select
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TextBox2) = False Then
displayMsg("Please fill in the textbox")
Else
If checkTextbox(TextBox2) = True Then
TextBox3.Focus()
End If
End If
Case Else
'do nothing
End Select
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TextBox3) = False Then
displayMsg("Please fill in the textbox")
Else
If checkTextbox(TextBox3) = True Then
Button1.Focus()
End If
End If
Case Else
'do nothing
End Select
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If checkIfAlreadyExists() = False Then
displayMsg("The Entered Data Already Exists in the Database,Please Enter Another Charge No")
TextBox1.Focus()
clearfields()
Else
If checkIfAlreadyExists() = True Then
addCharges()
displayMsg("The Data has been added into the database")
clearfields()
TextBox1.Focus()
End If
End If
End Sub
Function clearfields()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Function
Function checkIfAlreadyExists() As Boolean
getbyname()
If TextBox4.Text = TextBox1.Text Then
Return False
Else
Return True
End If
End Function
Function getbyname()
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM Charges WHERE ChargeNo ='" & TextBox1.Text & "'", MyConnection)
Try
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
TextBox4.Text = MyReader("ChargeNo")
End While
Catch c As Exception
MsgBox(c.ToString)
End Try
MyConnection.Close()
MyReader.Close()
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
clearfields()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -