unit U_BaoguanList;

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, cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore,
  dxSkinsDefaultPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu,
  U_BaseList, RM_e_Graphic, RM_e_Jpeg, RM_E_llPDF, Vcl.Clipbrd, dxSkinWXI,
  dxScrollbarAnnotations;

type
  TfrmBaoguanList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    GPM_1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_1: TDataSource;
    v1ConNo: TcxGridDBColumn;
    CDS_2: TClientDataSet;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    v1Column4: TcxGridDBColumn;
    pm2: TPopupMenu;
    Panel1: TPanel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    PONO: TEdit;
    HZSCSName: TEdit;
    MPRTCodeName: TEdit;
    ConNo: TEdit;
    MPRTKZ: TEdit;
    MPRTMF: TEdit;
    cxTabControl1: TcxTabControl;
    tchk: TToolButton;
    Tnochk: TToolButton;
    cxSplitter1: TcxSplitter;
    DS_2: TDataSource;
    Label2: TLabel;
    Tqx: TToolButton;
    Tnoqx: TToolButton;
    v1Column9: TcxGridDBColumn;
    GPM_2: TcxGridPopupMenu;
    CDS_1: TClientDataSet;
    btnTijiao: TToolButton;
    btnCXTijiao: TToolButton;
    Label3: TLabel;
    FPNO: TEdit;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Label6: TLabel;
    HZSCSEName: TEdit;
    pm1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    btnWC: TToolButton;
    btnWCCX: TToolButton;
    Label7: TLabel;
    CKS: TEdit;
    ADOQueryImage: TADOQuery;
    IsJYTime: TCheckBox;
    ToolButton7: TToolButton;
    N3: TMenuItem;
    N4: TMenuItem;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    v1XHNo: TcxGridDBColumn;
    VC_SCSCode: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    v1PRTPrice: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    N5: TMenuItem;
    N6: TMenuItem;
    ADOQuery1: TADOQuery;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    Tv1Column17: TcxGridDBColumn;
    Tv1Column18: TcxGridDBColumn;
    Tv1Column19: TcxGridDBColumn;
    Tv1Column20: TcxGridDBColumn;
    Tv1Column21: TcxGridDBColumn;
    Tv1Column22: TcxGridDBColumn;
    Tv1Column23: TcxGridDBColumn;
    Tv1Column24: TcxGridDBColumn;
    Tv1Column25: TcxGridDBColumn;
    TV2Column1: TcxGridDBColumn;
    TV2Column2: TcxGridDBColumn;
    TV2Column3: TcxGridDBColumn;
    TV2Column4: TcxGridDBColumn;
    TV2Column5: TcxGridDBColumn;
    TV2Column6: TcxGridDBColumn;
    TV2Column7: TcxGridDBColumn;
    TV2Column8: TcxGridDBColumn;
    TV2Column9: TcxGridDBColumn;
    TV2Column10: TcxGridDBColumn;
    TV2Column11: TcxGridDBColumn;
    TV2Column12: TcxGridDBColumn;
    TV2Column13: TcxGridDBColumn;
    TV2Column14: TcxGridDBColumn;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    Tv1Column26: TcxGridDBColumn;
    Tv1Column27: TcxGridDBColumn;
    Tv1Column28: TcxGridDBColumn;
    Tv1Column29: TcxGridDBColumn;
    Tv1Column30: TcxGridDBColumn;
    Tv1Column31: TcxGridDBColumn;
    Tv1Column32: TcxGridDBColumn;
    N7: TMenuItem;
    N8: TMenuItem;
    N9: TMenuItem;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    N13: TMenuItem;
    N14: TMenuItem;
    N15: TMenuItem;
    N16: TMenuItem;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure BuyNameChange(Sender: TObject);
    procedure tchkClick(Sender: TObject);
    procedure TnochkClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure TqxClick(Sender: TObject);
    procedure TnoqxClick(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure btnTijiaoClick(Sender: TObject);
    procedure btnCXTijiaoClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure btnWCClick(Sender: TObject);
    procedure btnWCCXClick(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton7Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure N6Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure N7Click(Sender: TObject);
    procedure N8Click(Sender: TObject);
    procedure N9Click(Sender: TObject);
    procedure N10Click(Sender: TObject);
    procedure N11Click(Sender: TObject);
    procedure N12Click(Sender: TObject);
    procedure N13Click(Sender: TObject);
    procedure N14Click(Sender: TObject);
    procedure N15Click(Sender: TObject);
    procedure N16Click(Sender: TObject);
  private
    fFlileFlag: string;
    procedure InitGrid();
    procedure SetStatus();
    procedure SetYJ();
    procedure SetDQR();
    procedure SetYQR();
    procedure InitSub();
    procedure InitImage();

    { Private declarations }
  public
    FFInt, FCloth: Integer;
    FAuthority, FGSTT, FSubIdS: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_SalesConInPut, U_RTFun, U_AttachmentUpload, U_LabelPrint,
  U_BaoguanInPut;

{$R *.dfm}

procedure TfrmBaoguanList.InitImage();
begin

  ADOQueryImage.Close;
  if CDS_1.IsEmpty then
    exit;
  with ADOQueryImage do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where WBID=' + quotedstr(trim(CDS_1.fieldbyname('SubId').AsString)));
    sql.Add('and TFType=' + quotedstr(trim('HX')));
    open;
  end;
end;

procedure TfrmBaoguanList.InitSub();
begin

  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from Baoguan_sub A  ');
    sql.Add('where BGMID =' + quotedstr((CDS_1.fieldbyname('BGMID').AsString)));
    open;
  end;
  SCreateCDS(ADOQueryTemp, CDS_2);
  SInitCDSData(ADOQueryTemp, CDS_2);

end;

procedure TfrmBaoguanList.N10Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' Update BaoGuan_Main Set CDZFlag='''' where BGMID=''' + Trim(CDS_1.fieldbyname('BGMID').AsString) + '''');
    ExecSQL;
  end;
  InitGrid();

end;

procedure TfrmBaoguanList.N11Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' Update BaoGuan_Main Set FYFlag=''是'' where BGMID=''' + Trim(CDS_1.fieldbyname('BGMID').AsString) + '''');
    ExecSQL;
  end;
  InitGrid();

end;

procedure TfrmBaoguanList.N12Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' Update BaoGuan_Main Set FYFlag='''' where BGMID=''' + Trim(CDS_1.fieldbyname('BGMID').AsString) + '''');
    ExecSQL;
  end;
  InitGrid();

end;

procedure TfrmBaoguanList.N13Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' Update BaoGuan_Main Set DFFlag=''是'' where BGMID=''' + Trim(CDS_1.fieldbyname('BGMID').AsString) + '''');
    ExecSQL;
  end;
  InitGrid();

end;

procedure TfrmBaoguanList.N14Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' Update BaoGuan_Main Set DFFlag='''' where BGMID=''' + Trim(CDS_1.fieldbyname('BGMID').AsString) + '''');
    ExecSQL;
  end;
  InitGrid();

end;

procedure TfrmBaoguanList.N15Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' Update BaoGuan_Main Set FKFlag=''是'' where BGMID=''' + Trim(CDS_1.fieldbyname('BGMID').AsString) + '''');
    ExecSQL;
  end;
  InitGrid();

end;

procedure TfrmBaoguanList.N16Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' Update BaoGuan_Main Set FKFlag='''' where BGMID=''' + Trim(CDS_1.fieldbyname('BGMID').AsString) + '''');
    ExecSQL;
  end;
  InitGrid();

end;

procedure TfrmBaoguanList.N1Click(Sender: TObject);
begin
  SelOKNoFiler(Tv1, True); //全选
end;

procedure TfrmBaoguanList.N2Click(Sender: TObject);
begin
  SelOKNoFiler(Tv1, False); //全弃
end;

procedure TfrmBaoguanList.N3Click(Sender: TObject);
begin
//  Clipboard.SetTextBuf(PChar(Trim(CDS_1.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmBaoguanList.N4Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_1.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmBaoguanList.N5Click(Sender: TObject);
begin
  SelOKNo(CDS_1, True);
end;

procedure TfrmBaoguanList.N6Click(Sender: TObject);
begin
  SelOKNo(CDS_1, False);

end;

procedure TfrmBaoguanList.N7Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' Update BaoGuan_Main Set TDFlag=''是'' where BGMID=''' + Trim(CDS_1.fieldbyname('BGMID').AsString) + '''');
    ExecSQL;
  end;
  InitGrid();
end;

procedure TfrmBaoguanList.N8Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' Update BaoGuan_Main Set TDFlag='''' where BGMID=''' + Trim(CDS_1.fieldbyname('BGMID').AsString) + '''');
    ExecSQL;
  end;
  InitGrid();

end;

procedure TfrmBaoguanList.N9Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' Update BaoGuan_Main Set CDZFlag=''是'' where BGMID=''' + Trim(CDS_1.fieldbyname('BGMID').AsString) + '''');
    ExecSQL;
  end;
  InitGrid();

end;

procedure TfrmBaoguanList.SetStatus();
begin
  TBAdd.Enabled := false;
  tbedit.Enabled := false;
  ToolButton2.Enabled := false;
  ToolButton3.Enabled := false;  //确认
  ToolButton4.Enabled := false;  //撤销确认
  tchk.Enabled := false;
  tnochk.Enabled := false;
  Tqx.Enabled := false;
  TNoqx.Enabled := false;
  TBPrint.Enabled := False;
  btnTijiao.Enabled := False;
  btnCXTijiao.Enabled := False;
  btnWC.Enabled := False;
  btnWCCX.Enabled := False;
//  ToolButton3.Enabled := false;

  if Trim(FAuthority) = '业务' then
  begin
    ToolButton2.Enabled := true;
//    TBAdd.Enabled := true;
    TBPrint.Enabled := True;

    case cxTabControl1.TabIndex of
      0:
        begin
//          tbedit.Enabled := true;
//          Tqx.Enabled := True;
          btnTijiao.Enabled := True;
//          ToolButton3.Enabled := True;
//          SetDQR();
        end;
      1:
        begin
          tbedit.Enabled := True;
          btnCXTijiao.Enabled := True;
          tchk.Enabled := True;
        end;
      2:
        begin
//          tbedit.Enabled := True;
          tnochk.Enabled := True;

          Toolbutton3.Enabled := True;
          SetDQR();
        end;
      3:
        begin
          Toolbutton4.Enabled := true;
          btnWC.Enabled := true;
          SetYQR();
        end;
      4:
        begin
          btnWCCX.Enabled := true;
        end;

      5:
        begin
          TNoqx.Enabled := true;
        end;
    end;
  end;
  if Trim(FAuthority) = '管理' then
  begin
    ToolButton2.Enabled := true;
    TBAdd.Enabled := true;
    TBPrint.Enabled := True;
    case cxTabControl1.TabIndex of
      0:
        begin
          tbedit.Enabled := true;
          Tqx.Enabled := true;
          btnTijiao.Enabled := True;
//          ToolButton3.Enabled := True;
        end;
      1:
        begin
          tbedit.Enabled := True;
          btnCXTijiao.Enabled := True;
          tchk.Enabled := True;
//          ToolButton3.Enabled := True;
        end;
      2:
        begin
//          tbedit.Enabled := True;
          tnochk.Enabled := True;

          Toolbutton3.Enabled := True;

          SetDQR();
        end;
//      3:
//        begin
//          btnWCCX.Enabled := True;
//        end;
      3:
        begin
          Toolbutton4.Enabled := true;
          btnWC.Enabled := true;
          SetYQR();
        end;
      4:
        begin
          btnWCCX.Enabled := true;
        end;

      5:
        begin
          TNoqx.Enabled := true;
        end;
    end;
  end;
//  if Trim(FAuthority) = '查询' then
//  begin
//    TBPrint.Enabled := True;
//  end;
end;

procedure TfrmBaoguanList.SetYJ();
begin
  N7.Visible := False;
  N8.Visible := False;
  N9.Visible := False;
  N10.Visible := False;
  N11.Visible := False;
  N12.Visible := False;
  N13.Visible := False;
  N14.Visible := False;
  N15.Visible := False;
  N16.Visible := False;
end;

procedure TfrmBaoguanList.SetDQR();
begin
  N7.Visible := True;
  N8.Visible := True;
  N9.Visible := True;
  N10.Visible := True;
  N11.Visible := True;
  N12.Visible := True;

end;

procedure TfrmBaoguanList.SetYQR();
begin

  N13.Visible := True;
  N14.Visible := True;
  N15.Visible := True;
  N16.Visible := True;
end;

procedure TfrmBaoguanList.FormDestroy(Sender: TObject);
begin
  inherited;
//  frmContractListNX:=nil;
end;

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

procedure TfrmBaoguanList.FormCreate(Sender: TObject);
begin
  inherited;
  EndDate.DateTime := SGetServerDate(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 90;

end;

procedure TfrmBaoguanList.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmBaoguanList.InitGrid();
var
  WSql: string;
begin
  WSql := SGetFilters(Panel1, 1, 2);
  if trim(WSql) <> '' then
  begin
    WSql := ' and ' + trim(WSql);
  end;
//
//  if IsJYTime.Checked then
//  begin
//    WSql := WSql + ' and ConDate>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
//    WSql := WSql + ' and ConDate<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
//  end
//  else
//  begin
//    if trim(WSql) <> '' then
//      WSql := ' and 1=1' + trim(WSql)
//    else
//      WSql := WSql + ' and 1=2 ';
//  end;
//  if trim(WSql) = 'and 1=2' then
//    Application.MessageBox('勾选制单日期或填入搜索条件', '提示', 0);

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;

      sql.Add('select *,QRFJS=ISNULL((select Count(F.WBID) FJS from FJ_File F where F.TFType = ''确认件'' and F.WBID=A.BGMID ),0)');
      sql.Add(',ZBFJS=ISNULL((select Count(F.WBID) FJS from FJ_File F where F.TFType = ''正本件'' and F.WBID=A.BGMID ),0)');
      sql.Add(',ISTD=Cast((case when ISNULL(TDFlag,'''')='''' then 0 else 1 end) AS bit)');
      sql.Add(',ISCDZ=Cast((case when ISNULL(CDZFlag,'''')='''' then 0 else 1 end) AS bit)');
      sql.Add(',ISFY=Cast((case when ISNULL(FYFlag,'''')='''' then 0 else 1 end) AS bit)');
      sql.Add(',ISDF=Cast((case when ISNULL(DFFlag,'''')='''' then 0 else 1 end) AS bit)');
      sql.Add(',ISFK=Cast((case when ISNULL(FKFlag,'''')='''' then 0 else 1 end) AS bit)');
      sql.Add(',(Case A.Status when ''0'' then ''草稿件'' when ''1'' then ''正式件''');
      sql.Add('when ''5'' then ''待确认'' when ''9'' then ''已确认'' when ''10'' then ''已完成'' ');
      SQL.Add('when ''-1'' then ''垃圾件'' end) AS ZT from Baoguan_Main A');

      sql.Add('where 1=1 ' + (WSql));
      sql.Add(' and FPDate>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
      sql.Add(' and FPDate<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');

//      if Trim(FAuthority) = '录入' then
//      begin
//        sql.Add(' and ( AA.SalesId=' + quotedstr(trim(DCode)) + ' or AA.Filler =' + quotedstr(trim(DCode)) + '  or B.SalesId =' + quotedstr(trim(DCode)) + ' ');
//        sql.Add('or exists (select * from [dbo].[F_Tool_SplitString](AA.TallyId,'','') X where X.RTValue =' + quotedstr(trim(DCode)) + '))');
//      end;

      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(' and  isnull(A.status,''0'')=''0''');
          end;
        1:
          begin
            sql.Add(' and  isnull(A.status,''0'')=''1''');
          end;
        2:
          begin
            sql.Add(' and  isnull(A.status,''0'')=''5''');
          end;
        3:
          begin
            sql.Add(' and  isnull(A.status,''0'')=''9''');
          end;
        4:
          begin
            sql.Add(' and  isnull(A.status,''0'')=''10''');
          end;
        5:
          begin
            sql.Add(' and  isnull(A.status,''0'')=''-1''');
          end;
      end;
//      ShowMessage(sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
    TV1.DataController.Filter.Clear;

  end;
end;

procedure TfrmBaoguanList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmBaoguanList.TBPrintClick(Sender: TObject);
var
  WSql: string;
begin
  if CDS_1.IsEmpty then
    Exit;

  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'BaoGuanPrint';
      FFiltration1 := Trim(Self.CDS_1.fieldbyname('BGMID').AsString);
      if ShowModal = 1 then
      begin
//        Self.InitGrid();
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

end;

procedure TfrmBaoguanList.TBEditClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
//  ShowMessage(Trim(CDS_1.fieldbyname('Filler').AsString));
//  ShowMessage(Trim(DName));
//  if Trim(CDS_1.fieldbyname('Filler').AsString) <> Trim(DName) then
//  begin
//    Application.MessageBox('不能操作他人的数据!', '提示', 0);
//    Exit;
//  end;
  try
    frmBaoguanInPut := TfrmBaoguanInPut.Create(Application);
    with frmBaoguanInPut do
    begin
      PState := '修改';
      FBGMId := Trim(Self.CDS_1.fieldbyname('BGMID').AsString);
      FAuthority := self.FAuthority;
      FGSTT := self.FGSTT;
      fFlileFlag := self.fFlileFlag;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmBaoguanInPut.Free;
  end;
end;

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

procedure TfrmBaoguanList.TBAddClick(Sender: TObject);
var
  maxno: string;
begin
  try
    frmBaoguanInPut := TfrmBaoguanInPut.Create(Application);
    with frmBaoguanInPut do
    begin
      PState := '新增';
      FBGMId := '';
      FAuthority := self.FAuthority;
      FGSTT := self.FGSTT;
      fFlileFlag := self.fFlileFlag;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmBaoguanInPut.Free;
  end;
end;

procedure TfrmBaoguanList.FormShow(Sender: TObject);
begin
  inherited;
  fFlileFlag := UserDataFlag + 'HX';
  FAuthority := self.fParameters1;
  readCxGrid(trim(Self.Caption) + 'tv1', Tv1, '报关管理');
  readCxGrid(trim(Self.Caption) + 'tv2', Tv2, '报关管理');
  if Trim(FAuthority) = '业务' then
    cxTabControl1.TabIndex := 2;

  SetStatus();
  InitGrid();
end;

procedure TfrmBaoguanList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if ToolButton1.Visible = False then
    Exit;
  ToolButton1.Click;
end;

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

procedure TfrmBaoguanList.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

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

procedure TfrmBaoguanList.ToolButton1Click(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmBaoguanInPut := TfrmBaoguanInPut.Create(Application);
    with frmBaoguanInPut do
    begin
      PState := '查看';
      FBGMId := Trim(Self.CDS_1.fieldbyname('BGMID').AsString);
      FGSTT := self.FGSTT;
//      ToolBar2.Visible := False;
      TBSave.Visible := False;
//      ScrollBox1.Enabled := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmBaoguanInPut.Free;
  end;
end;

procedure TfrmBaoguanList.ToolButton2Click(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmBaoguanInPut := TfrmBaoguanInPut.Create(Application);
    with frmBaoguanInPut do
    begin
      PState := '复制';
      FBGMId := Trim(Self.CDS_1.fieldbyname('BGMID').AsString);
      FAuthority := self.FAuthority;
      fFlileFlag := self.fFlileFlag;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmBaoguanInPut.Free;
  end;
end;

procedure TfrmBaoguanList.ToolButton3Click(Sender: TObject);
var
  MBGMIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;
//  MBGMIDS := MBGMIDS + CDS_1.fieldbyname('BGMID').AsString + ',';
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MBGMIDS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MBGMIDS := MBGMIDS + trim(fieldbyname('BGMID').AsString) + ',';
      end;
      next;
    end;
    MBGMIDS := copy(MBGMIDS, 1, Length(MBGMIDS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_BaoGuan_SetStatus ');
      sql.Add(' @BGMIDS=' + QuotedStr(MBGMIDS));
      sql.Add(',@Operation=''确认'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('报关单确认')));
      sql.Add(',' + quotedstr(trim('报关单ID：' + trim(MBGMIDS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('确认成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmBaoguanList.ToolButton4Click(Sender: TObject);
var
  MBGMIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;
//  MBGMIDS := MBGMIDS + CDS_1.fieldbyname('BGMID').AsString + ',';
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MBGMIDS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MBGMIDS := MBGMIDS + trim(fieldbyname('BGMID').AsString) + ',';
      end;
      next;
    end;
    MBGMIDS := copy(MBGMIDS, 1, Length(MBGMIDS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_BaoGuan_SetStatus ');
      sql.Add(' @BGMIDS=' + QuotedStr(MBGMIDS));
      sql.Add(',@Operation=''撤销确认'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('报关单撤销确认')));
      sql.Add(',' + quotedstr(trim('报关单ID：' + trim(MBGMIDS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;

    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('撤销确认成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmBaoguanList.btnWCClick(Sender: TObject);
var
  MBGMIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;
//  if CDS_1.FieldByName('ISFJ').AsBoolean = False then
//  begin
//    application.MessageBox('请上传附件后完成合同', '提示');
//    Exit;
//  end;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MBGMIDS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MBGMIDS := MBGMIDS + trim(fieldbyname('BGMID').AsString) + ',';
      end;
      next;
    end;
    MBGMIDS := copy(MBGMIDS, 1, Length(MBGMIDS) - 1);
    EnableControls;
  end;
//  MBGMIDS := CDS_1.fieldbyname('BGMID').AsString;
  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_BaoGuan_SetStatus ');
      sql.Add(' @BGMIDS=' + QuotedStr(MBGMIDS));
      sql.Add(',@Operation=''完成'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('报关单完成')));
      sql.Add(',' + quotedstr(trim('报关单ID：' + trim(MBGMIDS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('完成成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmBaoguanList.BuyNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmBaoguanList.tchkClick(Sender: TObject);
var
  MBGMIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;
//  MBGMIDS := MBGMIDS + CDS_1.fieldbyname('BGMID').AsString + ',';
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MBGMIDS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MBGMIDS := MBGMIDS + trim(fieldbyname('BGMID').AsString) + ',';
      end;
      next;
    end;
    MBGMIDS := copy(MBGMIDS, 1, Length(MBGMIDS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_BaoGuan_SetStatus ');
      sql.Add(' @BGMIDS=' + QuotedStr(MBGMIDS));
      sql.Add(',@Operation=''提交'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('报关单提交')));
      sql.Add(',' + quotedstr(trim('报关单ID：' + trim(MBGMIDS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('提交成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmBaoguanList.TnochkClick(Sender: TObject);
var
  MBGMIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;
//  MBGMIDS := MBGMIDS + CDS_1.fieldbyname('BGMID').AsString + ',';
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MBGMIDS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MBGMIDS := MBGMIDS + trim(fieldbyname('BGMID').AsString) + ',';
      end;
      next;
    end;
    MBGMIDS := copy(MBGMIDS, 1, Length(MBGMIDS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_BaoGuan_SetStatus ');
      sql.Add(' @BGMIDS=' + QuotedStr(MBGMIDS));
      sql.Add(',@Operation=''撤销提交'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('报关单撤销提交')));
      sql.Add(',' + quotedstr(trim('报关单ID：' + trim(MBGMIDS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;

    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('撤销提交成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmBaoguanList.cxTabControl1Change(Sender: TObject);
begin
  SetYJ();
  SetStatus();
  TBRafresh.Click;
end;

procedure TfrmBaoguanList.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
//  if CDS_1.IsEmpty then
//    exit;
  InitSub();
end;

procedure TfrmBaoguanList.TqxClick(Sender: TObject);
var
  MBGMIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;
//  MBGMIDS := MBGMIDS + CDS_1.fieldbyname('BGMID').AsString + ',';
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MBGMIDS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MBGMIDS := MBGMIDS + trim(fieldbyname('BGMID').AsString) + ',';
      end;
      next;
    end;
    MBGMIDS := copy(MBGMIDS, 1, Length(MBGMIDS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_BaoGuan_SetStatus ');
      sql.Add(' @BGMIDS=' + QuotedStr(MBGMIDS));
      sql.Add(',@Operation=''取消'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('报关单取消')));
      sql.Add(',' + quotedstr(trim('报关单ID：' + trim(MBGMIDS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('取消成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmBaoguanList.TnoqxClick(Sender: TObject);
var
  MBGMIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;
//  MBGMIDS := MBGMIDS + CDS_1.fieldbyname('BGMID').AsString + ',';
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MBGMIDS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MBGMIDS := MBGMIDS + trim(fieldbyname('BGMID').AsString) + ',';
      end;
      next;
    end;
    MBGMIDS := copy(MBGMIDS, 1, Length(MBGMIDS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_BaoGuan_SetStatus ');
      sql.Add(' @BGMIDS=' + QuotedStr(MBGMIDS));
      sql.Add(',@Operation=''撤销取消'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('报关单取消')));
      sql.Add(',' + quotedstr(trim('报关单ID：' + trim(MBGMIDS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('撤销取消成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmBaoguanList.ToolButton5Click(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmAttachmentUpload := TfrmAttachmentUpload.Create(Application);
    with frmAttachmentUpload do
    begin
      if self.FAuthority = '业务' then
        FEditAuthority := False;
      if self.FAuthority = '管理' then
        FEditAuthority := True;

      fkeyNO := Trim(Self.CDS_1.fieldbyname('BGMID').AsString);
      fType := '确认件';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmAttachmentUpload.Free;
  end;
end;

procedure TfrmBaoguanList.ToolButton6Click(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmAttachmentUpload := TfrmAttachmentUpload.Create(Application);
    with frmAttachmentUpload do
    begin
      if self.FAuthority = '业务' then
        FEditAuthority := False;
      if self.FAuthority = '管理' then
        FEditAuthority := True;

      fkeyNO := Trim(Self.CDS_1.fieldbyname('BGMID').AsString);
      fType := '正本件';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmAttachmentUpload.Free;
  end;

end;

procedure TfrmBaoguanList.ToolButton7Click(Sender: TObject);
begin
  writeCxGrid(trim(Self.Caption) + 'tv1', Tv1, '报关管理');
  writeCxGrid(trim(Self.Caption) + 'tv2', Tv2, '报关管理');
end;

procedure TfrmBaoguanList.btnWCCXClick(Sender: TObject);
var
  MBGMIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MBGMIDS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MBGMIDS := MBGMIDS + trim(fieldbyname('BGMID').AsString) + ',';
      end;
      next;
    end;
    MBGMIDS := copy(MBGMIDS, 1, Length(MBGMIDS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_BaoGuan_SetStatus ');
      sql.Add(' @BGMIDS=' + QuotedStr(MBGMIDS));
      sql.Add(',@Operation=''撤销完成'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('报关单撤销完成')));
      sql.Add(',' + quotedstr(trim('报关单ID：' + trim(MBGMIDS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('撤销完成成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmBaoguanList.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
//  if AViewInfo.GridRecord.Values[tv1.GetColumnByFieldName('status').Index] = '2' then
//    ACanvas.Brush.Color := clLime;
//  if cxTabControl1.TabIndex=5 then
//  begin
//  if AViewInfo.GridRecord.Values[tv1.GetColumnByFieldName('status').Index] = '-1' then
//    ACanvas.Brush.Color := clBtnShadow;
//  end;
end;

procedure TfrmBaoguanList.btnTijiaoClick(Sender: TObject);
var
  MBGMIDS: string;
  i: Integer;
begin
  if CDS_1.IsEmpty then
    exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;

  with CDS_1 do
  begin
    DisableControls;
    First;
    MBGMIDS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MBGMIDS := MBGMIDS + trim(fieldbyname('BGMID').AsString) + ',';
      end;
      next;
    end;
    MBGMIDS := copy(MBGMIDS, 1, Length(MBGMIDS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_BaoGuan_SetStatus ');
      sql.Add(' @BGMIDS=' + QuotedStr(MBGMIDS));
      sql.Add(',@Operation=''转正'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('报关单转正式')));
      sql.Add(',' + quotedstr(trim('报关单ID：' + trim(MBGMIDS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('转正式成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmBaoguanList.btnCXTijiaoClick(Sender: TObject);
var
  MBGMIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MBGMIDS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MBGMIDS := MBGMIDS + trim(fieldbyname('BGMID').AsString) + ',';
      end;
      next;
    end;
    MBGMIDS := copy(MBGMIDS, 1, Length(MBGMIDS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_BaoGuan_SetStatus ');
      sql.Add(' @BGMIDS=' + QuotedStr(MBGMIDS));
      sql.Add(',@Operation=''转草稿'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('报关单转草稿')));
      sql.Add(',' + quotedstr(trim('报关单ID：' + trim(MBGMIDS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('转草稿成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

end.

