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

Email服务器

开发平台:

Delphi

  1. unit ufrmAwake;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, cxTextEdit, cxSpinEdit, cxTimeEdit, cxControls, cxContainer,
  6.   cxEdit, cxMaskEdit, cxDropDownEdit, cxCalendar, StdCtrls, cxRadioGroup,
  7.   ExtCtrls, cxGroupBox, cxMemo, cxPC, cxGraphics, cxImageComboBox, cxLabel,
  8.   Menus, cxLookAndFeelPainters, cxButtons, dxSkinsCore, dxSkinBlack,
  9.   dxSkinBlue, dxSkinCaramel, dxSkinCoffee, {dxSkinDarkRoom,} dxSkinDarkSide,
  10.   {dxSkinFoggy,} dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian,
  11.   dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  12.   dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  13.   dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinPumpkin, {dxSkinSeven,}
  14.   {dxSkinSharp,} dxSkinSilver, {dxSkinSpringTime,} dxSkinStardust,
  15.   dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  16.   dxSkinXmas2008Blue, dxSkinscxPCPainter;
  17. type
  18.   TfrmAwake = class(TForm)
  19.     pnl1: TPanel;
  20.     rbSingle: TcxRadioButton;
  21.     rbRepeat: TcxRadioButton;
  22.     edtTitle: TcxTextEdit;
  23.     pcAwake: TcxPageControl;
  24.     tsByOne: TcxTabSheet;
  25.     tsRepeat: TcxTabSheet;
  26.     edByOne_Date: TcxDateEdit;
  27.     edTips: TcxMemo;
  28.     lbl13: TcxLabel;
  29.     lbl14: TcxLabel;
  30.     lbl15: TcxLabel;
  31.     bvl1: TBevel;
  32.     btnOk: TcxButton;
  33.     btnCancel: TcxButton;
  34.     bvl2: TBevel;
  35.     rgModal: TcxRadioGroup;
  36.     bvl3: TBevel;
  37.     pcByWhich: TcxPageControl;
  38.     tsByHour: TcxTabSheet;
  39.     edIntervalHour: TcxSpinEdit;
  40.     lbl10: TcxLabel;
  41.     lbl11: TcxLabel;
  42.     tsByDay: TcxTabSheet;
  43.     edIntervalDay: TcxSpinEdit;
  44.     lbl7: TcxLabel;
  45.     lbl9: TcxLabel;
  46.     tsByWeek: TcxTabSheet;
  47.     edWeekInterval: TcxSpinEdit;
  48.     rgWeek: TcxRadioGroup;
  49.     lbl1: TcxLabel;
  50.     lbl4: TcxLabel;
  51.     tsByManth: TcxTabSheet;
  52.     edManthDay: TcxSpinEdit;
  53.     lbl2: TcxLabel;
  54.     edManthWeek: TcxSpinEdit;
  55.     cbWeek_Day: TcxImageComboBox;
  56.     lbl5: TcxLabel;
  57.     rbManthDay: TcxRadioButton;
  58.     rbManthWeek: TcxRadioButton;
  59.     cbManthWeek_Week: TcxImageComboBox;
  60.     cbManthDay_Day: TcxImageComboBox;
  61.     tsByYear: TcxTabSheet;
  62.     cbByDay_YearInterval: TcxImageComboBox;
  63.     rbByDay: TcxRadioButton;
  64.     rbByWeek: TcxRadioButton;
  65.     cbByDay_Day: TcxImageComboBox;
  66.     cbByWeek_YearInterval: TcxImageComboBox;
  67.     cbByWeek_Week: TcxImageComboBox;
  68.     cbByWeek_Sort: TcxImageComboBox;
  69.     edTime: TcxTimeEdit;
  70.     lbl3: TcxLabel;
  71.     edMemoRepeat: TcxMemo;
  72.     lbl6: TcxLabel;
  73.     procedure FormCreate(Sender: TObject);
  74.     procedure rbSingleClick(Sender: TObject);
  75.     procedure rbRepeatClick(Sender: TObject);
  76.     procedure cxRadioGroup1PropertiesChange(Sender: TObject);
  77.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  78.     procedure btnOkClick(Sender: TObject);
  79.     procedure edMemoRepeatClick(Sender: TObject);
  80.     procedure edTipsClick(Sender: TObject);
  81.   private
  82.     { Private declarations }
  83.     procedure LoadInitData;
  84.     function CheckInput:Boolean;
  85.   public
  86.     { Public declarations }
  87.     FEmailAddr,            //显示窗体前必须设置这2个变量的值
  88.     FContentFilePath:String;
  89.   end;
  90. var
  91.   frmAwake: TfrmAwake;
  92. implementation
  93. uses DateUtils, uEmailAwake, uCommon;
  94. {$R *.dfm}
  95. procedure TfrmAwake.FormCreate(Sender: TObject);
  96. begin
  97.   LoadInitData;
  98. end;
  99. procedure TfrmAwake.LoadInitData;
  100. begin
  101.   pcAwake.HideTabs:=true;
  102.   pcByWhich.HideTabs:=true;
  103.   edByOne_Date.Date:=now;
  104.   edTime.Time:=now;
  105.   edTips.SelStart:=0;
  106.   edTips.SelLength:=Length(edTips.Lines.Text);
  107.   pcAwake.ActivePageIndex:=0;
  108.   pcByWhich.ActivePageIndex:=0;
  109. end;
  110. procedure TfrmAwake.rbSingleClick(Sender: TObject);
  111. begin
  112.   pcAwake.ActivePageIndex:=0;
  113. end;
  114. procedure TfrmAwake.rbRepeatClick(Sender: TObject);
  115. begin
  116.   pcAwake.ActivePageIndex:=1;
  117. end;
  118. procedure TfrmAwake.cxRadioGroup1PropertiesChange(Sender: TObject);
  119. begin
  120.   pcByWhich.ActivePageIndex:=rgModal.Properties.Items[rgModal.ItemIndex].Value;
  121. end;
  122. procedure TfrmAwake.FormClose(Sender: TObject; var Action: TCloseAction);
  123. begin
  124.   Action:=caFree;
  125. end;
  126. procedure TfrmAwake.btnOkClick(Sender: TObject);
  127. var
  128.   EmailAwake:TBaseAwake;
  129.   AwakeWeek:TAwakeWeek;
  130. begin
  131.   if not CheckInput then exit;
  132.   if rbSingle.Checked then
  133.    EmailAwake:=TSingleAwake.Create
  134.   else
  135.    EmailAwake:=TRepeatAwake.Create;
  136.   EmailAwake.BaseTime:=Now;
  137.   EmailAwake.AwakeTime:=TimeOf(edTime.Time);
  138.   EmailAwake.ContentFilePath:=FContentFilePath;
  139.   EmailAwake.EmailAddr:=FEmailAddr;
  140.   try
  141.     try
  142.       EmailAwake.Title:=trim(edtTitle.Text);
  143.       EmailAwake.EmailAddr:=FEmailAddr;
  144.       EmailAwake.ContentFilePath:=FContentFilePath;
  145.       if rbSingle.Checked then
  146.       begin
  147.         TSingleAwake(EmailAwake).AwakeTime:=edTime.Time;
  148.         TSingleAwake(EmailAwake).AwakeDate:=edByOne_Date.Date;
  149.         if trim(edTips.Text)='您可以在这里输入提醒时显示的文字'then edTips.Text:='';
  150.         EmailAwake.Memo:=edTips.Text;
  151.       end
  152.       else
  153.       begin
  154.         EmailAwake.Memo:=edMemoRepeat.Text;
  155.         TRepeatAwake(EmailAwake).AwakeModal:=TAwakeModal(rgModal.ItemIndex);
  156.         case TRepeatAwake(EmailAwake).AwakeModal of
  157.           amHour:
  158.             TRepeatAwake(EmailAwake).AwakeHour:=edIntervalHour.Value;
  159.           amDay:
  160.             TRepeatAwake(EmailAwake).AwakeHour:=edIntervalHour.Value;
  161.           amWeek:
  162.           begin
  163.             AwakeWeek.WeekInterval:=edWeekInterval.Value;
  164.             AwakeWeek.WeekDay:=rgWeek.ItemIndex;
  165.             TRepeatAwake(EmailAwake).AwakeWeek:=AwakeWeek;
  166.           end;
  167.           amManth:
  168.           begin
  169.             if rbManthDay.Checked then
  170.             begin
  171.               TRepeatAwake(EmailAwake).AwakeManth.FManthDayOrWeek:=mdwDay ;
  172.               TRepeatAwake(EmailAwake).AwakeManth.FManthInterval:=edManthDay.Value;
  173.               TRepeatAwake(EmailAwake).AwakeManth.FManthDay:=cbManthDay_Day.ItemIndex+1;
  174.             end
  175.             else
  176.             begin
  177.               TRepeatAwake(EmailAwake).AwakeManth.FManthDayOrWeek:=mdwWeek;
  178.               TRepeatAwake(EmailAwake).AwakeManth.FManthInterval:=edManthWeek.Value;
  179.               TRepeatAwake(EmailAwake).AwakeManth.FManthWeek:=cbManthWeek_Week.ItemIndex+1;
  180.               TRepeatAwake(EmailAwake).AwakeManth.FWeekDay:=cbWeek_Day.ItemIndex+1;
  181.             end;
  182.           end;
  183.           amYear:
  184.           begin
  185.             if rbByDay.Checked then
  186.             begin
  187.               TRepeatAwake(EmailAwake).FAwakeYear.FYearDayOrWeek:=mdwDay;
  188.               TRepeatAwake(EmailAwake).FAwakeYear.FYearInterval:=cbByDay_YearInterval.ItemIndex+1;
  189.               TRepeatAwake(EmailAwake).FAwakeYear.FYearDay:=cbByDay_Day.ItemIndex+1;
  190.             end
  191.             else
  192.             begin
  193.               TRepeatAwake(EmailAwake).FAwakeYear.FYearDayOrWeek:=mdwWeek;
  194.               TRepeatAwake(EmailAwake).FAwakeYear.FYearInterval:=cbByWeek_Week.ItemIndex+1;
  195.               TRepeatAwake(EmailAwake).FAwakeYear.FYearWeek:=cbByWeek_YearInterval.ItemIndex+1;
  196.               TRepeatAwake(EmailAwake).FAwakeYear.FWeekDay:=cbByWeek_Sort.ItemIndex+1;
  197.             end;
  198.           end;
  199.         end;
  200.       end;
  201.       EmailAwake.SaveToXml(AppPath+'EmailServers.xml');
  202.     except
  203.       raise;
  204.       exit;
  205.     end;
  206.     
  207.   finally
  208.     EmailAwake.Free;
  209.   end;
  210.  
  211.   self.ModalResult:=mrOk;
  212. end;
  213. function TfrmAwake.CheckInput: Boolean;
  214. begin
  215.   Result:=false;
  216.   if Length(trim(edtTitle.Text))=0 then
  217.   begin
  218.     MsgBoxError('标题不能为空');
  219.     edtTitle.SetFocus;
  220.     exit;
  221.   end;
  222.   if rbSingle.Checked then
  223.   begin
  224.     if edByOne_Date.Date<= DateOf(Now) then
  225.     begin
  226.       MsgBoxError('提醒日期不能小于当天日期');
  227.       edByOne_Date.SetFocus;
  228.       exit;
  229.     end;
  230.     if (edByOne_Date.Date= DateOf(Now))and (edTime.Time<= Timeof(Now)) then
  231.     begin
  232.       MsgBoxError('提醒时间不能小于当前时间');
  233.       edByOne_Date.SetFocus;
  234.       exit;
  235.     end;
  236.   end;
  237.   Result:=true;
  238. end;
  239. procedure TfrmAwake.edMemoRepeatClick(Sender: TObject);
  240. begin
  241.   if edMemoRepeat.Lines.Text='您可以在这里输入提醒时显示的文字' then
  242.    edMemoRepeat.Lines.Delete(0);
  243. end;
  244. procedure TfrmAwake.edTipsClick(Sender: TObject);
  245. begin
  246.   if edTips.Lines.Text='您可以在这里输入提醒时显示的文字' then
  247.    edTips.Lines.Delete(0);
  248. end;
  249. end.