unit U_YFMXlist;

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, cxDropDownEdit, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  RM_e_Xls;

type
  TfrmYFMXlist = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    Label1: TLabel;
    P_CodeName: TEdit;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    P_spec: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxCRTime: TcxGridDBColumn;
    cxMoneyYe: TcxGridDBColumn;
    cxQty: TcxGridDBColumn;
    cxQtyUnit: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2Price: TcxGridDBColumn;
    VMoney: TcxGridDBColumn;
    v2BBMoney: TcxGridDBColumn;
    v2MPRTCodeName: TcxGridDBColumn;
    Label4: TLabel;
    OrdDefNote3: TComboBox;
    v2factoryName: TcxGridDBColumn;
    v2MRPTspec: TcxGridDBColumn;
    v2YFName: TcxGridDBColumn;
    Label5: TLabel;
    factoryName: TEdit;
    ToolButton3: TToolButton;
    RMDBDataSet1: TRMDBDataSet;
    RMGridReport1: TRMGridReport;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column2: TcxGridDBColumn;
    Tv2Column3: TcxGridDBColumn;
    Tv2Column4: TcxGridDBColumn;
    Tv2Column5: TcxGridDBColumn;
    RMXLSExport1: TRMXLSExport;
    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 P_OrderNo_YSK(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure P_CodeNameChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    { Private declarations }

    procedure InitGrid();
  public
    { Public declarations }
    RKFlag, FCYID: string;
  end;

var
  frmYFMXlist: TfrmYFMXlist;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ProductOrderNewList;

{$R *.dfm}

procedure TfrmYFMXlist.InitGrid();
begin
  if trim(factoryName.Text) = '' then
  begin
    application.MessageBox('供应商不能为空，请输入供应商！', '提示信息', MB_ICONERROR);
    exit;
  end;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' exec  P_Qry_Yfk_mx');
      sql.Add(' @begdate=''' + formatdateTime('yyyy-MM-dd', begdate.DateTime) + ''' ');
      sql.Add(',@enddate=''' + formatdateTime('yyyy-MM-dd', enddate.DateTime + 1) + ''' ');
      sql.Add(',@factoryName=' + quotedstr(trim(factoryName.Text)));
//      ShowMessage(SQL.text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmYFMXlist.FormDestroy(Sender: TObject);
begin
  frmYFMXlist := nil;
end;

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

procedure TfrmYFMXlist.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption, Tv2, '财务管理');
  Close;
end;

procedure TfrmYFMXlist.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption, Tv2, '财务管理');
  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := Enddate.DateTime - 30;
//  InitGrid();
end;

procedure TfrmYFMXlist.TBRafreshClick(Sender: TObject);
begin
  begdate.SetFocus;
  InitGrid();
end;

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

procedure TfrmYFMXlist.P_OrderNo_YSK(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmYFMXlist.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv2, ADOQueryMain, self.Caption);
end;

procedure TfrmYFMXlist.P_CodeNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmYFMXlist.FormCreate(Sender: TObject);
begin
  cxGrid2.Align := AlClient;
end;

procedure TfrmYFMXlist.ToolButton3Click(Sender: TObject);
var
  filepath: string;
begin
  RMGridReport1.PreviewButtons := [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbPageSetup, pbExit, pbSaveToXLS, pbExport, pbNavigator];
  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', date());
    RmVariables['begDate'] := FormatDateTime('yyyy-mm-dd', begDate.Date);
    RmVariables['enddate'] := FormatDateTime('yyyy-mm-dd', enddate.Date);
    RMVariables['zdr'] := trim(DName);
    RmVariables['begDate'] := FormatDateTime('yyyy-mm-dd', begDate.Date) + ' 至 ' + FormatDateTime('yyyy-mm-dd', enddate.Date);
    CDS_HZ.First;
    RmVariables['QCNum'] := CDS_HZ.fieldbyname('MoneyYe').AsFloat - CDS_HZ.fieldbyname('Money').AsFloat + CDS_HZ.fieldbyname('BBMoney').AsFloat;
    CDS_HZ.Last;
    RmVariables['endNum'] := CDS_HZ.fieldbyname('MoneyYe').AsString;
    RMGridReport1.LoadFromFile(filepath);
   // RMGridReport1.PrintReport;
    RMGridReport1.ShowReport;

  finally

  end;
end;

end.

