unit U_BGHZSelList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter,
  RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport, RM_e_Xls,
  Menus, cxPC, cxButtonEdit, cxTextEdit, cxDropDownEdit;

type
  TfrmBGHZSelList = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    Panel1: TPanel;
    Label9: TLabel;
    OrderNo: TEdit;
    ToolButton2: TToolButton;
    N1: TMenuItem;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    DataSource2: TDataSource;
    CDS_HZ: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    v1Column1: TcxGridDBColumn;
    cxSplitter1: TcxSplitter;
    cxGrid6: TcxGrid;
    Tv6: TcxGridDBTableView;
    v6BCOrderNo: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    v6Column1: TcxGridDBColumn;
    Tv6Column1: TcxGridDBColumn;
    Tv6Column2: TcxGridDBColumn;
    v6Column2: TcxGridDBColumn;
    v6Column3: TcxGridDBColumn;
    v6Column4: TcxGridDBColumn;
    cxGridLevel6: TcxGridLevel;
    v6Column5: TcxGridDBColumn;
    v6Column6: TcxGridDBColumn;
    v6Column7: TcxGridDBColumn;
    v6Column8: TcxGridDBColumn;
    v6Column9: TcxGridDBColumn;
    v6Column10: TcxGridDBColumn;
    v6Column11: TcxGridDBColumn;
    v6Column12: TcxGridDBColumn;
    v6Column13: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton2Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure Tv6CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    procedure InitForm();
    { Private declarations }
  public
    FFInt,FCloth:Integer;

    { Public declarations }
  end;

var
  frmBGHZSelList: TfrmBGHZSelList;

implementation
uses
  U_DataLink,U_ConInPut,U_RTFun;

{$R *.dfm}

procedure TfrmBGHZSelList.FormDestroy(Sender: TObject);
begin
  frmBGHZSelList:=nil;
end;

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

procedure TfrmBGHZSelList.FormCreate(Sender: TObject);
begin
  //cxgrid1.Align:=alClient;
end;

procedure TfrmBGHZSelList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('报关汇总列表选择',Tv1,'发票管理');
  WriteCxGrid('报关汇总列表选择1',Tv6,'发票管理');
end;
procedure TfrmBGHZSelList.InitForm();
begin
  ReadCxGrid('报关汇总列表选择',Tv1,'发票管理');
  ReadCxGrid('报关汇总列表选择1',Tv6,'发票管理');
end;
procedure TfrmBGHZSelList.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmBGHZSelList.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Length(OrderNo.Text)<3 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        SQL.Clear;
        sql.Add(' select A.*,B.OrderNo,B.ComTaiTou,C.Chker,C.ChkTime,C.ChkStatus,C.BCOrderNo  ');
        sql.Add(' ,FPMoney=isnull((select Sum(Money) from FP_GYSNB AA where AA.NQID=A.NQID),0)');
        sql.Add(' ,FPQty=isnull((select Sum(Qty) from FP_GYSNB AA where AA.NQID=A.NQID),0)');
        sql.Add(',FPDanWei=(select Top 1 GHDanWei from FP_GYSNB AA where AA.NQID=A.NQID)');
        sql.Add(',KHName=(select CustomerNoName from JYOrder_Main BB where BB.OrderNo=B.OrderNo)');
        sql.Add(' ,WXFPMoney=isnull((select Sum(Money) from FP_XiaoShou_Sub AA where AA.NQID=A.NQID),0)');
        sql.Add(' ,WXFPQty=isnull((select Sum(Qty) from FP_XiaoShou_Sub AA where AA.NQID=A.NQID),0)');
        sql.Add(' from JYOrder_BG_CKName_Qty A  ');
        sql.Add(' inner join JYOrder_BG_CK C on A.BCId=C.BCId');
        sql.Add(' inner join JYOrder_BG B on A.BGId=B.BGId');
        SQL.Add(' where  B.OrderNo like '''+'%'+Trim(OrderNo.Text)+'%'+'''');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_HZ);
      SInitCDSData20(ADOQueryMain,CDS_HZ);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmBGHZSelList.ToolButton2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  if CDS_HZ.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  ModalResult:=1;
end;

procedure TfrmBGHZSelList.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);
end;

procedure TfrmBGHZSelList.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main,False);
end;

procedure TfrmBGHZSelList.Tv6CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  with ADOQueryMain do
  begin
    Filtered:=False;
    Close;
    SQL.Clear;
    sql.Add(' select A.*,B.OrderNo,B.ComTaiTou,C.Chker,C.ChkTime,C.ChkStatus,  ');
    sql.Add(' FPMoney=(select Sum(Money) from FP_GYSNB AA where AA.BFID=A.BFID)');
    sql.Add(' from JYOrder_BG_KPFee A  ');
    sql.Add(' inner join JYOrder_BG_CK C on A.BCId=C.BCId');
    sql.Add(' inner join JYOrder_BG B on A.BGId=B.BGId');
    SQL.Add(' where A.BCID='''+Trim(CDS_HZ.fieldbyname('BCID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

end.
