Thema: Delphi Projekt "kopieren"

Einzelnen Beitrag anzeigen

Igotcha

Registriert seit: 22. Dez 2003
544 Beiträge
 
Delphi 2006 Professional
 
#15

Re: Projekt "kopieren"

  Alt 4. Jul 2006, 09:26
Zitat von davar:
P.S.: Bitte nicht denken, dass ich hier nur auf Antworten warte. Ich schlage mich nebenbei durch Bücher und Tutorials durch, um die ganze Sache mit Klassen und Objekten zu verstehen.
Na gut, dann wollen wir mal

Delphi-Quellcode:
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;
Hierbei sind alle "property"-Methoden mal weggelassen worden (durch SHIFT+STRG+C werden diese automatisch erstellt.

xMAIN in der uses-Klausel ist mein Core-Modul in meinem Projekt (da steht quasi die DB-Verbindung drin), xForm ist die Main-Form meines Anwendungssystems. Du könntest auch das OnCreate-Event überschreiben und als Parameter Deine ZConnection mitgeben, damit Du dann die DB-Connection hast.

In der Unit gibt es 2 Klassen:

1. TContact und
2. TContactCustomerAdds (das sind zusätzliche Firmeninfos zu einem Kontakt [bei mir eine Person]. Eine Person kann bei mir in mehreren Firmen aktiv sein).

Dann wird weiter unten noch die Klasse TCustomer verwendet, die analog "Firmen-Objekte" abbildet.

Die o.g. Unit bindest Du in Deine Mainform ein. Entweder benutzt Du dann eine globale Variable "Kontakt", die vom Typ TContact ist, oder Du erstellst diese in den jeweiligen Proceduren, wo Du mit Kontaktdaten arbeitest.

Gruß Igotcha
  Mit Zitat antworten Zitat