unit U_CKProductBCPKCList;

interface

uses
  Windows, Messages, SysUtils,strUtils, 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, BtnEdit, cxTextEdit, cxButtonEdit, cxDropDownEdit, MovePanel,
  cxContainer, cxCurrencyEdit;

type
  TfrmCKProductBCPKCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    C_CodeName: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label5: TLabel;
    conNo: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    v1Column7: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label8: TLabel;
    KZ: TEdit;
    Label9: TLabel;
    MF: TEdit;
    Label7: TLabel;
    CPType: TComboBox;
    v1Column3: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    Panel4: TPanel;
    Label11: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    RichEdit1: TRichEdit;
    MovePanel2: TMovePanel;
    v1gangNO: TcxGridDBColumn;
    v1C_Color: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    Label10: TLabel;
    C_Color: TEdit;
    Label4: TLabel;
    AOrdDefStr1: TEdit;
    TBKWChg: TToolButton;
    kcKw1: TBtnEditA;
    v1Column11: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    v1KCROllNum: TcxGridDBColumn;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    Edit1: TEdit;
    Label12: TLabel;
    Edit2: TEdit;
    AdoPrint: TADOQuery;
    RMDB_MD: TRMDBDataSet;
    RMGridReport1: TRMGridReport;
    RMXLSExport2: TRMXLSExport;
    ToolButton4: TToolButton;
    ADOQueryPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    CheckBox1: TCheckBox;
    ToolButton5: TToolButton;
    ADOQueryTmp: TADOQuery;
    v1Column12: TcxGridDBColumn;
    Panel2: TPanel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    editoldpm: TEdit;
    editnewpm: TEdit;
    editoldYS: TEdit;
    editnewYs: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    ToolButton6: TToolButton;
    KCKW: TEdit;
    Label17: TLabel;
    C_CodeNameZw: TEdit;
    Label18: TLabel;
    BCKZ1: TEdit;
    Label19: TLabel;
    editnewKZ: TEdit;
    Label20: TLabel;
    Button4: TButton;
    v1Column13: TcxGridDBColumn;
    batchNo: TEdit;
    Label21: TLabel;
    editNewbatchNo: TEdit;
    Label22: TLabel;
    Button5: TButton;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    factoryName: TEdit;
    Label23: TLabel;
    Label24: TLabel;
    ComCPType: TComboBox;
    Button6: TButton;
    v1Column16: TcxGridDBColumn;
    PDFlag: TEdit;
    Label25: TLabel;
    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 C_CodeNameChange(Sender: TObject);
    procedure Panel10MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image2Click(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBKWChgClick(Sender: TObject);
    procedure kcKw1BtnClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure kcKw1Exit(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure v1Column5PropertiesEditValueChanged(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure editnewpmExit(Sender: TObject);
    procedure editnewYsExit(Sender: TObject);
    procedure Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo;
      var ADone: Boolean);
    procedure Button6Click(Sender: TObject);
  private
    TblCprk :string;
    FLeft,FTop:Integer;
    procedure InitGrid();
    { Private declarations }
  public
    fckName:string;
    procedure CreateTable();
    procedure DropTable();
    { Public declarations }
  end;

var
  frmCKProductBCPKCList: TfrmCKProductBCPKCList;


implementation
uses
  U_DataLink,U_Fun, U_ZDYHelp, U_kcchEdit, U_KCEdit;

{$R *.dfm}

procedure TfrmCKProductBCPKCList.DropTable();
var
  strSQL:string;
begin
 // TblCprk := '[##CP_INOut123' + trim(DCode) + IntToStr(Handle)+formatdatetime('hhnnsszzz',time) + ']';
	//创建临时表
  strSQL := 'IF OBJECT_ID(''tempdb..' + TblCprk + ''') IS NOT NULL DROP TABLE ' + TblCprk;
	with ADOQueryCmd do
	begin
		Close;
		SQL.Clear;
		SQL.Add(strSQL);
		ExecSQL;
	end;
end;
procedure TfrmCKProductBCPKCList.CreateTable();
var
  strSQL:string;
begin
  TblCprk := '[##CP_PPack' + trim(DCode) + IntToStr(Handle)+formatdatetime('hhnnsszzz',time) + ']';
	//创建临时表
  strSQL := 'IF OBJECT_ID(''tempdb..' + TblCprk + ''') IS NOT NULL DROP TABLE ' + TblCprk + #13
			    + 'CREATE TABLE ' + TblCprk + ' ('
			    + 'MainID VARCHAR(20),'
          + 'CRID  VARCHAR(20),'
          + 'BCID   Varchar(20))'#13;
	with ADOQueryCmd do
	begin
		Close;
		SQL.Clear;
		SQL.Add(strSQL);
		ExecSQL;
	end;
end;

procedure TfrmCKProductBCPKCList.FormDestroy(Sender: TObject);
begin
  frmCKProductBCPKCList:=nil;
end;

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

procedure TfrmCKProductBCPKCList.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  BegDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp)
end;

procedure TfrmCKProductBCPKCList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      SQL.Add('exec P_View_CPKCMX');
      SQl.Add('@ConNo='+quotedstr(trim(conNo.Text)));
      SQl.Add(',@C_CodeName='+quotedstr(trim(C_CodeName.Text)));
      SQl.Add(',@C_Color='+quotedstr(trim(C_Color.Text)));
      SQl.Add(',@ckName='+quotedstr(trim(fckName)));
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  TBFind.Click;
end;

procedure TfrmCKProductBCPKCList.TBRafreshClick(Sender: TObject);
begin
 // BegDate.SetFocus;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  InitGrid();

  MovePanel2.Visible:=False;
end;

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

procedure TfrmCKProductBCPKCList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('仓库库存列表1',Tv1,'成品仓库');
  Close;
end;

procedure TfrmCKProductBCPKCList.FormShow(Sender: TObject);
begin
  ReadCxGrid('仓库库存列表1',Tv1,'成品仓库');
  if Trim(DParameters1)<>'高权限' then
  begin
    TBKWChg.Visible:=False;
    kcKw1.Visible:=False;
    ToolButton1.Visible:=fALSE;
    ToolButton2.Visible:=false;
    v2Column6.Options.Editing:=false;
    v1Column5.Options.Editing:=TRUE;
    ToolButton3.Visible:=false;
    ToolButton5.Visible:=false;
    ToolButton6.Visible:=false;
  end else
  begin
    TBKWChg.Visible:=True;
    kcKw1.Visible:=True;
    ToolButton1.Visible:=fALSE;
    ToolButton2.Visible:=fALSE;
    v2Column6.Options.Editing:=true;
    v1Column5.Options.Editing:=TRUE;
    ToolButton3.Visible:=true;
    ToolButton5.Visible:=true;
    ToolButton6.Visible:=true;
  end;
  
  //InitGrid();
end;

procedure TfrmCKProductBCPKCList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('库存列表',cxGrid2);
end;

procedure TfrmCKProductBCPKCList.TBFindClick(Sender: TObject);
var
  strwhere:string;
begin

  if ADOQueryMain.Active then
  begin
    strwhere:=  SGetFilters(Panel1,1,2);

    if (trim(strwhere)='') and (trim(Edit1.Text)<>'') then
    begin
      strwhere:=' KCQty>='+floattostr(strtofloatdef(trim(edit1.Text),0));
    end
    else
    if (trim(strwhere)<>'') and (trim(Edit1.Text)<>'') then
    begin
      strwhere:=strwhere+' and KCQty>='+floattostr(strtofloatdef(trim(edit1.Text),0));
    end;

    if (trim(strwhere)='') and (trim(Edit2.Text)<>'') then
    begin
      strwhere:=' KCQty<='+floattostr(strtofloatdef(trim(Edit2.Text),0));
    end
    else
    if (trim(strwhere)<>'') and (trim(Edit2.Text)<>'') then
    begin
      strwhere:=strwhere+' and KCQty<='+floattostr(strtofloatdef(trim(Edit2.Text),0));
    end;


 {   if (trim(strwhere)='')  then
    begin

      IF trim(CPType.Text)='正品' then
      strwhere:=' CPType=''正品'' ';
      IF trim(CPType.Text)='次品' then
      strwhere:=' CPType<>''正品'' ';
    end;

    if (trim(strwhere)<>'')  then
    begin

      IF trim(CPType.Text)='正品' then
      strwhere:=strwhere+' and CPType=''正品'' ';
      IF trim(CPType.Text)='次品' then
      strwhere:=strwhere+' and CPType<>''正品'' ';
    end;  }

    SDofilter(ADOQueryMain,strwhere);
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;

end;

procedure TfrmCKProductBCPKCList.C_CodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKProductBCPKCList.Panel10MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  TWinControl(Panel4).Perform(WM_SYSCOMMAND,$F012,0);
end;

procedure TfrmCKProductBCPKCList.Image2Click(Sender: TObject);
begin
  Panel4.Visible:=False;
end;

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

procedure TfrmCKProductBCPKCList.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  {if Trim(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName)<>'CDQK' then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select CDQK=dbo.F_Get_Order_SubStr(:MJID,''MJCDHZSL'')');
    Parameters.ParamByName('MJID').Value:=Trim(CDS_Main.fieldbyname('MJID').AsString);
    Open;
  end;
  with CDS_Main do
  begin
    Edit;
    FieldByName('CDQK').Value:=Trim(ADOQueryTemp.fieldbyname('CDQK').AsString);
    Post;
  end; }
  Panel4.Left:=FLeft;
  Panel4.Top:=FTop+110;
  Panel4.Visible:=True;
  Panel4.Refresh;
  Panel10.Caption:=Trim(TV1.Controller.FocusedColumn.Caption);

  RichEdit1.Text:=CDS_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString;
end;

procedure TfrmCKProductBCPKCList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,True);
end;

procedure TfrmCKProductBCPKCList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,False);
end;

procedure TfrmCKProductBCPKCList.TBKWChgClick(Sender: TObject);
begin
  if not CDS_Main.Active then exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
 { if Trim(kcKw.Text)='' then
  begin
    Application.MessageBox('缸号不能为空!','提示',0);
    Exit;
  end;  }
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  conNo.SetFocus;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      while CDS_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update CK_BanCP_CR Set BCGANGnO='''+Trim(kcKw1.Text)+'''');
          sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
          sql.Add('Update CK_BanCP_KC Set BCGANGnO='''+Trim(kcKw1.Text)+'''');
          sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
          ExecSQL;
        end;
        Edit;
        FieldByName('SSel').Value:=False;
        FieldByName('AOrdDefStr1').Value:=Trim(kcKw1.Text);
        Post;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('操作成功!','提示',0);
    Exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmCKProductBCPKCList.kcKw1BtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CPKWFlag';
      flagname:='库位信息';
      V1Name.Caption:='库位名称';
      V1Note.Caption:='英文名称';
//      MainType:=Trim(DName);
      fnote:=FALSE;
      if ShowModal=1 then
      begin
        kcKw1.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCKProductBCPKCList.ToolButton1Click(Sender: TObject);
var
  CRID:integer;
  i,J:integer;
  fAPTM:string;
  Isedit:boolean;
  RollNum1:integer;
  num1:double;
  fBCID,FCRID:string;
begin
  if not CDS_Main.Active then exit;
  if CDS_Main.IsEmpty then exit;
  isEdit:=false;
  frmkcchEdit:=TfrmkcchEdit.create(self);
  with frmkcchEdit do
  begin
   // fBCID:=trim(CDS_Main.fieldbyname('BCID').AsString);
  //  FCRID:=trim(CDS_Main.fieldbyname('CRID').AsString);
    edit1.text:=trim(CDS_Main.fieldbyname('KCROllNum').AsString);
    edit2.text:=trim(CDS_Main.fieldbyname('KCqty').AsString);
    if showmodal=1 then
    begin
      RollNum1:=strtointdef(cxCurrencyEdit1.Text,0);
      num1:=strtofloatdef(cxCurrencyEdit2.Text,0);
    //  i:=RadioGroup1.ItemIndex;
      isEdit:=true;
    end;
    free;
  end;

  IF RollNum1<1 then exit;
  IF Isedit=false then exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      while CDS_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryTemp do
        begin
          close;
          sql.Clear;
          sql.Add(' select * from  CK_BanCP_KC  ');
          sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
        //  sql.Add(' and  KCQty=0.0 ');
          open;
          iF ADOQueryTemp.fieldbyname('KCQty').AsFloat=0.0 then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            application.MessageBox('所选记录已有出库，不能调整！','提示信息',MB_ICONERROR);
            exit;
          end;
        end;
        fBCID:=trim(CDS_Main.fieldbyname('BCID').AsString);
        FCRID:=trim(CDS_Main.fieldbyname('CRID').AsString);
        for J:=1 to RollNum1 do
        begin
          if GetLSNo(ADOQueryCmd,fAPTM,'C','APTM',4,1)=False then
          begin
          Application.MessageBox('取子流水号失败！','提示',0);
          Exit;
          end;
          with ADOQueryTmp do
          begin
          close;
          sql.Clear;
          sql.Add('select * from CK_BanCP_KC A');
          sql.Add('where BCID='+quotedstr(trim(fBCID)));
          sql.Add('and CRID='+quotedstr(trim(fCRID)));
          open;
          end;
          with ADOQueryCmd  do
          begin
          Close;
          sql.Clear;
          SQL.add('Update CK_BanCP_CRID Set CRID=CRID+1');
          sql.Add('select * from CK_BanCP_CRID');
          Open;
          end;
          CRID:=ADOQueryCmd.fieldbyname('CRID').AsInteger;
          with ADOQueryCmd do
          begin
          close;
          sql.Clear;
          sql.Add('select * from CK_BanCP_KC A');
          sql.Add('where 1=2 ');
          open;
          end;
          ADOQueryCmd.Append;
          for i:=0 to ADOQueryCmd.FieldCount-1 do
          begin
            ADOQueryCmd.fields[i].value:=ADOQueryTmp.Fields[i].Value ;
          end;
          ADOQueryCmd.FieldByName('CRID').Value:=CRID;
          ADOQueryCmd.FieldByName('KCROllNum').Value:=1;
          ADOQueryCmd.FieldByName('KCQty').Value:=num1;
          ADOQueryCmd.FieldByName('oldCRID').Value:=fcrID;
          ADOQueryCmd.FieldByName('MJID').Value:=trim(fAPTM);
          ADOQueryCmd.Post;


          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('select * from CK_BanCP_KC A');
            sql.Add('where CRID='''+trim(fCRID)+'''');
            open;
          end;
          ADOQueryCmd.Edit;
          ADOQueryCmd.FieldByName('KCROllNum').Value:=1;
          ADOQueryCmd.FieldByName('KCQty').Value:=ADOQueryCmd.FieldByName('KCQty').AsFloat - num1;
          ADOQueryCmd.Post;

          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update  CK_BanCP_KC SET KCROllNum=0 ');
            sql.Add('where CRID='''+trim(fCRID)+''' and KCQty<=0 ');
            execsql ;
          end;


        end;
     {   with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPDATE CK_BanCp_KC SET KCRollNum =1 ');
          sql.Add('WHERE (KCQty<>0 or KCKgQty<>0)and KcRollNum=0  ');
          ExecSQL;
        end;
        }

        Edit;
      //  FieldByName('kcqty').Value:=kcQty;
        FieldByName('SSel').Value:=False;
        post;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('操作成功!','提示',0);
    TBRafresh.Click;
    CDS_Main.Locate('CRID',fCRID,[]);
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmCKProductBCPKCList.ToolButton2Click(Sender: TObject);
var
  i,FCRID:integer;
  fconNo,FC_CodeName,FC_Color:string;

  fRollNum,FQty:double;
begin
  if not CDS_Main.Active then exit;
  if not CDS_Main.Locate('SSel',True,[]) then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要合并数据吗？','提示',32+4)<>IDYES then Exit;
  i:=0;
  with  CDS_Main do
  begin
    DisableControls;
    First;
    while not eof do
    begin
      if  Fieldbyname('Ssel').AsBoolean then
      begin
        with ADOQueryTemp do
        begin
          close;
          sql.Clear;
          sql.Add(' select * from  CK_BanCP_KC  ');
          sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
          sql.Add(' and  KCQty=0.0 ');
          open;
          iF not ADOQueryTemp.IsEmpty then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            application.MessageBox('所选记录已有出库，不能调整！','提示信息',MB_ICONERROR);
            exit;
          end;
        end;
        if i=0 then
        begin
          fconNo:= trim(Fieldbyname('ConNo').AsString);
          FC_CodeName:= trim(Fieldbyname('C_CodeName').AsString);
          FC_Color:= trim(Fieldbyname('C_Color').AsString);
        end
        else
        begin
          if trim(fconNo)<>trim(Fieldbyname('ConNo').AsString) then
          begin
            EnableControls;
            application.MessageBox('任务单号不同，不能合并！','提示信息',0);
            exit;
          end;
          if trim(FC_CodeName)<>trim(Fieldbyname('C_CodeName').AsString) then
          begin
            EnableControls;
            application.MessageBox('产品名称不同，不能合并！','提示信息',0);
            exit;
          end;
          if trim(FC_Color)<>trim(Fieldbyname('C_Color').AsString) then
          begin
            EnableControls;
            application.MessageBox('颜色不同，不能合并！','提示信息',0);
            exit;
          end;
        end;
        i:=i+1;
      end;
      next;
    end;
    EnableControls;
    First;
  end;

  if i<2 then exit;

  ADOQueryCmd.Connection.BeginTrans;
  try

    fRollNum:=0;
    FQty:=0;
    with  CDS_Main do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if  Fieldbyname('Ssel').AsBoolean then
        begin
          fCRID:=Fieldbyname('CRID').AsInteger;
          fRollNum:=fRollNum + Fieldbyname('KCROllNum').AsFloat;
          FQty:=FQty + Fieldbyname('kcQty').AsFloat;

          with adoqueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('select * from CK_BanCP_KC ');
            sql.Add('where CRID='+quotedstr(trim(CDS_Main.Fieldbyname('CRID').AsString)));
            open;
            edit;
            fieldbyname('KCROllNum').Value:=0;
            fieldbyname('kcQty').Value:=0;
            post;
          end;
        end;
        next;
      end;
      EnableControls;
      First;
    end;

    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select * from CK_BanCP_KC ');
      sql.Add('where CRID='+quotedstr(inttostr(fCRID)));
      open;
      edit;
      fieldbyname('KCROllNum').Value:=1;
      fieldbyname('kcQty').Value:=FQty;
      post;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    application.MessageBox('数据合并成功！','提示信息');
    TBRafresh.Click;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('数据合并失败！','提示信息',0);
  end;



end;

procedure TfrmCKProductBCPKCList.ToolButton3Click(Sender: TObject);
var
  oldQty,kcQty:double;
begin
  if not CDS_Main.Active then exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;

  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  conNo.SetFocus;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      while CDS_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryTemp do
        begin
          close;
          sql.Clear;
          sql.Add(' select * from  CK_BanCP_KC  ');
          sql.Add(' where CRID='+quotedstr(trim(Cds_Main.Fieldbyname('CRID').AsString)));
          open;
          iF Fieldbyname('KCQty').AsFloat=0.0 then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            application.MessageBox('所选记录已有出库，不能调整！','提示信息',MB_ICONERROR);
            exit;
          end;
        end;

        oldQty:=ADOQueryTemp.fieldbyname('KCQty').AsFloat;
        kcQty:=CDS_Main.fieldbyname('kcQty').AsFloat;
        IF oldQty<100 then
        begin
          IF  abs(oldQty-kcQty)>5.0 then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            application.MessageBox('库存调整不能超过5M','提示信息',MB_ICONERROR);
            exit;
          end;
        end
        else
        begin
          IF  strtofloat(format('%.1f',[abs(oldQty-kcQty)/oldQty*100]))>3.0 then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            application.MessageBox('库存调整不能超过原数量的%3','提示信息',MB_ICONERROR);
            exit;
          end;
        end;

        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add(' Update CK_BanCP_KC Set ZDYFlote1=KCqty ');
          sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
          sql.Add(' and ZDYFlote1=0 ');
          sql.Add(' Update CK_BanCP_KC Set kcqty='''+floattostr(kcQty)+''',ZDYStr1=''库存调整'' ');
          sql.Add(' ,kcNote='+quotedstr(trim(CDS_Main.fieldbyname('kcnote').AsString)));
          sql.Add(' ,CPType='+quotedstr(trim(CDS_Main.fieldbyname('CPType').AsString)) );
          sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
          sql.Add(' Update CK_BanCP_KC Set kcRollNum=0 ');
          sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
          sql.Add(' and kcqty=0 and kcRollNum<>0 ');
          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('卷号：'+trim(CDS_Main.FieldByName('MJID').AsString))));
          sql.Add(','+quotedstr(trim('成功')));
          sql.Add(')');
          ExecSQL;
        end;
        Edit;
        FieldByName('kcqty').Value:=kcQty;
        FieldByName('SSel').Value:=False;
        post;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('操作成功!','提示',0);
    Exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmCKProductBCPKCList.TBPrintClick(Sender: TObject);
var
  filepath:string;
begin
  if CDS_Main.IsEmpty then exit;
  CreateTable();
  with CDS_Main do
  begin
    DisableControls;
    first;
    while not eof do
    begin
        with adoqueryCmd do
        begin
          Close;
	   	    SQL.Clear;
	   	    SQL.Add(' insert into '+TblCprk+'(BCID,CRID) values( ');
          SQL.Add(' '+quotedstr(trim(CDS_Main.fieldbyname('BCID').AsString)));
          SQL.Add(','+quotedstr(trim(CDS_Main.fieldbyname('CRID').AsString)));
          sql.add(')');
	   	    execsql;
        end;
      next;
    end;
    First;
    EnableControls;
  end;
  with AdoPrint do
  begin
    close;
    sql.Clear;
    sql.Add('exec P_Get_CpkcList ');
    sql.Add('@mainID='+quotedstr(trim('')));
    sql.Add(',@TblCprk='+quotedstr(trim(TblCprk)));
    sql.Add(',@flag='+quotedstr(trim('1')));
    open;
  end;
  try
    filepath:=ExtractFilePath(Application.ExeName) + 'report\库存信息表.rmf';
    if not FileExists(Pchar(filepath))  then
    begin
      application.MessageBox(pchar('文件['+filepath+']不存在！'),'提示信息',MB_IConError);
      exit;
    end;
    RMVariables['begdate'] :=FormatDateTime('yyyy-MM-dd',BegDate.DateTime)+' - '+FormatDateTime('yyyy-MM-dd',enddate.DateTime);
    RMVariables['dtxz'] :=FormatDateTime('yyyy-mm-dd',date());
    RMVariables['zdr'] :=trim(DName);
//    RMVariables['Filler'] :=trim(CDS_Main.fieldbyname('Filler').AsString);
    RMGridReport1.LoadFromFile(filepath);
    RMGridReport1.ShowReport;
  finally

  end;
  DropTable();
end;
procedure TfrmCKProductBCPKCList.kcKw1Exit(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=kcKw1.Text;

  IF trim(mvalue)='' then exit;

  IF rightBstr(trim(mvalue),1)<>'W' THEN
  BEGIn
    mvalue:=trim(mvalue)+'W';
  END;

  kcKw1.Text:=trim(mvalue);
end;

procedure TfrmCKProductBCPKCList.ToolButton4Click(Sender: TObject);
var
  fPrintFile:string;
  Txt,fImagePath:string;
  Moudle: THandle;
  Makebar:TMakebar;
  Mixtext:TMixtext;
begin
  if CDS_Main.IsEmpty 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
        try
          Moudle:=LoadLibrary('MakeQRBarcode.dll');
          @Makebar:=GetProcAddress(Moudle,'Make');
          @Mixtext:=GetProcAddress(Moudle,'MixText');
          Txt:=Trim(CDS_Main.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);
          CDS_Main.EnableControls;
          exit;
        end;
        with ADOQueryPrint do     //英文名称不要在样品表中读取，要在客户自定义表中读取。note字段。
        begin
          Close;
          SQL.Clear;
          sql.Add('select A.*,B.BCFK as MJFK,B.BCKZ as MJSJKZ,kcQty as mjlen,kcQtyUnit as MJTypeother,C_CodeNameZW=(select Top 1 defnote3 from KH_Zdy_Attachment X where X.ZdyName=A.C_CodeName and Type=''CP'') ');
          sql.Add(',C_colorName=(select Top 1 DEFstr6 from KH_Zdy_Attachment X where X.ZdyName=A.C_CodeName and X.DEFstr3=A.C_Color and Type=''CP'') ');
          sql.Add(',factoryNameJZ=(select Top 1 X1.zdyNameZ from KH_Zdy_Attachment X1,WFB_MJJY X2 where X1.ZdyName=X2.factoryName and X2.MJID=A.MJID and X1.Type=''GYS'') ');
          sql.Add(' from CK_BanCP_KC A') ;
          sql.Add(' left join CK_BanCP_CR B on B.CRID=A.CRID') ;
          SQL.Add(' where A.MJID='''+Trim(CDS_Main.fieldbyname('MJID').AsString)+'''');
          SQL.Add(' and KCQty>0 ');
          Open;
        end;
          fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\通用标签.rmf' ;
        if FileExists(fPrintFile) then
        begin
          RMVariables['QRBARCODE']:=fImagePath;
          RMGridReport1.LoadFromFile(fPrintFile);
        //  RMGridReport1.ShowReport;
          RMGridReport1.PrintReport;
        end else
        begin
          CDS_Main.EnableControls;
          Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\卷标签.rmf'),'提示',0);
          Exit;
        end;
      end;
      Next;
    end;
  end;
  CDS_Main.EnableControls;
end;

procedure TfrmCKProductBCPKCList.CheckBox1Click(Sender: TObject);
begin
  IF  CDS_Main.IsEmpty then exit;
  with CDS_Main do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value:=checkbox1.Checked;
      post;
      next;
    end;
    First;
    EnableControls;
  end;
end;

procedure TfrmCKProductBCPKCList.ToolButton5Click(Sender: TObject);
var
  oldQty,kcQty,num1:Extended;
  i:integer;
  isEdit:boolean;
  str1:string;
begin
  //showmessage(format('%.1f',[117.50 * 0.98]));
  if not CDS_Main.Active then exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  isEdit:=false;

  frmKCEdit:=TfrmKCEdit.create(self);
  with frmKCEdit do
  begin
    if showmodal=1 then
    begin
      num1:=strtofloatdef(cxCurrencyEdit2.Text,0);
      i:=RadioGroup1.ItemIndex;
      isEdit:=true;
    end;
    free;
  end;

  IF Isedit=false then exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      while CDS_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryTemp do
        begin
          close;
          sql.Clear;
          sql.Add(' select * from  CK_BanCP_KC  ');
          sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
     //     sql.Add(' and  KCQty=0.0 ');
          open;
          iF ADOQueryTemp.fieldbyname('KCQty').AsFloat=0.0 then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            application.MessageBox('所选记录已有出库，不能调整！','提示信息',MB_ICONERROR);
            exit;
          end;
        end;

        oldQty:=ADOQueryTemp.fieldbyname('KCQty').AsFloat;
        if i=0 then
        kcQty:=CDS_Main.fieldbyname('kcQty').AsFloat + num1 ;
        if i=1 then
        kcQty:=CDS_Main.fieldbyname('kcQty').AsFloat - num1 ;
        if i=2 then
        begin
         // str1:=format('%.1f',[CDS_Main.fieldbyname('kcQty').AsFloat*1.00 * num1]);
          kcQty:=strtofloat(format('%.1f',[CDS_Main.fieldbyname('kcQty').AsFloat*1.00 * num1]));
        end;
        if i=3 then
        kcQty:=strtofloat(format('%.1f',[CDS_Main.fieldbyname('kcQty').AsFloat*1.00 / num1]));


        IF kcQty-oldQty<5 then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          application.MessageBox('库存调整要大于原数量5或者小于100','提示信息',MB_ICONERROR);
          exit;
        end;
        IF kcQty-oldQty>100 then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          application.MessageBox('库存调整要大于原数量5或者小于100','提示信息',MB_ICONERROR);
          exit;
        end;
     //   kcQty:=CDS_Main.fieldbyname('kcQty').AsFloat;
    {    IF oldQty<100 then
        begin
          IF  abs(oldQty-kcQty)>5.0 then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            application.MessageBox('库存调整不能超过5M','提示信息',MB_ICONERROR);
            exit;
          end;
        end
        else
        begin
          IF  strtofloat(format('%.1f',[abs(oldQty-kcQty)/oldQty*100]))>3.0 then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            application.MessageBox('库存调整不能超过原数量的%3','提示信息',MB_ICONERROR);
            exit;
          end;
        end;}
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add(' Update CK_BanCP_KC Set ZDYFlote1=KCqty ');
          sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
          sql.Add(' and ZDYFlote1=0 ');
          sql.Add(' Update CK_BanCP_KC Set kcqty='''+floattostr(kcQty)+''',ZDYStr1=''库存调整'' ');
          sql.Add(' ,kcNote='+quotedstr(trim(CDS_Main.fieldbyname('kcnote').AsString)));
          sql.Add(' ,CPType='+quotedstr(trim(CDS_Main.fieldbyname('CPType').AsString)) );
          sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
          sql.Add(' Update CK_BanCP_KC Set kcRollNum=0 ');
          sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
          sql.Add(' and kcqty=0 and kcRollNum<>0 ');
          
          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('卷号：'+trim(CDS_Main.FieldByName('MJID').AsString))));
          sql.Add(','+quotedstr(trim('成功')));
          sql.Add(')');
          ExecSQL;
        end;
        Edit;
        FieldByName('kcqty').Value:=kcQty;
        FieldByName('SSel').Value:=False;
        post;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('操作成功!','提示',0);
    Exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;

end;

procedure TfrmCKProductBCPKCList.v1Column5PropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
begin
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;

  with CDS_Main do
  begin
    edit;
    fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;
   // FieldByName('PrtMoney').Value:=strtofloat(format('%.2f',[Fieldbyname('PRTOrderQty').AsFloat*Fieldbyname('PrtPrice').AsFloat ]));
    post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' Update CK_BanCP_KC Set kcNote='+quotedstr(trim(CDS_Main.fieldbyname('kcnote').AsString)));
      sql.Add(' where CRID='+Cds_Main.Fieldbyname('CRID').AsString);
      ExecSQL;
    end;
  except
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmCKProductBCPKCList.Button1Click(Sender: TObject);
begin
  IF trim(editnewpm.Text)='' then
  begin
    application.MessageBox('新品名不能为空！','提示信息',0);
    exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      while CDS_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('update WFB_MJJY SET C_CodeName='''+trim(editnewpm.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          sql.Add('update CK_BanCP_CR SET C_CodeName='''+trim(editnewpm.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          sql.Add('update CK_BanCP_KC SET C_CodeName='''+trim(editnewpm.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          ExecSQL;
        end;
        Edit;
        FieldByName('SSel').Value:=False;
        FieldByName('C_CodeName').Value:=Trim(editnewpm.Text);
        Post;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('操作成功!','提示',0);
    Panel2.Visible:=false;
    Exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmCKProductBCPKCList.Button2Click(Sender: TObject);
begin

  IF trim(editnewYS.Text)='' then
  begin
    application.MessageBox('新颜色不能为空！','提示信息',0);
    exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      while CDS_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('update WFB_MJJY SET C_Color='''+trim(editnewYS.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          sql.Add('update CK_BanCP_CR SET C_Color='''+trim(editnewYS.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          sql.Add('update CK_BanCP_KC SET C_Color='''+trim(editnewYS.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          ExecSQL;
        end;
        Edit;
        FieldByName('SSel').Value:=False;
        FieldByName('C_Color').Value:=Trim(editnewYS.Text);
        Post;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('操作成功!','提示',0);
    Panel2.Visible:=false;
    Exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmCKProductBCPKCList.Button3Click(Sender: TObject);
begin
  Panel2.Visible:=false;
end;

procedure TfrmCKProductBCPKCList.ToolButton6Click(Sender: TObject);
begin
  if not CDS_Main.Active then exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  editoldpm.Text:='';
  editnewpm.Text:='';
  editoldYS.Text:='';
  editnewYS.Text:='';
  ComCPType.ItemIndex:=0;
  Panel2.Visible:=true;
end;

procedure TfrmCKProductBCPKCList.Button4Click(Sender: TObject);
begin
  IF trim(editnewKZ.Text)='' then
  begin
    application.MessageBox('新克重不能为空！','提示信息',0);
    exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      while CDS_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('update WFB_MJJY SET MJSJKZ='''+floattostr(strtofloatdef(trim(editnewKZ.Text),0))+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          sql.Add('update CK_BanCP_CR SET BCKZ='''+floattostr(strtofloatdef(trim(editnewKZ.Text),0))+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
         // sql.Add('update CK_BanCP_KC SET C_Color='''+trim(editnewYS.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          ExecSQL;
        end;
        Edit;
        FieldByName('SSel').Value:=False;
        FieldByName('BCKZ').Value:=strtofloatdef(trim(editnewKZ.Text),0);
        Post;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('操作成功!','提示',0);
    Panel2.Visible:=false;
    Exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmCKProductBCPKCList.Button5Click(Sender: TObject);
begin
  IF trim(editnewbatchNo.Text)='' then
  begin
    application.MessageBox('新白坯编号不能为空！','提示信息',0);
    exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      while CDS_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('update WFB_MJJY SET batchNo='''+trim(editnewbatchNo.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          sql.Add('update CK_BanCP_CR SET batchNo='''+trim(editnewbatchNo.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          sql.Add('update CK_BanCP_KC SET batchNo='''+trim(editnewbatchNo.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          ExecSQL;
        end;
        Edit;
        FieldByName('SSel').Value:=False;
        FieldByName('batchNo').Value:=trim(editnewbatchNo.Text);
        Post;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('操作成功!','提示',0);
    Panel2.Visible:=false;
    Exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmCKProductBCPKCList.editnewpmExit(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=trim(editnewpm.Text);

  IF trim(mvalue)='' then exit;

  IF rightBstr(trim(mvalue),1)<>'#'THEN
  BEGIn
    mvalue:=trim(mvalue)+'#';
  END;

  editnewpm.Text:=trim(mvalue);


 { with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select *  from KH_Zdy_Attachment A ');
    sql.Add('where zdyName='+quotedstr(trim(P_CodeName.Text)));
    open;
  end;
  IF ADOQueryCmd.IsEmpty then
  begin
    P_CodeName.Text:='';
    application.MessageBox('品名不存在！','提示信息',0);
  end;}

end;

procedure TfrmCKProductBCPKCList.editnewYsExit(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=trim(editnewYs.Text);

  IF trim(mvalue)='' then exit;

  IF rightBstr(trim(mvalue),1)<>'#'THEN
  BEGIn
    mvalue:=trim(mvalue)+'#';
  END;

  editnewYs.Text:=trim(mvalue);

end;

procedure TfrmCKProductBCPKCList.Tv1CustomDrawIndicatorCell(
  Sender: TcxGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
      FValue:   string;
      FBounds:   TRect;
  begin
      FBounds   :=   AViewInfo.Bounds;
      if   (AViewInfo   is   TcxGridIndicatorRowItemViewInfo)   then
      begin
          ACanvas.FillRect(FBounds);
          ACanvas.DrawComplexFrame(FBounds,   clBtnHighlight,   clBtnShadow,   [bBottom,   bLeft,   bRight],   1);
          FValue   :=IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index+1);
          InflateRect(FBounds,   -1,   -1) ;
          ACanvas.Font.Color   :=   clBlack;
          ACanvas.Brush.Style   :=   bsClear;
          ACanvas.DrawText(FValue,   FBounds,   cxAlignCenter   or   cxAlignTop);
          ADone   :=   True;
      end;
 end;

procedure TfrmCKProductBCPKCList.Button6Click(Sender: TObject);
begin
  IF trim(ComCPType.Text)='' then
  begin
    application.MessageBox('等级不能为空！','提示信息',0);
    exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      while CDS_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('update WFB_MJJY SET MJType='''+trim(ComCPType.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          sql.Add('update CK_BanCP_CR SET CPType='''+trim(ComCPType.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          sql.Add('update CK_BanCP_KC SET CPType='''+trim(ComCPType.Text)+''' where MJID='''+trim(CDS_Main.fieldbyname('MJID').AsString)+''' ');
          ExecSQL;
        end;
        Edit;
        FieldByName('SSel').Value:=False;
        FieldByName('CPType').Value:=Trim(ComCPType.Text);
        Post;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('操作成功!','提示',0);
    Panel2.Visible:=false;
    Exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

end.
