【文章內(nèi)容簡(jiǎn)介】
If = True: = True: = True = False: = False End SubPrivate Sub LoadData()39。裝載數(shù)據(jù)Set rs = NothingSQL = select *from 宿舍信息表 order by 宿舍號(hào)Set rs = SelectSQL(SQL) Set = rs End SubPrivate Function Checkdata() As Boolean39。檢查數(shù)據(jù)的合法性 Dim rsts As New Dim xb As New Dim msgt As String Dim gs As String gs = select 宿舍號(hào) from 宿舍信息表 Set xb = SelectSQL(gs) msgt = 39。檢查數(shù)據(jù)非空 If Trim(txtItem(0).Text) = Then msgt = 宿舍號(hào)不能為空 End If If Trim(txtItem(1).Text) = Then msgt = msgt amp。 總床位不能為空 End If If Trim(txtItem(2).Text) = Then msgt = msgt amp。 已分配不能為空 End If If Not msgt = Then MsgBox (msgt) Checkdata = False Exit Function End If SQL = select *from 宿舍信息表 where 宿舍號(hào)=39。 amp。 Trim(txtItem(0).Text) amp。 39。 Set rsts = SelectSQL(SQL) 39。查詢SQL語(yǔ)句 If flag = Add And 0 Then MsgBox (該宿舍的信息已經(jīng)存在,重復(fù)添加!) Checkdata = False Exit Function End If Checkdata = True 39。合法End FunctionPrivate Sub showdata()39。在文本框中顯示數(shù)據(jù) If 0 And = False Then For Index = 0 To 2 If (Index) Then txtItem(Index).Text = (Index) Else txtItem(Index).Text = End If txtItem(Index).Enabled = False Next Index End IfEnd SubPrivate Sub CmdMove_Click(Index As Integer) 39。移動(dòng)記錄 Select Case Index Case Is = 0 39。移到第一條記錄 If Not Then Case Is = 1 39。移到上一條記錄 If 0 Then If = False Then If = True Then End If Case Is = 2 39。移到下一條記錄 If 0 Then If = False Then If = True Then End If Case Is = 3 39。移到最后一條記錄 If 0 Then If Not = True Then End If End Select If 0 Then Call showdata 39。在文本框中顯示數(shù)據(jù) 39。按鈕可用性 = True: = True: = True = False: = False Else 39。按鈕可用性 = True: = False: = False = False: = False End IfEnd SubPrivate Sub cmdadd_click()39。清空文本框,文本框可用2 For Index = 0 To 2 txtItem(Index).Text = txtItem(Index).Enabled = True Next Index 39。設(shè)置標(biāo)志flag flag = Add 39。所有移動(dòng)按鈕不可用 For Index = 0 To 3 CmdMove(Index).Enabled = False Next Index 39。添加、修改、刪除按鈕不可用,取消、保存按鈕可用 = False: = False: = False = True: = TrueEnd SubPrivate Sub cmdsave_click() On Error GoTo ErrMsg If Not Checkdata Then Exit Sub 39。如果數(shù)據(jù)不合法就退出 If flag = Modify Then 39。如果是修改數(shù)據(jù) msg = MsgBox(您確實(shí)要修改這條數(shù)據(jù)嗎?, vbYesNo) If msg = vbYes Then For Index = 0 To 2 If txtItem(Index).Text Then (Index) = txtItem(Index).Text txtItem(Index).Enabled = False End If Next Index Else Exit Sub End If ElseIf flag = Add Then 39。如果是添加新數(shù)據(jù) For Index = 0 To 2 If txtItem(Index).Text Then (Index) = txtItem(Index).Text End If Next Index End If 39。更新數(shù)據(jù) 39。移動(dòng)控件可用 For Index = 0 To 3 CmdMove(Index).Enabled = True Next Index = True: = True: = True = False: = False If flag = Add Then MsgBox (成功添加數(shù)據(jù)!) Else MsgBox (成功更新數(shù)據(jù)!) End If Call LoadData 39。重新裝載數(shù)據(jù) 39。定位到添加或修改記錄 If 0 Then (宿舍號(hào)=39。 amp。 Trim(txtItem(0).Text) amp。 39。) If Not Then Call showdata 39。重新裝載數(shù)據(jù) End If Exit SubErrMsg: MsgBox , vbExclamation, 出錯(cuò)End SubPrivate Sub cmdmodify_click()39。修改操作2 If 0 Then 39。文本框可用 For Index = 0 To 2 txtItem(Index).Enabled = True Next Index 39。設(shè)置標(biāo)志flag flag = Modify 39。移動(dòng)控件不可用 For Index = 0 To 3 CmdMove(Index).Enabled = False Next Index 39。添加、修改、刪除按鈕不可用,取消、保存按鈕可用 = True: = True = False: = False: = False Else MsgBox (沒有可以修改的數(shù)據(jù)!) End IfEnd SubPrivate Sub CmdDelete_Click()39。刪除操作 On Error GoTo ErrMsg If 0 Then msg = MsgBox(刪除該條記錄嗎?, vbYesNo) If msg = vbYes Then Call SuSheDelete Call LoadData 39。重新裝載數(shù)據(jù) 39。清空文本框、并不可用 For Index = 0 To 2 txtItem(Index).Text = txtItem(Index).Enabled = False Next Index 39。所有移動(dòng)控件不可用 If = 0 Then For Index = 0 To 3 CmdMove(Index).Enabled = False Next Index End If 39。按鈕可用性處理 = True: = False: = True = False: = False Msg