ufrmViewEmail.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:11k
- unit ufrmViewEmail;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, uBaseEditorForm, ActnList, uHtmlEdit, dxBar, ImgList,
- dxBarExtItems, cxClasses, OleCtrls, SHDocVw, ExtCtrls, cxGraphics,
- cxControls, dxStatusBar, cxContainer, cxEdit, cxLabel, cxStyles,
- cxCustomData, cxFilter, cxData, cxDataStorage, cxGridCustomView,
- cxGridCustomTableView, cxGridTableView, cxGridLevel, cxGrid, dxSkinsCore,
- dxSkinsdxBarPainter, dxSkinBlack, dxSkinBlue, dxSkinCaramel,
- dxSkinCoffee, {dxSkinDarkRoom,} dxSkinDarkSide, {dxSkinFoggy,}
- dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
- dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
- dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
- dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinPumpkin, {dxSkinSeven,}
- {dxSkinSharp,} dxSkinSilver, {dxSkinSpringTime,} dxSkinStardust,
- dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
- dxSkinXmas2008Blue, dxSkinsdxStatusBarPainter;
- type
- TfrmViewEmail = class(TBaseEditorForm)
- pnl1: TPanel;
- dxStatusBar1: TdxStatusBar;
- dxbrsbtm4: TdxBarSubItem;
- dxbrsbtm5: TdxBarSubItem;
- dxbrsbtm6: TdxBarSubItem;
- btn1: TdxBarButton;
- btn2: TdxBarButton;
- btn3: TdxBarButton;
- btn4: TdxBarButton;
- btn5: TdxBarButton;
- btn6: TdxBarButton;
- btn7: TdxBarButton;
- btn8: TdxBarButton;
- btn9: TdxBarButton;
- btnNextUnread: TdxBarButton;
- btn11: TdxBarButton;
- btn12: TdxBarButton;
- btn13: TdxBarButton;
- dxbrsbtm7: TdxBarSubItem;
- btn14: TdxBarButton;
- btn15: TdxBarButton;
- btn16: TdxBarButton;
- btn17: TdxBarButton;
- btn18: TdxBarButton;
- btn19: TdxBarButton;
- btn20: TdxBarButton;
- btn21: TdxBarButton;
- btn22: TdxBarButton;
- btn23: TdxBarButton;
- btn24: TdxBarButton;
- lbl2: TcxLabel;
- lbl3: TcxLabel;
- lbl4: TcxLabel;
- lbl5: TcxLabel;
- lblSender: TcxLabel;
- lblRecver: TcxLabel;
- lblRecvDate: TcxLabel;
- lblSubject: TcxLabel;
- btnRecp: TdxBarLargeButton;
- btnPrior: TdxBarLargeButton;
- btnTurn: TdxBarLargeButton;
- btnSucc: TdxBarLargeButton;
- btnDeleteEmail: TdxBarLargeButton;
- btnPreview: TdxBarLargeButton;
- btnPrint: TdxBarLargeButton;
- btnExit: TdxBarLargeButton;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure btnRecpClick(Sender: TObject);
- procedure btnTurnClick(Sender: TObject);
- procedure btnDeleteEmailClick(Sender: TObject);
- procedure btnPriorClick(Sender: TObject);
- procedure btnSuccClick(Sender: TObject);
- procedure btnPreviewClick(Sender: TObject);
- procedure btnPrintClick(Sender: TObject);
- procedure btnExitClick(Sender: TObject);
- procedure btn1Click(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure btnNextUnreadClick(Sender: TObject);
- procedure btn6Click(Sender: TObject);
- procedure btn9Click(Sender: TObject);
- procedure btn11Click(Sender: TObject);
- private
- { Private declarations }
- FAttchs:TStrings;
- FOneEmail:Boolean;//只显示一封邮件
- public
- { Public declarations }
- FTableView:TcxGridTableView; //删除邮件时,在创建窗体之后,必须设置这5个值
- FCurRecordIndex,
- FContentFileItemIndex:Integer;
- FRecverEmail, //接收者
- FSenderEmail:string; //发送者
- FEmailAddr,
- FContentFilePath:string;
- procedure ShowEmail;
- procedure ShowOneEmail;
- {调用方法:
- 1,创建窗体 Create.
- 2,设置以下变量的值
- FTableView:TcxGridTableView; //从那个Grid中读取数据
- FCurRecordIndex, //记录集当前记录位置
- FContentFileItemIndex, // email保存位置在记录集的第几个字段.
- FRecverEMailAddrItemIndex:Integer; // email地址在记录集的第几个字段.
- FSenderEmail:string;
- 3,调用 ShowEmail
- }
- { 显示一封邮件时的调用方法:
- 1,设置FEmailAddr,
- 2,设置FContentFilePath:string;
- 3,调用ShowOneEmail;
- }
- end;
- var
- frmViewEmail: TfrmViewEmail;
- implementation
- uses UEmailFile, ufrmWriteEmail, uMyXml, uCommon, cxCheckListBox;
- {$R *.dfm}
- { TfrmViewEmail }
- procedure TfrmViewEmail.ShowEmail;
- var
- EMail:TEMailFile;
- begin
- if (FCurRecordIndex<0) then
- FCurRecordIndex:=FTableView.DataController.RecordCount-1 ;
- if FCurRecordIndex>FTableView.DataController.RecordCount-1 then
- FCurRecordIndex:=0;
- btnNextUnread.Enabled:=FCurRecordIndex<FTableView.DataController.RecordCount-1;
- btnPrior.Enabled:=FCurRecordIndex>0;
- btnSucc.Enabled:=FCurRecordIndex<FTableView.DataController.RecordCount-1;
- btnNextUnread.Enabled:=FCurRecordIndex<FTableView.DataController.RecordCount-1;
-
- FContentFilePath:=VarToStr(FTableView.DataController.Values[FCurRecordIndex,FContentFileItemIndex]);
- EMail:=TEMailFile.Create(FContentFilePath);
- try
- EMail.GetEmail;
- lblSender.Caption:=Email.Sender;
- lblRecver.Caption:=FRecverEmail;
- lblRecvDate.Caption:=Email.Date;
- lblSubject.Caption:=Email.Subject;
- HtmlEdit.Clear;
- HtmlEdit.Insert(Email.Content);
- FAttchs.Assign(EMail.Attchs);
- finally
- EMail.Free;
- end;
- end;
- procedure TfrmViewEmail.FormCreate(Sender: TObject);
- begin
- inherited;
- FOneEmail:=false;
- FAttchs:=TStringList.Create;
- end;
- procedure TfrmViewEmail.FormDestroy(Sender: TObject);
- begin
- FAttchs.Free;
- inherited;
- end;
- procedure TfrmViewEmail.btnRecpClick(Sender: TObject);
- var
- Email:TEmailFile;
- idx:Integer;
- begin
- if FOneEmail then
- begin
- with TfrmWriteEMail.Create(Application) do
- begin
- try
- Caption:='回复邮件';
- Email:=TEmailFile.Create(FContentFilePath);
- try
- Email.GetEmail;
- finally
- idx:=cbSender.Properties.Items.IndexOf(Email.Recver);
- if idx>=0 then
- cbSender.ItemIndex:=idx //cbSender.Properties.Items.IndexOf(FEmailAddr)
- else
- cbSender.Properties.Items.Insert(0,Email.Recver);
- idx:=cbRecver.Properties.Items.IndexOf(Email.Sender) ;
- if idx>=0 then
- cbRecver.ItemIndex:=idx
- //cbRecver.Properties.Items.Delete(cbRecver.Properties.Items.IndexOf(Email.Sender));
- else
- cbRecver.Properties.Items.Insert(0,Email.Sender);
- //cbRecver.ItemIndex:=0;
- end;
- ShowModal;
- finally
- Free;
- end;
- end;
- Exit;
- end;
- with TfrmWriteEMail.Create(Application) do
- try
- Caption:='回复邮件';
- with FTableView.DataController do
- begin
- cbRecver.Properties.Items.Insert(0,FSenderEmail) ;
- if cbSender.Properties.Items.IndexOf(FRecverEmail)<>-1 then
- cbSender.ItemIndex:=cbSender.Properties.Items.IndexOf(FRecverEmail);
- end;
- cbRecver.ItemIndex:=0;
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TfrmViewEmail.btnTurnClick(Sender: TObject);
- var
- EmailFile:TEmailFile;
- Path:string;
- I:Integer;
- begin
- if FOneEmail then
- Path:=FContentFilePath
- else
- begin
- if not FileExists(VarToStr(FTableView.DataController.Values[FCurRecordIndex,FContentFileItemIndex])) then exit;
- Path:=VarToStr(FTableView.DataController.Values[FCurRecordIndex,FContentFileItemIndex]);
- end;
- with TfrmWriteEMail.Create(Application) do
- try
- Caption:='转发邮件';
- FSetDoc:=True;
- pnl1.Height:=234;
-
- EmailFile:=TEmailFile.Create(Path);
- try
- EmailFile.GetEmail;
- for I:=0 to EmailFile.Attchs.Count-1 do
- begin
- with lstAttch.Items.Add do
- begin
- Text:=EmailFile.Attchs[I];
- Checked:=True;
- end;
- end;
- //cbAttch.Properties.Items.Assign(EmailFile.Attchs);
- if FOneEmail then
- begin
- if cbSender.Properties.Items.IndexOf(FEmailAddr)<>-1 then
- cbSender.ItemIndex:=cbSender.Properties.Items.IndexOf(FEmailAddr);
- cbSender.ItemIndex:=0;
- end;
- FStr:=EmailFile.Content;
- finally
- EmailFile.Free;
- end;
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TfrmViewEmail.btnDeleteEmailClick(Sender: TObject);
- var
- xml:TAppXml;
- begin
- if MessageDlg('你确定要删除当前邮件吗?' + #13#10#13#10#13#10#13#10 +
- #13#10, mtConfirmation, mbOKCancel, 0)=mrCancel then Exit;
- xml:=TAppXml.Create;
- try
- if FOneEmail then
- begin
- xml.DeleteEmailAwake(FEmailAddr,FContentFilePath);
- MsgBoxWarn('删除成功!');
- end
- else
- begin
- if xml.DeleteAEmail(FRecverEmail,VarToStr(FTableView.DataController.Values[FCurRecordIndex,FContentFileItemIndex])) then
- MsgBoxWarn('删除成功!')
- else
- MsgBoxError('无法删除邮件!');
- end;
- finally
- xml.Free;
- end;
- lblSender.Caption:='';
- lblRecver.Caption:='';
- lblRecvDate.Caption:='';
- lblSubject.Caption:='';
- HtmlEdit.Clear;
- if not FOneEmail then
- begin
- FTableView.DataController.DeleteRecord(FCurRecordIndex);
- btnSuccClick(nil);
- end;
- end;
- procedure TfrmViewEmail.btnPriorClick(Sender: TObject);
- begin
- Dec(FCurRecordIndex);
- ShowEmail;
- end;
- procedure TfrmViewEmail.btnSuccClick(Sender: TObject);
- begin
- Inc(FCurRecordIndex);
- ShowEmail;
- end;
- procedure TfrmViewEmail.btnPreviewClick(Sender: TObject);
- begin
- HtmlEdit.PrintPageSetup;
- HtmlEdit.PrintPreview;
- end;
- procedure TfrmViewEmail.btnPrintClick(Sender: TObject);
- begin
- HtmlEdit.PrintPageSetup;
- HtmlEdit.Print;
- end;
- procedure TfrmViewEmail.btnExitClick(Sender: TObject);
- begin
- close;
- end;
- procedure TfrmViewEmail.btn1Click(Sender: TObject);
- begin
- if dlgSave.Execute then
- HtmlEdit.SaveToFile(dlgSave.FileName);
- end;
- procedure TfrmViewEmail.FormClose(Sender: TObject;
- var Action: TCloseAction);
- begin
- Action:=caFree;
- end;
- procedure TfrmViewEmail.btnNextUnreadClick(Sender: TObject);
- begin
- repeat
- Inc(FCurRecordIndex);
- if FCurRecordIndex>=FTableView.DataController.RecordCount then
- begin
- MsgBoxWarn('没有未读邮件');
- exit;
- end;
- until (FTableView.DataController.Values[FCurRecordIndex,0]=false);
- ShowEmail;
- end;
- procedure TfrmViewEmail.btn6Click(Sender: TObject);
- begin
- dxbrmngr1Bar1.visible:=btn6.Down;
- end;
- procedure TfrmViewEmail.btn9Click(Sender: TObject);
- begin
- dxStatusBar1.visible:=btn9.Down;
- end;
- procedure TfrmViewEmail.btn11Click(Sender: TObject);
- begin
- pnl1.visible:=btn11.Down;
- end;
- procedure TfrmViewEmail.ShowOneEmail;
- var
- EMail:TEMailFile;
- begin
- FOneEmail:=True;
- btn12.Visible:=ivNever;
- btn13.Visible:=ivNever;
- btnNextUnread.Visible:=ivNever;
- btnPrior.Visible:=ivNever;
- btnSucc.Visible:=ivNever;
- EMail:=TEMailFile.Create(VarToStr(FTableView.DataController.Values[FCurRecordIndex,FContentFileItemIndex]));
- try
- EMail.GetEmail;
- lblSender.Caption:=Email.Sender;
- lblRecver.Caption:=FEmailAddr;
- lblRecvDate.Caption:=Email.Date;
- lblSubject.Caption:=Email.Subject;
- HtmlEdit.Clear;
- HtmlEdit.Insert(Email.Content);
- FAttchs.Assign(EMail.Attchs);
- finally
- EMail.Free;
- end;
- end;
- end.