II. Hoạch định CSDL tại công t y( câu hỏi phỏng vấn trưởng phòng kỹ thuật)
MÃ MỘT SỐ GIAO DIỆN CHƯƠNG TRÌNH Module tạo form quản lý nhân viên
Dim da As CSDL
'============================================================= ============
'Thu tuc lay ra cac du lieu cho cac Combo box
Private Sub AddDatatoCombox(control As ComboBox, strSQL As String) Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset Set rs = da.getRS(strSQL)
While (Not rs.EOF)
control.AddItem rs.Fields(1) rs.MoveNext
Wend rs.Close End Sub
Private Sub Init()
Dim strSQL As String
Me.DTPickerBDCT.Value = Date Me.DTPickerKTCT.Value = Date
AddDatatoCombox cboPhongban, "SELECT * FROM Phongban" AddDatatoCombox cboChucvu, "SELECT * FROM Chucvu" End Sub
Private Sub cboChucvu_KeyPress(KeyAscii As Integer) KeyAscii = 0 End Sub Else KeyAscii = 0 End If End Sub
Private Sub cboPhai_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then cmdChapnhan_Click Else KeyAscii = 0 End If End Sub
Private Sub cboPhongban_KeyPress(KeyAscii As Integer) KeyAscii = 0
End Sub
Private Sub cmdBoqua_Click() Me.txtDiachi = "" Me.txtDienthoai = "" Me.txtManv = "" Me.txtHoten = "" Me.txtSoCMNN = "" Me.txtTrinhdo = "" Me.txtQuequan = "" Me.cboPhai.Text = "" Me.cboPhongban.Text = "" Me.cboChucvu.Text = "" Me.cboBacluong.Text = "" End Sub
Function Get_ID(Tenbang As String, Tentruong As String, giatri As String) As String Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset Dim strSQL As String
strSQL = "SELECT * FROM " & Tenbang & " WHERE " & Tentruong & " ='" & giatri & "'"
Set rs = da.getRS(strSQL) Get_ID = rs.Fields(0)
End Function
Private Sub Refresh_TPGD() Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset
Set rs = da.getRS("SELECT * FROM tpgiadinh WHERE Manv='" & Me.txtManv & "'")
Set DataTPGD.DataSource = rs End Sub
Private Sub Refresh_QTCT() Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset
Set rs = da.getRS("SELECT * FROM qtct WHERE Manv='" & Me.txtManv & "'") Set DataQTCT.DataSource = rs
End Sub
++++++++++++++++++++++++++++++++++++++++++++++
'Cập nhật các thông tin trong bảng Nhân viên
Private Sub Update_Nhanvien() On Error GoTo errhandler Dim strSQL As String
If (Trim(Me.txtDiachi.Text) <> "") And (Me.txtQuequan <> "") And (Me.cboGioitinh <> "") Then
End If
If Trim(cboPhongban) = "" Then
MsgBox "Chưa chọn Phòng ban", vbInformation SSTab.Tab = 1
cboPhongban.SetFocus Exit Sub
End If
If Trim(cboChucvu) = "" Then
MsgBox "Chưa chọn Chức vụ", vbInformation SSTab.Tab = 1
cboChucvu.SetFocus Exit Sub
End If
If Trim(cboBacluong) = "" Then
MsgBox "Chưa chọn Bậc lương", vbInformation SSTab.Tab = 1
cboBacluong.SetFocus Exit Sub
End If
maPhongban = Get_ID("phongban", "Tenphongban", Me.cboPhongban.Text) machucvu = Get_ID("chucvu", "Tenchucvu", Me.cboChucvu.Text)
mabacluong = Get_ID("bacluong", "Tenbacluong", Me.cboBacluong.Text) strSQL = "UPDATE Hosocanbo SET " & _
"Hoten='" & EscStr(Me.txtHoten) & "'," & _ "Diachi='" & EscStr(Me.txtDiachi) & "'," & _ "Quequan='" & EscStr(Me.txtQuequan) & "'," & _ "SoCMND='" & Me.txtSoCMNN & "'," & _ "Ngaysinh='" & Me.dtNgaysinh.Value & "'," & _ "Gioitinh='" & Me.cboGioitinh.Text & "'," & _ "Dienthoai='" & EscStr(Me.txtDienthoai) & "'," & _ "Trinhdovanhoa='" & EscStr(Me.txtTrinhdo) & "'," & _ "Maphongban='" & maPhongban & "'," & _
"Machucvu='" & machucvu & "'," & _
"Mabacluong='" & mabacluong & "' WHERE manv ='" & txtManv.Text & "'"
Debug.Print strSQL
da.getConnection.Execute strSQL Else
MsgBox "Bạn phải nhập đầy đủ Địa chỉ, Quê quán và Giới tính cho nhân viên!", vbInformation, "QLNS"
End If Exit Sub
MsgBox "Error:" & Err.Description, vbCritical End Sub
End Sub
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++
' Thêm mới một Hồ sơ
Private Sub Insert_Hoso() On Error GoTo errhandler Dim strSQL As String
If (Trim(Me.txtDiachi.Text) <> "") And (Me.txtQuequan <> "") And (Me.cboGioitinh <> "") Then
Dim, maPhongban, machucvu, mabacluong As String If Trim(cboPhongban) = "" Then
MsgBox "Chưa chọn Phòng ban", vbInformation SSTab.Tab = 1
cboPhongban.SetFocus Exit Sub
End If
If Trim(cboChucvu) = "" Then
MsgBox "Chưa chọn Chức vụ", vbInformation SSTab.Tab = 1
Exit Sub End If
maPhongban = Get_ID("phongban", "Tenphongban", Me.cboPhongban.Text) machucvu = Get_ID("chucvu", "Tenchucvu", Me.cboChucvu.Text)
mabacluong = Get_ID("bacluong", "Tenbacluong", Me.cboBacluong.Text) strSQL = "INSERT INTO Hosocanbo( " & _
"Manv,Hoten,Diachi,Quequan,SoCMND,Ngaysinh,Gioitinh,Dienthoai,Trinhdo," & _ ,Maphongban," & _
"Machucvu,Mabacluong) VALUES ('" & _ EscStr(Me.txtManv) & "','" & _
EscStr(Me.txtHoten) & "','" & EscStr(Me.txtDiachi) & "','" & EscStr(Me.txtQuequan) & "','" & _
Me.txtSoCMNN & "'," & Me.dtNgaysinh.Value & ",'" & Me.cboGioitinh.Text & "','" & _
EscStr(Me.txtDienthoai) & "','" & EscStr(Me.txtTrinhdo) & "','" & _ ','" & matongiao & "','" & maPhongban & "','" & _
machucvu & "','" & mabacluong & "')" 'Debug.Print strSQL
da.getConnection.Execute strSQL Else
End If Exit Sub errhandler:
MsgBox "Error:" & Err.Description, vbCritical End Sub
'
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++
Private Sub cmdThoat_Click() Unload Me
End Sub
Private Sub cmdXoa_Click() On Error GoTo errhandler
If (SSTab.Tab = 0) Or (SSTab.Tab = 1) Then
If MsgBox("Bạn chắc chắn là muốn xóa hết tất cả những thông tin về nhân viên này?", vbOKCancel, "QLNS") = vbOK Then
' Xóa những thông tin trong bảng quá trình công tác
strSQL = "DELETE FROM qtct WHERE Manv='" & EscStr(txtManv.Text) & "'"
da.getConnection.Execute strSQL ' Xóa những thông tin trong bảng Lương
strSQL = "DELETE FROM luong WHERE Manv='" & EscStr(txtManv.Text) & "'"
da.getConnection.Execute strSQL
' Xóa những thông tin trong bảng Bảng chấm công
strSQL = "DELETE FROM Bangchamcong WHERE Manv='" & EscStr(txtManv.Text) & "'"
da.getConnection.Execute strSQL
' Xóa những thông tin trong bảng nhân viên
strSQL = "DELETE FROM hosocanbo WHERE Manv='" & EscStr(txtManv.Text) & "'" da.getConnection.Execute strSQL cmdBoqua_Click End If End If
If (SSTab.Tab = 2) And (Trim(txtMaQTCT) <> "") Then
If MsgBox("Bạn chắc chắn là muốn xóa Quá trình đào tạo này?", vbOKCancel, "QLNS") = vbOK Then
End If Exit Sub errhandler:
' Thủ tục lấy tên các phòng ban và tên chức vụ Function TimTen(sSQL As String) As String Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset Set rs = da.getRS(sSQL) If rs Is Nothing Then TimTen = "" Else TimTen = rs.Fields(1).Value End If End Function
Private Sub Form_Load() Set da = New CSDL Init
SSTab.Tab = 0 End Sub
Private Sub SSTab_Click(PreviousTab As Integer) If SSTab.Tab = 2 Then
Refresh_QTCT End If If SSTab.Tab = 3 Then Refresh_TPGD End If End Sub
Private Sub txtDiachi_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
cmdChapnhan_Click End If
End Sub
Private Sub txtDienthoai_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
cmdChapnhan_Click End If
End Sub
Private Sub txtQuequan_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
cmdChapnhan_Click End If
End Sub
Private Sub txtSoCMNN_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
cmdChapnhan_Click End If
End Sub
Private Sub txtTrinhdo_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
cmdChapnhan_Click End If