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, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxBarBuiltInMenu, DateUtils, dxSkinsCore, dxSkinsDefaultPainters,
  dxSkinscxPCPainter, dxSkinBlack, dxSkinBlue, dxSkinBlueprint,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide,
  dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue;

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;
    Label4: TLabel;
    Salesman: TEdit;
    cxTabControl1: TcxTabControl;
    v2Column10: TcxGridDBColumn;
    Label5: TLabel;
    ishs: TComboBox;
    v2Column16: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column2: TcxGridDBColumn;
    Tv2Column6: TcxGridDBColumn;
    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);
  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;

{$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) + '1', Tv2, '财务管理');
  Close;
end;

procedure TfrmYSSKList.FormShow(Sender: TObject);
var
  fsj: string;
begin
  ReadCxGrid(trim(self.Caption) + '1', Tv2, '财务管理');
  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := StartOfTheMonth(Now());
//  fsj := 'select distinct(YFGSType) name from YF_Money_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;
//    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 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_YSSK_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
    ExportFtErpFile('应收账款.rmf', ADOQueryTemp);
    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
  Clipboard.SetTextBuf(PChar(Trim(CDS_HZ.fieldbyname(TV2.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));

end;

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

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

end.

