VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 2  'RequiresTransaction
END
Attribute VB_Name = "CustomerInfo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Public Function GetCustomer(CustomerId As Long) As Customer

Dim c As Customer
Dim cmd As ADODB.Command
Dim db As ADODB.Connection
Dim o As ObjectContext
Dim parm As ADODB.Parameter
Dim rs As ADODB.Recordset

Set o = GetObjectContext()

Err.Clear
Set db = New ADODB.Connection

db.Provider = "sqloledb"
db.ConnectionString = "Athena"
db.CursorLocation = adUseNone
db.Open , "sa", ""
db.DefaultDatabase = "VB6DB"

Set cmd = New ADODB.Command
Set cmd.ActiveConnection = db
cmd.CommandText = "Select * from Customers Where CustomerId = ?"
Set parm = cmd.CreateParameter("CustomerId", adInteger, adParamInput, 4)
cmd.Parameters.Append parm

cmd.Parameters("CustomerId").Value = CustomerId

Set rs = cmd.Execute
If Err.Number <> 0 Then
   App.LogEvent "Customer(GetCustomer): Can't retrieve the record for CustomerId " & _
      FormatNumber(CustomerId, 0) & ". Error: " & _
      Err.Description & "-" & _
      Hex(Err.Number)
      
   Set c = Nothing
   
Else
   Set c = New Customer
   c.CustomerId = rs.Fields("CustomerId")
   c.Name = rs.Fields("Name")
   c.Street = rs.Fields("Street")
   c.City = rs.Fields("City")
   c.State = rs.Fields("State")
   c.Zip = rs.Fields("Zip")
   c.Phone = rs.Fields("Phone")
   c.EMailAddress = rs.Fields("EMailAddress")
   c.DateAdded = rs.Fields("DateAdded")
   c.DateUpdated = rs.Fields("DateUpdated")
   c.MailingList = rs.Fields("MailingList")
   c.Comments = rs.Fields("Comments")
 
End If

Set GetCustomer = c
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Set c = Nothing
Set o = Nothing

End Function

Public Function PutCustomer(c As Customer) As Long

On Error Resume Next

Dim cmd As ADODB.Command
Dim db As ADODB.Connection
Dim o As ObjectContext
Dim parm As ADODB.Parameter

Set o = GetObjectContext()

PutCustomer = 0
Err.Clear

Set db = New ADODB.Connection
db.Provider = "sqloledb"
db.ConnectionString = "Athena"
db.CursorLocation = adUseNone
db.Open , "sa", ""
db.DefaultDatabase = "VB6DB"

Set cmd = New ADODB.Command
Set cmd.ActiveConnection = db
cmd.CommandText = "Update Customers Set Name=?, Street=?, City=?, State=?, Zip=?, Phone=?, EMailAddress=?, DateAdded=?, DateUpdated=?, MailingList=?, Comments=? Where CustomerId=?"

Set parm = cmd.CreateParameter("Name", adVarChar, adParamInput, 64)
cmd.Parameters.Append parm

Set parm = cmd.CreateParameter("Street", adVarChar, adParamInput, 64)
cmd.Parameters.Append parm

Set parm = cmd.CreateParameter("City", adVarChar, adParamInput, 64)
cmd.Parameters.Append parm

Set parm = cmd.CreateParameter("State", adChar, adParamInput, 2)
cmd.Parameters.Append parm

Set parm = cmd.CreateParameter("Zip", adInteger, adParamInput, 4)
cmd.Parameters.Append parm

Set parm = cmd.CreateParameter("Phone", adVarChar, adParamInput, 32)
cmd.Parameters.Append parm

Set parm = cmd.CreateParameter("EMailAddress", adVarChar, adParamInput, 128)
cmd.Parameters.Append parm

Set parm = cmd.CreateParameter("DateAdded", adDBDate, adParamInput)
cmd.Parameters.Append parm

Set parm = cmd.CreateParameter("DateUpdated", adDBDate, adParamInput)
cmd.Parameters.Append parm

Set parm = cmd.CreateParameter("MailingList", adBoolean, adParamInput)
cmd.Parameters.Append parm

Set parm = cmd.CreateParameter("Comments", adVarChar, adParamInput, 256)
cmd.Parameters.Append parm

Set parm = cmd.CreateParameter("CustomerId", adInteger, adParamInput, 4)
cmd.Parameters.Append parm

cmd.Parameters("CustomerId").Value = c.CustomerId
cmd.Parameters("Name").Value = c.Name
cmd.Parameters("Street").Value = c.Street
cmd.Parameters("City").Value = c.City
cmd.Parameters("State").Value = c.State
cmd.Parameters("Zip").Value = c.Zip
cmd.Parameters("Phone").Value = c.Phone
cmd.Parameters("EMailAddress").Value = c.EMailAddress
cmd.Parameters("DateAdded").Value = c.DateAdded
cmd.Parameters("DateUpdated").Value = c.DateUpdated
cmd.Parameters("MailingList").Value = c.MailingList
cmd.Parameters("Comments").Value = c.Comments
cmd.Execute

If Err.Number <> 0 Then
   App.LogEvent "Customer(PutCustomer): Can't update the record for CustomerId " & _
      FormatNumber(c.CustomerId, 0) & ". Error: " & _
      Err.Description & "-" & _
      Hex(Err.Number)
   PutCustomer = Err.Number
End If

db.Close
o.SetComplete
Set cmd = Nothing
Set db = Nothing
Set o = Nothing

End Function
