ufrmSingnals.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:5k
源码类别:

Email服务器

开发平台:

Delphi

  1. unit ufrmSingnals;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, uBaseEditorForm, dxBarExtItems, cxControls, cxContainer,
  6.   cxListBox, ActnList, dxBar, ImgList, cxClasses, OleCtrls, SHDocVw,
  7.   uHtmlEdit, ExtCtrls,uSingnalMgr, cxTextEdit, cxEdit, cxLabel, cxCheckBox,
  8.   cxGroupBox, cxRadioGroup;
  9. type
  10.   TfrmSingnals = class(TBaseEditorForm)
  11.     btnAdd: TdxBarLargeButton;
  12.     btnDelete: TdxBarLargeButton;
  13.     btn3: TdxBarLargeButton;
  14.     btn4: TdxBarLargeButton;
  15.     btn5: TdxBarLargeButton;
  16.     btnExit: TdxBarLargeButton;
  17.     pnl1: TPanel;
  18.     lbl2: TcxLabel;
  19.     edtTitle: TcxTextEdit;
  20.     btnSave: TdxBarLargeButton;
  21.     chkDefault: TcxCheckBox;
  22.     lstSingnals: TcxListBox;
  23.     procedure FormCreate(Sender: TObject);
  24.     procedure FormDestroy(Sender: TObject);
  25.     procedure btnExitClick(Sender: TObject);
  26.     procedure btnAddClick(Sender: TObject);
  27.     procedure btnDeleteClick(Sender: TObject);
  28.     procedure btnSaveClick(Sender: TObject);
  29.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  30.     procedure edtTitleKeyDown(Sender: TObject; var Key: Word;
  31.       Shift: TShiftState);
  32.     procedure chkDefaultClick(Sender: TObject);
  33.     procedure lstSingnalsMouseUp(Sender: TObject; Button: TMouseButton;
  34.       Shift: TShiftState; X, Y: Integer);
  35.   private
  36.     { Private declarations }
  37.     FSingnalMgr:TAppSingnalMgr;
  38.   public
  39.     { Public declarations }
  40.     procedure ShowSingnals(index:Integer);
  41.   end;
  42. var
  43.   frmSingnals: TfrmSingnals;
  44. implementation
  45. uses uCommon, uEncrypt;
  46. {$R *.dfm}
  47. procedure TfrmSingnals.FormCreate(Sender: TObject);
  48. begin
  49.   inherited;
  50.   FSingnalMgr:=TAppSingnalMgr.Create;
  51.   FSingnalMgr.LoadFromFile;
  52.   while FSingnalMgr.Iterator.HasNext do
  53.     lstSingnals.Items.Add(PSingnalData(FSingnalMgr.Iterator.Next).Caption);
  54.   if lstSingnals.Items.Count>0 then
  55.   begin
  56.     lstSingnals.ItemIndex:=0;
  57.     ShowSingnals(0);
  58.   end ;
  59. end;
  60. procedure TfrmSingnals.FormDestroy(Sender: TObject);
  61. begin
  62.   FSingnalMgr.Free;
  63.   inherited;
  64. end;
  65. procedure TfrmSingnals.btnExitClick(Sender: TObject);
  66. begin
  67.   close;
  68. end;
  69. procedure TfrmSingnals.ShowSingnals(index:Integer);
  70. begin
  71.   htmlEdit.Clear;
  72.   edtTitle.Text:='';
  73.   if index=-1 then exit;
  74.   htmlEdit.Insert(FSingnalMgr.Get(index).Text);
  75.   edtTitle.Text:=FSingnalMgr.Get(index).Caption;
  76.   
  77.   chkDefault.OnClick:=nil;
  78.   try
  79.     chkDefault.Checked:=FSingnalMgr.Get(index).Default;
  80.   finally
  81.     chkDefault.OnClick:=self.chkDefaultClick;
  82.   end;
  83. end;
  84. procedure TfrmSingnals.btnAddClick(Sender: TObject);
  85. begin
  86.   edtTitle.Text:='新签名 请修改签名名称';
  87.   FSingnalMgr.Add.Caption:=edtTitle.Text;
  88.   lstSingnals.Items.Add(edtTitle.Text);
  89.   htmlEdit.Clear;
  90. end;
  91. procedure TfrmSingnals.btnDeleteClick(Sender: TObject);
  92. var
  93.   idx:Integer;
  94. begin
  95.   idx:=lstSingnals.ItemIndex;
  96.   FSingnalMgr.Remove(idx);
  97.   lstSingnals.Items.Delete(idx);
  98.   
  99.   if lstSingnals.Items.Count=0 then
  100.   begin
  101.     edtTitle.Text:='';
  102.     HtmlEdit.Clear;
  103.     Exit;
  104.   end;
  105.   if idx>lstSingnals.Count-1 then idx:=lstSingnals.Count-1;
  106.   lstSingnals.ItemIndex:=idx;
  107.   ShowSingnals(lstSingnals.ItemIndex);
  108. end;
  109. procedure TfrmSingnals.btnSaveClick(Sender: TObject);
  110. var
  111.   I:integer;
  112.   S:String;
  113. begin
  114.   if Length(htmledit.HTML)>0 then
  115.   begin
  116.     S:=htmledit.HTML;
  117.     if StrBeginWith(#$D#$A'<BODY>',S) then
  118.       delete(S,1,Length(#$D#$A'<BODY>'));
  119.     if StrEndWith('</BODY>',S) then
  120.       copy(S,1,Length(S)-Length('</BODY>'));
  121.     FillChar(FSingnalMgr.Get(lstSingnals.ItemIndex).Text[0],Length(FSingnalMgr.Get(lstSingnals.ItemIndex).Text),0);
  122.     for I:=0 to Length(S)-1 do
  123.       FSingnalMgr.Get(lstSingnals.ItemIndex).Text[I]:=S[I+1];
  124.   end;
  125.   FSingnalMgr.Get(lstSingnals.ItemIndex).Caption:=edtTitle.Text;
  126.   MsgBoxWarn('保存成功,您可以继续写新签名啦。');
  127. end;
  128. procedure TfrmSingnals.FormClose(Sender: TObject;
  129.   var Action: TCloseAction);
  130. begin
  131.   FSingnalMgr.SaveToFile;
  132.   Action:=caFree;
  133. end;
  134. procedure TfrmSingnals.edtTitleKeyDown(Sender: TObject; var Key: Word;
  135.   Shift: TShiftState);
  136. begin
  137.   if lstSingnals.ItemIndex=-1 then  Exit;
  138.   FSingnalMgr.Get(lstSingnals.ItemIndex).Caption:=edtTitle.Text;
  139.   lstSingnals.Items[lstSingnals.ItemIndex]:=edtTitle.Text;
  140. end;
  141. procedure TfrmSingnals.chkDefaultClick(Sender: TObject);
  142. begin
  143.   FSingnalMgr.Iterator.First;
  144.   while FSingnalMgr.Iterator.HasNext do
  145.     PSingnalData(FSingnalMgr.Iterator.Next).Default:=false;
  146.   FSingnalMgr.Get(lstSingnals.ItemIndex).Default:=true;
  147. end;
  148. procedure TfrmSingnals.lstSingnalsMouseUp(Sender: TObject;
  149.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  150. begin
  151.   if lstSingnals.ItemIndex>=0 then ShowSingnals(lstSingnals.ItemIndex);
  152. end;
  153. end.