unit U_BJGCl;

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, cxCurrencyEdit;

type
  TfrmBJGCl = 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;
    V1FillTime: TcxGridDBBandedColumn;
    V1Column2: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    V1Column4: TcxGridDBBandedColumn;
    V1Column1: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    V1Column10: TcxGridDBBandedColumn;
    V1Column11: TcxGridDBBandedColumn;
    V1Column12: TcxGridDBBandedColumn;
    V1Column17: TcxGridDBBandedColumn;
    V1Column18: TcxGridDBBandedColumn;
    V1Column19: TcxGridDBBandedColumn;
    V1Column20: TcxGridDBBandedColumn;
    V1Column33: TcxGridDBBandedColumn;
    V1Column34: TcxGridDBBandedColumn;
    V1Column35: TcxGridDBBandedColumn;
    V1Column36: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    V1MachType: TcxGridDBBandedColumn;
    V1MachOrder: TcxGridDBBandedColumn;
    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);
    procedure V1Column2CompareRowValuesForCellMerging(
      Sender: TcxGridColumn; ARow1: TcxGridDataRow;
      AProperties1: TcxCustomEditProperties; const AValue1: Variant;
      ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties;
      const AValue2: Variant; var AAreEqual: Boolean);
  private
    fstr1:string;
    fstr2:string;
    procedure DoQuery();
    procedure FilterData();
    { Private declarations }
  public
    istyjp:boolean;
    fdept:string;
    { Public declarations }
  end;

var
  frmBJGCl: TfrmBJGCl;

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


procedure TfrmBJGCl.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)+' '+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_BJGCl ');
      sql.Add(' @begdate='+quotedstr(trim(mbegdate)));
      sql.Add(',@Enddate='+quotedstr(trim(menddate)));
      sql.Add(',@dept='+quotedstr(trim('')));
      sql.Add(',@otherwhere='+quotedstr(trim('')));
      open;
    end;
    FilterData();
  finally
    Panetime.Visible:=false;
    screen.Cursor:=crdefault;
  end;
end;
procedure TfrmBJGCl.FilterData();
var
  filterStr:string;
begin
  filterStr:='';
  if trim(dept.Text)<>'' then
  filterStr:=filterStr+' and dept like '+quotedstr('%'+trim(dept.Text)+'%');
  if trim(userID.Text)<>'' then
  filterStr:=filterStr+' and userID like '+quotedstr('%'+trim(userID.Text)+'%');
  if trim(userName.Text)<>'' then
  filterStr:=filterStr+' and UserName like '+quotedstr('%'+trim(userName.Text)+'%');
  try
    ADOQueryTmp.DisableControls ;
    if trim(filterStr)='' then
    begin
      ADOQueryTmp.Filtered:=false;
      ADOQueryTmp.EnableControls;
      exit;
   end;
    filterStr:=trim(Copy(filterStr,5,length(filterStr)-4));
    with ADOQueryTmp do
    begin
      filtered:=false;
      filter:=filterStr;
      filtered:=true;
    end;
   finally
    ADOQueryTmp.EnableControls;
  end;
end;
procedure TfrmBJGCl.FormDestroy(Sender: TObject);
begin
  frmBJGCl:=nil;
end;

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

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

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

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

procedure TfrmBJGCl.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alClient;
  enddate.Date:=DServerDate;
  begdate.Date:=strtodate(formatdateTime('yyyy-MM',enddate.Date)+'-01');
 
end;

procedure TfrmBJGCl.FormShow(Sender: TObject);
begin
 writeCxBandedGrid(self.Caption+tv1.Name,tv1,'综合查询');
//  Tqry.Click;


end;

procedure TfrmBJGCl.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['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['dept'] :=trim(dept.Text);
    RMGridReport1.LoadFromFile(filepath);
   // RMGridReport1.PrintReport;
    RMGridReport1.ShowReport;

  finally

  end;

end;

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

procedure TfrmBJGCl.V1Column2CompareRowValuesForCellMerging(
  Sender: TcxGridColumn; ARow1: TcxGridDataRow;
  AProperties1: TcxCustomEditProperties; const AValue1: Variant;
  ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties;
  const AValue2: Variant; var AAreEqual: Boolean);
var
  i:integer;
begin
  i:=tv1.GetColumnByFieldName('MachOrder').Index;
  if ARow1.Values[i] = ARow2.Values[i] then
    AAreEqual := True
  else
    AAreEqual := False;


end;

end.
