Public Sub New(ByVal strPONumber As String, ByVal lngSupplierID As Long)
' this constructor is used to create a contract object when the po and supplier name are known
Dim intX As Integer
' set internal error flag to false
m_Error = False
' create a connection using global connection string
m_objConn = New System.Data.OleDb.OleDbConnection(gconnConnection)
' set-up the SQL which will return records for select PO number
m_strSQL = "SELECT * FROM tblContracts WHERE tblContracts.po_number = '" & strPONumber & "' AND " & _
"tblContracts.Supplierid = " & lngSupplierID & " ORDER BY " & _
"order_line "
' create a new data adapter for the required data
m_odaContract = New System.Data.OleDb.OleDbDataAdapter(m_strSQL, m_objConn)
' protect this section of code
Try
' open the connection to the required database
m_objConn.Open()
' fill the data table
m_odaContract.Fill(m_dsContract, "tblContracts")
' set the data row object to the first row of the table, there will be only 1 as the supplier table
' only allows unique entries
m_drContract = m_dsContract.Tables("tblContracts").Rows(0)
' assign values to private members, these will becomae available through each properties methods
' assign nothing if database field contains no data
m_ContractID = IIf(IsDBNull(m_drContract.Item("contractid")), Nothing, m_drContract.Item("contractid"))
m_SupplierID = IIf(IsDBNull(m_drContract.Item("supplierid")), Nothing, m_drContract.Item("supplierid"))
m_PRNumber = IIf(IsDBNull(m_drContract.Item("pr_number")), Nothing, m_drContract.Item("pr_number"))
m_BudgetCode = IIf(IsDBNull(m_drContract.Item("budget")), Nothing, m_drContract.Item("budget"))
m_DepartmentCode = IIf(IsDBNull(m_drContract.Item("dept")), Nothing, m_drContract.Item("dept"))
m_PONumber = IIf(IsDBNull(m_drContract.Item("po_number")), Nothing, m_drContract.Item("po_number"))
m_Dated = IIf(IsDBNull(m_drContract.Item("dated")), Nothing, m_drContract.Item("dated"))
m_Commencement = IIf(IsDBNull(m_drContract.Item("commencement")), Nothing, m_drContract.Item("commencement"))
m_Expiry = IIf(IsDBNull(m_drContract.Item("expires")), Nothing, m_drContract.Item("expires"))
m_Contact = IIf(IsDBNull(m_drContract.Item("contact")), Nothing, m_drContract.Item("contact"))
m_ContactTelephone = IIf(IsDBNull(m_drContract.Item("contact_tel")), Nothing, m_drContract.Item("contact_tel"))
m_OrderLine = IIf(IsDBNull(m_drContract.Item("order_line")), Nothing, m_drContract.Item("order_line"))
m_Detail = IIf(IsDBNull(m_drContract.Item("description")), Nothing, m_drContract.Item("description"))
m_Cost = IIf(IsDBNull(m_drContract.Item("price")), Nothing, m_drContract.Item("price"))
m_Frequency = IIf(IsDBNull(m_drContract.Item("frequency")), Nothing, m_drContract.Item("frequency"))
m_Active = IIf(IsDBNull(m_drContract.Item("active")), Nothing, m_drContract.Item("active"))
m_Internal = IIf(IsDBNull(m_drContract.Item("internal")), True, m_drContract.Item("internal"))
m_EquipmentID = IIf(IsDBNull(m_drContract.Item("equipmentid")), Nothing, m_drContract.Item("equipmentid"))
m_RecordCount = IIf(IsDBNull(m_dsContract.Tables("tblContracts").Rows.Count), Nothing, m_dsContract.Tables("tblContracts").Rows.Count)
' resize the service due date array to the frequency value
ReDim m_ServiceDates(m_Frequency, 2)
' cycle through table and store service due dates in array
For intX = 0 To m_Frequency - 1
m_ServiceDates(intX, 0) = m_drContract.Item("s" & intX)
m_ServiceDates(intX, 1) = m_drContract.Item("s" & intX & "done")
Next
' call function to calculate the total po cost
If Not POTotal() Then
Return
End If
' close connection to database
m_objConn.Close()
Catch objException As Exception
ShowError("Location: Class Contract" & ControlChars.CrLf & ControlChars.CrLf & _
"Procedure: New(ByVal strPONumber As String, ByVal strSupplierID As Long)" & _
ControlChars.CrLf & ControlChars.CrLf & "Error Text: " & objException.Message)
' set internal error flag to true
m_Error = True
End Try
End Sub