{*****************************************************************************
 *
 *  FMEditAdr.pas - Edit Address Form  (20-August-1998)
 *
 *  Copyright (c) 1998-99 Michael Haller
 *
 *  Author:     Michael Haller
 *  E-mail:     michael@discountdrive.com
 *  Homepage:   http://www.discountdrive.com/sunrise
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation;
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
 *
 *----------------------------------------------------------------------------
 *
 *  Revision history:
 *
 *     DATE     REV                 DESCRIPTION
 *  ----------- --- ----------------------------------------------------------
 *
 *****************************************************************************}

unit FMEditAdr;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  GradForm,
  ExtCtrls, StdCtrls, ComboBoxEx, ComCtrls, PXStuff, TB97Ctls;

type
  TEditAdrForm = class(TdfsGradientForm)
    BtnOk: TButton;
    Btncancel: TButton;
    Panel1: TPanel;
    Button3: TButton;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    TabSheet5: TTabSheet;
    Label1: TLabel;
    Bevel1: TBevel;
    Label2: TLabel;
    Label3: TLabel;
    EdtName: TEdit;
    EdtEAddress: TEdit;
    LstBoxEmail: TListBox;
    BtnAdd: TButton;
    BtnEdit: TButton;
    BtnDel: TButton;
    BtnDefault: TButton;
    Label4: TLabel;
    Bevel2: TBevel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    EdtPhone: TEdit;
    EdtP: TEdit;
    EdtSicq: TEdit;
    EdtIcq: TEdit;
    EdtHttp: TEdit;
    CmbBoxSex: TComboBox;
    MemoFond: TMemo;
    DateTimePicker1: TDateTimePicker;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    EdtCountry: TEdit;
    EdtProvince: TEdit;
    EdtCity: TEdit;
    EdtPost: TEdit;
    EdtRoad: TEdit;
    EdtPhoOne: TEdit;
    EdtPhoTwo: TEdit;
    EdtFax: TEdit;
    Label21: TLabel;
    Bevel3: TBevel;
    Label22: TLabel;
    Bevel4: TBevel;
    Label23: TLabel;
    Bevel5: TBevel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    EdtCorp: TEdit;
    EdtCountry2: TEdit;
    EdtProvince2: TEdit;
    EdtCity2: TEdit;
    EdtPost2: TEdit;
    EdtRoad2: TEdit;
    EdtHttp2: TEdit;
    EdtJob: TEdit;
    EdtDepartment: TEdit;
    EdtPhoOne2: TEdit;
    EdtPhoTwo2: TEdit;
    EdtFax2: TEdit;
    Label36: TLabel;
    MemoAttach: TMemo;
    procedure BtnOkClick(Sender: TObject);
    procedure TBSelDateClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BtnAddClick(Sender: TObject);
    procedure BtnDelClick(Sender: TObject);
    procedure BtnEditClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    CheckUnique: Boolean;
  end;

var
  EditAdrForm: TEditAdrForm;

implementation

uses
  FMSelDate, FMAddress, Main;

{$R *.DFM}

procedure TEditAdrForm.BtnOkClick(Sender: TObject);
var
  S: string;
  I: Integer;
begin
  {if CheckUnique then begin
    if ComboBox1.ItemIndex = AddressForm.Combobox1.ItemIndex then
      if EditEMail.Text <> '' then
        if not AddressForm.IsUniqueAddress(EditEMail.Text) then
          if MessageDlg(GetMessageString(78), mtConfirmation, [mbYes,
            mbNo], 0) = mrNo then
            Exit;
  end;

  S := EditBemerkung.Text + EditEMail.Text + EditTel.Text + EditPost.Text + EditVorname.Text + EditName.Text;
  for I := 1 to Length(S) do
    if S[I] in [';'] then begin
      MessageDlg(GetMessageString(49), mtWarning, [mbOK], 0);
      Exit;
    end;              }
  ModalResult := mrOK;
end;

procedure TEditAdrForm.TBSelDateClick(Sender: TObject);
var DForm: TFormSelDate;
  MR: Word;
begin
{  DForm := TFormSelDate.Create(self);
  if Assigned(LangHolder) then
  begin
    if LangHolder.Language <> '' then
      LangHolder.Translate([DForm]);
  end;

  MR := DForm.ShowModal;
  if MR = mrOK then
  begin
    EditDatum.Text := FormatDateTime('yyyy"-"mm"-"dd', DForm.MonthCalendar.Date);
  end;
  DForm.Free;}
end;

procedure TEditAdrForm.FormShow(Sender: TObject);
begin
  PageControl1.ActivePage:=TabSheet1;
end;

procedure TEditAdrForm.BtnAddClick(Sender: TObject);
begin
  LstBoxEmail.Items.Add (EdtEAddress.Text);
  EdtEAddress.Text:='';
end;

procedure TEditAdrForm.BtnDelClick(Sender: TObject);
var
  i:integer;
begin
  for i:=0 to LstBoxEmail.Items.Count-1 do
  begin
    if LstBoxEmail.Selected[i] then LstBoxEmail.Items.Delete(i);
    Exit;
  end;
end;

procedure TEditAdrForm.BtnEditClick(Sender: TObject);
var
  NewString: string;
  ClickedOK: Boolean;
  i:integer;
begin
  for i:=0 to LstBoxEmail.Items.Count do
    if LstBoxEmail.Selected[i] then
    begin
      NewString :=LstBoxEmail.Items.Strings[i];
      break;
    end;
  ClickedOK := InputQuery('输入', '请输入有效的E-mail地址', NewString);
  if ClickedOK then
  begin
    LstBoxEmail.Items.Delete(i);
    LstBoxEmail.Items.Insert(i,NewString);
  end;
end;
initialization
   PMRegistry.AddCustomClass(TEditAdrForm, 'TEditAdrForm');

end.
