unit U_PBTQCk;

interface

uses
  Windows, Messages, SysUtils, StrUtils, Variants, Classes, Graphics, Controls,
  Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, MMSystem,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGridLevel, cxClasses, cxControls, cxGridCustomView,
  cxGrid, StdCtrls, ComCtrls, ExtCtrls, ToolWin, cxButtonEdit, cxDropDownEdit,
  DBClient, ADODB, cxGridCustomPopupMenu, cxGridPopupMenu, BtnEdit, cxContainer,
  cxTextEdit, cxCurrencyEdit, cxCheckBox, Menus, RM_Common, RM_Class, RM_e_Xls,
  RM_Dataset, RM_System, RM_GridReport;

type
  TfrmPBTQCk = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    CRTime: TDateTimePicker;
    Label2: TLabel;
    CRType: TComboBox;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label8: TLabel;
    InoutNo: TEdit;
    Label9: TLabel;
    ToFactoryName: TBtnEditA;
    Panel3: TPanel;
    ADOQueryMain: TADOQuery;
    Label26: TLabel;
    BZType: TComboBox;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column3: TcxGridDBColumn;
    v1MJID: TcxGridDBColumn;
    v1P_Code: TcxGridDBColumn;
    v1P_CodeName: TcxGridDBColumn;
    v1P_SPEC: TcxGridDBColumn;
    v1P_Color: TcxGridDBColumn;
    v1Price: TcxGridDBColumn;
    v1P_MF: TcxGridDBColumn;
    v1P_KZ: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1Money: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ADOQueryPrint: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    v1Column1: TcxGridDBColumn;
    Label3: TLabel;
    fwdw: TEdit;
    v1Column5: TcxGridDBColumn;
    Label4: TLabel;
    fromFactoryName: TBtnEditA;
    Label5: TLabel;
    FactoryName: TBtnEditA;
    ToolButton3: TToolButton;
    v1Column2: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1P_CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure ToFactoryNameBtnClick(Sender: TObject);
    procedure v1QtyPropertiesEditValueChanged(Sender: TObject);
    procedure FHAddressBtnDnClick(Sender: TObject);
    procedure v1Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure fromFactoryNameBtnClick(Sender: TObject);
    procedure FactoryNameBtnClick(Sender: TObject);
    procedure v1P_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton3Click(Sender: TObject);
  private
    procedure InitGrid();
    function savedate(): Boolean;
    { Private declarations }
  public
    fkeyNO: string;
    FType: integer;
    fCKName: string;
    { Public declarations }
  end;

var
  frmPBTQCk: TfrmPBTQCk;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp, U_CPKcList, U_ZdyAttachment, U_ZDYHelpSel,
  U_ClothGMListSel, U_ZdyAttachGYS, U_CPManageSel;
{$R *.dfm}

function TfrmPBTQCk.savedate(): Boolean;
var
  MaxNo: string;
begin
  result := false;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    CDS_Main.First;
    with CDS_Main do
    begin
      while not eof do
      begin
        MaxNo := 'C' + Trim(CDS_Main.FieldByName('MJID').AsString);
        with ADOQueryCmd do
        begin
          close;
          sql.Clear;
          sql.Add('select * from CK_ML_CR');
          sql.Add('where CRNO=' + quotedstr(MaxNo));
          open;
        end;
        if ADOQueryCmd.IsEmpty then
        begin
          ADOQueryCmd.Append;
          ADOQueryCmd.FieldByName('Filler').Value := trim(DName);
          ADOQueryCmd.FieldByName('FillTime').Value := dateTimetostr(SGetServerDateTime(adoqueryTmp));
        end
        else
        begin
          ADOQueryCmd.Edit;
          ADOQueryCmd.FieldByName('editer').Value := trim(dName);
          ADOQueryCmd.FieldByName('editTime').Value := SGetServerDateTime(adoqueryTmp);
        end;

        ADOQueryCmd.FieldByName('inoutNo').Value := trim(inoutNo.Text);
        ADOQueryCmd.FieldByName('CRNO').Value := trim(MaxNo);
        ADOQueryCmd.FieldByName('CKName').Value := '坯布';
        ADOQueryCmd.FieldByName('BZType').Value := trim(BZType.Text);
        ADOQueryCmd.FieldByName('ToFactoryName').Value := trim(ToFactoryName.Text);
        ADOQueryCmd.FieldByName('fwdw').Value := trim(fwdw.Text);
        ADOQueryCmd.FieldByName('FactoryName').Value := trim(ToFactoryName.Text);
        ADOQueryCmd.FieldByName('fromFactoryName').Value := trim(fromFactoryName.Text);
        ADOQueryCmd.FieldByName('CRTime').Value := formatdateTime('yyyy-MM-dd', CRTIme.Date);
        ADOQueryCmd.FieldByName('CRType').Value := trim(CRType.Text);
        ADOQueryCmd.FieldByName('CRFlag').Value := '出库';
        ADOQueryCmd.FieldByName('CRQtyFlag').Value := -1;

         //保存明细
        RTSetSaveDataCDS(ADOQueryCmd, Tv1, CDS_Main, 'CK_ML_CR', 0);

         //保存隐藏ID
        ADOQueryCmd.FieldByName('mainID').Value := trim(fieldbyname('mainID').AsString);
        ADOQueryCmd.FieldByName('subID').Value := trim(fieldbyname('subID').AsString);
        ADOQueryCmd.FieldByName('MJID').Value := trim(fieldbyname('MJID').AsString);
        ADOQueryCmd.FieldByName('ISRCCK').Value := '染厂发货';

        ADOQueryCmd.Post;

        //插入库存
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          SQL.Add('exec P_Up_MlKcCR @MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').AsString)));
          Open;
        end;

        Edit;
        FieldByName('CRNO').Value := trim(MaxNo);
        post;
        next;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    result := true;
  except
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
  end;
end;

procedure TfrmPBTQCk.InitGrid();
begin
  try
    with adoqueryMain do
    begin
      close;
      sql.Clear;
      sql.Add('select A.* from CK_ML_CR A');
      sql.Add('where A.CRNO=' + quotedstr(trim(fkeyNO)));
      open;
    end;
    SCreateCDS20(adoqueryMain, CDS_Main);
    SInitCDSData20(adoqueryMain, CDS_Main);
    if not CDS_Main.IsEmpty then
    begin
      CRTime.Date := CDS_Main.fieldbyname('CRTime').AsDateTime;
      CRType.ItemIndex := CRType.Items.IndexOf(trim(CDS_Main.fieldbyname('CRType').AsString));
      BZType.ItemIndex := BZType.Items.IndexOf(trim(CDS_Main.fieldbyname('BZType').AsString));
      InoutNO.Text := trim(CDS_Main.fieldbyname('InoutNO').AsString);
      ToFactoryName.Text := trim(CDS_Main.fieldbyname('ToFactoryName').AsString);
      fwdw.Text := trim(CDS_Main.fieldbyname('fwdw').AsString);
      fromFactoryName.Text := trim(CDS_Main.fieldbyname('fromFactoryName').AsString);
      FactoryName.Text := trim(CDS_Main.fieldbyname('FactoryName').AsString);
    end;
  finally
  end;
end;

procedure TfrmPBTQCk.FormDestroy(Sender: TObject);
begin
  frmPBTQCk := nil;
end;

procedure TfrmPBTQCk.FormCreate(Sender: TObject);
begin
  CRTime.Date := SGetServerDate10(ADOQueryTmp);
end;

procedure TfrmPBTQCk.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := cahide;
end;

procedure TfrmPBTQCk.FormShow(Sender: TObject);
var
  fbhType, fInoutNo: string;
begin
  readCxGrid(self.Caption + tv1.Name, Tv1, '面料仓库');
  InitGrid();
  if fType = 0 then
  begin
    if GetLSNo(ADOQueryCmd, fkeyNo, 'MCK', 'CK_ML_CR', 3, 1) = False then
    begin
      Application.MessageBox('取最大号失败!', '提示', 0);
      Exit;
    end;
    inoutNo.Text := trim(fkeyNo);
  end;
end;

procedure TfrmPBTQCk.TBSaveClick(Sender: TObject);
begin
  if cds_main.IsEmpty then
    exit;
  CRTime.SetFocus;
  if trim(CRType.Text) = '' then
  begin
    application.MessageBox('出库类型不能为空！', '提示信息', 0);
    exit;
  end;
  if trim(fromFactoryName.Text) = '' then
  begin
    application.MessageBox('加工厂不能为空！', '提示信息', 0);
    exit;
  end;
  if trim(FactoryName.Text) = '' then
  begin
    application.MessageBox('存放工厂不能为空！', '提示信息', 0);
    exit;
  end;
  if trim(ToFactoryName.Text) = '' then
  begin
    application.MessageBox('出到工厂不能为空！', '提示信息', 0);
    exit;
  end;
  if cds_main.Locate('QtyUnit', '', []) then
  begin
    application.MessageBox('数量单位不能为空！', '提示信息', 0);
    exit;
  end;
  if cds_main.Locate('QtyUnit', NULL, []) then
  begin
    application.MessageBox('数量单位不能为空！', '提示信息', 0);
    exit;
  end;
  if savedate() then
  begin
    application.MessageBox('数据保存成功！', '提示信息');
  end
  else
  begin
    application.MessageBox('数据保存失败！', '提示信息', MB_ICONERROR);
  end;
end;

procedure TfrmPBTQCk.v1P_CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'Cloth';
      flagname := '坯布名称';
      if ShowModal = 1 then
      begin
        Self.CDS_Main.Edit;
        Self.CDS_Main.FieldByName('P_CodeName').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.CDS_Main.FieldByName('P_Code').Value := Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmPBTQCk.ToolButton1Click(Sender: TObject);
var
  FMJID: string;
begin
  FMJID := '';
  if GetLSNo(self.ADOQueryCmd, FMJID, 'MJ', 'CP_InOut1', 4, 1) = False then
  begin
    Application.MessageBox('取最大号失败!', '提示', 0);
    Exit;
  end;
  with Self.CDS_Main do
  begin
    append;
    FieldbyName('CPType').Value := '正品';
    FieldbyName('QtyUnit').Value := 'KG';
    FieldbyName('Rollnum').Value := 0;
    FieldbyName('qty').Value := 0;
    FieldbyName('Price').Value := 0;
    FieldbyName('MJID').Value := FMJID;

    Post;
  end;

//  frmClothGMListSel := TfrmClothGMListSel.Create(Application);
//  with frmClothGMListSel do
//  begin
//    if showmodal = 1 then
//    begin
//      while frmClothGMListSel.Order_Main.Locate('SSel', True, []) do
//      begin
//        FMJID := '';
//        if GetLSNo(self.ADOQueryCmd, FMJID, 'MJ', 'CP_InOut1', 4, 1) = False then
//        begin
//          Application.MessageBox('取最大号失败!', '提示', 0);
//          Exit;
//        end;
//        with Self.CDS_Main do
//        begin
//          append;
//          FieldbyName('CPType').Value := '正品';
//          FieldbyName('QtyUnit').Value := 'M';
//          FieldbyName('Rollnum').Value := 0;
//          FieldbyName('qty').Value := 0;
//          FieldbyName('Price').Value := 0;
//          FieldbyName('MJID').Value := FMJID;
//          fieldbyname('OrderNo').Value := trim(Order_Main.fieldbyname('OrderNo').AsString);
//          fieldbyname('MainID').Value := trim(Order_Main.fieldbyname('MainID').AsString);
//          fieldbyname('subID').Value := trim(Order_Main.fieldbyname('subID').AsString);
//          fieldbyname('P_Code').Value := trim(Order_Main.fieldbyname('MPRTCode').AsString);
//          fieldbyname('P_CodeName').Value := trim(Order_Main.fieldbyname('MPRTCodeName').AsString);
//          fieldbyname('P_SPEC').Value := trim(Order_Main.fieldbyname('MPRTSpec').AsString);
//          fieldbyname('P_Color').Value := trim(Order_Main.fieldbyname('PRTColor').AsString);
//          fieldbyname('P_MF').Value := trim(Order_Main.fieldbyname('MPRTMF').AsString);
//          fieldbyname('P_KZ').Value := trim(Order_Main.fieldbyname('MPRTKZ').AsString);
//          Post;
//        end;
//        frmClothGMListSel.Order_Main.Delete;
//      end;
//    end;
//    free;
//  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmPBTQCk.TBCloseClick(Sender: TObject);
begin
  writeCxGrid(self.Caption + tv1.Name, Tv1, '面料仓库');
  close;
end;

procedure TfrmPBTQCk.ToFactoryNameBtnClick(Sender: TObject);
begin
  if (trim(CRType.Text) = '加工出库') or (trim(CRType.Text) = '生产出库') or (trim(CRType.Text) = '退货出库') or (trim(CRType.Text) = '回修出库') then
  begin
    try
      frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
      with frmZdyAttachGYS do
      begin
        if ShowModal = 1 then
        begin
          ToFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
          fwdw.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        end;
      end;
    finally
      frmZdyAttachGYS.Free;
    end;
  end
  else
  begin
    try
      frmZdyAttachment := TfrmZdyAttachment.Create(Application);
      with frmZdyAttachment do
      begin
        if ShowModal = 1 then
        begin
          ToFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
          fwdw.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        end;
      end;
    finally
      frmZdyAttachment.Free;
    end;
  end;
end;

procedure TfrmPBTQCk.v1QtyPropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_Main do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    FieldbyName('Money').Value := format('%.2f', [FieldByName('Qty').AsFloat * FieldByName('Price').AsFloat]);
    Post;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmPBTQCk.FHAddressBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';
end;

procedure TfrmPBTQCk.v1Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  frmClothGMListSel := TfrmClothGMListSel.Create(Application);
  with frmClothGMListSel do
  begin
    if showmodal = 1 then
    begin
      CDS_Main.Edit;
      CDS_Main.fieldbyname('OrderNo').Value := trim(Order_Main.fieldbyname('OrderNo').AsString);
      CDS_Main.fieldbyname('MainID').Value := trim(Order_Main.fieldbyname('MainID').AsString);
      CDS_Main.fieldbyname('subID').Value := trim(Order_Main.fieldbyname('subID').AsString);
      CDS_Main.fieldbyname('P_Code').Value := trim(Order_Main.fieldbyname('MPRTCode').AsString);
      CDS_Main.fieldbyname('P_CodeName').Value := trim(Order_Main.fieldbyname('MPRTCodeName').AsString);
      CDS_Main.fieldbyname('P_SPEC').Value := trim(Order_Main.fieldbyname('MPRTSpec').AsString);
      CDS_Main.fieldbyname('P_Color').Value := trim(Order_Main.fieldbyname('PRTColor').AsString);
      CDS_Main.fieldbyname('P_MF').Value := trim(Order_Main.fieldbyname('MPRTMF').AsString);
      CDS_Main.fieldbyname('P_KZ').Value := trim(Order_Main.fieldbyname('MPRTKZ').AsString);
      CDS_Main.fieldbyname('KeHuKuanHao').Value := trim(Order_Main.fieldbyname('PrtKuanNO').AsString);
      CDS_Main.Post;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmPBTQCk.v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'MLType';
      flagname := '面料类型';
      if ShowModal = 1 then
      begin
        CDS_Main.Edit;
        CDS_Main.FieldByName('P_Type').Value := Trim(ClientDataSet1.fieldbyname('zdyName').AsString);
        CDS_Main.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmPBTQCk.ToolButton2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  if Trim(CDS_Main.FieldByName('CRNO').AsString) = '' then
  begin
    CDS_Main.Delete;
  end
  else
  begin
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('update CK_ml_CR set Valid=''N''  where MJID=' + quotedstr(Trim(CDS_Main.FieldByName('MJID').AsString)));
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('exec P_Up_mlKc ' + quotedstr(Trim(CDS_Main.FieldByName('MJID').AsString)));
      Open;
    end;
    if Trim(ADOQueryCmd.FieldByName('Msg').AsString) = '操作失败' then
    begin
      CDS_Main.EnableControls;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('出库数量超出库存数量!', '提示', 0);
      Exit;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    CDS_Main.Delete;
  end;
end;

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

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

procedure TfrmPBTQCk.fromFactoryNameBtnClick(Sender: TObject);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal = 1 then
      begin
        fromFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        FactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmPBTQCk.FactoryNameBtnClick(Sender: TObject);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal = 1 then
      begin
        FactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmPBTQCk.v1P_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  frmCPManageSel := TfrmCPManageSel.Create(self);
  with frmCPManageSel do
  begin
    if showmodal = 1 then
    begin
      self.CDS_Main.Edit;
      self.CDS_Main.fieldbyname('P_Code').Value := CDS_Main.fieldbyname('CYNo').asstring;
      self.CDS_Main.fieldbyname('P_CodeName').Value := CDS_Main.fieldbyname('CYName').asstring;
      self.CDS_Main.fieldbyname('P_SPEC').Value := CDS_Main.fieldbyname('CYSpec').asstring;
      self.CDS_Main.fieldbyname('P_MF').Value := CDS_Main.fieldbyname('CYMF').asstring;
      self.CDS_Main.fieldbyname('P_KZ').Value := CDS_Main.fieldbyname('CYKZ').asstring;
      self.CDS_Main.fieldbyname('P_Color').Value := CDS_Main.fieldbyname('CYColor').asstring;
      self.CDS_Main.Post;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmPBTQCk.ToolButton3Click(Sender: TObject);
var
  FMJID: string;
begin
  frmClothGMListSel := TfrmClothGMListSel.Create(Application);
  with frmClothGMListSel do
  begin
    if showmodal = 1 then
    begin
      while Order_Main.Locate('SSel', True, []) do
      begin
        FMJID := '';
        if GetLSNo(self.ADOQueryCmd, FMJID, 'MJ', 'CP_InOut1', 4, 1) = False then
        begin
          Application.MessageBox('取最大号失败!', '提示', 0);
          Exit;
        end;
        CDS_Main.append;
        CDS_Main.FieldbyName('CPType').Value := '正品';
        CDS_Main.FieldbyName('QtyUnit').Value := 'KG';
        CDS_Main.FieldbyName('Rollnum').Value := 0;
        CDS_Main.FieldbyName('qty').Value := 0;
        CDS_Main.FieldbyName('Price').Value := 0;
        CDS_Main.FieldbyName('MJID').Value := FMJID;
        CDS_Main.fieldbyname('OrderNo').Value := trim(Order_Main.fieldbyname('OrderNo').AsString);
        CDS_Main.fieldbyname('MainID').Value := trim(Order_Main.fieldbyname('MainID').AsString);
        CDS_Main.fieldbyname('subID').Value := trim(Order_Main.fieldbyname('subID').AsString);
        CDS_Main.fieldbyname('P_Code').Value := trim(Order_Main.fieldbyname('MPRTCode').AsString);
        CDS_Main.fieldbyname('P_CodeName').Value := trim(Order_Main.fieldbyname('MPRTCodeName').AsString);
        CDS_Main.fieldbyname('P_SPEC').Value := trim(Order_Main.fieldbyname('MPRTSpec').AsString);
        CDS_Main.fieldbyname('P_Color').Value := trim(Order_Main.fieldbyname('PRTColor').AsString);
        CDS_Main.fieldbyname('P_MF').Value := trim(Order_Main.fieldbyname('MPRTMF').AsString);
        CDS_Main.fieldbyname('P_KZ').Value := trim(Order_Main.fieldbyname('MPRTKZ').AsString);
        CDS_Main.fieldbyname('KeHuKuanHao').Value := trim(Order_Main.fieldbyname('PrtKuanNO').AsString);
        CDS_Main.Post;
        Order_Main.Delete;
      end;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

end.

