unit U_CPXSTJList;

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

type
  TfrmCPXSTJList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label2: TLabel;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DSKH: TDataSource;
    Label1: TLabel;
    ComTaiTou: TEdit;
    ToolButton4: TToolButton;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    cxTabSheet3: TcxTabSheet;
    cxTabSheet4: TcxTabSheet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column6: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBTableView;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    CDSKH: TClientDataSet;
    CDSCP: TClientDataSet;
    DSCP: TDataSource;
    CDSTH: TClientDataSet;
    DSTH: TDataSource;
    CDSPJ: TClientDataSet;
    DSPJ: TDataSource;
    ADOQueryPrint: TADOQuery;
    V3Column1: TcxGridDBColumn;
    begdate: TDateTimePicker;
    Label3: TLabel;
    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 FactoryNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fmanage:string;
    { Public declarations }
    RKFlag,FCYID:String;

  end;

var
  frmCPXSTJList: TfrmCPXSTJList;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp, U_YSMXlist;

{$R *.dfm}



procedure TfrmCPXSTJList.InitGrid();
begin
  case cxPageControl1.ActivePageIndex of
  0:begin
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        SQL.Clear;
        sql.Add(' P_View_SxHzCtm'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)))) ;
        sql.Add(' ,'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime)))) ;
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDSKH);
      SInitCDSData20(ADOQueryMain,CDSKH);
    end;
  1:begin
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        SQL.Clear;
        sql.Add(' P_View_SxHzCP'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)))) ;
        sql.Add(' ,'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime)))) ;
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDSCP);
      SInitCDSData20(ADOQueryMain,CDSCP);
    end;
  2:begin
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        SQL.Clear;
        sql.Add(' P_View_SxHzTH'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)))) ;
        sql.Add(' ,'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime)))) ;
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDSTH);
      SInitCDSData20(ADOQueryMain,CDSTH);
    end;
  3:begin
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        SQL.Clear;
        sql.Add(' P_View_SxHzPJ'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)))) ;
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDSPJ);
      SInitCDSData20(ADOQueryMain,CDSPJ);
    end;
  end;

end;


procedure TfrmCPXSTJList.FormDestroy(Sender: TObject);
begin
  frmCPXSTJList:=nil;
end;

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

procedure TfrmCPXSTJList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption),Tv2,'财务管理');
  Close;
end;
procedure TfrmCPXSTJList.FormShow(Sender: TObject);
begin
  ReadCxGrid(trim(self.Caption),Tv2,'财务管理');
  begdate.DateTime:=StartOfTheMonth(Now);//SGetServerDate(ADOQueryTemp);
  Enddate.DateTime:= EndOfTheMonth(Now);
  InitGrid();
end;

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

procedure TfrmCPXSTJList.ToolButton2Click(Sender: TObject);
var
  fsj:string;
begin
//  if ADOQueryMain.Active=False then Exit;
//
//  SDofilter(ADOQueryMain,Trim(SGetFilters(Panel1,1,2)));
//  SCreateCDS20(ADOQueryMain,CDS_HZ);
//  SInitCDSData20(ADOQueryMain,CDS_HZ);
end;

procedure TfrmCPXSTJList.FactoryNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmCPXSTJList.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv2,ADOQueryMain,'统计列表');
end;

procedure TfrmCPXSTJList.ToolButton4Click(Sender: TObject);
var
  filepath:string;
  mBegdate,mEnddate:string;
begin

  case cxPageControl1.ActivePageIndex of
  0:begin
      with ADOQueryPrint do
      begin
        Filtered:=False;
        Close;
        SQL.Clear;
        sql.Add(' P_View_SxHzCtm'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)))) ;
         sql.Add(' ,'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime)))) ;
        Open;
      end;
      filepath:=ExtractFilePath(Application.ExeName) + 'report\客户汇总.rmf';
    end;
  1:begin
      with ADOQueryPrint do
      begin
        Filtered:=False;
        Close;
        SQL.Clear;
        sql.Add(' P_View_SxHzCP'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)))) ;
         sql.Add(' ,'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime)))) ;
        Open;
      end;
      filepath:=ExtractFilePath(Application.ExeName) + 'report\产品汇总.rmf';
    end;
  2:begin
      with ADOQueryPrint do
      begin
        Filtered:=False;
        Close;
        SQL.Clear;
        sql.Add(' P_View_SxHzTH'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)))) ;
         sql.Add(' ,'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime)))) ;
        Open;
      end;
      filepath:=ExtractFilePath(Application.ExeName) + 'report\提花汇总.rmf';
    end;
  3:begin
      with ADOQueryPrint do                                 
      begin
        Filtered:=False;
        Close;
        SQL.Clear;
        sql.Add(' P_View_SxHzPJ'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)))) ;
         sql.Add(' ,'+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime)))) ;
        Open;
      end;
      filepath:=ExtractFilePath(Application.ExeName) + 'report\平机汇总.rmf';
    end;
  end;


  if not FileExists(Pchar(filepath))  then
  begin
    application.MessageBox(pchar('文件['+filepath+']不存在！'),'提示信息',MB_IConError);
    exit;
  end;

  try
    RmVariables['enddate'] :=FormatDateTime('yyyy-mm-dd',enddate.Date);
    RMVariables['ZDR'] :=trim(DName);
    RM1.LoadFromFile(filepath);
    RM1.ShowReport;
  finally

  end;

end;

procedure TfrmCPXSTJList.cxPageControl1Change(Sender: TObject);
begin
  InitGrid();
end;

end.
