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, cxImage, cxBlobEdit,
  cxImageComboBox, ImgList, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmConInPutNX = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label3: TLabel;
    ConDate: TDateTimePicker;
    Label4: TLabel;
    DlyDate: TDateTimePicker;
    Label7: TLabel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1PRTPrice: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    v1PRTOrderQty: TcxGridDBColumn;
    Label9: TLabel;
    Label10: TLabel;
    ConNo: TEdit;
    Label14: TLabel;
    Label20: TLabel;
    FromPlace: TBtnEditC;
    v1XHNo: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    Label17: TLabel;
    Label18: TLabel;
    SellBankNo: TBtnEditC;
    SellAddress: TEdit;
    Label19: TLabel;
    SellBankName: TEdit;
    Label21: TLabel;
    BuyAddress: TEdit;
    Label8: TLabel;
    SellTel: TEdit;
    Label23: TLabel;
    SellFax: TEdit;
    CDS_Type: TClientDataSet;
    Label5: TLabel;
    Label28: TLabel;
    Label22: TLabel;
    Label24: TLabel;
    BuyTel: TEdit;
    BuyFax: TEdit;
    Label31: TLabel;
    Label34: TLabel;
    BuyConNo: TEdit;
    Label35: TLabel;
    Label36: TLabel;
    BuyBankName: TEdit;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    YwyName: TBtnEditC;
    ZLNote: TMemo;
    YSBZNote: TMemo;
    Note: TMemo;
    v1Column1: TcxGridDBColumn;
    BuyBankNo: TEdit;
    Sellname: TBtnEditC;
    v1Column13: TcxGridDBColumn;
    TsNote: TEdit;
    BuyName: TBtnEditC;
    v1Column3: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Label1: TLabel;
    Label2: TLabel;
    ConNoType: TComboBox;
    v1Column17: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Label6: TLabel;
    xstype: TComboBox;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Label11: TLabel;
    jiaohuodidian: TBtnEditC;
    Label12: TLabel;
    PayMent: TBtnEditC;
    Label13: TLabel;
    begfkts: TEdit;
    Label15: TLabel;
    endfkts: TEdit;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure BuyNameBtnUpClick(Sender: TObject);
    procedure BuyNameBtnDnClick(Sender: TObject);
    procedure v1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column4PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column6PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column7PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure DlyNoteBtnUpClick(Sender: TObject);
    procedure ZLNoteDblClick(Sender: TObject);
    procedure v1Column15PropertiesEditValueChanged(Sender: TObject);
    procedure SellBankNoBtnUpClick(Sender: TObject);
    procedure SellNameBtnUpClick(Sender: TObject);
    procedure v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure v1PRTPricePropertiesEditValueChanged(Sender: TObject);
    procedure TSBtnUpClick(Sender: TObject);
    procedure v1Column10PropertiesEditValueChanged(Sender: TObject);
    procedure jiaohuodidianBtnUpClick(Sender: TObject);
  private
    fuserName: string;
    procedure InitData();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    procedure GetSell(MSellName: string);
    function TestData(): Boolean;
    function SaveData(): Boolean;
   // function UpperCase(const S: string): string;

    { Private declarations }
  public
    CopyInt: Integer;
    PState: string;
    FMainId, FFMainId: string;
    canshu1, FGSTT: string;
    { Public declarations }
  end;

var
  frmConInPutNX: TfrmConInPutNX;
  newh: hwnd;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ZDYHelpSel, U_CPManageFMSel, U_ZdyAttachment,
  U_CPManage, U_CPSel, getpic;

{$R *.dfm}
procedure TfrmConInPutNX.GetSell(MSellName: string);
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select top 1 A.* ');
    sql.Add(' from Contract_Main A  ');
    SQL.Add('where  A.ConType=''销售'' and A.SellName=' + quotedstr(trim(MSellName)));
    sql.Add(' order by  A.ConDate desc ');
    //ShowMessage(SQL.Text);
    Open;
  end;
  SellAddress.Text := trim(ADOTemp.FieldByName('SellAddress').AsString);
  SellTel.Text := trim(ADOTemp.FieldByName('SellTel').AsString);
  SellBankNo.Text := trim(ADOTemp.FieldByName('SellBankNo').AsString);
  SellBankName.Text := trim(ADOTemp.FieldByName('SellBankName').AsString);
  SellFax.Text := trim(ADOTemp.FieldByName('SellFax').AsString);
  SellName.Text := trim(MSellName);
end;

function TfrmConInPutNX.TestData(): Boolean;
begin
  try
    if Trim(ConNo.Text) = '' then
      raise Exception.Create('合同号不能为空！');
    if Trim(SellName.Text) = '' then
      raise Exception.Create('供方不能为空！');
    if Trim(BuyName.Text) = '' then
      raise Exception.Create('需方不能为空！');
    if Trim(xstype.Text) = '' then
      raise Exception.Create('销售类型不能为空！');

    if Order_Sub.IsEmpty then
      raise Exception.Create('明细不能为空！');
    if Order_Sub.Locate('P_Code', null, []) then
      raise Exception.Create('产品编号不能为空！');
    if Order_Sub.Locate('P_Code', '', []) then
      raise Exception.Create('产品编号不能为空！');
    if Order_Sub.Locate('Qty', null, []) then
      raise Exception.Create('数量不能为空！');
    if Order_Sub.Locate('Qty', 0, []) then
      raise Exception.Create('数量不能为0！');
    if Order_Sub.Locate('QtyUnit', null, []) then
      raise Exception.Create('数量单位不能为空！');
    if Order_Sub.Locate('QtyUnit', '', []) then
      raise Exception.Create('数量单位不能为空！');
    if Order_Sub.Locate('BZType', null, []) then
      raise Exception.Create('币种不能为空！');
    if Order_Sub.Locate('BZType', '', []) then
      raise Exception.Create('币种不能为空！');
    Result := True;
  except
    Result := false;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmConInPutNX.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(trim(self.Caption), Tv1, '销售合同管理');
  ModalResult := 1;
end;

procedure TfrmConInPutNX.InitData();
begin
  //刷新产品信息
  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from Contract_Sub ');
    sql.Add('where ConMainId=''' + Trim(FMainId) + '''');
  //  ShowMessage(SQL.Text);
    Open;
  end;
  SCreateCDS20(ADOTemp, Order_Sub);
  SInitCDSData20(ADOTemp, Order_Sub);
   //刷新条款信息
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Contract_Main where ConMainId=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCSHDataNew(ADOTemp, ScrollBox1, 2);
  BuyName.TxtCode := ADOTemp.FieldByName('buyno').AsString;
  if PState = '新增' then
  begin
    ConDate.DateTime := SGetServerDateTime(ADOTemp);
    DlyDate.DateTime := ConDate.DateTime;
    ConNo.Text := '自动生成';
    Sellname.Text := '陈丰';
    GetSell(SellName.Text);
  end;

  if PState = '复制' then
  begin

    PState := '新增';
    FMainId := '';
    ConDate.DateTime := SGetServerDateTime(ADOTemp);
    DlyDate.DateTime := ConDate.DateTime;
    YwyName.Text := Trim(DName);
    ConNo.Text := '自动生成';

    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('ConMainId').Value := '';
        FieldByName('ConSubId').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(trim(self.Caption), 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, 'CM', 'Contract_Main', 3, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
      if trim(ConNo.Text) = '自动生成' then
      begin
//        if GetLSNo(ADOCmd, fconNO, 'LH', 'Contract_Main', 2, 1) = False then
        if GetLSNo(ADOCmd, fconNO, 'CF', 'Contract_Main', 2, 1) = 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 := fconNO;
      end;
    end
    else
    begin
      maxno := Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from Contract_Main where conMainId=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
        FieldByName('Filler').Value := Trim(DName);
        FieldByName('FillCode').Value := Trim(DCode);
        FieldByName('FillTime').Value := SGetServerDateTime(ADOTemp);
        FieldByName('status').Value := '-1';
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditCode').Value := Trim(DCode);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
      end;
      FieldByName('ConMainId').Value := Trim(maxno);
      FieldByName('ConType').Value := '销售';
      FieldByName('TChuang').Value := '未查看';
      FieldByName('buyno').Value := BuyName.TxtCode;
      SSetsaveSqlNew(ADOCmd, 'Contract_Main', ScrollBox1, 2);
      Post;
    end;

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Contract_Main where ConNo=''' + Trim(ConNo.Text) + '''');
      Open;
    end;
    if ADOCmd.RecordCount > 1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('合同号重复!', '提示', 0);
      Exit;
    end;

    FMainId := Trim(maxno);
    ///保存子表

    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('ConSubId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxno, 'CS', 'Contract_Sub', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(Order_Sub.fieldbyname('ConSubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Contract_Sub where ConMainId=''' + Trim(FMainId) + '''');
          sql.Add(' and ConSubId=''' + Trim(maxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('ConSubId').AsString) = '' then
            Append
          else
            Edit;
          FieldByName('ConMainId').Value := Trim(FMainId);
          FieldByName('SFPaiZ').Value := '未排轴';
          FieldByName('SFKGyiDan').Value := '未开';
          FieldByName('ConSubId').Value := Trim(maxno);

          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'Contract_Sub', 0);
          Post;
        end;
        with ADOTemp do
        begin
          Close;
          SQL.Clear;
          sql.Add('UPDATE PD_Plan_sub SET P_CODE=''' + Trim(Order_Sub.FIELDBYNAME('P_Code').AsString) + '''');
          SQL.Add(',P_CODENAME=''' + Trim(Order_Sub.FIELDBYNAME('P_NAME').AsString) + '''');
          SQL.Add(',PiQty=''' + Trim(Order_Sub.FIELDBYNAME('PiQty').AsString) + '''');
          SQL.Add(',QTY=''' + Trim(Order_Sub.FIELDBYNAME('Qty').AsString) + '''');
          sql.Add(' WHERE  ConSubId=''' + Trim(maxno) + '''');

          sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
          sql.Add(' ' + quotedstr(trim(DName)));
          sql.Add(',getdate() ');
          sql.Add(',' + quotedstr(trim(self.Caption)));
          sql.Add(',' + quotedstr(trim('合同同步计划单')));
          sql.Add(',' + quotedstr(trim('合同ConSubId：' + trim(maxno) + '改为' + Trim(Order_Sub.FIELDBYNAME('P_Code').AsString) + Trim(Order_Sub.FIELDBYNAME('PiQty').AsString) + '匹' + Trim(Order_Sub.FIELDBYNAME('Qty').AsString) + 'M')));
          sql.Add(',' + quotedstr(trim('成功')));
          sql.Add(')');

          ExecSQL;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('ConSubId').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;

procedure TfrmConInPutNX.TBSaveClick(Sender: TObject);
begin
  ConDate.SetFocus;

  if TestData() = false then
    exit;

  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    Close;
    ModalResult := 1;
  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('SubDlyDate').Value := Trim(FormatDateTime('yyyy-MM-dd', DlyDate.DateTime));
    FieldByName('XHNO').Value := i;
    FieldByName('BZTYPE').Value := 'RMB';
    FieldByName('QtyUnit').Value := 'M';
    FieldByName('DDLX').Value := '新订单';
    Post;
  end;
end;

procedure TfrmConInPutNX.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from  PD_Plan_Sub B INNER JOIN PD_PLAN_MAIN A ON A.MAINID=B.MAINID where conSubId=''' + Trim(Order_Sub.fieldbyname('conSubId').AsString) + '''');
    SQL.Add('AND A.VALID=''Y''');
    open;
  end;
  if ADOTemp.IsEmpty = false then
  begin
    application.MessageBox('该明细已经在生产！', '提示信息');
    exit;
  end;
  if Trim(Order_Sub.fieldbyname('conSubId').AsString) <> '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Contract_Sub where conSubId=''' + Trim(Order_Sub.fieldbyname('conSubId').AsString) + '''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
end;

procedure TfrmConInPutNX.BuyNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
      if self.canshu1 = '业务员' then
        canshu1 := '业务员';
      if ShowModal = 1 then
      begin
        self.BuyName.TxtCode := Trim(CDS_HZ.fieldbyname('Code').AsString);
        self.BuyName.Text := Trim(CDS_HZ.fieldbyname('Name').AsString);
        self.BuyAddress.Text := Trim(CDS_HZ.fieldbyname('Address').AsString);
        self.BuyTel.Text := Trim(CDS_HZ.fieldbyname('Telephone').AsString);
        self.BuyFax.Text := Trim(CDS_HZ.fieldbyname('Fax').AsString);
        self.BuyBankNo.Text := Trim(CDS_HZ.fieldbyname('BankNo').AsString);
        self.BuyBankName.Text := Trim(CDS_HZ.fieldbyname('BankName').AsString);
        self.YwyName.Text := Trim(CDS_HZ.fieldbyname('YwyName').AsString);

      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

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

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

end;

procedure TfrmConInPutNX.v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'PriceUnit';
      flagname := '价格单位';
      if Trim(DParameters1) <> '高权限' then
      begin
        TBAdd.Visible := False;
        TBEdit.Visible := False;
        TBDel.Visible := False;
      end;
      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PriceUnit').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPutNX.v1Column4PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'MPRTCodeName';
      flagname := '产品名称';
      if ShowModal = 1 then
      begin
        Order_Sub.Edit;
        Order_Sub.fieldbyname('PRTCodeName').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Order_Sub.fieldbyname('PRTCode').Value := Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
        Order_Sub.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNX.v1Column6PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'MPRTMF';
      flagname := '门幅信息';
      if ShowModal = 1 then
      begin
        Order_Sub.Edit;
        Order_Sub.fieldbyname('PRTMF').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
     //   Order_Sub.fieldbyname('PRTCode').Value:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
        Order_Sub.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNX.v1Column7PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'MPRTKZ';
      flagname := '克重信息';
      if ShowModal = 1 then
      begin
        Order_Sub.Edit;
        Order_Sub.fieldbyname('PRTKZ').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
     //   Order_Sub.fieldbyname('PRTCode').Value:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
        Order_Sub.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNX.v1Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  MCYNo: string;
begin
  frmCPSel := TfrmCPSel.create(self);
  with frmCPSel do
  begin
    if showmodal = 1 then
    begin
      cds_main.DisableControls;
      cds_main.first;
      while not cds_main.Eof do
      begin
        if cds_main.FieldByName('ssel').AsBoolean then
        begin
          Order_Sub.Edit;
          MCYNo := CDS_Main.fieldbyname('CYNo').asstring;
          Order_Sub.fieldbyname('P_Code').Value := MCYNo;
          Order_Sub.fieldbyname('P_Name').Value := CDS_Main.fieldbyname('CYName').asstring;
          Order_Sub.fieldbyname('P_Spec').Value := CDS_Main.fieldbyname('CYSpec').asstring;
          Order_Sub.fieldbyname('P_CF').Value := CDS_Main.fieldbyname('CYCF').asstring;
          Order_Sub.fieldbyname('P_Color').Value := CDS_Main.fieldbyname('CYColor').asstring;
          Order_Sub.fieldbyname('P_HX').Value := CDS_Main.fieldbyname('CYHX').asstring;
          Order_Sub.fieldbyname('P_MF').Value := CDS_Main.fieldbyname('CYMF').asstring;
          Order_Sub.fieldbyname('P_KZ').Value := CDS_Main.fieldbyname('CYKZ').asstring;
          Order_Sub.Post;
        end;
        cds_main.next;
      end;
      cds_main.EnableControls;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutNX.DlyNoteBtnUpClick(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.ZLNoteDblClick(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(FieldByName('ZDYName').AsString)      //inttostr(i)+'.'+
            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.SellBankNoBtnUpClick(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);
      flag := 'SellBankNo';
      V1Name.Caption := '银行账户';
      V1Note.Caption := '开户行';
      fnote := True;
      if ShowModal = 1 then
      begin
        SellBankNo.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        SellBankName.Text := Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPutNX.SellNameBtnUpClick(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);
      flag := 'SellName';

      if ShowModal = 1 then
      begin
        SellName.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
    GetSell(SellName.Text);
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPutNX.v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FQuantity, FUnitPrice, FCourierCharge, FPiqty, Fmxmoney, Fpilen: double;
begin
  with Order_Sub do
  begin
    if TcxTextEdit(Sender).EditingText = '' then
    begin
      mvalue := '0';
    end
    else
      mvalue := TcxTextEdit(Sender).EditingText;
    FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  end;
  with Order_Sub do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
    FQuantity := FieldByName('Qty').asfloat;
    FUnitPrice := FieldByName('Price').asfloat;
    FPiqty := FieldByName('piQty').asfloat;
    Fpilen := FieldByName('pilen').asfloat;

  end;
  if (FFieldName = 'Qty') or (FFieldName = 'Price') then
  begin
    Fmxmoney := FQuantity * FUnitPrice;
  end
  else
  begin
    FQuantity := FPiqty * Fpilen;
    Fmxmoney := FQuantity * FUnitPrice;
  end;
  with Order_Sub do
  begin
    Edit;
    //if (FFieldName = 'PiQty') or (FFieldName = 'piLen') then

    FieldByName('Qty').Value := FQuantity;

    FieldByName('MxMoney').Value := Fmxmoney;
    Post;
  end;

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

procedure TfrmConInPutNX.v1PRTPricePropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FQuantity, FUnitPrice, FCourierCharge: double;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with Order_Sub do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;

    FQuantity := FieldByName('Qty').asfloat;
    FUnitPrice := FieldByName('Price').asfloat;
  end;

  with Order_Sub do
  begin
    Edit;
    FieldByName('MxMoney').Value := (FQuantity * FUnitPrice);
    Post;
  end;

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

procedure TfrmConInPutNX.TSBtnUpClick(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);
      fnote := True;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        TsNote.Text := Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmConInPutNX.v1Column10PropertiesEditValueChanged(Sender: TObject);
var
  mavlue, FFieldName: string;
begin
  mavlue := TcxTextEdit(Sender).EditingText;
  FFieldName := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_Sub do
  begin
    edit;
    FieldByName(FFieldName).Value := UpperCase(mavlue);
    post;
  end;

end;

function UpperCase(const S: string): string;
var
  Ch: Char;
  L: Integer;
  Source, Dest: PChar;
begin
  L := Length(S);
  SetLength(Result, L);
  Source := Pointer(S);
  Dest := Pointer(Result);
  while L <> 0 do
  begin
    Ch := Source^;
    if (Ch >= 'a') and (Ch <= 'z') then
      Dec(Ch, 32);
    Dest^ := Ch;
    Inc(Source);
    Inc(Dest);
    Dec(L);
  end;
end;

procedure TfrmConInPutNX.jiaohuodidianBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TbtnEditc(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
        TbtnEditc(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

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

end.

