unit U_BaoGuanList;

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

type
  TfrmBaoGuanList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    TBDel: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    ClientDataSet1: TClientDataSet;
    Label6: TLabel;
    A4FPNO: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column2: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column4: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    cxSplitter1: TcxSplitter;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    ClientDataSet2: TClientDataSet;
    v1Column11: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    Label5: TLabel;
    A6PONO: TEdit;
    Label8: TLabel;
    A5ConNO: TEdit;
    v1Column15: TcxGridDBColumn;
    Label3: TLabel;
    A1ChuKouShang: TEdit;
    v1Column16: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    v1Column24: TcxGridDBColumn;
    v1Column25: TcxGridDBColumn;
    v1Column26: TcxGridDBColumn;
    v1Column27: TcxGridDBColumn;
    v1Column28: TcxGridDBColumn;
    v1Column29: TcxGridDBColumn;
    v1Column30: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    TBCopy: TToolButton;
    TBBGZL: TToolButton;
    RMXLSExport1: TRMXLSExport;
    CDS_Print: TClientDataSet;
    RM1: TRMGridReport;
    RMDBDataSet1: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    TBHT: TToolButton;
    TBFP: TToolButton;
    TBZXD: TToolButton;
    TBBGD: TToolButton;
    TBView: TToolButton;
    TBSBYS: TToolButton;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    TBSS: TToolButton;
    TBSSCX: TToolButton;
    TBHD: TToolButton;
    TBHDCX: TToolButton;
    TBSH: TToolButton;
    TBSHCX: TToolButton;
    v1Column31: TcxGridDBColumn;
    v1Column32: TcxGridDBColumn;
    v1Column33: TcxGridDBColumn;
    v1Column34: TcxGridDBColumn;
    v1Column35: TcxGridDBColumn;
    v1Column36: TcxGridDBColumn;
    v1Column37: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    TBAll: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure CRTypeChange(Sender: TObject);
    procedure A4FPNOKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure A6PONOKeyPress(Sender: TObject; var Key: Char);
    procedure A5ConNOKeyPress(Sender: TObject; var Key: Char);
    procedure TBCopyClick(Sender: TObject);
    procedure TBBGZLClick(Sender: TObject);
    procedure TBHTClick(Sender: TObject);
    procedure TBFPClick(Sender: TObject);
    procedure TBZXDClick(Sender: TObject);
    procedure TBBGDClick(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure TBSBYSClick(Sender: TObject);
    procedure TBSSClick(Sender: TObject);
    procedure TBSSCXClick(Sender: TObject);
    procedure TBHDClick(Sender: TObject);
    procedure TBHDCXClick(Sender: TObject);
    procedure TBSHClick(Sender: TObject);
    procedure TBSHCXClick(Sender: TObject);
    procedure TBAllClick(Sender: TObject);
  private
    canshu1:string;
    canshu2:string;
    FDate:TDateTime;
    procedure InitGrid();
    function DelData():Boolean;
    procedure InitSubGrid();
    procedure InitGridSql(var fsj:String);
    procedure InitButton();
    procedure InitPrtData();
    { Private declarations }
  public
    { Public declarations }
  end;

//var
  //frmBaoGuanList: TfrmBaoGuanList;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp,U_BaoGuanInPut;

{$R *.dfm}

procedure TfrmBaoGuanList.FormDestroy(Sender: TObject);
begin
  //frmBaoGuanList:=nil;
end;
procedure TfrmBaoGuanList.InitButton();
begin
  if Trim(Self.Caption)='报关管理' then  //单机
  begin
    TBAdd.Visible:=True;TBEdit.Visible:=True;TBDel.Visible:=True;TBCopy.Visible:=True;
    TBSS.Visible:=False; TBSSCX.Visible:=False;TBAll.Visible:=True;
    TBBGZL.Visible:=True;TBHT.Visible:=True;TBFP.Visible:=True;
    TBZXD.Visible:=True;TBBGD.Visible:=True;TBSBYS.Visible:=True;
    cxTabControl1.TabIndex:=0;
    cxTabControl1.Visible:=False;
    v1Column31.Visible:=False;
    v1Column31.Hidden:=True;
    v1Column32.Visible:=False;
    v1Column32.Hidden:=True;
    v1Column33.Visible:=False;
    v1Column33.Hidden:=True;
    v1Column34.Visible:=False;
    v1Column34.Hidden:=True;
    v1Column35.Visible:=False;
    v1Column35.Hidden:=True;
    v1Column36.Visible:=False;
    v1Column36.Hidden:=True;
    v1Column37.Visible:=False;
    v1Column37.Hidden:=True;
  end else
  if Trim(Self.Caption)='报关资料录入' then
  begin
    TBAdd.Visible:=True;TBEdit.Visible:=True;TBDel.Visible:=True;TBCopy.Visible:=True;
    TBSS.Visible:=True; TBSSCX.Visible:=True;TBAll.Visible:=True;
    TBBGZL.Visible:=True;TBHT.Visible:=True;TBFP.Visible:=True;
    TBZXD.Visible:=True;TBBGD.Visible:=True;TBSBYS.Visible:=True;
    cxTabControl1.TabIndex:=0;
  end else
  if Trim(Self.Caption)='报关资料录入(高权限)' then
  begin
    TBAdd.Visible:=True;TBEdit.Visible:=True;TBDel.Visible:=True;TBCopy.Visible:=True;
    TBSS.Visible:=True; TBSSCX.Visible:=True;TBAll.Visible:=True;
    TBBGZL.Visible:=True;TBHT.Visible:=True;TBFP.Visible:=True;
    TBZXD.Visible:=True;TBBGD.Visible:=True;TBSBYS.Visible:=True;
    cxTabControl1.TabIndex:=0;
  end else
  if Trim(Self.Caption)='报关资料查询(高权限)' then
  begin
    TBBGZL.Visible:=True;TBHT.Visible:=True;TBFP.Visible:=True;
    TBZXD.Visible:=True;TBBGD.Visible:=True;TBSBYS.Visible:=True; TBAll.Visible:=True;
    cxTabControl1.TabIndex:=4;
    cxTabControl1.Visible:=False;
  end else
  if Trim(Self.Caption)='报关资料打印查询' then
  begin
    TBBGZL.Visible:=True;
    cxTabControl1.TabIndex:=4;
    cxTabControl1.Visible:=False;
  end else
  if Trim(Self.Caption)='报关合同打印查询' then
  begin
    TBHT.Visible:=True;
    cxTabControl1.TabIndex:=4;
    cxTabControl1.Visible:=False;
  end else
  if Trim(Self.Caption)='报关发票打印查询' then
  begin
    TBFP.Visible:=True;
    cxTabControl1.TabIndex:=4;
    cxTabControl1.Visible:=False;
  end else
  if Trim(Self.Caption)='报关装箱单打印查询' then
  begin
    TBZXD.Visible:=True;
    cxTabControl1.TabIndex:=4;
    cxTabControl1.Visible:=False;
  end else
  if Trim(Self.Caption)='报关单打印查询' then
  begin
    TBBGD.Visible:=True;
    cxTabControl1.TabIndex:=4;
    cxTabControl1.Visible:=False;
  end else
  if Trim(Self.Caption)='申报要素打印查询' then
  begin
    TBSBYS.Visible:=True;
    cxTabControl1.TabIndex:=4;
    cxTabControl1.Visible:=False;
  end else
  if Trim(Self.Caption)='报关资料核对' then
  begin
    TBHD.Visible:=True; TBHDCX.Visible:=True;  TBAll.Visible:=True;
    TBBGZL.Visible:=True;TBHT.Visible:=True;TBFP.Visible:=True;
    TBZXD.Visible:=True;TBBGD.Visible:=True;TBSBYS.Visible:=True;
    cxTabControl1.TabIndex:=1;
  end else
  if Trim(Self.Caption)='报关资料审核' then
  begin
    TBSH.Visible:=True; TBSHCX.Visible:=True; TBAll.Visible:=True;
    TBBGZL.Visible:=True;TBHT.Visible:=True;TBFP.Visible:=True;
    TBZXD.Visible:=True;TBBGD.Visible:=True;TBSBYS.Visible:=True;
    cxTabControl1.TabIndex:=2;
  end;
end;

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

procedure TfrmBaoGuanList.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=SGetServerDateMBeg(ADOQueryTemp);
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
end;

procedure TfrmBaoGuanList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.* ');
      sql.Add(' from JYOrder_BaoGuan_Main A  ');
      sql.Add(' where Valid=''Y'' ');
      if Trim(canshu1)<>'高权限' then
      begin
        SQL.Add(' and Filler='''+Trim(DName)+'''');
      end;
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(SChker,'''')='''' ');

      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and  isnull(OKPerson,'''')='''' and isnull(SChker,'''')<>''''   ');
      end else
      if cxTabControl1.TabIndex=2 then
      begin
        sql.Add(' and isnull(Chker,'''')='''' and isnull(OKPerson,'''')<>''''  ');
      end else
      begin
        sql.Add(' and A7FPDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and A7FPDate<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
        if cxTabControl1.TabIndex=3 then
        begin
          sql.Add('  and isnull(Chker,'''')<>'''' ');
        end else
        begin
          if cxTabControl1.Visible=False then
          begin
            sql.Add('  and isnull(OKPerson,'''')<>'''' ');
          end;
        end;
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBaoGuanList.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  InitGrid();
end;

procedure TfrmBaoGuanList.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  end;
end;

procedure TfrmBaoGuanList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('报关主表',Tv1,'报关管理');
  WriteCxGrid('报关明细',Tv1,'报关管理');
  Close;
end;

procedure TfrmBaoGuanList.FormShow(Sender: TObject);
begin
  ReadCxGrid('报关主表'+self.Caption,Tv1,'报关管理');
  ReadCxGrid('报关明细'+self.Caption,Tv1,'报关管理');
  InitButton();
  InitGrid();
end;

procedure TfrmBaoGuanList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('报关资料列表',cxGrid1);
end;

procedure TfrmBaoGuanList.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 TfrmBaoGuanList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,True);
end;

procedure TfrmBaoGuanList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,False);
end;
procedure TfrmBaoGuanList.InitSubGrid();
begin
  if CDS_Main.IsEmpty=False then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_BaoGuan_Sub where BGID='''+Trim(CDS_Main.fieldbyname('BGID').AsString)+'''');
      sql.Add(' and SValid=''Y'' ');
      Open;
    end;
  end else
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_BaoGuan_Sub where 1=2');
      Open;
    end;
  end;

  SCreateCDS20(ADOQueryTemp,ClientDataSet2);
  SInitCDSData20(ADOQueryTemp,ClientDataSet2);
end;

procedure TfrmBaoGuanList.TBDelClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  if DelData() then
  begin
    InitSubGrid();
  end;
end;
function TfrmBaoGuanList.DelData():Boolean;
begin
  try
    Result:=false;
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate JYOrder_BaoGuan_Main Set Valid=''N'',C7BGMoneyHZ=Null,E1BZQtyHZ=Null, E2ChiMaQtyHZ=Null,E3MaoZHZ=Null,E4JingZHZ=Null');
          sql.Add(',Editer='''+Trim(DName)+''',EditTime=getdate()');
          sql.Add(' where BGId='''+Trim(CDS_Main.fieldbyname('BGId').AsString)+'''');
          sql.Add('UPdate JYOrder_BaoGuan_Sub Set SValid=''N'',SEditer='''+Trim(DName)+''',SEditTime=getdate()  where BGId='''+Trim(CDS_Main.fieldbyname('BGId').AsString)+'''');
          ExecSQL;
        end;
        CDS_Main.Delete;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Result:=False;
    Application.MessageBox('数据删除异常！','提示',0);
  end;
end;
procedure TfrmBaoGuanList.TBAddClick(Sender: TObject);
begin
  try
    frmBaoGuanInPut:=TfrmBaoGuanInPut.Create(Application);
    with frmBaoGuanInPut do
    begin
      FBCId:='';
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmBaoGuanInPut.Free;
  end;
end;

procedure TfrmBaoGuanList.TBEditClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  try
    frmBaoGuanInPut:=TfrmBaoGuanInPut.Create(Application);
    with frmBaoGuanInPut do
    begin
      FBCId:=Trim(CDS_Main.fieldbyname('BGID').AsString);
      //TBDel.Visible:=False;
      //TBAdd.Visible:=False;
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmBaoGuanInPut.Free;
  end;
end;

procedure TfrmBaoGuanList.FactoryNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

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



procedure TfrmBaoGuanList.CRTypeChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmBaoGuanList.A4FPNOKeyPress(Sender: TObject; var Key: Char);
var
  fsj:String;
begin
  if Key=#13 then
  begin
    if Trim(A4FPNO.Text)='' then Exit;
    fsj:=' and isnull(A.A4FPNO,'''') like '''+'%'+Trim(A4FPNO.Text)+'%'+'''';
    InitGridSql(fsj);
  end;
end;
procedure TfrmBaoGuanList.InitGridSql(var fsj:String);
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.* ');
      sql.Add(' from JYOrder_BaoGuan_Main A  ');
      sql.Add(' where 1=1 ');
      if Trim(canshu1)<>'高权限' then
      begin
        SQL.Add(' and FillerCode='''+Trim(DCode)+'''');
      end;
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(SChker,'''')='''' ');
      end else
      begin
        if cxTabControl1.TabIndex=1 then
        begin
          sql.Add(' and isnull(SChker,'''')<>'''' and isnull(Chker,'''')='''' ');
        end else
        if cxTabControl1.TabIndex=2 then
        begin
          sql.Add('  and isnull(Chker,'''')<>'''' ');
        end;
      end;
      sql.Add(fsj);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBaoGuanList.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  InitSubGrid();
end;

procedure TfrmBaoGuanList.A6PONOKeyPress(Sender: TObject;
  var Key: Char);
var
  fsj:String;
begin
  if Key=#13 then
  begin
    if Trim(A6PONO.Text)='' then Exit;
    fsj:=' and isnull(A.A6PONO,'''') like '''+'%'+Trim(A6PONO.Text)+'%'+'''';
    InitGridSql(fsj);
  end;
end;

procedure TfrmBaoGuanList.A5ConNOKeyPress(Sender: TObject;
  var Key: Char);
var
  fsj:String;
begin
  if Key=#13 then
  begin
    if Trim(A5ConNO.Text)='' then Exit;
    fsj:=' and isnull(A.A5ConNO,'''') like '''+'%'+Trim(A5ConNO.Text)+'%'+'''';
    InitGridSql(fsj);
  end;
end;

procedure TfrmBaoGuanList.TBCopyClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
 // if cxTabControl1.TabIndex<>0 then Exit;
  try
    frmBaoGuanInPut:=TfrmBaoGuanInPut.Create(Application);
    with frmBaoGuanInPut do
    begin
      FBCId:=Trim(CDS_Main.fieldbyname('BGID').AsString);
      CopyStr:='99';
      //TBDel.Visible:=False;
      //TBAdd.Visible:=False;
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmBaoGuanInPut.Free;
  end;
end;
procedure TfrmBaoGuanList.InitPrtData();
begin
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add(' exec P_View_BaoGuanData :BGID ');
    Parameters.ParamByName('BGID').Value:=Trim(CDS_Main.fieldbyname('BGId').AsString);
    Open;
  end;
  SCreateCDS20(ADOQueryPrint,CDS_Print);
  SInitCDSData20(ADOQueryPrint,CDS_Print);
end;
procedure TfrmBaoGuanList.TBBGZLClick(Sender: TObject);
var
   fPrintFile:string;
   EngMoney,BZZH:string;
begin
  if CDS_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\报关资料.rmf';
  InitPrtData();
  RMXLSExport1:= TRMXLSExport.Create(RMXLSExport1);
  if FileExists(fPrintFile) then
  begin
    //RMVariables['enddate']:=enddate.DateTime;
    //RMVariables['printtime']:=Now;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\报关资料.rmf'),'提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBHTClick(Sender: TObject);
var
   fPrintFile:string;
   EngMoney,BZZH:string;
begin
  if CDS_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\报关合同.rmf';
  InitPrtData();
  RMXLSExport1:= TRMXLSExport.Create(RMXLSExport1);
  if FileExists(fPrintFile) then
  begin
    //RMVariables['enddate']:=enddate.DateTime;
    //RMVariables['printtime']:=Now;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\报关合同.rmf'),'提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBFPClick(Sender: TObject);
var
   fPrintFile:string;
   EngMoney,BZZH:string;
begin
  if CDS_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\报关发票.rmf';
  {if Trim(CDS_Main.fieldbyname('A1ChuKouShang').AsString)='绍兴宇玎纺织有限公司' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\报关发票YD.rmf';
  end else
  if Trim(CDS_Main.fieldbyname('A1ChuKouShang').AsString)='绍兴锦凤进出口有限公司' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\报关发票JF.rmf';
  end;  }
  InitPrtData();
  RMXLSExport1:= TRMXLSExport.Create(RMXLSExport1);
  if FileExists(fPrintFile) then
  begin
    //RMVariables['enddate']:=enddate.DateTime;
    //RMVariables['printtime']:=Now;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\报关发票.rmf'),'提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBZXDClick(Sender: TObject);
var
   fPrintFile:string;
   EngMoney,BZZH:string;
begin
  if CDS_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\报关装箱单.rmf';
  {if Trim(CDS_Main.fieldbyname('A1ChuKouShang').AsString)='绍兴宇玎纺织有限公司' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\报关装箱单YD.rmf';
  end else
  if Trim(CDS_Main.fieldbyname('A1ChuKouShang').AsString)='绍兴锦凤进出口有限公司' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\报关装箱单JF.rmf';
  end; }

  InitPrtData();
  RMXLSExport1:= TRMXLSExport.Create(RMXLSExport1);
  if FileExists(fPrintFile) then
  begin
    //RMVariables['enddate']:=enddate.DateTime;
    //RMVariables['printtime']:=Now;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\报关装箱单.rmf'),'提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBBGDClick(Sender: TObject);
var
   fPrintFile:string;
   EngMoney,BZZH:string;
begin
  if CDS_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\报关单.rmf';
  InitPrtData();
  RMXLSExport1:= TRMXLSExport.Create(RMXLSExport1);
  if FileExists(fPrintFile) then
  begin
    //RMVariables['enddate']:=enddate.DateTime;
    //RMVariables['printtime']:=Now;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\报关单.rmf'),'提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBViewClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  //if cxTabControl1.TabIndex<>0 then Exit;
  try
    frmBaoGuanInPut:=TfrmBaoGuanInPut.Create(Application);
    with frmBaoGuanInPut do
    begin
      FBCId:=Trim(CDS_Main.fieldbyname('BGID').AsString);
      TBSave.Visible:=False;
      ToolBar2.Visible:=False;
      Panel1.Enabled:=False;
      Tv1.OptionsData.Editing:=False;
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmBaoGuanInPut.Free;
  end;
end;

procedure TfrmBaoGuanList.TBSBYSClick(Sender: TObject);
var
   fPrintFile:string;
   EngMoney,BZZH:string;
begin
  if CDS_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\申报要素.rmf';
  InitPrtData();
  RMXLSExport1:= TRMXLSExport.Create(RMXLSExport1);
  if FileExists(fPrintFile) then
  begin
    //RMVariables['enddate']:=enddate.DateTime;
    //RMVariables['printtime']:=Now;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\申报要素.rmf'),'提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBSSClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行送审操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate JYOrder_BaoGuan_Main Set Status=''已送审'',SStime=getdate(),SChker='''+Trim(DName)+'''');
          sql.Add(' where BGID='''+Trim(CDS_Main.fieldbyname('BGID').AsString)+'''');
          ExecSQL;
        end;
        CDS_Main.Delete;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    InitSubGrid();
  except
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBSSCXClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>1 then Exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  CDS_Main.DisableControls;
  with CDS_Main do
  begin
    First;
    while not Eof do
    begin
      if CDS_Main.FieldByName('SSel').AsBoolean=True then
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JYOrder_BaoGuan_Main ');
          sql.Add(' where BGID='''+Trim(CDS_Main.fieldbyname('BGID').AsString)+'''');
          Open;
        end;
        if Trim(ADOQueryTemp.fieldbyname('OKPerson').AsString)<>'' then
        begin
          CDS_Main.EnableControls;
          Application.MessageBox('已核对不能撤销!','提示',0);
          Exit;
        end;
      end;
      Next;
    end;
  end;
  CDS_Main.EnableControls;
  if Application.MessageBox('确定要执行送审撤销操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate JYOrder_BaoGuan_Main Set Status=Null,SStime=Null,SChker=Null');
          sql.Add(' where BGID='''+Trim(CDS_Main.fieldbyname('BGID').AsString)+'''');
          ExecSQL;
        end;
        CDS_Main.Delete;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    InitSubGrid();
  except
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBHDClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>1 then Exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行核对操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate JYOrder_BaoGuan_Main Set Status=''已核对'',OKTime=getdate(),OKPerson='''+Trim(DName)+'''');
          sql.Add(' where BGID='''+Trim(CDS_Main.fieldbyname('BGID').AsString)+'''');
          ExecSQL;
        end;
        CDS_Main.Delete;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    InitSubGrid();
  except
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBHDCXClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>2 then Exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  CDS_Main.DisableControls;
  with CDS_Main do
  begin
    First;
    while not Eof do
    begin
      if CDS_Main.FieldByName('SSel').AsBoolean=True then
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JYOrder_BaoGuan_Main ');
          sql.Add(' where BGID='''+Trim(CDS_Main.fieldbyname('BGID').AsString)+'''');
          Open;
        end;
        if Trim(ADOQueryTemp.fieldbyname('Chker').AsString)<>'' then
        begin
          CDS_Main.EnableControls;
          Application.MessageBox('已审核不能撤销!','提示',0);
          Exit;
        end;
      end;
      Next;
    end;
  end;
  CDS_Main.EnableControls;
  if Application.MessageBox('确定要执行核对撤销操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate JYOrder_BaoGuan_Main Set Status=''已送审'',OKtime=Null,OKPerson=Null');
          sql.Add(' where BGID='''+Trim(CDS_Main.fieldbyname('BGID').AsString)+'''');
          ExecSQL;
        end;
        CDS_Main.Delete;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    InitSubGrid();
  except
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBSHClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>2 then Exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行审核操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate JYOrder_BaoGuan_Main Set Status=''已审核'',ChkTime=getdate(),Chker='''+Trim(DName)+'''');
          sql.Add(' where BGID='''+Trim(CDS_Main.fieldbyname('BGID').AsString)+'''');
          ExecSQL;
        end;
        CDS_Main.Delete;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    InitSubGrid();
  except
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBSHCXClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>3 then Exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行审核撤销操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate JYOrder_BaoGuan_Main Set Status=''已核对'',ChkTime=Null,Chker=Null');
          sql.Add(' where BGID='''+Trim(CDS_Main.fieldbyname('BGID').AsString)+'''');
          ExecSQL;
        end;
        CDS_Main.Delete;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    InitSubGrid();
  except
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmBaoGuanList.TBAllClick(Sender: TObject);
var
   fPrintFile:string;
   EngMoney,BZZH:string;
begin
  if CDS_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\全部报关资料.rmf';
  {if Trim(CDS_Main.fieldbyname('A1ChuKouShang').AsString)='绍兴宇玎纺织有限公司' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\全部报关资料YD.rmf';
  end else
  if Trim(CDS_Main.fieldbyname('A1ChuKouShang').AsString)='绍兴锦凤进出口有限公司' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\全部报关资料JF.rmf';
  end; }
  InitPrtData();
  RMXLSExport1:= TRMXLSExport.Create(RMXLSExport1);
  if FileExists(fPrintFile) then
  begin
    //RMVariables['enddate']:=enddate.DateTime;
    //RMVariables['printtime']:=Now;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\全部报关资料.rmf'),'提示',0);
  end;
end;

end.
