unit U_CPOutListCX;

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, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxCheckBox, Menus,
  MovePanel, cxCalendar, cxButtonEdit;

type
  TfrmCPOutListCX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    Label5: TLabel;
    orderNo: TEdit;
    MovePanel2: TMovePanel;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1ZSYJMoney: TcxGridDBColumn;
    v1GDYJMoney: TcxGridDBColumn;
    v1FZYJMoney: TcxGridDBColumn;
    v1OrderNo: TcxGridDBColumn;
    v1FHMoney: TcxGridDBColumn;
    v1YRLMoney: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure orderNoKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCPOutListCX: TfrmCPOutListCX;

implementation
uses
  U_DataLink,U_Fun,U_BanCpRkOutPut;

{$R *.dfm}

procedure TfrmCPOutListCX.FormDestroy(Sender: TObject);
begin
  frmCPOutListCX:=nil;
end;

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

procedure TfrmCPOutListCX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      SQL.Add('select A.*,D.ConNo,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ,B.OrderNo,D.OrdConPrcUnit ');
      sql.Add(',D.OrdConPrcNote,D.OrdConPrcShuoM,C.*,FHMoney=round(C.PRTPrice*A.Qty,2,1)  ');
      sql.add(',YRLMoney=(select Sum(FP.FPMoney)+isnull(sum(FP.SXMoney),0) from SK_Money_FP FP where FP.BCID=A.BCID and FP.WBID=A.Mainid)');
      sql.add('from CK_BanCP_CR A ');
      Sql.add(' inner join JYOrder_Main B on A.MainId=B.MainId');
      sql.Add(' left join JYOrderCon_Sub C on B.ConSubId=C.Subid');
      sql.Add(' left join JYOrderCon_Main D on C.Mainid=D.Mainid');
      sql.Add(' where D.ConNo like '''+'%'+Trim(orderNo.Text)+'%'+'''');
      SQL.Add(' and CRType=''正常出库'' and A.BCID=A.MJID');
      sql.add(' order by B.OrderNo');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

procedure TfrmCPOutListCX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('业务成品出库查询',Tv1,'成品仓库');
  Close;
end;

procedure TfrmCPOutListCX.FormShow(Sender: TObject);
begin
  ReadCxGrid('业务成品出库查询',Tv1,'成品仓库');
end;

procedure TfrmCPOutListCX.N1Click(Sender: TObject);
begin
  //SelOKNo(CDS_Main,True);
end;

procedure TfrmCPOutListCX.N2Click(Sender: TObject);
begin
  //SelOKNo(CDS_Main,False);
end;



procedure TfrmCPOutListCX.orderNoKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    InitGrid();
  end;
end;

procedure TfrmCPOutListCX.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid('业务成品出库查询',Tv1,'成品仓库');
  ModalResult:=1;
end;

end.
