unit U_BGLDManage; //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, cxDropDownEdit,
  cxCheckBox, Menus, RM_Dataset, RM_Common, RM_Class, RM_e_Xls, RM_System,
  RM_GridReport;

type
  TfrmBGLDManage = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: 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;
    OrderNo: TEdit;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Order_Main: TClientDataSet;
    DataSource1: TDataSource;
    ADOQueryTemp: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryPrint: TADOQuery;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    ClientDataSet7: TClientDataSet;
    cxGridPopupMenu7: TcxGridPopupMenu;
    DataSource7: TDataSource;
    Panel2: TPanel;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    CDS_11: TClientDataSet;
    cxGridPopupMenu11: TcxGridPopupMenu;
    DS_11: TDataSource;
    CDS_19: TClientDataSet;
    cxGridPopupMenu19: TcxGridPopupMenu;
    DS_19: TDataSource;
    cxTabControl1: TcxTabControl;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton4: TToolButton;
    Panel4: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    CDS_BGName: TClientDataSet;
    cxGridPopupMenu5: TcxGridPopupMenu;
    DSBGName: TDataSource;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Panel8: TPanel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid5: TcxGrid;
    TVBGName: TcxGridDBTableView;
    cxGridDBColumn8: TcxGridDBColumn;
    v1Column1ty: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxPageControl2: TcxPageControl;
    cxTabSheet2: TcxTabSheet;
    cxTabSheet3: TcxTabSheet;
    cxGrid7: TcxGrid;
    Tv7: TcxGridDBTableView;
    cxGridDBColumn30: TcxGridDBColumn;
    cxGridDBColumn34: TcxGridDBColumn;
    v7Column2: TcxGridDBColumn;
    cxGridDBColumn32: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    v7Column1: TcxGridDBColumn;
    cxGridDBColumn36: TcxGridDBColumn;
    cxGridLevel5: TcxGridLevel;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    cxGrid6: TcxGrid;
    Tv19: TcxGridDBTableView;
    cxGridDBColumn11: TcxGridDBColumn;
    v6Column1: TcxGridDBColumn;
    Tv19Column1: TcxGridDBColumn;
    Tv19Column2: TcxGridDBColumn;
    v6Column2: TcxGridDBColumn;
    v6Column3: TcxGridDBColumn;
    v6Column4: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    ToolButton5: TToolButton;
    cxGrid3: TcxGrid;
    Tv11: TcxGridDBTableView;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    v11Column1: TcxGridDBColumn;
    v11Column2: TcxGridDBColumn;
    v11Column3: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    ToolButton6: TToolButton;
    v1Column1: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    cxGrid12: TcxGrid;
    Tv12: TcxGridDBTableView;
    vJCKMXColumn1: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    v12Column1: TcxGridDBColumn;
    v12Column2: TcxGridDBColumn;
    v12Column3: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    cxGridLevel6: TcxGridLevel;
    ClientDataSet12: TClientDataSet;
    DataSource12: TDataSource;
    cxGridPopupMenu12: TcxGridPopupMenu;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    RMDB12: TRMDBDataSet;
    RMDB19: TRMDBDataSet;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    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 ToolButton4Click(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Tv11CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TBFindClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure Tv19CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
  private
    { Private declarations }
    canshu1,canshu2:string;
    procedure InitGrid();
  public
    FSel:String;
    { Public declarations }
  end;

var
  frmBGLDManage: TfrmBGLDManage;

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

{$R *.dfm}

procedure TfrmBGLDManage.FormDestroy(Sender: TObject);
begin
  frmBGLDManage:=nil;
end;

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

procedure TfrmBGLDManage.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 TfrmBGLDManage.TBAddClick(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex=0 then
  begin
    try
      frmBGZLInput:=TfrmBGZLInput.Create(Application);
      with frmBGZLInput do
      begin
        FBGID:='';
        FOrderNo:='';
        if ShowModal=1 then
        begin

        end;
      end;
    finally
      frmBGZLInput.Free;
    end;
  end;
end;

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

  Close;
end;

procedure TfrmBGLDManage.FormShow(Sender: TObject);
begin
  EndDate.DateTime:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.DateTime-30;
  cxPageControl1.ActivePageIndex:=0;
  ReadCxGrid('Tv1',Tv1,'报关管理');
  ReadCxGrid('Tv2',Tv2,'报关管理');
  if Trim(FSel)='99' then
  begin
    cxTabControl1.TabIndex:=3;
    frmBGLDManage.Align:=alClient;
  end else
  begin
    cxTabControl1.TabIndex:=0;
  end;
  InitGrid();
  cxPageControl2.ActivePageIndex:=0;
end;

procedure TfrmBGLDManage.InitGrid();
var
  fsj:string;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_BG A where 1=1');
      if Trim(canshu1)<>'高权限' then
      begin
        //sql.Add(' and Filler='''+Trim(DName)+'''');
        fsj:=' and Filler in(select UserName from  SY_User where DPID in'+
                                              '(select DPID from SY_User where UserName='''+Trim(DName)+'''))';
        SQL.Add(fsj);
      end;
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(ChkStatus,'''')='''' ');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(ChkStatus,'''')<>'''' ');
        SQL.Add(' and not exists(select * from JYOrder_BG_CK B where B.BGID=A.BGID and isnull(B.ChkStatus,'''')=''审核通过'' )');
      end else
      if cxTabControl1.TabIndex=2 then
      begin
        sql.Add(' and isnull(ChkStatus,'''')<>'''' ');
        SQL.Add(' and exists(select * from JYOrder_BG_CK B where B.BGID=A.BGID and isnull(B.ChkStatus,'''')=''审核通过'' and B.OKFlag=0 )');
      end else
      if cxTabControl1.TabIndex=3 then
      begin
        sql.Add(' and isnull(ChkStatus,'''')<>'''' ');
        SQL.Add(' and not exists(select * from JYOrder_BG_CK B where B.BGID=A.BGID and isnull(B.ChkStatus,'''')=''审核通过'' and B.OKFlag=0 )');
      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;
      if CheckBox1.Checked=False then
      begin
        sql.Add('and isnull(ChkStatus,'''')<>''审核不通过'' ');
      end;
      if CheckBox2.Checked=False then
      begin

        sql.Add('and isnull(Valid,'''')<>''N'' ');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

        end;
      end;
    finally
      frmBGZLInput.Free;
    end;
  end else
  if cxPageControl1.ActivePageIndex=1 then
  begin
    try
      frmBGJCKMXInput:=TfrmBGJCKMXInput.Create(Application);
      with frmBGJCKMXInput do
      begin
        FBGID:=Trim(Self.Order_Main.fieldbyname('BGID').AsString);
        FOrderNo:=Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
        if ShowModal=1 then
        begin

        end;
      end;
    finally
      frmBGJCKMXInput.Free;
    end;
  end;
end;

procedure TfrmBGLDManage.Tv1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
var
  FMainId:String;
begin
  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 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); 
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_CK where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    sql.Add(' and isnull(ChkStatus,'''')=''审核通过'' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_11);
  SInitCDSData20(ADOQueryTemp,CDS_11);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_CKName_Qty where BCID='''+Trim(CDS_11.fieldbyname('BCID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_19);
  SInitCDSData20(ADOQueryTemp,CDS_19);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_KPFee where BCID='''+Trim(CDS_11.fieldbyname('BCID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet12);
  SInitCDSData20(ADOQueryTemp,ClientDataSet12);
  {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 TfrmBGLDManage.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmBGLDManage.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.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 Set ChkStatus=''已送审'',SSTime=getdate() ');
    sql.Add(' where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    ExecSQL;
  end;
  Order_Main.Delete;
end;

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

procedure TfrmBGLDManage.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>1 then Exit;
  {if CDS_11.IsEmpty=False then
  begin
    Application.MessageBox('财务已登记数据，不能撤销!','提示',0);
    Exit;
  end; }
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG  ');
    sql.Add(' where BGID='''+Trim(Order_Main.fieldbyname('BGID').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 Trim(Order_Main.fieldbyname('Valid').AsString)='N' 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 Set ChkStatus='''',SSTime=Null ');
    sql.Add(' where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    ExecSQL;
  end;
  Order_Main.Delete;
end;

procedure TfrmBGLDManage.ToolButton4Click(Sender: TObject);
begin
  if cxTabControl1.TabIndex>2 then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG where OrderNo='''+Trim(Order_Main.fieldbyname('OrderNo').AsString)+'''');
    sql.Add(' and isnull(BatchNo,'''')='''+Trim(Order_Main.fieldbyname('BatchNo').AsString)+'''');
    sql.Add(' and isnull(ChkStatus,'''')='''' ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False then
  begin
    Application.MessageBox('此订单号有未送审的数据，不能执行复制操作!','提示',0);
    Exit;
  end;
  if Application.MessageBox(Pchar('确定要执行此操作吗？执行此操作后，'+#13+'之前录入的数据将作废!'),'提示',32+4)<>IDYES then Exit;
  try
    frmBGZLInput:=TfrmBGZLInput.Create(Application);
    with frmBGZLInput do
    begin
      FCopyInt:=1;
      FBGID:=Trim(Self.Order_Main.fieldbyname('BGID').AsString);
      FOrderNo:=Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmBGZLInput.Free;
  end;
end;

procedure TfrmBGLDManage.TBViewClick(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex=0 then
  begin
    
    try
      frmBGZLInput:=TfrmBGZLInput.Create(Application);
      with frmBGZLInput do
      begin
        FBGID:=Trim(Self.Order_Main.fieldbyname('BGID').AsString);
        FOrderNo:=Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
        TBSave.Visible:=False;
        ToolBar2.Visible:=False;
        ToolBar3.Visible:=False;
        if ShowModal=1 then
        begin

        end;
      end;
    finally
      frmBGZLInput.Free;
    end;
  end else
  if cxPageControl1.ActivePageIndex=1 then
  begin
    try
      frmBGJCKMXInput:=TfrmBGJCKMXInput.Create(Application);
      with frmBGJCKMXInput do
      begin
        FBGID:=Trim(Self.Order_Main.fieldbyname('BGID').AsString);
        FOrderNo:=Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
        if ShowModal=1 then
        begin

        end;
      end;
    finally
      frmBGJCKMXInput.Free;
    end;
  end;
end;

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

procedure TfrmBGLDManage.Tv11CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_CKName_Qty where BCID='''+Trim(CDS_11.fieldbyname('BCID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_19);
  SInitCDSData20(ADOQueryTemp,CDS_19);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_KPFee where BCID='''+Trim(CDS_11.fieldbyname('BCID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet12);
  SInitCDSData20(ADOQueryTemp,ClientDataSet12);
end;

procedure TfrmBGLDManage.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmBGLDManage.OrderNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmBGLDManage.ToolButton5Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if CDS_11.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>2 then Exit;
  if cxPageControl2.ActivePageIndex<>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 OKFlag=1,OKTime=getdate(),OKPerson='''+Trim(DName)+'''');
    sql.Add(' where BCID='''+Trim(CDS_11.fieldbyname('BCID').AsString)+'''');
    ExecSQL;
  end;
  with CDS_11 do
  begin
    Edit;
    FieldByName('OKFlag').Value:=True;
    FieldByName('OKTime').Value:=Now;
    FieldByName('OKPerson').Value:=Trim(DName);
    Post;
  end;
end;

procedure TfrmBGLDManage.ToolButton6Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if CDS_11.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>3 then Exit;
  if cxPageControl2.ActivePageIndex<>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 OKFlag=0,OKTime=NUll,OKPerson=Null');
    sql.Add(' where BCID='''+Trim(CDS_11.fieldbyname('BCID').AsString)+'''');
    ExecSQL;
  end;
  with CDS_11 do
  begin
    Edit;
    FieldByName('OKFlag').Value:=False;
    FieldByName('OKTime').Value:=Null;
    FieldByName('OKPerson').Value:='';
    Post;
  end;
end;

procedure TfrmBGLDManage.N1Click(Sender: TObject);
begin
  if CDS_19.IsEmpty then Exit;
  TcxGridToExcel('财务反馈信息',cxGrid6);
end;

procedure TfrmBGLDManage.MenuItem1Click(Sender: TObject);
var
   fPrintFile:string;
   FMoney,FMQty,FKgQty,FBCID,FPrice:String;
begin
  FBCID:=Trim(CDS_11.fieldbyname('BCID').AsString);
  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);

  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\货物进出口报关明细表LD.rmf';
  if FileExists(fPrintFile) then
  begin
    RMVariables['BCOrderNo']:=CDS_11.fieldbyname('BCOrderNo').Value;
    RMVariables['BGDate']:=CDS_11.fieldbyname('BGDate').Value;
    RMVariables['FMQty']:=FMQty;
    RMVariables['FKgQty']:=FKgQty;
    RMVariables['FPrice']:=FPrice;
    RMVariables['HaiYunFee']:=Order_Main.fieldbyname('HaiYunFee').Value;
    RMVariables['BaoFee']:=Order_Main.fieldbyname('BaoFee').Value;
    RMVariables['YunDiG']:=Order_Main.fieldbyname('YunDiG').Value;
    RMVariables['ChuKouKA']:=Order_Main.fieldbyname('ChuKouKA').Value;
    RMVariables['HuoYuanPlace']:=Order_Main.fieldbyname('HuoYuanPlace').Value;
    RMVariables['ChengJiaoType']:=Order_Main.fieldbyname('ChengJiaoType').Value;
    RMVariables['ComTaiTou']:=Order_Main.fieldbyname('ComTaiTou').Value;

    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\货物进出口报关明细表LD.rmf'),'提示',0);
  end;  
 // Panel4.Visible:=True;
end;

procedure TfrmBGLDManage.Tv19CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_19.IsEmpty then Exit;
  if Trim(FSel)='99' then
  begin
    CDS_BGName.Locate('BGName',Trim(CDS_19.fieldbyname('BGName').AsString),[]);
    ModalResult:=1;
  end;
end;

procedure TfrmBGLDManage.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmBGLDManage.CheckBox2Click(Sender: TObject);
begin
  InitGrid();
end;

end.
