unit U_TCRk;

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, cxTextEdit, BtnEdit,
  cxCheckBox, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmTCRk = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    CRTime: TDateTimePicker;
    Label2: TLabel;
    CRType: TComboBox;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1P_CodeName: TcxGridDBColumn;
    v1PRTSpec: TcxGridDBColumn;
    v1P_MF: TcxGridDBColumn;
    v1P_KZ: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1MJXH: TcxGridDBColumn;
    v1MJId: TcxGridDBColumn;
    v1P_Color: TcxGridDBColumn;
    v1P_Code: TcxGridDBColumn;
    InoutNo: TEdit;
    Label8: TLabel;
    v1Price: TcxGridDBColumn;
    v1Money: TcxGridDBColumn;
    Label6: TLabel;
    v1Column2: TcxGridDBColumn;
    Label9: TLabel;
    FactoryName: TBtnEditA;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label3: TLabel;
    fromFactoryName: TBtnEditA;
    v1Column3: TcxGridDBColumn;
    Label4: TLabel;
    v1Column4: TcxGridDBColumn;
    btn1: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure v1P_ColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1P_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1P_ColorPropertiesEditValueChanged(Sender: TObject);
    procedure v1QtyPropertiesEditValueChanged(Sender: TObject);
    procedure v1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column8PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure FactoryNameBtnClick(Sender: TObject);
    procedure Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    procedure v1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure fromFactoryNameBtnClick(Sender: TObject);
    procedure btn1Click(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  private
    procedure InitGrid();
    function savedate(): Boolean;
    function CheckData(): Boolean;
    { Private declarations }
  public
    fkeyNO: string;
    FType: integer;

    { Public declarations }
  end;

var
  frmTCRk: TfrmTCRk;

implementation

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

function TfrmTCRk.CheckData(): Boolean;
begin
  try
    if Trim(CRType.Text) = '' then
      raise Exception.Create('入库类型不能为空！');
    if Trim(fromFactoryName.Text) = '' then
      raise Exception.Create('来自工厂不能为空！');
    if Trim(FactoryName.Text) = '' then
      raise Exception.Create('存放工厂不能为空！');
    if cds_main.IsEmpty then
      raise Exception.Create('产品信息不能为空！');
//    if cds_main.Locate('P_Code', NULL, []) then
//      raise Exception.Create('产品编号不能为空！');
//    if cds_main.Locate('P_Code', '', []) then
//      raise Exception.Create('产品编号不能为空！');
    if cds_main.Locate('P_CodeName', NULL, []) then
      raise Exception.Create('产品名称不能为空！');
    if cds_main.Locate('P_CodeName', '', []) then
      raise Exception.Create('产品名称不能为空！');
    if cds_main.Locate('qty', NULL, []) then
      raise Exception.Create('数量不能为空！');
    if cds_main.Locate('qty', 0, []) then
      raise Exception.Create('数量不能为0！');
    if cds_main.Locate('QtyUnit', NULL, []) then
      raise Exception.Create('数量单位不能为空！');
    if cds_main.Locate('QtyUnit', '', []) then
      raise Exception.Create('数量单位不能为空！');
    Result := True;
  except
    Result := false;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

function TfrmTCRk.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
        with ADOQueryCmd do
        begin
          close;
          sql.Clear;
          sql.Add('select * from CK_ML_CR');
          sql.Add('where CRNO=' + quotedstr(Trim(CDS_Main.FieldByName('CRNO').AsString)));
          open;
        end;
        if ADOQueryCmd.IsEmpty then
        begin
          if GetLSNo(ADOQueryTmp, MaxNo, 'MR', 'CK_ML_CR', 3, 1) = False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取最大号失败!', '提示', 0);
            Exit;
          end;
          ADOQueryCmd.Append;
          ADOQueryCmd.FieldByName('Filler').Value := trim(DName);
          ADOQueryCmd.FieldByName('FillTime').Value := dateTimetostr(SGetServerDateTime(adoqueryTmp));
        end
        else
        begin
          MaxNo := Trim(CDS_Main.FieldByName('CRNO').AsString);
          ADOQueryCmd.Edit;
          ADOQueryCmd.FieldByName('editer').Value := trim(dName);
          ADOQueryCmd.FieldByName('editTime').Value := SGetServerDateTime(adoqueryTmp);
        end;

        //保存主表
        ADOQueryCmd.FieldByName('InOutNo').Value := trim(InOutNo.Text);
        ADOQueryCmd.FieldByName('FactoryName').Value := trim(FactoryName.Text);
        ADOQueryCmd.FieldByName('fromFactoryName').Value := trim(fromFactoryName.Text);
        ADOQueryCmd.FieldByName('CRNO').Value := trim(MaxNo);
        ADOQueryCmd.FieldByName('CRTime').Value := formatdateTime('yyyy-MM-dd', CRTIme.Date);
        ADOQueryCmd.FieldByName('CKName').Value := trim('待检布');
        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('JGId').Value := trim(fieldbyname('JGId').AsString);
        ADOQueryCmd.FieldByName('MJID').Value := trim(fieldbyname('MJID').AsString);
        ADOQueryCmd.Post;

        //插入库存
        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;

        CDS_Main.Edit;
        CDS_Main.FieldByName('CRNO').Value := Trim(MaxNo);
        CDS_Main.Post;
        Next;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    result := true;
  except
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
  end;
end;

procedure TfrmTCRk.InitGrid();
var
  i: Integer;
begin
  try
    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('select A.* ');
      SQL.Add(' from CK_ML_CR A');
      sql.Add('where  A.CRNO=' + quotedstr(trim(fkeyNO)));
      open;
    end;
    SCreateCDS20(adoqueryTmp, CDS_Main);
    SInitCDSData20(adoqueryTmp, 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));
      inoutNo.Text := CDS_Main.fieldbyname('inoutNo').asstring;
      FactoryName.Text := trim(CDS_Main.fieldbyname('FactoryName').AsString);
      fromFactoryName.Text := trim(CDS_Main.fieldbyname('fromFactoryName').AsString);

    end;
  finally
  end;
end;

procedure TfrmTCRk.FormDestroy(Sender: TObject);
begin
  frmTCRk := nil;
end;

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

procedure TfrmTCRk.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  writeCxGrid(self.Caption + tv1.Name + '1', Tv1, '面料仓库');
  Action := cahide;
end;

procedure TfrmTCRk.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption, Tv1, '待检布');
  InitGrid();
  if fType = 0 then
  begin
    if GetLSNo(ADOQueryCmd, fkeyNo, 'MRK', 'CK_ML_CR', 3, 1) = False then
    begin
      Application.MessageBox('取最大号失败!', '提示', 0);
      Exit;
    end;
    inoutNo.Text := Trim(fkeyNo);
  end;
end;

procedure TfrmTCRk.TBSaveClick(Sender: TObject);
begin
  if CheckData() = false then
    exit;
  CRTime.SetFocus;
  if savedate() then
  begin
    application.MessageBox('数据保存成功！', '提示信息');
    ModalResult := 1;
  end
  else
  begin
    application.MessageBox('数据保存失败！', '提示信息', MB_ICONERROR);
  end;
end;

procedure TfrmTCRk.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;
  if CDS_Main.IsEmpty then
  begin
    with 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;
  end
  else
  begin
    CopyAddRowCDS(CDS_Main);
    with CDS_Main do
    begin
      edit;
      FieldbyName('MJID').Value := FMJID;
      FieldbyName('CRNO').Value := '';
      post;
    end;
  end;
end;

procedure TfrmTCRk.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 CRNO=' + quotedstr(Trim(CDS_Main.FieldByName('CRNO').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 TfrmTCRk.TBCloseClick(Sender: TObject);
begin
  writeCxGrid(self.Caption, Tv1, '待检布');
  close;
end;

procedure TfrmTCRk.v1P_ColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'OrdColor';
      flagname := '颜色';
      V1Name.Caption := '中文名称';
      V1Note.Caption := '英文名称';
      MainType := Trim(DName);
      fnote := True;
      if ShowModal = 1 then
      begin
        Self.CDS_Main.Edit;
        Self.CDS_Main.FieldByName('P_Color').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.CDS_Main.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  self.tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmTCRk.v1P_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  FKuWei: string;
begin
//  try
//    frmZdyAttachCP20:=TfrmZdyAttachCP20.Create(Application);
//    with frmZdyAttachCP20 do
//    begin
//      CKType.Text:='面料';
//      if ShowModal=1 then
//      begin
//        Self.CDS_Main.Edit;
////        Self.CDS_Main.FieldByName('WLType').Value:=Trim(CDS_HZ.fieldbyname('WLType').AsString);
//        Self.CDS_Main.FieldByName('P_Code').Value:=Trim(CDS_HZ.fieldbyname('ZdyCode').AsString);
//        Self.CDS_Main.FieldByName('P_CodeName').Value:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
//        Self.CDS_Main.FieldByName('P_SPEC').Value:=Trim(CDS_HZ.fieldbyname('DEFstr1').AsString);
////        Self.CDS_Main.FieldByName('P_Color').Value:=Trim(CDS_HZ.fieldbyname('DEFstr1').AsString);
//        Self.CDS_Main.FieldByName('P_MF').Value:=Trim(CDS_HZ.fieldbyname('DEFstr7').AsString);
//        Self.CDS_Main.FieldByName('P_KZ').Value:=Trim(CDS_HZ.fieldbyname('DEFstr8').AsString);
//        Self.CDS_Main.FieldByName('qtyUnit').Value:=Trim(CDS_HZ.fieldbyname('DEFstr4').AsString);
//      end;
//    end;
//  finally
//    frmZdyAttachCP20.Free;
//  end;
//  self.tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmTCRk.v1P_ColorPropertiesEditValueChanged(Sender: TObject);
var
  mvalue: string;
begin
 { mvalue:=TcxTextEdit(Sender).EditingText;

  IF trim(mvalue)='' then exit;

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



  with CDS_Main do
  begin
    Edit;
    FieldByName('P_Color').Value:=Trim(mvalue);
    Post;
  end;
  self.tv1.Controller.EditingController.ShowEdit();  }
end;

procedure TfrmTCRk.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 TfrmTCRk.v1Column2PropertiesButtonClick(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.Post;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmTCRk.v1Column8PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'CPProperty';
      flagname := '面料属性';
      if ShowModal = 1 then
      begin
        Self.CDS_Main.Edit;
        Self.CDS_Main.FieldByName('CPProperty').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmTCRk.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 TfrmTCRk.Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    FValue := IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + 1);
    FBounds := AViewInfo.Bounds;
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 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 TfrmTCRk.v1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'kuwei';
      flagname := '库位';

      if ShowModal = 1 then
      begin
        Self.CDS_Main.Edit;
        Self.CDS_Main.FieldByName('kuwei').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.CDS_Main.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  self.tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmTCRk.fromFactoryNameBtnClick(Sender: TObject);
begin

  if (trim(CRType.Text) = '客供入库') then
  begin
    try
      frmZdyAttachment := TfrmZdyAttachment.Create(Application);
      with frmZdyAttachment do
      begin
        if ShowModal = 1 then
        begin
          fromFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        end;
      end;
    finally
      frmZdyAttachment.Free;
    end;
  end
  else
  begin
    try
      frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
      with frmZdyAttachGYS do
      begin
        if ShowModal = 1 then
        begin
          fromFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        end;
      end;
    finally
      frmZdyAttachGYS.Free;
    end;

  end;
end;

procedure TfrmTCRk.btn1Click(Sender: TObject);
var
  FMJID: string;
begin

  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 := 'KG';
          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 TfrmTCRk.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if CDS_Main.fieldbyname('ISRCCK').AsString = '染厂发货' then
  begin
    v1P_Code.Options.Editing := True;
  end;
end;

end.

