unit U_OrderInPut_FB;

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, cxPC, Menus,
  cxCheckBox, cxGridCustomPopupMenu, cxGridPopupMenu;

type
  TfrmOrderInPut_FB = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    ToolButton3: TToolButton;
    cxTabControl2: TcxTabControl;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1XHNo: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxTabControl1: TcxTabControl;
    v1SOrdDefNote1: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N3: TMenuItem;
    CDS_CG: TClientDataSet;
    DataSource2: TDataSource;
    PopupMenu2: TPopupMenu;
    N4: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    N8: TMenuItem;
    N9: TMenuItem;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Panel1: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label10: TLabel;
    Label43: TLabel;
    Label14: TLabel;
    Label19: TLabel;
    Label42: TLabel;
    Label2: TLabel;
    invoiceNo: TEdit;
    OrdDate: TDateTimePicker;
    OrdPerson2: TBtnEditC;
    CustomerNoName: TBtnEditC;
    MPRTBZNote: TMemo;
    MPRTSCTeBieNote: TMemo;
    conNO: TEdit;
    KHConNO: TEdit;
    orderNo: TBtnEditA;
    Label5: TLabel;
    v1Column3: TcxGridDBColumn;
    Label7: TLabel;
    orddefstr10: TEdit;
    conDefstr1: TEdit;
    Label13: TLabel;
    Label9: TLabel;
    Label35: TLabel;
    Label11: TLabel;
    conDefstr2: TEdit;
    ConPerson1: TEdit;
    ConPerson2: TEdit;
    v1Column2: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label12: TLabel;
    Label15: TLabel;
    orddefstr5: TEdit;
    orddefstr4: TEdit;
    orddefstr6: TEdit;
    Label16: TLabel;
    orddefstr7: TEdit;
    Label17: TLabel;
    Label20: TLabel;
    CYNO: TBtnEditA;
    v1Prtmoney: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    Label4: TLabel;
    Label6: TLabel;
    OrdDefStr9: TEdit;
    OrdDefStr8: TBtnEditA;
    Label21: TLabel;
    Label28: TLabel;
    OrdDefStr12: TEdit;
    OrdDefStr11: TEdit;
    MPRTTYpe: TEdit;
    v1SordQty4: TcxGridDBColumn;
    v1SordQty5: TcxGridDBColumn;
    v1SordQty3: TcxGridDBColumn;
    Label8: TLabel;
    OrdDefDate1: TDateTimePicker;
    Label18: TLabel;
    OrdDefStr13: TEdit;
    Label22: TLabel;
    OrdDefStr14: TEdit;
    orddefstr3: TMemo;
    Label37: TLabel;
    v1SordQty7: TcxGridDBColumn;
    Label23: TLabel;
    Orddefstr15: TComboBox;
    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 v1OrderUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure YCLFactoryBtnUpClick(Sender: TObject);
    procedure MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
    procedure MPRTBZNoteDblClick(Sender: TObject);
    procedure MPRTSCTeBieNoteDblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure conNoChange(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure orderNoBtnClick(Sender: TObject);
    procedure OrdPerson1BtnUpClick(Sender: TObject);
    procedure v1Column4PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column7PropertiesEditValueChanged(Sender: TObject);
    procedure v1PrtmoneyPropertiesEditValueChanged(Sender: TObject);
    procedure CYNOBtnClick(Sender: TObject);
    procedure v1Column8PropertiesEditValueChanged(Sender: TObject);
    procedure OrdDefStr8BtnClick(Sender: TObject);
    procedure v1Column5PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    procedure InitData();
    procedure ZDYHelp(FButn:TcxButtonEdit;LType:string);
    function  SaveData():Boolean;
    function YSData():Boolean;
    { Private declarations }
  public
    PState,CopyInt,PriceFlag:Integer;
    FMainId,FFMainId,FOrderNo,ftype:String;
    FXS:Integer;
    { Public declarations }
  end;

var
  frmOrderInPut_FB: TfrmOrderInPut_FB;
  newh:hwnd;
implementation
uses
  U_DataLink,U_ZDYHelp,U_Fun,U_ZDYHelpSel, U_ProductOrderListSel,U_ProductOrderNewList_CY_SEL,
  U_ZdyAttachment;

{$R *.dfm}

function TfrmOrderInPut_FB.YSData():Boolean;
var
  CRID,OrdMainId,YFID,FComTaiTou,FCRID,FFactoryName:String;
begin
  Result:=False;
  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from YF_Money_KC where FactoryName='+quotedstr(Trim(CustomerNoName.Text)));
    Open;
  end;
  if ADOTemp.IsEmpty=False then
  begin
    CRID:=ADOTemp.fieldbyname('CRID').AsString;
  end else
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update YF_Money_CRID set CRID=CRID+1');
      sql.Add('select * from YF_Money_CRID ');
      Open;
    end;
    CRID:=ADOCmd.fieldbyname('CRID').AsString;
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YF_Money_KC where 1<>1');
      Open;
    end;
    with ADOCmd do
    begin
      Append;
      FieldByName('CRID').Value:=StrToInt(CRID);
      FieldByName('FactoryName').Value:=Trim(CustomerNoName.Text);
      FieldByName('ZdyStr1').Value:='应收收';
      Post;
    end;
  end;
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from YF_Money_CR where FactoryName='+quotedstr(Trim(CustomerNoName.Text)));
        sql.Add(' and mainID='''+Trim(Order_Sub.fieldbyname('mainID').AsString)+'''');
        sql.Add(' and subID='''+Trim(Order_Sub.fieldbyname('subID').AsString)+'''');
        Open;
      end;
      if ADOTemp.IsEmpty then
      begin
      if GetLSNo(ADOCmd,YFID,'YS','YF_Money_CR',3,1)=False then
      begin
        Application.MessageBox('取坯布应付最大号失败!','提示',0);
        Exit;
      end;
      end
      else
      begin
        YFID:=Trim(ADOTemp.fieldbyname('YFID').AsString);
      end;
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from YF_Money_CR where YFID='''+Trim(YFID)+'''');
        Open;
      end;
      with ADOCmd do
      begin
        if ADOTemp.IsEmpty then
          Append
        else
        Edit;
        FieldByName('YFID').Value:=Trim(YFID);
        FieldByName('YFTypeId').Value:=Trim(Order_Sub.fieldbyname('mainID').AsString);
        FieldByName('CRID').Value:=StrToInt(CRID);
        FieldByName('Filler').Value:=Trim(DName);
        FieldByName('CRType').Value:='应收款登记';
        FieldByName('CRFlag').Value:='应收收';
        FieldByName('QtyFlag').Value:=1;
        FieldByName('FactoryName').Value:=Trim(CustomerNoName.Text);
        FieldByName('CRTime').Value:=OrdDate.Date;
        FieldByName('Qty').Value:=Order_Sub.fieldbyname('SordQty1').AsFloat;
        FieldByName('PS').Value:=0;
        FieldByName('YFType').Value:='自动生成';
        FieldByName('Price').Value:=Order_Sub.fieldbyname('prtPrice').AsFloat;
        FieldByName('money').Value:=Order_Sub.fieldbyname('prtmoney').AsFloat;
        FieldByName('BBmoney').Value:=Order_Sub.fieldbyname('prtmoney').AsFloat;
        FieldByName('HuiLv').Value:=1;
        FieldByName('BZType').Value:=Order_Sub.fieldbyname('priceUnit').AsString;
        FieldByName('ComTaiTou').Value:='';
        FieldByName('QtyUnit').Value:=Trim(Order_Sub.fieldbyname('OrderUnit').AsString);
        FieldByName('YFName').Value:='销售金额';
        FieldByName('MainId').Value:=Trim(Order_Sub.fieldbyname('MainId').AsString);
        FieldByName('subId').Value:=Trim(Order_Sub.fieldbyname('subId').AsString);
        Post;
      end;
    with ADOCmd do
    begin
    Close;
    sql.Clear;
    sql.Add('Update YF_Money_KC Set KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
    sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
    sql.Add(' where CRID='+CRID);
    ExecSQL;
    end;
  Result:=True;
end;

procedure TfrmOrderInPut_FB.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('指示单录入AA',Tv1,'生产指示单管理');
end;

procedure TfrmOrderInPut_FB.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrderFB_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;
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrderFB_Main A ');
    SQL.ADD('where MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,Panel1,2);
  if PState=0 then
  begin
    invoiceNO.Text:='自动生成';
  end else
  begin
    Orddefstr15.Enabled:=false;
  end;
  if CopyInt=99 then
  begin
    PState:=0;
    FMainId:='';
    invoiceNO.Text:='自动生成';
    Orddefstr15.Enabled:=true;
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value:='';
        FieldByName('SubId').Value:='';
        Post;
        Next;
      end;
    end;
  end;
end;

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

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

function TfrmOrderInPut_FB.SaveData():Boolean;
var
  maxno,finvoiceNO,fmxType:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOCmd,maxno,'FM','JYOrderFB_Main',3,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
     { with ADOTemp do
      begin
        close;
        sql.Clear;
        sql.Add('exec P_Get_MaxInvoiceNo ');
        sql.Add(' @MPRTType='''+trim(Ftype)+''' ');
        open;
      end;
      IF trim(ADOTemp.FieldByName('maxStr').AsString)='XXX' then
      begin
        fmxType:=uppercase(formatdateTime('yy',DServerDate));
        IF  trim(Orddefstr15.Text)='内销'  then
        fmxType:='Q'+fmxType;
        if GetLSNo(ADOCmd,finvoiceNO,fmxType,'JYOrderCon_Main',3,0)=False then
        begin
          ADOCmd.Connection.RollbackTrans;
          Application.MessageBox('取最大号失败!','提示',0);
          Exit;
        end;
      end
      else
      finvoiceNO:=trim(ADOTemp.FieldByName('maxStr').AsString);

      if trim(Orddefstr15.Text)='内销' then
      finvoiceNO:=Trim(finvoiceNO)+trim(orddefstr10.Text)
      else
      finvoiceNO:='K'+Trim(finvoiceNO)+trim(orddefstr10.Text);
      invoiceNO.Text:=uppercase(finvoiceNO); }
      IF  trim(Orddefstr15.Text)='内销'  then
      fmxType:='Q'+trim(orddefstr10.Text)+uppercase(formatdateTime('yy',DServerDate))
      else
      fmxType:='K'+trim(orddefstr10.Text)+uppercase(formatdateTime('yy',DServerDate));
        if GetLSNo(ADOCmd,finvoiceNO,fmxType,'JYOrderCon_Main',3,0)=False then
        begin
          ADOCmd.Connection.RollbackTrans;
          Application.MessageBox('取最大号失败!','提示',0);
          Exit;
        end;
      invoiceNO.Text:=uppercase(finvoiceNO);
    end
    else
    begin
      maxno:=Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrderFB_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,'JYOrderFB_Main',Panel1,2);
      FieldByName('OrdDefStr15').Value:=Trim(Orddefstr15.Text);
      FieldByName('status').Value:='0';
      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;

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrderFB_Main where INVoiceNO='''+Trim(INVoiceNO.Text)+'''');
      Open;
    end;
    if ADOCmd.RecordCount>1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('出运单号重复!','提示',0);
      Exit;
    end;
    FMainId:=Trim(maxno);
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete from   JYOrderFB_Sub where MainId='''+Trim(FMainId)+'''');
      sql.Add('delete from   YF_Money_CR where MainId='''+Trim(FMainId)+'''');
      execsql;
    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,'FS','JYOrderFB_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 JYOrderFB_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,'JYOrderFB_Sub',0);
          FieldByName('orderNO').Value:=Trim(orderNO.Text);
          fieldbyname('PRTOrderQty').Value:=Order_Sub.fieldbyname('PRTOrderQty').AsFloat;
          fieldbyname('PRTPrice').Value:=Order_Sub.fieldbyname('PRTPrice').AsFloat;
          fieldbyname('PRTmoney').Value:=Order_Sub.fieldbyname('PRTmoney').AsFloat;
          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('SordQty4').Value:=Order_Sub.fieldbyname('SordQty4').AsFloat;
          fieldbyname('SordQty5').Value:=Order_Sub.fieldbyname('SordQty5').AsFloat;
          fieldbyname('SordQty6').Value:=Order_Sub.fieldbyname('SordQty6').AsFloat;
          fieldbyname('SordQty7').Value:=Order_Sub.fieldbyname('SordQty7').AsFloat;
          FieldByName('PriceUnit').Value:=Trim(Order_Sub.fieldbyname('PriceUnit').AsString);
          FieldByName('Sorddefstr10').Value:=Trim(Order_Sub.fieldbyname('Sorddefstr10').AsString);
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('mainID').Value:=Trim(FMainId);
        Order_Sub.FieldByName('SubId').Value:=Trim(maxno);
        IF  not YSdata() then
        begin
          ADOCmd.Connection.RollbackTrans;
          Application.MessageBox('生成应收款失败!','提示',0);
          Exit;
        end;
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;



procedure TfrmOrderInPut_FB.TBSaveClick(Sender: TObject);
begin
  OrdDate.SetFocus;
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!','提示',0);
    Exit;
  end;
  if trim(orddefstr10.Text)='' then
  begin
    application.MessageBox('客户简称不能为空','提示',0);
    exit;
  end;
  if trim(orderNo.Text)='' then
  begin
    application.MessageBox('指示单号不能为空','提示',0);
    exit;
  end;
  if trim(conNO.Text)='' then
  begin
    application.MessageBox('合同号不能为空','提示',0);
    exit;
  end;
  if order_Sub.Locate('PrtCodeName',null,[])=True then
  begin
    application.MessageBox('产品名称不能为空','提示',0);
    exit;
  end;
  if trim(Orddefstr15.Text)='' then
  begin
    application.MessageBox('发票类型不能为空','提示',0);
    exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
  end;
  ModalResult:=1;
end;

procedure TfrmOrderInPut_FB.v1PRTColorPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdColor';
      flagname:='颜色';
      V1Name.Caption:='中文名称';
      V1Note.Caption:='英文名称';
      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_FB.ToolButton1Click(Sender: TObject);
var
  i:Integer;
  priceUnit:string;
begin
 { if Trim(OrderNo.Text)='' then
  begin
    Application.MessageBox('订单号不能为空!','提示',0);
    Exit;
  end;    }
  i:=Order_Sub.RecordCount;
  i:=i+1;
  If not Order_Sub.IsEmpty then
  PriceUnit:=Order_Sub.fieldbyname('PriceUnit').AsString;
  with Order_Sub do
  begin
    append;
    FieldByName('XHNO').Value:=IntToStr(i);
    FieldByName('PriceUnit').Value:=trim(PriceUnit);
    Post;
  end;
end;

procedure TfrmOrderInPut_FB.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;


{  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 JYOrderCY_Sub where SubId='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
      ExecSQL;
    end;
  end; }
  Order_Sub.Delete;

end;

procedure TfrmOrderInPut_FB.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_FB.CustomerNoNameBtnUpClick(Sender: TObject);
begin
 { try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CustomerNoName';
      flagname:='客户名称';
      if Trim(DParameters1)<>'高权限' then
        MainType:=Trim(DName);
      if ShowModal=1 then
      begin
        CustomerNoName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        CustomerNoName.TxtCode:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;}
  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);
        orddefstr10.Text:=Trim(CDS_HZ.fieldbyname('ZDYNameZ').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

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

procedure TfrmOrderInPut_FB.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_FB.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_FB.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_FB.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_FB.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_FB.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_FB.FormCreate(Sender: TObject);
begin
  cxGrid1.Align:=alClient;
  OrdDate.DateTime:=SGetServerDateTime(ADOTemp);
  OrdDefDate1.DateTime:=SGetServerDateTime(ADOTemp);
 //   DlyDate.DateTime:=OrdDate.Date;
  //  OrdDefDate1.DateTime:=OrdDate.Date;
   // OrdDefDate2.DateTime:=OrdDate.Date;

end;

procedure TfrmOrderInPut_FB.N1Click(Sender: TObject);
begin
  ToolButton1.Click;
end;

procedure TfrmOrderInPut_FB.N3Click(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmOrderInPut_FB.conNoChange(Sender: TObject);

var
  ConMainId:string;
begin

 
end;

procedure TfrmOrderInPut_FB.ToolButton4Click(Sender: TObject);
begin
  CDS_CG.Append;
  CDS_CG.FieldByName('CRTime').Value:=formatdateTime('yyyy-MM-dd',date());
  CDS_CG.Post;
end;

procedure TfrmOrderInPut_FB.ToolButton5Click(Sender: TObject);
begin
  IF CDS_CG.IsEmpty then exit;
  IF CDS_CG.FieldByName('defBit1').AsBoolean then
  begin
    if Application.MessageBox('此单已生成采购单，是否删除采购单和拆分信息','提示',32+4)<>IDYES then Exit;
  end;

  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete BP_InOut_CF where CRNO='''+Trim(CDS_CG.fieldbyname('CRNO').AsString)+'''');
    sql.Add('delete YF_Money_CR where mainID='''+Trim(CDS_CG.fieldbyname('CRNO').AsString)+'''');
    ExecSQL;
  end;
  CDS_CG.Delete;
end;

procedure TfrmOrderInPut_FB.orderNoBtnClick(Sender: TObject);
var
  ConMainId:string;
begin
   ConMainId:='';
   frmProductOrderListSel:=TfrmProductOrderListSel.create(self);
   with frmProductOrderListSel do
   begin
     FFInt:=1;
     if showmodal=1 then
     begin
       ConMainId:=trim(Order_Main.fieldbyname('mainID').asstring);
     end;
     free;
   end;
   iF ConMainId='' then exit;
   with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select B.*,A.*,c.KhconNo,C.ConPerson2,C.ConPerson3,C.conDefstr2,C.conDefstr6,C.condefstr10,C.priceNote,C.Payment,C.ShippMent, ');
      sql.Add('PriceUnit1=(select top 1 PriceUnit from JYordercon_sub X where X.mainID=C.mainid)');
      sql.Add('from JYOrder_sub A ');
      sql.Add('inner join  JYOrder_Main B on B.mainID=A.mainID          ');
      sql.Add('left  join JYOrderCon_Main C on C.conNO=B.conNO           ');
      sql.Add('where  B.mainID like '''+'%'+Trim(ConMainId)+'%'+'''');
      Open;
    end;
    IF not ADOTemp.IsEmpty then
    begin
      ConNo.Text:=Trim(ADOTemp.fieldbyname('ConNo').AsString);
      orderNo.Text:=Trim(ADOTemp.fieldbyname('orderNo').AsString);
    //  CYNO.Text:='CY_'+Trim(ADOTemp.fieldbyname('ConNo').AsString);
      CustomerNoName.Text:=Trim(ADOTemp.fieldbyname('CustomerNoName').AsString);
      CustomerNoName.TxtCode:=Trim(ADOTemp.fieldbyname('CustomerNo').AsString);
    //  DLYDate.DateTime:=ADOTemp.fieldbyname('DLYDate').AsDateTime;
   //   ConMainId:=Trim(ADOTemp.fieldbyname('MainId').AsString);
      OrdPerson2.Text:=Trim(ADOTemp.fieldbyname('OrdPerson2').AsString);
      KHCONNO.Text:=Trim(ADOTemp.fieldbyname('KHCONNO').AsString);
     // LBNameNote.Text:=Trim(ADOTemp.fieldbyname('LBNameNote').AsString);
    //  MaiTouNote.Text:=Trim(ADOTemp.fieldbyname('MaiTouNote').AsString);

      ConPerson1.Text:=Trim(ADOTemp.fieldbyname('ConPerson2').AsString);
      ConPerson2.Text:=Trim(ADOTemp.fieldbyname('ConPerson3').AsString);

      conDefstr1.Text:=Trim(ADOTemp.fieldbyname('conDefstr2').AsString);
      conDefstr2.Text:=Trim(ADOTemp.fieldbyname('conDefstr6').AsString);

      orddefstr4.Text:=Trim(ADOTemp.fieldbyname('Payment').AsString);
      orddefstr5.Text:=Trim(ADOTemp.fieldbyname('priceNote').AsString);
      orddefstr6.Text:=Trim(ADOTemp.fieldbyname('ShippMent').AsString);
      orddefstr10.Text:=Trim(ADOTemp.fieldbyname('condefstr10').AsString);
    end;
    Order_Sub.EmptyDataSet;
    with ADOTemp do
    begin
        First;
        while not Eof do
        begin
          with Order_Sub do
          begin
            Append;
            FieldByName('XHNO').Value:=Trim(ADOTemp.fieldbyname('XHNO').AsString);
            FieldByName('PRTCode').Value:=Trim(ADOTemp.fieldbyname('MPRTCode').AsString);
            FieldByName('PRTCodeName').Value:=Trim(ADOTemp.fieldbyname('MPRTCodeName').AsString);
            FieldByName('PRTspec').Value:=Trim(ADOTemp.fieldbyname('MPRTspec').AsString);
            FieldByName('PRTOrderQty').Value:=Trim(ADOTemp.fieldbyname('PRTOrderQty').AsString);
            FieldByName('PRTMF').Value:=Trim(ADOTemp.fieldbyname('MPRTMF').AsString);
            FieldByName('PRTKZ').Value:=Trim(ADOTemp.fieldbyname('MPRTKZ').AsString);
            FieldByName('Sorddefstr1').Value:=Trim(ADOTemp.fieldbyname('Sorddefstr1').AsString);
            FieldByName('Sorddefstr2').Value:=Trim(ADOTemp.fieldbyname('Sorddefstr2').AsString);
            FieldByName('Sorddefstr4').Value:=Trim(ADOTemp.fieldbyname('Sorddefstr4').AsString);
            FieldByName('PRTColor').Value:=Trim(ADOTemp.fieldbyname('PRTColor').AsString);
            FieldByName('OrderUnit').Value:=Trim(ADOTemp.fieldbyname('OrderUnit').AsString);
            FieldByName('PRTPrice').Value:=Trim(ADOTemp.fieldbyname('PRTPrice').AsString);
            FieldByName('PriceUnit').Value:=Trim(ADOTemp.fieldbyname('PriceUnit1').AsString);
//            FieldByName('PriceUnitRate').Value:=Trim(ADOTemp.fieldbyname('PriceUnitRate').AsString);
       //     FieldByName('PRTmoney').Value:=Trim(ADOTemp.fieldbyname('PRTmoney').AsString);
            FieldByName('SordQty1').Value:=Trim(ADOTemp.fieldbyname('PRTOrderQty').AsString);

            FieldByName('Sorddefstr10').Value:=Trim(ADOTemp.fieldbyname('subID').AsString);
            Post;
          end;
          Next;
        end;
    end;



end;

procedure TfrmOrderInPut_FB.OrdPerson1BtnUpClick(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
        //flag:='OrdDefStr2';
        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;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmOrderInPut_FB.v1Column4PropertiesButtonClick(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_FB.v1Column7PropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
begin
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_Sub do
  begin
    edit;
    if Trim(TcxTextEdit(Sender).EditingText)='' then
    begin
      fieldbyname(Fieldname).Value:='0';
    end
    else
    fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;
    FieldByName('PrtMoney').Value:=strtofloat(format('%.2f',[Fieldbyname('SordQty1').AsFloat*Fieldbyname('PrtPrice').AsFloat ]));
    post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut_FB.v1PrtmoneyPropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
begin
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_Sub do
  begin
    edit;
    if Trim(TcxTextEdit(Sender).EditingText)='' then
    begin
      fieldbyname(Fieldname).Value:='0';
    end
    else
    fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;
    IF Fieldbyname('SordQty1').AsFloat>0 then
    FieldByName('PrtPrice').Value:=(Fieldbyname('PrtMoney').AsFloat/Fieldbyname('SordQty1').AsFloat);
    post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut_FB.CYNOBtnClick(Sender: TObject);
var
  ConMainId:string;
begin
   ConMainId:='';
   frmProductOrderNewList_CY_SEL:=TfrmProductOrderNewList_CY_SEL.create(self);
   with frmProductOrderNewList_CY_SEL do
   begin
     FFInt:=1;
     if showmodal=1 then
     begin
       ConMainId:=trim(Order_Main.fieldbyname('mainID').asstring);
     end;
     free;
   end;
   iF ConMainId='' then exit;
   with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select B.*,A.*,c.KhconNo,C.ConPerson2,C.ConPerson3,C.conDefstr2,C.conDefstr6,C.condefstr10,C.priceNote,C.Payment,C.ShippMent, ');
      sql.Add('C.BankNo,C.BankName,C.BankSelfFastNo,C.BankAddress,C.MPRTTYpe,');
      sql.Add('PriceUnit1=(select top 1 PriceUnit from JYordercon_sub X where X.mainID=C.mainid) ');
      sql.Add('from JYOrderCY_sub A ');
      sql.Add('inner join  JYOrderCY_Main B on B.mainID=A.mainID ');
      sql.Add('left  join JYOrderCon_Main C on C.conNO=B.conNO ');
      sql.Add('where  B.mainID like '''+'%'+Trim(ConMainId)+'%'+'''');
      Open;
    end;
    IF not ADOTemp.IsEmpty then
    begin
      ConNo.Text:=Trim(ADOTemp.fieldbyname('ConNo').AsString);
      orderNo.Text:=Trim(ADOTemp.fieldbyname('orderNo').AsString);
      CYNO.Text:=Trim(ADOTemp.fieldbyname('CYNO').AsString);
      CustomerNoName.Text:=Trim(ADOTemp.fieldbyname('CustomerNoName').AsString);
      CustomerNoName.TxtCode:=Trim(ADOTemp.fieldbyname('CustomerNo').AsString);
      OrdPerson2.Text:=Trim(ADOTemp.fieldbyname('OrdPerson2').AsString);
      KHCONNO.Text:=Trim(ADOTemp.fieldbyname('KHCONNO').AsString);
      ConPerson1.Text:=Trim(ADOTemp.fieldbyname('ConPerson1').AsString);
      ConPerson2.Text:=Trim(ADOTemp.fieldbyname('ConPerson2').AsString);
      conDefstr1.Text:=Trim(ADOTemp.fieldbyname('conDefstr1').AsString);
      conDefstr2.Text:=Trim(ADOTemp.fieldbyname('conDefstr2').AsString);
      
      orddefstr3.Text:=Trim(ADOTemp.fieldbyname('MaiTouNote').AsString);
      orddefstr4.Text:=Trim(ADOTemp.fieldbyname('orddefstr4').AsString);
      orddefstr5.Text:=Trim(ADOTemp.fieldbyname('orddefstr5').AsString);

      orddefstr6.Text:=Trim(ADOTemp.fieldbyname('orddefstr6').AsString);
      OrdDefStr8.Text:=Trim(ADOTemp.Fieldbyname('BankNo').AsString);
      OrdDefStr9.text:=Trim(ADOTemp.fieldbyname('BankName').AsString);
      orddefstr10.Text:=Trim(ADOTemp.fieldbyname('condefstr10').AsString);
      OrdDefStr11.Text:=Trim(ADOTemp.Fieldbyname('BankSelfFastNo').AsString);
      OrdDefStr12.text:=Trim(ADOTemp.fieldbyname('BankAddress').AsString);
      if Trim(ADOTemp.fieldbyname('MPRTTYpe').AsString)='' then
      begin
        MPRTTYpe.Text:='外销';
      end
      else
      MPRTTYpe.Text:=Trim(ADOTemp.fieldbyname('MPRTTYpe').AsString);
    end;
    Order_Sub.EmptyDataSet;
    with ADOTemp do
    begin
      First;
      while not Eof do
      begin
        with Order_Sub do
        begin
          Append;
          FieldByName('XHNO').Value:=Trim(ADOTemp.fieldbyname('XHNO').AsString);
          FieldByName('PRTCode').Value:=Trim(ADOTemp.fieldbyname('PRTCode').AsString);
          FieldByName('PRTCodeName').Value:=Trim(ADOTemp.fieldbyname('PRTCodeName').AsString);
          FieldByName('PRTspec').Value:=Trim(ADOTemp.fieldbyname('PRTspec').AsString);
          FieldByName('PRTOrderQty').Value:=Trim(ADOTemp.fieldbyname('PRTOrderQty').AsString);
          FieldByName('PRTMF').Value:=Trim(ADOTemp.fieldbyname('PRTMF').AsString);
          FieldByName('PRTKZ').Value:=Trim(ADOTemp.fieldbyname('PRTKZ').AsString);
          FieldByName('Sorddefstr1').Value:=Trim(ADOTemp.fieldbyname('Sorddefstr1').AsString);
          FieldByName('Sorddefstr2').Value:=Trim(ADOTemp.fieldbyname('Sorddefstr2').AsString);
          FieldByName('Sorddefstr4').Value:=Trim(ADOTemp.fieldbyname('Sorddefstr4').AsString);
          FieldByName('PRTColor').Value:=Trim(ADOTemp.fieldbyname('PRTColor').AsString);
          FieldByName('OrderUnit').Value:=Trim(ADOTemp.fieldbyname('OrderUnit').AsString);
          FieldByName('PRTPrice').Value:=Trim(ADOTemp.fieldbyname('PRTPrice').AsString);
          FieldByName('PriceUnit').Value:=Trim(ADOTemp.fieldbyname('PriceUnit1').AsString);
          FieldByName('SordQty1').Value:=Trim(ADOTemp.fieldbyname('SordQty1').AsString);
          FieldByName('SordQty3').Value:=Trim(ADOTemp.fieldbyname('SordQty3').AsString);
          FieldByName('SordQty4').Value:=Trim(ADOTemp.fieldbyname('SordQty4').AsString);
          FieldByName('SordQty5').Value:=Trim(ADOTemp.fieldbyname('SordQty5').AsString);
          FieldByName('PrtMoney').Value:=strtofloat(format('%.2f',[Fieldbyname('SordQty1').AsFloat*Fieldbyname('PrtPrice').AsFloat ]));
          FieldByName('Sorddefstr10').Value:=Trim(ADOTemp.fieldbyname('subID').AsString);
          Post;
        end;
        Next;
      end;
    end;
end;

procedure TfrmOrderInPut_FB.v1Column8PropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
begin
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  begin
    with Order_Sub do
    begin
      edit;
      if Trim(TcxTextEdit(Sender).EditingText)='' then
      begin
        fieldbyname(Fieldname).Value:='0';
      end
      else
      fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;
      FieldByName('PrtMoney').Value:=(Fieldbyname('SordQty1').AsFloat)*(Fieldbyname('PrtPrice').AsFloat);
      post;
    end;
    Tv1.Controller.EditingController.ShowEdit();
  end;
end;

procedure TfrmOrderInPut_FB.OrdDefStr8BtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BankNo';
      flagname:='银行账号';
      if ShowModal=1 then
      begin
        OrdDefStr8.text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        with ADOTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select Top 1* from JYOrderCon_Main where BankNo='''+Trim(ClientDataSet1.fieldbyname('ZDYName').AsString)+'''');
          sql.Add(' and MPRTTYpe='''+Trim(MPRTTYpe.Text)+'''');
          sql.Add(' order by FillTime desc ');
          Open;
          Self.OrdDefStr9.Text:=Trim(ADOTemp.fieldbyname('BankName').AsString);
          Self.OrdDefStr12.Text:=Trim(ADOTemp.fieldbyname('BankAddress').AsString);
          Self.OrdDefStr11.Text:=Trim(ADOTemp.fieldbyname('BankSelfFastNo').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut_FB.v1Column5PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
   frmProductOrderListSel:=TfrmProductOrderListSel.create(self);
   with frmProductOrderListSel do
   begin
     FFInt:=1;
     if showmodal=1 then
     begin
          with Order_Sub do
          begin
            edit;
            FieldByName('XHNO').Value:=Trim(Order_Main.fieldbyname('XHNO').AsString);
            FieldByName('PRTCode').Value:=Trim(Order_Main.fieldbyname('MPRTCode').AsString);
            FieldByName('PRTCodeName').Value:=Trim(Order_Main.fieldbyname('MPRTCodeName').AsString);
            FieldByName('PRTspec').Value:=Trim(Order_Main.fieldbyname('MPRTspec').AsString);
            FieldByName('PRTOrderQty').Value:=Trim(Order_Main.fieldbyname('PRTOrderQty').AsString);
            FieldByName('PRTMF').Value:=Trim(Order_Main.fieldbyname('MPRTMF').AsString);
            FieldByName('PRTKZ').Value:=Trim(Order_Main.fieldbyname('MPRTKZ').AsString);
            FieldByName('Sorddefstr1').Value:=Trim(Order_Main.fieldbyname('Sorddefstr1').AsString);
            FieldByName('Sorddefstr2').Value:=Trim(Order_Main.fieldbyname('Sorddefstr2').AsString);
            FieldByName('Sorddefstr4').Value:=Trim(Order_Main.fieldbyname('Sorddefstr4').AsString);
            FieldByName('PRTColor').Value:=Trim(Order_Main.fieldbyname('PRTColor').AsString);
            FieldByName('OrderUnit').Value:=Trim(Order_Main.fieldbyname('OrderUnit').AsString);
            FieldByName('PRTPrice').Value:=Trim(Order_Main.fieldbyname('PRTPrice').AsString);
            FieldByName('PriceUnit').Value:=Trim(Order_Main.fieldbyname('PriceUnit1').AsString);
//            FieldByName('PriceUnitRate').Value:=Trim(ADOTemp.fieldbyname('PriceUnitRate').AsString);
       //     FieldByName('PRTmoney').Value:=Trim(ADOTemp.fieldbyname('PRTmoney').AsString);
            FieldByName('SordQty1').Value:=Trim(Order_Main.fieldbyname('PRTOrderQty').AsString);

            FieldByName('Sorddefstr10').Value:=Trim(Order_Main.fieldbyname('subID').AsString);
            Post;
          end;
     end;
     free;
   end;
   tv1.Controller.EditingController.ShowEdit();
end;

end.
