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

📄 main_rcyw_tsrk.frm

📁 是基于C#语言的一个图书综合管理系统的开发案例,相当实用
💻 FRM
📖 第 1 页 / 共 3 页
字号:
  '到达第1行,第1列
  MS1.Row = 1
  MS1.Col = 1
  Text1.SetFocus
 End If
End Sub
Private Sub jsr_LostFocus()
 jsr.BackColor = &HFFFFFF     ' 设置颜色
End Sub
Private Sub MS1_Click()
 If MS1.Row >= 1 And MS1.TextMatrix(MS1.Row - 1, 6) <> "" Then     '在MS1表格第1行或大于第1行时
  Select Case MS1.Col
    Case 7
       Combo1.Visible = True
       Combo2.Visible = False
       Combo1.Width = MS1.CellWidth
       Combo1.Left = MS1.CellLeft + MS1.Left
       Combo1.Top = MS1.CellTop + MS1.Top
       Combo1.SetFocus
    Case 8
       Combo2.Visible = True
       Combo1.Visible = False
       Combo2.Width = MS1.CellWidth
       Combo2.Left = MS1.CellLeft + MS1.Left
       Combo2.Top = MS1.CellTop + MS1.Top
       Combo2.SetFocus
    Case Else
       Combo1.Visible = False
       Combo2.Visible = False
       Text1.Visible = True     'text1可见
       Text1.SetFocus
  End Select
 End If
End Sub

Private Sub MS1_entercell()
 Dim X, Y, p As String   '定义字符串变量
 If MS1.CellWidth <= 0 Or MS1.CellHeight <= 0 Then Exit Sub
 X = MS1.TextMatrix(MS1.FixedRows, MS1.Col)
 Y = MS1.TextMatrix(MS1.Row, 0)
 If Y <> "" Then
  If MS1.Col - MS1.LeftCol <= 3 Then MS1.LeftCol = MS1.LeftCol + 1
  If MS1.CellWidth > 0 And MS1.CellHeight > 0 Then
   Text1.Width = MS1.CellWidth
   Text1.Height = MS1.CellHeight
   Text1.Left = MS1.CellLeft + MS1.Left
   Text1.Top = MS1.CellTop + MS1.Top
  End If
  X = MS1.TextMatrix(MS1.FixedRows, MS1.Col)
  Y = MS1.TextMatrix(MS1.Row, 0)
  p = MS1.TextMatrix(MS1.Row, MS1.Col)
  Text1.text = MS1.text
  Text1.SelStart = 0
  Text1.SelLength = Len(Text1.text)
 End If
End Sub
Private Sub MS1_RowColChange()     '格式化金额
  For i = 1 To 100
   If MS1.TextMatrix(i, 1) <> "" Then
    MS1.TextMatrix(i, 9) = Format(MS1.TextMatrix(i, 9), "#0.00")
    'Format 函数返回 Variant (String),其中含有一个表达式,它是根据格式表达式中的指令来格式化的。
    MS1.TextMatrix(MS1.Row, 11) = Val(MS1.TextMatrix(MS1.Row, 9)) * Val(MS1.TextMatrix(MS1.Row, 10))
    'Val 函数返回包含于字符串内的数字,字符串中是一个适当类型的数值。
    MS1.TextMatrix(i, 11) = Format(MS1.TextMatrix(i, 11), "#0.00")
   End If
  Next i
End Sub



Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then    '按回车键
        Text1.text = MS1.text
        Adodc3.RecordSource = "select * from kcb where 条形码='" + MS1.TextMatrix(MS1.Row, 2) + "'"
        Adodc3.Refresh
        If Adodc3.Recordset.RecordCount > 0 Then     '当记录大于零时
            If MS1.Col = 2 Then
                With Adodc3.Recordset
                    '赋值给MS1表格
                    If .Fields("书号") <> "" Then MS1.TextMatrix(MS1.Row, 1) = .Fields("书号")
                    If .Fields("条形码") <> "" Then MS1.TextMatrix(MS1.Row, 2) = .Fields("条形码")
                    If .Fields("书名") <> "" Then MS1.TextMatrix(MS1.Row, 3) = .Fields("书名")
                    If .Fields("作者") <> "" Then MS1.TextMatrix(MS1.Row, 4) = .Fields("作者")
                    If .Fields("出版社") <> "" Then MS1.TextMatrix(MS1.Row, 5) = .Fields("出版社")
                    If .Fields("图书类别") <> "" Then MS1.TextMatrix(MS1.Row, 7) = .Fields("图书类别")
                    If .Fields("存放位置") <> "" Then MS1.TextMatrix(MS1.Row, 8) = .Fields("存放位置")
                    If .Fields("单价") <> "" Then MS1.TextMatrix(MS1.Row, 9) = .Fields("单价")
                    Text1.text = MS1.text
                    MS1.Col = 6
                    Grid1.Visible = False
                    Text1.SetFocus
                End With
            End If
        End If
        If Adodc1.Recordset.RecordCount > 0 Then     '当记录大于零时
            If MS1.Col = 1 Then
                With Adodc1.Recordset
                    '赋值给MS1表格
                    If .Fields("书号") <> "" Then MS1.TextMatrix(MS1.Row, 1) = .Fields("书号")
                    If .Fields("条形码") <> "" Then MS1.TextMatrix(MS1.Row, 2) = .Fields("条形码")
                    If .Fields("书名") <> "" Then MS1.TextMatrix(MS1.Row, 3) = .Fields("书名")
                    If .Fields("作者") <> "" Then MS1.TextMatrix(MS1.Row, 4) = .Fields("作者")
                    If .Fields("出版社") <> "" Then MS1.TextMatrix(MS1.Row, 5) = .Fields("出版社")
                    If .Fields("图书类别") <> "" Then MS1.TextMatrix(MS1.Row, 7) = .Fields("图书类别")
                    If .Fields("存放位置") <> "" Then MS1.TextMatrix(MS1.Row, 8) = .Fields("存放位置")
                    If .Fields("单价") <> "" Then MS1.TextMatrix(MS1.Row, 9) = .Fields("单价")
                    MS1.Col = 6
                    Text1.text = MS1.text
                    Text1.SetFocus
                End With
            End If
            If MS1.Col = 6 Then MS1.Col = 9
            If MS1.Col = 10 Then
                MS1.Row = MS1.Row + 1
                MS1.Col = 1
            Else
                If MS1.Col + 1 <= MS1.Cols - 1 Then
                    MS1.Col = MS1.Col + 1
                Else
                    If MS1.Row + 1 <= MS1.Rows - 1 Then
                        MS1.Row = MS1.Row + 1
                        MS1.Col = 1
                    End If
                End If
            End If
        Else
            If MS1.Col = 10 Then
                MS1.Row = MS1.Row + 1
                MS1.Col = 1
            Else
                If MS1.Col + 1 <= MS1.Cols - 1 Then
                    MS1.Col = MS1.Col + 1
                Else
                    If MS1.Row + 1 <= MS1.Rows - 1 Then
                        MS1.Row = MS1.Row + 1
                        MS1.Col = 1
                    End If
                End If
            End If
        End If
    End If
    If KeyCode = vbKeyUp Then        '按KeyUp键
        If MS1.Row > 1 Then MS1.Row = MS1.Row - 1
    End If
    If KeyCode = vbKeyDown And (MS1.TextMatrix(MS1.Row, 1)) <> "" Then   '按KeyDown键
        If MS1.Row < 99 Then MS1.Row = MS1.Row + 1
    End If
    If KeyCode = vbKeyLeft Then    '按KeyLeft键
        If Text1.text <> "" Then
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.text)
            'Len 函数返回 Long,其中包含字符串内字符的数目,或是存储一变量所需的字节数。
        End If
        If MS1.Col - 10 <= MS1.Cols + 1 Then
            MS1.Col = MS1.Col - 1
            If MS1.Col = 0 Then MS1.Col = 1
        Else
            If MS1.Row + 1 <= MS1.Row - 1 Then
                MS1.Row = MS1.Row + 1
                MS1.Col = 1
            End If
        End If
    End If
    If KeyCode = vbKeyRight Then     '按KeyRight键
        If Text1.text <> "" Then
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.text)
        End If
        If MS1.Col + 1 <= MS1.Cols - 1 Then
            MS1.Col = MS1.Col + 1
        Else
            If MS1.Row + 1 <= MS1.Rows - 1 Then
                MS1.Row = MS1.Row + 1
                MS1.Col = 1
            End If
        End If
    End If
    If KeyCode = vbKeyPageDown And MS1.Col = 1 Then    '按KeyPageDown 键
        Adodc1.RecordSource = "select * from kcb"
        Adodc1.Refresh
        Grid1.Visible = True
        Grid1.SetFocus
    End If
End Sub

Private Sub Text1_Change()
    MS1.text = Text1.text     '赋值给MS1.text
    If MS1.Col = 1 Then
        '按书号查询库存图书信息
        Adodc1.RecordSource = "select * from kcb where 书号 like +'" + Text1.text + "'+'%'"
        Adodc1.Refresh
        If Text1.text = "" Then     '当text1.text为空时
            Grid1.Visible = False     'Grid1不可见
        Else
            If Adodc1.Recordset.RecordCount > 0 Then     '当记录大于零时
                Grid1.Visible = True     'Grid1可见
                Text1.Visible = True
                Text1.SetFocus
            Else
                Grid1.Visible = False
            End If
        End If
    End If
    If MS1.Col = 9 Then MS1.TextMatrix(MS1.Row, 11) = Val(MS1.TextMatrix(MS1.Row, 9)) * Val(MS1.TextMatrix(MS1.Row, 10))
    'Val 函数返回包含于字符串内的数字,字符串中是一个适当类型的数值。
    If MS1.Col = 10 Then MS1.TextMatrix(MS1.Row, 11) = Val(MS1.TextMatrix(MS1.Row, 9)) * Val(MS1.TextMatrix(MS1.Row, 10))
    If MS1.Col = 7 Then
        Text1.Visible = False
        Combo1.Visible = True
        Combo1.Width = MS1.CellWidth
        Combo1.Left = MS1.CellLeft + MS1.Left
        Combo1.Top = MS1.CellTop + MS1.Top
        Combo1.SetFocus
    End If
    Dim a, B As Single
    For i = 1 To 101
        a = Val(MS1.TextMatrix(i, 11)) + a
        B = Val(MS1.TextMatrix(i, 10)) + B
        If MS1.TextMatrix(i, 1) <> "" And MS1.TextMatrix(i, 10) <> "" Then pz.Caption = i
    Next i
    '计算合计金额,合计数量
    hjje.Caption = a     '计算合计金额
    hjsl.Caption = B     '计算合计数量
End Sub
Private Sub CmdReg_Click()  '登记
'查询所有入库数据,并按票号排序
    Adodc2.RecordSource = "select * from rkb order by 票号"
    Adodc2.Refresh
    '创建入库票号
    If Adodc2.Recordset.RecordCount > 0 Then    '当记录数大于零
        If Not Adodc2.Recordset.EOF Then Adodc2.Recordset.MoveLast
        If Adodc2.Recordset.Fields("票号") <> "" Then
            lsph = Right(Trim(Adodc2.Recordset.Fields("票号")), 4) + 1
            'Right 函数返回 Variant (String),其中包含从字符串右边取出的指定数量的字符。
            'Trim 函数返回 Variant (String),其中包含指定字符串的拷贝,没有前导和尾随空白 (Trim)。
            PH.Caption = Date & "rk" & Format(lsph, "0000")
        End If
    Else
        PH.Caption = Date & "rk" & "0001"
    End If
    '设置jsr有效
    jsr.Enabled = True
    'jsr获得焦点
    jsr.SetFocus
    Text1.Enabled = True
    MS1.Enabled = True
    '确定文本框在MS1表格中的位置
    Text1.Width = MS1.CellWidth
    Text1.Height = MS1.CellHeight
    Text1.Left = MS1.CellLeft + MS1.Left
    Text1.Top = MS1.CellTop + MS1.Top
    '设置按钮有效或无效
    CmdSave.Enabled = True
    CmdCancel.Enabled = True
    CmdReg.Enabled = False
    MS1.Enabled = True
    jsr.Enabled = True
End Sub

Private Sub CmdSave_Click()   '保存
 For i = 1 To 101
   If MS1.TextMatrix(i, 1) <> "" Then
   '添加入库商品信息到"rkb"表中
    If MS1.TextMatrix(i, 1) <> "" And MS1.TextMatrix(i, 2) <> "" And MS1.TextMatrix(i, 3) <> "" And MS1.TextMatrix(i, 4) <> "" _
    And MS1.TextMatrix(i, 5) <> "" And MS1.TextMatrix(i, 6) <> "" And MS1.TextMatrix(i, 7) <> "" And MS1.TextMatrix(i, 8) <> "" _
    And MS1.TextMatrix(i, 9) <> "" And MS1.TextMatrix(i, 10) <> "" And MS1.TextMatrix(i, 11) <> "" And jsr.text <> "" And _
    PH.Caption <> "" And jsr.text <> "" And rq.Caption <> "" Then
        Cnn.Execute ("insert into rkb(书号,条形码,书名,作者,出版社,版次,图书类别,存放位置,单价,入库数量,金额" & _
        ",经手人,票号,操作员,日期) values('" & MS1.TextMatrix(i, 1) & "','" & MS1.TextMatrix(i, 2) & "','" & _
        MS1.TextMatrix(i, 3) & "','" & MS1.TextMatrix(i, 4) & "','" & MS1.TextMatrix(i, 5) & "','" & MS1.TextMatrix(i, 6) & _
        "','" & MS1.TextMatrix(i, 7) & "','" & MS1.TextMatrix(i, 8) & _
        "','" & MS1.TextMatrix(i, 9) & "','" & MS1.TextMatrix(i, 10) & "','" & MS1.TextMatrix(i, 11) & _
        "','" & jsr.text & "','" & PH.Caption & "','" & frm_main.St1.Panels(3).text & "','" & rq.Caption & "') ")
    Else
    MsgBox "请输入完整信息", , ""
    End If
   '查找库存图书信息
   Set rs2 = New ADODB.Recordset
   rs2.Open "select * from kcb where 书号='" + MS1.TextMatrix(i, 1) + "'", Cnn, adOpenKeyset, adLockOptimistic
   If rs2.RecordCount = 0 Then
    '添加入库图书信息到"kcb"表中
        If MS1.TextMatrix(i, 1) <> "" And MS1.TextMatrix(i, 2) <> "" And MS1.TextMatrix(i, 3) <> "" And MS1.TextMatrix(i, 4) <> "" _
        And MS1.TextMatrix(i, 5) <> "" And MS1.TextMatrix(i, 7) <> "" And MS1.TextMatrix(i, 8) <> "" _
        And MS1.TextMatrix(i, 9) <> "" And MS1.TextMatrix(i, 10) <> "" And MS1.TextMatrix(i, 11) <> "" Then
            Cnn.Execute ("insert into kcb(书号,条形码,书名,作者,出版社,图书类别,存放位置,单价,现存数量,图书总数,借出次数) " & _
            "values('" & MS1.TextMatrix(i, 1) & "','" & MS1.TextMatrix(i, 2) & "','" & _
            MS1.TextMatrix(i, 3) & "','" & MS1.TextMatrix(i, 4) & "','" & MS1.TextMatrix(i, 5) & _
            "','" & MS1.TextMatrix(i, 7) & "','" & MS1.TextMatrix(i, 8) & "','" & MS1.TextMatrix(i, 9) & _
            "','" & MS1.TextMatrix(i, 10) & "','" & MS1.TextMatrix(i, 10) & "',0) ")
        Else
            MsgBox "请输入完整信息", , ""
        End If
   Else
    '更新"kcb"表中的"库存"及"库存金额"
    Adodc1.Recordset.Fields("现存数量") = Val(MS1.TextMatrix(i, 10)) + Val(Adodc1.Recordset.Fields("现存数量"))
    'Val 函数返回包含于字符串内的数字,字符串中是一个适当类型的数值。
    Adodc1.Recordset.Fields("图书总数") = Val(MS1.TextMatrix(i, 10)) + Val(Adodc1.Recordset.Fields("图书总数"))
    Adodc1.Recordset.Update
   End If
  End If
 Next i
Cnn.Execute ("insert into rkph(票号,入库品种,入库数量,合计金额,经手人,操作员,日期) " & _
"values('" & PH.Caption & "','" & pz.Caption & "','" & _
hjsl.Caption & "','" & hjje.Caption & "','" & jsr.text & _
"','" & frm_main.St1.Panels(3).text & "','" & rq.Caption & "') ")
 '关闭对象
 rs2.Close
  '清空数据
 For i = 1 To 101
 For j = 1 To 11
   MS1.TextMatrix(i, j) = ""
 Next j
 Next i
 '清空控件
 jsr.text = ""
 pz.Caption = ""
 hjsl.Caption = ""
 hjje.Caption = ""
 Text1.Visible = False     '设置控件不可见
 '设置控件状态
 MS1.Enabled = False
 CmdSave.Enabled = False
 CmdReg.Enabled = True
 CmdCancel.Enabled = False
End Sub
Private Sub CmdCancel_Click()      '取消操作
 '清空控件
 jsr.text = ""
 pz.Caption = ""
 hjsl.Caption = ""
 hjje.Caption = ""
 For i = 1 To 100
 For j = 1 To 11
     MS1.TextMatrix(i, j) = ""
 Next j
 Next i
 '设置控件状态
 jsr.Enabled = False
 Text1.Enabled = False
 MS1.Enabled = False
 CmdSave.Enabled = False
 CmdCancel.Enabled = False
 CmdReg.Enabled = True
 CmdReg.SetFocus
End Sub
Private Sub CmdEnd_Click()  '退出
  frm_main.Enabled = True
  Unload Me
End Sub



⌨️ 快捷键说明

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