unit U_BGCWManage; //22

interface

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

type
  TfrmBGCWManage = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBView: TToolButton;
    TBDel: TToolButton;
    TBPrint: TToolButton;
    ToolButton3: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    BCOrderNo: TEdit;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Order_Main: TClientDataSet;
    DataSource1: TDataSource;
    ADOQueryTemp: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryPrint: TADOQuery;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    ClientDataSet7: TClientDataSet;
    cxGridPopupMenu7: TcxGridPopupMenu;
    DataSource7: TDataSource;
    Panel2: TPanel;
    Panel7: TPanel;
    Panel3: TPanel;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    Panel4: TPanel;
    CDS_BGName: TClientDataSet;
    cxGridPopupMenu5: TcxGridPopupMenu;
    DSBGName: TDataSource;
    DataSource11: TDataSource;
    ClientDataSet11: TClientDataSet;
    DataSource12: TDataSource;
    ClientDataSet12: TClientDataSet;
    DataSource15: TDataSource;
    ClientDataSet15: TClientDataSet;
    DataSource16: TDataSource;
    ClientDataSet16: TClientDataSet;
    DataSource17: TDataSource;
    ClientDataSet17: TClientDataSet;
    DataSource18: TDataSource;
    ClientDataSet18: TClientDataSet;
    cxGridPopupMenu11: TcxGridPopupMenu;
    cxGridPopupMenu12: TcxGridPopupMenu;
    cxGridPopupMenu15: TcxGridPopupMenu;
    cxGridPopupMenu16: TcxGridPopupMenu;
    cxGridPopupMenu17: TcxGridPopupMenu;
    cxGridPopupMenu18: TcxGridPopupMenu;
    Panel6: TPanel;
    cxGrid12: TcxGrid;
    Tv12: TcxGridDBTableView;
    vJCKMXColumn1: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    cxGridLevel6: TcxGridLevel;
    cxGrid19: TcxGrid;
    Tv19: TcxGridDBTableView;
    cxGridDBColumn43: TcxGridDBColumn;
    Tv19Column1: TcxGridDBColumn;
    Tv19Column2: TcxGridDBColumn;
    cxGridLevel10: TcxGridLevel;
    DataSource19: TDataSource;
    ClientDataSet19: TClientDataSet;
    cxGridPopupMenu19: TcxGridPopupMenu;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    cxGridDBColumn44: TcxGridDBColumn;
    cxGridDBColumn45: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid5: TcxGrid;
    TVBGName: TcxGridDBTableView;
    cxGridDBColumn17: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    cxGridDBColumn30: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    cxGridDBColumn32: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    cxTabControl1: TcxTabControl;
    cxGrid3: TcxGrid;
    Tv11: TcxGridDBTableView;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    v11Column1: TcxGridDBColumn;
    v11Column2: TcxGridDBColumn;
    v11Column3: TcxGridDBColumn;
    cxGrid4: TcxGrid;
    TvFee: TcxGridDBTableView;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridDBColumn33: TcxGridDBColumn;
    TvFeeColumn2: TcxGridDBColumn;
    TvFeeColumn1: TcxGridDBColumn;
    TvFeeColumn3: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    DS_Fee: TDataSource;
    cxGridPopupMenu3: TcxGridPopupMenu;
    CDS_Fee: TClientDataSet;
    v12Column1: TcxGridDBColumn;
    v12Column2: TcxGridDBColumn;
    RM1: TRMGridReport;
    RMDB12: TRMDBDataSet;
    RMDB19: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ToolButton3Click(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cxPageControl2Change(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
    procedure TV16CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure BCOrderNoChange(Sender: TObject);
    procedure Tv11FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure TBPrintClick(Sender: TObject);
  private
    { Private declarations }
    canshu1,canshu2:string;
    procedure InitGrid();
    procedure InitGridMD();
  public
    { Public declarations }
  end;

var
  frmBGCWManage: TfrmBGCWManage;

implementation
uses
  U_DataLink,U_RTFun, U_ZDYHelp, U_ZDYHelpSel,U_ModuleNote,
  U_BGZLInput,U_BGJCKMXInput,U_BGJCKMXGYSInput;

{$R *.dfm}

procedure TfrmBGCWManage.FormDestroy(Sender: TObject);
begin
  frmBGCWManage:=nil;
end;

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

procedure TfrmBGCWManage.ToolButton3Click(Sender: TObject);
begin
  try
    frmModuleNote:=TfrmModuleNote.Create(Application);
    with frmModuleNote do
    begin
      flag:='货物进出口报关明细';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmModuleNote.Free;
  end;
end;

procedure TfrmBGCWManage.TBAddClick(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex=0 then
  begin
    if Order_Main.IsEmpty then Exit;
  end else
  if cxPageControl1.ActivePageIndex=1 then
  begin
    if ClientDataSet11.IsEmpty then Exit;
  end;
  try
    frmBGJCKMXGYSInput:=TfrmBGJCKMXGYSInput.Create(Application);
    with frmBGJCKMXGYSInput do
    begin
      if Self.cxPageControl1.ActivePageIndex=0 then
      begin
        FBGID:=Trim(Order_Main.fieldbyname('BGID').AsString);
        FBCID:='';
      end else
      if Self.cxPageControl1.ActivePageIndex=1 then
      begin
        FBGID:=Trim(ClientDataSet11.fieldbyname('BGID').AsString);
        FBCID:='';
      end;
      FOrderNo:='';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmBGJCKMXGYSInput.Free;
  end;
end;

procedure TfrmBGCWManage.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('Tv1',Tv1,'报关管理');
  WriteCxGrid('Tv2',Tv2,'报关管理');

  Close;
end;

procedure TfrmBGCWManage.FormShow(Sender: TObject);
begin
  EndDate.DateTime:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.DateTime-30;
  cxPageControl1.ActivePageIndex:=0;
  InitGrid();
  ReadCxGrid('Tv1',Tv1,'报关管理');
  ReadCxGrid('Tv2',Tv2,'报关管理');

end;

procedure TfrmBGCWManage.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    if cxPageControl1.ActivePageIndex=0 then
    begin
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add('select * from JYOrder_BG A');
        sql.Add(' where isnull(ChkStatus,'''')=''审核通过'' ');
        sql.Add(' and isnull(Valid,'''')=''Y'' ');
       // ShowMessage(sql.Text);
        sql.Add(' and not exists(select * from JYOrder_BG_KPFee B where B.BGID=A.BGID )');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
    end else
    begin
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add('select A.*,OrderNo=A.BCOrderNo from JYOrder_BG_CK A where 1=1');
        if cxTabControl1.TabIndex=0 then
        begin
          sql.Add(' and isnull(ChkStatus,'''')='''' ');
        end else
        if cxTabControl1.TabIndex=1 then
        begin
          sql.Add(' and isnull(ChkStatus,'''')<>'''' ');
        end;
        if cxTabControl1.TabIndex<>0 then
        begin
          sql.Add(' and FillTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
          sql.Add(' and FillTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
        end;
        Open;
      end;
      SCreateCDS20(ADOQueryMain,ClientDataSet11);
      SInitCDSData20(ADOQueryMain,ClientDataSet11);
    end;

  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

procedure TfrmBGCWManage.TBEditClick(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex<>1 then Exit;
  if ClientDataSet11.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Trim(canshu1)<>'高权限' then
  begin
    if Trim(DName)<>Trim(ClientDataSet11.fieldbyname('Filler').AsString) then
    begin
      Application.MessageBox('不能操作他人的数据!','提示',0);
      Exit;
    end;
  end;
  try
    frmBGJCKMXGYSInput:=TfrmBGJCKMXGYSInput.Create(Application);
    with frmBGJCKMXGYSInput do
    begin
      FBGID:=Trim(ClientDataSet11.fieldbyname('BGID').AsString);
      FBCID:=Trim(ClientDataSet11.fieldbyname('BCID').AsString);
      FOrderNo:='';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmBGJCKMXGYSInput.Free;
  end;
end;

procedure TfrmBGCWManage.Tv1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
var
  FMainId:String;
begin
  
  {with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from (');
    sql.Add('select PSName=Cast(A.PSXH As Varchar(20))+'' ''+Cast(A.PSName As Varchar(20)),B.FactoryNo,PSName10=A.PSName,B.FactoryName,sum(QtyFlag*PS) MDPS,Sum(QtyFlag*Qty) MDQty,B.QtyUnit');
    sql.Add(' from JYOrder_Process A  ');
    sql.Add(' left join JYOrder_Main_MD B on A.PSID=B.PSID');
    sql.Add(' inner join JYOrder_Main C on A.Mainid=C.MainId');
    sql.Add(' where C.OrderNo='''+Trim(Order_Main.fieldbyname('OrderNo').AsString)+'''');
    sql.Add(' group by A.PSXH,A.PSName,B.FactoryName,B.FactoryNo,B.QtyUnit)AA where MDQty>0 order by PSName');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet7);
  SInitCDSData20(ADOQueryTemp,ClientDataSet7); }
end;

procedure TfrmBGCWManage.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmBGCWManage.InitGridMD();
var
  fsj:string;
begin
  
end;
procedure TfrmBGCWManage.ToolButton1Click(Sender: TObject);
begin
  if ClientDataSet11.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate JYOrder_BG_CK Set ChkStatus=''已送审'',SSTime=getdate() ');
    sql.Add(' where BCID='''+Trim(ClientDataSet11.fieldbyname('BCID').AsString)+'''');
    ExecSQL;
  end;
  ClientDataSet11.Delete;
end;

procedure TfrmBGCWManage.TBDelClick(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex<>1 then Exit;
  
  if ClientDataSet11.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete JYOrder_BG_CK where BCID='''+Trim(ClientDataSet11.fieldbyname('BCID').AsString)+'''');
    sql.Add('delete JYOrder_BG_KPFee where BCID='''+Trim(ClientDataSet11.fieldbyname('BCID').AsString)+'''');
    sql.Add('delete JYOrder_BG_CKName_Qty where BCID='''+Trim(ClientDataSet11.fieldbyname('BCID').AsString)+'''');
    ExecSQL;
  end;
  ClientDataSet11.Delete;
end;

procedure TfrmBGCWManage.ToolButton2Click(Sender: TObject);
begin
  if ClientDataSet11.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>1 then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_CK  ');
    sql.Add(' where BCID='''+Trim(ClientDataSet11.fieldbyname('BCID').AsString)+'''');
    sql.Add(' and isnull(ChkStatus,'''')<>'''' ');
    sql.Add(' and isnull(ChkStatus,'''')<>''已送审'' ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False then
  begin
    Application.MessageBox('已审核，不能撤销!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate JYOrder_BG_CK Set ChkStatus='''',SSTime=Null ');
    sql.Add(' where BCID='''+Trim(ClientDataSet11.fieldbyname('BCID').AsString)+'''');
    ExecSQL;
  end;
  ClientDataSet11.Delete;
end;

procedure TfrmBGCWManage.TBViewClick(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex<>1 then Exit;
  if ClientDataSet11.IsEmpty then Exit;
  
  try
    frmBGJCKMXGYSInput:=TfrmBGJCKMXGYSInput.Create(Application);
    with frmBGJCKMXGYSInput do
    begin
      FBGID:=Trim(ClientDataSet11.fieldbyname('BGID').AsString);
      FBCID:=Trim(ClientDataSet11.fieldbyname('BCID').AsString);
      FOrderNo:='';
      TBSave.Visible:=False;
      ToolBar2.Visible:=False;
      ToolBar3.Visible:=False;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmBGJCKMXGYSInput.Free;
  end;
end;

procedure TfrmBGCWManage.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
end;

procedure TfrmBGCWManage.cxPageControl2Change(Sender: TObject);
begin
  InitGridMD();
end;

procedure TfrmBGCWManage.cxPageControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmBGCWManage.TV16CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if cxPageControl1.ActivePageIndex<>1 then Exit;
  InitGridMD();
end;

procedure TfrmBGCWManage.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var
  FMainId:String;
begin
  if cxPageControl1.ActivePageIndex<>0 then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_Qty where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet2);
  SInitCDSData20(ADOQueryTemp,ClientDataSet2);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_Name where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_BGName);
  SInitCDSData20(ADOQueryTemp,CDS_BGName);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main_MD_HZ where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Fee);
  SInitCDSData20(ADOQueryTemp,CDS_Fee);
 { with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(Order_Main.fieldbyname('OrderNo').AsString)+'''');
    Open;
  end;
  FMainId:=Trim(ADOQueryTemp.fieldbyname('MainId').AsString);
  with  ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_View_MDQtyFooter :MainId');
    Parameters.ParamByName('MainId').Value:=Trim(FMainId);
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet7);
  SInitCDSData20(ADOQueryTemp,ClientDataSet7); }
end;

procedure TfrmBGCWManage.BCOrderNoChange(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex<>1 then Exit;
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,ClientDataSet11);
  SInitCDSData20(ADOQueryMain,ClientDataSet11);
end;

procedure TfrmBGCWManage.Tv11FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  if cxPageControl1.ActivePageIndex<>1 then Exit;
  //if ClientDataSet11.IsEmpty  then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_KPFee where BCID='''+Trim(ClientDataSet11.fieldbyname('BCID').AsString)+'''');
    open;
  end;
  SCreateCDS20(ADOQueryCmd,ClientDataSet12);
  SInitCDSData20(ADOQueryCmd,ClientDataSet12);
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_CKName_Qty where BCID='''+Trim(ClientDataSet11.fieldbyname('BCID').AsString)+'''');
    open;
  end;
  SCreateCDS20(ADOQueryCmd,ClientDataSet19);
  SInitCDSData20(ADOQueryCmd,ClientDataSet19);
end;

procedure TfrmBGCWManage.TBPrintClick(Sender: TObject);
var
   fPrintFile:string;
   FMoney,FMQty,FKgQty,FBCID,FPrice:String;
begin
  if cxPageControl1.ActivePageIndex<>1 then Exit;
  if ClientDataSet11.IsEmpty then Exit;
  FBCID:=Trim(ClientDataSet11.fieldbyname('BCID').AsString);
  FMoney:=Tv12.DataController.Summary.FooterSummaryTexts[0];
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(sum(BFQty),0) KgQty from JYOrder_BG_KPFee where BCID='''+Trim(FBCID)+'''');
    sql.Add(' and PSXH=(select Max(PSXH) from JYOrder_BG_KPFee where BCID='''+Trim(FBCID)+''')');
    open;
  end;
  FKgQty:=Trim(ADOQueryTemp.fieldbyname('KgQty').AsString);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(sum(BFMQty),0) MQty from JYOrder_BG_KPFee where BCID='''+Trim(FBCID)+'''');
    sql.Add(' and PSXH=(select Max(PSXH) from JYOrder_BG_KPFee where BCID='''+Trim(FBCID)+''')');
    open;
  end;
  FMQty:=Trim(ADOQueryTemp.fieldbyname('MQty').AsString);
  if Trim(ClientDataSet12.fieldbyname('BFUnit').AsString)='M' then
  begin
    if Trim(FMQty)<>'' then
    begin
      if StrToFloat(FMQty)>0 then
      begin
        FPrice:=FloatToStr(SSWR(StrToFloat(FMoney)*1.00/StrToFloat(FMQty)));
      end;
    end;
  end else
  begin
    if Trim(FKgQty)<>'' then
    begin
      if StrToFloat(FKgQty)>0 then
      begin
        FPrice:=FloatToStr(SSWR(StrToFloat(FMoney)*1.00/StrToFloat(FKgQty)));
      end;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYorder_BG where BGID='''+Trim(ClientDataSet11.fieldbyname('BGID').AsString)+'''');
    Open;
  end;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\货物进出口报关明细表Fee.rmf';
  if FileExists(fPrintFile) then
  begin
    RMVariables['BCOrderNo']:=ClientDataSet11.fieldbyname('BCOrderNo').Value;
    RMVariables['BGDate']:=ClientDataSet11.fieldbyname('BGDate').Value;
    RMVariables['CBMoney']:=Tv12.DataController.Summary.FooterSummaryValues[0];
    RMVariables['FMQty']:=FMQty;
    RMVariables['FKgQty']:=FKgQty;
    RMVariables['FPrice']:=FPrice;
    RMVariables['ComTaiTou']:=ADOQueryTemp.fieldbyname('ComTaiTou').Value;
    {RMVariables['HaiYunFee']:=ADOQueryTemp.fieldbyname('HaiYunFee').Value;
    RMVariables['BaoFee']:=ADOQueryTemp.fieldbyname('BaoFee').Value;
    RMVariables['YunDiG']:=ADOQueryTemp.fieldbyname('YunDiG').Value;
    RMVariables['ChuKouKA']:=ADOQueryTemp.fieldbyname('ChuKouKA').Value;
    RMVariables['HuoYuanPlace']:=ADOQueryTemp.fieldbyname('HuoYuanPlace').Value;
    RMVariables['ChengJiaoType']:=ADOQueryTemp.fieldbyname('ChengJiaoType').Value; }
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\货物进出口报关明细表.rmf'),'提示',0);
  end;
 // Panel4.Visible:=True;
end;

end.
