设为首页   |  加入收藏夹 快速导航:  热门文章  |  最新文章  |  梦想博客  
当前位置:编程之家 -> 文章频道 ->vb 
站内搜索:  

VB+Access设计图书管理系统(10)

作者:不详 来源:csdn 整理日期:2007-02-19


  (7) 值班管理子窗体代码

  值班管理子窗体的作用是把值班人员的时间安排形成列表。运行的值班管理子窗体如图44所示。

  VB+Access设计图书管理系统(图四十四)

  图44 运行的值班管理子窗体

  先定义连接数据库的变量:

  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

  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, conn, adOpenKeyset, adLockPessimistic 打开数据库

   设定DataGrid控件属性

  DataGrid1.AllowAddNew = False 不可增加

  DataGrid1.AllowDelete = False 不可删除

  DataGrid1.AllowUpdate = False

  Set DataGrid1.DataSource = rs_zhiban

  Exit Sub

  loaderror:

  MsgBox Err.Description

  End Sub

  Private Sub Form_Unload(Cancel As Integer)

  Set DataGrid1.DataSource = Nothing

  rs_zhiban.Close

  End Sub

  (8) 投诉管理子窗体代码

  投诉管理子窗体是为了对人员进行更好的管理而设置的,可以向其添加投诉的对象、时间和内容等。投诉管理运行后的子窗体如图45所示。

  VB+Access设计图书管理系统(图四十五)

  图45 运行的投诉管理子窗体

[1]  [2]  [3]  [4]  [5]  [6]  [7]  [8]  [9]  [10]  [11]