Phần 3 Mã nguồn Form Khởi tạo
2.5 Mã nguồn thủ tục cmddeletedv_Click() Private Sub cmddeletedv_Click()
Dim i, j As Integer
If Me.cmbmadichvu.Text = "" Then MsgBox "chua chon dich vu can xoa"
Me.cmbmadichvu.SetFocus Exit Sub
ElseIf Me.cmbmanhanvien.Text = "" Then MsgBox "chua chon nhan vien can xoa"
Me.cmbmadichvu.SetFocus Exit Sub
Else
rst1.MoveFirst
While Not rst1.EOF
If rst1!mabenhnhan = Me.txtmabenhnhan And rst1!manhanvien = Me.cmbmanhanvien.Text And rst1!madichvu = Me.cmbmadichvu.Text Then rst1.Delete
End If
rst1.MoveNext Wend
End If
i = Me.lst1.ListItems.Count j = 0
While i > 0 And j <> 1
If Me.lst1.ListItems(i).Text = Me.cmbmadichvu.Text Then Me.lst1.ListItems.Remove i
i = i - 1 j = 1 Else
i = i - 1 End If Wend
i = Me.lst2.ListItems.Count j = 0
While i > 0 And j <> 1
If Me.lst2.ListItems(i).Text = Me.cmbmanhanvien.Text Then Me.lst2.ListItems.Remove i
i = i - 1 j = 1 Else
i = i - 1 End If Wend End Sub
2.6 Mã nguồn thủ tục cmdin_Click() Private Sub cmdin_Click()
Dim sql As String
Dim rst10 As ADODB.Recordset
sql = "SELECT tblDV.MaBenhNhan, tblBenhnhan.Hoten, tblDichvu.TenDV, tblDichvu.Giadv, tblDV.NgaylamDV" & _
" FROM tblNhanVien INNER JOIN (tblBenhnhan INNER JOIN (tblDichvu INNER JOIN tblDV ON tblDichvu.MaDV = tblDV.MaDichVu) ON
tblBenhnhan.MaBenhNhan = tblDV.MaBenhNhan) ON
tblNhanVien.MaNhanVien = tblDV.MaNhanVien" & _
" WHERE tblDV.Mabenhnhan ='" & Me.txtmabenhnhan.Text & "'"
Set rst10 = New ADODB.Recordset With rst10
.ActiveConnection = cnnData .Source = sql
.Open End With
Set rpt_Hoadon.DataSource = rst10 rpt_Hoadon.Show
End Sub
2.7 Mã nguồn thủ tục cmdluu_Click() Private Sub cmdluu_Click()
Dim sql As String
If Me.CmdAdd.Caption = "Huû" Then Skin.RemoveSkin CmdAdd.hwnd CmdAdd.Caption = "Tạo mới"
Skin.LoadSkin App.Path & "\_temp.skn"
Skin.ApplySkin CmdAdd.hwnd End If
If flag = True Then
If Me.txtmabenhnhan = "" Then Me.txtmabenhnhan.SetFocus
cmdluu.Enabled = False Exit Sub
Else
If Me.cmbmadichvu.Text = "" Then MsgBox "cha nhập dịch vụ"
Me.cmbmadichvu.SetFocus Exit Sub
End If
If Me.cmbmanhanvien.Text = "" Then MsgBox "cha nhập nhân viên"
Me.cmbmanhanvien.SetFocus Exit Sub
End If With rst .AddNew
.Fields(0).Value = Me.txtmabenhnhan.Text .Fields(1).Value = Me.txthoten.Text
.Fields(2).Value = Me.txttuoi.Text .Fields(3).Value = Me.txtdiachi.Text .Fields(4).Value = Me.txtdienthoai.Text .Update
End With With rst1 .AddNew
.Fields(0).Value = Me.txtmabenhnhan.Text .Fields(1).Value = Me.cmbmanhanvien.Text .Fields(2).Value = Me.cmbmadichvu.Text .Fields(3).Value = Date
.Update End With
TreeView1.Nodes.Add "parent", tvwChild, , Me.txtmabenhnhan.Text, "tron"
Me.lst1.Enabled = True Me.lst2.Enabled = True
Set l = Me.lst1.ListItems.Add(, , Me.cmbmadichvu.Text) l.SubItems(1) = Me.txttendichvu.Text
l.SubItems(2) = Me.txtdongia.Text
Set s = Me.lst2.ListItems.Add(, , Me.cmbmanhanvien.Text) s.SubItems(1) = Me.txttennhanvien
s.SubItems(2) = Me.txtchuyenkhoa
'If Me.CmdAdd.Caption = "Huû" Then Me.cmdnewdv.Enabled = True
Skin.RemoveSkin Me.CmdAdd.hwnd Me.CmdAdd.Caption = "Tạo mới"
Skin.LoadSkin App.Path & "\_temp.skn"
Skin.ApplySkin Me.CmdAdd.hwnd 'End If
End If
ElseIf flag = False Then
sql = "update tblbenhnhan set [hoten] ='" & Me.txthoten.Text & "'," & "[tuoi]
='" & Me.txttuoi.Text & "'," & "[diachi] ='" & Me.txtdiachi.Text & "'," &
"[dienthoai] ='" & Me.txtdienthoai.Text & "'" & _
" where tblbenhnhan.mabenhnhan ='" & Me.txtmabenhnhan.Text &
"'"
Set cmd = New ADODB.Command With cmd
.ActiveConnection = cn .CommandText = sql .Execute
End With End If
flag = False b = True
Me.txtchuyenkhoa = ""
Me.txtdiachi = ""
Me.txtdienthoai = ""
Me.txtdongia = ""
Me.txthoten = ""
Me.txtmabenhnhan = ""
Me.txttendichvu = ""
Me.txttennhanvien = ""
Me.txttuoi = ""
Me.cmbmadichvu.Clear Me.cmbmanhanvien.Clear cmdluu.Enabled = False cmdxoa.Enabled = True
cmdsua.Enabled = True End Sub
2.8 Mã nguồn thủ tục cmdnewdv_Click() Private Sub cmdnewdv_Click()
If Me.cmdnewdv.Caption = "Thêm dịch vụ" Then flag1 = True
Me.cmbmadichvu.Clear rst2.MoveFirst
While Not rst2.EOF
Me.cmbmadichvu.AddItem rst2.Fields(0).Value rst2.MoveNext
Wend
Me.cmbmanhanvien.Clear rst4.MoveFirst
While Not rst4.EOF
If rst4!ngaylamviec = Date Then
Me.cmbmanhanvien.AddItem rst4!manhanvien End If
rst4.MoveNext Wend
Skin.RemoveSkin Me.cmdnewdv.hwnd Me.cmdnewdv.Caption = "Huû"
Skin.LoadSkin App.Path & "\_temp.skn"
Skin.ApplySkin Me.cmdnewdv.hwnd Me.cmddeletedv.Enabled = False Me.cmdsavedv.Enabled = True b = False
Me.txttendichvu = ""
Me.txtdongia = ""
Me.txttennhanvien = ""
Me.txtchuyenkhoa = ""
Me.cmdAddlist.Visible = True ' Me.cmddeletelist.Visible = True ok = Me.lst1.ListItems.Count
ElseIf Me.cmdnewdv.Caption = "Huû" Then flag1 = False
rst1.MoveFirst lst1.ListItems.Clear Me.cmbmadichvu.Clear While Not rst1.EOF
If rst1!mabenhnhan = Me.txtmabenhnhan.Text Then Me.cmbmadichvu.AddItem rst1!madichvu
rst2.MoveFirst While Not rst2.EOF
If rst2!madv = rst1!madichvu Then
Set l = lst1.ListItems.Add(, , rst2!madv) l.SubItems(1) = rst2!tendv
l.SubItems(2) = rst2!giadv End If
rst2.MoveNext Wend
End If
rst1.MoveNext Wend
'MsgBox Me.cmbmadichvu.ListCount
' For i = Me.cmbmadichvu.ListCount - 1 To 2 Step -1 ' For j = Me.cmbmadichvu.ListCount - 2 To 1 Step -1
' If Me.cmbmadichvu.List(i) = Me.cmbmadichvu.List(j) Then ' Me.cmbmadichvu.RemoveItem j
' End If ' Next j ' Next i
rst1.MoveFirst lst2.ListItems.Clear While Not rst1.EOF
If rst1!mabenhnhan = Me.txtmabenhnhan.Text Then rst3.MoveFirst
While Not rst3.EOF
If rst3!manhanvien = rst1!manhanvien Then Set s = lst2.ListItems.Add(, , rst3!manhanvien) If IsNull(rst3!tennhanvien) Then
s.SubItems(1) = ""
Else
s.SubItems(1) = rst3!tennhanvien End If
If IsNull(rst3!capbac) Then s.SubItems(2) = ""
Else
s.SubItems(2) = rst3!capbac End If
If IsNull(rst3!chuyenkhoa) Then s.SubItems(3) = ""
Else
s.SubItems(3) = rst3!chuyenkhoa End If
End If
rst3.MoveNext Wend
End If
rst1.MoveNext Wend
Me.CmdAdd.Enabled = True Me.cmdluu.Enabled = True Me.cmdxoa.Enabled = True
'Me.cmdnewdv.Enabled = True 'Me.cmdsavedv.Enabled = True 'Me.cmddeletedv.Enabled = True Skin.RemoveSkin Me.cmdnewdv.hwnd Me.cmdnewdv.Caption = "Thêm dịch vụ"
Skin.LoadSkin App.Path & "\_temp.skn"
Skin.ApplySkin Me.cmdnewdv.hwnd Me.cmbmanhanvien.Clear
Me.txttendichvu = ""
Me.txtdongia = ""
Me.txttennhanvien = ""
Me.txtchuyenkhoa = ""
b = True
Me.cmdAddlist.Visible = False Me.cmddeletelist.Visible = False End If
End Sub
2.9 Mã nguồn thủ tục cmdsavedv_Click()