unit U_CpRkSaoMNew;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, StdCtrls, ExtCtrls, ADODB, DBClient,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, MovePanel, cxCheckBox, Menus,
  ComCtrls, cxTextEdit;

type
  TfrmCpRkSaoMNewPB = class(TForm)
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column5: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    DataSource1: TDataSource;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    Panel1: TPanel;
    BaoID: TEdit;
    Label1: TLabel;
    v1Column5: TcxGridDBColumn;
    Button2: TButton;
    Button3: TButton;
    CDS_Sub: TClientDataSet;
    DataSource2: TDataSource;
    ADOQuerySub: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGridPopupMenu3: TcxGridPopupMenu;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DS_MainSel: TDataSource;
    CDS_MainSel: TClientDataSet;
    v3Column1: TcxGridDBColumn;
    Button1: TButton;
    cxGridPopupMenu4: TcxGridPopupMenu;
    MovePanel1: TMovePanel;
    Edit1: TEdit;
    Edit2: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Button4: TButton;
    cxGrid1: TcxGrid;
    Tv2: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v3Column3: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v3Column5: TcxGridDBColumn;
    Button5: TButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    MovePanel2: TMovePanel;
    CRTime: TDateTimePicker;
    Label4: TLabel;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    KuWei: TEdit;
    Label5: TLabel;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BaoIDKeyPress(Sender: TObject; var Key: Char);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
    procedure InitSubGrid();
    procedure SavedataCK();
  public
    { Public declarations }
  end;

var
  frmCpRkSaoMNewPB: TfrmCpRkSaoMNewPB;

implementation
uses
U_DataLink,U_Fun,U_OrderSelRK ;

{$R *.dfm}

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

procedure TfrmCpRkSaoMNewPB.FormDestroy(Sender: TObject);
begin
  frmCpRkSaoMNewPB:=nil;
end;
procedure TfrmCpRkSaoMNewPB.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      SQL.Add('select A.*,ConNo=(select ConNo from Cloth_Main where MainId=A.MainId) ');
      SQL.Add(',C_Color=(select C_Color from Cloth_Sub where MainId=A.MainId)');
      sql.Add(',MJXH=(select APXH from WFB_MJJY_PB where MJID=A.MJID)');
      sql.Add(',MJStr3=(select MJStr3 from WFB_MJJY_PB where MJID=A.MJID)');
      sql.Add(',CarNo=(select CarNo from WFB_MJJY_PB where MJID=A.MJID)');
      sql.Add('from CK_PBCP_CR A');
      sql.add('where 1<>1');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      SQL.Add('select A.*,ConNo=(select ConNo from Cloth_Main where MainId=A.MainId) ');
      SQL.Add(',C_Color=(select C_Color from Cloth_Sub where MainId=A.MainId)');
      sql.Add(',MJXH=(select APXH from WFB_MJJY_PB where MJID=A.MJID)');
      sql.Add(',CarNo=(select CarNo from WFB_MJJY_PB where MJID=A.MJID)');
      sql.Add(',MJStr3=(select MJStr3 from WFB_MJJY_PB where MJID=A.MJID)');
      sql.Add('from CK_PBCP_CR A');
      sql.add('where 1<>1');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_MainSel);
    SInitCDSData20(ADOQueryMain,CDS_MainSel);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmCpRkSaoMNewPB.FormShow(Sender: TObject);
begin
  ReadCxGrid('订单选择PB111',Tv2,'成品仓库');
  ReadCxGrid('成品出库PB111',Tv1,'成品仓库');
  ReadCxGrid('成品出库SelsPB111',Tv3,'成品仓库');
  InitSubGrid();
  InitGrid();
  CRTime.DateTime:=SGetServerDate(ADOQueryTemp);
end;

procedure TfrmCpRkSaoMNewPB.BaoIDKeyPress(Sender: TObject; var Key: Char);
var
  maxno:String;
  CRID:Integer;
  MaxCkNo,MaxCkSubNo:String;
begin
  if Key=#13 then
  begin
    if CDS_Sub.IsEmpty then
    begin
      BaoID.Text:='';
      Application.MessageBox('未选单不能扫描出库！','提示',0);
      Exit;
    end;
    if CDS_Main.Locate('MJId',Trim(BaoID.Text),[])=False then
    begin
      BaoID.Text:='';
      //Application.MessageBox('此卷不包含在待入库的卷数据中！','提示',0);
      Exit;
    end;
    CDS_Main.Locate('MJId',Trim(BaoID.Text),[]);
    try
      ADOQueryCmd.Connection.BeginTrans;
    
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from WFB_MJJY_PB where MJStr2=''已入库''');
        sql.Add(' and MJID='''+Trim(CDS_Main.fieldbyname('MJID').AsString)+'''');
        Open;
      end;
      if ADOQueryTemp.IsEmpty=False then
      begin
        //CDS_Main.EnableControls;
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('已有入库数据，请退出模块重新进入!','提示',0);
        Exit;
      end;
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('exec P_Do_PBRK @CRFlag=''入库'',  @MJID='+quotedstr(Trim(CDS_Main.fieldbyname('MJID').AsString)));
         sql.Add(' ,@KuWei='+quotedstr(trim(KuWei.text)));
        ExecSQL;
      end;

      ADOQueryCmd.Connection.CommitTrans;
      with CDS_MainSel do
      begin
        Append;
        FieldByName('MainId').Value:=CDS_Main.fieldbyname('MainId').Value;
        FieldByName('SubId').Value:=Self.CDS_Main.fieldbyname('SubId').Value;
        FieldByName('ConNo').Value:=Self.CDS_Main.fieldbyname('ConNo').Value;
        FieldByName('KGQty').Value:=Self.CDS_Main.fieldbyname('KGQty').Value;
        FieldByName('Qty').Value:=Self.CDS_Main.fieldbyname('Qty').Value;
        FieldByName('QtyUnit').Value:=Self.CDS_Main.fieldbyname('QtyUnit').Value;
        FieldByName('MJId').Value:=Self.CDS_Main.fieldbyname('MJId').Value;
        FieldByName('CRId').Value:=IntToStr(CRID);
        FieldByName('APID').Value:=Self.CDS_Main.fieldbyname('APID').Value;
        FieldByName('CPType').Value:=CDS_Main.fieldbyname('CPType').Value;
        FieldByName('BCID').Value:=Trim(MaxCkNo);
        FieldByName('C_Color').Value:=CDS_Main.fieldbyname('C_Color').Value;
        FieldByName('MJXH').Value:=CDS_Main.fieldbyname('MJXH').Value;
        FieldByName('CarNo').Value:=CDS_Main.fieldbyname('CarNo').Value;
        FieldByName('MJStr3').Value:=CDS_Main.fieldbyname('MJStr3').Value;
        //FieldByName('AOrdDefstr1').Value:=CDS_Main.fieldbyname('AOrdDefstr1').Value;
        //FieldByName('JZXNo').Value:=Trim(JZXNo.Text);
        Post;
      end;
      CDS_Main.Delete;
      MovePanel1.Visible:=True;
      if CDS_MainSel.IsEmpty=False then
        Edit1.Text:=IntToStr(Tv3.DataController.Summary.FooterSummaryValues[2])
      else
        Edit1.Text:='0';
      Edit2.Text:=Trim(BaoID.Text);
      BaoID.Text:='';
      Exit;
    except
      BaoID.Text:='';
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('入库异常！','提示',0);
    end;
  end;
end;
procedure TfrmCpRkSaoMNewPB.SavedataCK();
var
  CRID:Integer;
  MaxCkNo,MaxCkSubNo:String;
begin
  //if Trim(Cds_Main.fieldbyname('SubType').AsString)='大卷' then
  //////////////////////////////////////////////////////////////保存到半成品仓库////////////////////////////////////////////////
    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').Value;
    if GetLSNo(ADOQueryCmd,MaxCkNo,'JR','CK_BanCP_CR',4,1)=False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取成品仓库最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_BanCP_CR where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('MainId').Value:=Trim(CDS_Main.fieldbyname('MainId').AsString);
      FieldByName('SubId').Value:=Trim(CDS_Main.fieldbyname('SubId').AsString);
      FieldByName('APID').Value:=Trim(CDS_Main.fieldbyname('APID').AsString);
      FieldByName('MJID').Value:=Trim(CDS_Main.fieldbyname('MJId').AsString);
      FieldByName('BCID').Value:=Trim(MaxCkNo);
      FieldByName('CRTime').Value:=SGetServerDateTime(ADOQueryTemp);
      FieldByName('CRFlag').Value:='入库';
      FieldByName('CRType').Value:='检验入库';
      //FieldByName('JTType').Value:=Trim(XJFlag);
      FieldByName('CRID').Value:=CRID;
      FieldByName('KGQty').Value:=CDS_Main.fieldbyname('KGQty').Value;
      FieldByName('Qty').Value:=CDS_Main.fieldbyname('Qty').Value;
      FieldByName('QtyUnit').Value:=CDS_Main.fieldbyname('QtyUnit').Value;
      FieldByName('CPType').Value:=CDS_Main.fieldbyname('CPType').Value;
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('FillTime').Value:=SGetServerDateTime(ADOQueryTemp);
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_BanCP_KC where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('CRID').Value:=CRID;
      FieldByName('BCID').Value:=Trim(MaxCkNo);
      FieldByName('MJID').Value:=Trim(CDS_Main.fieldbyname('MJID').AsString);
      FieldByName('KCKGQty').Value:=CDS_Main.fieldbyname('KGQty').Value;
      FieldByName('KCQty').Value:=CDS_Main.fieldbyname('Qty').Value;
      FieldByName('KCQtyUnit').Value:=CDS_Main.fieldbyname('QtyUnit').Value;
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update WFB_MJJY Set MJStr2=''已入库'' where MJID='''+Trim(CDS_Main.fieldbyname('MJID').AsString)+'''');
      ExecSQL;
    end;
end;
procedure TfrmCpRkSaoMNewPB.Button2Click(Sender: TObject);
begin
  Close;
  WriteCxGrid('订单选择PB111',Tv2,'成品仓库');
  WriteCxGrid('成品出库PB111',Tv1,'成品仓库');
  WriteCxGrid('成品出库SelsPB111',Tv3,'成品仓库');
end;

procedure TfrmCpRkSaoMNewPB.Button3Click(Sender: TObject);
begin
  {if CDS_Main.IsEmpty=False then
  begin
    Application.MessageBox('已扫描不能更改单号！','提示',0);
    Exit;
  end;}
  InitSubGrid();
  InitGrid();
  try
    frmOrderSelRK:=TfrmOrderSelRK.Create(Application);
    with frmOrderSelRK do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Append;
          FieldByName('MainId').Value:=Trim(CDS_OrderSel.fieldbyname('MainId').AsString);
          FieldByName('SubId').Value:=Trim(CDS_OrderSel.fieldbyname('SubId').AsString);
          FieldByName('ConNo').Value:=Trim(CDS_OrderSel.fieldbyname('ConNo').AsString);
          FieldByName('C_CodeName').Value:=Trim(CDS_OrderSel.fieldbyname('C_CodeName').AsString);
          FieldByName('C_Code').Value:=Trim(CDS_OrderSel.fieldbyname('C_Code').AsString);
          FieldByName('C_Color').Value:=Trim(CDS_OrderSel.fieldbyname('C_Color').AsString);
          FieldByName('ClothType').Value:=Trim(CDS_OrderSel.fieldbyname('ClothType').AsString);
          Post;
        end;
        with Self.ADOQueryTemp do
        begin
          Close;
          SQL.Clear;
          sql.Add('select ConNo=(select ConNo from Cloth_Main where MainId=A.MainId)  ');
          sql.Add(',C_Color=(select  C_Color from Cloth_Sub JS where  JS.MainId=A.MainId) ');
          sql.Add(',KgQty=A.MJMaoZ,Qty=A.MJLen,QtyUnit=A.MJTypeOther,CPType=A.ClothType,MJXH=A.APXH');
          sql.Add(',A.* ');
          sql.Add(' from WFB_MJJY_PB A ');
          sql.Add(' where isnull(A.MJStr2,'''')=''未入库'' ');
          SQL.Add(' and A.MainId='''+Trim(CDS_Sub.fieldbyname('MainId').AsString)+'''');
          SQL.Add(' and A.ClothType='''+Trim(CDS_Sub.fieldbyname('ClothType').AsString)+'''');
          Open;
        end;
        SCreateCDS20(Self.ADOQueryTemp,CDS_Main);
        SInitCDSData20(Self.ADOQueryTemp,CDS_Main);
      end;
    end;
  finally
    frmOrderSelRK.Free;
  end;
end;

procedure TfrmCpRkSaoMNewPB.InitSubGrid();
begin
  try
    ADOQuerySub.DisableControls;
    with ADOQuerySub do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*,ClothType=Cast('''' as varchar(20))');
      sql.Add(' from Cloth_Main A inner join Cloth_Sub B on A.MainId=B.Mainid');
      sql.Add(' where 1<>1  ');

      Open;
    end;
    SCreateCDS20(ADOQuerySub,CDS_Sub);
    SInitCDSData20(ADOQuerySub,CDS_Sub);
  finally
    ADOQuerySub.EnableControls;
  end;
end;


procedure TfrmCpRkSaoMNewPB.Button1Click(Sender: TObject);
begin
  if CDS_MainSel.IsEmpty then Exit;
  if CDS_MainSel.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_MainSel.DisableControls;
    with CDS_MainSel do
    begin
      First;
      while not Eof do
      begin
        if CDS_MainSel.FieldByName('SSel').AsBoolean=True then
        begin
          with ADOQueryTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('exec P_Do_PBRK @CRFlag=''未入库'',@KuWei='''',@MJID='+quotedstr(Trim(CDS_MainSel.fieldbyname('MJID').AsString)));
            ExecSQL;
          end;
       
          with CDS_Main do
          begin
            Append;
            FieldByName('MainId').Value:=CDS_MainSel.fieldbyname('MainId').Value;
            FieldByName('SubId').Value:=Self.CDS_MainSel.fieldbyname('SubId').Value;
            FieldByName('ConNo').Value:=Self.CDS_MainSel.fieldbyname('ConNo').Value;
            FieldByName('KgQty').Value:=Self.CDS_MainSel.fieldbyname('KgQty').Value;
            FieldByName('Qty').Value:=Self.CDS_MainSel.fieldbyname('Qty').Value;
            FieldByName('QtyUnit').Value:=Self.CDS_MainSel.fieldbyname('QtyUnit').Value;
            FieldByName('MJId').Value:=Self.CDS_MainSel.fieldbyname('MJId').Value;
            FieldByName('APID').Value:=Self.CDS_MainSel.fieldbyname('APID').Value;
            FieldByName('CPType').Value:=Self.CDS_MainSel.fieldbyname('CPType').Value;
            FieldByName('C_Color').Value:=Self.CDS_MainSel.fieldbyname('C_Color').Value;
            //FieldByName('AOrddefstr1').Value:=Self.CDS_MainSel.fieldbyname('AOrddefstr1').Value;
            FieldByName('MJXH').Value:=Self.CDS_MainSel.fieldbyname('MJXH').Value;
            FieldByName('CarNo').Value:=Self.CDS_MainSel.fieldbyname('CarNo').Value;
            FieldByName('MJStr3').Value:=Self.CDS_MainSel.fieldbyname('MJStr3').Value;
            Post;
          end;
          CDS_MainSel.Delete;
        end else
          Next;
      end;
    end;
    CDS_MainSel.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    MovePanel2.Visible:=False;

    {MovePanel1.Visible:=True;
    if CDS_MainSel.IsEmpty=False then
      Edit1.Text:=IntToStr(Tv3.DataController.Summary.FooterSummaryValues[2])
    else
      Edit1.Text:='0';
    Edit2.Text:=Trim(CDS_Main.fieldbyname('MJId').AsString); }
  except
    MovePanel2.Visible:=False;
    CDS_MainSel.DisableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销成功！','提示',0);
  end;
end;

procedure TfrmCpRkSaoMNewPB.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_MainSel.IsEmpty=False then Exit;
  if CDS_Sub.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  CDS_Main.DisableControls;
  with CDS_Main do
  begin
    First;
    while not Eof do
    begin
      if Trim(CDS_Main.fieldbyname('SubId').AsString)=Trim(CDS_Sub.fieldbyname('SubId').AsString) then
      begin
        CDS_Main.Delete;
      end else
        Next;
    end;
  end;
  CDS_Main.EnableControls;
  CDS_Sub.Delete;
end;

procedure TfrmCpRkSaoMNewPB.Button4Click(Sender: TObject);
begin
  MovePanel1.Visible:=False;
end;

procedure TfrmCpRkSaoMNewPB.Button5Click(Sender: TObject);
var
  maxno:String;
  CRID:Integer;
  MaxCkNo,MaxCkSubNo:String;
begin
  if CDS_Sub.IsEmpty then Exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行入库操作吗？','提示',32+4)<>IDYES then exit;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while not Eof do
      begin
        if CDS_Main.FieldByName('SSel').AsBoolean=True then
        begin
          with ADOQueryTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from WFB_MJJY_PB where MJStr2=''已入库''');
            sql.Add(' and MJID='''+Trim(CDS_Main.fieldbyname('MJID').AsString)+'''');
            Open;
          end;
          if ADOQueryTemp.IsEmpty=False then
          begin
            CDS_Main.EnableControls;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('已有入库数据，请退出模块重新进入!','提示',0);
            Exit;
          end;
          with ADOQueryTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('exec P_Do_PBRK @CRFlag=''入库'',  @MJID='+quotedstr(Trim(CDS_Main.fieldbyname('MJID').AsString)));
             sql.Add(' ,@KuWei='+quotedstr(trim(KuWei.text)));
            ExecSQL;
          end;
           with CDS_MainSel do
          begin
            Append;
            FieldByName('MainId').Value:=CDS_Main.fieldbyname('MainId').Value;
            FieldByName('SubId').Value:=Self.CDS_Main.fieldbyname('SubId').Value;
            FieldByName('ConNo').Value:=Self.CDS_Main.fieldbyname('ConNo').Value;
            FieldByName('KGQty').Value:=Self.CDS_Main.fieldbyname('KGQty').Value;
            FieldByName('Qty').Value:=Self.CDS_Main.fieldbyname('Qty').Value;
            FieldByName('QtyUnit').Value:=Self.CDS_Main.fieldbyname('QtyUnit').Value;
            FieldByName('MJId').Value:=Self.CDS_Main.fieldbyname('MJId').Value;
            FieldByName('CRId').Value:=IntToStr(CRID);
            FieldByName('APID').Value:=Self.CDS_Main.fieldbyname('APID').Value;
            FieldByName('CPType').Value:=CDS_Main.fieldbyname('CPType').Value;
            FieldByName('BCID').Value:=Trim(MaxCkNo);
            FieldByName('C_Color').Value:=Self.CDS_Main.fieldbyname('C_Color').Value;
            FieldByName('MJXH').Value:=Self.CDS_Main.fieldbyname('MJXH').Value;
            FieldByName('CarNo').Value:=CDS_Main.fieldbyname('CarNo').Value;
            FieldByName('MJStr3').Value:=CDS_Main.fieldbyname('MJStr3').Value;
           // FieldByName('AOrdDefstr1').Value:=CDS_Main.fieldbyname('AOrdDefstr1').Value;
            //FieldByName('JZXNo').Value:=Trim(JZXNo.Text);
            Post;
          end;
          CDS_Main.Delete;
        end else
          CDS_Main.Next;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    MovePanel2.Visible:=False;
    Exit;
  except
    BaoID.Text:='';
    CDS_Main.EnableControls;
    MovePanel2.Visible:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('入库异常！','提示',0);
  end;
end;

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

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

procedure TfrmCpRkSaoMNewPB.MenuItem1Click(Sender: TObject);
begin
  SelOKNo(CDS_MainSel,True);
end;

procedure TfrmCpRkSaoMNewPB.MenuItem2Click(Sender: TObject);
begin
  SelOKNo(CDS_MainSel,False);
end;

end.
