Dim addingCL As Boolean Dim str, str1, str2, str3, str4, str5
Private Sub cbocvcm_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
cmdluu.SetFocus End Select
End Sub
Private Sub cmdBoqua_Click()
Call resetvalues
cmdxoa.Enabled = True cmdmoi.Enabled = True cmdsua.Enabled = False cmdboqua.Enabled = False cmdketiep.Enabled = True cmdquaylui.Enabled = True cmdluu.Enabled = False Call DisplayData
txtmanv.Enabled = False End Sub
Private Sub cmdct_Click()
If txtmanv.Text <> "" And txttennv.Text <> "" Then frmquatrinhcongtac.Show
Else
MsgBox "Bạn cha chọn nhân viên!", vbOKOnly + vbExclamation, "Thông Báo"
End If End Sub
Private Sub cmdgd_Click()
If txtmanv.Text <> "" And txttennv.Text <> "" Then frmgiadinh.Show
Else
MsgBox "Bạn cha chọn nhân viên!", vbOKOnly + vbExclamation, "Thông Báo"
End If
Private Sub cmdktkl_Click()
If txtmanv.Text <> "" And txttennv.Text <> "" Then frmktkl.Show
Else
MsgBox "Bạn cha chọn nhân viên!", vbOKOnly + vbExclamation, "Thông Báo"
End If End Sub
Private Sub cmdin_Click() rpt_llnv.Show
End Sub
Private Sub cmdKetiep_Click() On Error GoTo errs
cmdquaylui.Enabled = True If Adodc1.Recordset.EOF Then
MsgBox " Day la ban ghi cuoi cung ", vbInformation, "Thong bao"
Adodc1.Recordset.MoveLast cmdketiep.Enabled = False Else
Adodc1.Recordset.MoveNext End If
Call DisplayData
cmdsua.Enabled = True txtmanv.Enabled = False errs:
Private Sub cmdLuu_Click() Dim str As String
If Len(Trim(txtmanv.Text)) = 0 Then
MsgBox "Ban phai nhap du lieu ", vbOKOnly + vbInformation, "Thong bao"
txtmanv.SetFocus Exit Sub
End If
If Adodc1.Recordset.RecordCount <> 0 Then
str = "select * from nhanvien where Manv ='" & Trim(txtmanv.Text) & "'"
If checkey(str) And addingCL Then
MsgBox "Ma da ton tai", vbOKOnly + vbInformation, "Thong bao"
txtmanv.SetFocus Call resetvalues Exit Sub
End If End If
If Len(Trim(txttennv)) = 0 Then
MsgBox "Ban nen nhap ten", vbOKOnly + vbInformation, "Thong bao"
txttennv.SetFocus Exit Sub
End If
With Adodc1.Recordset If addingCL Then .AddNew
!Manv = txtmanv.Text
!mapb = cbopb.Text
!chucvudang = cboda.Text !chucvudoan = cbodo.Text !chucvucm = cbocvcm.Text !trinhdovh = cbotdvh.Text !matgiao = cbotg.Text !trinhdollct = cbollct.Text !trinhdocmnv = cbotdcm.Text !loaihd = cbohd.Text
!socmnd = txtcmnd.Text !ngayvaovms = txtnvao.Text !madtoc = cbodt.Text
!ngayvaodang = txtnvd.Text !sodt = txtdt.Text
!Quequan = txtqq.Text !Diachihiennay = txtdc.Text !gioitinh = Cbogt1.Text
!ngaysinh = mskNgaysinh.Text Else
!tennv = txttennv.Text !mapb = cbopb.Text
!chucvudang = cboda.Text !chucvudoan = cbodo.Text !chucvucm = cbocvcm.Text !trinhdovh = cbotdvh.Text
!trinhdollct = cbollct.Text !trinhdocmnv = cbotdcm.Text !loaihd = cbohd.Text
!socmnd = txtcmnd.Text !ngayvaovms = txtnvao.Text !madtoc = cbodt.Text
!ngayvaodang = txtnvd.Text !sodt = txtdt.Text
!Quequan = txtqq.Text !Diachihiennay = txtdc.Text !gioitinh = Cbogt1.Text
!ngaysinh = mskNgaysinh.Text End If
.Update End With
addingCL = False Call resetvalues
cmdxoa.Enabled = True cmdmoi.Enabled = True cmdsua.Enabled = False cmdboqua.Enabled = False cmdketiep.Enabled = False cmdquaylui.Enabled = True cmdluu.Enabled = False txtmanv.Enabled = False
Private Sub cmdquaylui_Click() On Error GoTo errs
cmdketiep.Enabled = True If Adodc1.Recordset.BOF Then
MsgBox " Day la ban ghi dau tien ", vbInformation, "Thong bao"
Adodc1.Recordset.MoveFirst cmdquaylui.Enabled = False Else
Adodc1.Recordset.MovePrevious End If
Call DisplayData
txtmanv.Enabled = False errs:
End Sub
Private Sub Cmdsua_Click() txtmanv.Enabled = True cmdmoi.Enabled = False cmdboqua.Enabled = True cmdluu.Enabled = True cmdketiep.Enabled = False cmdquaylui.Enabled = False txtmanv.SetFocus
addingCL = False End Sub
cmdxoa.Enabled = False cmdsua.Enabled = False cmdboqua.Enabled = True cmdluu.Enabled = True cmdketiep.Enabled = False cmdquaylui.Enabled = False addingCL = True
'Goi phuong thuc resetvalues de xoa du lieu trong text box Call resetvalues
txtmanv.Enabled = True txtmanv.SetFocus
End Sub
Private Sub cmdthoat_Click()
If MsgBox("Ban co muon thoat khong", vbYesNo + vbInformation, "Thong bao")
= vbNo Then Exit Sub Else
Unload Me End If End Sub
Private Sub Cmdxoa_Click() With Adodc1.Recordset If .RecordCount <> 0 Then
If MsgBox("Ban co muon xoa ban ghi nay khong", vbYesNo, "Thong bao") = vbYes Then
.Delete
Call resetvalues End If
Else
MsgBox " Khong co ban ghi ", vbInformation, "Thong bao"
cmdxoa.Enabled = False End If
End With End Sub
Private Sub Form_Load() Adodc1.Visible = False CenterMyform Me addingCL = False cmdsua.Enabled = True cmdluu.Enabled = False cmdboqua.Enabled = False cmdketiep.Enabled = True cmdquaylui.Enabled = True txtmanv.Enabled = False
Set conn = New adodb.Connection
gConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Persist Security Info=False;" & _
"Data Source= " & App.Path & "\Data\db1.mdb"
conn.Open gConnectionString Set rs = New adodb.Recordset str = "select mapb from phongban"
rs.Open str, conn Do While Not rs.EOF
Me.cbopb.AddItem rs("mapb") rs.MoveNext
Loop
Set rs1 = New adodb.Recordset
str1 = "select macvdoan from chucvudoan"
rs1.Open str1, conn Do While Not rs1.EOF
Me.cbodo.AddItem rs1("macvdoan") rs1.MoveNext
Loop
Set rs2 = New adodb.Recordset
str2 = "select macvcm from chucvucmon"
rs2.Open str2, conn Do While Not rs2.EOF
Me.cbocvcm.AddItem rs2("macvcm") rs2.MoveNext
Loop
Set rs3 = New adodb.Recordset
str3 = " select macvdang from chucvudang"
rs3.Open str3, conn
Me.cboda.AddItem rs3("macvdang") rs3.MoveNext
Loop
Set rs5 = New adodb.Recordset str5 = " select matg from tongiao"
rs5.Open str5, conn Do While Not rs5.EOF
Me.cbotg.AddItem rs5("matg") rs5.MoveNext
Loop
Set rs4 = New adodb.Recordset str4 = " select madt from dantoc"
rs4.Open str4, conn Do While Not rs4.EOF
Me.cbodt.AddItem rs4("madt") rs4.MoveNext
Loop End Sub
Private Sub DisplayData() With Adodc1.Recordset If .BOF Or .EOF Then Exit Sub
End If
txtmanv = !Manv txttennv = !tennv
txtdc.Text = !Diachihiennay txtdt.Text = !sodt
mskNgaysinh.Mask = ""
mskNgaysinh.Text = !ngaysinh txtqq.Text = !Quequan
cbodt.Text = !madtoc cbotg.Text = !matgiao
txtnvd.Text = !ngayvaodang txtcmnd.Text = !socmnd cbotdvh.Text = !trinhdovh cbotdcm.Text = !trinhdocmnv cbollct.Text = !trinhdollct cbocvcm.Text = !chucvucm cbodo.Text = !chucvudoan cboda.Text = !chucvudang txtnvao.Text = !ngayvaovms cbohd.Text = !loaihd
cbopb.Text = !mapb End With
End Sub
Private Sub Grid1_Click() 'Call DisplayData
cmdsua.Enabled = True cmdluu.Enabled = True cmdketiep.Enabled = True cmdquaylui.Enabled = True If addingCL Then
If MsgBox("Dang o che do them moi, chon OK de hien thi du lieu", vbOKCancel + vbInformation, "Thong bao") = vbCancel Then
cmdsua.Enabled = False Exit Sub
Else
addingCL = False
cmdboqua.Enabled = False End If
End If
txtmanv.Enabled = False Call DisplayData
End Sub
Private Sub grid1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
Call Grid1_Click
End Sub
Private Sub resetvalues() txtmanv.Text = ""
txttennv.Text = ""
Cbogt1 = ""
txtdc.Text = ""
txtdt.Text = ""
mskNgaysinh.Mask = ""
mskNgaysinh.Text = ""
txtqq.Text = ""
cbodt.Text = ""
cbotg.Text = ""
txtnvd.Text = ""
txtcmnd.Text = ""
cbotdvh.Text = ""
cbotdcm.Text = ""
cbollct.Text = ""
cbocvcm.Text = ""
cbodo.Text = ""
cboda.Text = ""
txtnvao.Text = ""
cbohd.Text = ""
cbopb.Text = ""
End Sub
Private Sub txtmado_KeyPress(KeyAscii As Integer)
Case 13
txttennv.SetFocus End Select
End Sub
Private Sub mnuback_Click() frmmain.Show
End Sub
Private Sub txttennv_keypress(KeyAscii As Integer) Select Case KeyAscii
Case 13
cbopb.SetFocus End Select End Sub
Private Sub cmdmoi_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
txtmanv.SetFocus End Select
End Sub
Private Sub txtmanv_GotFocus() txtmanv.BackColor = &H8000000F End Sub
Private Sub txttennv_gotfocus() txttennv.BackColor = &H8000000F End Sub
Private Sub txtmanv_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
txttennv.SetFocus End Select
End Sub
Private Sub cbopb_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
mskNgaysinh.SetFocus End Select
End Sub
Private Sub mskngaysinh_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
Cbogt1.SetFocus End Select
Private Sub cbogt1_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
cbodt.SetFocus End Select End Sub
Private Sub cbodt_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
cbotg.SetFocus End Select End Sub
Private Sub cbotg_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
txtdc.SetFocus End Select End Sub
Private Sub txtdc_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
txtqq.SetFocus End Select End Sub
Private Sub txtqq_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
txtdt.SetFocus End Select End Sub
Private Sub txtdt_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
txtnvd.SetFocus End Select End Sub
Private Sub txtnvd_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
txtcmnd.SetFocus End Select
End Sub
Private Sub txtcmnd_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
txtnvao.SetFocus End Select
End Sub
Private Sub txtnvao_KeyPress(KeyAscii As Integer)
Case 13
cbohd.SetFocus End Select End Sub
Private Sub cbohd_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
cbotdcm.SetFocus End Select
End Sub
Private Sub cbotdcm_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
cbotdvh.SetFocus End Select
End Sub
Private Sub cbotdvh_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
cbollct.SetFocus End Select End Sub
Private Sub cbollct_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
End Select End Sub
Private Sub cboda_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
cbodo.SetFocus End Select End Sub
Private Sub cbodo_KeyPress(KeyAscii As Integer) Select Case KeyAscii
Case 13
cbocvcm.SetFocus End Select
End Sub
Private Sub cboda_gotfocus() cboda.BackColor = &H8000000F End Sub
Private Sub cbopb_gotfocus() cbopb.BackColor = &H8000000F End Sub
Private Sub maskngaysinh_gotfocus() maskngaysinh.BackColor = &H8000000F End Sub
Private Sub cbogt1_gotfocus() Cbogt1.BackColor = &H8000000F
Private Sub txtdiachi_gotfocus() txttdkt.BackColor = &H8000000F End Sub
Private Sub txtqq_gotfocus() txtqq.BackColor = &H8000000F End Sub
Private Sub txtdt_gotfocus() txtdt.BackColor = &H8000000F End Sub
Private Sub cbodt_gotfocus() cbodt.BackColor = &H8000000F End Sub
Private Sub txttg_gotfocus() txttg.BackColor = &H8000000F End Sub
Private Sub txtnvao_gotfocus() txtnvao.BackColor = &H8000000F End Sub
Private Sub cbohd_gotfocus() cbohd.BackColor = &H8000000F End Sub
Private Sub cbovh_gotfocus() Cbovh.BackColor = &H8000000F End Sub
Private Sub cbollct_gotfocus()
End Sub
Private Sub cbotdcm_gotfocus() cbotdcm.BackColor = &H8000000F End Sub
Private Sub cbocvda_gotfocus() cbocvda.BackColor = &H8000000F End Sub
Private Sub cbocvdo_gotfocus() cbocvdo.BackColor = &H8000000F End Sub
Private Sub cbocvcm_gotfocus() cbocvcm.BackColor = &H8000000F End Sub
Private Sub cbotg_gotfocus() cbotg.BackColor = &H8000000F End Sub
Private Sub txtdc_gotfocus() txtdc.BackColor = &H8000000F End Sub
Private Sub mskngaysinh_gotfocus() mskNgaysinh.BackColor = &H8000000F End Sub
Private Sub txtnvd_gotfocus()
End Sub
Private Sub txtcmnd_gotfocus() txtcmnd.BackColor = &H8000000F End Sub
Private Sub cbotdvh_gotfocus() cbotdvh.BackColor = &H8000000F End Sub