VERSION 5.00
Begin VB.Form frmBook1
BorderStyle = 3 'Fixed Dialog
Caption = "书籍信息"
ClientHeight = 4812
ClientLeft = 48
ClientTop = 336
ClientWidth = 7428
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4812
ScaleWidth = 7428
ShowInTaskbar = 0 'False
StartUpPosition = 1 'CenterOwner
Begin VB.TextBox txtNo
Height = 270
Left = 840
TabIndex = 21
TabStop = 0 'False
Top = 4320
Visible = 0 'False
Width = 735
End
Begin VB.Frame Frame3
Caption = "备注信息"
Height = 1215
Left = 240
TabIndex = 16
Top = 2760
Width = 6972
Begin VB.TextBox txtItem
Height = 840
Index = 7
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 8
Top = 240
Width = 6732
End
End
Begin VB.Frame Frame1
Caption = "书籍信息"
Height = 2412
Left = 240
TabIndex = 10
Top = 240
Width = 6972
Begin VB.TextBox txtItem
Height = 270
Index = 6
Left = 4560
MaxLength = 10
TabIndex = 7
Top = 1920
Width = 2172
End
Begin VB.TextBox txtItem
Height = 270
Index = 5
Left = 4560
MaxLength = 10
TabIndex = 6
Top = 1440
Width = 2172
End
Begin VB.TextBox txtItem
Height = 270
Index = 4
Left = 4560
MaxLength = 5
TabIndex = 5
Top = 960
Width = 2172
End
Begin VB.TextBox txtItem
Height = 270
Index = 3
Left = 4560
MaxLength = 10
TabIndex = 4
Top = 480
Width = 2172
End
Begin VB.TextBox txtItem
Height = 270
Index = 2
Left = 1200
MaxLength = 20
TabIndex = 3
Top = 1920
Width = 2172
End
Begin VB.TextBox txtItem
Height = 270
Index = 1
Left = 1200
MaxLength = 20
TabIndex = 2
Top = 1440
Width = 2175
End
Begin VB.TextBox txtItem
Height = 270
Index = 0
Left = 1200
MaxLength = 20
TabIndex = 0
Top = 480
Width = 2175
End
Begin VB.ComboBox cboItem
Height = 288
Index = 0
Left = 1200
Style = 2 'Dropdown List
TabIndex = 1
Top = 960
Width = 2175
End
Begin VB.Label Label2
Caption = "登记日期:"
Height = 252
Index = 6
Left = 3600
TabIndex = 20
Top = 1920
Width = 972
End
Begin VB.Label Label2
Caption = "关键词:"
Height = 252
Index = 5
Left = 3600
TabIndex = 19
Top = 1440
Width = 972
End
Begin VB.Label Label2
Caption = "书籍页数:"
Height = 252
Index = 4
Left = 3600
TabIndex = 18
Top = 960
Width = 972
End
Begin VB.Label Label2
Caption = "出版日期:"
Height = 252
Index = 2
Left = 3600
TabIndex = 17
Top = 480
Width = 972
End
Begin VB.Label Label2
Caption = "出版社名称:"
Height = 255
Index = 3
Left = 240
TabIndex = 15
Top = 1920
Width = 975
End
Begin VB.Label Label2
Caption = "书籍名称:"
Height = 255
Index = 0
Left = 240
TabIndex = 14
Top = 480
Width = 975
End
Begin VB.Label Label2
Caption = "书籍类别:"
Height = 255
Index = 1
Left = 240
TabIndex = 13
Top = 960
Width = 975
End
Begin VB.Label Label2
Caption = "作者姓名:"
Height = 255
Index = 16
Left = 240
TabIndex = 12
Top = 1440
Width = 975
End
End
Begin VB.CommandButton cmdExit
Caption = "返回 (&X)"
Height = 375
Left = 4320
TabIndex = 11
Top = 4200
Width = 1215
End
Begin VB.CommandButton cmdSave
Caption = "保存 (&S)"
Height = 375
Left = 2880
TabIndex = 9
Top = 4200
Width = 1215
End
End
Attribute VB_Name = "frmBook1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'是否改动过记录,ture为改过
Dim mblChange As Boolean
Dim mrc As ADODB.Recordset
Public txtSQL As String
Private Sub cboItem_Change(Index As Integer)
'有变化设置gblchange
mblChange = True
End Sub
Private Sub cboItem_Click(Index As Integer)
Dim sSql As String
Dim MsgText As String
Dim mrcc As ADODB.Recordset
End Sub
Private Sub cboItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
EnterToTab KeyCode
End Sub
Private Sub cmdExit_Click()
If mblChange And cmdSave.Enabled Then
If MsgBox("保存当前记录的变化吗?", vbOKCancel + vbExclamation, "警告") = vbOK Then
'保存
Call cmdSave_Click
End If
End If
Unload Me
End Sub
Private Sub cmdSave_Click()
Dim intCount As Integer
Dim sMeg As String
Dim mrcc As ADODB.Recordset
Dim MsgText As String
For intCount = 0 To 6
If Trim(txtItem(intCount) & " ") = "" Then
Select Case intCount
Case 0
sMeg = "书籍名称"
Case 1
sMeg = "作者姓名"
Case 2
sMeg = "出版社名称"
Case 3
sMeg = "出版日期"
Case 4
sMeg = "书籍页码"
Case 5
sMeg = "关键词"
Case 6
sMeg = "登记日期"
End Select
sMeg = sMeg & "不能为空!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
txtItem(intCount).SetFocus
Exit Sub
End If
Next intCount
For intCount = 3 To 6 Step 3
If Not IsDate(Trim(txtItem(intCount) & " ")) Then
Select Case intCount
Case 3
sMeg = "出版日期"
Case 6
sMeg = "登记日期"
End Select
sMeg = sMeg & "请输入日期!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
txtItem(intCount).SetFocus
Exit Sub
End If
Next intCount
If gintBmode = 1 Then
txtSQL = "select * from books where bookname ='" & Trim(txtItem(0)) & "' and bookauthor = '" & Trim(txtItem(1)) & "' and bookpub = '" & Trim(txtItem(2)) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = False Then
MsgBox "已经存在此书籍的记录!", vbOKOnly + vbExclamation, "警告"
txtItem(0).SetFocus
Exit Sub
End If
mrc.Close
End If
If gintBmode = 2 Then
'先删除已有记录
txtSQL = "delete from books where bookid ='" & Trim(txtNo) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
End If
'再加入新记录
txtSQL = "select * from books"
Set mrc = ExecuteSQL(txtSQL, MsgText)
mrc.AddNew
mrc.Fields(0) = Trim(txtNo)
mrc.Fields(1) = Trim(txtItem(0))
mrc.Fields(2) = Trim(cboItem(0))
For intCount = 3 To 8
If Trim(txtItem(intCount - 2) & " ") = "" Then
mrc.Fields(intCount) = Null
Else
mrc.Fields(intCount) = Trim(txtItem(intCount - 2))
End If
Next intCount
mrc.Fields(9) = " "
mrc.Fields(10) = Trim(txtItem(7))
mrc.Update
mrc.Close
If gintBmode = 1 Then
For intCount = 0 To 7
txtItem(intCount) = ""
Next intCount
mblChange = False
If flagBedit Then
Unload frmBook
frmBook.txtSQL = "select * from books"
frmBook.Show
End If
ElseIf gintBmode = 2 Then
Unload Me
If flagBedit Then
Unload frmBook
End If
frmBook.txtSQL = "select * from books"
frmBook.Show
End If
End Sub
Private Sub Form_Load()
Dim sSql As String
Dim intCount As Integer
Dim MsgText As String
Dim mrcc As ADODB.Recordset
If gintBmode = 1 Then
Me.Caption = Me.Caption & "添加"
'初始化物资名称
txtSQL = "select DISTINCT typename from booktype"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If Not mrc.EOF Then
Do While Not mrc.EOF
cboItem(0).AddItem Trim(mrc.Fields(0))
mrc.MoveNext
Loop
cboItem(0).ListIndex = 0
Else
MsgBox "请先进行书籍标准设置!", vbOKOnly + vbExclamation, "警告"
cmdSave.Enabled = False
Exit Sub
End If
mrc.Close
txtNo = GetRkno()
ElseIf gintBmode = 2 Then
Set mrcc = ExecuteSQL(txtSQL, MsgText)
If mrcc.EOF = False Then
With mrcc
txtNo = .Fields(0)
txtItem(0) = .Fields(1)
For intCount = 1 To 6
If Not IsNull(.Fields(intCount + 2)) Then
txtItem(intCount) = .Fields(intCount + 2)
End If
Next intCount
txtItem(7) = .Fields(9)
txtSQL = "select DISTINCT typename from booktype"
cboItem(0).Clear
Set mrc = ExecuteSQL(txtSQL, MsgText)
If Not mrc.EOF Then
Do While Not mrc.EOF
cboItem(0).AddItem Trim(mrc.Fields(0))
mrc.MoveNext
Loop
Else
MsgBox "请先进行书籍种类设置!", vbOKOnly + vbExclamation, "警告"
cmdSave.Enabled = False
Exit Sub
End If
mrc.Close
End With
End If
mrcc.Close
Me.Caption = Me.Caption & "修改"
End If
mblChange = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
gintBmode = 0
End Sub
Private Sub txtItem_Change(Index As Integer)
'有变化设置gblchange
mblChange = True
End Sub
Private Sub txtItem_GotFocus(Index As Integer)
txtItem(Index).SelStart = 0
txtItem(Index).SelLength = Len(txtItem(Index))
End Sub
Private Sub txtItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
EnterToTab KeyCode
End Sub
Private Function GetRkno() As String
GetRkno = Format(Now, "yymmddhhmmss")
Randomize
GetRkno = GetRkno & Int((99 - 10 + 1) * Rnd + 10)
End Function