unit U_YFHZ_EMX;

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, cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore, 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, dxSkinsDefaultPainters,
  dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue,
  dxSkinscxPCPainter, cxNavigator;

type
  TfrmYFHZ_EMX = 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;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label1: TLabel;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Qty: TcxGridDBColumn;
    v2Price: TcxGridDBColumn;
    v2yfk: TcxGridDBColumn;
    v2fk: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    v2yfkye: TcxGridDBColumn;
    v2YFName: TcxGridDBColumn;
    Label5: TLabel;
    YFName: TEdit;
    Label7: TLabel;
    FKTaitou: TEdit;
    FactoryName: TComboBox;
    Label6: TLabel;
    P_Codename: TEdit;
    v2KPType: TcxGridDBColumn;
    v2PayMent: TcxGridDBColumn;
    Label4: TLabel;
    KPType: TEdit;
    Label8: TLabel;
    PayMent: TEdit;
    v2FKNo: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column2: TcxGridDBColumn;
    Tv2Column3: TcxGridDBColumn;
    TCK: TToolButton;
    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 FormCreate(Sender: TObject);
    procedure TCKClick(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
  private
    { Private declarations }
    procedure InitGrid();
  public
    { Public declarations }
    RKFlag, FCYID, FSQType, Fyear: string;
  end;

var
  frmYFHZ_EMX: TfrmYFHZ_EMX;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_YFHZ_MX;

{$R *.dfm}

procedure TfrmYFHZ_EMX.InitGrid();
var
  FMoney: double;
  i: Integer;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_FK_HZ_M_E  @year=''' + Trim(Fyear) + '''');
      sql.Add(',@SQType=''' + FSQType + '''');
//      ShowMessage(SQL.text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);

  finally
    ADOQueryMain.EnableControls;

  end;
end;

procedure TfrmYFHZ_EMX.FormDestroy(Sender: TObject);
begin
  frmYFHZ_EMX := nil;
end;

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

procedure TfrmYFHZ_EMX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption, Tv2, '二级费用明细');
  Close;
end;

procedure TfrmYFHZ_EMX.FormShow(Sender: TObject);
var
  fsj: string;
begin
  ReadCxGrid(self.Caption, Tv2, '二级费用明细');
  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := Enddate.DateTime - 7;
//  fsj:='select distinct (A.FactoryName) name from YF_Money_CR A where A.CRType=''应付款登记'' ';
//  SInitComBoxBySql(ADOQueryCmd,FactoryName,False,fsj);
  InitGrid();
end;

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

procedure TfrmYFHZ_EMX.ToolButton2Click(Sender: TObject);
begin
//  initgrid();
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, CDS_HZ);
  SInitCDSData20(ADOQueryMain, CDS_HZ);
end;

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

procedure TfrmYFHZ_EMX.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid2);
//  SelExportData(Tv2,ADOQueryMain,'应付款付款统计列表');
end;

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

procedure TfrmYFHZ_EMX.TCKClick(Sender: TObject);
begin
  frmYFHZ_MX := TfrmYFHZ_MX.Create(self);
  with frmYFHZ_MX do
  begin
    Fyear := Trim(FormatDateTime('yyyy', self.BegDate.Date));
    FSQType := Trim(Self.CDS_HZ.fieldbyname('SQType').AsString);
    if ShowModal = 1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmYFHZ_EMX.Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  TCK.Click;
end;

end.

