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

📄 form_output.frm

📁 运用VB和SQL Server实现
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form Form_Output 
   Caption         =   "日常支出表"
   ClientHeight    =   5355
   ClientLeft      =   3870
   ClientTop       =   2655
   ClientWidth     =   7980
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   5355
   ScaleWidth      =   7980
   Begin MSAdodcLib.Adodc Adodc_Output 
      Height          =   330
      Left            =   600
      Top             =   4920
      Visible         =   0   'False
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc_Output"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.CommandButton Command4 
      Caption         =   "退出"
      Height          =   375
      Left            =   6600
      TabIndex        =   5
      Top             =   4800
      Width           =   1215
   End
   Begin VB.CommandButton Command3 
      Caption         =   "删除"
      Height          =   375
      Left            =   5120
      TabIndex        =   4
      Top             =   4800
      Width           =   1215
   End
   Begin VB.CommandButton Command2 
      Caption         =   "修改"
      Height          =   375
      Left            =   3640
      TabIndex        =   3
      Top             =   4800
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "添加"
      Height          =   375
      Left            =   2160
      TabIndex        =   2
      Top             =   4800
      Width           =   1215
   End
   Begin MSDataGridLib.DataGrid DataGrid_Output 
      Bindings        =   "Form_Output.frx":0000
      Height          =   2415
      Left            =   120
      TabIndex        =   1
      Top             =   120
      Width           =   7695
      _ExtentX        =   13573
      _ExtentY        =   4260
      _Version        =   393216
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   2052
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   2052
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin VB.Frame Frame1 
      Height          =   2175
      Left            =   120
      TabIndex        =   0
      Top             =   2520
      Width           =   7695
      Begin MSComCtl2.DTPicker DTPicker1 
         Height          =   375
         Left            =   1440
         TabIndex        =   15
         Top             =   360
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   661
         _Version        =   393216
         Format          =   25559041
         CurrentDate     =   39220
      End
      Begin VB.ComboBox Combo2 
         Height          =   315
         Left            =   1440
         TabIndex        =   9
         Top             =   1560
         Width           =   1335
      End
      Begin VB.ComboBox Combo1 
         Height          =   315
         Left            =   1440
         TabIndex        =   8
         Top             =   990
         Width           =   1335
      End
      Begin VB.TextBox Text_Output_BZ 
         Height          =   975
         Left            =   4560
         TabIndex        =   7
         Top             =   960
         Width           =   2775
      End
      Begin VB.TextBox Text_Output_money 
         Height          =   375
         Left            =   4560
         TabIndex        =   6
         Top             =   360
         Width           =   1575
      End
      Begin VB.Label Label5 
         Caption         =   "备注:"
         Height          =   375
         Left            =   3600
         TabIndex        =   14
         Top             =   1080
         Width           =   1095
      End
      Begin VB.Label Label4 
         Caption         =   "支出金额:"
         Height          =   375
         Left            =   3600
         TabIndex        =   13
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label3 
         Caption         =   "支出类型:"
         Height          =   375
         Left            =   240
         TabIndex        =   12
         Top             =   1560
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "支出人员:"
         Height          =   375
         Left            =   240
         TabIndex        =   11
         Top             =   960
         Width           =   975
      End
      Begin VB.Label Label1 
         Caption         =   "支出日期:"
         Height          =   375
         Left            =   240
         TabIndex        =   10
         Top             =   360
         Width           =   975
      End
   End
End
Attribute VB_Name = "Form_Output"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()    '添加一个记录
Dim sqlstr As String
Dim rsdb As New adodb.Recordset
Dim Num As Integer
If Me.DTPicker1.Value = "" Or Me.Text_Output_money = "" Or Me.Combo1.Text = "" Or Me.Combo2.Text = "" Then
    MsgBox "不能空白!"
    Exit Sub
End If

If Not IsNumeric(Me.Text_Output_money) Then
    MsgBox "支出金额必须是数字"
    Exit Sub
End If

On Error Resume Next
'查找对应人员编号的姓名
rsdb.Open "select * from Family where FamilyName=" & "'" & Me.Combo1.Text & "'", RemoteCnn, adOpenStatic, adLockReadOnly, -1
    If rsdb.RecordCount > 0 Then
        If Not rsdb.EOF Then rsdb.MoveFirst
        Num = Val(rsdb.Fields("FamilyID").Value)
    End If
rsdb.Close
'添加一个记录到数据库
sqlstr = "insert into DailyOutput" & "(DailyOutputDate,DailyOutputName,DailyOutputType,DailyOutputNum,DailyOutputBZ)" & _
        "values(" & "'" & Me.DTPicker1.Value & "'," & _
                    Num & "," & _
                    Val(Me.Combo2.Text) & "," & _
                    Val(Me.Text_Output_money.Text) & "," & _
                    "'" & Me.Text_Output_BZ.Text & "');"
RemoteCnn.Execute sqlstr
MsgBox "添加成功!"
'更新界面
Me.Adodc_Output.Refresh
End Sub

Private Sub Command2_Click()    '修改一个记录
Dim sqlstr As String
Dim rsdb As New adodb.Recordset
Dim Num As Integer
If Me.DTPicker1.Value = "" Or Me.Text_Output_money = "" Or Me.Combo1.Text = "" Or Me.Combo2.Text = "" Then
    MsgBox "不能空白!"
    Exit Sub
End If
On Error Resume Next
'查找对应人员编号的姓名
rsdb.Open "select * from Family where FamilyName=" & "'" & Me.Combo1.Text & "'", RemoteCnn, adOpenStatic, adLockReadOnly, -1
    If rsdb.RecordCount > 0 Then
        If Not rsdb.EOF Then rsdb.MoveFirst
        Num = Val(rsdb.Fields("FamilyID").Value)
    End If
rsdb.Close
'修改选定的记录
sqlstr = "update DailyOutput set DailyOutputDate=" & "'" & Me.DTPicker1.Value & "'," & _
                               "DailyOutputName=" & Num & "," & _
                               "DailyOutputType=" & Val(Me.Combo2.Text) & "," & _
                               "DailyOutputNum=" & Val(Me.Text_Output_money.Text) & "," & _
                               "DailyOutputBZ=" & "'" & Me.Text_Output_BZ.Text & "' " & _
                               "where DailyOutputID=" & Val(DataGrid_Output.Columns(0).Text)
RemoteCnn.Execute sqlstr
MsgBox "修改成功!"
'更新界面
Me.Adodc_Output.Refresh
End Sub

Private Sub Command3_Click()    '删除一个记录
'是否选定了要删除的记录
If Me.DataGrid_Output.Row = -1 Then
    MsgBox "没有数据"
    Exit Sub
End If
'删除选定的记录
Me.Adodc_Output.Recordset.Delete
MsgBox "删除成功"
End Sub

Private Sub Command4_Click()
Unload Me
End Sub

Private Sub DataGrid_Output_Click() '选择一个记录
Dim str As String
Dim rsdb As New adodb.Recordset
On Error Resume Next
'查找对应人员编号的姓名
rsdb.Open "select * from Family where FamilyID=" & Val(DataGrid_Output.Columns(2).Text), RemoteCnn, adOpenStatic, adLockReadOnly, -1
    If rsdb.RecordCount > 0 Then
        If Not rsdb.EOF Then rsdb.MoveFirst
        str = rsdb.Fields("FamilyName").Value
    End If
rsdb.Close
'在界面上显示选定记录
Me.DTPicker1.Value = DataGrid_Output.Columns(1).Text
Me.Combo1.Text = str
Me.Combo2.Text = Me.Combo2.list(Val(DataGrid_Output.Columns(3).Text) - 1)
Me.Text_Output_money.Text = DataGrid_Output.Columns(4).Text
Me.Text_Output_BZ.Text = DataGrid_Output.Columns(5).Text
End Sub

Private Sub Form_Load() '窗体装载
Dim rsdb As New adodb.Recordset
Dim I As Integer
On Error Resume Next
'打开日常支出表并填充表格
Me.Adodc_Output.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=" & UID & ";pwd=" & PWD & ";Data Source=" & MyDSN
Adodc_Output.RecordSource = "select DailyOutputID as 编号,DailyOutputDate as 支出日期,DailyOutputName as 支出人员,DailyOutputType as 支出类型,DailyOutputNum as 支出金额,DailyOutputBZ as 备注 from DailyOutput"
Adodc_Output.Refresh
'填充支出类型框
rsdb.Open "select * from OutputType", RemoteCnn, adOpenStatic, adLockReadOnly, -1
    If rsdb.RecordCount > 0 Then
        If Not rsdb.BOF Then rsdb.MoveFirst
        For I = 1 To rsdb.RecordCount
            Me.Combo2.AddItem rsdb.Fields("OutputTypeID").Value & ":" & rsdb.Fields("OutputTypeType").Value
            If Not rsdb.EOF Then rsdb.MoveNext
        Next I
    End If
rsdb.Close
'填充支出人员框
rsdb.Open "select * from Family", RemoteCnn, adOpenStatic, adLockReadOnly, -1
    If rsdb.RecordCount > 0 Then
        If Not rsdb.BOF Then rsdb.MoveFirst
        For I = 1 To rsdb.RecordCount
            Me.Combo1.AddItem rsdb.Fields("FamilyName").Value
            If Not rsdb.EOF Then rsdb.MoveNext
        Next I
    End If
rsdb.Close
End Sub

⌨️ 快捷键说明

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