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

📄 frmsale.frm

📁 <Visual Basic 数据库开发实例精粹(第二版)>一书首先介绍了Visual Basic(简称VB)开发的技巧和重点技术
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmSale 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "销售管理"
   ClientHeight    =   3180
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6375
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   ScaleHeight     =   3180
   ScaleWidth      =   6375
   StartUpPosition =   1  '所有者中心
   Begin VB.Frame FrameBG 
      Height          =   3300
      Left            =   0
      TabIndex        =   6
      Top             =   -120
      Width           =   6375
      Begin VB.ComboBox cbo 
         Height          =   300
         Left            =   1290
         Style           =   2  'Dropdown List
         TabIndex        =   0
         Top             =   690
         Width           =   4590
      End
      Begin VB.TextBox txt 
         Height          =   990
         Index           =   2
         Left            =   1290
         MaxLength       =   500
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   3
         Top             =   1485
         Width           =   4605
      End
      Begin VB.CommandButton cmdCancel 
         Cancel          =   -1  'True
         Caption         =   "取消(&C)"
         Height          =   375
         Left            =   4725
         TabIndex        =   5
         Top             =   2700
         Width           =   1080
      End
      Begin VB.CommandButton cmdSale 
         Caption         =   "确定(&O)"
         Height          =   375
         Left            =   3405
         TabIndex        =   4
         Top             =   2700
         Width           =   1080
      End
      Begin VB.TextBox txt 
         Height          =   270
         IMEMode         =   3  'DISABLE
         Index           =   1
         Left            =   3420
         TabIndex        =   2
         Top             =   1095
         Width           =   1095
      End
      Begin VB.TextBox txt 
         Height          =   270
         IMEMode         =   3  'DISABLE
         Index           =   0
         Left            =   1290
         TabIndex        =   1
         Top             =   1095
         Width           =   1095
      End
      Begin VB.PictureBox picTitle 
         Appearance      =   0  'Flat
         BackColor       =   &H00808080&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   360
         Left            =   30
         ScaleHeight     =   360
         ScaleWidth      =   6315
         TabIndex        =   7
         TabStop         =   0   'False
         Top             =   120
         Width           =   6315
         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        =   8
            Top             =   90
            Width           =   1350
         End
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         Caption         =   "元"
         Height          =   180
         Left            =   2430
         TabIndex        =   13
         Top             =   1140
         Width           =   180
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         Caption         =   "备注"
         Height          =   180
         Left            =   405
         TabIndex        =   12
         Top             =   1515
         Width           =   360
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         Caption         =   "数量"
         Height          =   180
         Left            =   2910
         TabIndex        =   11
         Top             =   1155
         Width           =   360
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Caption         =   "销售单价"
         Height          =   180
         Left            =   405
         TabIndex        =   10
         Top             =   1155
         Width           =   720
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         Caption         =   "商品名称"
         Height          =   180
         Left            =   405
         TabIndex        =   9
         Top             =   780
         Width           =   720
      End
   End
End
Attribute VB_Name = "frmSale"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Sale As clsSale     '销售对象

'验证用户输入的有效性
Private Function IsOK() As Boolean
  '除备注外的项目必须全部填写
  If txt(0) = "" Or txt(1) = "" Or cbo.Text = "" Then
     MsgBox "除备注外,请把所有项目填写完整!", vbInformation
     Exit Function
  End If
  
  '售价和数量必须为数字
  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 cmdSale_Click()
  '用户输入无效则退出该过程的执行
  If Not IsOK Then Exit Sub
  
  '初始化销售对象
  Set Sale = New clsSale
  With Sale
    '为销售对象的属性赋值
    .GoodsID = cbo.ItemData(cbo.ListIndex)
    .UnitPrice = Val(txt(0))
    .Amount = Val(txt(1))
    .RegistrarID = UserID
    .Remark = IIf(Trim(txt(2)) = "", "无", RTrim(txt(2)))
    '根据cmdSale的Caption属性修改或添加销售对象
    Select Case cmdSale.Caption
      Case "修改(&M)": UpdateSale  '修改销售对象
      Case Else: AddNewSale        '添加销售对象
    End Select
  End With
  cbo.SetFocus
End Sub

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

'添加销售对象
Private Sub AddNewSale()
  Dim AddNewResult As gxcAddNew   '添加结果
  '添加销售对象并返回添加结果
  AddNewResult = Sale.AddNew
  '添加成功之后的操作
  If AddNewResult = AddNewOK Then
     txt(0) = "": txt(1) = "": txt(2) = ""
     Dim Sales As New clsSales    '销售对象集
     '按照编号查询刚添加的销售对象
     Sales.Query Sale.ID
     '当前操作处于浏览销售信息状态,则在列表视图上添加销售信息
     If CurrentOperation = BrowseSale Then ShowObjInLvw Sales.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 New clsGoodses   '商品对象集
  Dim i As Long
  
  '检索所有商品
  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 + -