unit U_YSYFList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView,
  cxGridTableView, cxGridBandedTableView, cxGridDBBandedTableView,
  cxGridLevel, cxClasses, cxControls, cxGridCustomView, cxGridDBTableView,
  cxGrid, StdCtrls, ComCtrls, ExtCtrls, ToolWin, cxGridCustomPopupMenu,
  cxGridPopupMenu, ADODB, DBClient, cxDropDownEdit, MovePanel, cxButtonEdit,
  cxCalendar, cxPC, cxCheckBox, cxTextEdit;

type
  TfrmYSYFList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2ssel: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    v2PayMent: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    VYB: TcxGridDBColumn;
    VBZ: TcxGridDBColumn;
    VHL: TcxGridDBColumn;
    VBB: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    VOrderNo: TcxGridDBColumn;
    v2OrderNO: TcxGridDBColumn;
    v2C_CodeName: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    v2Note: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    v2Column12: TcxGridDBColumn;
    Panel1: TPanel;
    Label5: TLabel;
    Label4: TLabel;
    orderNo: TEdit;
    conNo: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure orderNoChange(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmYSYFList: TfrmYSYFList;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp,U_OrderJD;

{$R *.dfm}

procedure TfrmYSYFList.FormDestroy(Sender: TObject);
begin
  frmYSYFList:=nil;
end;

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

procedure TfrmYSYFList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YF_Money_CR') ;
      SQL.Add(' where ((OrderNo='+quotedstr(Trim(conNo.Text))+')or (OrderNo in (select OrderNo from JYOrder_Main X where X.ConNo='+quotedstr(Trim(conNo.Text))+')))');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmYSYFList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption+tv2.Name+'1',Tv2);
  Close;
end;

procedure TfrmYSYFList.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption+tv2.Name+'1',Tv2);
  InitGrid();
end;

procedure TfrmYSYFList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel(self.Caption,cxGrid2);
end;

procedure TfrmYSYFList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmYSYFList.orderNoChange(Sender: TObject);
begin
if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

end.
