unit U_JYOrderCDCPList;

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, MovePanel, cxTextEdit,
  cxContainer, cxCurrencyEdit, BtnEdit, RM_e_main, RM_e_htm, RM_e_Graphic,
  RM_e_Jpeg, RM_e_txt, RM_e_csv, RM_E_llPDF, Math, Clipbrd, cxPC,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu;
type
  TfrmJYOrderCDCPList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    OrderNo: TEdit;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    conNO: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    MJID: TEdit;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    Label4: TLabel;
    MJType: TComboBox;
    v1Column13: TcxGridDBColumn;
    Label5: TLabel;
    MPRTCodeName: TEdit;
    Label6: TLabel;
    MJStr2: TComboBox;
    v1Column17: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    Label12: TLabel;
    factoryName: TEdit;
    v1Column20: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    Filler: TComboBox;
    TBManage: TToolButton;
    v1Column22: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    TBZF: TToolButton;
    ToolButton1: TToolButton;
    RM2: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    v1Column24: TcxGridDBColumn;
    MovePanel2: TMovePanel;
    v1Column27: TcxGridDBColumn;
    v1Column28: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    CDS_CD: TClientDataSet;
    RMCD: TRMGridReport;
    RMDBCD: TRMDBDataSet;
    CDS_LS: TClientDataSet;
    v1Column15: TcxGridDBColumn;
    ToolButton3: TToolButton;
    Panel2: TPanel;
    Label15: TLabel;
    cxCurrencyEdit1: TcxCurrencyEdit;
    Button1: TButton;
    Button2: TButton;
    v1MKXS: TcxGridDBColumn;
    Mjstr4: TEdit;
    PrtColor: TEdit;
    RM3: TRMGridReport;
    v1Column31: TcxGridDBColumn;
    ToolButton8: TToolButton;
    v1Column32: TcxGridDBColumn;
    v1Column33: TcxGridDBColumn;
    KHConNO: TEdit;
    Label19: TLabel;
    v1Column34: TcxGridDBColumn;
    v1Column36: TcxGridDBColumn;
    RMXLSExport1: TRMXLSExport;
    CDS_HZ: TClientDataSet;
    RMDBHZ: TRMDBDataSet;
    cxCurrencyEdit2: TcxCurrencyEdit;
    Label24: TLabel;
    Label25: TLabel;
    ComboBox4: TComboBox;
    RMDBPRT: TRMDBDataSet;
    CDS_PRT: TClientDataSet;
    ToolButton12: TToolButton;
    Panel5: TPanel;
    Label28: TLabel;
    ComboBox5: TComboBox;
    Button5: TButton;
    Button6: TButton;
    v1Column39: TcxGridDBColumn;
    Panel6: TPanel;
    Label31: TLabel;
    LBCPAP: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    TCBNOR: TComboBox;
    IsJYTime: TCheckBox;
    v1Column42: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    Label1: TLabel;
    RKOrdID: TEdit;
    N3: TMenuItem;
    ToolButton4: TToolButton;
    X1: TMenuItem;
    cxTabControl1: TcxTabControl;
    v1Column18: TcxGridDBColumn;
    B1: TToolButton;
    lbl1: TLabel;
    APID: TEdit;
    Label2: TLabel;
    RCGangNo: TEdit;
    v1Column25: TcxGridDBColumn;
    v1Column26: TcxGridDBColumn;
    TBSH: TToolButton;
    v1Column29: TcxGridDBColumn;
    TBHH: TToolButton;
    v1Column30: TcxGridDBColumn;
    v1Column35: TcxGridDBColumn;
    Label11: TLabel;
    lidan: TEdit;
    Label13: TLabel;
    YWY: TEdit;
    v1Column37: TcxGridDBColumn;
    v1Column38: TcxGridDBColumn;
    v1Column40: TcxGridDBColumn;
    Label14: TLabel;
    KuanHao: TEdit;
    v1Column41: TcxGridDBColumn;
    v1Column43: TcxGridDBColumn;
    v1Column44: TcxGridDBColumn;
    Label16: TLabel;
    IsOutRange: TEdit;
    ComboBox1: TComboBox;
    v1Column45: TcxGridDBColumn;
    v1Column46: TcxGridDBColumn;
    v1Column47: TcxGridDBColumn;
    v1Column48: TcxGridDBColumn;
    chkDP: TCheckBox;
    Label17: TLabel;
    PBLY: TEdit;
    v1Column49: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure TBManageClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBZFClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure v1Column15PropertiesEditValueChanged(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure MJIDKeyPress(Sender: TObject; var Key: Char);
    procedure Button6Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure ToolButton12Click(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure conNOKeyPress(Sender: TObject; var Key: Char);
    procedure MJStr2Change(Sender: TObject);
    procedure MJTypeChange(Sender: TObject);
    procedure KHConNOKeyPress(Sender: TObject; var Key: Char);
    procedure RKOrdIDKeyPress(Sender: TObject; var Key: Char);
    procedure N3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure X1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure B1Click(Sender: TObject);
    procedure TBSHClick(Sender: TObject);
    procedure TBHHClick(Sender: TObject);
    procedure chkDPClick(Sender: TObject);
  private
    DQdate: TDateTime;
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure InitForm();
    function Savedata(): Boolean;
    procedure GetCDSData();
    procedure SetStatus();
    procedure PrintCKMDG(MRKOrdID: string);
    { Private declarations }
  public
    FFInt: Integer;
    canshu1: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_OrderInPut, U_Fun, U_MJEdit, U_ZDYHelp, U_ProductOrderListSel,
  U_SysLogHelp,U_RTFun;

{$R *.dfm}
procedure TfrmJYOrderCDCPList.SetStatus();
begin
  TBManage.Visible := False;
  TBZF.Visible := False;
  v1Column15.Options.Focusing := False;
  ToolButton1.Visible := False;
  TBSH.Visible := False;
  TBHH.Visible := False;
  if ((Trim(canshu1) = '管理') or (Trim(canshu1) = '打卷工')) then
  begin
    TBManage.Visible := True;
    TBZF.Visible := True;
    v1Column15.Options.Focusing := True;
    ToolButton1.Visible := true;
    case cxTabControl1.TabIndex of
      0:
        begin
          ToolButton8.Visible := true;
          ToolButton4.Visible := false;
        end;
      1:
        begin
          ToolButton8.Visible := false;
          ToolButton4.Visible := true;
        end;
      2:
        begin
          ToolButton8.Visible := false;
          ToolButton4.Visible := true;
        end;
    end;
  end;
  if Trim(canshu1) = '次品管理' then
  begin
    TBZF.Visible := True;
    TBSH.Visible := True;
    TBHH.Visible := True;
  end;

end;

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

procedure TfrmJYOrderCDCPList.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
  DQdate := SGetServerDate(ADOQueryTemp);
end;

procedure TfrmJYOrderCDCPList.TBCloseClick(Sender: TObject);
begin
  if Trim(DName)='ADMIN' then
  begin
    WriteCxGridAll(trim(self.Caption), Tv1,ADOQueryCmd,ADOQueryTemp);
  end;
  Close;
end;

procedure TfrmJYOrderCDCPList.PrintCKMDG(MRKOrdID: string);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Order_Main.IsEmpty then
    Exit;
  ExportFtErpFile('仓库码单.rmf', ADOQueryTemp);
  with Order_Main do
  begin

    with ADOQueryPrint do
    begin
      Close;
      SQL.Clear;
      sql.Add(' exec P_Print_RKMDGangNo ');
      SQL.Add(' @RKOrdID=''' + Trim(MRKOrdID) + '''');
      Open;
    end;
    try
      Moudle := LoadLibrary('MakeQRBarcode.dll');
      @Makebar := GetProcAddress(Moudle, 'Make');
      @Mixtext := GetProcAddress(Moudle, 'MixText');
      Txt := Trim(ADOQueryPrint.fieldbyname('RKOrdID').AsString);
      fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
      if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
        CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
      if FileExists(fImagePath) then
        DeleteFile(fImagePath);
      Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
    except
      application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
      exit;
    end;
    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\仓库码单.rmf';
    if FileExists(fPrintFile) then
    begin
      RMVariables['QRBARCODE'] := fImagePath;
      RM2.LoadFromFile(fPrintFile);
      Rm2.DefaultCopies := strtointdef(trim(ComboBox1.Text), 1);
//      RM2.PrintReport;
      RM2.ShowReport;
    end
    else
    begin
      Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
      Exit;
    end;

  end;

end;

procedure TfrmJYOrderCDCPList.InitGrid();
var
  fwhere, Pwhere: string;
begin
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  if IsJYTime.Checked then
  begin
    fwhere := ' where Filltime>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
    fwhere := fwhere + ' and Filltime<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
  end;

  Pwhere := SGetFilters(Panel1, 1, 2);

  if trim(Pwhere) <> '' then
  begin
    case cxTabControl1.TabIndex of
      0:
        begin
          Pwhere := Pwhere + ' and MJStr2=''未入库'' ';
        end;
      1:
        begin
          Pwhere := Pwhere + ' and MJStr2<>''未入库'' ';
        end;
      2:
        begin
          if Trim(MJStr2.Text) <> '' then
          begin
            if Trim(MJStr2.Text) = '未出库' then
            begin
              Pwhere := Pwhere + ' and MJStr2<>''已出库'' ';
            end
            else
            begin
              Pwhere := Pwhere + ' and MJStr2=' + quotedstr(Trim(MJStr2.Text));
            end;
          end;

        end;
    end;
  end
  else
  begin
    case cxTabControl1.TabIndex of
      0:
        begin
          Pwhere := ' MJStr2=''未入库'' ';
        end;
      1:
        begin
          Pwhere := ' MJStr2<>''未入库'' ';
        end;
      2:
        begin
          if Trim(MJStr2.Text) <> '' then
          begin
            if Trim(MJStr2.Text) = '未出库' then
            begin
              Pwhere := '  MJStr2<>''已出库'' ';
            end
            else
            begin
              Pwhere := '  MJStr2=' + quotedstr(Trim(MJStr2.Text));
            end;
          end
          else
          begin
            Pwhere := ' 1=1 ';
          end;
        end;
    end;
  end;

//  if (canshu1 = '次品管理') or (canshu1 = '次品查询') then
//  begin
//    Pwhere := Pwhere + ' and MJType=''次品'' ';
//  end;
  if chkDP.Checked then
  begin
    //十公斤以上，米数20米
    Pwhere := Pwhere + ' and ( MJMaoZ>10 or MJLen>20 )';
  end;
  if canshu1 = '活货管理' then
  begin
    Pwhere := Pwhere + ' and MJType=''次品'' ';
    Pwhere := Pwhere + ' and ISQYCP=''活货'' ';
  end;
  if canshu1 = '死货管理' then
  begin
    Pwhere := Pwhere + ' and MJType=''次品'' ';
    Pwhere := Pwhere + ' and ISQYCP=''死货'' ';
  end;

  if trim(fwhere) <> '' then
  begin
    fwhere := fwhere + ' and ' + trim(Pwhere);
  end
  else
  begin
    fwhere := ' where ' + trim(Pwhere);
  end;

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_Page_ClothInfoCP ');
      sql.Add('@pageIndex=' + inttostr(CurrentPage));
      sql.Add(',@pageSize=' + inttostr(RecordsNumber));
      sql.Add(',@criteria= ' + quotedstr(fwhere));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
    LBCPAP.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(Order_Main.FieldByName('TotalCount').AsInteger / RecordsNumber));
    MovePanel2.Visible := false;
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
  end;
end;

procedure TfrmJYOrderCDCPList.InitForm();
var
  fsj: string;
begin
  ReadCxGridAll(trim(self.Caption), Tv1);
  fsj := 'select distinct(Filler) name from WFB_MJJY   ';
  SInitComBoxBySql(ADOQueryCmd, Filler, False, fsj);

  if canshu1 = '打卷工' then
  begin
    Filler.Clear;
    Filler.Items.Add(trim(DName));
    Filler.ItemIndex := Filler.Items.IndexOf(trim(DName));
    Filler.Enabled := False;
  end;

  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);

  if (canshu1 = '次品管理') or (canshu1 = '次品查询') then
  begin
    chkDP.Visible := True;
  end;

  if canshu1 = '次品查询' then
  begin
    BegDate.DateTime := EndDate.DateTime - 90;
    Filler.ItemIndex := Filler.Items.IndexOf('女工检验');
  end
  else
  begin
    BegDate.DateTime := EndDate.DateTime - 14;
  end;
  if canshu1 = '超范围' then
  begin
    IsOutRange.Text := '超范围';
  end;
    //InitGrid();
end;

procedure TfrmJYOrderCDCPList.TBFindClick(Sender: TObject);
var
  fsj, fwhere: string;
begin

end;

procedure TfrmJYOrderCDCPList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '检验报告');
end;

procedure TfrmJYOrderCDCPList.TBRafreshClick(Sender: TObject);
begin
  OrderNo.SetFocus;

  CurrentPage := 1;
  InitGrid();

end;

procedure TfrmJYOrderCDCPList.FormShow(Sender: TObject);
begin
  CurrentPage := 1;
  RecordsNumber := 500;
  InitForm();
  SetStatus();
end;

procedure TfrmJYOrderCDCPList.Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft := X;
  FTop := Y;
end;

procedure TfrmJYOrderCDCPList.TBManageClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_BanCP_CR where CRFlag=''入库'' and MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Order_Main.EnableControls;
    Application.MessageBox('已产生入库数据不能编辑!', '提示', 0);
    Exit;
  end;
  try
    frmMJEdit := TfrmMJEdit.Create(Application);
    with frmMJEdit do
    begin
      MJID.Text := Trim(Self.Order_Main.fieldbyname('MJID').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmMJEdit.Free;
  end;
end;

procedure TfrmJYOrderCDCPList.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main, True);
end;

procedure TfrmJYOrderCDCPList.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, False);
end;

procedure TfrmJYOrderCDCPList.TBZFClick(Sender: TObject);
var
  FSCRZ: string;
begin
  if Order_Main.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要作废数据吗？作废后数据不能恢复。', '提示', 32 + 4) <> IDYES then
    Exit;
  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      if Order_Main.FieldByName('SSel').AsBoolean = True then
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_BanCP_CR where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + ''' and CRFlag=''入库''');
          Open;
        end;
        if ADOQueryTemp.IsEmpty = False then
        begin
          Order_Main.EnableControls;
          Application.MessageBox('已产生入库数据不能删除!', '提示', 0);
          Exit;
        end
        else
        begin
          FSCRZ := '卷条码：' + trim(Order_Main.fieldbyname('MJID').AsString);
          FSCRZ := FSCRZ + ' 卷号：' + trim(Order_Main.fieldbyname('MJXH').AsString);
          FSCRZ := FSCRZ + ' 卡号：' + trim(Order_Main.fieldbyname('apid').AsString);
          FSCRZ := FSCRZ + ' 毛重：' + trim(Order_Main.fieldbyname('MJMaoZ').AsString);
          FSCRZ := FSCRZ + ' 净重：' + trim(Order_Main.fieldbyname('MJQty4').AsString);
          FSCRZ := FSCRZ + ' 长度：' + trim(Order_Main.fieldbyname('MJLen').AsString);

          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('delete WFB_MJJY where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('delete CK_BanCP_CR where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('delete CK_BanCP_KC where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('delete WFB_MJJY_CD where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            //更新开卡
            sql.Add('exec P_UPdate_LCKJY @APID=''' + trim(Order_Main.fieldbyname('APID').AsString) + '''');

            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(FSCRZ));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;
        end;
        Order_Main.Delete;
      end
      else
        Next;
    end;
  end;
  Order_Main.EnableControls;

end;

procedure TfrmJYOrderCDCPList.ToolButton1Click(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      if Order_Main.FieldByName('SSel').AsBoolean = True then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update WFB_MJJY Set PrtAgnFlag=1,PrtAgnDate=getdate(),PrtAgnPerson=''' + Trim(DName) + '''');
          sql.Add(' where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
          ExecSQL;
        end;
        with ADOQueryPrint do
        begin
          Close;
          SQL.Clear;
          sql.Add(' EXEC P_Print_JYLab ');
          SQL.Add(' @MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
          Open;
        end;
        try
          Moudle := LoadLibrary('MakeQRBarcode.dll');
          @Makebar := GetProcAddress(Moudle, 'Make');
          @Mixtext := GetProcAddress(Moudle, 'MixText');
          Txt := Trim(ADOQueryPrint.fieldbyname('MJID').AsString);
          fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
          if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
            CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
          if FileExists(fImagePath) then
            DeleteFile(fImagePath);
          Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
        except
          application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
          exit;
        end;

        if Trim(ADOQueryPrint.fieldbyname('LbName').AsString) <> '' then
        begin
          ExportFtErpFile(Trim(ADOQueryPrint.fieldbyname('LbName').AsString) + '.rmf', ADOQueryTemp);
          fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ADOQueryPrint.fieldbyname('LbName').AsString) + '.rmf'
        end
        else
        begin
          ExportFtErpFile('通用英文标签.rmf', ADOQueryTemp);
          fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\通用英文标签.rmf';
        end;

        if Trim(Order_Main.fieldbyname('MJType').AsString) = '次品' then
        begin
          ExportFtErpFile('次品标签.rmf', ADOQueryTemp);
          fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\次品标签.rmf';
        end;

        if FileExists(fPrintFile) then
        begin
          RMVariables['QRBARCODE'] := fImagePath;
          RM2.LoadFromFile(fPrintFile);
          Rm2.DefaultCopies := strtointdef(trim(ComboBox1.Text), 1);
          RM2.PrintReport;
        end
        else
        begin
          Order_Main.EnableControls;
          Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
          Exit;
        end;
      end;
      Next;
    end;
  end;
  Order_Main.EnableControls;
end;

function TfrmJYOrderCDCPList.Savedata(): Boolean;
var
  maxno, LLID: string;
  HXPS: Integer;
  HXQty, HXMQty: Double;
begin
  HXPS := 0;
  HXQty := 0;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select Top 1 * from Contract_Cloth_LL where OrdSubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
    sql.Add(' and FirstName=''' + Trim(Order_Main.fieldbyname('AOrddefstr4').AsString) + '''');
    Open;
  end;
  LLID := Trim(ADOQueryTemp.fieldbyname('LLID').AsString);
  if Trim(LLID) = '' then
  begin
    Result := False;
    Application.MessageBox('没有相对应的加工厂!', '提示', 0);
    Exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd, maxno, 'HX', 'Contract_Cloth_BefChkHX', 2, 1) = False then
    begin
      Result := False;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取回修最大号失败!', '提示', 0);
      Exit;
    end;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Order_Main.FieldByName('SSel').AsBoolean = True then
        begin
          HXPS := HXPS + 1;
          HXQty := HXQty + Order_Main.FieldByName('MJLen').Value;
        end;
        Next;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('');
      Open;
    end;
  except
  end;
end;

procedure TfrmJYOrderCDCPList.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(OrderNo.Text) < 4 then
      Exit;
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYOrderCDCPList.GetCDSData();
begin
  CDS_CD.FieldByName('MJXH').Value := CDS_LS.fieldbyname('MJXH').Value;
  CDS_CD.FieldByName('GangNo').Value := CDS_LS.fieldbyname('Aorddefstr1').Value;
  CDS_CD.FieldByName('PRTColor').Value := CDS_LS.fieldbyname('PRTColor').Value;
  CDS_CD.FieldByName('PRTEColor').Value := CDS_LS.fieldbyname('SOrddefstr4').Value;
  CDS_CD.FieldByName('MJLen').Value := CDS_LS.fieldbyname('MJLen').Value;
  CDS_CD.FieldByName('MJJZ').Value := CDS_LS.fieldbyname('MJQty4').Value;
  CDS_CD.FieldByName('MJMZ').Value := CDS_LS.fieldbyname('MJMaoZ').Value;
  CDS_CD.FieldByName('MJFK').Value := CDS_LS.fieldbyname('MJFK').Value;
  CDS_CD.FieldByName('KFQtyHZ').Value := CDS_LS.fieldbyname('KFQtyHZ').Value;
  CDS_CD.FieldByName('DengJi').Value := CDS_LS.fieldbyname('DengJi').Value;
  CDS_CD.FieldByName('PanDing').Value := CDS_LS.fieldbyname('PanDing').Value;
  CDS_CD.FieldByName('MJID').Value := CDS_LS.fieldbyname('MJID').Value;
end;

procedure TfrmJYOrderCDCPList.v1Column15PropertiesEditValueChanged(Sender: TObject);
var
  mvalue: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  with Order_Main do
  begin
    Edit;
    FieldByName('PanDing').Value := Trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate WFB_MJJY Set PanDing=''' + Trim(mvalue) + '''');
    SQL.Add(' where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
    ExecSQL;
  end;
end;

procedure TfrmJYOrderCDCPList.Button2Click(Sender: TObject);
begin
  Panel2.Visible := false;
end;

procedure TfrmJYOrderCDCPList.Button1Click(Sender: TObject);
var
  i, J: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if trim(ComboBox4.Text) = '' then
  begin
    Application.MessageBox('换算类型不能为空!', '提示', 0);
    Exit;
  end;
  i := floattostr(strtofloatdef(trim(cxCurrencyEdit1.Text), 0));
  J := floattostr(strtofloatdef(trim(cxCurrencyEdit2.Text), 0));
  try
    Order_Main.DisableControls;
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Order_Main.FieldByName('SSel').AsBoolean = True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
     //     sql.Add('Update WFB_MJJY Set MKXs='''+trim(i)+''',MJLen=cast(1.00000* MJQty4 *'''+trim(i)+''' as decimal(18,1))  ');
            if trim(ComboBox4.Text) = '长度换算净重' then
            begin
              sql.Add('Update WFB_MJJY Set MKXs=''' + trim(i) + ''',MJQty3=''' + trim(J) + ''',MJQty4=cast(1.00000* MJlen *''' + trim(i) + ''' as decimal(18,1))  ');
              sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
              sql.Add('Update WFB_MJJY Set MJMaoZ=MJQty4+MJQty3  ');
              sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');

              SQL.Add('Update CK_BanCP_CR set KGQty=B.MJMaoZ from CK_BanCP_CR A');
              SQL.Add('INNER JOIN WFB_MJJY B ON B.MJID=A.MJID ');
              SQL.Add('WHERE A.MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');

              SQL.Add('Update CK_BanCP_KC set KGQty=B.MJMaoZ from CK_BanCP_KC A');
              SQL.Add('INNER JOIN WFB_MJJY B ON B.MJID=A.MJID ');
              SQL.Add('WHERE A.MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            end;
            if trim(ComboBox4.Text) = '净重换算长度' then
            begin
              sql.Add('Update WFB_MJJY Set MKXs=''' + trim(i) + ''',MJQty3=''' + trim(J) + ''',MJlen=cast(1.00000* MJQty4 *''' + trim(i) + ''' as decimal(18,0))  ');
              sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
              sql.Add('Update WFB_MJJY Set MJMaoZ=MJQty4+MJQty3  ');
              sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');

              SQL.Add('Update CK_BanCP_CR set KGQty=B.MJMaoZ,Qty=B.MJLen from CK_BanCP_CR A');
              SQL.Add('INNER JOIN WFB_MJJY B ON B.MJID=A.MJID ');
              SQL.Add('WHERE A.MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');

              SQL.Add('Update CK_BanCP_KC set KGQty=B.MJMaoZ,Qty=B.MJLen from CK_BanCP_KC A');
              SQL.Add('INNER JOIN WFB_MJJY B ON B.MJID=A.MJID ');
              SQL.Add('WHERE A.MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            end;
            ExecSQL;
          end;
        end;
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据保存成功！', '提示信息');
    Panel2.Visible := false;
    TBRafresh.Click;
    exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据保存失败！', '提示信息', 0);
  end;
end;

procedure TfrmJYOrderCDCPList.ToolButton3Click(Sender: TObject);
begin
  Panel2.Left := (self.Width - Panel2.Width) div 2;
  Panel2.Visible := true;
end;

procedure TfrmJYOrderCDCPList.MJIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(MJID.Text) < 4 then
      Exit;
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYOrderCDCPList.Button6Click(Sender: TObject);
begin
  Panel5.Visible := false;
end;

procedure TfrmJYOrderCDCPList.Button5Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if trim(ComboBox5.Text) = '' then
  begin
    Application.MessageBox('数量单位不能为空!', '提示', 0);
    Exit;
  end;
  try
    Order_Main.DisableControls;
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Order_Main.FieldByName('SSel').AsBoolean = True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update WFB_MJJY Set MJTypeOther=''' + trim(ComboBox5.Text) + ''' ');
            sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('Update CK_BanCP_CR Set QtyUnit=''' + trim(ComboBox5.Text) + ''' ');
            sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('Update CK_BanCP_KC Set kcQtyUnit=''' + trim(ComboBox5.Text) + ''' ');
            sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            ExecSQL;
          end;
        end;
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据保存成功！', '提示信息');
    Panel2.Visible := false;
    TBRafresh.Click;
    exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据保存失败！', '提示信息', 0);
  end;
end;

procedure TfrmJYOrderCDCPList.ToolButton12Click(Sender: TObject);
begin
  Panel5.Visible := true;
end;

procedure TfrmJYOrderCDCPList.BTLPClick(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
end;

procedure TfrmJYOrderCDCPList.BTNPClick(Sender: TObject);
begin
  if CurrentPage < Order_Main.FieldByName('TotalCount').AsInteger / RecordsNumber then
    CurrentPage := CurrentPage + 1;
  InitGrid();
end;

procedure TfrmJYOrderCDCPList.TCBNORChange(Sender: TObject);
begin
  RecordsNumber := StrToInt(TCBNOR.Text);
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmJYOrderCDCPList.ToolButton8Click(Sender: TObject);
var
  SRKOrdID, strsql: string;
begin
  if cxTabControl1.TabIndex <> 0 then
    exit;
  ToolButton8.Enabled := false;
  ExportFtErpFile('仓库码单.rmf', ADOQueryTemp);
  if Order_Main.IsEmpty then
  begin
    ToolButton8.Enabled := True;
    Exit;
  end;

  if Order_Main.Locate('SSel', True, []) = False then
  begin
    ToolButton8.Enabled := True;
    Exit;
  end;
  if Application.MessageBox('确定要打印仓库码单么。', '提示', 32 + 4) <> IDYES then
  begin
    ToolButton8.Enabled := True;
    Exit;
  end;
  if GetLSNo(ADOQueryTemp, SRKOrdID, 'RK', 'CK_BanCP_CR', 4, 1) = False then
  begin
    Application.MessageBox('生成流水号异常！', '提示', 0);
    ToolButton8.Enabled := True;
    Exit;
  end;
  try
    Order_Main.DisableControls;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete TbForBatch where DName=' + quotedstr(Trim(DName)));
      SQL.Add('and MainType=' + quotedstr('仓库打码'));
      ExecSQL;
    end;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Order_Main.FieldByName('SSel').AsBoolean then
        begin
          strsql := '卷ID：' + trim(Order_Main.FieldByName('MJID').AsString) + '原入库单号：' + trim(Order_Main.FieldByName('RKOrdID').AsString) + '新入库单号：' + trim(SRKOrdID);
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            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(strsql)));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          with Self.ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' insert into TbForBatch(DName,MainType,Value1,MJID) ');
            sql.Add(' values( ' + quotedstr(Trim(DName)) + ',' + quotedstr('仓库打码') + ',' + quotedstr(Trim(SRKOrdID)) + ',' + quotedstr(Trim(Self.Order_Main.FieldByName('MJID').AsString)) + ')');
            ExecSQL;
          end;
        end;
        Next;
      end;
    end;
    with Self.ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE CK_BanCP_CR Set  ');
      sql.add('RKOrdID=A.Value1  ');
      sql.Add('FROM TbForBatch A where CK_BanCP_CR.MJID=A.MJID  ');
      SQL.Add('and A.MainType=''仓库打码'' and A.DName=' + quotedstr(trim(DName)));
      sql.Add('and CK_BanCP_CR.CRFlag in (''待入库'',''待出库'') ');

      sql.Add('UPDATE CK_BanCP_CR Set  ');
      sql.add(' CRTime=getdate(),CRType=''检验入库'',CRFlag=''入库''  ');
      sql.Add('FROM TbForBatch A where CK_BanCP_CR.MJID=A.MJID  ');
      SQL.Add('and A.MainType=''仓库打码'' and A.DName=' + quotedstr(trim(DName)));
      sql.Add('and CK_BanCP_CR.CRFlag=''待入库''  ');

      sql.Add('UPDATE WFB_MJJY Set  ');
      sql.add('RKOrdID=A.Value1 ,MJStr2=''已入库'' ');
      sql.Add('FROM TbForBatch A where WFB_MJJY.MJID=A.MJID  ');
      SQL.Add('and A.MainType=''仓库打码'' and A.DName=' + quotedstr(trim(DName)));
      SQL.Add('and WFB_MJJY.MJStr2=''未入库'' ');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    if Application.MessageBox('入库完成是否打印码单！！', '提示', 32 + 4) = IDYES then
    begin
      PrintCKMDG(Trim(SRKOrdID));
    end;
    TBRafresh.Click;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    ToolButton8.Enabled := true;
    application.MessageBox('数据撤销失败！', '提示信息', 0);
  end;
  ToolButton8.Enabled := true;
end;

procedure TfrmJYOrderCDCPList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  Clipboard.SetTextBuf(PChar(Trim(Order_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmJYOrderCDCPList.conNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYOrderCDCPList.MJStr2Change(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmJYOrderCDCPList.MJTypeChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmJYOrderCDCPList.KHConNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYOrderCDCPList.RKOrdIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmJYOrderCDCPList.N3Click(Sender: TObject);
var
  SSubId, SGangNo: string;
begin

  with Order_Main do
  begin
    SSubId := trim(FieldByName('SubId').AsString);
    SGangNo := trim(FieldByName('Mjstr4').AsString);
    Order_Main.DisableControls;
    first;
    while not eof do
    begin
      if ((SSubId = trim(FieldByName('SubId').AsString)) and (SGangNo = trim(FieldByName('Mjstr4').AsString))) then
      begin
        edit;
        FieldByName('SSel').value := true;
        Post;
      end
      else
      begin
        edit;
        FieldByName('SSel').value := false;
        Post;
      end;
      Next;
    end;
    Order_Main.Locate('SubId;Mjstr4', VarArrayOf([SSubId, SGangNo]), []);
    Order_Main.EnableControls;
  end;
end;

procedure TfrmJYOrderCDCPList.ToolButton4Click(Sender: TObject);
begin
  if Trim(Order_Main.fieldbyname('RKOrdID').AsString) = '' then
    exit;
  PrintCKMDG(Trim(Order_Main.fieldbyname('RKOrdID').AsString));
end;

procedure TfrmJYOrderCDCPList.X1Click(Sender: TObject);
var
  str, SSubId, SGangNo: string;
  ZChiShu, DQChiShu: integer;
  ISSel: boolean;
begin
  ISSel := true;
  SSubId := trim(Order_Main.FieldByName('SubId').AsString);
  SGangNo := trim(Order_Main.FieldByName('Mjstr4').AsString);
  str := '';
  if InputQuery('选择', '请输入数字', str) then
  begin
    ZChiShu := strtointdef(str, 0);
    if ZChiShu <= 0 then
      exit;

    with Order_Main do
    begin

      Order_Main.DisableControls;
      first;
      DQChiShu := 0;
      while not eof do
      begin

        if ((SSubId = trim(FieldByName('SubId').AsString)) and (SGangNo = trim(FieldByName('Mjstr4').AsString))) then
        begin
          edit;
          FieldByName('SSel').value := ISSel;
          DQChiShu := DQChiShu + 1;
          Post;
        end
        else
        begin
          edit;
          FieldByName('SSel').value := false;
          Post;
        end;
        if DQChiShu = ZChiShu then
          ISSel := false;
        Next;
      end;
      Order_Main.Locate('SubId;Mjstr4', VarArrayOf([SSubId, SGangNo]), []);
      Order_Main.EnableControls;
    end;
  end;

end;

procedure TfrmJYOrderCDCPList.cxTabControl1Change(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
  SetStatus();
end;

procedure TfrmJYOrderCDCPList.B1Click(Sender: TObject);
begin
  frmSysLogHelp := TfrmSysLogHelp.create(self);
  with frmSysLogHelp do
  begin
    fModel := self.caption;
  //  facction:='生产指示单删除';
    showmodal;
    free;
  end;
end;

procedure TfrmJYOrderCDCPList.TBSHClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  try
    Order_Main.DisableControls;
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Order_Main.FieldByName('SSel').AsBoolean = True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update WFB_MJJY Set ISQYCP=''死货'' ');
            sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('Update CK_BanCP_CR Set ISQYCP=''死货'' ');
            sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            ExecSQL;
          end;
        end;
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据修改成功！', '提示信息');
    TBRafresh.Click;
    exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据修改失败！', '提示信息', 0);
  end;
end;

procedure TfrmJYOrderCDCPList.TBHHClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  try
    Order_Main.DisableControls;
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Order_Main.FieldByName('SSel').AsBoolean = True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update WFB_MJJY Set ISQYCP=''活货'' ');
            sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add('Update CK_BanCP_CR Set ISQYCP=''活货'' ');
            sql.Add('where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
            ExecSQL;
          end;
        end;
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据修改成功！', '提示信息');
    TBRafresh.Click;
    exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox('数据修改失败！', '提示信息', 0);
  end;
end;

procedure TfrmJYOrderCDCPList.chkDPClick(Sender: TObject);
begin
  OrderNo.SetFocus;

  CurrentPage := 1;
  InitGrid();

end;

end.

