unit U_YFFKList;

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, Clipbrd, cxPC, Menus;

type
  TfrmYFFKList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    FactoryName: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    ADOQueryMain: TADOQuery;
    CDS_HZ: TClientDataSet;
    ToolButton3: TToolButton;
    v2Column4: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    ToolButton4: TToolButton;
    ADOQueryPrint: TADOQuery;
    v2Column8: TcxGridDBColumn;
    Label7: TLabel;
    YFGSType: TComboBox;
    cxTabControl1: TcxTabControl;
    v2Column9: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyleRepository2: TcxStyleRepository;
    cxStyle2: TcxStyle;
    v2Column11: TcxGridDBColumn;
    Label1: TLabel;
    ishs: TComboBox;
    v2Column12: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    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 ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure Tv2DblClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure YFGSTypeChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fDParameters1: string;
    { Public declarations }
    RKFlag, FCYID: string;
  end;

var
  frmYFFKList: TfrmYFFKList;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_YFMXlist;

{$R *.dfm}

procedure TfrmYFFKList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      Filtered := False;
      sql.Add(' exec P_YFFK_List @begdate=' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', begdate.DateTime))) + ',@Enddate=' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', Enddate.DateTime + 1))));
      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(',@flag=''已审核'' ');
          end;
        1:
          begin
            sql.Add(',@flag=''全部'' ');
          end;
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
  //ToolButton2.Click;
end;

procedure TfrmYFFKList.FormDestroy(Sender: TObject);
begin
  frmYFFKList := nil;
end;

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

procedure TfrmYFFKList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('应付付款统计2', Tv2, '财务管理');
  Close;
end;

procedure TfrmYFFKList.FormShow(Sender: TObject);
var
  fsj: string;
begin
  ReadCxGrid('应付付款统计2', Tv2, '财务管理');
  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := Enddate.DateTime;

  fsj := 'select distinct(YFGSType) name from YF_Money_CR where CRType=''应付款登记'' ';
  SInitComBoxBySql(ADOQueryCmd, YFGSType, False, fsj);

  InitGrid();
end;

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

procedure TfrmYFFKList.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 TfrmYFFKList.FactoryNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

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

procedure TfrmYFFKList.ToolButton3Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  frmYFMXlist := TfrmYFMXlist.Create(self);
  with frmYFMXlist do
  begin
    begdate.DateTime := self.begdate.DateTime;
    enddate.DateTime := self.Enddate.DateTime;
    factoryName.Text := self.CDS_HZ.fieldbyname('factoryName').AsString;
//    YFGSType.ItemIndex := YFGSType.Items.IndexOf(trim(self.CDS_HZ.fieldbyname('YFGSType').AsString));
//    ishs.ItemIndex := ishs.Items.IndexOf(trim(self.CDS_HZ.fieldbyname('ishs').AsString));
    cxTabControl1.TabIndex := self.cxTabControl1.TabIndex;
    show;
  end;
end;

procedure TfrmYFFKList.ToolButton4Click(Sender: TObject);
var
  filepath: string;
  mBegdate, mEnddate: string;
begin
  mBegdate := FormatDateTime('yyyy-MM-dd', begdate.Date);
  mEnddate := FormatDateTime('yyyy-MM-dd', enddate.Date);
  if CDS_HZ.IsEmpty then
    exit;
  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    with ADOQueryPrint do
    begin
      Close;
      SQL.Clear;
      Filtered := False;
      sql.Add(' exec P_YFFK_List @begdate=' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', begdate.DateTime))) + ',@Enddate=' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', Enddate.DateTime + 1))) + ',@flag=''已审核''');
      Open;
    end;
    Open;
  end;

  try
    filepath := ExtractFilePath(Application.ExeName) + 'report\应付账款.rmf';
    if not FileExists(Pchar(filepath)) then
    begin
      application.MessageBox(pchar('文件[' + filepath + ']不存在！'), '提示信息', MB_IConError);
      exit;
    end;

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

  end;

end;

procedure TfrmYFFKList.Tv2DblClick(Sender: TObject);
begin
  ToolButton3.Click;
end;

procedure TfrmYFFKList.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmYFFKList.YFGSTypeChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmYFFKList.N1Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_HZ.fieldbyname(TV2.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));

end;

end.

