unit U_CP_CRC;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ADODB, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, StdCtrls, ComCtrls, ExtCtrls, ToolWin, DBClient,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Common, RM_Class, RM_e_Xls,
  RM_GridReport, RM_System, RM_Dataset, cxCheckBox, cxCalendar,
  cxGridBandedTableView, cxGridDBBandedTableView, Buttons;

type
  TfrmCP_CRC = class(TForm)
    ToolBar1: TToolBar;
    Tqry: TToolButton;
    Tprint: TToolButton;
    Txls: TToolButton;
    tclose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    begdate: TDateTimePicker;
    enddate: TDateTimePicker;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    Panetime: TPanel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    RMDBDataSet1: TRMDBDataSet;
    RMGridReport1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    Label7: TLabel;
    userID: TEdit;
    Label8: TLabel;
    userName: TEdit;
    Label3: TLabel;
    ComboBox1: TComboBox;
    begTime: TDateTimePicker;
    endTime: TDateTimePicker;
    Label2: TLabel;
    Label4: TLabel;
    dept: TComboBox;
    TV1: TcxGridDBBandedTableView;
    V1Column2: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    V1Column6: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    V1Column10: TcxGridDBBandedColumn;
    V1Column11: TcxGridDBBandedColumn;
    V1Column12: TcxGridDBBandedColumn;
    V1Column13: TcxGridDBBandedColumn;
    Label5: TLabel;
    Label6: TLabel;
    Label9: TLabel;
    C_Color: TEdit;
    C_CodeName: TEdit;
    V1Column1: TcxGridDBBandedColumn;
    BCKZ1: TEdit;
    Label10: TLabel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TqryClick(Sender: TObject);
    procedure TxlsClick(Sender: TObject);
    procedure tcloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TprintClick(Sender: TObject);
    procedure userIDChange(Sender: TObject);
  private
    fstr1:string;
    fstr2:string;
    procedure DoQuery();
    procedure FilterData();
    { Private declarations }
  public
    istyjp:boolean;
    fdept:string;
    { Public declarations }
  end;

var
  frmCP_CRC: TfrmCP_CRC;

implementation
uses U_Fun10,U_DataLink;
{$R *.dfm}


procedure TfrmCP_CRC.DoQuery();
var
  mBegdate,mEnddate:string;
  i:integer;
begin
  mbegdate:=FormatDateTime('yyyy-MM-dd',begdate.Date);//+' '+FormatDateTime('HH:nn',begTime.Time);
  menddate:=FormatDateTime('yyyy-MM-dd',enddate.Date+1);//+' '+FormatDateTime('HH:nn',endTime.Time);
  screen.Cursor:=crsqlwait;
  Panetime.Visible:=true;
  Panetime.Left:=(Width-Panetime.Width) div 2;
  Panetime.top:=(Height-Panetime.Height-200) div 2;
  application.ProcessMessages;

  try
    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      filtered:=false;
      sql.Add(' exec P_Get_CP_CRC ');
      sql.Add(' @begdate='+quotedstr(trim(mbegdate)));
      sql.Add(',@Enddate='+quotedstr(trim(menddate)));
      sql.Add(',@otherwhere='+quotedstr(trim('')));
      open;
    end;
    FilterData();
  finally
    Panetime.Visible:=false;
    screen.Cursor:=crdefault;
  end;
end;
procedure TfrmCP_CRC.FilterData();
var
  filterStr:string;
begin
 if ADOQueryTmp.Active=False then Exit;
  SDofilter(ADOQueryTmp,SGetFilters(Panel1,1,2));
end;
procedure TfrmCP_CRC.FormDestroy(Sender: TObject);
begin
  frmCP_CRC:=nil;
end;

procedure TfrmCP_CRC.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  writeCxBandedGrid(self.Caption+tv1.Name,tv1,'综合查询');
  action:=cafree;
end;

procedure TfrmCP_CRC.TqryClick(Sender: TObject);
begin
  DoQuery();
end;

procedure TfrmCP_CRC.TxlsClick(Sender: TObject);
begin
  if adoquerytmp.IsEmpty then exit;
  TcxGridToExcel(self.Caption,cxgrid1);
end;

procedure TfrmCP_CRC.tcloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmCP_CRC.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alClient;
  enddate.Date:=date();
  begdate.Date:=date();

end;

procedure TfrmCP_CRC.FormShow(Sender: TObject);
begin
  readCxBandedGrid(self.Caption+tv1.Name,tv1,'综合查询');
  DoQuery();
end;

procedure TfrmCP_CRC.TprintClick(Sender: TObject);
var
  filepath:string;
  mBegdate,mEnddate:string;
begin
  mbegdate:=FormatDateTime('yyyy-MM-dd',begdate.Date)+' '+FormatDateTime('HH:nn',begTime.Time);
  menddate:=FormatDateTime('yyyy-MM-dd',enddate.Date)+' '+FormatDateTime('HH:nn',endTime.Time);
  if ADOQueryTmp.IsEmpty then exit;
  try
    filepath:=ExtractFilePath(Application.ExeName) + 'report\机修工考核表.rmf';
    if not FileExists(Pchar(filepath))  then
    begin
      application.MessageBox(pchar('文件['+filepath+']不存在！'),'提示信息',MB_IConError);
      exit;
    end;
    RMVariables.Clear;
    RMVariables['dtxz'] :=FormatDateTime('yyyy-mm-dd',DServerDate);
    RmVariables['begDate'] :=FormatDateTime('yyyy-mm-dd',begDate.Date);
    RmVariables['enddate'] :=FormatDateTime('yyyy-mm-dd',enddate.Date);
    RMVariables['zdr'] :=trim(DName);
    RMVariables['fstr1'] :=trim(fstr1);
    RMVariables['fstr2'] :=trim(fstr2);
    RmVariables['begDate'] :=mbegdate+' - '+menddate;
    RmVariables['Title'] :=trim(dept.Text);
    RMGridReport1.LoadFromFile(filepath);
   // RMGridReport1.PrintReport;
    RMGridReport1.ShowReport;

  finally

  end;

end;

procedure TfrmCP_CRC.userIDChange(Sender: TObject);
begin
  FilterData();
end;

end.
