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

📄 productlist.frm

📁 这个是完整的数据库商品管理系统,有完整的源代码,本人测试过了,非常好用.里面还有详细的说明!
💻 FRM
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "Msflxgrd.ocx"
Begin VB.Form frmProductList 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "商品信息列表"
   ClientHeight    =   5370
   ClientLeft      =   30
   ClientTop       =   330
   ClientWidth     =   6495
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   5370
   ScaleWidth      =   6495
   ShowInTaskbar   =   0   'False
   Begin VB.Frame fraManage 
      Caption         =   "控制"
      Height          =   1335
      Left            =   120
      TabIndex        =   1
      Top             =   3840
      Width           =   6135
      Begin VB.CommandButton cmdDelete 
         Caption         =   "删除(&D).."
         Height          =   375
         Left            =   3045
         TabIndex        =   7
         Top             =   240
         Width           =   1095
      End
      Begin VB.CommandButton cmdEdit 
         Caption         =   "编辑(&E).."
         Height          =   375
         Left            =   1830
         TabIndex        =   6
         Top             =   240
         Width           =   1095
      End
      Begin VB.CommandButton cmdAdd 
         Caption         =   "添加(&A).."
         Height          =   375
         Left            =   600
         TabIndex        =   5
         Top             =   240
         Width           =   1095
      End
      Begin VB.CommandButton cmdFind 
         Caption         =   "查找(&F).."
         Height          =   375
         Left            =   4275
         TabIndex        =   4
         Top             =   240
         Width           =   1095
      End
      Begin VB.CommandButton cmdShowAll 
         Caption         =   "显示所有记录(&A)"
         Height          =   375
         Left            =   960
         TabIndex        =   3
         Top             =   840
         Width           =   1815
      End
      Begin VB.CommandButton cmdReport 
         Caption         =   "显示库存状态(&S).."
         Height          =   375
         Left            =   3000
         TabIndex        =   2
         Top             =   840
         Width           =   1815
      End
   End
   Begin MSFlexGridLib.MSFlexGrid grdList 
      Height          =   3615
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6135
      _ExtentX        =   10821
      _ExtentY        =   6376
      _Version        =   393216
      Cols            =   4
      FixedCols       =   3
      AllowUserResizing=   1
   End
End
Attribute VB_Name = "frmProductList"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim mRs As ADODB.Recordset

Private Sub cmdAdd_Click()
    frmProduct.mbAddMode = True
    frmProduct.Show vbModal
End Sub

Private Sub cmdDelete_Click()
    On Error GoTo errHandler
    
    Dim l As Long
    l = grdList.TextMatrix(grdList.Row, 1)
    
    gConn.Execute "delete from products where 顺序号= " & l
    
    '刷新整个FlexGrid
    Unload Me
    Load Me
    Me.SQL = "select * from products"
    Me.Show
    
    Exit Sub
    
errHandler:
    MsgBox Err.Description, vbCritical, "错误"
End Sub

Private Sub cmdEdit_Click()
    On Error GoTo errHandler

    frmProduct.mnSerial = CLng(grdList.TextMatrix(grdList.Row, 1))
    frmProduct.mbAddMode = False
    frmProduct.Show
    
    Exit Sub
    
errHandler:
    MsgBox Err.Description, vbCritical, "错误"
End Sub

Private Sub cmdFind_Click()
    frmFind.SQL = mRs.Source
    frmFind.Show vbModal
    
    If Trim(frmFind.msResultSQL) = "" Then Exit Sub
    
    '重新加载当前的窗体
    Unload Me
    Load Me
    Me.SQL = "select * from products where " & frmFind.msResultSQL
    Me.Show
    
    Unload frmFind
End Sub

Private Sub cmdReport_Click()
    If mRs.EOF And mRs.BOF Then
        MsgBox "当前没有任何记录!", vbExclamation, "错误"
        Exit Sub
    End If
    
    '查看库存状况
    Load frmChart
    
    frmChart.Caption = "当前商品的库存状态"
    Dim arr()
    ReDim arr(1 To mRs.RecordCount, 1 To 2)
    Dim i As Integer
    i = 1
    mRs.MoveFirst
    Dim str As String
    While Not mRs.EOF
        str = Trim(mRs("商品名称"))
        arr(i, 1) = "" & str & ""
        arr(i, 2) = mRs("库存数量")
        i = i + 1
        mRs.MoveNext
    Wend
            
    With frmChart.charReport
        .Title = "当前的库存商品的剩余数量"
        .ChartData = arr
    End With
    frmChart.Show vbModal
End Sub

Private Sub cmdShowAll_Click()
    Unload Me
    Load Me
    Me.SQL = "select * from products"
    Me.Show
End Sub

Private Sub Form_Load()
    Set mRs = New ADODB.Recordset
    
    Dim i As Integer
    '设置grdList控件的标题
    With grdList
        .Cols = 7
        .TextMatrix(0, 1) = ""
        .TextMatrix(0, 2) = "商品名称"
        .TextMatrix(0, 3) = "商品规格"
        .TextMatrix(0, 4) = "商品单位"
        .TextMatrix(0, 5) = "备注信息"
        .TextMatrix(0, 6) = "库存数量"
        
        '固定表头
        .FixedRows = 1
                
        '设置各列的对齐方式
        For i = 0 To .Cols - 1
            .ColAlignment(i) = 0
        Next i
                
        '表头项居中
        .FillStyle = flexFillRepeat
        .Col = 0
        .Row = 0
        .RowSel = 1
        .ColSel = .Cols - 1
        .CellAlignment = 4
        
        '设置单元大小
        .ColWidth(0) = 100
        .ColWidth(1) = 0
        .ColWidth(2) = 1000
        .ColWidth(3) = 1000
        .ColWidth(4) = 1000
        .ColWidth(5) = 1000
        .ColWidth(6) = 1000
        .Row = 1
    End With
End Sub

'只写属性SQL,在Let事件响应中,取得数据
Public Property Let SQL(ByVal vNewValue As Variant)
    On Error GoTo errHandler

    Dim j As Integer
    Dim i As Integer
    
    If mRs.State <> adStateClosed Then mRs.Close
    
    mRs.Open CStr(vNewValue), gConn, adOpenStatic
    '设置FlexGrid中的数据
    With grdList
        .Rows = 1
        Do While Not mRs.EOF
            .Rows = .Rows + 1
            For i = 1 To mRs.Fields.Count
                If Not IsNull(Trim(mRs.Fields(i - 1))) Then
                    Select Case mRs.Fields(i - 1).Type
                        Case adDBDate
                            .TextMatrix(.Rows - 1, i) = Format(mRs.Fields(i - 1) & "", "yyyy-mm-dd")
                        Case Else
                            .TextMatrix(.Rows - 1, i) = mRs.Fields(i - 1) & ""
                    End Select
                End If
            Next i
            mRs.MoveNext
        Loop
    End With
    
    Exit Property
    
errHandler:
    MsgBox Err.Description, vbCritical, "错误"
End Property

Private Sub Form_Unload(Cancel As Integer)
    If mRs.State <> adStateClosed Then mRs.Close
End Sub

⌨️ 快捷键说明

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