unit U_ConInPut;

interface

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

type
  TfrmConInPut = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label3: TLabel;
    OrdDate: TDateTimePicker;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1PRTPrice: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    v1PRTOrderQty: TcxGridDBColumn;
    Label10: TLabel;
    ConNo: TEdit;
    Label14: TLabel;
    Label20: TLabel;
    CustomerNoName: TBtnEditC;
    SYRName: TBtnEditC;
    v1OrderUnit: TcxGridDBColumn;
    v1PriceUnit: TcxGridDBColumn;
    ToolButton3: TToolButton;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    Label1: TLabel;
    PayMent: TBtnEditC;
    Label2: TLabel;
    PriceTK: TBtnEditC;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label7: TLabel;
    Label4: TLabel;
    FromPlace: TBtnEditC;
    ToPlace: TBtnEditC;
    Label5: TLabel;
    DlyDate: TDateTimePicker;
    Label6: TLabel;
    OrdConQtyNote: TBtnEditC;
    Label8: TLabel;
    ZFPayment: TBtnEditC;
    Label9: TLabel;
    BankNameHZ: TBtnEditC;
    Label11: TLabel;
    BankNo: TBtnEditC;
    Label12: TLabel;
    Note: TEdit;
    Label13: TLabel;
    PONO: TEdit;
    v1Column1: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    Label15: TLabel;
    DlyDateNote: TBtnEditC;
    v1Column12: TcxGridDBColumn;
    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 SYRNameBtnUpClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure v1Column4PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure PayMentBtnUpClick(Sender: TObject);
    procedure PriceTKBtnUpClick(Sender: TObject);
    procedure FromPlaceBtnUpClick(Sender: TObject);
    procedure BankNameHZBtnUpClick(Sender: TObject);
    procedure BankNoBtnUpClick(Sender: TObject);
  private
    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:String;
    FXS:Integer;
    { Public declarations }
  end;

var
  frmConInPut: TfrmConInPut;
  newh:hwnd;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel, U_ZHKHListNewCX,
  U_CPSel;

{$R *.dfm}

procedure TfrmConInPut.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('订单合同录入1',Tv1,'生产指示单管理');
end;

procedure TfrmConInPut.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrderCon_Sub ');
    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 where MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,ScrollBox1,2);
  if PState=0 then
  begin
    OrdDate.DateTime:=SGetServerDateTime(ADOTemp);
    DlyDate.DateTime:=OrdDate.DateTime;
    //MoneyDate.Date:=OrdDate.Date;
    //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;
  end;
end;

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

procedure TfrmConInPut.FormShow(Sender: TObject);
begin
  readCxGrid('订单合同录入1',Tv1,'生产指示单管理');
  InitData();
end;

function TfrmConInPut.SaveData():Boolean;
var
  maxno,maxsubno:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOCmd,maxno,'JC','JYOrderCon_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 JYOrderCon_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);
      RTSetsavedata(ADOCmd,'JYOrderCon_Main',ScrollBox1,2);
      if Trim(FMainId)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
      end else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
      end;
     // FieldByName('Note').Value:=Trim(Note.Text);
      Post;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrderCon_Main where ConNo='''+Trim(ConNo.Text)+'''');
      Open;
    end;
    if ADOCmd.RecordCount>1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('合同号重复!','提示',0);
      Exit;
    end;

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate JYOrderCon_Main Set Filler='''+Trim(DName)+'''');
      sql.Add(' where MainId='''+Trim(maxno)+'''');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update JYOrderCon_Main Set SYRAddress=(select Top 1 ZdyStr4 from KH_Zdy where ZdyName=JYOrderCon_Main.SYRName and Type=''GSTT'' )');
      sql.Add(',SYRTel=(select Top 1 ZdyStr2 from KH_Zdy where ZdyName=JYOrderCon_Main.SYRName and Type=''GSTT'' )');
      sql.Add(',SYRFax=(select Top 1 ZdyStr3 from KH_Zdy where ZdyName=JYOrderCon_Main.SYRName and Type=''GSTT'' )');
      sql.Add(',KHAddress=(select Top 1 ZKAddress from ZH_KH_Info A where A.KHNameJC=JYOrderCon_Main.CustomerNoName)');
      sql.Add(',KHTel=(select Top 1 ZKTelNo from ZH_KH_Info A where A.KHNameJC=JYOrderCon_Main.CustomerNoName)');
      sql.Add(',BankFastNoHZ=(select Top 1 Note from KH_Zdy where ZdyName=JYOrderCon_Main.BankNameHZ and Type=''BankNameHZ'' )');
      sql.Add(',BankName=(select Top 1 ZdyStr1 from KH_Zdy where ZdyName=JYOrderCon_Main.BankNo and Type=''BankNoHT'' )');
      sql.Add(',BankFastNo=(select Top 1 ZdyStr2 from KH_Zdy where ZdyName=JYOrderCon_Main.BankNo and Type=''BankNoHT'' )');
      sql.Add(' where MainId='''+Trim(maxno)+'''');
      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,maxsubno,'JB','JYOrderCon_Sub',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxsubno:=Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrderCon_Sub where MainId='''+Trim(maxno)+'''');
          sql.Add(' and SubId='''+Trim(maxsubno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
            Append
          else
            Edit;
          FieldByName('MainId').Value:=Trim(maxno);
          FieldByName('SubId').Value:=Trim(maxsubno);
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'JYOrderCon_Sub',0);
          if Trim(fieldbyname('PRTOrderQty').AsString)='' then
          begin
            fieldbyname('PRTOrderQty').Value:=0;
          end else
          begin
            fieldbyname('PRTOrderQty').Value:=Order_Sub.fieldbyname('PRTOrderQty').Value;
          end;
          if Trim(fieldbyname('PRTPrice').AsString)='' then
          begin
            fieldbyname('PRTPrice').Value:=0;
          end else
          begin
            fieldbyname('PRTPrice').Value:=Order_Sub.fieldbyname('PRTPrice').Value;
          end;
          if Trim(fieldbyname('PRTMoney').AsString)='' then
          begin
            fieldbyname('PRTMoney').Value:=0;
          end else
          begin
            fieldbyname('PRTMoney').Value:=Order_Sub.fieldbyname('PRTMoney').Value;
          end;
          if Trim(fieldbyname('BaoGangFee').AsString)='' then
          begin
            fieldbyname('BaoGangFee').Value:=0;
          end else
          begin
            fieldbyname('BaoGangFee').Value:=Order_Sub.fieldbyname('BaoGangFee').Value;
          end;
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value:=Trim(maxsubno);
        //Order_Sub.Post;
        Next;
      end;
    end;

    ADOCmd.Connection.CommitTrans;
    FMainId:=Trim(maxno);
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;
function TfrmConInPut.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 TfrmConInPut.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 TfrmConInPut.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 TfrmConInPut.TBSaveClick(Sender: TObject);
begin
  OrdDate.SetFocus;
  if Trim(ConNo.Text)='' then
  begin
    Application.MessageBox('合同号不能为空！','提示',0);
    Exit;
  end;
  if Trim(CustomerNoName.Text)='' then
  begin
    Application.MessageBox('客户不能为空！','提示',0);
    Exit;
  end;
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!','提示',0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
  end;
end;

procedure TfrmConInPut.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 TfrmConInPut.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('SOrddefstr1').Value:=null;
    FieldByName('SOrddefstr2').Value:=null;
    Post;
  end;
end;

procedure TfrmConInPut.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 JYOrderCon_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 TfrmConInPut.CustomerNoNameBtnUpClick(Sender: TObject);
begin
  try
    frmZHKHListNewCX:=TfrmZHKHListNewCX.Create(Application);
    with frmZHKHListNewCX do
    begin
      if ShowModal=1 then
      begin
        CustomerNoName.Text:=Trim(frmZHKHListNewCX.Order_Main.fieldbyname('KHNameJC').AsString);
        CustomerNoName.TxtCode:=Trim(frmZHKHListNewCX.Order_Main.fieldbyname('ZKID').AsString);
      end;
    end;
  finally
    frmZHKHListNewCX.Free;
  end;
end;

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

procedure TfrmConInPut.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 TfrmConInPut.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 TfrmConInPut.SYRNameBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='GSTT';
      flagname:='公司抬头';
      V1ZdyStr1.Visible:=True;
      V1ZdyStr2.Visible:=True;
      V1ZdyStr3.Visible:=True;
      V1ZdyStr4.Visible:=True;
      V1ZdyStr1.Caption:='简称';
      V1ZdyStr2.Caption:='电话';
      V1ZdyStr3.Caption:='传真';
      V1ZdyStr4.Caption:='地址';
      frmZDYHelp.Align:=alClient;
      if ShowModal=1 then
      begin
        SYRName.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

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

procedure TfrmConInPut.v1Column4PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
var
  fsj:string;
begin
  try
    frmCPSel:=TfrmCPSel.Create(Application);
    with frmCPSel do
    begin
      if ShowModal=1 then
      begin
        with Self.Order_Sub do
        begin
          Edit;
          FieldByName('PRTCode').Value:=Trim(frmCPSel.CDS_Main.fieldbyname('CYNO').AsString);
          FieldByName('PRTCodeName').Value:=Trim(frmCPSel.CDS_Main.fieldbyname('CYEName').AsString);
          FieldByName('PRTSpec').Value:=Trim(frmCPSel.CDS_Main.fieldbyname('CYSpec').AsString);
          FieldByName('PRTCF').Value:=Trim(frmCPSel.CDS_Main.fieldbyname('CYECF').AsString);
          if Trim(frmCPSel.CDS_Main.fieldbyname('CYMF').AsString)<>'' then
          begin
            FieldByName('PRTMF').Value:=Trim(frmCPSel.CDS_Main.fieldbyname('CYMF').AsString);
          end;
          if Trim(frmCPSel.CDS_Main.fieldbyname('CYKZ').AsString)<>'' then
          begin
            FieldByName('PRTKZ').Value:=Trim(frmCPSel.CDS_Main.fieldbyname('CYKZ').AsString);
          end;
          //Post;
        end;
      end;
    end;
  finally
    frmCPSel.Free;
  end;

end;

procedure TfrmConInPut.v1PRTOrderQtyPropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FName,FPrice,FQty,FBaoGangFee:string;
begin
  FName:=Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:='0';
  end;
  with Order_Sub do
  begin
    Edit;
    FieldByName(FName).Value:=mvalue;
    Post;
  end;
  FPrice:=Trim(Order_Sub.fieldbyname('PRTPrice').AsString);
  FQty:=Trim(Order_Sub.fieldbyname('PRTOrderQty').AsString);
  FBaoGangFee:=Trim(Order_Sub.fieldbyname('BaoGangFee').AsString);
  if Trim(FPrice)='' then
  begin
    FPrice:='0';
  end;
  if Trim(FQty)='' then
  begin
    FQty:='0';
  end;
  if Trim(FBaoGangFee)='' then
  begin
    FBaoGangFee:='0';
  end;
  with Order_Sub do
  begin
    Edit;
    FieldByName('PRTMoney').Value:=StrToFloat(FPrice)*StrToFloat(FQty)+StrToFloat(FBaoGangFee);
    Post;
  end;
end;

procedure TfrmConInPut.PayMentBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PIPayMent';
      flagname:='付款方式';
      frmZDYHelp.Align:=alClient;
      if ShowModal=1 then
      begin
        PayMent.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPut.PriceTKBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PriceTK';
      flagname:='价格条款';
      frmZDYHelp.Align:=alClient;
      if ShowModal=1 then
      begin
        PriceTK.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

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

procedure TfrmConInPut.BankNameHZBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BankNameHZ';
      flagname:='收款银行';
      fnote:=True;
      V1Name.Caption:='收款银行';
      V1Note.Caption:='迅速代码';
      if ShowModal=1 then
      begin
        BankNameHZ.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPut.BankNoBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BankNoHT';
      flagname:='银行账号';
      V1Name.Caption:='银行账号';
      V1ZdyStr1.Visible:=True;
      V1ZdyStr2.Visible:=True;
      V1ZdyStr1.Caption:='银行名称';
      V1ZdyStr2.Caption:='迅速代码';
      frmZDYHelp.Align:=alClient;
      if ShowModal=1 then
      begin
        BankNo.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.
