unit U_WorkDeptList_KQJL;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, cxStyles, cxCustomData, cxGraphics, cxFilter,
  cxData, cxDataStorage, cxEdit, DB, cxDBData, cxTextEdit, cxCalendar,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxControls, cxGridCustomView, cxGrid, ADODB, DBClient,
  cxButtonEdit, cxPC, StdCtrls, ExtCtrls;

type
  TFrmWorkDeptList_KQJL = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    ToolButton2: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1LYDate: TcxGridDBColumn;
    v1LYName: TcxGridDBColumn;
    v1LYMoney: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Order_Main: TClientDataSet;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    ADOQueryDel: TADOQuery;
    v1PriceUnit: TcxGridDBColumn;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    cxTabControl1: TcxTabControl;
    procedure TBExportClick(Sender: TObject);
    procedure v1Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
  private
    procedure initGrid();
    procedure SetStatus();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmWorkDeptList_KQJL: TFrmWorkDeptList_KQJL;

implementation

uses U_ZDYHelp,U_RTfun,U_DataLink;

{$R *.dfm}

procedure TFrmWorkDeptList_KQJL.SetStatus();
begin
  
end;

procedure TFrmWorkDeptList_KQJL.initGrid();
begin
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('select * from Worker_Fee_LK ');
    sql.add('where LYDate>='''+formatdatetime('yyyy-MM-dd',BegDate.DateTime)+''' ');
    sql.add('and LYDate<'''+formatdatetime('yyyy-MM-dd',EndDate.DateTime+1)+'''');
    if cxTabControl1.TabIndex=0 then
    begin
      sql.add('and ChkStatus=''0'' ');
    end;
    if cxtabControl1.TabIndex=1 then
    begin
      sql.add('and ChkStatus=''1'' ');
    end;
    open;
  end;
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TFrmWorkDeptList_KQJL.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  TcxGridToExcel('现金管理',cxGrid1);
end;

procedure TFrmWorkDeptList_KQJL.v1Column1PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PriceUnit';
      flagname:='币种';
      if ShowModal=1 then
      begin
        with Order_Main do
        begin
          edit;
          fieldbyname('PriceUnit').AsString:=trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmWorkDeptList_KQJL.TBRafreshClick(Sender: TObject);
begin
  initGrid();
end;

procedure TFrmWorkDeptList_KQJL.ToolButton2Click(Sender: TObject);
begin
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TFrmWorkDeptList_KQJL.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  initGrid();
end;

procedure TFrmWorkDeptList_KQJL.FormShow(Sender: TObject);
begin
  ReadCxGrid('领用报销金',Tv1,'费用管理');
  endDate.Date:=SGetServerDate(ADOQueryDel);
  BegDate.Date:=EndDate.Date-15;
  cxGrid1.Align:=alClient;
  SetStatus();
  InitGrid();
end;

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

procedure TFrmWorkDeptList_KQJL.FormDestroy(Sender: TObject);
begin
  FrmWorkDeptList_XJGL:=nil;
end;

procedure TFrmWorkDeptList_KQJL.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('领用报销金',TV1,'费用报销管理');
  Close;
end;

end.
