unit U_OrderInPut;

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, cxCurrencyEdit, cxImage, Menus,
  cxLookAndFeelPainters, cxButtons, cxDBEdit, cxGridCustomPopupMenu,
  cxGridPopupMenu;

type
  TfrmOrderInPut = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    OrderNo: TEdit;
    Label7: TLabel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1PRTColor: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    v1PRTOrderQty: TcxGridDBColumn;
    Label10: TLabel;
    ConNo: TEdit;
    RanFactory: TBtnEditC;
    v1XHNo: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    v1SOrddefstr1: TcxGridDBColumn;
    v1SOrddefstr2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    ToolButton3: TToolButton;
    v1PRTHX: TcxGridDBColumn;
    Label3: TLabel;
    Label14: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    OrdDate: TDateTimePicker;
    CustomerNoName: TBtnEditC;
    MPRTMF: TBtnEditC;
    MPRTKZ: TBtnEditC;
    Label2: TLabel;
    MPRTCodeName: TBtnEditC;
    Label6: TLabel;
    MPRTSpec: TBtnEditC;
    Label5: TLabel;
    MPRTDuiSeGY: TBtnEditC;
    Label11: TLabel;
    MPRTSL: TBtnEditC;
    Label9: TLabel;
    MPRTNiuDu: TBtnEditC;
    Label8: TLabel;
    MPRTPH: TBtnEditC;
    Label15: TLabel;
    HZLFactory: TBtnEditC;
    Label16: TLabel;
    PBFactory: TBtnEditC;
    Label17: TLabel;
    YCLFactory: TBtnEditC;
    Label18: TLabel;
    MPRTZHName: TEdit;
    Label19: TLabel;
    Label20: TLabel;
    MPRTKaiJian: TBtnEditC;
    Label21: TLabel;
    MPRTChuanY: TBtnEditC;
    Label22: TLabel;
    MPRTYaoFeng: TBtnEditC;
    Label23: TLabel;
    MPRTJiBenNote: TBtnEditC;
    Label24: TLabel;
    MPRTTeBieNote: TBtnEditC;
    Label25: TLabel;
    DLYDate: TDateTimePicker;
    Label26: TLabel;
    MPRTCode: TBtnEditC;
    Label27: TLabel;
    MPRTQtyNote: TBtnEditC;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    MPRTColorLaoDu1: TBtnEditC;
    MPRTColorLaoDu2: TBtnEditC;
    MPRTColorLaoDu3: TBtnEditC;
    MPRTColorLaoDu4: TBtnEditC;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    MPRTKQiQiu: TBtnEditC;
    MPRTDingPoLv: TBtnEditC;
    MPRTZuRanXing: TBtnEditC;
    Label35: TLabel;
    MPRTKuanNO: TBtnEditC;
    Label36: TLabel;
    Label37: TLabel;
    Label38: TLabel;
    MPRTTangJin: TBtnEditC;
    Label39: TLabel;
    OrdDefDate1: TDateTimePicker;
    Label40: TLabel;
    OrdDefDate2: TDateTimePicker;
    Label41: TLabel;
    OrdPerson1: TBtnEditC;
    Label43: TLabel;
    OrdPerson2: TBtnEditC;
    LBNameNote: TMemo;
    MaiTouNote: TMemo;
    SYRName: TBtnEditC;
    MPRTBZNote: TMemo;
    MPRTSCTeBieNote: TMemo;
    Orddefstr5: TEdit;
    Label45: TLabel;
    v1Column1: TcxGridDBColumn;
    Label46: TLabel;
    orddefnote1: TMemo;
    orddefstr1: TBtnEditC;
    Label47: TLabel;
    orddefstr2: TEdit;
    orddefstr4: TBtnEditC;
    orddefstr3: TEdit;
    Label48: TLabel;
    Label49: TLabel;
    EditCnt: TcxCurrencyEdit;
    v1PRTCodeName: TcxGridDBColumn;
    v1KHorderNo: TcxGridDBColumn;
    v1PRTCode: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    Label42: TLabel;
    Label4: TLabel;
    FileName: TcxButton;
    Files: TcxDBImage;
    ADOQueryImage: TADOQuery;
    DSIMage: TDataSource;
    Label44: TLabel;
    orddefnote2: TMemo;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    Label50: TLabel;
    Label51: TLabel;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label52: TLabel;
    Label53: TLabel;
    PBPrice: TcxCurrencyEdit;
    v1Column9: TcxGridDBColumn;
    PbQty: TcxCurrencyEdit;
    Label54: TLabel;
    v1Column8: TcxGridDBColumn;
    ToolButton4: TToolButton;
    Panel4: TPanel;
    Panel10: TPanel;
    Image2: TImage;
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label56: TLabel;
    Label57: TLabel;
    Label55: TLabel;
    PONO: TEdit;
    Label58: TLabel;
    MPRTCOLNUM: TEdit;
    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 RanFactoryBtnUpClick(Sender: TObject);
    procedure CustomerNoNameBtnUpClick(Sender: TObject);
    procedure CustomerNoNameBtnDnClick(Sender: TObject);
    procedure MPRTCodeNameBtnUpClick(Sender: TObject);
    procedure NoteDblClick(Sender: TObject);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure OrdDefStr2BtnUpClick(Sender: TObject);
    procedure ss(Sender: TObject; var Key: Char);
    procedure ToolButton3Click(Sender: TObject);
    procedure YCLFactoryBtnUpClick(Sender: TObject);
    procedure MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
    procedure Label36DblClick(Sender: TObject);
    procedure Label37DblClick(Sender: TObject);
    procedure SYRNameBtnUpClick(Sender: TObject);
    procedure MPRTBZNoteDblClick(Sender: TObject);
    procedure MPRTSCTeBieNoteDblClick(Sender: TObject);
    procedure v1PRTCodeNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FileNameClick(Sender: TObject);
    procedure v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure v1Column9PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure Image2Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure v1Column12PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    procedure InitData();
    procedure ZDYHelp(FButn:TcxButtonEdit;LType:string);
    function  SaveData():Boolean;
    function  SaveDataSubOne():Boolean;
    function  SaveDataMain():Boolean;
    function SaveDataSubMore():Boolean;
    procedure CJEWM();
    procedure InitImage();
    { Private declarations }
  public
    PState,CopyInt,PriceFlag:Integer;
    FMainId,FFMainId,FOrderNo:String;
    FXS:Integer;
    fFlileFlag:string;
    { Public declarations }
  end;

var
  frmOrderInPut: TfrmOrderInPut;
  newh:hwnd;
implementation

uses
  U_DataLink,U_ZDYHelp,U_Fun,U_ZDYHelpSel,U_ZdyAttachment,getpic;
{$R *.dfm}

procedure TfrmOrderInPut.InitImage();
begin
//  IF Order_Sub.IsEmpty then exit;
  with ADOQueryImage do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where TFid='+quotedstr(trim(OrderNO.Text)));
    open;
  end;
end;

procedure TfrmOrderInPut.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(self.Caption+TV1.Name+'1',Tv1,'生产指示单管理');
end;

procedure TfrmOrderInPut.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrder_Sub where 1=1 ');
    if PState=1 then
    begin
      sql.Add(' and MainId='''+Trim(FMainId)+'''');
    end;
    if PState=0 then
    begin
      sql.Add(' and 1<>1');
    end;
    sql.Add('order by cast(dbo.Get_ShuZi(SOrddefstr1) as bigint)');
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,ScrollBox1,2);
  if PState=0 then
  begin
    OrdDate.DateTime:=SGetServerDateTime(ADOTemp);
    DlyDate.DateTime:=OrdDate.DateTime;
    OrdDefDate1.DateTime:=OrdDate.DateTime;
    OrdDefDate2.DateTime:=OrdDate.DateTime;
    OrdPerson2.Text:=trim(dName);
  end else
  begin
  end;
  if CopyInt=99 then
  begin
    PState:=0;
    FMainId:='';
    OrderNo.Text:='';
    orddefnote1.Text:='';
    OrdPerson2.Text:=trim(dName);
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value:='';
        FieldByName('SubId').Value:='';
        Fieldbyname('SLBName').value:=null;
        Post;
        Next;
      end;
    end;
  end;
  InitImage();
end;

procedure TfrmOrderInPut.ZDYHelp(FButn:TcxButtonEdit;LType:string);
begin

end;

procedure TfrmOrderInPut.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption+TV1.Name+'1',Tv1,'生产指示单管理');
  InitData();
end;

procedure TfrmOrderInPut.CJEWM();
var
  Txt,fImagePath,maxNo:string;
  Moudle: THandle;
  Makebar:TMakebar;
  Mixtext:TMixtext;
begin
  try
    Moudle:=LoadLibrary('MakeQRBarcode.dll');
    @Makebar:=GetProcAddress(Moudle,'Make');
    @Mixtext:=GetProcAddress(Moudle,'MixText');
    Txt:=Trim(order_Sub.fieldbyname('Subid').AsString);
    fImagePath:=ExtractFilePath(Application.ExeName)+'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName)+'image')) then
    CreateDirectory(pchar(ExtractFilePath(Application.ExeName)+'image'),nil);
    if FileExists(fImagePath) then DeleteFile(fImagePath);
    Makebar(pchar(Txt),Length(Txt),3,3,0,PChar(fImagePath),3);

    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from TP_File ');
      sql.Add('where TFID='+quotedstr(trim(Txt)));
      sql.Add('and TFType=''EWM''');
      open;
      if isempty then
      begin
        append;
        fieldbyname('TFID').Value:=trim(Txt);
        fieldbyname('WBID').Value:=trim(order_Sub.fieldbyname('Mainid').AsString);
        fieldbyname('TFType').Value:='EWM';
        fieldbyname('FillTime').Value:=SGetServerDateTime(ADOTemp);
        tblobfield(FieldByName('Filesother')).LoadFromFile(fImagePath);
        post;
      end;
    end;
  except
    application.MessageBox('条形码生成失败！','提示信息',MB_ICONERROR);
    order_Sub.EnableControls;
    exit;
  end;
end;

function TfrmOrderInPut.SaveData():Boolean;
var
  maxno:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOCmd,maxno,'JM','JYOrder_Main',3,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
    end else
    begin
      maxno:=Trim(FMainId);
    end;
    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;
      end
      else begin
        Edit;
      end;
      FieldByName('MainId').Value:=Trim(maxno);
      SSetsaveSqlNew(ADOCmd,'JYOrder_Main',ScrollBox1,2);
      if Trim(FMainId)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
        FieldByName('Filltime').Value:=SGetServerDateTime(ADOTemp);
      end
      else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
      end;
      FieldByName('LBNameNote').Value:=Trim(LBNameNote.Text);
      FieldByName('MaiTouNote').Value:=MaiTouNote.Text;
      FieldByName('editcnt').Value:=strtointdef(trim(editcnt.Text),0);
      FieldByName('PBPrice').Value:=strtofloatdef(trim(PBPrice.Text),0);
      FieldByName('PBQty').Value:=strtofloatdef(trim(PBQty.Text),0);
      FieldByName('Orddefstr15').Value:='按颜色生成';
      FieldByName('status').Value:='0';
      Post;
    end;

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main where orderno='''+Trim(OrderNo.Text)+'''');
      Open;
    end;
    if ADOCmd.RecordCount>1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('指示单号重复!','提示',0);
      Exit;
    end;
    FMainId:=Trim(maxno);
    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
        begin
          if GetLSNo(ADOCmd,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
          begin
            Append;
          end
          else
            Edit;
          FieldByName('MainId').Value:=Trim(FMainId);
          FieldByName('SubId').Value:=Trim(maxno);
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'JYOrder_Sub',0);
          fieldbyname('PRTMF').Value:=Order_Sub.fieldbyname('PRTMF').AsString;
          fieldbyname('PRTKZ').Value:=Order_Sub.fieldbyname('PRTKZ').AsFloat;
          if Trim(fieldbyname('PRTOrderQty').AsString)='' then
          begin
            fieldbyname('PRTOrderQty').Value:=0
          end;
          if Trim(fieldbyname('PRTOrderKG').AsString)='' then
          begin
            fieldbyname('PRTOrderKG').Value:=0
          end;
          if Trim(fieldbyname('PRTPrice').AsString)='' then
          begin
            fieldbyname('PRTPrice').Value:=0
          end;
          fieldbyname('SordQty1').Value:=Order_Sub.fieldbyname('SordQty1').AsFloat;
          fieldbyname('SordQty2').Value:=Order_Sub.fieldbyname('SordQty2').AsFloat;
          fieldbyname('SordQty3').Value:=Order_Sub.fieldbyname('SordQty3').AsFloat;
          FieldByName('Sorddefstr10').Value:=Order_Sub.FieldByName('Sorddefstr10').AsString;
          FieldByName('khOrderNO').Value:=trim(Order_Sub.FieldByName('khOrderNO').AsString);
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value:=Trim(maxno);
        Order_Sub.FieldByName('Mainid').Value:=Trim(FMainId);
        CJEWM();
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

function TfrmOrderInPut.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
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

function TfrmOrderInPut.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 TfrmOrderInPut.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 TfrmOrderInPut.TBSaveClick(Sender: TObject);
begin
  OrdDate.SetFocus;
  if Trim(OrderNo.Text)='' then
  begin
    Application.MessageBox('指示单号不能为空！','提示',0);
    Exit;
  end;
{  if Order_Sub.Locate('PRTColor',null,[])=True then
  begin
    Application.MessageBox('颜色不能为空!','提示',0);
    Exit;
  end; }
  if order_Sub.Locate('OrderUnit',null,[])=true then
  begin
    application.messagebox('数量单位不能为空','提示');
    exit;
  end;
  
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!','提示',0);
    Exit;
  end;

  if PState=1 then
  begin
    if Trim(OrderNo.Text)<>Trim(FOrderNo) then
    begin
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from YF_Money_CR where MainId='''+Trim(FMainId)+'''');
        Open;
      end;
      if ADOTemp.IsEmpty=False then
      begin
        Application.MessageBox('已产生数据，不能更改订单号!','提示',0);
        Exit;
      end;
    end;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  end;
end;

procedure TfrmOrderInPut.v1PRTColorPropertiesButtonClick(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.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 TfrmOrderInPut.ToolButton1Click(Sender: TObject);
var
  i:Integer;
begin
  if Trim(OrderNo.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:=0;
    FieldByName('SOrddefstr4').Value:=null;
    FieldByName('SOrddefstr2').Value:=null;
    FieldByName('SOrddefstr10').Value:=null;
    FieldByName('hxFile').Value:='';
    Post;
  end;
end;

procedure TfrmOrderInPut.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Contract_Cloth_LLMX where OrdSubId='''+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 JYOrder_Sub_AnPai where SubId='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
    Open;
  end;
  if ADOTemp.IsEmpty=False then
  begin
    Application.MessageBox('已回仓不能删除数据!','提示',0);
    Exit;
  end;
  if Trim(Order_Sub.fieldbyname('SubId').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete TP_File where WBID='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+''' and TFType=''EWM'' ');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Sub where SubId='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
 { if Order_Sub.IsEmpty then
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Main where MainId='''+Trim(FMainId)+'''');
      ExecSQL;
    end;
  end;  }
end;

procedure TfrmOrderInPut.RanFactoryBtnUpClick(Sender: TObject);
begin
  {try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='RKPlace';
      flagname:='染厂名称';    
      if ShowModal=1 then
      begin
        JGFactoryName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        JGFactoryName.TxtCode:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end; }
end;

procedure TfrmOrderInPut.CustomerNoNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachment:=TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
      fkhType:='';
      if ShowModal=1 then
      begin
        CustomerNoName.Text:=Trim(CDS_HZ.fieldbyname('ZDYName').AsString);
        CustomerNoName.TxtCode:=Trim(CDS_HZ.fieldbyname('ZDYCode').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

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

procedure TfrmOrderInPut.MPRTCodeNameBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MPRTCodeName';
      flagname:='产品名称';
      //fnote:=True;
      //V1Note.Caption:='产品编号';
      if ShowModal=1 then
      begin
        MPRTCodeName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        //MPRTCode.Text:=Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.NoteDblClick(Sender: TObject);
begin
  {try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='OrdNote';
      flagname:='备注及要求';
      if ShowModal=1 then
      begin
        Note.Text:=Note.Text+frmZDYHelpSel.ReturnStr;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;}
end;

procedure TfrmOrderInPut.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 TfrmOrderInPut.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 TfrmOrderInPut.OrdDefStr2BtnUpClick(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)='OrdDefStr2' then
      begin
        V1Name.Caption:='中文名称';
        V1Note.Caption:='英文名称';
        fnote:=True;
      end;
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        if Trim(flag)='MPRTCode' then
        begin
          with ADOTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('select Top 1 * from JYOrder_Main where MPRTCode='''+Trim(ClientDataSet1.fieldbyname('ZDYName').AsString)+'''');
            sql.Add(' order by FillTime desc');
            Open;
          end;
          MPRTCodeName.Text:=ADOTemp.fieldbyname('MPRTCodeName').AsString;
          MPRTMF.Text:=ADOTemp.fieldbyname('MPRTMF').AsString;
          MPRTKZ.Text:=ADOTemp.fieldbyname('MPRTKZ').AsString;
          MPRTSpec.Text:=ADOTemp.fieldbyname('MPRTSpec').AsString;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.ss(Sender: TObject; var Key: Char);
var
  ConMainId:string;
begin
  if Key=#13 then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrderCon_Main where ConNo like '''+'%'+Trim(ConNo.Text)+'%'+'''');
      Open;
    end;
    if ADOTemp.RecordCount>1 then
    begin
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select Top 1* from JYOrderCon_Main where ConNo='''+Trim(ConNo.Text)+'''');
        Open;
      end;
      if ADOTemp.IsEmpty then Exit;
    end else
    if ADOTemp.RecordCount=1 then
    begin
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from JYOrderCon_Main where ConNo like '''+'%'+Trim(ConNo.Text)+'%'+'''');
        Open;
      end;
    end;
    begin
      ConNo.Text:=Trim(ADOTemp.fieldbyname('ConNo').AsString);
      //OrdDefStr1.Text:=Trim(ADOTemp.fieldbyname('ConDefStr1').AsString);
      MPRTCodeName.Text:=Trim(ADOTemp.fieldbyname('MPRTCodeName').AsString);
      MPRTZHName.Text:=Trim(ADOTemp.fieldbyname('CPZHName').AsString);
      MPRTMF.Text:=Trim(ADOTemp.fieldbyname('MPRTMF').AsString);
      MPRTKZ.Text:=Trim(ADOTemp.fieldbyname('MPRTKZ').AsString);
      MPRTChuanY.Text:=Trim(ADOTemp.fieldbyname('ChuanYangNote').AsString);
      MPRTQtyNote.Text:=Trim(ADOTemp.fieldbyname('QtyNote').AsString);
      CustomerNoName.Text:=Trim(ADOTemp.fieldbyname('CustomerNoName').AsString);
      CustomerNoName.TxtCode:=Trim(ADOTemp.fieldbyname('CustomerNo').AsString);
      DLYDate.DateTime:=ADOTemp.fieldbyname('DLYDate').Value;
      ConMainId:=Trim(ADOTemp.fieldbyname('MainId').AsString);
     // ConGS:=Trim(ADOTemp.fieldbyname('SYRName').AsString);
      //OrdDefStr2.Text:=Trim(ADOTemp.fieldbyname('ConDefStr2').AsString);
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select A.*,ColorName=(select ZdyName from KH_Zdy B where B.Note=A.PRTColor and B.Type=''OrdColor'' ) ');
        SQL.Add(' from JYOrderCon_Sub A where MainId='''+Trim(ConMainId)+'''');
        Open;
      end;
      with ADOTemp do
      begin
        First;
        while not Eof do
        begin
          with Order_Sub do
          begin
            Append;
            FieldByName('PRTColor').Value:=Trim(ADOTemp.fieldbyname('PRTColor').AsString);
            FieldByName('SOrdDefStr4').Value:=Trim(ADOTemp.fieldbyname('SOrdDefStr4').AsString);
            FieldByName('SOrdDefStr3').Value:=Trim(ADOTemp.fieldbyname('SOrdDefStr3').AsString);
            FieldByName('PRTOrderQty').Value:=Trim(ADOTemp.fieldbyname('PRTOrderQty').AsString);
            FieldByName('OrderUnit').Value:=Trim(ADOTemp.fieldbyname('OrderUnit').AsString);
            FieldByName('PRTPrice').Value:=Trim(ADOTemp.fieldbyname('PRTPrice').AsString);
            FieldByName('PriceUnit').Value:=Trim(ADOTemp.fieldbyname('PriceUnit').AsString);
            FieldByName('PRTHX').Value:=Trim(ADOTemp.fieldbyname('PRTHX').AsString);
            FieldByName('XHNO').Value:=Trim(ADOTemp.fieldbyname('XHNO').AsString);
            FieldByName('Sorddefstr10').Value:=Trim(ADOTemp.fieldbyname('SUBID').AsString);

            Post;
          end;
          Next;
        end;
      end;
    end;

  end;
end;

procedure TfrmOrderInPut.ToolButton3Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  OneKeyPost(Tv1,Order_Sub);
end;

procedure TfrmOrderInPut.YCLFactoryBtnUpClick(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);
      MainType:=TEdit(Sender).Name;
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
begin
  fsj:=Trim(TEdit(Sender).Hint);
  FWZ:=Pos('/',fsj);
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=ReturnStr;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;


procedure TfrmOrderInPut.Label36DblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='LbNameNote';
      flagname:='标签内容';
      if ShowModal=1 then
      begin
        ClientDataSet1.DisableControls;
        //LBNameNote.Text:='';
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if ClientDataSet1.FieldByName('SSel').AsBoolean=True then
            begin
              if Trim(Self.LBNameNote.Text)='' then
              begin
                Self.LBNameNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
              end else
              begin
                Self.LBNameNote.Text:=Self.LBNameNote.Text+#13+#10+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
              end;

            end;
            Next;
          end;
        end;
        ClientDataSet1.EnableControls;
      end;
    end;
  finally
  end;
end;

procedure TfrmOrderInPut.Label37DblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='MaitouNote';
      flagname:='唛头内容';
      if ShowModal=1 then
      begin
        ClientDataSet1.DisableControls;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if ClientDataSet1.FieldByName('SSel').AsBoolean=True then
            begin
              if Trim(Self.MaitouNote.Text)='' then
              begin
                Self.MaitouNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
              end else
              begin
                Self.MaitouNote.Text:=Self.MaitouNote.Text+#13+#10+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
              end;

            end;
            Next;
          end;
        end;
        ClientDataSet1.EnableControls;
      end;
    end;
  finally
  end;
end;

procedure TfrmOrderInPut.SYRNameBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdDefStr2';
      flagname:='公司抬头';
      V1Name.Caption:='中文名称';
      V1Note.Caption:='英文名称';
      fnote:=True;
    {  if Trim(DParameters1)<>'高权限' then
      begin
        TBAdd.Visible:=False;
        TBEdit.Visible:=false;
        TBDel.Visible:=false;
        TBSave.Visible:=false;
      end;   }
      if ShowModal=1 then
      begin
        SYRName.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.MPRTBZNoteDblClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
  i:integer;
begin
  fsj:=Trim(TMemo(Sender).Hint);
  FWZ:=Pos('/',fsj);
  i:=0;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      if ShowModal=1 then
      begin
        MPRTBZNote.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              i:=i+1;
              MPRTBZNote.Lines.Add(inttostr(i)+'.'+FieldByName('ZDYName').AsString)
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPut.MPRTSCTeBieNoteDblClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
  i:integer;
begin
  fsj:=Trim(TMemo(Sender).Hint);
  FWZ:=Pos('/',fsj);
  i:=0;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      if ShowModal=1 then
      begin
        MPRTSCTeBieNote.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              i:=i+1;
              MPRTSCTeBieNote.Lines.Add(inttostr(i)+'.'+FieldByName('ZDYName').AsString)
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;


procedure TfrmOrderInPut.v1PRTCodeNamePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PRTCodeName';
      flagname:='产品名称';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PRTCodeName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.FileNameClick(Sender: TObject);
begin
  IF trim(OrderNo.Text)='' then
  begin
    application.MessageBox('订单号不能为空！','提示信息',MB_ICONERROR);
    exit;
  end;

  try
	  FormGetPic := TFormGetPic.Create(Application);
    with FormGetPic do
    begin
     // fkeyNO:=trim(Order_Sub.fieldbyname('subID').AsString);
      fkeyNO:=trim(OrderNo.Text);
      pat1:=TCXbutton(Sender).Name;
      pic1:=TCXbutton(Sender).Hint;
      FTFType:='ORDERTY';
 //   pat1:='PatFile1';
//   pic1:='Picture1';
      IF ShowModal = 1 then
      begin
     // self.Timage(Tbutton(Sender).Hint).Picture.Assign(FormGetPic.Image2.Picture.Bitmap);
        OrderNo.Enabled:=false;
      end;

      Release;
    end;
    Initimage();
  except
    if FormGetPic<>nil then FormGetPic.Release;
  end;
end;

procedure TfrmOrderInPut.v1PRTOrderQtyPropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,fieldname:String;
begin
  fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_Sub do
  begin
    Edit;
    FieldByName(Trim(fieldname)).Value:=TcxTextEdit(Sender).EditingText;
    IF (1-FieldByName('SordQty1').AsFloat/100.00)<>0 then
    FieldByName('SordQty3').Value:=format('%.0f',[FieldByName('PRTOrderQty').AsFloat*(1+FieldByName('SordQty2').AsFloat/100.00)
                                   /(1-FieldByName('SordQty1').AsFloat/100.00)]);
    Post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut.v1Column9PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  FormGetPic:=TFormGetPic.create(self);
  with FormGetPic do
  begin
    fFlileFlag:=self.fFlileFlag;
    fkeyNo:=Order_Sub.fieldbyname('HXFile').asstring;
    pat1:='FileName';
    pic1:='FilesOther';
    FTFType:='HX';
    if showmodal=1 then
    begin
      Order_Sub.edit;
      Order_Sub.fieldbyname('HXFile').Value:=trim(fkeyNo);
    end;
    free;
  end;
end;

procedure TfrmOrderInPut.Image2Click(Sender: TObject);
begin
   panel4.Visible:=False;
end;

procedure TfrmOrderInPut.ToolButton4Click(Sender: TObject);
begin
  Panel4.Visible:=true;
end;

procedure TfrmOrderInPut.Button1Click(Sender: TObject);
var
  i,j,k:Integer;
begin
  if Trim(OrderNo.Text)='' then
  begin
    Application.MessageBox('订单号不能为空!','提示',0);
    Exit;
  end;
  j:=1;

  while j<=StrToInt(Edit1.Text) do
  begin
    k:=1;
    while k<=StrToInt(Edit2.Text) do
    begin
      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:=0;
        FieldByName('SOrddefstr4').Value:=null;
        FieldByName('SOrddefstr2').Value:=null;
        FieldByName('SOrddefstr10').Value:=null;
        FieldByName('hxFile').Value:='';
        FieldByName('PRTHX').Value:=j;
        FieldByName('SOrddefstr1').Value:=k;
        Post;
      end;
      k:=k+1;
    end;
    j:=j+1;

  end;

end;

procedure TfrmOrderInPut.v1Column12PropertiesButtonClick(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('HCUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.
