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;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1PRTColor: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    v1PRTOrderQty: TcxGridDBColumn;
    Label9: TLabel;
    Label10: TLabel;
    Label14: TLabel;
    Label20: TLabel;
    BuyName: TBtnEditC;
    v1XHNo: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    Label6: TLabel;
    v1Column3: TcxGridDBColumn;
    CDS_Type: TClientDataSet;
    Label5: TLabel;
    Label31: TLabel;
    Label34: TLabel;
    BuyConNo: TEdit;
    v1Column2: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Salesman: TBtnEditC;
    Label39: TLabel;
    ZhiLiangNote: TMemo;
    ShouGanNote: TBtnEditC;
    PZFYNote: TMemo;
    Note: TMemo;
    v1Column8: TcxGridDBColumn;
    Sellname: TBtnEditC;
    Label2: TLabel;
    lidan: TBtnEditC;
    Label8: TLabel;
    JGFactoryName: TBtnEditC;
    Label41: TLabel;
    GDY: TBtnEditC;
    Label1: TLabel;
    ColorNote: TBtnEditC;
    Label11: TLabel;
    SLDNote: TBtnEditC;
    Label12: TLabel;
    RSSHNote: TBtnEditC;
    Label13: TLabel;
    NiuDuNote: TBtnEditC;
    Label15: TLabel;
    YuSuoNote: TBtnEditC;
    Label16: TLabel;
    GanMoNote: TBtnEditC;
    Label17: TLabel;
    QiQiuNote: TBtnEditC;
    Label18: TLabel;
    SuoShuiNote: TBtnEditC;
    Label19: TLabel;
    JiangBianNote: TBtnEditC;
    Label21: TLabel;
    ShiMoNote: TBtnEditC;
    Label22: TLabel;
    QtyNote: TBtnEditC;
    Label23: TLabel;
    QieBianNote: TBtnEditC;
    Label24: TLabel;
    ShaoMaoNote: TBtnEditC;
    Label25: TLabel;
    ChuMaoNote: TBtnEditC;
    Label26: TLabel;
    KePanNote: TBtnEditC;
    Label27: TLabel;
    fuguangyuan: TBtnEditC;
    Label7: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label32: TLabel;
    Label60: TLabel;
    SCMName: TEdit;
    SCMCF: TEdit;
    SCMMF: TEdit;
    SCMSpec: TEdit;
    SCMKZ: TEdit;
    v1Column1: TcxGridDBColumn;
    xgcs: TComboBox;
    Label33: TLabel;
    Label35: TLabel;
    SCMNDXS: TEdit;
    ConNo: TBtnEditA;
    SCMCode: TEdit;
    OrderDetail: TEdit;
    ToolButton3: TToolButton;
    QryCheckNet: TADOQuery;
    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 SalesmanBtnUpClick(Sender: TObject);
    procedure ZhiLiangNoteDblClick(Sender: TObject);
    procedure v1Column15PropertiesEditValueChanged(Sender: TObject);
    procedure SellNameBtnUpClick(Sender: TObject);
    procedure SCMCodeBtnUpClick(Sender: TObject);
    procedure JGFactoryNameBtnUpClick(Sender: TObject);
    procedure ConNoBtnClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    fuserName: string;
    procedure InitData();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    function TestData(): Boolean;
    function SaveData(): Boolean;
    function SelfConnData(): Boolean;
    { 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_ZdyAttachment, U_CPManageSel,
  U_ZdyAttachGYS, U_YCLViewSel, U_PhoneOrder;

{$R *.dfm}
function TfrmConInPutNX.SelfConnData(): Boolean;
begin
  try
    with QryCheckNet do
    begin
      Close;
      sql.Clear;
      //查询一个小表检测网络
      SQL.Add('select getdate()');
      Open;
    end;
    Result := true;
  except
//    if Application.MessageBox('是否重新连接网络！','提示',32+4)<>IDYES then  Exit;
    if not Assigned(DataLink_ContractManagement) then
      DataLink_ContractManagement := DataLink_ContractManagement.Create(Application);
    try
      with DataLink_ContractManagement.ADOLink do
      begin
        //if not Connected then
        begin
          Connected := false;
          ConnectionString := DConString;
          LoginPrompt := false;
          Connected := true;
        end;
      end;
      Result := true;
    except
      Result := false;
    end;
  end;
end;

function TfrmConInPutNX.TestData(): Boolean;
begin
  try
    if Trim(ConNo.Text) = '' then
      raise Exception.Create('合同号不能为空！');
//    if Trim(KHConNo.Text)='' then raise Exception.Create('客户合同号不能为空！');
//    if Trim(QtyNote.Text)='' then   raise Exception.Create('溢短装不能为空！');
//    if Trim(SellName.Text) = '' then
//      raise Exception.Create('供方不能为空！');
    if Trim(BuyName.Text) = '' then
      raise Exception.Create('需方不能为空！');
    if Trim(SCMCode.Text) = '' then
      raise Exception.Create('产品编号不能为空！');
    if Order_Sub.IsEmpty then
      raise Exception.Create('明细不能为空！');

    if Order_Sub.Locate('SCSColor', null, []) then
      raise Exception.Create('颜色不能为空！');
    if Order_Sub.Locate('SCSColor', '', []) then
      raise Exception.Create('颜色不能为空！');
//    if Order_Sub.Locate('SCSKX',null,[]) then raise Exception.Create('款型不能为空！');
//    if Order_Sub.Locate('SCSKX','',[]) then raise Exception.Create('款型不能为空！');
//    if Order_Sub.Locate('SCSMF', null, []) then
//      raise Exception.Create('门幅不能为空！');
//    if Order_Sub.Locate('SCSMF', '', []) then
//      raise Exception.Create('门幅不能为空！');
//    if Order_Sub.Locate('SCSKZ', null, []) then
//      raise Exception.Create('克重不能为空！');
//    if Order_Sub.Locate('SCSKZ', '', []) then
//      raise Exception.Create('克重不能为空！');
    if Order_Sub.Locate('SCSQty', null, []) then
      raise Exception.Create('数量不能为空！');
//    if Order_Sub.Locate('SCSQty', 0, []) then
//      raise Exception.Create('数量不能为0！');
    if Order_Sub.Locate('SCSUnit', null, []) then
      raise Exception.Create('数量单位不能为空！');
    if Order_Sub.Locate('SCSUnit', '', []) then
      raise Exception.Create('数量单位不能为空！');
//    if Order_Sub.Locate('SCSCurrency', null, []) then
//      raise Exception.Create('币种不能为空！');
//    if Order_Sub.Locate('SCSCurrency', '', []) 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, '销售合同管理');
end;

procedure TfrmConInPutNX.InitData();
begin
  //刷新产品信息
  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from SalesContract_Sub ');
    sql.Add('where MainId=''' + Trim(FMainId) + '''');
    sql.Add(' order by XHNo ');
    Open;
  end;
  SCreateCDS20(ADOTemp, Order_Sub);
  SInitCDSData20(ADOTemp, Order_Sub);
   //刷新条款信息
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* ');
    sql.Add(',OrderDetail=(select Top 1 OrderDetail  from PBOrder_Main B where B.OrderNo=A.ConNo and B.Valid=''Y'')');
    sql.Add(' from SalesContract_Main A where MainId=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCSHDataNew(ADOTemp, ScrollBox1, 2);
  OrderDetail.Text := Trim(ADOTemp.fieldbyname('OrderDetail').AsString);
  if PState = '新增' then
  begin
    OrdDate.DateTime := SGetServerDateTime(ADOTemp);
    DlyDate.DateTime := OrdDate.DateTime;
    DlyDate.Checked := False;
  end;

  if PState = '复制' then
  begin

    PState := '新增';
    FMainId := '';
    Salesman.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(trim(self.Caption), Tv1, '销售合同管理');    
  InitData();
end;

function TfrmConInPutNX.SaveData(): Boolean;
var
  maxno,maxsno: string;
  fconNO, fmxType: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOCmd, maxno, 'SCM', 'SalesContract_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 SalesContract_Main where MainId=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
        FieldByName('Filler').Value := Trim(DName);
        FieldByName('status').Value := '-1';
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
      end;
      FieldByName('MainId').Value := Trim(maxno);
      SSetsaveSqlNew(ADOCmd, 'SalesContract_Main', ScrollBox1, 2);
      FieldByName('SCMType').Value := '内销';
      Post;
    end;

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


    ///保存子表

    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxsno, 'SCS', 'SalesContract_Sub', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxsno := Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from SalesContract_Sub where MainId=''' + Trim(maxno) + '''');
          sql.Add(' and SubId=''' + Trim(maxsno) + '''');
          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(maxsno);
          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'SalesContract_Sub', 0);
          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;
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main where ConMainId=''' + Trim(maxno) + '''');
      Open;
    end;
    if ADOTemp.IsEmpty = False then
    begin
      if Trim(ADOTemp.fieldbyname('ConNo').AsString) <> Trim(ConNo.Text) then
      begin
        if Application.MessageBox('包装指示单已产生数据，点击是会同步订单号，确定要执行吗？', '', 32 + 4) <> IDYES then
        begin
          ADOCmd.Connection.RollbackTrans;
          Exit;
        end;
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update JYOrder_Main Set ConNo=''' + Trim(ConNo.Text) + '''');
          sql.Add(' where isnull(ConMainId,'''')=''' + Trim(maxno) + ''' and isnull(ConMainId,'''')<>''''');
          ExecSQL;
        end;
      end;                         
    end;
    ADOCmd.Connection.CommitTrans;

    Fmainid := Trim(maxno);
    with ADOTemp do                                             
    begin                                  
      Close;
      SQL.Clear;
      sql.Add(' select * from SalesContract_Sub ');
      sql.Add('where mainid=''' + Trim(FMainId) + '''');
      sql.Add(' order by subid ');
      Open;
    end;
    SCreateCDS20(ADOTemp, Order_Sub);
    SInitCDSData20(ADOTemp, Order_Sub);

    Result := True;
  except

    ADOCmd.Connection.RollbackTrans;
//    Application.MessageBox('保存失败！', '提示', 0);
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    Result := False;
  end;
end;

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

  if TestData() = false then
    exit;

  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 := i;
    FieldByName('SCSColor').Value := '';
    FieldByName('SCSpiQty').Value := 0;
    FieldByName('SCSQty').Value := 0;
    FieldByName('SCSCurrency').Value := 'RMB';
    FieldByName('huilv').Value := '1';

    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  JYOrder_Sub where isnull(conSubId,'''')<>'''' and conSubId=''' + Trim(Order_Sub.fieldbyname('SubId').AsString) + '''');
    open;
  end;
  if ADOTemp.IsEmpty = false then
  begin

    application.MessageBox('该明细已经在生产！', '提示信息');
    exit;
  end;
  if Trim(Order_Sub.fieldbyname('SubId').AsString) <> '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete SalesContract_Sub where SubId=''' + Trim(Order_Sub.fieldbyname('SubId').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('CoCode').AsString);
        self.BuyName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);

        self.Salesman.Text := Trim(CDS_HZ.fieldbyname('Salesman').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.SalesmanBtnUpClick(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.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(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.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;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPutNX.SCMCodeBtnUpClick(Sender: TObject);
begin
//  frmCPManageSel := TfrmCPManageSel.Create(self);
//  with frmCPManageSel do
//  begin
//    if showmodal = 1 then
//    begin
//      SCMCode.Text := CDS_Main.fieldbyname('CYNo').asstring;
//      SCMName.Text := CDS_Main.fieldbyname('CYName').asstring;
//      SCMSpec.Text := CDS_Main.fieldbyname('CYSpec').asstring;
//      SCMCF.Text := CDS_Main.fieldbyname('CYCF').asstring;
//      SCMMF.Text := CDS_Main.fieldbyname('CYmf').asstring;
//      SCMKZ.Text := CDS_Main.fieldbyname('CYkz').asstring;
//    end;
//    free;
//  end;
 { try
    frmYCLViewSel := TfrmYCLViewSel.Create(Application);
    with frmYCLViewSel do
    begin
      if ShowModal = 1 then
      begin
        SCMCode.Text := frmYCLViewSel.CDS_HZ.fieldbyname('SPCode').asstring;
        SCMName.Text := frmYCLViewSel.CDS_HZ.fieldbyname('SPName').asstring;
        SCMNDXS.Text := frmYCLViewSel.CDS_HZ.fieldbyname('SPXS').asstring;
//        MPRTSpec.Text := frmYCLViewSel.CDS_HZ.fieldbyname('SPSpec').asstring;
//      MPRTCF.Text := frmYCLViewSel.CDS_HZ.fieldbyname('CYCF').asstring;
//        MPRTMF.Text := frmYCLViewSel.CDS_HZ.fieldbyname('SPMF').asstring;
//        MPRTKZ.Text := frmYCLViewSel.CDS_HZ.fieldbyname('SPKZ').asstring;
      end;
    end;
  finally
    frmYCLViewSel.Free;
  end; }

end;

procedure TfrmConInPutNX.JGFactoryNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
//      frmZdyAttachGYS.FactType.ItemIndex:=FactType.Items.IndexOf('加工厂');

      if ShowModal = 1 then
      begin
        JGFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmConInPutNX.ConNoBtnClick(Sender: TObject);
begin
  try
    frmPhoneOrder := TfrmPhoneOrder.Create(Application);
    with frmPhoneOrder do
    begin
      if ShowModal = 1 then
      begin
        Self.SCMCode.Text := frmPhoneOrder.CDS_HZ.fieldbyname('SPCode').asstring;
        Self.SCMName.Text := frmPhoneOrder.CDS_HZ.fieldbyname('MPRTCodeName').asstring;
        Self.SCMNDXS.Text := frmPhoneOrder.CDS_HZ.fieldbyname('SPXS').asstring;
        Self.ConNo.Text := frmPhoneOrder.CDS_HZ.fieldbyname('OrderNo').asstring;
        Self.lidan.Text := frmPhoneOrder.CDS_HZ.fieldbyname('Filler').asstring;
        Self.OrderDetail.Text := frmPhoneOrder.CDS_HZ.fieldbyname('OrderDetail').asstring;
      end;
    end;
  finally
    frmPhoneOrder.Free;
  end;
end;

procedure TfrmConInPutNX.ToolButton3Click(Sender: TObject);
begin
  if SelfConnData() = false then
  begin
    Application.MessageBox('网络链接失败，请重新保存', '提示', 0);
    Exit;
  end;
end;

end.

