Tải bản đầy đủ (.pdf) (44 trang)

ĐỒ ÁN TỐT NGHIỆP QUẢN LÍ VẬT TƯ, THIẾT BỊ, ỨNG DỤNG PHÁT TRIỂN CHO TRUNG TÂM CNTTĐHQG TPHCM_CHƯƠNG 5_2 docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (105.43 KB, 44 trang )

ĐỒ ÁN TỐT NGHIỆP QUẢN LÍ VẬT
TƯ, THIẾT BỊ, ỨNG DỤNG PHÁT
TRIỂN CHO TRUNG TÂM CNTT-
ĐHQG TPHCM
Chương 5
Thiết kế giao diện người máy

5.4 Các mã lệnh được sử dụng trong chương trình

Private Sub Form_Load()
DoCmd.Restore
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("user")
If rs.EOF Then
DoCmd.Close
DoCmd.OpenForm "main"
End If
End Sub

Private Sub login_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Me.dem = Me.dem + 1
Set db = CurrentDb()
Set rs = db.OpenRecordset("user")
rs.MoveFirst
Do While Not rs.EOF
If rs![username] = ten And rs![password] = ma Then
kt = 1


Exit Do
End If
rs.MoveNext
Loop
If kt = 1 Then
DoCmd.Close
DoCmd.OpenForm "main"
Else
If Me.dem = 3 Then
DoCmd.Quit
Exit Sub
End If
MsgBox "ban nhap username hoac password sai", 0 + 48, "thong bao"
End If
End Sub

Private Sub Form_Timer()
Dim x As String, y As String
Randomize
r = Rnd(1) * 250 + 1
g = Rnd(1) * 250 + 1
b = Rnd(1) * 250 + 1
r1 = Rnd(1) * 250 + 1
g1 = Rnd(1) * 250 + 1
b1 = Rnd(1) * 250 + 1
Me.Label6.ForeColor = RGB(r, g, b)
End Sub


Option Compare Database

Private Sub Form_Load()
DoCmd.Restore
End Sub

Private Sub ok_Click()
Dim db As DAO.Database, rec As DAO.Recordset
Set db = CurrentDb()
Set rec = db.OpenRecordset("admin")
rec.MoveFirst
If passcu = rec![pass] Then
If IsNull(passmoi) And IsNull(xlpassmoi) Then
MsgBox "Ban chua nhap ma so he thong moi!" & Chr(10) & "De nghi nhap
day du", 0 + vbCritical, "Thong bao"
Exit Sub
End If
If passmoi = xlpassmoi Then
rec.Edit
rec![pass] = passmoi
rec.Update
rec.Close
db.Close
passcu = ""
passmoi = ""
xlpassmoi = ""
MsgBox "Ma so he thong da duoc thay doi", 0 + 64, "Thong bao"
DoCmd.Close
Else
MsgBox "Xac lap ma so moi sai !" & Chr(10) & "De nghi nhap lai ", 0 +
vbCritical, "Thong bao"
passmoi = ""

xlpassmoi = ""
End If
Else
MsgBox "Ma he thong khong dung" & Chr(10) & "De nghi nhap lai", 0 + 16,
"Thong bao"
passcu = ""
End If
End Sub



Option Compare Database
Private Sub Command4_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("user")

If Not rs.EOF Then
rs.MoveFirst
Do Until rs.EOF
If rs![userID] = mauser And rs![username] = ten And rs![password] = ma Then
If IsNull(ma1) = False And IsNull(ma2) = False Then
If ma1 = ma2 Then
rs.Edit
rs![password] = ma1
rs.Update
MsgBox "Ban da thay doi ma so thanh cong", 0 + 60, "thong bao"
Me.mauser = ""
Me.ten = ""

Me.ma = ""
Me.ma1 = ""
Me.ma2 = ""
GoTo Thoat
Else
If ma1 <> ma2 Then
MsgBox "new password va retype new password cua ban khong
dung", 0 + 48, "thong bao"
GoTo Thoat
End If
End If
Else
MsgBox "ban khong duoc de trong new password va retype new
password", 0 + 48, "thong bao"
GoTo Thoat
End If
End If
rs.MoveNext
Loop

MsgBox "ban nhap userID, username hoac password chua dung", 0 + 60,
"Thong bao"
End If
Thoat:
End Sub


Private Sub Form_Load()
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("user")
If Not rs.EOF Then
Me.ma.Enabled = True
Me.ten.Enabled = True
Else
Me.ma.Enabled = False
Me.ten.Enabled = False
End If
End Sub
Private Sub Command13_Click()
On Error GoTo Err_Command13_Click


DoCmd.Close

Exit_Command13_Click:
Exit Sub

Err_Command13_Click:
MsgBox Err.Description
Resume Exit_Command13_Click

End Sub


Private Sub Form_Load()
DoCmd.Restore
Me.khungxoa.Visible = False
Me.khungthem.Visible = False


End Sub

Private Sub Ghi_Click()
Dim db As DAO.Database
Dim rec As DAO.Recordset
Set db = CurrentDb()
Set rec = db.OpenRecordset("user")
If (mamoi <> "") And (ten <> "") And (pass <> "") Then
On Error GoTo loi
rec.AddNew
rec![userID] = mamoi
rec![username] = ten
rec![password] = pass
rec.Update
mamoi = ""
ten = ""
pass = ""
MsgBox "Ho so da duoc luu", 0 + 64, "Thong bao"
Me.macu.Requery
Me.bangma.Requery
Else
MsgBox "Nhap thieu du lieu", 0 + 64, "Thong bao"
End If

loi:
rec.MoveFirst
Do Until rec.EOF
If rec![userID] = mamoi Then
MsgBox "Ma User da ton tai" & Chr(10) & "De nghi nhap Ma User

khac", 0 + 64, "thông báo"
Exit Sub
End If
rec.MoveNext
Loop

End Sub

Private Sub Option59_GotFocus()
Me.khungxoa.Visible = False
Me.khungthem.Visible = True
End Sub

Private Sub Option61_GotFocus()
Me.khungxoa.Visible = True
Me.khungthem.Visible = False
End Sub

Private Sub thoat1_Click()
DoCmd.Close
End Sub

Private Sub thoat2_Click()
DoCmd.Close
End Sub
Private Sub Xoa_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("user")

rs.Edit
Do While Not rs.EOF
If rs![userID] = macu Then
rs.Delete
End If
rs.MoveNext
Loop
Me.macu = ""
bangma.Requery
macu.Requery
End Sub


Option Compare Database
Dim xMshh, xsl, Xthem, Xsua

Private Sub Command13_Click()
Select Case luachon
Case 1: Me.List12.RowSource = "select * from nhacungcap
where([nhacungcap]![mancc] like '*" & [txtma] & "*')"
Case 2: Me.List12.RowSource = "select * from nhacungcap
where([nhacungcap]![tenncc] like '*" & [txtten] & "*')"
Case 3: Me.List12.RowSource = "select * from nhacungcap
where([nhacungcap]![diachi] like '*" & [txtdiachi] & "*')"
Case 4: Me.List12.RowSource = "select * from nhacungcap
where([nhacungcap]![dienthoai] like '*" & [txtdienthoai] & "*')"
End Select
End Sub



Private Sub Command49_Click()
Me.txtma = ""
Me.txtten = ""
Me.txtdiachi = ""
Me.txtdienthoai = ""
Me.List12.RowSource = "select * from nhacungcap"
End Sub
Private Sub Cuoi_Click()
On Error GoTo Err_Cuoi_Click
If cmt = mancc Then
MsgBox "ban dang o hang cuoi cung!", vbExclamation + vbDefaultButton1, "chu
y"

Else

DoCmd.GoToRecord , , acLast
End If
Exit_Cuoi_Click:
Exit Sub

Err_Cuoi_Click:
MsgBox Err.Description
Resume Exit_Cuoi_Click

End Sub
Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
End Sub
Private Sub Dau_Click()
On Error GoTo Err_Dau_Click

If dmt = mancc Then
MsgBox "ban dang o hang dau tien !", vbExclamation + vbDefaultButton1, "chu
y"
Else
End If

DoCmd.GoToRecord , , acFirst

Exit_Dau_Click:
Exit Sub

Err_Dau_Click:
MsgBox Err.Description
Resume Exit_Dau_Click

End Sub


Private Sub Ghi_Click()
On Error GoTo Err_Ghi_Click
If IsNull(mancc) Then
MsgBox "khong luu duoc gia tri rong!", vbExclamation + vbDefaultButton1,
"chu y"
Exit Sub
Else
DoCmd.RunCommand (acCmdSaveRecord)
List12.Requery
End If
List12.Visible = True
Dau.Visible = True

Truoc.Visible = True
Sau.Visible = True
dieukien.Visible = True
Cuoi.Visible = True
Them.Visible = True
Thoat.Visible = True
DoCmd.GoToControl "Them"
Ghi.Visible = False
Khong.Visible = False
Sua.Visible = True
Xoa.Visible = True
Xthem = False
Xsua = False
mancc.Locked = True
tenncc.Locked = True
diachi.Locked = True
dienthoai.Locked = True
sotk.Locked = True
fax.Locked = True
List12.Requery
Exit_Ghi_Click:
List12.Visible = True
Dau.Visible = True
dieukien.Visible = True
Sau.Visible = True
Truoc.Visible = True
Cuoi.Visible = True
Thoat.Visible = True
Ghi.Visible = False
Khong.Visible = False

Xoa.Visible = True
Sua.Visible = True
Them.Visible = True
DoCmd.GoToControl "Them"
Xthem = False
Xsua = False
mancc.Locked = True
tenncc.Locked = True
diachi.Locked = True
dienthoai.Locked = True
sotk.Locked = True
fax.Locked = True
List12.Requery
Exit Sub
Err_Ghi_Click:
MsgBox "Du lieu nhap khong hop le"
End Sub


Private Sub Khong_Click()
On Error Resume Next
DoCmd.RunCommand acCmdUndo
DoCmd.GoToRecord , , acFirst
List12.Visible = True
Dau.Visible = True
Sau.Visible = True
dieukien.Visible = True
Truoc.Visible = True
Cuoi.Visible = True
Thoat.Visible = True

Sua.Visible = True
Xoa.Visible = True
Them.Visible = True
Them.SetFocus
Khong.Visible = False
Ghi.Visible = False
Xthem = False
Xsua = False
mancc.Locked = True
tenncc.Locked = True
diachi.Locked = True
dienthoai.Locked = True
sotk.Locked = True
fax.Locked = True
List12.Requery

End Sub

Private Sub Option35_GotFocus()
Me.txtma.Enabled = True
Me.txtten.Enabled = False
Me.txtdiachi.Enabled = False
Me.txtdienthoai.Enabled = False

Me.txtma = ""
Me.txtten = ""
Me.txtdiachi = ""
Me.txtdienthoai = ""

End Sub


Private Sub Option37_GotFocus()
Me.txtma.Enabled = False
Me.txtten.Enabled = True
Me.txtdiachi.Enabled = False
Me.txtdienthoai.Enabled = False
Me.txtma = ""
Me.txtten = ""
Me.txtdiachi = ""
Me.txtdienthoai = ""
End Sub

Private Sub Option39_GotFocus()
Me.txtma.Enabled = False
Me.txtten.Enabled = False
Me.txtdiachi.Enabled = True
Me.txtdienthoai.Enabled = False
Me.txtma = ""
Me.txtten = ""
Me.txtdiachi = ""
Me.txtdienthoai = ""
End Sub

Private Sub Option41_GotFocus()
Me.txtma.Enabled = False
Me.txtten.Enabled = False
Me.txtdiachi.Enabled = False
Me.txtdienthoai.Enabled = True
Me.txtma = ""
Me.txtten = ""

Me.txtdiachi = ""
Me.txtdienthoai = ""
End Sub

Private Sub Sau_Click()
On Error GoTo Err_Sau_Click
If cmt = mancc Then
MsgBox "Ban dang o hang sau cung!", vbExclamation + vbDefaultButton1, "chu
y"
Else

DoCmd.GoToRecord , , acNext
End If

Exit_Sau_Click:
Exit Sub

Err_Sau_Click:
MsgBox Err.Description
Resume Exit_Sau_Click

End Sub

Private Sub Sua_Click()
On Error GoTo Err_Sua_Click
mancc.Locked = False
tenncc.Locked = False
diachi.Locked = False
dienthoai.Locked = False
sotk.Locked = False

fax.Locked = False
mancc.SetFocus
List12.Visible = False
Dau.Visible = False
Sau.Visible = False
Truoc.Visible = False
Cuoi.Visible = False
dieukien.Visible = False
Sua.Visible = False
Khong.Visible = True
Ghi.Visible = True
Xoa.Visible = False
Thoat.Visible = False
Them.Visible = False
Xsua = True

Exit_Sua_Click:
Exit Sub

Err_Sua_Click:
MsgBox Err.Description
Resume Exit_Sua_Click

End Sub

Private Sub Them_Click()
On Error GoTo Err_Them_Click
DoCmd.GoToRecord , , acNewRec
mancc.Locked = False
tenncc.Locked = False

diachi.Locked = False
dienthoai.Locked = False
sotk.Locked = False
fax.Locked = False
mancc.SetFocus
List12.Visible = False
Dau.Visible = False
Sau.Visible = False
dieukien.Visible = False
Truoc.Visible = False
Cuoi.Visible = False
Sua.Visible = False
Khong.Visible = True
Ghi.Visible = True
Xoa.Visible = False
Thoat.Visible = False
Them.Visible = False
Xthem = True

Exit_Them_Click:

×