unit U_WorkDeptFeeChkList_DC;

interface

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

type
  TfrmWorkDeptFeeChkList_DC = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    Order_Sub: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column2: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    v1JieCunMoney: TcxGridDBColumn;
    ToolButton2: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    CDS_Chker: TClientDataSet;
    v1YuJieMoney: TcxGridDBColumn;
    DataSource2: TDataSource;
    v1YCLName: TcxGridDBColumn;
    TSel: TToolButton;
    CDS_PRT: TClientDataSet;
    v1WFDate: TcxGridDBColumn;
    ADOQueryHZ: TADOQuery;
    v1Worker: TcxGridDBColumn;
    Label3: TLabel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TSelClick(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    FInt,PFInt:Integer;
    canshu1,canshu2:string;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmWorkDeptFeeChkList_DC: TfrmWorkDeptFeeChkList_DC;

implementation
uses
  U_DataLink,U_RTFun,U_ModuleNote,U_WorkerDeptFeeInPut, U_ZDYHelpSel;

{$R *.dfm}

procedure TfrmWorkDeptFeeChkList_DC.FormDestroy(Sender: TObject);
begin
  frmWorkDeptFeeChkList_DC:=nil;
end;

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

procedure TfrmWorkDeptFeeChkList_DC.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('费用报销结存查询',Tv1,'费用管理');
end;

procedure TfrmWorkDeptFeeChkList_DC.InitGrid();
var FJieCunMoney: Double;
    Fint: integer;
begin
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('exec P_Select_CWTJ ');
    sql.add('@Status=''1'', ');
    sql.add('@begdate='''+formatdatetime('yyyy-MM-dd',Begdate.DateTime)+'''');
    sql.add(',@Enddate='''+formatdatetime('yyyy-MM-dd',Enddate.DateTime+1)+'''');
    open;
  end;
  SCreateCDS20(ADOQueryCmd,Order_Main);
  SInitCDSData20(ADOQueryCmd,Order_Main);
  FJieCunMoney:=Order_Main.fieldbyname('JieCunMoney').AsFloat;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('exec P_Select_CWTJ ');
      sql.add('@Status=''2'', ');
      sql.add('@begdate='''+formatdatetime('yyyy-MM-dd',Begdate.DateTime)+'''');
      sql.add(',@Enddate='''+formatdatetime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Chker);
    SInitCDSData20(ADOQueryMain,CDS_Chker);
    with CDS_Chker do
    begin
      first;
      while not eof do
      begin
        Order_Main.append;
        Order_Main.fieldbyname('WFDate').AsDateTime:=fieldbyname('WFDate').AsDateTime;
        Order_Main.fieldbyname('YCLName').Value:=trim(fieldbyname('YCLName').AsString);
        Order_Main.fieldbyname('Worker').Value:=trim(fieldbyname('Worker').AsString);
        Order_Main.fieldbyname('LYMoney').Value:=fieldbyname('LYMoney').AsFloat;
        Order_Main.fieldbyname('YuJieMoney').Value:=fieldbyname('YuJieMoney').AsFloat;
        FJieCunMoney:=FJieCunMoney+fieldbyname('LYMoney').AsFloat-fieldbyname('YuJieMoney').AsFloat;
        Order_Main.fieldbyname('JieCunMoney').AsFloat:=FJieCunMoney;
        Order_Main.post;
        next;
      end;
    end;
  finally;
    ADOQueryMain.EnableControls;
  end; 
end;

procedure TfrmWorkDeptFeeChkList_DC.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  TcxGridToExcel('费用报销单',cxGrid1);
end;

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

procedure TfrmWorkDeptFeeChkList_DC.FormShow(Sender: TObject);
begin
  ReadCxGrid('费用报销结存查询',Tv1,'费用管理');
  endDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  InitGrid();
end;

procedure TfrmWorkDeptFeeChkList_DC.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
end;

procedure TfrmWorkDeptFeeChkList_DC.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryCmd,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryCmd,Order_Main);
  SInitCDSData20(ADOQueryCmd,Order_Main);
end;

procedure TfrmWorkDeptFeeChkList_DC.TSelClick(Sender: TObject);
begin
  {try
    frmWorkerDeptFeeInPut:=TfrmWorkerDeptFeeInPut.Create(Application);
    with frmWorkerDeptFeeInPut do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('WFID').AsString);
      TBSave.Visible:=False;
      ToolBar2.Visible:=False;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmWorkerDeptFeeInPut.Free;
  end;}
end;

procedure TfrmWorkDeptFeeChkList_DC.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  Tsel.Click;
end;

end.
