unit U_ConInPutNX;

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

type
  TfrmConInPutNX = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label3: TLabel;
    OrdDate: TDateTimePicker;
    Label4: TLabel;
    DlyDate: TDateTimePicker;
    Label7: TLabel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1PRTColor: TcxGridDBColumn;
    v1PRTPrice: 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;
    Label15: TLabel;
    Payment: TBtnEditC;
    Label17: TLabel;
    Label18: TLabel;
    BankNo: TBtnEditC;
    Label19: TLabel;
    Label21: TLabel;
    Label8: TLabel;
    Label23: TLabel;
    DlyNote: TBtnEditC;
    CDS_Type: TClientDataSet;
    Label22: TLabel;
    Label24: TLabel;
    Label34: TLabel;
    KHConNo: TEdit;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    Label2: TLabel;
    Label5: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    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;
    v1Column1: TcxGridDBColumn;
    TelNo: TBtnEditC;
    FaxNo: TBtnEditC;
    BankName: TBtnEditC;
    v1Column3: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    GFLXPerson: TBtnEditC;
    GFLXTel: TBtnEditC;
    SYRAddress: TBtnEditC;
    CTMAddress: TBtnEditC;
    XFLXPerson: TBtnEditC;
    XFLXTel: TBtnEditC;
    CTMFaxNo: TBtnEditC;
    CTMTelNo: TBtnEditC;
    ConPerson1: TBtnEditC;
    Label25: TLabel;
    SQRatio: TEdit;
    Label26: TLabel;
    YsFs: TBtnEditC;
    Label27: TLabel;
    BzNote: TBtnEditC;
    Label28: TLabel;
    JsFs: TBtnEditC;
    Label30: TLabel;
    WyZr: TBtnEditC;
    Label31: TLabel;
    HtJf: TBtnEditC;
    Label32: TLabel;
    QtTk: TBtnEditC;
    Label29: TLabel;
    IsHS: TComboBox;
    Label33: TLabel;
    zlbz: TBtnEditC;
    v1Column10: TcxGridDBColumn;
    Label35: TLabel;
    ZhiYuan: TComboBox;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    ToolButton3: TToolButton;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    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 Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure v1Column8PropertiesEditValueChanged(Sender: TObject);
    procedure v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure DlyDateChange(Sender: TObject);
    procedure v1Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column3PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  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
  frmConInPutNX: TfrmConInPutNX;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_ZDYHelpSel, U_ZdyAttachment, U_CPManageFMSel,
  DateUtils, U_FjList_RZ;

{$R *.dfm}

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

procedure TfrmConInPutNX.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 TfrmConInPutNX.ZDYHelp(FButn: TcxButtonEdit; LType: string);
var
  FType, ZDYName, FText: string;
begin
end;

procedure TfrmConInPutNX.FormShow(Sender: TObject);
begin
  fuserName := DCode;
  readCxGrid('合同录入内销RZ', Tv1, '生产指示单管理');
  InitData();
  if CopyInt = 99 then
    Exit;
  if ChkStr = '已审核' then
  begin
    ScrollBox1.Enabled := False;
    ToolBar2.Visible := False;
    v1XHNo.Options.Focusing := False;
    v1Column14.Options.Focusing := False;
    v1Column4.Options.Focusing := False;
    v1Column5.Options.Focusing := False;
    v1PRTColor.Options.Focusing := False;
    v1Column6.Options.Focusing := False;
    v1Column7.Options.Focusing := False;
    v1PRTOrderQty.Options.Focusing := False;
    v1Column1.Options.Focusing := False;
    v1Column2.Options.Focusing := False;
    v1Column8.Options.Focusing := False;
    v1Column3.Options.Focusing := False;
  end;
end;

function TfrmConInPutNX.SaveData(): Boolean;
var
  maxno, maxmnno, MConNo, MConFlag: string;
  fconNO, fmxType: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId) = '' then
    begin

      if GetLSNo(ADOCmd, maxno, 'RT', 'JYOrderCon_Main_PB', 2, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
      maxno := Copy(maxno, 1, 2) + '20' + Copy(maxno, 3, Length(maxno) - 2);

      if trim(XSType.Text) = '开发样' then
      begin
        if GetLSNo(ADOCmd, MConNo, 'SHJSKF', 'JYOrderCon_Main_PB', 3, 1) = False then
        begin
          ADOCmd.Connection.RollbackTrans;
          Application.MessageBox('取最大号失败!', '提示', 0);
          Exit;
        end;
        MConNo := 'SHJSKF' + copy(MConNo, 7, 9);
//        ForOrderNo.Text:=  trim(MConNo);
        //SHJSKF020306001
      end
      else
      begin
        //SH020602 0057
        MConFlag := trim(copy(maxno, 3, 4));
        if GetLSNo(ADOCmd, MConNo, MConFlag, 'JYOrderCon_Main_PB', 4, 0) = False then
        begin
          ADOCmd.Connection.RollbackTrans;
          Application.MessageBox('取最大号失败!', '提示', 0);
          Exit;
        end;
        MConNo := 'SH' + copy(trim(maxno), 5, 6) + copy(trim(MConNo), 5, 4);
      end;
    end
    else
    begin
      maxno := Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrderCon_Main_PB where MainId=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
        FieldByName('ConNo').Value := Trim(MConNo);
      end
      else
      begin
        Edit;
      end;
      FieldByName('MainId').Value := Trim(maxno);
      SSetsaveSqlNew(ADOCmd, 'JYOrderCon_Main_PB', ScrollBox1, 2);
      FieldByName('ConDefStr2').Value := Trim(SYRName.TxtCode);
      if Trim(FMainId) = '' then
      begin
        FieldByName('Filler').Value := Trim(DName);
        FieldByName('FillerCode').Value := Trim(DCode);
      end
      else
      begin
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
      end;
      FieldByName('MPRTType').Value := '内销';
      Post;
    end;
//    with ADOCmd do
//    begin
//      Close;
//      SQL.Clear;
//      SQL.Add('select * from JYOrderCon_Main_PB where ForOrderNo='+quotedstr(Trim(ForOrderNo.Text)));
//      Open;
//    end;
//    if ADOCmd.RecordCount>1 then
//    begin
//      Application.MessageBox('订单号不能重复！','提示',0);
//      Exit;
//    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate JYOrderCon_Main_PB Set Filler=''' + Trim(DName) + '''');
      sql.Add(' where MainId=''' + Trim(FMainId) + '''');
      ExecSQL;
    end;
    FMainId := Trim(maxno);
    ///保存备注表
    with Order_Note do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Note.fieldbyname('MNId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxmnno, 'MN', 'JYOrderCon_Main_Note_PB', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取备注流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxmnno := Trim(Order_Note.fieldbyname('MNId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrderCon_Main_Note_PB where MainId=''' + Trim(FMainId) + '''');
          sql.Add(' and MNId=''' + Trim(maxmnno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Note.fieldbyname('MNId').AsString) = '' then
            Append
          else
            Edit;
          FieldByName('MainId').Value := Trim(FMainId);
          FieldByName('MNId').Value := Trim(maxmnno);
          FieldByName('MNType').Value := '内销';
          RTSetSaveDataCDS(ADOCmd, Tv2, Order_Note, 'JYOrderCon_Main_Note_PB', 0);
          Post;
        end;
        Order_Note.Edit;
        Order_Note.FieldByName('MNId').Value := Trim(maxmnno);
        Next;
      end;
    end;
    ///保存备注表
    ///保存子表

    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxno, 'JB', 'JYOrderCon_Sub_PB', 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 JYOrderCon_Sub_PB 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, 'JYOrderCon_Sub_PB', 0);
          FieldByName('OrderUnit').Value := Trim(ConQtyUnit.Text);
          if Trim(fieldbyname('PRTOrderQty').AsString) = '' then
          begin
            fieldbyname('PRTOrderQty').Value := 0
          end;
          if Trim(fieldbyname('PRTPrice').AsString) = '' then
          begin
            fieldbyname('PRTPrice').Value := 0
          end;
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value := Trim(maxno);
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          SQL.Add('Update JYOrderCon_Sub_PB Set ConMXMoney=Cast(PRTPrice*PRTOrderQty as decimal(18,2))+isnull(DYMoney,0)');
          sql.Add(' where SubId=''' + Trim(maxno) + '''');
          ExecSQL;
        end;

        //Order_Sub.Post;
        Next;
      end;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update JYOrderCon_Main_PB Set ');
      sql.Add('ConMoney=(select Sum(ConMXMoney) from JYOrderCon_Sub_PB A where A.MainId=JYOrderCon_Main_PB.MainId)');
      sql.Add(',ConQty=(select Sum(PRTOrderQty) from JYOrderCon_Sub_PB A where A.MainId=JYOrderCon_Main_PB.MainId)');
      sql.Add('where MainId=''' + Trim(FMainId) + '''');
      ExecSQL;
    end;
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except

    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
    Result := False;
  end;
end;

function TfrmConInPutNX.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 TfrmConInPutNX.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 TfrmConInPutNX.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 TfrmConInPutNX.TBSaveClick(Sender: TObject);
var
  MaxDS, FlagDS: string;
begin
  ToolBar1.SetFocus;
//  if Trim(ForOrderNo.Text)='' then
//  begin
//    FlagDS:='DS'+Trim(FormatDateTime('yyyyMM',SGetServerDate10(ADOTemp)));
//    if GetLSNo(ADOCmd,MaxDS,FlagDS,'JYOrderCon_Main_PB',3,0)=False then
//    begin
//      Application.MessageBox('取最大号失败!','提示',0);
//      Exit;
//    end;
//
//    ForOrderNo.Text:=MaxDS;
//  end;

  if Trim(ZhiYuan.Text) = '' then
  begin
    Application.MessageBox('资源不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(CustomerNoName.Text) = '' then
  begin
    Application.MessageBox('需方不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(ConPerson1.Text) = '' then
  begin
    Application.MessageBox('业务员不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(SYRName.Text) = '' then
  begin
    Application.MessageBox('供方不能为空！', '提示', 0);
    Exit;
  end;
  if DlyDate.Checked = False then
  begin
    Application.MessageBox('交货日期不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(ConQtyUnit.Text) = '' then
  begin
    Application.MessageBox('单位不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(IsHS.Text) = '' then
  begin
    Application.MessageBox('是否含税不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(XSType.Text) = '' then
  begin
    Application.MessageBox('类型不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(XSType.Text) = '打样' then
  begin
    if Order_Sub.Locate('DYMoney', Null, []) then
    begin
      Application.MessageBox('打样费不能为空!', '提示', 0);
      Exit;
    end;
  end;
  if Order_Sub.Locate('PrtCodeName', null, []) = True then
  begin
    Application.MessageBox('产品名称不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('PRTOrderQty', null, []) = True then
  begin
    Application.MessageBox('数量不能为空！', '提示', 0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
  end;
end;

procedure TfrmConInPutNX.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 TfrmConInPutNX.ToolButton1Click(Sender: TObject);
var
  i: Integer;
begin
  {if Trim(ConNo.Text)='' then
  begin
    Application.MessageBox('合同号不能为空!','提示',0);
    Exit;
  end; }
  i := Order_Sub.RecordCount;
  i := i + 1;
  CopyAddRow(Tv1, Order_Sub);
  with Order_Sub do
  begin
    Edit;
    FieldByName('XHNO').Value := IntToStr(i);
    FieldByName('PRTColor').Value := '';
    FieldByName('PRTOrderQty').Value := null;
   // FieldByName('PRTPrice').Value:=null;
    FieldByName('SOrddefstr4').Value := null;
    FieldByName('PriceUnit').Value := 'RMB';
    Post;
  end;
end;

procedure TfrmConInPutNX.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  if Trim(Order_Sub.fieldbyname('SubId').AsString) <> '' then
  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;
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrderCon_Sub_PB where SubId=''' + Trim(Order_Sub.fieldbyname('SubId').AsString) + '''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update JYOrderCon_Main_PB Set ');
    sql.Add('ConMoney=(select Sum(ConMXMoney) from JYOrderCon_Sub_PB A where A.MainId=JYOrderCon_Main_PB.MainId)');
    sql.Add(',ConQty=(select Sum(PRTOrderQty) from JYOrderCon_Sub_PB A where A.MainId=JYOrderCon_Main_PB.MainId)');
    sql.Add('where MainId=''' + Trim(FMainId) + '''');
    ExecSQL;
  end;
end;

procedure TfrmConInPutNX.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.CTMAddress.Text := Trim(CDS_HZ.fieldbyname('CoAddress').AsString);
//        Self.CTMTelNo.Text:=Trim(CDS_HZ.fieldbyname('SDEFstr4').AsString);
//        Self.CTMFaxNo.Text:=Trim(CDS_HZ.fieldbyname('SDEFstr3').AsString);
//        Self.XFLXPerson.Text:=Trim(CDS_HZ.fieldbyname('SDEFstr1').AsString);
//        Self.XFLXTel.Text:=Trim(CDS_HZ.fieldbyname('SDEFstr5').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('CTMAddress').AsString) <> '' then
            Self.CTMAddress.Text := Trim(ADOTemp.fieldbyname('CTMAddress').AsString);
          if Trim(ADOTemp.fieldbyname('CTMTelNo').AsString) <> '' then
            Self.CTMTelNo.Text := Trim(ADOTemp.fieldbyname('CTMTelNo').AsString);
          if Trim(ADOTemp.fieldbyname('CTMFaxNo').AsString) <> '' then
            Self.CTMFaxNo.Text := Trim(ADOTemp.fieldbyname('CTMFaxNo').AsString);
          if Trim(ADOTemp.fieldbyname('XFLXPerson').AsString) <> '' then
            Self.XFLXPerson.Text := Trim(ADOTemp.fieldbyname('XFLXPerson').AsString);
          if Trim(ADOTemp.fieldbyname('XFLXTel').AsString) <> '' then
            Self.XFLXTel.Text := Trim(ADOTemp.fieldbyname('XFLXTel').AsString);
          if Trim(ADOTemp.fieldbyname('ConPerson1').AsString) <> '' then
            Self.ConPerson1.Text := Trim(ADOTemp.fieldbyname('ConPerson1').AsString);
        end;
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

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

procedure TfrmConInPutNX.v1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
type
  TMyFunc = function(App: Tapplication; FormH: hwnd; FormID: integer; Language: integer; WinStyle: integer; GCode: Pchar; GName: Pchar; DataBase: Pchar; Title: PChar; Parameters1: PChar; Parameters2: PChar; Parameters3: PChar; Parameters4: PChar; Parameters5: PChar; Parameters6: PChar; Parameters7: PChar; Parameters8: PChar; Parameters9: PChar; Parameters10: PChar; DataBaseStr: PChar): hwnd; stdcall;
var
  Tf: TMyFunc;
  Tp: TFarProc;
  Th: Thandle;
  LabInt, labname: string;
begin
  //if PPInt=2 then Exit;
  Ddatabase := StringOfChar(' ', 32);
  Th := LoadLibrary('LabelSet.dll');
  if Th > 0 then
  begin
    try
      Tp := GetProcAddress(Th, 'GetDllForm');
      if Tp <> nil then
      begin
        Tf := TMyFunc(Tp);
        newh := Tf(Application, 0, 2, 0, 0, PChar(DCode), PChar(DName), PChar(Ddatabase), PChar('标签模版设置'), PChar(''), PChar(''), '', '', '', '', '', '', '', '', PChar(DConString));
        if Trim(PChar(Ddatabase)) <> '' then
        begin
          Ddatabase := Trim(PChar(Ddatabase));
          LabInt := Trim(LeftBStr(Ddatabase, Pos('|', Ddatabase) - 1));
          labname := Trim(RightBStr(Ddatabase, Length(Ddatabase) - Pos('|', Ddatabase)));
          with Order_Sub do
          begin
            Edit;
            FieldByName('SLbName').Value := labname;
            FieldByName('SLbInt').Value := LabInt;
          end;
        end;
      end
      else
      begin
        ShowMessage('打印执行错误');
      end;
    finally
    // FreeLibrary();
    end;
  end
  else
  begin
    ShowMessage('找不到' + Trim('LabelSet.dll'));
  end;

end;

procedure TfrmConInPutNX.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 TfrmConInPutNX.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 TfrmConInPutNX.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
        if Trim(flag) <> 'GSTTPB' then
        begin
          TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
          if Trim(flag) = 'syrname' then
          begin
            with ADOTemp do
            begin
              Close;
              sql.Clear;
              sql.Add('select Top 1* from JYOrderCon_Main_PB where syrname=''' + Trim(ClientDataSet1.fieldbyname('ZDYName').AsString) + '''');
              sql.Add(' and MPRTTYpe=''内销'' ');
              sql.Add(' order by FillTime desc');
              Open;
//              Self.BankName.Text := Trim(ADOTemp.fieldbyname('BankName').AsString);
              //Self.BankAddress.Text:=Trim(ADOTemp.fieldbyname('BankAddress').AsString);
              //Self.BankFastNo.Text:=Trim(ADOTemp.fieldbyname('BankFastNo').AsString);

              Self.SYRAddress.Text := Trim(ADOTemp.fieldbyname('SYRAddress').AsString);
              Self.TelNo.Text := Trim(ADOTemp.fieldbyname('TelNo').AsString);
              Self.FaxNo.Text := Trim(ADOTemp.fieldbyname('FaxNo').AsString);
              Self.BankNo.Text := Trim(ADOTemp.fieldbyname('BankNo').AsString);
              Self.BankName.Text := Trim(ADOTemp.fieldbyname('BankName').AsString);
              Self.GFLXPerson.Text := Trim(ADOTemp.fieldbyname('GFLXPerson').AsString);
              Self.GFLXTel.Text := Trim(ADOTemp.fieldbyname('GFLXTel').AsString);
              Self.FromPlace.Text := Trim(ADOTemp.fieldbyname('FromPlace').AsString);
              Self.QtyNote.Text := Trim(ADOTemp.fieldbyname('QtyNote').AsString);
              Self.DlyNote.Text := Trim(ADOTemp.fieldbyname('DlyNote').AsString);
              Self.Payment.Text := Trim(ADOTemp.fieldbyname('Payment').AsString);
            end;
          end;
        end
        else
        begin
          TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
          //SYRName.TxtCode:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
          with ADOTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('select Top 1* from JYOrderCon_Main_PB where SYRName=''' + Trim(ClientDataSet1.fieldbyname('ZdyName').AsString) + '''');
            sql.Add(' and MPRTTYpe=''内销'' ');
            sql.Add(' order by FillTime desc');
            Open;
            Self.SYRAddress.Text := Trim(ADOTemp.fieldbyname('SYRAddress').AsString);
            Self.TelNo.Text := Trim(ADOTemp.fieldbyname('TelNo').AsString);
            Self.FaxNo.Text := Trim(ADOTemp.fieldbyname('FaxNo').AsString);
            Self.BankNo.Text := Trim(ADOTemp.fieldbyname('BankNo').AsString);
            Self.BankName.Text := Trim(ADOTemp.fieldbyname('BankName').AsString);
            Self.GFLXPerson.Text := Trim(ADOTemp.fieldbyname('GFLXPerson').AsString);
            Self.GFLXTel.Text := Trim(ADOTemp.fieldbyname('GFLXTel').AsString);
            Self.FromPlace.Text := Trim(ADOTemp.fieldbyname('FromPlace').AsString);
            Self.QtyNote.Text := Trim(ADOTemp.fieldbyname('QtyNote').AsString);
            Self.DlyNote.Text := Trim(ADOTemp.fieldbyname('DlyNote').AsString);
            Self.Payment.Text := Trim(ADOTemp.fieldbyname('Payment').AsString);
          end;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPutNX.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 TfrmConInPutNX.CPRanHouGYBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';

end;

procedure TfrmConInPutNX.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 TfrmConInPutNX.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 TfrmConInPutNX.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 TfrmConInPutNX.v1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  fsj: string;
  FWZ: Integer;
begin
  if Trim(Order_Sub.fieldbyname('SubId').AsString) <> '' then
  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;
  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 TfrmConInPutNX.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Order_Sub.IsEmpty then
    Exit;
  if Trim(Order_Sub.fieldbyname('SubId').AsString) <> '' then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from FHSQ_Main where ConSubId=''' + Trim(Order_Sub.fieldbyname('SubId').AsString) + '''');
      Open;
    end;
    if Trim(ADOTemp.fieldbyname('YSID').AsString) <> '' then
    begin
      v1PRTPrice.Options.Focusing := False;
    end
    else
    begin
      v1PRTPrice.Options.Focusing := True;
    end;
  end;

end;

procedure TfrmConInPutNX.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;

    Post;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNX.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;
    if (FieldByName('PRTOrderQty').asstring <> '') and (FieldByName('pizhong').asstring <> '') then
    begin
      FieldByName('PiShu').value := trunc(FieldByName('PRTOrderQty').asfloat / FieldByName('pizhong').asfloat);
    end;
    Post;

  end;
end;

procedure TfrmConInPutNX.DlyDateChange(Sender: TObject);
begin
  DlyNote.text := inttostr(DaysBetween(DlyDate.Date, OrdDate.Date)) + '天';
end;

procedure TfrmConInPutNX.v1Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  fsj: string;
  FWZ: Integer;
begin
//  fsj := Trim(TEdit(Sender).Hint);
//  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'KFNOTE';
      flagname := '开幅要求';
      if ShowModal = 1 then
      begin
        with Order_Sub do
        begin
          edit;
          Order_Sub.FieldByName('KFNote').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;

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

procedure TfrmConInPutNX.v1Column3PropertiesEditValueChanged(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;
    if (FieldByName('PRTOrderQty').asstring <> '') and (FieldByName('pizhong').asstring <> '') then
    begin
      FieldByName('PiShu').value := trunc(FieldByName('PRTOrderQty').asfloat / FieldByName('pizhong').asfloat);
    end;
    Post;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNX.ToolButton3Click(Sender: TObject);
begin
  if FMainId = '' then
  begin
    Application.MessageBox('该合同未保存，请先保存!', '提示', 0);
    Exit;
  end;
  try
    frmFjList_RZ := TfrmFjList_RZ.Create(Application);
    with frmFjList_RZ do
    begin

      fkeyNO := Trim(fmainid);
      FType := '合同';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmFjList_RZ.Free;
  end;
end;

end.

