Chào các bạn! Truyen4U chính thức đã quay trở lại rồi đây!^^. Mong các bạn tiếp tục ủng hộ truy cập tên miền Truyen4U.Com này nhé! Mãi yêu... ♥

hoanthanhvb

Dim cnn As New ADODB.Connection 'Ket noi

Dim rs As New ADODB.Recordset   'Chua CSDL

Dim flag As Integer             'Co, de chua trang thai lam viec

Private Sub cmdDelete_Click()

    Dim kq

    kq = MsgBox("Ban co dong y xoa khong?", vbYesNo, "Thong bao")

    If (kq = vbYes) Then

        rs.Delete

        If rs.EOF Then

            Exit Sub

        Else

            rs.MoveFirst

            txtMNV.Text = rs.Fields("MNV")

            txtHT.Text = rs.Fields("HoTen")

            txtNS.Text = rs.Fields("NgaySinh")

            If rs.Fields("GT") = True Then

                optNam.Value = True

                optNu.Value = False

            Else

                optNam.Value = False

                optNu.Value = True

            End If

        End If

    Else

        Exit Sub

    End If

End Sub

Private Sub cmdFirst_Click()

        'Chuyen ve ban ghi dau tien

    rs.MoveFirst

        'Lay du lieu tu ban ghi hien thi len Form

    txtMNV.Text = rs.Fields("MNV")

    txtHT.Text = rs.Fields("HoTen")

    txtNS.Text = rs.Fields("NgaySinh")

    If rs.Fields("GT") = True Then

        optNam.Value = True

        optNu.Value = False

    Else

        optNam.Value = False

        optNu.Value = True

    End If

End Sub

Private Sub cmdLast_Click()

    rs.MoveLast

    txtMNV.Text = rs.Fields("MNV")

    txtHT.Text = rs.Fields("HoTen")

    txtNS.Text = rs.Fields("NgaySinh")

    If rs.Fields("GT") = True Then

         optNam.Value = True

         optNu.Value = False

    Else

         optNam.Value = False

         optNu.Value = True

    End If

End Sub

Private Sub cmdNew_Click()

    txtMNV.SetFocus 'Dat con tro soan thao

    txtMNV.Text = ""

    txtHT.Text = ""

    txtNS.Text = ""

    flag = 1

    cmdSave.Enabled = True

End Sub

Private Sub cmdNext_Click()

    If rs.EOF Then

        Exit Sub

    Else

        rs.MoveNext

        If rs.EOF Then rs.MoveLast

        txtMNV.Text = rs.Fields("MNV")

        txtHT.Text = rs.Fields("HoTen")

        txtNS.Text = rs.Fields("NgaySinh")

        If rs.Fields("GT") = True Then

            optNam.Value = True

            optNu.Value = False

        Else

            optNam.Value = False

            optNu.Value = True

        End If

    End If

End Sub

Private Sub cmdPrevious_Click()

    If rs.BOF Then  'Kiem tra co dang o ban ghi dau tien khong

        Exit Sub    'Neu dang o ban ghi dau tien thi dung

    Else

            'Di chuyen ve ban ghi truoc

        rs.MovePrevious

        If rs.BOF Then rs.MoveFirst

            'Lay thong tin tu co so du lieu dat len Form

        txtMNV.Text = rs.Fields("MNV")

        txtHT.Text = rs.Fields("HoTen")

        txtNS.Text = rs.Fields("NgaySinh")

        If rs.Fields("GT") = True Then

            optNam.Value = True

            optNu.Value = False

        Else

            optNam.Value = False

            optNu.Value = True

        End If

    End If

End Sub

Private Sub cmdThem_Click()

End Sub

Private Sub cmdSave_Click()

    If flag = 1 Then

        rs.AddNew

    End If

    rs.Fields("MNV") = txtMNV.Text

    rs.Fields("HoTen") = txtHT.Text

    rs.Fields("NgaySinh") = txtNS.Text

    If (optNam.Value = True) Then

        rs.Fields("GT") = True

    End If

    If (optNu.Value = True) Then

        rs.Fields("GT") = False

    End If

    rs.Update

    cmdSave.Enabled = False

End Sub

Private Sub cmdUpdate_Click()

    txtMNV.SetFocus 'Dat con tro soan thao

    flag = 2

    cmdSave.Enabled = True

End Sub

Private Sub Form_Load()

        'Ket noi CSDL

    If cnn.State = adStateOpen Then cnn.Close

    cnn.CursorLocation = adUseClient

    cnn.Provider = "Microsoft.Jet.Oledb.4.0"

    cnn.ConnectionString = "Data\QLNV.mdb"

    cnn.Open

        'Mo bang can lien ket

    rs.Open "select * from tblNhanVien", cnn, adOpenDynamic, _

                                adLockOptimistic, adCmdText

        'Dua du lieu tu bang len tung dieu khien

    txtMNV.Text = rs.Fields("MNV")

    txtHT.Text = rs.Fields("HoTen")

    txtNS.Text = rs.Fields("NgaySinh")

    If rs.Fields("GT") = True Then

        optNam.Value = True

        optNu.Value = False

    Else

        optNam.Value = False

        optNu.Value = True

    End If

        'Khoa nut Save chua cho thuc hien

    cmdSave.Enabled = False

End Sub

Bạn đang đọc truyện trên: Truyen4U.Com

Tags: