unit U_ReceivableValueSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, ToolWin, ComCtrls, U_BaseHelp, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls,
  cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu,
  System.ImageList, U_BaseInput, cxButtonEdit, cxDropDownEdit, cxCheckBox,
  Vcl.Menus, dxScrollbarAnnotations, FrameDateSel, cxContainer, cxCalendar,
  dxSkinsCore, dxSkinsDefaultPainters;

type
  TfrmReceivableValueSel = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    ADOConnection1: TADOConnection;
    Panel1: TPanel;
    GPM_1: TcxGridPopupMenu;
    ImageList1: TImageList;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    SHuangSeCu: TcxStyle;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    frmFrameDateSel1: TfrmFrameDateSel;
    ToolButton2: TToolButton;
    Label3: TLabel;
    Label4: TLabel;
    Label6: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label2: TLabel;
    OppCoName: TcxTextEdit;
    F_Name: TcxTextEdit;
    F_Code: TcxTextEdit;
    ConNo: TcxTextEdit;
    BuyConNo: TcxTextEdit;
    OppParentCoName: TcxTextEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    Tv1Column22: TcxGridDBColumn;
    v2CRTime: TcxGridDBColumn;
    Tv1Column23: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2FactoryName: TcxGridDBColumn;
    v2OrderNo: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column19: TcxGridDBColumn;
    Tv1Column24: TcxGridDBColumn;
    Tv1Column20: TcxGridDBColumn;
    Tv1Column21: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column28: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column29: TcxGridDBColumn;
    Tv1Column30: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column31: TcxGridDBColumn;
    Tv1Column27: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column39: TcxGridDBColumn;
    Tv1Column37: TcxGridDBColumn;
    Tv1Column38: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    Tv1Column17: TcxGridDBColumn;
    Tv1Column18: TcxGridDBColumn;
    Tv1Column25: TcxGridDBColumn;
    Tv1Column26: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column32: TcxGridDBColumn;
    Tv1Column34: TcxGridDBColumn;
    Tv1Column33: TcxGridDBColumn;
    Tv1Column36: TcxGridDBColumn;
    Tv1Column35: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TV1DblClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FCoType, FAuthority, FConNo, FC_Code: string;
    { Public declarations }
  end;

var
  frmReceivableValueSel: TfrmReceivableValueSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmReceivableValueSel.FormCreate(Sender: TObject);
begin
  inherited;
  try
    with ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      Connected := true;
    end;
    ADOQueryBaseCmd.Connection := ADOConnection1;
    ADOQueryBaseTemp.Connection := ADOConnection1;
  except
    application.MessageBox('网络连接失败！', '提示信息');
  end;
end;

procedure TfrmReceivableValueSel.ConNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmReceivableValueSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin

//  BuyName.SetFocus;

  Action := cahide;
end;

procedure TfrmReceivableValueSel.InitGrid();
var
  Msql, mbegdate, menddate: string;
  SqlStr: string;
begin
  SqlStr := '  select A.*  ';
  SqlStr := SqlStr + ',FJFlag=CAST((CASE WHEN (SELECT COUNT(X.FileName) FROM FJ_File X where X.TFType=''财务流水'' and X.WBID=A.FFID)>0 THEN 1 ELSE 0 END) AS BIT)';
  SqlStr := SqlStr + ',ConDate=(select top 1 ConDate from Bs_Contract_Main X where X.ConNo=A.ConNo)';
  SqlStr := SqlStr + ',DlyNote=(select top 1 DlyNote from Bs_Contract_Main X where X.ConNo=A.ConNo)';
  SqlStr := SqlStr + ' from Finance_Flow A ';
  SqlStr := SqlStr + ' left join Bs_Company B on A.OppCoNo=B.CoCode ';
  SqlStr := SqlStr + ' where A.FFType=''应收款登记''  ';
  SqlStr := SqlStr + ' and A.FFTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.BegDate.Date)) + '''';
  SqlStr := SqlStr + ' and A.FFTime<''' + Trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.enddate.Date + 1)) + '''';
  SqlStr := SqlStr + ' and isnull(A.status,''0'')=''9'' ';

  if FAuthority = '低权限' then
    SqlStr := SqlStr + ' and CHARINDEX(' + quotedstr(DCode) + ',(ISNULL(B.SalesId, '''') +'',''+ISNULL(B.TallyId, '''')+'',''+ISNULL(A.FillId, '''') )  ) > 0 ';

  InitCDSData(ADOQueryMain, CDS_1, Tv1, SqlStr, SGetFilters(Panel1, 1, 2), 'FFID');
end;

procedure TfrmReceivableValueSel.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_1, True);

end;

procedure TfrmReceivableValueSel.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_1, False);
end;

procedure TfrmReceivableValueSel.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(Trim(self.Caption), TV1, '自定义数据');
  frmFrameDateSel1.Enddate.Date := SGetServerDate(ADOQueryTemp);
  frmFrameDateSel1.begdate.Date := frmFrameDateSel1.Enddate.Date - 30;
  InitGrid();
end;

procedure TfrmReceivableValueSel.TBCloseClick(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TfrmReceivableValueSel.TBSaveClick(Sender: TObject);
begin
  WriteCxGrid(Trim(self.Caption), TV1, '自定义数据');

end;

procedure TfrmReceivableValueSel.ToolButton1Click(Sender: TObject);
begin
//  BuyName.SetFocus;
  ModalResult := 1;
end;

procedure TfrmReceivableValueSel.ToolButton2Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmReceivableValueSel.TV1DblClick(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmReceivableValueSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmReceivableValueSel := nil;
end;

end.

