⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvqscheduleeditorform.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
                  IndexValue := StrToInt64(cbMonthlyIndexValue.Text);
                Interval := StrToInt64(edMonthlyIndexInterval.Text);
              end;
            end;
          end;
        srkYearly:
          begin
            with ASchedule as IJclYearlySchedule do
            begin
              if rbYearlyDate.Checked then
              begin
                IndexKind := sikNone;
                Day := StrToInt64(edYearlyDateDay.Text);
                Month := cbYearlyDateMonth.ItemIndex + 1;
                Interval := StrToInt64(edYearlyDateInterval.Text);
              end
              else
              begin
                IndexKind := TScheduleIndexKind(cbYearlyIndexKind.ItemIndex + 1);
                if cbYearlyIndexValue.ItemIndex > -1 then
                begin
                  if cbYearlyIndexValue.ItemIndex < 4 then
                    IndexValue := cbYearlyIndexValue.ItemIndex + 1
                  else
                    IndexValue := sivLast;
                end
                else
                  IndexValue := StrToInt64(cbYearlyIndexValue.Text);
                Month := cbYearlyIndexMonth.ItemIndex + 1;
                Interval := StrToInt64(edYearlyIndexInterval.Text);
              end;
            end;
          end;
      end;

      with ASchedule as IJclScheduleDayFrequency do
      begin
        if rbFreqOneshot.Checked then
        begin
          StartTime := DateTimeToTimeStamp(dtpDayFreqOneshot.Time).Time;
          EndTime := StartTime;
          Interval := 1;
        end
        else
        begin
          StartTime := DateTimeToTimeStamp(dtpFreqFrom.Time).Time;
          EndTime := DateTimeToTimeStamp(dtpFreqTo.Time).Time;
          case cbFreqIntervalUnit.ItemIndex of
            0: { Milliseconds }
              Interval := StrToInt64(edFreqInterval.Text);
            1: { Seconds }
              Interval := 1000 * StrToInt64(edFreqInterval.Text);
            2: { Minutes }
              Interval := 60 * 1000 * StrToInt64(edFreqInterval.Text);
            3: { Hours }
              Interval := 60 * 60 * 1000 * StrToInt64(edFreqInterval.Text);
          end;
        end;
      end;

      case EndType of
        sekDate:
          EndDate := DateTimeToTimeStamp(Trunc(dtpEndDate.Date) + Frac(dtpEndTime.Time));
        sekTriggerCount:
          EndCount := StrToInt64(edEventCount.Text);
        sekDayCount:
          EndCount := StrToInt64(edDayCount.Text);
      end;
    end;
    Reset;
  end;
end;

procedure TFrmScheduleEditor.ScheduleToUI(const ASchedule: IJclSchedule);
var
  TempStamp: TTimeStamp;
begin
  with ASchedule do
  begin
    dtpStartDate.Date := Trunc(TimeStampToDateTime(StartDate));
    dtpStartTime.Time := Frac(TimeStampToDateTime(StartDate));

    case RecurringType of
      srkOneShot:
        rbSingleShot.Checked := True;
      srkDaily:
        begin
          rbDaily.Checked := True;
          with ASchedule as IJclDailySchedule do
          begin
            if EveryWeekDay then
              rbDailyEveryWeekDay.Checked := True
            else
            begin
              rbDailyInterval.Checked := True;
              edDailyInterval.Text := IntToStr(Interval);
            end;
          end;
        end;
      srkWeekly:
        begin
          rbWeekly.Checked := True;
          with ASchedule as IJclWeeklySchedule do
          begin
            cbWeeklyMon.Checked := swdMonday in DaysOfWeek;
            cbWeeklyTue.Checked := swdTuesday in DaysOfWeek;
            cbWeeklyWed.Checked := swdWednesday in DaysOfWeek;
            cbWeeklyThu.Checked := swdThursday in DaysOfWeek;
            cbWeeklyFri.Checked := swdFriday in DaysOfWeek;
            cbWeeklySat.Checked := swdSaturday in DaysOfWeek;
            cbWeeklySun.Checked := swdSunday in DaysOfWeek;
            edWeeklyInterval.Text := IntToStr(Interval);
          end
        end;
      srkMonthly:
        begin
          rbMonthly.Checked := True;
          with ASchedule as IJclMonthlySchedule do
          begin
            case IndexKind of
              sikNone:
                begin
                  rbMonthlyDay.Checked := True;
                  edMonthlyDay.Text := IntToStr(Day);
                  edMonthlyEveryMonth.Text := IntToStr(Interval);
                end;
              sikDay, sikWeekDay, sikWeekendDay, sikMonday, sikTuesday,
              sikWednesday, sikThursday, sikFriday, sikSaturday,
              sikSunday:
                begin
                  rbMonthlyEveryIndex.Checked := True;
                  if (IndexValue > 0) and (IndexValue < 5) then
                    cbMonthlyIndexValue.ItemIndex := IndexValue - 1
                  else
                  if IndexValue = sivLast then
                    cbMonthlyIndexValue.ItemIndex := 4
                  else
                  begin
                    cbMonthlyIndexValue.ItemIndex := -1;
                    cbMonthlyIndexValue.Text := IntToStr(IndexValue);
                  end;
                  cbMonthlyIndexType.ItemIndex := Ord(IndexKind) - 1;
                  edMonthlyIndexInterval.Text := IntToStr(Interval);
                end;
            else
              raise ESchedule.Create(RsEInvalidScheduleSettingsFound);
            end;
          end;
        end;
      srkYearly:
        begin
          rbYearly.Checked := True;
          with ASchedule as IJclYearlySchedule do
          begin
            case IndexKind of
              sikNone:
                begin
                  rbYearlyDate.Checked := True;
                  edYearlyDateDay.Text := IntToStr(Day);
                  cbYearlyDateMonth.ItemIndex := Month - 1;
                  edYearlyDateInterval.Text := IntToStr(Interval);
                end;
              sikDay, sikWeekDay, sikWeekendDay, sikMonday, sikTuesday,
                sikWednesday, sikThursday, sikFriday, sikSaturday,
                sikSunday:
                begin
                  rbYearlyIndex.Checked := True;
                  if (IndexValue > 0) and (IndexValue < 5) then
                    cbYearlyIndexValue.ItemIndex := IndexValue - 1
                  else
                  if IndexValue = sivLast then
                    cbYearlyIndexValue.ItemIndex := 4
                  else
                  begin
                    cbYearlyIndexValue.ItemIndex := -1;
                    cbYearlyIndexValue.Text := IntToStr(IndexValue);
                  end;
                  cbYearlyIndexKind.ItemIndex := Ord(IndexKind) - 1;
                  cbYearlyIndexMonth.ItemIndex := Month - 1;
                  edYearlyIndexInterval.Text := IntToStr(Interval);
                end;
            else
              raise ESchedule.Create(RsEInvalidScheduleSettingsFound);
            end;
          end;
        end;
    end;
    case EndType of
      sekNone:
        rbInfinite.Checked := True;
      sekDate:
        begin
          rbDate.Checked := True;
          dtpEndDate.Date := Trunc(TimeStampToDateTime(EndDate));
          dtpEndTime.Time := Frac(TimeStampToDateTime(EndDate));
        end;
      sekTriggerCount:
        begin
          rbTriggerCount.Checked := True;
          edEventCount.Text := IntToStr(EndCount);
        end;
      sekDayCount:
        begin
          rbDayCount.Checked := True;
          edDayCount.Text := IntToStr(EndCount);
        end;
    end;
    if RecurringType <> srkOneShot then
    begin
      with ASchedule as IJclScheduleDayFrequency do
      begin
        rbFreqOneshot.Checked := StartTime = EndTime;
        rbFreqInterval.Checked := StartTime <> EndTime;
        if rbFreqOneshot.Checked then
        begin
          TempStamp := DateTimeToTimeStamp(Now);
          TempStamp.Time := StartTime;
          dtpDayFreqOneshot.Time := TimeStampToDateTime(TempStamp);
        end
        else
        begin
          TempStamp := DateTimeToTimeStamp(Now);
          TempStamp.Time := StartTime;
          dtpFreqFrom.Time := TimeStampToDateTime(TempStamp);
          TempStamp.Time := EndTime;
          dtpFreqTo.Time := TimeStampToDateTime(TempStamp);

          if Interval mod (60 * 60 * 1000) = 0 then
          begin
            cbFreqIntervalUnit.ItemIndex := 3;
            edFreqInterval.Text := IntToStr(Interval div (60 * 60 * 1000));
          end
          else
          if Interval mod (60 * 1000) = 0 then
          begin
            cbFreqIntervalUnit.ItemIndex := 2;
            edFreqInterval.Text := IntToStr(Interval div (60 * 1000));
          end
          else
          if Interval mod 1000 = 0 then
          begin
            cbFreqIntervalUnit.ItemIndex := 1;
            edFreqInterval.Text := IntToStr(Interval div 1000);
          end
          else
          begin
            cbFreqIntervalUnit.ItemIndex := 0;
            edFreqInterval.Text := IntToStr(Interval);
          end;
        end;
      end;
    end;
  end;
end;

procedure TFrmScheduleEditor.FormCreate(Sender: TObject);
const
  cTimeFormat = 'HH:mm:ss';
  cDateFormat = 'dd-MM-yyyy';
begin
  FTestSchedule := CreateSchedule;
  
  dtpStartDate.Format := cDateFormat;
  dtpStartTime.Format := cTimeFormat;
  dtpEndDate.Format := cDateFormat;
  dtpEndTime.Format := cTimeFormat;
  dtpDayFreqOneshot.Format := cTimeFormat;
  dtpFreqFrom.Format := cTimeFormat;
  dtpFreqTo.Format := cTimeFormat;
  
  dtpStartDate.DateTime := Now;
  dtpEndDate.DateTime := Now;

  cbMonthlyIndexValue.ItemIndex := 0;
  cbMonthlyIndexType.ItemIndex := 1;
  cbYearlyIndexValue.ItemIndex := 0;
  cbYearlyIndexKind.ItemIndex := 1;
  cbYearlyDateMonth.ItemIndex := 0;
  cbYearlyIndexMonth.ItemIndex := 0;
  cbFreqIntervalUnit.ItemIndex := 2;
end;

procedure TFrmScheduleEditor.btnTestClick(Sender: TObject);
var
  Stamp: TTimeStamp;
  AYear, AMonth, ADay: Word;
  ADays, AHour, AMinute, ASecond, AMSec: Word;
begin
  if FBusy then
    FBusy := False
  else
  begin
    try
      FBusy := True;
      btnTest.Caption := RsStop;
      btnOk.Enabled := False;
      btnCancel.Enabled := False;
      InitSchedule(FTestSchedule);
      mmLog.Lines.Clear;
      if cxStartToday.Checked then
        Stamp := FTestSchedule.NextEventFromNow(cxCountMissedEvents.Checked)
      else
        Stamp := FTestSchedule.NextEventFrom(FTestSchedule.StartDate, True);
      while (Stamp.Date > 0) and FBusy do
      begin
        JclDateTime.DecodeDate(TimeStampToDateTime(Stamp), AYear, AMonth, ADay);
        DecodeTimeStampTime(Stamp, ADays, AHour, AMinute, ASecond, AMSec);
        mmLog.Lines.Add(Format('%.5d (%.4d): %.2d-%.2d-%.4d@%.2d:%.2d:%.2d.%.3d',
          [FTestSchedule.TriggerCount, FTestSchedule.DayCount, ADay, AMonth,
           AYear, AHour, AMinute, ASecond, AMSec]));
        Application.ProcessMessages;
        Stamp := FTestSchedule.NextEvent(True);
      end;
    finally
      FBusy := False;
      btnTest.Caption := RsRun;
      btnOk.Enabled := True;
      btnCancel.Enabled := True;
    end;
  end;
end;

procedure TFrmScheduleEditor.AppEventsIdle(Sender: TObject;
  var Done: Boolean);
begin
  SelectRecurringInfoPage;
  if rbDaily.Checked then
    UpdateDailyPageInfo
  else
  if rbWeekly.Checked then
    UpdateWeeklyPageInfo
  else
  if rbMonthly.Checked then
    UpdateMonthlyPageInfo
  else
  if rbYearly.Checked then
    UpdateYearlyPageInfo;
  UpdateFrequencyPageInfo;
  UpdateEndPageInfo;

  UpdateTestSettings;
end;

procedure TFrmScheduleEditor.btnOkClick(Sender: TObject);
begin
  InitSchedule(Schedule);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -