Vous êtes sur la page 1sur 16

Build Bright University -1-

dMeNaHRsay
Coding

1. kUdenAkñúg Module- MduDB

Option Explicit

Public conn As New ADODB.Connection


Public Rs As New ADODB.Recordset

Public Sub openConnection()


If conn.State = 0 Then
conn.Open "DSN=SaleProductDSN"
End If
End Sub

'Checking Data format


Public Function isValidDateFormat(ByVal txt As TextBox) As Boolean
Dim d As Date
On Error GoTo Error_Block
d = CDate(txt.Text)
isValidDateFormat = True
Exit Function
Error_Block:
isValidDateFormat = False
End Function

2. kUdenAelI Form- frmProductCategory


+cmdSave_Click()

Private Sub cmdSave_Click()


Dim Msg As String
Dim isNotValidInput As Boolean

If txtCategoryID.Text = "" Then


Msg = "Category ID does not allow Null"
isNotValidInput = True
ElseIf Len(txtCategoryID.Text) <> 4 Then
Msg = "CategoryID must have 4 characters"
isNotValidInput = True
ElseIf isDuplicatedID() = True Then
Msg = "Category ID already exist"
isNotValidInput = True
ElseIf txtCategoryName.Text = "" Then
Msg = "Category name does not allow null"
isNotValidInput = True
Else
isNotValidInput = False
'Save data to Table-ProductCategory
Rs.Open "ProductCategory", conn, adOpenDynamic, adLockOptimistic
Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)
Build Bright University -2-
Rs.AddNew
Rs.Fields("PCatID") = txtCategoryID.Text
Rs.Fields("PCatName") = txtCategoryName.Text
Rs.Fields("Description") = txtDescription.Text
Rs.Update
Rs.Close

'Cleare input value after save


txtCategoryID.Text = ""
txtCategoryID.SetFocus
txtCategoryName.Text = ""
txtDescription.Text = ""
End If

'Display message if invalid input


If isNotValidInput = True Then
MsgBox Msg, vbOKOnly, "Input validation"
End If
frmnewProduct.txtCategory.Text = txtCategoryID.Text
Unload Me
End Sub

+ isDuplicatedID( )

Private Function isDuplicatedID() As Boolean


Rs.Open "ProductCategory", conn, adOpenDynamic
Rs.Find "PCatID='" & txtCategoryID.Text & "'"
isDuplicatedID = Not Rs.EOF
Rs.Close
End Function

+ cmdCancel_Click

Private Sub cmdCancel_Click()


Unload Me
End Sub

3. kUdenAelI Form- frmnewProduct


+ cmdSave_Click( )

Private Sub cmdSave_Click()


Dim Msg As String
Dim isNotValidInput As Boolean

If txtProductID.Text = "" Then


txtProductID.SetFocus
Msg = "ProductID do not null"
isNotValidInput = True
ElseIf Len(txtProductID.Text) <> 9 Then
txtProductID.SetFocus
Msg = "Product ID must take 9 characters"
isNotValidInput = True

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University -3-
ElseIf isDuplicatedID() = True Then
txtProductID.SetFocus
Msg = "Product ID already exist"
isNotValidInput = True
ElseIf txtProductName.Text = "" Then
txtProductName.SetFocus
Msg = "Product name do not null"
isNotValidInput = True
ElseIf isNotPCatID() = True Then
If MsgBox("Invalid Product Category ID" & vbNewLine & "Do you to add new
Category ID?", vbYesNo, "Invalid") = vbNo Then
txtCategory.SetFocus
Else
cmdNewCategory_Click
End If
Else
Rs.Open "Product", conn, adOpenDynamic, adLockOptimistic
Rs.AddNew
Rs.Fields("ProID") = txtProductID.Text
Rs.Fields("ProName") = txtProductName.Text
Rs.Fields("PCatID") = txtCategory.Text
Rs.Fields("QuantityInStock") = CInt(txtQuantity.Text)
Rs.Update
Rs.Close

txtProductID.Text = ""
txtProductID.SetFocus
txtProductName.Text = ""
txtCategory.Text = ""
txtQuantity.Text = "0"
End If

If isNotValidInput = True Then


MsgBox Msg, , "Input validation"
End If
End Sub

+ isDuplicatedID()

Public Function isDuplicatedID() As Boolean


Rs.Open "Product", conn, adOpenDynamic, adLockReadOnly
Rs.Find "ProID='" & txtProductID.Text & "'"
isDuplicatedID = Not Rs.EOF
Rs.Close
End Function

+ isNotPCatID()

Public Function isNotPCatID() As Boolean


Rs.Open "ProductCategory", conn, adOpenDynamic, adLockReadOnly
Rs.Find "PCatID='" & txtCategory.Text & "'"
isNotPCatID = Rs.EOF
Rs.Close

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University -4-
End Function

+ cmdNewCategory_Click()

Private Sub cmdNewCategory_Click()


frmProductCategory.txtCategoryID.Text = Me.txtCategory.Text
frmProductCategory.Show vbModal
End Sub

+ Sub cmdCancel_Click()

Private Sub cmdCancel_Click()


Unload Me
End Sub

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University -5-

4. cUreFVIkarsresrkUdenAelI Form frmNewEmployee³


+ cmdSave_Click()

Private Sub cmdSave_Click()


Dim Msg As String
Dim isNotValidInput As Boolean

If txtEmployeeID.Text = "" Then


txtEmployeeID.SetFocus
Msg = "Employee ID does not allow null"
isNotValidInput = True
ElseIf Len(txtEmployeeID.Text) <> 4 Then
txtEmployeeID.SetFocus
Msg = "Employee ID must have 4 characters"
isNotValidInput = True
ElseIf isDuplicatedID() = True Then
txtEmployeeID.SetFocus
Msg = "Employee ID aready exist"
isNotValidInput = True
ElseIf txtEmployeeName.Text = "" Then
txtEmployeeName.SetFocus
Msg = "Employee name does not allow null"
isNotValidInput = True
ElseIf StrComp(txtSex.Text, "M", vbTextCompare) <> 0 And
StrComp(txtSex.Text, "F", vbTextCompare) Then
txtSex.SetFocus
Msg = "Sex must tak 'M' or 'F'"
isNotValidInput = True
ElseIf txtFunction.Text = "" Then
txtFunction.SetFocus
Msg = "Function does not allow null"
isNotValidInput = True
Else
Rs.Open "Employee", conn, adOpenDynamic, adLockOptimistic
Rs.AddNew
Rs.Fields("EmpID") = txtEmployeeID.Text
Rs.Fields("Name") = txtEmployeeName.Text
Rs.Fields("Sex") = txtSex.Text
Rs.Fields("Function") = txtFunction.Text
Rs.Fields("Phone") = txtPhone.Text
Rs.Update
Rs.Close

'Cleare input field after complete save


txtEmployeeID.Text = ""
txtEmployeeID.SetFocus
txtEmployeeName.Text = ""
txtSex.Text = ""
txtFunction.Text = ""
txtPhone.Text = ""

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University -6-
End If
If isNotValidInput = True Then
MsgBox Msg, , "Input validation"
End If
End Sub

+ isDuplicatedID() { True:exist, False: not exist }

Private Function isDuplicatedID() As Boolean


Rs.Open "Employee", conn, adOpenDynamic, adLockReadOnly
Rs.Find "EmpID='" & txtEmployeeID.Text & "'"
isDuplicatedID = Not Rs.EOF
Rs.Close
End Function

5. cUreFVIkarsresrkUdenAelI Form frmNewCustomer³


+ cmdSave_Click()

Private Sub cmdSave_Click()


Dim Msg As String
Dim isNotValidInput As Boolean

If txtCustomerID.Text = "" Then


txtCustomerID.SetFocus
Msg = "Customer ID does not allow null"
isNotValidInput = True
ElseIf Len(txtCustomerID.Text) <> 6 Then
txtCustomerID.SetFocus
Msg = "Customer ID takes 4 character"
isNotValidInput = True
ElseIf isDuplicatedID() = True Then
txtCustomerID.SetFocus
Msg = "Customer ID already exist"
isNotValidInput = True
ElseIf txtCustomerName.Text = "" Then
txtCustomerName.SetFocus
Msg = "Customer name does not allow null"
isNotValidInput = True
ElseIf txtAddress.Text = "" Then
txtAddress.SetFocus
Msg = "Customer Address does not allow null"
isNotValidInput = True
Else
isNotValidInput = False
'Save all input data to Table-Customer
Rs.Open "Customer", conn, adOpenDynamic, adLockOptimistic
Rs.AddNew
Rs.Fields("CusID") = txtCustomerID.Text
Rs.Fields("Name") = txtCustomerName.Text
Rs.Fields("Address") = txtAddress.Text
Rs.Fields("Phone") = txtPhone.Text
Rs.Update

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University -7-
Rs.Close

'Cleare all input value


txtCustomerID.Text = ""
txtCustomerID.SetFocus
txtCustomerName.Text = ""
txtAddress.Text = ""
txtPhone.Text = ""
End If
If isNotValidInput = True Then
MsgBox Msg, , "Input validation"
End If
End Sub

+ isDuplicatedID() { True:exist, False: not exist }

Private Function isDuplicatedID() As Boolean


Rs.Open "Customer", conn, adOpenDynamic, adLockReadOnly
Rs.Find "CusID='" & txtCustomerID.Text & "'"
isDuplicatedID = Not Rs.EOF
Rs.Close
End Function

6. cUreFVIkarsresrkUdenAelI Form frmReceivedProduct³


+ Form_Load()

Private Sub Form_Load()


lblReceivedID.Caption = Format(getReceivedID(), "00000#")
txtReceivedDate.Text = Format(Now(), "mm-dd-yyyy")

'Cleare all combox value


cboEmployeeID.Clear
cboProductID.Clear
lvReceivedItem.ListItems.Clear

'Open EmployeeID to EmployeeID combobox


Rs.Open "Employee", conn, adOpenKeyset
While Rs.EOF = False
cboEmployeeID.AddItem Rs.Fields("EmpID")
Rs.MoveNext
Wend
Rs.Close

Rs.Open "Product", conn, adOpenKeyset


While Rs.EOF = False
cboProductID.AddItem Rs.Fields("ProID")
Rs.MoveNext
Wend
Rs.Close

'Setup Form size


Me.BorderStyle = vbFixedSingle

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University -8-
Me.Width = 9210
Me.Height = 6840
End Sub

+ getReceivedID() { n: long integer }

Private Function getReceivedID() As Long


Dim sql As String
sql = "Select RProID From ReceivedProduct Order By RProID DESC"
Rs.Open sql, conn, adOpenDynamic
If Rs.EOF = True Then
getReceivedID = 1
Else
Rs.MoveFirst
getReceivedID = Rs.Fields("RProID") + 1
End If
Rs.Close
End Function

+ cboEmployeeID_Click()

Private Sub cboEmployeeID_Click()


'Cleare all Employee Information input fields
lblEmployeeName.Caption = ""
lblFunction.Caption = ""
Rs.Open "Select * from Employee where EmpID='" & cboEmployeeID.Text & "'",
conn, adOpenDynamic, adLockReadOnly
If Rs.EOF = False Then
lblEmployeeName.Caption = Rs.Fields("Name")
lblFunction.Caption = Rs.Fields("Function")
End If
Rs.Close
End Sub

+ cmdReceived_Click()

Private Sub cmdReceived_Click()


Dim Msg As String
Dim isNotValidInput As Boolean

If txtReceivedDate.Text = "" Then


txtReceivedDate.SetFocus
Msg = "Received date does not allow null"
isNotValidInput = True
ElseIf isValidDateFormat(txtReceivedDate) = False Then
txtReceivedDate.SetFocus
Msg = "Received date you input not date format"
isNotValidInput = True
ElseIf cboEmployeeID.Text = "" Then
cboEmployeeID.SetFocus
Msg = "EmployeeID does not allow null"
isNotValidInput = True
Else

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University -9-
'Save data to Table-ReceivedProduct
Rs.Open "ReceivedProduct", conn, adOpenDynamic, adLockOptimistic
Rs.AddNew
Rs.Fields("RProID") = CLng(lblReceivedID.Caption)
Rs.Fields("ReceivedDate") = CDate(txtReceivedDate.Text)
Rs.Fields("EmpID") = cboEmployeeID.Text
Rs.Update
Rs.Close

'Enable the next button


cboProductID.Enabled = True
txtQuantity.Enabled = True
txtUnitPrice.Enabled = True
txtExpiredDate.Enabled = True
cmdReceivedItem.Enabled = True
cmdReceived.Enabled = False
txtReceivedDate.Enabled = False
End If
If isNotValidInput = True Then
MsgBox Msg, , "Validate Input"
End If
End Sub

+ cboProductID_Click()

Private Sub cboProductID_Click()

'Clear all input Product information from control


lblProductName.Caption = ""
txtQuantity.Text = "0"
txtUnitPrice.Text = "0"
txtExpiredDate.Text = ""

Rs.Open "Select * from Product where ProID='" & cboProductID.Text & "'",
conn, adOpenDynamic, adLockReadOnly
If Rs.EOF = False Then
lblProductName.Caption = Rs.Fields("ProName")
End If
Rs.Close
End Sub

+ cmdReceivedItem_Click()

Private Sub cmdReceivedItem_Click()


Dim Msg As String
Dim isNotValidInput As Boolean

If CInt(txtQuantity.Text) < 0 Then


txtQuantity.SetFocus
Msg = "Quantity you input, do not less than zero"
isNotValidInput = True
ElseIf CSng(txtUnitPrice.Text) < 0 Then
txtUnitPrice.SetFocus

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University - 10 -
Msg = "UnitPrice you input, do not less than zero"
isNotValidInput = True
ElseIf isValidDateFormat(txtExpiredDate) = False Then
txtExpiredDate.SetFocus
Msg = "Expired date do not date format"
isNotValidInput = True
ElseIf cboProductID.Text = "" Then
cboProductID.SetFocus
Msg = "Product ID does not allow null"
isNotValidInput = True
Else

'Save data to table Received product Item


Rs.Open "ReceivedProductItem", conn, adOpenDynamic, adLockOptimistic
Rs.AddNew
Rs.Fields("RProID") = Int(lblReceivedID.Caption)
Rs.Fields("ProID") = cboProductID.Text
Rs.Fields("Quantity") = txtQuantity.Text
Rs.Fields("UnitPrice") = txtUnitPrice.Text
Rs.Fields("ExpiredDate") = txtExpiredDate.Text
Rs.Update
Rs.Close

'Calucalate Amount

'Adding Item to Listview


lvReceivedItem.ListItems.Add , , lblReceivedID.Caption
lvReceivedItem.ListItems(lvReceivedItem.ListItems.Count).SubItems(1) =
txtReceivedDate.Text
lvReceivedItem.ListItems(lvReceivedItem.ListItems.Count).SubItems(2) =
lblProductName.Caption
lvReceivedItem.ListItems(lvReceivedItem.ListItems.Count).SubItems(3) =
txtUnitPrice.Text
lvReceivedItem.ListItems(lvReceivedItem.ListItems.Count).SubItems(4) =
txtQuantity.Text
lvReceivedItem.ListItems(lvReceivedItem.ListItems.Count).SubItems(5) =
Format(CInt(txtQuantity.Text) * CSng(txtUnitPrice.Text), "#,###.00")

'Update Quantiy instock in Table-Product


Rs.Open "Product", conn, adOpenDynamic, adLockOptimistic
Rs.Find "ProID='" & cboProductID.Text & "'"
If Rs.EOF = False Then
Rs.Fields("QuantityInStock") = Rs.Fields("QuantityInStock") +
CInt(txtQuantity.Text)
Rs.Update
End If
Rs.Close

'Remove all input Item


cboProductID.RemoveItem cboProductID.ListIndex

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University - 11 -
'Reset all input value
cboProductID.Text = ""
cboProductID.SetFocus
txtQuantity.Text = "0"
txtUnitPrice.Text = "0"
txtExpiredDate.Text = ""

txtReceivedDate.Enabled = False
End If
If isNotValidInput = True Then
MsgBox Msg, , "Validate Input"
End If
End Sub

7. cUreFVIkarsresrkUdenAelI Form frmSaleProduct³


+ Sub Form_Load

Private Sub Form_Load()


'Screen size
Me.BorderStyle = vbFixedSingle
Me.Width = 9210
Me.Height = 6840

'Create Invoice Number


lblInvoiceID.Caption = Format(getInvoiceID(), "0000000#")
txtSaleDate.Text = Format(Now(), "mm-dd-yyyy")

cboCustomer.Clear
lblCustomerName.Caption = ""
lblCustomerAddress.Caption = ""

cboEmployeeID.Clear
lblEmployeeName.Caption = ""
lblFunction.Caption = ""

Rs.Open "Customer", conn, adOpenKeyset


While Rs.EOF = False
cboCustomer.AddItem Rs.Fields("CusID")
Rs.MoveNext
Wend
Rs.Close

Rs.Open "Employee", conn, adOpenKeyset


While Rs.EOF = False
cboEmployeeID.AddItem Rs.Fields("EmpID")
Rs.MoveNext
Wend
Rs.Close

Rs.Open "Product", conn, adOpenKeyset


While Rs.EOF = False
cboProductID.AddItem Rs.Fields("ProID")

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University - 12 -
Rs.MoveNext
Wend
Rs.Close

End Sub

+ Sub cboCustomer_Click()

Private Sub cboCustomer_Click()


lblCustomerName.Caption = ""
lblCustomerAddress.Caption = ""

Rs.Open "Customer", conn, adOpenKeyset


Rs.Find "CusID='" & cboCustomer.Text & "'"
If Rs.EOF = False Then
lblCustomerName.Caption = Rs.Fields("Name")
lblCustomerAddress.Caption = Rs.Fields("Address")
End If
Rs.Close
End Sub

+ cboEmployeeID_Click()

Private Sub cboEmployeeID_Click()


lblEmployeeName.Caption = ""
lblFunction.Caption = ""
Rs.Open "Employee", conn, adOpenKeyset
Rs.Find "EmpID='" & cboEmployeeID.Text & "'"
If Rs.EOF = False Then
lblEmployeeName.Caption = Rs.Fields("Name")
lblFunction.Caption = Rs.Fields("Function")
End If
Rs.Close
End Sub

+ cboProductID_Click()

Private Sub cboProductID_Click()


lblProductName.Caption = ""
Rs.Open "Product", conn, adOpenKeyset
Rs.Find "ProID='" & cboProductID.Text & "'"
If Rs.EOF = False Then
lblProductName.Caption = Rs.Fields("ProName")
End If
Rs.Close
End Sub

+ cmdSale_Click()

Private Sub cmdSale_Click()


If isValidDateFormat(txtSaleDate) = False Then
txtSaleDate.SetFocus
MsgBox "Sale date you input not date format", , "Validate input"

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University - 13 -
ElseIf cboCustomer.Text = "" Then
cboCustomer.SetFocus
MsgBox "Customer ID does not allow null", , "Validate input"
ElseIf cboEmployeeID.Text = "" Then
cboEmployeeID.SetFocus
MsgBox "Employee ID does not allow null", , "Validate input"
ElseIf txtRegion.Text = "" Then
txtRegion.SetFocus
MsgBox "Sale Region does not allow null", , "Validate input"
Else
Rs.Open "SaleProduct", conn, adOpenDynamic, adLockOptimistic
Rs.AddNew
Rs.Fields("SPID") = lblInvoiceID.Caption
Rs.Fields("SaleDate") = txtSaleDate.Text
Rs.Fields("EmpID") = cboEmployeeID.Text
Rs.Fields("CusID") = cboCustomer.Text
Rs.Fields("Region") = txtRegion.Text
Rs.Update
Rs.Close

txtSaleDate.Enabled = False
cboCustomer.Enabled = False
cboEmployeeID.Enabled = False
txtRegion.Enabled = False
cmdSale.Enabled = False

cboProductID.Enabled = True
txtQuantity.Enabled = True
txtUnitPrice.Enabled = True
cmdSaleItem.Enabled = True
End If
End Sub

+ cmdSaleItem_Click()

Private Sub cmdSaleItem_Click()


Dim Msg As String
Dim isNotValidInput As Boolean
If CInt(txtQuantity.Text) < 0 Then
txtQuantity.SetFocus
Msg = "Quantity you input do not less that 0"
isNotValidInput = True
ElseIf isEnoughQuantity(cboProductID.Text, CInt(txtQuantity.Text)) = False
Then
txtQuantity.SetFocus
Msg = "Does not have Production Quantity in stock for sale"
isNotValidInput = True
ElseIf CSng(txtUnitPrice.Text) <= 0 Then
txtUnitPrice.SetFocus
Msg = "Unit Price must greater than 0"
isNotValidInput = True
Else

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University - 14 -
'Record to Table SaleProductItem
Rs.Open "SaleProductItem", conn, adOpenDynamic, adLockOptimistic
Rs.AddNew
Rs.Fields("SPID") = lblInvoiceID.Caption
Rs.Fields("ProID") = cboProductID.Text
Rs.Fields("Quantity") = txtQuantity.Text
Rs.Fields("UnitPrice") = txtUnitPrice
Rs.Update
Rs.Close

'Update Quatity instock of Table-Product


Rs.Open "Product", conn, adOpenDynamic, adLockOptimistic
Rs.Find "ProID='" & cboProductID.Text & "'"
If Rs.EOF = False Then
Rs.Fields("QuantityInStock") = Rs.Fields("QuantityInStock") -
CInt(txtQuantity.Text)
Rs.Update
End If
Rs.Close

'List all Item to Listview


lvSaleItem.ListItems.Add , , lvSaleItem.ListItems.Count + 1
lvSaleItem.ListItems(lvSaleItem.ListItems.Count).SubItems(1) =
lblProductName.Caption
lvSaleItem.ListItems(lvSaleItem.ListItems.Count).SubItems(2) =
txtQuantity.Text
lvSaleItem.ListItems(lvSaleItem.ListItems.Count).SubItems(3) =
txtUnitPrice.Text
lvSaleItem.ListItems(lvSaleItem.ListItems.Count).SubItems(4) =
Format(CInt(txtQuantity.Text) * CSng(txtUnitPrice.Text), "#,###.00$")

'Cleare Input value


cboProductID.RemoveItem (cboProductID.ListIndex)
cboProductID.Text = ""
cboProductID.SetFocus
txtQuantity.Text = "0"
txtUnitPrice.Text = "0"
cmdPrintInvoice.Enabled = True
End If
If isNotValidInput = True Then
MsgBox Msg, , "Validate Input"
End If
End Sub

+ getInvoiceID() { n: Long Integer }

Private Function getInvoiceID() As Long


Dim sql As String
sql = "Select SPID From SaleProduct Order By SPID DESC"
Rs.Open sql, conn, adOpenDynamic
If Rs.EOF = True Then
getInvoiceID = 1
Else

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University - 15 -
Rs.MoveFirst
getInvoiceID = Rs.Fields("SPID") + 1
End If
Rs.Close
End Function

+ isEnoughQuantity() { True:enough, False: Not enough }

Private Function isEnoughQuantity(ByVal pProID As String, ByVal pSaleQty


As Integer) As Boolean
Rs.Open "Select * from Product where ProID='" & pProID & "'", conn,
adOpenDynamic, adLockReadOnly
If Rs.EOF = False Then
If pSaleQty <= Rs.Fields("QuantityInStock") Then
isEnoughQuantity = True
Else
isEnoughQuantity = False
End If
Else
isEnoughQuantity = False
End If
Rs.Close

End Function

8. cUreFVIkarsresrkUdenAelI Form frmListProduct³


+ Private Sub Form_Load()

Private Sub Form_Load()


Me.Width = Screen.Width
Me.Height = Screen.Height
Shape1.Width = Me.Width
LvProduct.Width = Me.Width - LvProduct.Left
LvProduct.Height = Me.Height - LvProduct.Top
tvProductCategory.Height = Me.Height - tvProductCategory.Top

tvProductCategory.Nodes.Clear
tvProductCategory.Nodes.Add , , "PCatID", "Product Category"

Rs.Open " Select * from ProductCategory order by PCatName ASC", conn


While Rs.EOF = False
tvProductCategory.Nodes.Add "PCatID", tvwChild, Rs.Fields("PCatID"),
Rs.Fields("PCatName")
Rs.MoveNext
Wend
Rs.Close
End Sub
+ Private Sub tvProductCategory_NodeClick(ByVal Node As MSComctlLib.Node)

Private Sub tvProductCategory_NodeClick(ByVal Node As MSComctlLib.Node)

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)


Build Bright University - 16 -
Rs.Open "Select * from Product where PCatID='" & Node.Key & "'", conn,
adOpenKeyset, adLockReadOnly
LvProduct.ListItems.Clear
While Rs.EOF = False
LvProduct.ListItems.Add , , Rs.Fields("ProID")
LvProduct.ListItems(LvProduct.ListItems.Count).SubItems(1) =
Rs.Fields("ProName")
LvProduct.ListItems(LvProduct.ListItems.Count).SubItems(2) =
Rs.Fields("QuantityInStock")
LvProduct.ListItems(LvProduct.ListItems.Count).SubItems(3) = Node.Text
Rs.MoveNext
Wend
Rs.Close

End Sub

+ Private Sub cmdGo_Click()

Private Sub cmdGo_Click()


Dim sql As String
If txtCriteria.Text = "" Then
sql = "Select ProID,ProName,QuantityInStock,PCatName from Product P,
ProductCategory PC where P.PCatID=PC.PCatID"
Else
sql = "Select P.*,PC.* From Product P, ProductCategory PC where
P.PCatID=PC.PCatID And ProName = '" & txtCriteria.Text & "'"
End If
Rs.Open sql, conn, adOpenDynamic
LvProduct.ListItems.Clear
If Rs.EOF = True Then
MsgBox "Product name could not Found", , "Searching"
End If
While Rs.EOF = False
LvProduct.ListItems.Add , , Rs.Fields("ProID")
LvProduct.ListItems(LvProduct.ListItems.Count).SubItems(1) =
Rs.Fields("ProName")
LvProduct.ListItems(LvProduct.ListItems.Count).SubItems(2) =
Rs.Fields("QuantityInStock")
LvProduct.ListItems(LvProduct.ListItems.Count).SubItems(3) =
Rs.Fields("PCatName")
Rs.MoveNext
Wend

Rs.Close
End Sub

+ Private Sub Form_Activate()

Private Sub Form_Activate()


Me.WindowState = 2
cmdGo_Click
End Sub

Compiled By: PEN PHIROM (MscIT) Program Design and Algorithm(VB6.0)