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

📄 delpay.frm

📁 感觉还可以了 大家看看 指点下 有什么不足的地方,大家多多指教啊
💻 FRM
字号:
VERSION 5.00
Begin VB.Form DelPay 
   Caption         =   "删除"
   ClientHeight    =   3165
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   3675
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   3165
   ScaleWidth      =   3675
   StartUpPosition =   3  '窗口缺省
   Begin VB.Frame Frame1 
      Caption         =   "定位要删除的工资记录"
      Height          =   2895
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   3375
      Begin VB.CommandButton Command2 
         Caption         =   "取消"
         Height          =   495
         Left            =   1920
         TabIndex        =   9
         Top             =   2040
         Width           =   1215
      End
      Begin VB.CommandButton Command1 
         Caption         =   "删除"
         Default         =   -1  'True
         Height          =   495
         Left            =   360
         TabIndex        =   8
         Top             =   2040
         Width           =   1215
      End
      Begin VB.ComboBox Combo2 
         Height          =   300
         Left            =   1920
         TabIndex        =   5
         Text            =   "Combo2"
         Top             =   1440
         Width           =   855
      End
      Begin VB.ComboBox Combo1 
         Height          =   300
         ItemData        =   "DelPay.frx":0000
         Left            =   360
         List            =   "DelPay.frx":0002
         TabIndex        =   4
         Text            =   "Combo1"
         Top             =   1425
         Width           =   1215
      End
      Begin VB.TextBox Text1 
         Height          =   270
         Left            =   360
         TabIndex        =   1
         Text            =   "Text1"
         Top             =   720
         Width           =   2655
      End
      Begin VB.Label Label5 
         Caption         =   "月"
         Height          =   255
         Left            =   2880
         TabIndex        =   7
         Top             =   1470
         Width           =   255
      End
      Begin VB.Label Label4 
         Caption         =   "年"
         Height          =   255
         Left            =   1680
         TabIndex        =   6
         Top             =   1470
         Width           =   255
      End
      Begin VB.Label Label3 
         Caption         =   "工资月份"
         Height          =   255
         Left            =   360
         TabIndex        =   3
         Top             =   1200
         Width           =   1215
      End
      Begin VB.Label Label1 
         Caption         =   "职工ID"
         Height          =   255
         Left            =   360
         TabIndex        =   2
         Top             =   480
         Width           =   2175
      End
   End
End
Attribute VB_Name = "DelPay"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
    Dim sql As String
    Dim rs As New ADODB.Recordset
    Dim paydate As String
    
    If Text1.Text = "" Then     '检查输入数据有效性
        MsgBox "职工ID不能为空!", vbCritical
        Text1.SetFocus
        Exit Sub
    End If
    If Combo1.ListIndex = -1 Then
        MsgBox "年份必须选择!", vbCritical
        Combo1.SetFocus
        Exit Sub
    End If
    If Combo2.ListIndex = -1 Then
        MsgBox "月份必须选择!", vbCritical
        Combo2.SetFocus
        Exit Sub
    End If
    paydate = Combo1.List(Combo1.ListIndex) & "-" & Combo2.List(Combo2.ListIndex)
    '组合年月成为一体的日期
    If DbHandle.DbConnection Then
        sql = "TBL_USER"        '从职工表中判断是否存在输入的职工ID
        rs.CursorType = adOpenDynamic
        rs.LockType = adLockOptimistic
        rs.Filter = "USER_ID='" & Text1.Text & "'"
        rs.Open sql, DbFinance
        If DbHandle.resultcount(rs) <> 1 Then       '不存在提示出错,并且释放数据库,退出
            MsgBox "错误,不存在的职工ID号!", vbExclamation
            Text1.SetFocus
            rs.Close
            Set rs = Nothing
            DbHandle.DbClose
            Exit Sub
        End If
        rs.Close        '存在输入职工ID,在工资表中查看工资记录是否存在
        sql = "TBL_PAY"
        rs.CursorType = adOpenDynamic
        rs.LockType = adLockOptimistic
        rs.Filter = "PAY_USER='" & Text1.Text & "' AND PAY_DATE='" & paydate & "'"
        rs.Open sql, DbFinance
        If DbHandle.resultcount(rs) <> 1 Then       '不存在,无法删除
            MsgBox "工资记录不存在!", vbExclamation
            rs.Close
            DbHandle.DbClose
            Exit Sub
        End If
        rs.Delete       '存在,删除工资记录,提示成功,返回主窗体
        rs.Close
        DbHandle.DbClose
        MsgBox "工资记录已经成功删除!"
        Unload Me
    Else        '数据库连接出错,退出
        MsgBox "数据库错误!", vbExclamation
        DbHandle.DbClose
        End
    End If
End Sub

Private Sub Command2_Click()
    Unload Me       '返回主窗体
End Sub

Private Sub Form_Load()
    Dim i As Long
    
    Me.Left = (Screen.Width - Me.ScaleWidth) / 2        '窗体居中显示
    Me.Top = (Screen.Height - Me.ScaleHeight) / 2
    For i = 2003 To 2030        '设置年月下拉列表2003-2030年间
        Combo1.AddItem Trim(Str(i))
    Next i
    For i = 1 To 12     '1-12月间
        Combo2.AddItem Trim(Str(i))
    Next i
    Text1.Text = ""     '设置窗体元素初始化属性
    Combo1.Text = ""
    Combo2.Text = ""
End Sub

Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
    DbHandle.DbClose        '窗体关闭时关闭数据库连接
End Sub

⌨️ 快捷键说明

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