【VB开源代码栏目提醒】:以下是网学会员为您推荐的VB开源代码-Form4.frm,希望本篇文章对您学习有所帮助。
VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form frmzhiban
Caption = "值班管理"
ClientHeight = 4845
ClientLeft = 60
ClientTop = 450
ClientWidth = 8220
LinkTopic = "Form4"
ScaleHeight = 4845
ScaleWidth = 8220
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdcancel
Caption = "取消"
Height = 375
Left = 5640
TabIndex = 4
Top = 3240
Width = 1095
End
Begin VB.CommandButton cmddel
Caption = "删除纪录"
Height = 375
Left = 3240
TabIndex = 3
Top = 3240
Width = 1095
End
Begin VB.CommandButton cmdadd
Caption = "增加纪录"
Height = 375
Left = 960
TabIndex = 2
Top = 3240
Width = 1335
End
Begin
VB.Frame Frame1
Caption = "值班管理"
Height = 2295
Left = 120
TabIndex = 0
Top = 240
Width = 7935
Begin MSDataGridLib.DataGrid DataGrid1
Height = 1695
Left = 240
TabIndex = 1
Top = 360
Width = 7455
_ExtentX = 13150
_ExtentY = 2990
_Version = 393216
HeadLines = 1
RowHeight = 15
AllowAddNew = -1 'True
AllowDelete = -1 'True
BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
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
End
End
Attribute VB_Name = "frmzhiban"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim rs_zhiban As New ADODB.Recordset
Private Sub cmdadd_Click()
On Error GoTo adderror
If cmdadd.Caption = "确定增加记录" Then '当此按钮的状态为为“增加记录”时
cmdadd.Caption = "确定" '按钮名称改为“确定”
cmddel.Enabled = False
cmdcancel.Enabled = True
DataGrid1.AllowAddNew = True
DataGrid1.AllowUpdate = True '设定datagrid可以增加记录
Else
If Not IsNull(DataGrid1.Bookmark) Then
If Not IsDate(Trim(DataGrid1.Columns("值班开始日期").CellText(DataGrid1.Bookmark))) Then
MsgBox "请按照格式yyyy-mm-dd输入值班开始日期", vbOKOnly + vbExclamation, ""
Exit Sub
End If
If Not IsDate(Trim(DataGrid1.Columns("值班开始时间").CellText(DataGrid1.Bookmark))) Then
MsgBox "请按照格式hh-mm输入值班开始时间", vbOKOnly + vbExclamation, ""
Exit Sub
End If
If Not IsDate(Trim(DataGrid1.Columns("值班截止日期").CellText(DataGrid1.Bookmark))) Then
MsgBox "请按照格式yyyy-mm-dd输入值班截止日期", vbOKOnly + vbExclamation, ""
Exit Sub
End If
If Not IsDate(Trim(DataGrid1.Columns("值班截止时间").CellText(DataGrid1.Bookmark))) Then
MsgBox "请按照格式hh-mm输入值班截止时间", vbOKOnly + vbExclamation, ""
Exit Sub
End If
If Trim(DataGrid1.Columns("值班人").CellText(DataGrid1.Bookmark)) = "" Then
MsgBox "值班人不能为空!", vbOKOnly + vbExclamation, ""
Exit Sub
End If
rs_zhiban.Update
'MsgBox "添加信息成功!", vbOKOnly + vbExclamation, ""
DataGrid1.AllowAddNew = False
DataGrid1.AllowUpdate = False
Else
MsgBox "没有添加信息!", vbOKOnly + vbExclamation, ""
End If
cmdadd.Caption = "确定增加记录"
cmddel.Enabled = True
End If
adderror:
If Err.Number <> 0 Then
MsgBox Err.Description
End If
End Sub
Private Sub cmdcancel_Click()
Unload Me
MDIForm1.Show
End Sub
Private Sub cmddel_Click()
Dim answer As String
On Error GoTo delerror
answer = MsgBox("确定要删除吗?", vbYesNo, "")
If answer = vbYes Then
DataGrid1.AllowDelete = True
rs_zhiban.Delete
rs_zhiban.Update
DataGrid1.Refresh
MsgBox "成功删除!", vbOKOnly + vbExclamation, ""
DataGrid1.AllowDelete = False
Else
Exit Sub
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_zhiban.CursorLocation = adUseClient
rs_zhiban.Open sql, co