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

📄 frmbuy.frm

📁 <Visual Basic 数据库开发实例精粹(第二版)>一书首先介绍了Visual Basic(简称VB)开发的技巧和重点技术
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmBuy 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "进货管理"
   ClientHeight    =   3600
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6705
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   ScaleHeight     =   3600
   ScaleWidth      =   6705
   StartUpPosition =   1  '所有者中心
   Begin VB.Frame FrameBG 
      Height          =   3720
      Left            =   0
      TabIndex        =   8
      Top             =   -120
      Width           =   6705
      Begin VB.ComboBox cbo 
         Height          =   300
         Left            =   1365
         Style           =   2  'Dropdown List
         TabIndex        =   0
         Top             =   735
         Width           =   4860
      End
      Begin VB.TextBox txt 
         Height          =   990
         Index           =   4
         Left            =   1365
         MaxLength       =   500
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   5
         Top             =   1890
         Width           =   4830
      End
      Begin VB.TextBox txt 
         Height          =   270
         Index           =   3
         Left            =   3630
         MaxLength       =   5
         TabIndex        =   4
         Top             =   1500
         Width           =   1080
      End
      Begin VB.TextBox txt 
         Height          =   270
         Index           =   2
         Left            =   1365
         MaxLength       =   5
         TabIndex        =   3
         Top             =   1515
         Width           =   1080
      End
      Begin VB.PictureBox picTitle 
         Appearance      =   0  'Flat
         BackColor       =   &H00808080&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   360
         Left            =   30
         ScaleHeight     =   360
         ScaleWidth      =   6660
         TabIndex        =   9
         TabStop         =   0   'False
         Top             =   120
         Width           =   6660
         Begin VB.Label lblTitle 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "登记进货信息"
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   10.5
               Charset         =   134
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00FFFFFF&
            Height          =   210
            Left            =   255
            TabIndex        =   10
            Top             =   90
            Width           =   1350
         End
      End
      Begin VB.TextBox txt 
         Height          =   270
         IMEMode         =   3  'DISABLE
         Index           =   0
         Left            =   1365
         TabIndex        =   1
         Top             =   1140
         Width           =   1080
      End
      Begin VB.TextBox txt 
         Height          =   270
         IMEMode         =   3  'DISABLE
         Index           =   1
         Left            =   3630
         TabIndex        =   2
         Top             =   1125
         Width           =   1080
      End
      Begin VB.CommandButton cmdBuy 
         Caption         =   "确定(&O)"
         Height          =   375
         Left            =   3615
         TabIndex        =   6
         Top             =   3045
         Width           =   1080
      End
      Begin VB.CommandButton cmdCancel 
         Cancel          =   -1  'True
         Caption         =   "取消(&C)"
         Height          =   375
         Left            =   4950
         TabIndex        =   7
         Top             =   3045
         Width           =   1080
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         Caption         =   "元"
         Height          =   180
         Left            =   2490
         TabIndex        =   17
         Top             =   1185
         Width           =   180
      End
      Begin VB.Label Label11 
         AutoSize        =   -1  'True
         Caption         =   "办理员"
         Height          =   180
         Left            =   2895
         TabIndex        =   16
         Top             =   1560
         Width           =   540
      End
      Begin VB.Label Label10 
         AutoSize        =   -1  'True
         Caption         =   "送货员"
         Height          =   180
         Left            =   405
         TabIndex        =   15
         Top             =   1560
         Width           =   540
      End
      Begin VB.Label Label9 
         AutoSize        =   -1  'True
         Caption         =   "进货备注"
         Height          =   180
         Left            =   405
         TabIndex        =   14
         Top             =   1965
         Width           =   720
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         Caption         =   "商品名称"
         Height          =   180
         Left            =   405
         TabIndex        =   13
         Top             =   780
         Width           =   720
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Caption         =   "进货单价"
         Height          =   180
         Left            =   405
         TabIndex        =   12
         Top             =   1185
         Width           =   720
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         Caption         =   "数量"
         Height          =   180
         Left            =   3075
         TabIndex        =   11
         Top             =   1185
         Width           =   360
      End
   End
End
Attribute VB_Name = "frmBuy"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Buy As clsBuy     '进货对象

'验证用户输入的有效性
Private Function IsOK() As Boolean
  Dim i As Long
  
  '必须选择进货商品
  If cbo.Text = "" Then
     MsgBox "请选择进货商品!", vbInformation
     Exit Function
  End If
  
  '除备注外的项目必须全部填写
  For i = 0 To 3
    If txt(i) = "" Then
       MsgBox "除备注外,请把所有项目填写完整!", vbInformation
       Exit Function
    End If
  Next i
  
  '进价和数量必须为数字
  If Not IsNumeric(txt(0)) Then
     MsgBox "进价不是数字,请重新填写!", vbInformation
     txt(0).SetFocus
     Exit Function
  End If
  If Not IsNumeric(txt(1)) Then
     MsgBox "数量不是数字,请重新填写!", vbInformation
     txt(1).SetFocus
     Exit Function
  End If
  
  '返回函数值
  IsOK = True
End Function

Private Sub cmdBuy_Click()
  '用户输入无效则退出该过程的执行
  If Not IsOK Then Exit Sub
  
  '初始化进货对象
  Set Buy = New clsBuy
  With Buy
    '为进货对象的属性赋值
    .GoodsID = cbo.ItemData(cbo.ListIndex)
    .UnitPrice = Val(txt(0))
    .Amount = Val(txt(1))
    .Deliverer = Trim(txt(2))
    .Transactor = Trim(txt(3))
    .RegistrarID = UserID
    .Remark = IIf(Trim(txt(4)) = "", "无", RTrim(txt(4)))
    '根据cmdBuy的Caption属性修改或添加进货对象
    Select Case cmdBuy.Caption
      Case "修改(&M)": UpdateBuy  '修改进货对象
      Case Else: AddNewBuy        '添加进货对象
    End Select
  End With
  cbo.SetFocus
End Sub

'更新进货对象
Private Sub UpdateBuy()
  Dim UpdateResult As gxcUpdate   '更新结果
  '指定进货对象的ID属性
  Buy.ID = Me.Tag
  '更新进货对象并返回更新结果
  UpdateResult = Buy.Update
  
  Dim Buys As New clsBuys         '进货对象集
  '按照编号查询更新后的进货对象
  Buys.Query Buy.ID
  '同步更新列表视图并弹出提示消息框
  ProcUpdateResult UpdateResult, Buys.Item(1)
End Sub

'添加进货对象
Private Sub AddNewBuy()
  Dim AddNewResult As gxcAddNew   '添加结果
  '添加进货对象并返回添加结果
  AddNewResult = Buy.AddNew
  '添加成功之后的操作
  If AddNewResult = AddNewOK Then
     txt(0) = "": txt(1) = "": txt(2) = "": txt(3) = "": txt(4) = ""
     '
     Dim Buys As New clsBuys      '进货对象集
     '按照编号查询刚添加的进货对象
     Buys.Query Buy.ID
     '当前操作处于浏览进货信息状态,则在列表视图上添加进货信息
     If CurrentOperation = BrowseBuy Then ShowObjInLvw Buys.Item(1)
     MsgBox "登记成功!", vbInformation
     Exit Sub
  End If
  '添加失败后的操作(消息框提示用户)
  ProcAddNewResult AddNewResult
End Sub

Private Sub cmdCancel_Click()
  Unload Me
End Sub

Private Sub Form_Load()
  Dim Goodses As clsGoodses   '商品对象集
  Dim i As Long
  
  '初始化商品对象集
  Set Goodses = New clsGoodses
  '检索所有商品
  Goodses.Query
  '将商品名称和编号添加到组合框
  For i = 1 To Goodses.Count
    cbo.AddItem Goodses.Item(i).GoodsName
    cbo.ItemData(i - 1) = Goodses.Item(i).ID
  Next i
End Sub

'文本框获得焦点时选中所有文字
Private Sub txt_GotFocus(Index As Integer)
  txt(Index).SelStart = 0                   '选中文字的起始位置
  txt(Index).SelLength = Len(txt(Index))    '选中文字的长度
End Sub

⌨️ 快捷键说明

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