VB07ct1
Dim strDK(0 To 4) As String
Dim i As Byte
Dim S, t, traloi As String
Private Declare Sub InitCommonControls Lib "comctl32.dll" ()
Private Sub Form_Initialize()
InitCommonControls
End Sub
Private Sub CmdThem_Click()
cbxsxuat.Visible = False
DTPSXuat.Visible = True
DTPHHan.Visible = True
CbxHHan.Visible = False
End Sub
Private Sub Cmdthem1_Click()
cbxsxuat.Visible = False
DTPSXuat.Visible = True
DTPHHan.Visible = True
CbxHHan.Visible = False
End Sub
Sub Kiemtra()
If RS.State = adStateOpen Then
RS.Close
End If
End Sub
Private Sub CbxNhanvien_click()
S = "select * from mathang where nhapxuat like '%" & Trim(CbxNhanvien.Text) & "%'"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Set dtgBang.DataSource = RS
End Sub
Private Sub Cbxsoluong_click()
S = "select * from mathang where soluong =" & Trim(Cbxsoluong.Text)
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Set dtgBang.DataSource = RS
End Sub
Private Sub CmdHuy_Click()
CbxMasp.Text = ""
TxtTensp.Text = ""
TxtGhichu.Text = ""
CbxNhanvien.Text = ""
TxtDonGia.Text = ""
Cbxsoluong.Text = ""
CbxMasp.Enabled = True
cmdluu.Enabled = False
CmdHuy.Enabled = False
End Sub
Private Sub TxtDonGia_keypress(m As Integer)
If ChkDongia.Value <> 1 Then
If m = 13 Then
S = "select * from mathang where dongia like '%" & Trim(TxtDonGia.Text) & "%'"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Set dtgBang.DataSource = RS
End If
End If
End Sub
Private Sub txttensp_keypress(m As Integer)
If m = 13 Then
S = "select * from mathang where tensp like '%" & Trim(TxtTensp.Text) & "%'"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Set dtgBang.DataSource = RS
End If
End Sub
Private Sub CbxMasp_Click()
If ChkMa.Value <> 1 Then
S = "select * from mathang where masp like'" & CbxMasp.Text & "'"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Set dtgBang.DataSource = RS
End If
End Sub
Private Sub cbxsxuat_Click()
If ChkNgay.Value <> 1 Then
S = "select * from mathang where ngaysx =# " & cbxsxuat.Text & "#"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Set dtgBang.DataSource = RS
End If
End Sub
Private Sub cbxhhan_Click()
If ChkNgayhh.Value <> 1 Then
S = "select * from mathang where ngayhh =# " & CbxHHan.Text & "#"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Set dtgBang.DataSource = RS
End If
End Sub
Private Sub cmdluu_Click()
S = "update mathang set tensp = '" & Trim(TxtTensp.Text) & "',dongia = '" & Val(Trim(TxtDonGia.Text)) & "'," & _
"Soluong = '" & Val(Trim(Cbxsoluong.Text)) & "',Nhapxuat =' " & Trim(CbxNhanvien.Text) & "',Ngaysx = #" & Format(DTPSXuat.Value, "dd/mm/yyyy") & "#," & _
"ngayhh = #" & Format(DTPHHan.Value, "dd/mm/yyyy") & "#,ghichu = '" & Trim(TxtGhichu.Text) & "' where masp = '" & CbxMasp & "'"
cn.Execute S
MsgBox "Sua Va Luu Thong Tin Thanh Cong ", vbinfomation, "Sua Thong Tin"
Call napdl
cmdluu.Enabled = False
CmdHuy.Enabled = False
CbxMasp.Enabled = True
End Sub
Private Sub CmdNhap_Click()
CmdSave.Enabled = True
CbxMasp.Text = ""
TxtTensp.Text = ""
TxtGhichu.Text = ""
CbxNhanvien.Text = ""
TxtDonGia.Text = ""
Cbxsoluong.Text = ""
CbxMasp.Enabled = True
CmdHuy.Enabled = False
cmdluu.Enabled = False
CbxMasp.SetFocus
cbxsxuat.Visible = False
CbxHHan.Visible = False
DTPSXuat.Visible = True
DTPSXuat.Value = RS!ngaysx
DTPHHan.Visible = True
DTPHHan.Value = RS!ngayhh
dtgBang.Enabled = False
CmdSua.Enabled = False
End Sub
Private Sub CmdSave_Click()
S = "Select * from mathang where trim(masp) = '" & CbxMasp.Text & "'"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
If Not RS.EOF Then
MsgBox "Ban Da Nhap Ma San Pham Nay Roi, Xin Vui Long Nhap Lai !", vbExclamation, "Them Moi"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Set dtgBang.DataSource = RS
CbxMasp.Text = ""
CbxMasp.SetFocus
End If
If Trim(CbxMasp.Text) = "" Then
MsgBox "Ban Chua Nhap Ma San Pham", vbInformation, "Thong Tin"
CbxMasp.SetFocus
Exit Sub
End If
If TxtTensp.Text = "" Then
MsgBox "Ban Chua Nhap Ten San Pham", vbInformation, "Thong Tin"
TxtTensp.SetFocus
Exit Sub
End If
If Trim(CbxNhanvien.Text) = "" Then
MsgBox "Ban Chua Nhap Nguoi Nhap Hang", vbInformation, "Thong Tin"
CbxNhanvien.SetFocus
Exit Sub
End If
If DTPSXuat.Value > DTPHHan.Value Then
MsgBox "San Xuat Sau Khi Het Han Su Dung !", vbInformation, "Thong Tin"
DTPHHan.SetFocus
Exit Sub
End If
If TxtDonGia.Text = "" Then
MsgBox "Ban Chua Nhap Don Gia Cua San Pham", vbInformation, "Thong Tin"
TxtDonGia.SetFocus
Exit Sub
End If
If Cbxsoluong.Text = "" Then
MsgBox "Ban Chua Nhap So Luong San Pham", vbInformation, "Thong Tin"
Cbxsoluong.SetFocus
Exit Sub
End If
S = "insert into mathang(masp,tensp,dongia,soluong,nhapXuat,ngaysx,ngayhh,ghichu)values('" & CbxMasp.Text & "'," & _
"'" & TxtTensp.Text & "','" & Val(TxtDonGia.Text) & "','" & Val(Cbxsoluong.Text) & "','" & CbxNhanvien.Text & "'," & _
"#" & Format(DTPSXuat.Value, "dd/mm/yyyy") & "#,#" & Format(DTPHHan.Value, "dd/mm/yyyy") & "#,'" & TxtGhichu.Text & "')"
Call Kiemtra
cn.Execute S
MsgBox " Cap nhat thong tin thanh cong", vbOKOnly + vbInformation, "Thong tin"
CmdSave.Enabled = False
Call napdl
dtgBang.Enabled = True
CmdSua.Enabled = True
End Sub
Private Sub CmdSua_Click()
DTPHHan.Visible = True
CbxHHan.Visible = False
cbxsxuat.Visible = False
DTPSXuat.Visible = True
CmdHuy.Enabled = True
If RS.EOF = False Then
DTPHHan.Value = RS!ngayhh
DTPSXuat.Value = RS!ngaysx
dtgBang.Enabled = True
End If
CbxMasp.Enabled = False
cmdluu.Enabled = True
End Sub
Private Sub Cmdthoat_Click()
End
End Sub
Sub napdl()
S = "select * from Mathang"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Set dtgBang.DataSource = RS
dtgBang.HeadFont.Bold = True
dtgBang.ForeColor = vbRed
dtgBang.Columns(0).Width = 800
dtgBang.Columns(1).Width = 2000
dtgBang.Columns(2).Width = 1500
dtgBang.Columns(3).Width = 1500
dtgBang.Columns(4).Width = 2500
dtgBang.Columns(5).Width = 1500
dtgBang.Columns(6).Width = 1500
dtgBang.Columns(7).Width = 5000
End Sub
Private Sub Cmdtim_Click()
cbxsxuat.Visible = True
DTPSXuat.Visible = False
DTPHHan.Visible = False
CbxHHan.Visible = True
For i = 0 To 4
strDK(i) = ""
Next i
If ChkMa.Value = 1 Then
strDK(0) = " and masp like '%" & Trim(CbxMasp.Text) & "%'"
End If
If ChkTen.Value = 1 Then
strDK(1) = " and tensp like '%" & Trim(TxtTensp.Text) & "%'"
End If
If ChkNgay.Value = 1 Then
strDK(2) = " and ngaysx = #" & Trim(cbxsxuat.Text) & "#"
End If
If ChkNgayhh.Value = 1 Then
strDK(3) = " and ngayhh = #" & Trim(CbxHHan.Text) & "#"
End If
If ChkDongia.Value = 1 Then
strDK(4) = " and dongia like '%" & Trim(TxtDonGia.Text) & "%'"
End If
t = ""
For i = 0 To 4
t = t & strDK(i)
Next i
S = "select * from mathang where masp"
S = S & t
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Set dtgBang.DataSource = RS
dtgBang.Enabled = True
End Sub
Private Sub dtgBang_Click()
If RS.EOF = False Then
CbxNhanvien.Text = RS!nhapxuat
TxtTensp.Text = RS!tensp
Cbxsoluong.Text = RS!soluong
cbxsxuat.Text = RS!ngaysx
CbxHHan.Text = RS!ngayhh
TxtDonGia.Text = RS!dongia
TxtGhichu.Text = RS!ghichu
CbxMasp.Text = RS!masp
End If
End Sub
Private Sub Form_Load()
CmdSave.Enabled = False
Set cn = New ADODB.Connection
cn.Open "DSN=mathang"
dtgBang.AllowUpdate = False
dtgBang.Enabled = True
S = "select distinct Nhapxuat from mathang"
cbxsxuat.Visible = True
CbxHHan.Visible = True
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Do While Not RS.EOF
CbxNhanvien.AddItem RS!nhapxuat
RS.MoveNext
Loop
S = "select Masp from Mathang"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Do While Not RS.EOF
CbxMasp.AddItem RS!masp
RS.MoveNext
Loop
S = "select distinct Ngaysx from Mathang"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Do While Not RS.EOF
cbxsxuat.AddItem RS!ngaysx
RS.MoveNext
Loop
S = "select distinct ngayhh from mathang"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Do While Not RS.EOF
CbxHHan.AddItem RS!ngayhh
RS.MoveNext
Loop
S = "select distinct soluong from mathang"
Call Kiemtra
RS.Open S, cn, adOpenKeyset, adLockOptimistic
Do While Not RS.EOF
Cbxsoluong.AddItem RS!soluong
RS.MoveNext
Loop
Call napdl
End Sub
Bạn đang đọc truyện trên: Truyen247.Pro