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

📄 form_type.frm

📁 运用VB和SQL Server实现
💻 FRM
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form_Type 
   Caption         =   "收支项目"
   ClientHeight    =   4950
   ClientLeft      =   3870
   ClientTop       =   2400
   ClientWidth     =   4965
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   4950
   ScaleWidth      =   4965
   Begin MSComctlLib.TabStrip TabStrip1 
      Height          =   255
      Left            =   360
      TabIndex        =   0
      Top             =   120
      Width           =   1850
      _ExtentX        =   3254
      _ExtentY        =   450
      _Version        =   393216
      BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
         NumTabs         =   2
         BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "收入来源"
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "支出类型"
            ImageVarType    =   2
         EndProperty
      EndProperty
   End
   Begin VB.Frame Frame2 
      Height          =   4215
      Left            =   360
      TabIndex        =   6
      Top             =   360
      Width           =   4215
      Begin VB.ListBox List2 
         Height          =   3570
         Left            =   240
         TabIndex        =   11
         Top             =   240
         Width           =   1695
      End
      Begin VB.TextBox Text2 
         Height          =   375
         Left            =   2280
         TabIndex        =   10
         Top             =   1560
         Width           =   1575
      End
      Begin VB.CommandButton Command5 
         Caption         =   "添加"
         Height          =   375
         Left            =   2880
         TabIndex        =   9
         Top             =   2160
         Width           =   1095
      End
      Begin VB.CommandButton Command7 
         Caption         =   "删除"
         Height          =   375
         Left            =   2520
         TabIndex        =   8
         Top             =   3120
         Width           =   1095
      End
      Begin VB.CommandButton Command8 
         Caption         =   "退出"
         Height          =   375
         Left            =   2520
         TabIndex        =   7
         Top             =   3600
         Width           =   1095
      End
      Begin VB.Frame Frame4 
         Caption         =   "编辑框"
         Height          =   2535
         Left            =   2160
         TabIndex        =   14
         Top             =   240
         Width           =   1935
         Begin VB.TextBox Text3 
            Height          =   375
            Left            =   120
            TabIndex        =   17
            Top             =   480
            Width           =   1575
         End
         Begin VB.Label Label2 
            Caption         =   "新添支出类型:"
            Height          =   375
            Left            =   120
            TabIndex        =   16
            Top             =   960
            Width           =   1335
         End
         Begin VB.Label Label1 
            Caption         =   "编号:"
            Height          =   375
            Left            =   120
            TabIndex        =   15
            Top             =   240
            Width           =   735
         End
      End
   End
   Begin VB.Frame Frame1 
      Height          =   4215
      Left            =   360
      TabIndex        =   1
      Top             =   360
      Width           =   4215
      Begin VB.CommandButton Command2 
         Caption         =   "退出"
         Height          =   375
         Left            =   2640
         TabIndex        =   13
         Top             =   3360
         Width           =   1095
      End
      Begin VB.CommandButton Command3 
         Caption         =   "删除"
         Height          =   375
         Left            =   2640
         TabIndex        =   5
         Top             =   2880
         Width           =   1095
      End
      Begin VB.CommandButton Command1 
         Caption         =   "添加"
         Height          =   375
         Left            =   2640
         TabIndex        =   4
         Top             =   2040
         Width           =   1095
      End
      Begin VB.TextBox Text1 
         Height          =   375
         Left            =   2280
         TabIndex        =   3
         Top             =   1440
         Width           =   1455
      End
      Begin VB.ListBox List1 
         Height          =   3570
         Left            =   240
         TabIndex        =   2
         Top             =   240
         Width           =   1695
      End
      Begin VB.Frame Frame3 
         Caption         =   "编辑框"
         Height          =   2295
         Left            =   2040
         TabIndex        =   12
         Top             =   240
         Width           =   1935
         Begin VB.TextBox Text4 
            Height          =   375
            Left            =   240
            TabIndex        =   19
            Top             =   480
            Width           =   1455
         End
         Begin VB.Label Label4 
            Caption         =   "编号:"
            Height          =   255
            Left            =   240
            TabIndex        =   20
            Top             =   240
            Width           =   1095
         End
         Begin VB.Label Label3 
            Caption         =   "新添收入来源:"
            Height          =   255
            Left            =   120
            TabIndex        =   18
            Top             =   960
            Width           =   1455
         End
      End
   End
End
Attribute VB_Name = "Form_Type"
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

If Me.Text1.Text = "" Or Me.Text4.Text = "" Then
    MsgBox "不能为空!"
    Exit Sub
End If

If IsNumeric(Me.Text4.Text) = False Then
    MsgBox "编号只能为数字"
    Exit Sub
End If

On Error GoTo Err
'判断该项是否已经存在
rsdb.Open "select * from IncomeType where IncomeTypeID =" & _
Val(Me.Text4.Text), RemoteCnn, adOpenStatic, adLockReadOnly, -1
If rsdb.RecordCount > 0 Then
    MsgBox "已经存在该编号"
    Exit Sub
End If
rsdb.Close

rsdb.Open "select * from IncomeType where IncomeTypeType=" & "'" & _
Trim(Me.Text1.Text) & "'", RemoteCnn, adOpenStatic, adLockReadOnly, -1
If rsdb.RecordCount > 0 Then
    MsgBox "已经存在该项目"
    Exit Sub
End If
rsdb.Close

'添加到数据库
sqlstr = "insert into IncomeType " & "(IncomeTypeID,IncomeTypeType)" & _
"values(" & Val(Me.Text4.Text) & ",'" & Me.Text1.Text & "');"
RemoteCnn.Execute sqlstr
MsgBox "添加成功!"
'添加到界面中显示
List1.AddItem Me.Text4.Text & ":" & Me.Text1.Text
'编辑框清出
Me.Text1.Text = ""
Me.Text4.Text = ""
On Error GoTo 0
Exit Sub
Err:
    MsgBox "打开数据库错误!"
    End
End Sub


Private Sub Command2_Click()    '退出
Unload Me
End Sub

Private Sub Command3_Click()    '删除收入来源
Dim id As Integer
Dim sqlstr As String
On Error GoTo Err
'删除选定的项
id = Val(Me.List1.List(List1.ListIndex))
sqlstr = "delete from IncomeType where IncomeTypeID=" & id
RemoteCnn.Execute sqlstr
MsgBox " 删除成功!"
'在显示界面中清除该项
List1.RemoveItem List1.ListIndex
On Error GoTo 0
Exit Sub
Err:
    MsgBox "打开数据库错误!"
    End
End Sub

Private Sub Command5_Click()    '添加支出类型
Dim sqlstr As String
Dim rsdb As New ADODB.Recordset

If Me.Text2.Text = "" Or Me.Text3.Text = "" Then
    MsgBox "不能为空!"
    Exit Sub
End If

If IsNumeric(Me.Text3.Text) = False Then
    MsgBox "编号只能为数字"
    Exit Sub
End If

On Error GoTo Err

'判断该项是否已经存在

rsdb.Open "select * from OutputType where OutputTypeID =" & _
Val(Me.Text3.Text), RemoteCnn, adOpenStatic, adLockReadOnly, -1
If rsdb.RecordCount > 0 Then
    MsgBox "已经存在该编号"
    Exit Sub
End If
rsdb.Close

rsdb.Open "select * from OutputType where OutputTypeType=" & "'" & _
Trim(Me.Text2.Text) & "'", RemoteCnn, adOpenStatic, adLockReadOnly, -1
If rsdb.RecordCount > 0 Then
    MsgBox "已经存在该项目"
    Exit Sub
End If
rsdb.Close

'添加到数据库
sqlstr = "insert into OutputType " & "(OutputTypeID,OutputTypeType)" & _
"values(" & Val(Me.Text3.Text) & ",'" & Me.Text2.Text & "');"
RemoteCnn.Execute sqlstr
MsgBox "添加成功!"
'添加到界面中显示
List2.AddItem Me.Text3.Text & ":" & Me.Text2.Text
'编辑框清出
Me.Text2.Text = ""
Me.Text3.Text = ""
On Error GoTo 0
Exit Sub
Err:
    MsgBox "打开数据库错误!"
    End
End Sub

Private Sub Command7_Click()    '删除支出类型
Dim id As Integer
Dim sqlstr As String
On Error GoTo Err
'删除选定的项
id = Val(Me.List2.List(List2.ListIndex))
sqlstr = "delete from OutputType where OutputTypeID=" & id
RemoteCnn.Execute sqlstr
MsgBox " 删除成功!"
'在显示界面中清除该项
List2.RemoveItem List2.ListIndex
On Error GoTo 0
Exit Sub
Err:
    MsgBox "打开数据库错误!"
    End
End Sub

Private Sub Command8_Click()    '退出
Unload Me
End Sub

Private Sub Form_Load()  '窗体装载
Dim rsdb As New ADODB.Recordset
Dim i As Integer
Dim str As String
On Error GoTo Err
'载入收入来源表中的数据
rsdb.Open "select * from IncomeType", RemoteCnn, adOpenStatic, adLockReadOnly, -1
    If rsdb.RecordCount > 0 Then
        If Not rsdb.BOF Then rsdb.MoveFirst
        For i = 1 To rsdb.RecordCount
        str = rsdb.Fields("IncomeTypeID").Value & ":" & _
        rsdb.Fields("IncomeTypeType").Value
        Me.List1.AddItem str, i - 1    '添加到List1中
        If Not rsdb.EOF Then rsdb.MoveNext
        Next i
    End If
rsdb.Close  '关闭记录集
'载入支出类型表中的数据
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
            str = rsdb.Fields("OutputTypeID").Value & ":" & _
            rsdb.Fields("OutputTypeType").Value
            Me.List2.AddItem str, i - 1    '添加到List2中
            If Not rsdb.EOF Then rsdb.MoveNext
        Next i
    End If
rsdb.Close  '关闭记录集
TabStrip1_Click
On Error GoTo 0
Exit Sub
Err:
    MsgBox "打开数据库错误!"
    End
End Sub



Private Sub TabStrip1_Click()
Select Case TabStrip1.SelectedItem.Index
    Case 1:     '显示收入来源界面
        Me.Frame1.Visible = True
        Me.Frame2.Visible = False
    Case 2:     '显示支出类型界面
        Me.Frame1.Visible = False
        Me.Frame2.Visible = True
End Select
End Sub

⌨️ 快捷键说明

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