unit AccountStep;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls,PXStuff;

type
  Tstepform = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Image1: TImage;
    Bevel1: TBevel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Pnl1: TPanel;
    Label2: TLabel;
    Label3: TLabel;
    nameEdit: TEdit;
    Label4: TLabel;
    pnl4: TPanel;
    Label11: TLabel;
    Pnl3: TPanel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    AccountNameEdit: TEdit;
    PassEdit: TEdit;
    Pnl2: TPanel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    AddressEdit: TEdit;
    Pnl5: TPanel;
    Label12: TLabel;
    Label13: TLabel;
    ReceiveSer: TEdit;
    SendSer: TEdit;
    procedure FormShow(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure AddressEditChange(Sender: TObject);
    procedure nameEditChange(Sender: TObject);
    procedure AccountNameEditChange(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure RegistUse;
    procedure ReceiveSerChange(Sender: TObject);
  private

    { Private declarations }
  public
    procedure LoadAccountData(Data: PAccountData);
    procedure SaveAccountData(var Data: PAccountData);
    { Public declarations }
  end;

var
  stepform: Tstepform;
  iCount:integer=0;
  iSuccess:boolean=false;

implementation

uses Main;



{$R *.DFM}

{ Tstepform }

procedure Tstepform.LoadAccountData(Data: PAccountData);
begin

end;

procedure Tstepform.FormShow(Sender: TObject);
begin
  pnl1.BringToFront;
  nameEdit.SetFocus;
end;

procedure Tstepform.Button3Click(Sender: TObject);
begin
  iCount:=0;
  close;
end;

procedure Tstepform.Button2Click(Sender: TObject);
begin
  iCount:=iCount+1;
  RegistUse;
end;

procedure Tstepform.AddressEditChange(Sender: TObject);
begin
  if AddressEdit.Text<>'' then
    Button2.Enabled:=true
  else
    Button2.Enabled:=false;
end;

procedure Tstepform.nameEditChange(Sender: TObject);
begin
  if nameEdit.Text<>'' then
    Button2.Enabled:=true
  else
    Button2.Enabled:=false;
end;

procedure Tstepform.AccountNameEditChange(Sender: TObject);
begin
  if AccountNameEdit.Text<>'' then
    Button2.Enabled:=true
  else
    Button2.Enabled:=false;
end;

procedure Tstepform.Button1Click(Sender: TObject);
begin
  button2.Caption:='下一步(&N) >';
  iCount:=iCount-1;
  if iCount=0 then
  begin
    pnl1.BringToFront;
    Label1.Caption:='您的姓名';
    nameEdit.SetFocus;
    Button1.Enabled:=false;
    exit;
  end;
     RegistUse;
end;

procedure Tstepform.RegistUse;
begin
try
  Button1.Enabled:=true;
  if iCount=1 then
  begin
    button2.Enabled:=false;
    pnl2.BringToFront;
    AddressEdit.SetFocus;
    Label1.Caption:='电子邮件地址';
  end
  else if  iCount=3 then
  begin
    button2.Enabled:=false;
    pnl3.BringToFront;
    AccountNameEdit.SetFocus;
    Label1.Caption:='登录';
  end
  else if  iCount=2 then
  begin
    button2.Enabled:=false;
    pnl5.BringToFront;
    ReceiveSer.SetFocus;
    Label1.Caption:='电子邮件服务器名称';
  end
  else if  iCount=4 then
  begin
    button2.Caption:='完成';
    pnl4.BringToFront;
    Label1.Caption:='祝贺您';
  end

  else
  begin
    iCount:=0;
    iSuccess := true;
    close;
  end;
except
  iCount:=0;
  showmessage('创建新帐号失败!');
end;
end;

procedure Tstepform.SaveAccountData(var Data: PAccountData);
begin
  Data^.Name:= SendSer.Text;
    Data^.Path := sAccountRootFolder +
      Data^.Name + '\';
    CreateFolder(Data^.Path);

  Data^.FromMail := AddressEdit.Text;
  Data^.FromDesc := nameEdit.Text;

//  Data^.ReplyMail := Edit4.Text;
//  Data^.ReplyDesc := Edit5.Text;
  Data^.POPServer := ReceiveSer.Text;
//  Data^.POPPort := Edit7.Text;
  Data^.POPUser := AccountNameEdit.Text;
  Data^.POPPass := PassEdit.Text;
  Data^.SMTPServer := SendSer.Text;
//  Data^.SMTPPort := Edit11.Text;
//  Data^.KeepFilter := Edit12.Text;
//  Data^.DeleteFilter := Edit13.Text;
//  Data^.Organization := Edit14.Text;
  Data^.SMTPAuthenticate := true;
  Data^.SMTPUserName := AccountNameEdit.Text;
  Data^.SMTPPassword := PassEdit.Text;

  Data^.DoPOP := Ord(true); //AH16
  Data^.DoSMTP := Ord(true); // AH16
  Data^.DoSMTPAfterPOP := Ord(true); //AH16
//  Data^.StandardDownload := StrToInt(ComboBoxEx1.Value); //AH16
 // Data^.PromptPassword := Ord(Checkbox3.Checked);
  // AHRK19
//  Data^.ShowDownload := Ord(CheckBox4.Checked);
  // AH05 delete file...
{  if Trim(Memo1.Lines.Text) = '' then
  begin
    if FileExists(Data^.path + 'signat.txt') then
      DeleteFile(Data^.path + 'signat.txt');
  end
  else
    Memo1.Lines.SaveToFile(Data^.Path + 'signat.txt');
  // AH05}
end;

procedure Tstepform.ReceiveSerChange(Sender: TObject);
begin
  if (ReceiveSer.Text<>'') and (SendSer.Text<>'') then
    Button2.Enabled:=true
  else
    Button2.Enabled:=false;

end;

end.
