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

📄 findofdatefrm.~pas

📁 基于Interbase的图书管理系统
💻 ~PAS
字号:
unit findOfDateFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, Buttons, ExtCtrls;

type
  TfindOfDateForm = class(TForm)
    GroupBox1: TGroupBox;
    Image1: TImage;
    bbtnFind: TBitBtn;
    bbtncancel: TBitBtn;
    cbbField: TComboBox;
    cbbWhere: TComboBox;
    dtpDate: TDateTimePicker;
    dtpDate1: TDateTimePicker;
    dtpDate2: TDateTimePicker;
    procedure bbtnFindClick(Sender: TObject);
    procedure cbbWhereChange(Sender: TObject);
  private
    { Private declarations }
    Ffield:string;
    Fwhere:string;
    FDate:string;
  public
    { Public declarations }
  end;

 procedure FindDataWhereDate(aCaption,aField:string;var aWhere,aDate:string);

implementation

{$R *.dfm}
procedure FindDataWhereDate(aCaption,aField:string;var aWhere,aDate:string);
var
  findOfDateForm: TfindOfDateForm;
begin
  findOfDateForm:=TfindOfDateForm.Create(nil);
  try
    findOfDateForm.Caption:=aCaption;
    findOfDateForm.cbbWhere.ItemIndex:=5;
    findOfDateForm.dtpDate1.Date:=now;
    findOfDateForm.dtpDate2.Date:=now;
    findOfDateForm.dtpDate.Date:=now;
    findOfDateForm.dtpDate1.Visible:=false;
    findOfDateForm.dtpDate2.Visible:=false;
    findOfDateForm.dtpDate.Visible:=true;
    findOfDateForm.cbbField.Enabled:=false;
    findOfDateForm.FDate:=DateTostr(now);
    if aField='借书日期' then
      begin
       findOfDateForm.cbbField.ItemIndex:=0;
       findOfDateForm.Ffield:='borrow_date';
      end
     else begin
       findOfDateForm.cbbField.ItemIndex:=1;
       findOfDateForm.Ffield:='return_date';
     end;
    if findOfDateForm.ShowModal=mrOK then
       begin
          aWhere:=findOfDateForm.Fwhere;
          aDate:=findOfDateForm.FDate;
       end
     else begin
       aWhere:='';
       aDate:='';
     end;
  finally
    findOfDateForm.Free;
    findOfDateForm:=nil;
  end;
end;

procedure TfindOfDateForm.bbtnFindClick(Sender: TObject);
var
  tmpBistr:string;
begin
  if (cbbWhere.ItemIndex<>0)and(cbbWhere.ItemIndex<>5) then
    begin
      case cbbWhere.ItemIndex of
        1 : tmpBistr:='>';
        2 : tmpBistr:='>=';
        3 : tmpBistr:='<';
        4 : tmpBistr:='<=';
        5 : tmpBistr:='=';
        6 : tmpBistr:='<>';
      end;
     Fwhere:='where '+ffield+tmpBistr+'cast('+'"'+DateTimeTostr(dtpDate.DateTime)+'"'+' as '+'Timestamp)';
     FDate:='日期'+cbbWhere.Items.Strings[cbbWhere.ItemIndex]+DateToStr(dtpDate.Date)+'时';
    end;
  if (cbbWhere.ItemIndex=0)or(cbbWhere.ItemIndex=5) then
    begin
       FDate:='日期为'+DateToStr(dtpDate1.Date)+'时';
       if cbbWhere.ItemIndex=5 then
         begin
           dtpDate1.Date:=dtpDate.Date;
           dtpDate2.Date:=dtpDate.Date;
           FDate:='日期为'+DateToStr(dtpDate.Date)+'时';
         end;
       if dtpDate1.DateTime<dtpDate2.DateTime then
        begin
         //  showmessage(datetimetostr(dtpdate1.DateTime)+'/'+datetimetostr(dtpdate2.DateTime));
          Fwhere:='where ('+'cast('+'"'+DateTimeTostr(dtpDate1.DateTime)+'"'+' as '+'Timestamp)'+'<='+ffield+') and (';
          Fwhere:=Fwhere+'cast('+'"'+DateTimeTostr(dtpDate2.DateTime)+'"'+' as '+'Timestamp)'+'>='+ffield+')';
          if (cbbWhere.ItemIndex=0)and(Datetostr(dtpDate1.Date)<>DateToStr(dtpDate2.Date)) then
              FDate:='日期为'+DateToStr(dtpDate1.Date)+'与'+DateToStr(dtpDate2.Date)+'之间时';
        end
       else begin
          Fwhere:='where ('+'cast('+'"'+DateTimeTostr(dtpDate2.DateTime)+'"'+' as '+'Timestamp)'+'<='+ffield+') and (';
          Fwhere:=Fwhere+'cast('+'"'+DateTimeTostr(dtpDate1.DateTime)+'"'+' as '+'Timestamp)'+'>='+ffield+')';
         if (cbbWhere.ItemIndex=0)and(Datetostr(dtpDate1.Date)<>DateToStr(dtpDate2.Date)) then
              FDate:='日期为'+DateToStr(dtpDate2.Date)+'与'+DateToStr(dtpDate1.Date)+'之间时';
       end;
      end;
      showmessage(FDate);
  ModalResult:=mrOk;
end;

procedure TfindOfDateForm.cbbWhereChange(Sender: TObject);
begin
 if cbbWhere.ItemIndex<>0 then
   begin
     dtpDate1.Visible:=false;
     dtpDate2.Visible:=false;
     dtpDate.Visible:=true;
   end
   else begin
     dtpDate1.Visible:=true;
     dtpDate2.Visible:=true;
     dtpDate.Visible:=false;
   end;
end;

end.

⌨️ 快捷键说明

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