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

📄 frm_bookadd.frm

📁 图书馆信息管理系统
💻 FRM
📖 第 1 页 / 共 3 页
字号:
      TabIndex        =   35
      Top             =   2280
      Width           =   1095
   End
   Begin VB.Line Line_Split 
      BorderColor     =   &H00C0C0C0&
      X1              =   3600
      X2              =   3600
      Y1              =   600
      Y2              =   5640
   End
   Begin VB.Line Line_SplitShadow 
      BorderColor     =   &H00FFFFFF&
      X1              =   3615
      X2              =   3615
      Y1              =   615
      Y2              =   5625
   End
End
Attribute VB_Name = "Frm_BookAdd"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim BID() As String          '图书编号数组
Dim BookNum As Integer       '图书数量
Public xISBN As String       '图书ISBN
Public FormType As String    '窗口类型(添加 OR 修改)
Public SourceForm As Form    '调用本窗口的源窗口
Option Explicit

Private Sub Chk_FrameSwitch_Click()
    Frame_Add2Store.Enabled = Chk_FrameSwitch.Value
End Sub

Private Sub Chk_Transparent_Click()
    If Chk_Transparent.Value = 1 Then
        SetLayeredWindowAttributes Me.hwnd, 0, 192, LWA_ALPHA
    Else
        SetLayeredWindowAttributes Me.hwnd, 0, 255, LWA_ALPHA
    End If
End Sub

Private Sub Cmb_Index_Click()
    If Cmb_Index.ListCount < 1 Then Exit Sub
    Txt_BookID.Text = BID(Cmb_Index.ListIndex)
End Sub

Private Sub Cmd_Add_Click()
    Dim Err_Msg As String
    If Trim(Txt_ISBN.Text) = vbNullString Or _
            Trim(Txt_BookName.Text) = vbNullString Or _
            Trim(Txt_Writer.Text) = vbNullString Or _
            Trim(Cmb_Press.Text) = vbNullString Then
        MsgFrm "请输入必要信息!", "!", "提示"
        Exit Sub
    End If

    Dim i As Integer
    If Chk_FrameSwitch.Value = 1 Then
        If BookNum = 0 Then
            MsgFrm "请输入数量!", "!", "提示"
            Txt_Num.SetFocus
            Exit Sub
        End If
    
        For i = 0 To BookNum - 1
            If BID(i) = vbNullString Then
                MsgFrm "请输入第" & i + 1 & "本数的编号!", "!", "提示"
                Cmb_Index.ListIndex = i
                Txt_BookID.SetFocus
                Exit Sub
            End If
        Next i
    End If

On Error GoTo ERRORZONE
    If FormType = "ADD_Book" Then
        If ADD_Book(Err_Msg) = False Then GoTo ERRORZONE
        
        If Chk_FrameSwitch.Value = 1 Then
            If ADD_Store(Err_Msg) = False Then GoTo ERRORZONE
        End If
        
        If Chk_AutoClose.Value = 1 Then Unload Me
        Call Cmd_Clear_Click
    ElseIf FormType = "ADD_Store" Then
        If ADD_Store(Err_Msg) = False Then GoTo ERRORZONE
        Unload Me
    Else
        If MOD_Book(Err_Msg) = False Then GoTo ERRORZONE
        Unload Me
    End If
    
    Call SourceForm.Cmd_Refresh_Click
    Exit Sub
ERRORZONE:
    MsgFrm Err_Msg, "x", "错误"
    Call SourceForm.Cmd_Refresh_Click
End Sub

Private Sub Cmd_Clear_Click()
    BookNum = 0
    ReDim BID(-1 To 0)
    
    Txt_BookName.Text = vbNullString
    Txt_Writer.Text = vbNullString
    If FormType = "ADD_Book" Then Txt_ISBN.Text = vbNullString
    
    Dim rs As New ADODB.Recordset
    Dim strSQL As String
    strSQL = "SELECT DISTINCT 出版社名称 FROM 出版社"
    rs.Open strSQL, cnMain, 1, 1
    Cmb_Press.Clear
    Do While Not rs.EOF
        Cmb_Press.AddItem rs("出版社名称")
        rs.MoveNext
    Loop
    
    Txt_PressDate.Text = vbNullString
    Txt_Price.Text = vbNullString
    Txt_Rent.Text = vbNullString
    
    Cmb_IsBrw.Clear
    Cmb_IsBrw.AddItem "是"
    Cmb_IsBrw.AddItem "否"
    
    Txt_Num.Text = vbNullString
    Cmb_Index.Clear
    Txt_BookID.Text = vbNullString
End Sub

Private Sub Cmd_GoBack_Click()
    Unload Me
End Sub

Private Sub Cmd_TBarClose_Click()
    Call Cmd_GoBack_Click
End Sub

Private Sub Form_Load()
    Dim sty As Long
    sty = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
    sty = sty Or WS_EX_LAYERED
    SetWindowLong Me.hwnd, GWL_EXSTYLE, sty
    SetLayeredWindowAttributes Me.hwnd, 0, 255, LWA_ALPHA

    Call Cmd_Clear_Click
    Call SetFormType
End Sub

Private Sub SetFormType()
    If FormType = "ADD_Book" Then
        Me.caption = "添加图书"
        Cmd_Add.caption = "添加"
        
        Chk_FrameSwitch.Value = 1
        Chk_AutoClose.Value = 1
        
        Lbl_Tip.Visible = True
    ElseIf FormType = "ADD_Store" Then
        Me.caption = "添加库存"
        Cmd_Add.caption = "添加"
        
        Frame_BaseInfo.Enabled = False
        
        Chk_FrameSwitch.Value = 1
        Chk_FrameSwitch.Enabled = False
        
        Chk_AutoClose.Visible = False
        
        Cmd_Clear.Visible = False
        Cmd_GoBack.Top = Cmd_Clear.Top
        
        Lbl_Tip.Visible = False
        
        Call LoadData
    ElseIf FormType = "MOD_Book" Then
        Me.Height = 4800
        Me.caption = "修改图书"
        Cmd_Add.caption = "修改"
        
        Txt_ISBN.Enabled = False
        
        Chk_FrameSwitch.Visible = False
        Frame_Add2Store.Visible = False
        
        Chk_Transparent.Top = Chk_Transparent.Top - 1440
        Chk_AutoClose.Visible = False
        
        Line_Split.Y2 = Line_Split.Y2 - 1440
        Line_SplitShadow.Y2 = Line_SplitShadow.Y2 - 1440
        
        Lbl_Tip.Visible = False
        
        Call LoadData
    End If
    
    Lbl_TBarText.caption = Me.caption
    Chk_Transparent.Value = 0
End Sub

Private Function LoadData() As Boolean
On Error GoTo ERRORZONE
    Dim strSQL As String
    Dim rs As New ADODB.Recordset

    strSQL = "SELECT * FROM 图书档案 WHERE ISBN =" & Str2SQL(xISBN)
    rs.Open strSQL, cnMain, 1, 1

    Txt_ISBN.Text = xISBN
    Txt_BookName.Text = rs("图书名称")
    Txt_Writer.Text = rs("作者")
    
    Dim i As Long
    For i = 0 To Cmb_Press.ListCount - 1
        If Cmb_Press.List(i) = rs("出版社名称") Then Cmb_Press.ListIndex = i
    Next
    
    Txt_PressDate.Text = rs("出版时间") & vbNullString
    Txt_Price.Text = rs("价格")
    Txt_Rent.Text = rs("每日租金")

    Cmb_IsBrw.ListIndex = IIf(rs("可否外借") = True, 0, 1)
    
    LoadData = True
    Exit Function
ERRORZONE:
    LoadData = False
End Function

Private Sub Timer1_Timer()
    Lbl_TBarText.caption = BookNum
End Sub

Private Sub Txt_BookID_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        BID(Cmb_Index.ListIndex) = Trim(Txt_BookID.Text)
        
        With Cmb_Index
            .ListIndex = IIf(.ListIndex = .ListCount - 1, 0, .ListIndex + 1)
        End With
        
        Txt_BookID.SetFocus
    End If
End Sub

Private Sub Txt_BookID_Validate(Cancel As Boolean)
    Call Txt_BookID_KeyPress(13)
End Sub

Private Sub Txt_ISBN_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        xISBN = Trim(Txt_ISBN.Text)
        If LoadData = False Then Exit Sub
        Me.FormType = "ADD_Store"
        Call SetFormType
    End If
End Sub

Private Sub Txt_Num_KeyPress(KeyAscii As Integer)
    If Chr(KeyAscii) = "." Then KeyAscii = 0
End Sub

Private Sub Txt_Num_Validate(Cancel As Boolean)
    Dim num As Long
    Dim i As Integer
    
    num = Val(Txt_Num.Text)
    If num = 0 Then
        Exit Sub
    ElseIf num < 1 Or num > 1000 Then
        MsgFrm "数量超出范围(1~1000)", "x", "错误"
        Txt_Num.SetFocus
        Exit Sub
    End If
    
    If num > BookNum Then
        BookNum = num
    ElseIf num < BookNum Then
        If MsgFrm("输入的数比之前的小,这样会造成部分数据丢失,请确认?", "?", "提示") = 2 Then Txt_Num.Text = BookNum: Exit Sub
        BookNum = num
    Else: Exit Sub
    End If
    
    Cmb_Index.Clear
    For i = 1 To BookNum
        Cmb_Index.AddItem i
    Next i
    Cmb_Index.ListIndex = 0
    
    ReDim Preserve BID(-1 To BookNum - 1)
End Sub

Private Sub Txt_PressDate_Validate(Cancel As Boolean)
    If IsDate(Txt_PressDate.Text) = False Then Txt_PressDate.Text = vbNullString
End Sub

Private Function ADD_Book(Optional ByRef Err_Msg As String) As Boolean
On Error GoTo ERRORZONE

    If FindPress(Cmb_Press.Text) = False Then Call Add2Press(Cmb_Press.Text)

    cnMain.Execute "INSERT 图书档案 VALUES(" & _
                    Str2SQL(Txt_ISBN.Text) & "," & _
                    Str2SQL(Txt_BookName.Text) & "," & _
                    Str2SQL(Txt_Writer.Text) & "," & _
                    Str2SQL(Cmb_Press.Text) & "," & _
                    Str2SQL(Txt_PressDate.Text) & "," & _
                    Val(Txt_Price.Text) & "," & _
                    Val(Txt_Rent.Text) & "," & _
                    Str2SQL(IIf(Cmb_IsBrw.ListIndex = 0, 1, 0)) & ")"
    
    ADD_Book = True
    Exit Function
ERRORZONE:
    Err_Msg = Err.Description
    ADD_Book = False
End Function

Private Function ADD_Store(Optional ByRef Err_Msg As String) As Boolean
On Error GoTo ERRORZONE
    Dim i As Integer
    For i = 0 To UBound(BID)
        cnMain.Execute "INSERT 图书库存 (图书编号, ISBN, 入库日期, 经手人) VALUES(" & _
                        Str2SQL(BID(i)) & "," & _
                        Str2SQL(Txt_ISBN.Text) & "," & _
                        Str2SQL(Format(Date, "yyyy-mm-dd") & " " & Format(Time, "hh:nn:ss")) & "," & _
                        Str2SQL(strUID) & ")"
    Next i
    
    ADD_Store = True
    Exit Function
ERRORZONE:
    Err_Msg = Err.Description
    ADD_Store = False
End Function

Private Function MOD_Book(Optional ByRef Err_Msg As String) As Boolean
On Error GoTo ERRORZONE

    If FindPress(Cmb_Press.Text) = False Then Call Add2Press(Cmb_Press.Text)
    
    cnMain.Execute "UPDATE 图书档案 SET " & _
        " 图书名称=" & Str2SQL(Txt_BookName.Text) & _
        ",作者=" & Str2SQL(Txt_Writer.Text) & _
        ",出版社名称=" & Str2SQL(Cmb_Press.Text) & _
        ",出版时间=" & Str2SQL(Txt_PressDate.Text) & _
        ",价格=" & Val(Txt_Price.Text) & _
        ",每日租金=" & Val(Txt_Rent.Text) & _
        ",可否外借=" & Str2SQL(IIf(Cmb_IsBrw.ListIndex = 0, 1, 0)) & _
        " WHERE ISBN=" & Str2SQL(Txt_ISBN.Text)
    
    MOD_Book = True
    Exit Function
ERRORZONE:
    Err_Msg = Err.Description
    MOD_Book = False
End Function

Private Function FindPress(strPress As String) As Boolean
    Dim rs As New ADODB.Recordset
    Dim strSQL As String
    
    strSQL = "SELECT * FROM 出版社 WHERE 出版社名称 = " & Str2SQL(strPress)
    rs.Open strSQL, cnMain, 1, 1

    FindPress = IIf(rs.EOF, False, True)
End Function

Private Sub Add2Press(strPress As String)
On Error Resume Next
    cnMain.Execute ("INSERT 出版社 (出版社名称) VALUES (" & Str2SQL(strPress) & ")")
End Sub

⌨️ 快捷键说明

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