unit U_ConInPutNX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo,
  cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit,
  StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxCalendar, StrUtils,
  cxDropDownEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle,
  dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary,
  dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin,
  dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmConInPutNX = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label3: TLabel;
    OrdDate: TDateTimePicker;
    Label4: TLabel;
    DlyDate: TDateTimePicker;
    Label7: TLabel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1PRTColor: TcxGridDBColumn;
    v1PRTPrice: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    v1PRTOrderQty: TcxGridDBColumn;
    Label9: TLabel;
    Label10: TLabel;
    ConNo: TEdit;
    Label14: TLabel;
    Label20: TLabel;
    FromPlace: TBtnEditC;
    CustomerNoName: TBtnEditC;
    v1XHNo: TcxGridDBColumn;
    SYRName: TBtnEditC;
    v1OrderUnit: TcxGridDBColumn;
    Label6: TLabel;
    Label15: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    SYRAddress: TEdit;
    Label19: TLabel;
    SYRBankName: TEdit;
    Label21: TLabel;
    CTMAddress: TEdit;
    v1Column3: TcxGridDBColumn;
    Label8: TLabel;
    SYRTelNo: TEdit;
    Label23: TLabel;
    SYRFaxNo: TEdit;
    CDS_Type: TClientDataSet;
    Label5: TLabel;
    Label29: TLabel;
    Label22: TLabel;
    Label24: TLabel;
    CTMTelNo: TEdit;
    CTMFaxNo: TEdit;
    Label31: TLabel;
    Label34: TLabel;
    KHConNo: TEdit;
    Label35: TLabel;
    Label36: TLabel;
    CTMBankName: TEdit;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    YWY: TBtnEditC;
    Label1: TLabel;
    CTMPerson: TEdit;
    ZhiLiangNote: TMemo;
    QtyNote: TBtnEditC;
    Payment: TMemo;
    DlyNote: TMemo;
    Note: TMemo;
    SYRBankNo: TEdit;
    CTMBankNo: TEdit;
    v1Column1: 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 v1Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ZhiLiangNoteDblClick(Sender: TObject);
    procedure v1Column15PropertiesEditValueChanged(Sender: TObject);
    procedure v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure FromPlaceBtnUpClick(Sender: TObject);
    procedure FromPlaceBtnDnClick(Sender: TObject);
    procedure SYRNameBtnUpClick(Sender: TObject);
  private
    fuserName: string;
    procedure InitData();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    function SaveData(): Boolean;
    function SaveDataSubOne(): Boolean;
    function SaveDataMain(): Boolean;
    function SaveDataSubMore(): Boolean;
    { Private declarations }
  public
    PState, CopyInt: Integer;
    FMainId, FFMainId: string;
    FXS: Integer;
    canshu1: string;
    { Public declarations }
  end;

var
  frmConInPutNX: TfrmConInPutNX;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_ZDYHelpSel, U_ZdyAttachment, U_CPManageSel;

{$R *.dfm}

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

procedure TfrmConInPutNX.InitData();
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from SY_User where username=''' + Trim(DName) + '''');
    open;
  end;
  if ADOTemp.FieldByName('utype').Value = '业务员' then
  begin
    Label21.Visible := False;
    Label35.Visible := False;
    Label36.Visible := False;
    Label1.Visible := False;
    Label22.Visible := False;
    Label24.Visible := False;
    CTMAddress.Visible := False;
    CTMBankNo.Visible := False;
    CTMBankName.Visible := False;
    CTMPerson.Visible := False;
    CTMTelNo.Visible := False;
    CTMFaxNo.Visible := False;
  end
  else
  begin
    Label21.Visible := true;
    Label35.Visible := true;
    Label36.Visible := true;
    Label1.Visible := true;
    Label22.Visible := true;
    Label24.Visible := true;
    CTMAddress.Visible := true;
    CTMBankNo.Visible := true;
    CTMBankName.Visible := true;
    CTMPerson.Visible := true;
    CTMTelNo.Visible := true;
    CTMFaxNo.Visible := true;
  end;
  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 := SGetServerDateTime(ADOTemp);
    ConNo.Text := '自动生成';
  end
  else
  begin
  end;
  if CopyInt = 99 then
  begin
    PState := 0;
    FMainId := '';
    YWY.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 TfrmConInPutNX.ZDYHelp(FButn: TcxButtonEdit; LType: string);
var
  FType, ZDYName, FText: string;
begin
end;

procedure TfrmConInPutNX.FormShow(Sender: TObject);
begin
  readCxGrid('合同录入内销', Tv1, '合同管理');
  InitData();
end;

function TfrmConInPutNX.SaveData(): Boolean;
var
  maxno: string;
  fconNO, fmxType: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOCmd, maxno, 'JN', 'JYOrderCon_Main', 3, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
      if trim(ConNo.Text) = '自动生成' then
      begin
        if GetLSNo(ADOCmd, fconNO, 'HR', 'JYOrderCon_Main', 3, 0) = False then
        begin
          ADOCmd.Connection.RollbackTrans;
          Application.MessageBox('取最合同编号失败!', '提示', 0);
          Exit;
        end;
        fconNO := copy(fconNO, 1, 2) + formatdateTime('yy', DServerDate) + copy(fconNO, 3, 3);
        ConNo.Text := uppercase(fconNO);
      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);
      SSetsaveSqlNew(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('MPRTType').Value := '内销';
      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(FMainId) + '''');
      ExecSQL;
    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, 'JB', 'JYOrderCon_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 JYOrderCon_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, 'JYOrderCon_Sub', 0);
          fieldbyname('PRTOrderQty').Value := Order_Sub.fieldbyname('PRTOrderQty').AsFloat;
          fieldbyname('prtPrice').Value := Order_Sub.fieldbyname('prtPrice').AsFloat;
          fieldbyname('huilv').Value := Order_Sub.fieldbyname('huilv').AsFloat;

          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value := Trim(maxno);
        //Order_Sub.Post;
        Next;
      end;
    end;

    ADOCmd.Connection.CommitTrans;
    Result := True;
  except

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

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

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

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

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

procedure TfrmConInPutNX.TBSaveClick(Sender: TObject);
begin
  OrdDate.SetFocus;
  if Trim(ConNo.Text) = '' then
  begin
    Application.MessageBox('合同号不能为空！', '提示', 0);
    Exit;
  end;

  if Trim(QtyNote.Text) = '' then
  begin
    Application.MessageBox('溢短装不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(SYRName.Text) = '' then
  begin
    Application.MessageBox('公司抬头不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('PRTCode', null, []) then
  begin
    Application.MessageBox('产品编号不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('PrtCodeName', null, []) then
  begin
    Application.MessageBox('品名不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('PRTColor', null, []) then
  begin
    Application.MessageBox('颜色不能为空！', '提示', 0);
    Exit;
  end;

  if Order_Sub.Locate('PRTMF', null, []) then
  begin
    Application.MessageBox('门幅不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('PRTKZ', null, []) then
  begin
    Application.MessageBox('克重不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('OrderUnit', null, []) then
  begin
    Application.MessageBox('数量单位不能为空！', '提示', 0);
    Exit;
  end;

  if Order_Sub.Locate('PRTCode', '', []) then
  begin
    Application.MessageBox('产品编号不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('PrtCodeName', '', []) then
  begin
    Application.MessageBox('品名不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('PRTColor', '', []) then
  begin
    Application.MessageBox('颜色不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('prtkuanNo', '', []) then
  begin
    Application.MessageBox('款型不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('PRTMF', '', []) then
  begin
    Application.MessageBox('门幅不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('PRTKZ', '', []) then
  begin
    Application.MessageBox('克重不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('OrderUnit', '', []) then
  begin
    Application.MessageBox('数量单位不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.Locate('PriceUnit', '', []) then
  begin
    Application.MessageBox('币种不能为空！', '提示', 0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
  end;
end;

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

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

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

procedure TfrmConInPutNX.CustomerNoNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
      if ShowModal = 1 then
      begin
        CustomerNoName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        CustomerNoName.TxtCode := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
        CTMPerson.Text := Trim(CDS_HZ.fieldbyname('Contacts').AsString);
        CTMAddress.Text := Trim(CDS_HZ.fieldbyname('CoAddress').AsString);
        CTMTelNo.Text := Trim(CDS_HZ.fieldbyname('Telephone').AsString);
        CTMFaxNo.Text := Trim(CDS_HZ.fieldbyname('Fax').AsString);
        CTMbankNo.Text := Trim(CDS_HZ.fieldbyname('BankNo').AsString);
        CTMbankName.Text := Trim(CDS_HZ.fieldbyname('bankName').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmConInPutNX.v1Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  frmCPManageSel := TfrmCPManageSel.Create(self);
  with frmCPManageSel do
  begin
    if showmodal = 1 then
    begin
      Order_Sub.Edit;
      Order_Sub.fieldbyname('PRTCode').Value := CDS_Main.fieldbyname('CYNo').asstring;
      Order_Sub.fieldbyname('PRTCodeName').Value := CDS_Main.fieldbyname('CYName').asstring;
      Order_Sub.fieldbyname('PRTspec').Value := CDS_Main.fieldbyname('CYSpec').asstring;
      Order_Sub.fieldbyname('prtmf').Value := CDS_Main.fieldbyname('CYMF').asstring;
      Order_Sub.fieldbyname('prtkz').Value := CDS_Main.fieldbyname('CYKZ').asstring;
      Order_Sub.fieldbyname('PRTHX').Value := CDS_Main.fieldbyname('CYHX').asstring;
      Order_Sub.fieldbyname('PRTColor').Value := CDS_Main.fieldbyname('CYColor').asstring;
      Order_Sub.Post;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNX.ZhiLiangNoteDblClick(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
        TMemo(Sender).Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean = True then
            begin
              i := i + 1;
//              TMemo(Sender).Lines.Add(inttostr(i)+'.'+FieldByName('ZDYName').AsString)
              TMemo(Sender).Lines.Add(FieldByName('ZDYName').AsString)
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmConInPutNX.v1Column15PropertiesEditValueChanged(Sender: TObject);
var
  mvalue: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;

  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  with Order_Sub do
  begin
    Edit;
    FieldByName('YongJinPrice').Value := mvalue;
    FieldByName('YongJin').Value := FieldByName('YongJinPrice').AsFloat * FieldByName('PRTOrderQty').AsFloat;
    Post;
  end;
end;

procedure TfrmConInPutNX.v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FPRTOrderQty, FPRTPrice, FPRTMoney: Extended;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  with Order_Sub do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;
    FPRTOrderQty := FieldByName('PRTOrderQty').asfloat;
    FPRTPrice := FieldByName('PRTPrice').asfloat;
  end;
  FPRTMoney := StrToFloat(format('%.2f', [FPRTOrderQty * FPRTPrice]));
  with Order_Sub do
  begin
    Edit;
    FieldByName('PRTMoney').Value := FPRTMoney;
    Post;
  end;
end;

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

procedure TfrmConInPutNX.SYRNameBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

  with ADOTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select top 1 * from JYOrderCon_Main ');
    sql.Add(' where SYRName=' + quotedstr(Trim(SYRName.Text)));
    sql.Add(' order by OrdDate desc ');
    open;
  end;

  SYRAddress.Text := trim(ADOTemp.fieldbyname('SYRAddress').AsString);
  SYRTelNo.Text := trim(ADOTemp.fieldbyname('SYRTelNo').AsString);
  SYRBankNo.Text := trim(ADOTemp.fieldbyname('SYRBankNo').AsString);
  SYRBankName.Text := trim(ADOTemp.fieldbyname('SYRBankName').AsString);
  SYRFaxNo.Text := trim(ADOTemp.fieldbyname('SYRFaxNo').AsString);
end;

end.

