Chương 7: THIẾT KẾ GIAO DIỆN VÀ XÂY DỰNG MODUL CHƯƠNG TRÌNH
7.4. Thiết kế giao diện chức năng xử lí thông tin
7.4.2. Chức năng xử lí xe vào - ra bến
a. Giao diện.
b. Modul chương trình.
+ Chức năng mới:
- Hiện thị bảng xe vào – ra bến - Nhập thông tin xe vào và xuất bến + Chức năng Ghi:
- Kiểm tra dữ liệu hợp lệ.
- Kiểm tra ghi cho các chức năng mới, sửa. Bao gồm các thuộc tính: Tên
Dim vt As Variant
Dim rsnhapben As ADODB.Recordset Dim rsluong As ADODB.Recordset Dim rsxe As ADODB.Recordset Dim ngay As Integer
Dim thang As Integer Dim nam As Integer Dim gio As Integer Private Sub cbsx_Click()
If Timkiem("Xetaiben", " soxe='" & cbsx.Text & "' and ((ngayxuat = #" &
Format(Date, "mm/dd/yyyy") & "# and giochay > #" & Format(Time, "hh:mm") &
"#) or (ngayxuat > #" & Format(Date, "mm/dd/yyyy") & "# )) ") Then
MsgBox "Bạn chọn nhầm số xe", vbOKOnly + vbInformation, "Thông báo"
cbsx.Text = ""
Exit Sub End If
Dim clc As String
If Timkiem("soxe", "soxe='" & cbsx.Text & "'") = True Then clc = rschung!
chatluongcao
If Timkiem("giave", "chatluongcao='" & clc & "' and tuyen='" & cbtl.Text & "'") = False Then
MsgBox "Giá vé " & cbtl.Text & " Chưa cập nhật"
cbsx.Text = ""
cbtl.Text = ""
If MsgBox("Bạn muốn cập nhật giá vé bây giờ không?", vbOKCancel + vbQuestion, "Thông báo") = vbOK Then frmcapnhatgiave.Show
Private Sub cmdghi_Click() Call xoacach(Me)
If cbtl.Text = "" Then
MsgBox "Bạn chưa nhập luồng xe chạy", vbOKOnly + vbExclamation, "Thông báo"
Exit Sub End If
If cbsx.Text = "" Then
MsgBox "Bạn chưa nhập số xe", vbOKOnly + vbExclamation, "Thông báo"
Exit Sub End If
If Not IsDate(txtnx.Text) Then
MsgBox "Bạn nhập sai ngày xe chạy", vbOKOnly + vbExclamation, "Thông báo"
Exit Sub End If
If txtnx.Text = "" Then
MsgBox "Bạn chưa nhập ngày xe chạy", vbOKOnly + vbExclamation, "Thông báo"
Exit Sub End If
If txtgc.Text = "" Then
MsgBox "Bạn chưa nhập giờ chạy", vbOKOnly + vbExclamation, "Thông báo"
Dim sx As String
If Timkiem("soxe", "soxe='" & cbsx.Text & "'") = True Then sg = rschung!soghe Dim ngayvao As Date
Dim ngayra As Date Dim sn As String
ngayvao = Format(Date, "dd/mm/yyyy") ngayra = Format(txtnx.Text, "dd/mm/yyyy") If ngayvao > ngayra Then
MsgBox "Bạn nhập sai ngày ra", vbOKOnly + vbInformation, "Thông báo"
Exit Sub End If
sn = ngayra - ngayvao
If Timkiem("phibendau", "songay='" & sn & "'") = False Then
MsgBox "Số ngày đậu tại bến của xe chưa có trong bảng thu phí", vbOKOnly + vbInformation, "Thông báo"
Exit Sub End If
If Timkiem("Phivaora", " socho='" & sg & "' and tuyen='" & cbtl.Text & "'") = False Then
MsgBox "Tuyến luồng" & cbtl.Text & " Chưa có mức phí vào ra cho xe " & sg &
" chỗ", vbCritical, "Thông báo"
Exit Sub End If
If nutmoi = True Then rsnhapben.AddNew
End If
rsnhapben!tuyen = cbtl.Text rsnhapben!Soxe = cbsx.Text rsnhapben!ngayvao = ngayvao rsnhapben!ngayxuat = ngayra rsnhapben!giochay = txtgc.Text rsnhapben!songay = ngayra - ngayvao rsnhapben.Update
Call sang(Me, True) End Sub
Private Sub cmdhuy_Click() Call sang(Me, True)
ht
End Sub
Private Sub cmdmoi_Click() nutmoi = True
Call xoatext(Me) Call sang(Me, False) End Sub
Private Sub cmdsua_Click()
If MsgBox("Có chắc là bạn muốn thoát không?", vbOKCancel + vbQuestion,
"Thông báo") = vbOK Then Unload Me End Sub
Private Sub cmdxoa_Click()
If MsgBox("Có chắc là bạn muốn xóa không?", vbOKCancel + vbQuestion, "Thông báo") = vbOK Then rsnhapben.Delete
If rsnhapben.RecordCount = 0 Then cmdsua.Enabled = False
cmdxoa.Enabled = False End If
End Sub
Private Sub DataGrid1_Click() txtml.Text = rsluong!ma_luong End Sub
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
txtml.Text = rsluong!ma_luong End Sub
Private Sub ht()
If rsnhapben.RecordCount > 0 Then cbtl.Text = rsnhapben!tuyen cbsx.Text = rsnhapben!Soxe
txtnx.Text = Format(rsnhapben!ngayxuat, "dd/mm/yyyy") txtgc.Text = rsnhapben!giochay
Private Sub DataGrid2_Click() ht
vt = rsnhapben.Bookmark End Sub
Private Sub Form_Load() d = Now
d1 = Format(d, "mm/mm/yyyy") ngay = Day(d)
thang = Month(d) nam = Year(d)
Dim homnay As String
homnay = Str(ngay) & "/" & Str(thang) & "/" & Str(nam) gio = Hour(d)
phut = Minute(d) '''''''''''''''''''''''''''''''''''''''''''''''''' Call sang(Me, True)
Call modulieu(rsluong, "Luongchay") If rsluong.RecordCount > 0 Then rsluong.MoveFirst
Do While Not rsluong.EOF cbtl.AddItem rsluong!tuyen rsluong.MoveNext
If rsxe.RecordCount > 0 Then rsxe.MoveFirst
Do While Not rsxe.EOF cbsx.AddItem rsxe!Soxe rsxe.MoveNext
Loop Else
MsgBox "Bạn hãy cập nhật số xe", vbOKOnly + vbInformation, "Thông báo"
End If
Set rsnhapben = New ADODB.Recordset
rsnhapben.Open "select * from xetaiben where (ngayxuat >= #" & Format(Date,
"mm/dd/yyyy") & "# and giochay > #" & Format(Time, "hh:mm") & "#) or (ngayxuat > #" & Format(Date, "mm/dd/yyyy") & "# ) ", kn, adOpenDynamic, adLockOptimistic
Set DataGrid2.DataSource = rsnhapben If rsnhapben.RecordCount = 0 Then cmdxoa.Enabled = False
cmdsua.Enabled = False End If
ht
End Sub
Private Sub Timer1_Timer()
If rsnhapben.RecordCount > 0 Then rsnhapben.MoveFirst
Do While Not rsnhapben.EOF
If rsnhapben!ngayxuat = Format(Date, "mm/dd/yyyy") Then
End If
rsnhapben.MoveNext Loop
Else
MsgBox "Đã hết xe trong bến", vbOKCancel + vbInformation, "Thông báo"
End If
rsnhapben.Close
rsnhapben.Open "select * from xetaiben where (ngayxuat >= #" & Format(Date,
"mm/dd/yyyy") & "# and giochay > #" & Format(Time, "hh:mm") & "#) or (ngayxuat > #" & Format(Date, "mm/dd/yyyy") & "#)", kn, adOpenDynamic, adLockOptimistic
Set DataGrid2.DataSource = rsnhapben End Sub.