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

📄 frmspoilage.frm

📁 <Visual Basic 数据库开发实例精粹(第二版)>一书首先介绍了Visual Basic(简称VB)开发的技巧和重点技术
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmSpoilage 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "报损管理"
   ClientHeight    =   3585
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6375
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   ScaleHeight     =   3585
   ScaleWidth      =   6375
   StartUpPosition =   1  '所有者中心
   Begin VB.Frame FrameBG 
      Height          =   3705
      Left            =   0
      TabIndex        =   7
      Top             =   -120
      Width           =   6375
      Begin VB.TextBox txt 
         Height          =   990
         Index           =   4
         Left            =   1305
         MaxLength       =   500
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   4
         Top             =   1890
         Width           =   4620
      End
      Begin VB.PictureBox picTitle 
         Appearance      =   0  'Flat
         BackColor       =   &H00808080&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   360
         Left            =   30
         ScaleHeight     =   360
         ScaleWidth      =   6315
         TabIndex        =   8
         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        =   9
            Top             =   90
            Width           =   1350
         End
      End
      Begin VB.TextBox txt 
         Height          =   285
         Index           =   0
         Left            =   1290
         TabIndex        =   0
         Top             =   690
         Width           =   1755
      End
      Begin VB.TextBox txt 
         Enabled         =   0   'False
         Height          =   270
         IMEMode         =   3  'DISABLE
         Index           =   1
         Left            =   1290
         TabIndex        =   1
         Top             =   1095
         Width           =   4635
      End
      Begin VB.TextBox txt 
         Height          =   285
         IMEMode         =   3  'DISABLE
         Index           =   2
         Left            =   1305
         TabIndex        =   2
         Top             =   1485
         Width           =   1755
      End
      Begin VB.CommandButton cmdSpoilage 
         Caption         =   "确定(&C)"
         Height          =   375
         Left            =   3405
         TabIndex        =   5
         Top             =   3075
         Width           =   1080
      End
      Begin VB.CommandButton cmdCancel 
         Cancel          =   -1  'True
         Caption         =   "取消(&C)"
         Height          =   375
         Left            =   4725
         TabIndex        =   6
         Top             =   3075
         Width           =   1080
      End
      Begin VB.TextBox txt 
         Height          =   285
         Index           =   3
         Left            =   4170
         MaxLength       =   5
         TabIndex        =   3
         Top             =   1485
         Width           =   1755
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         Caption         =   "进货编号"
         Height          =   180
         Left            =   405
         TabIndex        =   14
         Top             =   750
         Width           =   720
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         Caption         =   "商品名称"
         Height          =   180
         Left            =   405
         TabIndex        =   13
         Top             =   1155
         Width           =   720
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Caption         =   "报损数量"
         Height          =   180
         Left            =   405
         TabIndex        =   12
         Top             =   1545
         Width           =   720
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         Caption         =   "报损人"
         Height          =   180
         Left            =   3435
         TabIndex        =   11
         Top             =   1545
         Width           =   540
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         Caption         =   "报损原因"
         Height          =   180
         Left            =   405
         TabIndex        =   10
         Top             =   1920
         Width           =   720
      End
   End
End
Attribute VB_Name = "frmSpoilage"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Spoilage As clsSpoilage    '报损对象

'验证用户输入的有效性
Private Function IsOK() As Boolean
  Dim i As Long

  '所有项目必须全部填写
  For i = 0 To 4
    If txt(i) = "" Then
       MsgBox "请把所有项目填写完整!", vbInformation
       Exit Function
    End If
  Next i
  
  '报损数量必须为数字
  If Not IsNumeric(txt(2)) Then
     MsgBox "报损数量不是数字,请重新填写!", vbInformation
     txt(2).SetFocus
     Exit Function
  End If
  
  '返回函数值
  IsOK = True
End Function

Private Sub cmdSpoilage_Click()
  '用户输入无效则退出该过程的执行
  If Not IsOK Then Exit Sub
  
  '初始化报损对象
  Set Spoilage = New clsSpoilage
  With Spoilage
    '为报损对象的属性赋值
    .BuyId = Val(txt(0))
    .Amount = Val(txt(2))
    .Reportor = Trim(txt(3))
    .RegistrarID = UserID
    .Reason = RTrim(txt(4))
    '根据cmdSpoilage的Caption属性修改或添加报损对象
    Select Case cmdSpoilage.Caption
      Case "修改(&M)": UpdateSpoilage  '修改报损对象
      Case Else: AddNewSpoilage        '添加报损对象
    End Select
  End With
  txt(0).SetFocus
End Sub

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

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

Private Sub cmdCancel_Click()
  Unload Me
End Sub

Private Sub txt_LostFocus(Index As Integer)
  '仅对txt(0)执行失去焦点后操作
  If Index <> 0 Then Exit Sub
  
  '防止不能点击cmdCancel按钮
  If TypeOf Screen.ActiveControl Is CommandButton Then
     If Screen.ActiveControl.Caption = "取消(&C)" Then Exit Sub
  End If
  
  '进货编号必须是数字
  If Not IsNumeric(txt(Index)) Then
     MsgBox "进货编号不是数字,请重新输入。", vbInformation
     txt(Index).SetFocus
     Exit Sub
  End If
  
  Dim Buys As New clsBuys   '报损对象
  '按照txt(0)的值查询报损信息
  Buys.Query Val(txt(Index))
  If Buys.Count > 0 Then
     '如果返回进货信息则在txt(1)显示商品名称
     txt(1) = Buys.Item(1).GoodsName
  Else
     '如果没有返回进货信息则提示用户
     txt(1) = ""
     If MsgBox("该进货编号不存在,要放弃修改吗?", vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then
        txt(0).SetFocus
     Else
        Unload Me
     End If
  End If
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 + -