unit UContact;
interface
uses
Contnrs,
DB, ZAbstractRODataset, ZAbstractDataset, ZDataset, xMain,
Dialogs, UCustomer;
type
TContactCustomerAdds =
class(TObject)
private
FCustomerID: integer;
FPhone1:
String;
FPhone2:
String;
FMobile:
String;
FFax:
String;
FEmail:
String;
FAssName:
String;
FAssPhone:
String;
FAssEmail:
String;
procedure SetFCustomerID(
const Value: integer);
procedure SetFPhone1(
const Value:
String);
procedure SetFAssEmail(
const Value:
string);
procedure SetFAssName(
const Value:
string);
procedure setFAssPhone(
const Value:
string);
procedure SetFEmail(
const Value:
string);
procedure SetFFax(
const Value:
string);
procedure SetFMobile(
const Value:
string);
public
property CustomerID: integer
read FCustomerID
write SetFCustomerID;
property Phone1:
String read FPhone1
write SetFPhone1;
property Phone2:
String read FPhone2
write SetFPhone1;
property Mobile:
string read FMobile
write SetFMobile;
property Fax:
string read FFax
write SetFFax;
property Email:
string read FEmail
write SetFEmail;
property AssName:
string read FAssName
write SetFAssName;
property AssPhone:
string read FAssPhone
write setFAssPhone;
property AssEmail:
string read FAssEmail
write SetFAssEmail;
constructor create;
end;
type
TContact =
class(TObject)
private
FContactID: integer;
FSalutation: integer;
FTitle: integer;
FFName1:
String;
FFName2:
String;
FLName:
String;
FBirthdate: TDateTime;
FPAddStreet:
String;
FPAddPostal:
String;
FPAddCity:
String;
FPAddRegion:
String;
FPAddCountry: Integer;
FPhone1:
String;
FPhone2:
String;
FMobile:
String;
FFax:
String;
FEMail1:
String;
FEmail2:
String;
FContactBy: Integer;
FContactDate: TDateTime;
FContactCreatedBy: Integer;
FMaritalStatus: Integer;
FMALetter: integer;
FMAEmail: integer;
FMAFax: integer;
FMAPhone: integer;
FNote:
String;
FAddNote:
String;
FCustomerList: TObjectList;
FCustomerAddsList: TObjectList;
OQuery1, OQuery2: TZQuery;
procedure SetFCcontactID(
const Value: Integer);
procedure SetFFName1(
const Value:
String);
procedure SetFSalutation(
const Value: Integer);
procedure SetFTitle(
const Value: Integer);
procedure SetFBirthdate(
const Value: TDateTime);
procedure SetFFName2(
const Value:
String);
procedure SetFLName(
const Value:
String);
procedure SetFPAddStreet(
const Value:
String);
procedure SetFPAddCity(
const Value:
String);
procedure SetFPAddPostal(
const Value:
String);
procedure SetFPAddRegion(
const Value:
String);
procedure SetFPhone1(
const Value:
String);
procedure SetFEMail1(
const Value:
String);
procedure SetFFax(
const Value:
String);
procedure SetFMobile(
const Value:
String);
procedure SetFPhone2(
const Value:
String);
procedure SetFEMail2(
const Value:
String);
procedure SetFPAddCountry(
const Value: Integer);
procedure SetFContactBy(
const Value: Integer);
procedure SetFContactDate(
const Value: TDateTime);
procedure SetFContactCreatedBy(
const Value: Integer);
procedure SetFMaritalStatus(
const Value: Integer);
procedure SetFMALetter(
const Value: integer);
procedure SetFMAEmail(
const Value: integer);
procedure SetFMAFax(
const Value: integer);
procedure SetMAPhone(
const Value: integer);
procedure SetFNote(
const Value:
String);
procedure SetFAddNote(
const Value:
String);
procedure SetFCustomerList(
const Value: TObjectList);
procedure SetFCustomerAddsList(
const Value: TObjectList);
public
property ContactID: Integer
read FContactID
write SetFCcontactID;
property Salutation: Integer
read FSalutation
write SetFSalutation;
property Title: Integer
read FTitle
write SetFTitle;
property ForeName1:
String read FFName1
write SetFFName1;
property ForeName2:
String read FFName2
write SetFFName2;
property LastName:
String read FLName
write SetFLName;
property Birthdate: TDateTime
read FBirthdate
write SetFBirthdate;
property Street:
String read FPAddStreet
write SetFPAddStreet;
property Postal:
String read FPAddPostal
write SetFPAddPostal;
property City:
String read FPAddCity
write SetFPAddCity;
property Region:
String read FPAddRegion
write SetFPAddRegion;
property Country: Integer
read FPAddCountry
write SetFPAddCountry;
property AddNote:
String read FAddNote
write SetFAddNote;
property Phone1:
String read FPhone1
write SetFPhone1;
property Phone2:
String read FPhone2
write SetFPhone2;
property Mobile:
String read FMobile
write SetFMobile;
property Fax:
String read FFax
write SetFFax;
property EMail1:
String read FEMail1
write SetFEMail1;
property EMail2:
String read FEMail2
write SetFEMail2;
property ContactBy: Integer
read FContactBy
write SetFContactBy;
property ContactDate: TDateTime
read FContactDate
write SetFContactDate;
property ContactCreatedBy:Integer
read FContactCreatedBy
write SetFContactCreatedBy;
property MaritalStatus: Integer
read FMaritalStatus
write SetFMaritalStatus;
property MALetter: integer
read FMALetter
write SetFMALetter;
property MAEmail: integer
read FMAEmail
write SetFMAEmail;
property MAFax: integer
read FMAFax
write SetFMAFax;
property MAPhone: integer
read FMAPhone
write SetMAPhone;
property Note:
String read FNote
write SetFNote;
property CustomerList: TObjectList
read FCustomerList
write SetFCustomerList;
property CustomerAddsList: TObjectList
read FCustomerAddsList
write SetFCustomerAddsList;
procedure LoadContact(aID: Integer);
procedure AddCustomer(aCustomer: TCustomer);
procedure AddCustomerAdds(aCustomerAdds: TContactCustomerAdds);
procedure RemoveCustomer(aID: Integer);
constructor create;
end;
implementation
{ TContact }
procedure TContact.AddCustomer(aCustomer: TCustomer);
begin
FCustomerList.Add(aCustomer);
end;
procedure TContact.AddCustomerAdds(aCustomerAdds: TContactCustomerAdds);
begin
FCustomerAddsList.Add(aCustomerAdds);
end;
constructor TContact.create;
begin
OQuery1:=TZQuery.Create(
nil);
OQuery1.Connection:=XForm.XBASDBC;
OQuery2:=TZQuery.Create(
nil);
OQuery2.Connection:=XForm.XBASDBC;
FCustomerList:=TObjectList.Create(true);
FCustomerAddsList:=TObjectList.Create(true);
end;
procedure TContact.LoadContact(aID: Integer);
var
myCustomer: TCustomer;
myCustomerAdds: TContactCustomerAdds;
begin
OQuery1.SQL.Text:='
SELECT * FROM kom_ko2000 WHERE id=:id';
OQuery1.ParamByName('
id').AsInteger:=aID;
OQuery1.Open;
If OQuery1.RecordCount > 0
then
begin
Salutation:=OQuery1.fieldbyname('
salutation').AsInteger;
Title:=OQuery1.fieldbyname('
title').AsInteger;
ForeName1:=OQuery1.fieldbyname('
fname1').AsString;
ForeName2:=OQuery1.fieldbyname('
fname2').AsString;
ForeName1:=OQuery1.fieldbyname('
fname1').AsString;
LastName:=OQuery1.fieldbyname('
lname').AsString;
Birthdate:=OQuery1.fieldbyname('
birthdate').AsDateTime;
Street:=OQuery1.fieldbyname('
street').AsString;
Postal:=OQuery1.fieldbyname('
postal').AsString;
City:=OQuery1.fieldbyname('
city').AsString;
Region:=OQuery1.fieldbyname('
region').AsString;
Country:=OQuery1.fieldbyname('
country').AsInteger;
AddNote:=OQuery1.fieldbyname('
addnote').AsString;
Phone1:=OQuery1.fieldbyname('
phone1').AsString;
Phone2:=OQuery1.fieldbyname('
phone2').AsString;
Mobile:=OQuery1.fieldbyname('
mobile').AsString;
Fax:=OQuery1.fieldbyname('
fax').AsString;
EMail1:=OQuery1.fieldbyname('
email1').AsString;
EMail2:=OQuery1.fieldbyname('
email2').AsString;
ContactBy:=OQuery1.fieldbyname('
contactby').AsInteger;
ContactDate:=OQuery1.fieldbyname('
contactdate').AsDateTime;
ContactCreatedBy:=OQuery1.fieldbyname('
contactcreatedby').AsInteger;
MaritalStatus:=OQuery1.fieldbyname('
maritalstatus').AsInteger;
MALetter:=OQuery1.fieldbyname('
maletter').AsInteger;
MAEmail:=OQuery1.fieldbyname('
maemail').AsInteger;
MAFax:=OQuery1.fieldbyname('
mafax').AsInteger;
MAPhone:=OQuery1.fieldbyname('
maphone').AsInteger;
Note:=OQuery1.fieldbyname('
note').AsString;
// Customer zu Contact laden
CustomerList.Clear;
OQuery1.SQL.Text:='
SELECT c.id FROM kom_ko3000 cc JOIN kom_ko1000 c ON c.id = cc.custid WHERE cc.contactid=:contactid ORDER BY c.name1 ASC';
OQuery1.ParamByName('
contactid').AsInteger:=ContactID;
OQuery1.Open;
While not OQuery1.Eof
do
begin
myCustomer:=TCustomer.Create;
myCustomer.LoadCustomer(OQuery1.fieldbyname('
id').AsInteger);
AddCustomer(myCustomer);
// Kundenspezifische Informationen zum Kontakt laden
OQuery2.SQL.Text:='
SELECT * FROM kom_ko3010 WHERE custid=:custid AND contactid=:contactid';
OQuery2.ParamByName('
custid').AsInteger:=OQuery1.fieldbyname('
id').AsInteger;
OQuery2.ParamByName('
contactid').AsInteger:=ContactID;
OQuery2.Open;
myCustomerAdds:=TContactCustomerAdds.create;
myCustomerAdds.FCustomerID:=OQuery1.fieldbyname('
id').AsInteger;
myCustomerAdds.FPhone1:=OQuery2.fieldbyname('
phone1').AsString;
AddCustomerAdds(myCustomerAdds);
OQuery2.Close;
// =================================================
OQuery1.Next;
end;
// ====================================================================
end;
OQuery1.Close;
end;