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

📄 frmtian.frm

📁 档案管理
💻 FRM
📖 第 1 页 / 共 2 页
字号:
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         Caption         =   "提案编号"
         Height          =   195
         Left            =   1920
         TabIndex        =   6
         Top             =   360
         Width           =   720
      End
   End
End
Attribute VB_Name = "frmtian"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim rs_tian As New ADODB.Recordset
Dim tian_bm

Private Sub Command1_Click()
On Error GoTo nexterror
rs_tian.MoveNext
If rs_tian.EOF Then
   MsgBox "这已经是最后一条记录!", vbOKOnly + vbExclamation, ""
   rs_tian.MovePrevious
   Exit Sub
Else
   viewdata
End If
nexterror:
If Err.Number <> 0 Then
   MsgBox Err.Description
End If
End Sub

Private Sub Command10_Click()
viewdata
If Command6.Caption = "确定" Then
   Command6.Caption = "增加记录"
   Command7.Enabled = True
   Command8.Enabled = True
   Command10.Enabled = False
ElseIf Command7.Caption = "确定" Then
   Command7.Caption = "修改记录"
   Command6.Enabled = True
   Command8.Enabled = True
   Command10.Enabled = False
End If
Frame2.Enabled = True
End Sub

Private Sub Command2_Click()
On Error GoTo previouserror
rs_tian.MovePrevious
If rs_tian.BOF Then
   MsgBox "这已经是第一条记录!", vbOKOnly + vbExclamation, ""
   rs_tian.MoveNext
   Exit Sub
Else
   viewdata
End If
previouserror:
If Err.Number <> 0 Then
   MsgBox Err.Description
End If
End Sub

Private Sub Command3_Click()
On Error GoTo firsterror
rs_tian.MoveFirst
If rs_tian.EOF Then
   Exit Sub
Else
   viewdata
End If
firsterror:
If Err.Number <> 0 Then
   MsgBox Err.Description
End If
End Sub

Private Sub Command4_Click()
On Error GoTo firsterror
rs_tian.MoveLast
If rs_tian.EOF Then
   Exit Sub
Else
   viewdata
End If
firsterror:
If Err.Number <> 0 Then
   MsgBox Err.Description
End If
End Sub

Private Sub Command6_Click()
Dim i As Integer
Dim rs_add As New ADODB.Recordset
Dim sql As String
On Error GoTo adderror
'tian_bm = rs_tian.Bookmark
Frame2.Enabled = False
If Command6.Caption = "增加记录" Then                        '当此按钮的状态为为“增加记录”时
   Command6.Caption = "确定"                                 '按钮名称改为“确定”
   Command7.Enabled = False                                  '删除与修改按钮不可用
   Command8.Enabled = False
   Command10.Enabled = True
   For i = 0 To 10
       Text1(i).Enabled = True                               '各文本框可用
       Text1(i).Text = ""                                    '文本框内容设为空
   Next i
Else                                                         '当按钮的状态为“确定”时
   If Trim(Text1(0).Text) = "" Then
      MsgBox "提案编号不能为空", vbOKOnly + vbExclamation, ""
      Text1(0).SetFocus
      Exit Sub
   End If
   If Not IsDate(Text1(5).Text) Then
      MsgBox "请按照yyyy-mm-dd格式输入日期", vbOKOnly + vbExclamation, ""
      Text1(5).SetFocus
      Exit Sub
   End If
   If Not IsDate(Text1(6).Text) Then
      MsgBox "请按照yyyy-mm-dd格式输入日期", vbOKOnly + vbExclamation, ""
      Text1(6).SetFocus
      Exit Sub
   End If
'判断编号是否有重复
   sql = "select * from 提案管理 where 提案编号 ='" & Text1(0).Text & "'"
   rs_add.Open sql, conn, adOpenKeyset, adLockPessimistic
   If rs_add.EOF Then
      Text1(5) = Format(Text1(5), "yyyy-mm-dd")                 '转化为正确的格式
      Text1(6) = Format(Text1(6), "yyyy-mm-dd")
      Command6.Caption = "增加记录"                             '按钮名称改为“增加记录”
      Command7.Enabled = True                                   '删除与修改按钮可用
      Command8.Enabled = True
      Command10.Enabled = False
      rs_tian.AddNew
      For i = 0 To 10
          rs_tian.Fields(i) = Trim(Text1(i).Text)
      Next i
      rs_tian.Update
      MsgBox "增加成功", vbOKOnly + vbExclamation, ""
      For i = 0 To 10
       Text1(i).Enabled = False
      Next i
      Frame2.Enabled = True
Else
   MsgBox "提案编号重复", vbOKOnly + vbExclamation, ""
   Exit Sub
End If
End If
adderror:
If Err.Number <> 0 Then
   MsgBox Err.Description
End If
End Sub

Private Sub Command7_Click()
Dim sql As String
Dim rs_modify As New ADODB.Recordset
Dim i As Integer
On Error GoTo modifyerror
'tian_bm = rs_tian.Bookmark
Frame2.Enabled = False
If Command7.Caption = "修改记录" Then                        '当此按钮的状态为为“增加记录”时
   Command7.Caption = "确定"                                 '按钮名称改为“确定”
   Command6.Enabled = False                                  '删除与修改按钮不可用
   Command8.Enabled = False
   Command10.Enabled = True
   For i = 1 To 10                                           '编号不可以改变
       Text1(i).Enabled = True                               '各文本框可用
   Next i
ElseIf Command7.Caption = "确定" Then                        '当按钮的状态为“确定”时
   If Trim(Text1(0).Text) = "" Then
      MsgBox "提案编号不能为空", vbOKOnly + vbExclamation, ""
      Text1(0).SetFocus
      Exit Sub
   End If
   If Not IsDate(Text1(5).Text) Then
      MsgBox "请按照yyyy-mm-dd格式输入日期", vbOKOnly + vbExclamation, ""
      Text1(5).SetFocus
      Exit Sub
   End If
   If Not IsDate(Text1(6).Text) Then
      MsgBox "请按照yyyy-mm-dd格式输入日期", vbOKOnly + vbExclamation, ""
      Text1(6).SetFocus
      Exit Sub
   End If
   Text1(5) = Format(Text1(5), "yyyy-mm-dd")                 '转化为正确的格式
   Text1(6) = Format(Text1(6), "yyyy-mm-dd")
   Command7.Caption = "修改记录"                             '按钮名称改为“修改记录”
   Command6.Enabled = True                                   '删除与增加按钮可用
   Command8.Enabled = True
   Command10.Enabled = False
   For i = 0 To 10
       rs_tian.Fields(i) = Trim(Text1(i).Text)
   Next i
   rs_tian.Update
   MsgBox "修改成功", vbOKOnly + vbExclamation, ""
   Frame2.Enabled = True
End If
modifyerror:
If Err.Number <> 0 Then
   MsgBox Err.Description
End If
End Sub

Private Sub Command8_Click()
Dim i As Integer
Dim answer As String
On Error GoTo delerror
answer = MsgBox("确定要删除吗?", vbYesNo, "")
If answer = vbYes Then
   rs_tian.Delete
   rs_tian.MoveNext
   If rs_tian.EOF Then
      rs_tian.MoveFirst
   End If
      viewdata
Else
   viewdata
End If
delerror:
If Err.Number <> 0 Then
   MsgBox Err.Description
End If
End Sub

Private Sub Form_Load()
Dim sql As String
On Error GoTo loaderror
sql = "select * from 提案管理"
rs_tian.CursorLocation = adUseClient
rs_tian.Open sql, conn, adOpenKeyset, adLockPessimistic     '打开数据库
If userpow = "guest" Then
   Frame3.Enabled = False
End If
If rs_tian.EOF = False Then
   rs_tian.MoveFirst
   viewdata
Else
   MsgBox "没有记录!", vbOKOnly + vbExclamation, ""
End If
Command10.Enabled = False
loaderror:
If Err.Number <> 0 Then
   MsgBox Err.Description
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
rs_tian.Close
End Sub

Public Sub viewdata()
Dim i As Integer
On Error GoTo viewerror
For i = 0 To 10
       If IsNull(rs_tian.Fields(i)) Then
          Text1(i).Text = ""
       Else
          Text1(i).Text = rs_tian.Fields(i)
       End If
          Text1(i).Enabled = False
Next i
viewerror:
If Err.Number <> 0 Then
   MsgBox Err.Description
End If
End Sub

⌨️ 快捷键说明

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