unit U_KhGzMX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin,
  StdCtrls, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP,ShellAPI,IniFiles, cxCheckBox, cxCalendar,
  cxButtonEdit, cxTextEdit, cxPC, cxCheckComboBox, cxDropDownEdit, Menus,
  RM_e_Xls;

type
  TfrmKhGzMX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2Note: TcxGridDBColumn;
    v2C_CodeName: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2OrderNO: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    v2Column19: TcxGridDBColumn;
    Panel1: TPanel;
    Label3: TLabel;
    Label2: TLabel;
    Label6: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Customer: TEdit;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    OrderNO: TEdit;
    CPCode: TEdit;
    CDS_PRT: TClientDataSet;
    RMXLSExport2: TRMXLSExport;
    RMDBMain: TRMDBDataSet;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    Label1: TLabel;
    Label7: TLabel;
    Dept: TEdit;
    Name: TEdit;
    v2Column14: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure DeptChange(Sender: TObject);
  private
    { Private declarations }

    procedure InitGrid();
  public
    fFlag:integer;
    { Public declarations }
    RKFlag,FCYID,fmanage:String;

  end;

var
  frmKhGzMX: TfrmKhGzMX;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp,
   U_ZdyAttachGYS, U_ProductOrderListSel, U_ProductOrderNewList,
  U_ZdyAttachment;

{$R *.dfm}


procedure TfrmKhGzMX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      Filtered:=False;
      sql.Add(' exec P_View_KHHZ '
      +quotedstr(Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime)))
      +','+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)))
      +','+quotedstr('明细')
      );
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
    ToolButton2.Click;
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
  end;
end;

procedure TfrmKhGzMX.FormDestroy(Sender: TObject);
begin
  frmKhGzMX:=nil;
end;

procedure TfrmKhGzMX.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=caFree;
end;

procedure TfrmKhGzMX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Trim(Self.Caption),Tv2,'临时工作管理');
  Close;
end;
procedure TfrmKhGzMX.FormShow(Sender: TObject);
begin
  ReadCxGrid(Trim(Self.Caption),Tv2,'临时工作管理');
//  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
//  begdate.DateTime:=Enddate.DateTime-30;
  InitGrid();
end;

procedure TfrmKhGzMX.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmKhGzMX.ToolButton2Click(Sender: TObject);
var
  sql:string;
begin
  if ADOQueryMain.Active then
  begin
    sql:=SGetFilters(Panel1,1,2);
    SDofilter(ADOQueryMain,sql);
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  end;
end;

procedure TfrmKhGzMX.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv2,ADOQueryMain,'考核明细列表');
end;

procedure TfrmKhGzMX.DeptChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

end.
