ufrmSingnals.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:5k
- unit ufrmSingnals;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, uBaseEditorForm, dxBarExtItems, cxControls, cxContainer,
- cxListBox, ActnList, dxBar, ImgList, cxClasses, OleCtrls, SHDocVw,
- uHtmlEdit, ExtCtrls,uSingnalMgr, cxTextEdit, cxEdit, cxLabel, cxCheckBox,
- cxGroupBox, cxRadioGroup;
- type
- TfrmSingnals = class(TBaseEditorForm)
- btnAdd: TdxBarLargeButton;
- btnDelete: TdxBarLargeButton;
- btn3: TdxBarLargeButton;
- btn4: TdxBarLargeButton;
- btn5: TdxBarLargeButton;
- btnExit: TdxBarLargeButton;
- pnl1: TPanel;
- lbl2: TcxLabel;
- edtTitle: TcxTextEdit;
- btnSave: TdxBarLargeButton;
- chkDefault: TcxCheckBox;
- lstSingnals: TcxListBox;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure btnExitClick(Sender: TObject);
- procedure btnAddClick(Sender: TObject);
- procedure btnDeleteClick(Sender: TObject);
- procedure btnSaveClick(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure edtTitleKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure chkDefaultClick(Sender: TObject);
- procedure lstSingnalsMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- private
- { Private declarations }
- FSingnalMgr:TAppSingnalMgr;
- public
- { Public declarations }
- procedure ShowSingnals(index:Integer);
- end;
- var
- frmSingnals: TfrmSingnals;
- implementation
- uses uCommon, uEncrypt;
- {$R *.dfm}
- procedure TfrmSingnals.FormCreate(Sender: TObject);
- begin
- inherited;
- FSingnalMgr:=TAppSingnalMgr.Create;
- FSingnalMgr.LoadFromFile;
- while FSingnalMgr.Iterator.HasNext do
- lstSingnals.Items.Add(PSingnalData(FSingnalMgr.Iterator.Next).Caption);
- if lstSingnals.Items.Count>0 then
- begin
- lstSingnals.ItemIndex:=0;
- ShowSingnals(0);
- end ;
- end;
- procedure TfrmSingnals.FormDestroy(Sender: TObject);
- begin
- FSingnalMgr.Free;
- inherited;
- end;
- procedure TfrmSingnals.btnExitClick(Sender: TObject);
- begin
- close;
- end;
- procedure TfrmSingnals.ShowSingnals(index:Integer);
- begin
- htmlEdit.Clear;
- edtTitle.Text:='';
- if index=-1 then exit;
- htmlEdit.Insert(FSingnalMgr.Get(index).Text);
- edtTitle.Text:=FSingnalMgr.Get(index).Caption;
-
- chkDefault.OnClick:=nil;
- try
- chkDefault.Checked:=FSingnalMgr.Get(index).Default;
- finally
- chkDefault.OnClick:=self.chkDefaultClick;
- end;
- end;
- procedure TfrmSingnals.btnAddClick(Sender: TObject);
- begin
- edtTitle.Text:='新签名 请修改签名名称';
- FSingnalMgr.Add.Caption:=edtTitle.Text;
- lstSingnals.Items.Add(edtTitle.Text);
- htmlEdit.Clear;
- end;
- procedure TfrmSingnals.btnDeleteClick(Sender: TObject);
- var
- idx:Integer;
- begin
- idx:=lstSingnals.ItemIndex;
- FSingnalMgr.Remove(idx);
- lstSingnals.Items.Delete(idx);
-
- if lstSingnals.Items.Count=0 then
- begin
- edtTitle.Text:='';
- HtmlEdit.Clear;
- Exit;
- end;
- if idx>lstSingnals.Count-1 then idx:=lstSingnals.Count-1;
- lstSingnals.ItemIndex:=idx;
- ShowSingnals(lstSingnals.ItemIndex);
- end;
- procedure TfrmSingnals.btnSaveClick(Sender: TObject);
- var
- I:integer;
- S:String;
- begin
- if Length(htmledit.HTML)>0 then
- begin
- S:=htmledit.HTML;
- if StrBeginWith(#$D#$A'<BODY>',S) then
- delete(S,1,Length(#$D#$A'<BODY>'));
- if StrEndWith('</BODY>',S) then
- copy(S,1,Length(S)-Length('</BODY>'));
- FillChar(FSingnalMgr.Get(lstSingnals.ItemIndex).Text[0],Length(FSingnalMgr.Get(lstSingnals.ItemIndex).Text),0);
- for I:=0 to Length(S)-1 do
- FSingnalMgr.Get(lstSingnals.ItemIndex).Text[I]:=S[I+1];
- end;
- FSingnalMgr.Get(lstSingnals.ItemIndex).Caption:=edtTitle.Text;
- MsgBoxWarn('保存成功,您可以继续写新签名啦。');
- end;
- procedure TfrmSingnals.FormClose(Sender: TObject;
- var Action: TCloseAction);
- begin
- FSingnalMgr.SaveToFile;
- Action:=caFree;
- end;
- procedure TfrmSingnals.edtTitleKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- if lstSingnals.ItemIndex=-1 then Exit;
- FSingnalMgr.Get(lstSingnals.ItemIndex).Caption:=edtTitle.Text;
- lstSingnals.Items[lstSingnals.ItemIndex]:=edtTitle.Text;
- end;
- procedure TfrmSingnals.chkDefaultClick(Sender: TObject);
- begin
- FSingnalMgr.Iterator.First;
- while FSingnalMgr.Iterator.HasNext do
- PSingnalData(FSingnalMgr.Iterator.Next).Default:=false;
- FSingnalMgr.Get(lstSingnals.ItemIndex).Default:=true;
- end;
- procedure TfrmSingnals.lstSingnalsMouseUp(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- if lstSingnals.ItemIndex>=0 then ShowSingnals(lstSingnals.ItemIndex);
- end;
- end.