unit U_YSSKList;

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

type
  TfrmYSSKList = 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;
    Label3: TLabel;
    FactoryName: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    Label1: TLabel;
    ComTaiTou: TEdit;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ADOQueryPrint: TADOQuery;
    v2Column11: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    Label4: TLabel;
    Salesman: TEdit;
    cxTabControl1: TcxTabControl;
    v2Column10: TcxGridDBColumn;
    Label5: TLabel;
    ishs: TComboBox;
    v2Column16: TcxGridDBColumn;
    ToolButton5: TToolButton;
    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 ToolButton5Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fmanage: string;
    { Public declarations }
    RKFlag, FCYID: string;
  end;

var
  frmYSSKList: TfrmYSSKList;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_YSMXlist, U_YSCRMXList;

{$R *.dfm}

procedure TfrmYSSKList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' exec P_YSSK_List  ');
      sql.Add(' @begdate=' + quotedstr(Trim(FormatDateTime('yyyy-MM-dd', begdate.DateTime))));
      sql.Add(',@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 TfrmYSSKList.FormDestroy(Sender: TObject);
begin
  frmYSSKList := nil;
end;

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

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

procedure TfrmYSSKList.FormShow(Sender: TObject);
var
  fsj: string;
begin
  ReadCxGrid(trim(self.Caption), Tv2, '财务管理');
  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := Enddate.DateTime;
//  fsj := 'select distinct(YFGSType) name from YF_Monesy_CR where CRType=''应收款登记'' ';
//  SInitComBoxBySql(ADOQueryCmd, YFGSType, False, fsj);
  InitGrid();
end;

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

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

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

procedure TfrmYSSKList.ToolButton3Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  frmYSMXlist := TfrmYSMXlist.Create(self);
  with frmYSMXlist do
  begin

    begdate.DateTime := self.begdate.DateTime;
    enddate.DateTime := self.Enddate.DateTime;
    factoryName.Text := self.CDS_HZ.fieldbyname('factoryName').AsString;
//    ishs.ItemIndex := ishs.Items.IndexOf(trim(self.CDS_HZ.fieldbyname('ishs').AsString));
    cxTabControl1.TabIndex := self.cxTabControl1.TabIndex;

    show;
  end;
end;

procedure TfrmYSSKList.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 TfrmYSSKList.Tv2DblClick(Sender: TObject);
begin
  ToolButton3.Click;
end;

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

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

procedure TfrmYSSKList.ToolButton5Click(Sender: TObject);
begin

  if CDS_HZ.IsEmpty then
    exit;
  frmYSCRMXList := TfrmYSCRMXList.Create(self);
  with frmYSCRMXList do
  begin

    begdate.DateTime := self.begdate.DateTime;
    enddate.DateTime := self.Enddate.DateTime;
    FactoryNameSel.Text := self.CDS_HZ.fieldbyname('factoryName').AsString;
    cxTabControl1.TabIndex := self.cxTabControl1.TabIndex + 1;
    show;
  end;
end;

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

end;

end.

