unit U_FPINVOICE_TJ;

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;

type
  TfrmFPInvoice_TJ = 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;
    ToFactoryName: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    VBBMoney: TcxGridDBColumn;
    v2FPMoney: TcxGridDBColumn;
    v2WFPMoney: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    cxStyle_fontBlack: TcxStyle;
    cxStyle_fontclFuchsia: TcxStyle;
    cxStyle_fontclPurple: TcxStyle;
    cxStyle_fontclGreen: TcxStyle;
    cxStyle_fontclBlue: TcxStyle;
    cxStyle_fontclTeal: TcxStyle;
    cxStyle_fontclOlive: TcxStyle;
    Label5: TLabel;
    BBMoney: TEdit;
    Label7: TLabel;
    v2FactoryName: TcxGridDBColumn;
    FactoryName: TEdit;
    FactoryNameTJ: TEdit;
    Label1: TLabel;
    Label4: TLabel;
    ToFactoryNameTJ: TEdit;
    Label8: TLabel;
    Label9: TLabel;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column3: 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 ToFactoryNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv2DblClick(Sender: TObject);
    procedure v2Column3CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
  private
    IsEdit: integer;
    { Private declarations }
    procedure InitGrid();
  public
    { Public declarations }
    RKFlag, FCYID: string;
    fInvoiceFlag: string;
    IsHx: integer;
  end;

var
  frmFPInvoice_TJ: TfrmFPInvoice_TJ;

implementation

uses
  U_DataLink, U_Fun10;

{$R *.dfm}

procedure TfrmFPInvoice_TJ.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add('exec P_get_Jxinvoice ');
      sql.Add('@EndDate=''' + trim(formatdateTime('yyyy-MM-dd', enddate.DateTime + 1)) + '''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmFPInvoice_TJ.FormDestroy(Sender: TObject);
begin
  frmFPInvoice_TJ := nil;
end;

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

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

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

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

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

procedure TfrmFPInvoice_TJ.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid2);
end;

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

end;

procedure TfrmFPInvoice_TJ.v2Column3CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin

  if AViewInfo.GridRecord.Values[tv2.GetColumnByFieldName('QKMoney').index] < 0 then
  begin
    ACanvas.Font.Color := $0000FF;
  end;

end;

end.

