unit U_ConInPutNXKFSH;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, cxMemo, cxRichEdit, ComCtrls, cxContainer,
  cxTextEdit, cxMaskEdit, cxButtonEdit, StdCtrls, ToolWin, DBClient, ADODB,
  ExtCtrls, BtnEdit, cxCalendar,StrUtils, cxDropDownEdit,
  cxGridCustomPopupMenu, cxGridPopupMenu;

type
  TfrmConInPutNXKFSH = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label3: TLabel;
    OrdDate: TDateTimePicker;
    Label4: TLabel;
    DlyDate: TDateTimePicker;
    Label7: TLabel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1PRTColor: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    v1PRTOrderQty: TcxGridDBColumn;
    Label9: TLabel;
    Label10: TLabel;
    ConNo: TEdit;
    Label11: TLabel;
    Label14: TLabel;
    Label20: TLabel;
    FromPlace: TBtnEditC;
    CustomerNoName: TBtnEditC;
    v1XHNo: TcxGridDBColumn;
    SYRName: TBtnEditC;
    Label6: TLabel;
    QtyNote: TBtnEditC;
    DlyNote: TBtnEditC;
    CDS_Type: TClientDataSet;
    Label34: TLabel;
    KHConNo: TEdit;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    Button1: TButton;
    Button2: TButton;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Order_Note: TClientDataSet;
    DataSource2: TDataSource;
    v1Column14: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Label1: TLabel;
    XSType: TComboBox;
    Label16: TLabel;
    ConQtyUnit: TComboBox;
    v1Column3: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    ConPerson1: TBtnEditC;
    Label25: TLabel;
    SQRatio: TEdit;
    Label29: TLabel;
    IsHS: TComboBox;
    Label33: TLabel;
    zlbz: TBtnEditC;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    Label35: TLabel;
    ZhiYuan: TComboBox;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure CustomerNoNameBtnUpClick(Sender: TObject);
    procedure CustomerNoNameBtnDnClick(Sender: TObject);
    procedure v1Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure SYRNameBtnUpClick(Sender: TObject);
    procedure CPCFNoDblClick(Sender: TObject);
    procedure CPRanHouGYBtnDnClick(Sender: TObject);
    procedure v1Column4PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure v1Column14PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column8PropertiesEditValueChanged(Sender: TObject);
    procedure v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure v1Column13PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column16PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column15PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
        fuserName:string;
    procedure InitData();
    procedure ZDYHelp(FButn:TcxButtonEdit;LType:string);
    function  SaveData():Boolean;
    function  SaveDataSubOne():Boolean;
    function  SaveDataMain():Boolean;
    function SaveDataSubMore():Boolean;
    { Private declarations }
  public
    PState,CopyInt:Integer;
    FMainId,FFMainId,ChkStr,ConPriceStr:String;
    FXS:Integer;
    { Public declarations }
  end;

var
  frmConInPutNXKFSH: TfrmConInPutNXKFSH;
  newh:hwnd;
implementation
uses
  U_DataLink,U_ZDYHelp,U_Fun,U_ZDYHelpSel, U_ZdyAttachment,
  U_CPManageFMSel;

{$R *.dfm}

procedure TfrmConInPutNXKFSH.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('合同录入内销RZ',Tv1,'生产指示单管理');
end;

procedure TfrmConInPutNXKFSH.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from KH_Zdy where Type=''MPRTNameType'' ');
    Open;
  end;
  SCreateCDS20(ADOQuery1,CDS_Type);
  SInitCDSData20(ADOQuery1,CDS_Type);
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrderCon_Sub_PB ');
    if PState=1 then
    begin
      sql.Add('where MainId='''+Trim(FMainId)+'''');
    end;
    if PState=0 then
    begin
      sql.Add(' where 1<>1');
    end;
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrderCon_Main_Note_PB ');
    if PState=1 then
    begin
      sql.Add('where MainId='''+Trim(FMainId)+'''');
    end;
    if PState=0 then
    begin
      sql.Add(' where 1<>1');
    end;
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_Note);
  SInitCDSData20(ADOQuery1,Order_Note);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrderCon_Main_PB where MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,ScrollBox1,2);
  SYRName.TxtCode:=Trim(ADOQuery1.fieldbyname('ConDefStr2').AsString);
  ConNo.Text:=Trim(ADOQuery1.fieldbyname('ConNo').AsString);
  if Trim(ADOQuery1.fieldbyname('status').AsString)='1' then
  begin
    ChkStr:='已审核';
  end;
  if PState=0 then
  begin
    OrdDate.DateTime:=SGetServerDateTime(ADOTemp);
    DlyDate.DateTime:=SGetServerDateTime(ADOTemp);
    //ConPerson1.Text:=Trim(DName);
  end else
  begin
  end;
  if CopyInt=99 then
  begin
    PState:=0;
    FMainId:='';
    //ConPerson1.Text:=Trim(DName);
    ConNo.Text:='';
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value:='';
        FieldByName('SubId').Value:='';
        Post;
        Next;
      end;
    end;
    with Order_Note do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value:='';
        FieldByName('MNId').Value:='';
        Post;
        Next;
      end;
    end;
  end;
  
end;

procedure TfrmConInPutNXKFSH.ZDYHelp(FButn:TcxButtonEdit;LType:string);
var
  FType,ZDYName,FText:String;
begin
end;

procedure TfrmConInPutNXKFSH.FormShow(Sender: TObject);
begin
  fuserName:=DCode;
  readCxGrid('合同录入内销RZ',Tv1,'生产指示单管理');
  InitData();
  if CopyInt=99 then Exit;

   ScrollBox1.Enabled:=False;
end;

function TfrmConInPutNXKFSH.SaveData():Boolean;
var
  maxno,maxmnno,MConNo,MConFlag:String;
  fconNO,fmxType:string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    maxno:=Trim(FMainId);
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrderCon_Main_PB where MainId='''+Trim(FMainId)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      Edit;
      SSetsaveSqlNew(ADOCmd,'JYOrderCon_Main_PB',ScrollBox1,3);
      Post;
    end;
 


    FMainId:=Trim(maxno);
  
    ///保存子表
    
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        maxno:=Trim(Order_Sub.fieldbyname('SubId').AsString);
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrderCon_Sub_PB where MainId='''+Trim(FMainId)+'''');
          sql.Add(' and SubId='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          Edit;
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'JYOrderCon_Sub_PB',0);
          Post;
        end;
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except

    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
    Result:=False;
  end;
end;
function TfrmConInPutNXKFSH.SaveDataMain():Boolean;
var
  maxno:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrder_Main where MainId='''+Trim(FMainId)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId)='' then
      begin
        Append;
        maxno:=Trim(FFMainId);
      end
      else begin
        maxno:=Trim(FMainId);
        Edit;
      end;
      FieldByName('MainId').Value:=Trim(maxno);
      SSetsaveSqlNew(ADOCmd,'JYOrder_Main',ScrollBox1,2);
      if PState=1 then
      begin
        FieldByName('OrdUpDate').Value:=SGetServerDateTime(ADOTemp);
      end;
      if Trim(FMainId)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
      end else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
      end;
      Post;
    end;
    FMainId:=Trim(maxno);
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except

    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
    Result:=False;
  end;
end;
function TfrmConInPutNXKFSH.SaveDataSubOne():Boolean;
var
  maxno:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存子表
    with Order_Sub do
    begin
      //First;
      //while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
        begin
          if GetLSNo(ADOTemp,maxno,'JS','JYOrder_Sub',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Sub where MainId='''+Trim(FMainId)+'''');
          sql.Add(' and SubId='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
            Append
          else
            Edit;
          FieldByName('MainId').Value:=Trim(FMainId);
          FieldByName('SubId').Value:=Trim(maxno);
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'JYOrder_Sub',0);
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value:=Trim(maxno);
        //Order_Sub.Post;
        //Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常！','提示',0);
  end;
end;
function TfrmConInPutNXKFSH.SaveDataSubMore():Boolean;
var
  maxno:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
        begin
          if GetLSNo(ADOTemp,maxno,'JS','JYOrder_Sub',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Sub where MainId='''+Trim(FMainId)+'''');
          sql.Add(' and SubId='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
            Append
          else
            Edit;
          FieldByName('MainId').Value:=Trim(FMainId);
          FieldByName('SubId').Value:=Trim(maxno);
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'JYOrder_Sub',0);
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value:=Trim(maxno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常！','提示',0);
  end;
end;

procedure TfrmConInPutNXKFSH.TBSaveClick(Sender: TObject);
var
    MaxDS,FlagDS:string;
begin
  ToolBar1.SetFocus;
 
  if Order_Sub.Locate('KFNote',null,[])=True then
  begin
    Application.MessageBox('开福要求不能为空！','提示',0);
    Exit;
  end;
  if Order_Sub.Locate('KFNote','',[])=True then
  begin
    Application.MessageBox('开福要求不能为空！','提示',0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
  end;
end;

procedure TfrmConInPutNXKFSH.v1PRTColorPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdColor';
      flagname:='颜色';
      V1Name.Caption:='中文名称';
     // V1Note.Caption:='英文名称';
      //fnote:=True;
      MainType:=Trim(DName);
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PRTColor').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        //Self.Order_Sub.FieldByName('SOrdDefStr4').Value:=Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPutNXKFSH.CustomerNoNameBtnUpClick(Sender: TObject);
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from FHSQ_Main where ConMainId='''+Trim(FMainId)+'''');
    Open;
  end;
  if ADOTemp.IsEmpty=False  then
  begin
    Application.MessageBox('已做发货申请，不能修改客户！','提示',0);
    Exit;
  end;
  try
    frmZdyAttachment:=TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
      if ShowModal=1 then
      begin
        CustomerNoName.Text:=Trim(CDS_HZ.fieldbyname('CoName').AsString);
        CustomerNoName.TxtCode:=Trim(CDS_HZ.fieldbyname('CoCode').AsString);
        Self.ConPerson1.Text:=Trim(CDS_HZ.fieldbyname('Salesman').AsString);
        with ADOTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select Top 1* from JYOrderCon_Main_PB where CustomerNoName='''+Trim(CDS_HZ.fieldbyname('CoName').AsString)+'''');
          sql.Add(' order by FillTime desc');
          Open;
          
         
          
        
          
          if Trim(ADOTemp.fieldbyname('ConPerson1').AsString)<>'' then
          Self.ConPerson1.Text:=Trim(ADOTemp.fieldbyname('ConPerson1').AsString);
        end;
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmConInPutNXKFSH.CustomerNoNameBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text:='';
  TBtnEditC(Sender).TxtCode:='';
end;

procedure TfrmConInPutNXKFSH.v1Column1PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);

begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ZhenZhiNote';
      flagname:='织针要求';
      if ShowModal=1 then
      begin
        Order_Sub.Edit;
        Order_Sub.fieldbyname('ZhenZhiNote').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
       
        Order_Sub.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNXKFSH.v1OrderUnitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrderUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('OrderUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPutNXKFSH.v1PriceUnitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PriceUnit';
      flagname:='价格单位';
      if Trim(DParameters1)<>'高权限' then
      begin
        TBAdd.Visible:=False;
        TBEdit.Visible:=False;
        TBDel.Visible:=False;
      end;
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PriceUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPutNXKFSH.SYRNameBtnUpClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
begin
  fsj:=Trim(TEdit(Sender).Hint);
  FWZ:=Pos('/',fsj);
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      if Trim(flag)='SYRName' then
      begin
        flag:='GSTTPB';
        V1Name.Caption:='中文名称';
      end;
      if Trim(flag)='BankNo' then
      begin
        fnote:=True;
      end;
      if ShowModal=1 then
      begin
        
          TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

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

procedure TfrmConInPutNXKFSH.CPCFNoDblClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MPRTNameType';
      flagname:='产品类别定义';
      V1HelpType.Visible:=True;
      V1HelpType.Caption:='缩写名';
      fnote:=True;
      V1Name.Caption:='中文';
      V1Note.Caption:='英文';
      if ShowModal=1 then
      begin
        with ADOQuery1 do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from KH_Zdy where Type=''MPRTNameType'' ');
          Open;
        end;
        SCreateCDS20(ADOQuery1,CDS_Type);
        SInitCDSData20(ADOQuery1,CDS_Type);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPutNXKFSH.CPRanHouGYBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text:='';
  TBtnEditC(Sender).TxtCode:='';

end;

procedure TfrmConInPutNXKFSH.v1Column4PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MPRTCodeNameZW';
      flagname:='产品名称';
      if ShowModal=1 then
      begin
        Order_Sub.Edit;
        Order_Sub.fieldbyname('PRTCodeName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        //Order_Sub.fieldbyname('PRTCode').Value:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
        Order_Sub.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNXKFSH.Button1Click(Sender: TObject);
var
  i:Integer;
begin
  i:=Order_Note.RecordCount;
  i:=i+1;
  with Order_Note do
  begin
    Append;
    FieldByName('XHNO').Value:=IntToStr(i);
    Post;
  end;
end;

procedure TfrmConInPutNXKFSH.Button2Click(Sender: TObject);
begin
  if Order_Note.IsEmpty then Exit;
  if Trim(Order_Note.fieldbyname('MNId').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrderCon_Main_Note_PB where MNId='''+Trim(Order_Note.fieldbyname('MNId').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_Note.Delete;
end;

procedure TfrmConInPutNXKFSH.v1Column14PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
var
  fsj:string;
  FWZ:Integer;
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Cloth_Main where ConSubId='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
    Open;
  end;
  if ADOTemp.IsEmpty=False  then
  begin
    Application.MessageBox('已做计划单，不能修改编号！','提示',0);
    Exit;
  end;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from FHSQ_Main where ConSubId='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
    Open;
  end;
  if ADOTemp.IsEmpty=False  then
  begin
    Application.MessageBox('已做发货申请，不能修改编号！','提示',0);
    Exit;
  end;
  try
    frmCPManageFMSel:=TfrmCPManageFMSel.Create(Application);
    with frmCPManageFMSel do
    begin
      if ShowModal=1 then
      begin
        with Self.Order_Sub do
        begin
          Edit;
          FieldByName('PrtCode').Value:=frmCPManageFMSel.CDS_Main.fieldbyname('CYNo').Value;
          FieldByName('PrtCodeName').Value:=frmCPManageFMSel.CDS_Main.fieldbyname('CYName').Value;
          FieldByName('PRTspec').Value:=frmCPManageFMSel.CDS_Main.fieldbyname('HZSPEC').Value;
          FieldByName('PRTColor').Value:=frmCPManageFMSel.CDS_Main.fieldbyname('CYColor').Value;
          FieldByName('PRTMF').Value:=frmCPManageFMSel.CDS_Main.fieldbyname('CYMF').Value;
          FieldByName('PRTKZ').Value:=frmCPManageFMSel.CDS_Main.fieldbyname('CYKZ').Value;
        end;
      end;
    end;
  finally
    frmCPManageFMSel.Free;
  end;
end;

procedure TfrmConInPutNXKFSH.v1Column8PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
  FPiShu,FPiZhong:double;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with Order_Sub do
  begin
    Edit;
    FieldByName(FFieldName).Value:=mvalue;
    Post;
    FPiShu:=FieldByName('PiShu').AsFloat;
    FPiZhong:=FieldByName('PiZhong').AsFloat;

  end;
  with Order_Sub do
  begin
    Edit;
    FieldByName('PRTOrderQty').Value:=FPiShu*FPiZhong;
    Post;
  end;
    tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNXKFSH.v1PRTOrderQtyPropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
  FPRTOrderQty:double;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with Order_Sub do
  begin
    Edit;
    FieldByName(FFieldName).Value:=mvalue;
    FieldByName('SCQty').Value:=mvalue;
    Post;

  end;
end;
procedure TfrmConInPutNXKFSH.v1Column13PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ZZSunHao';
      flagname:='织造损耗';
      if ShowModal=1 then
      begin
        Order_Sub.Edit;
        Order_Sub.fieldbyname('ZZSunHao').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
       
        Order_Sub.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNXKFSH.v1Column16PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ZongJieNote';
      flagname:='批量风险总结';
      if ShowModal=1 then
      begin
        Order_Sub.Edit;
        Order_Sub.fieldbyname('ZongJieNote').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

        Order_Sub.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNXKFSH.v1Column15PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MeiFenZhuanSu';
      flagname:='转速/分';
      if ShowModal=1 then
      begin
        Order_Sub.Edit;
        Order_Sub.fieldbyname('MeiFenZhuanSu').Value:=strtointdef(Trim(ClientDataSet1.fieldbyname('ZDYName').AsString),0);

        Order_Sub.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

end.
