unit U_ConInPutWX;

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
  TfrmConInPutWX = 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;
    v1PRTOrderQty: TcxGridDBColumn;
    Label9: TLabel;
    Label10: TLabel;
    ConNo: TEdit;
    Label14: TLabel;
    Label20: TLabel;
    FromPlace: TBtnEditC;
    BuyName: TBtnEditC;
    v1XHNo: TcxGridDBColumn;
    SellName: TBtnEditC;
    v1OrderUnit: TcxGridDBColumn;
    Label6: TLabel;
    Label15: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    SellBankNo: TBtnEditC;
    SellAddress: TEdit;
    Label19: TLabel;
    SellBankName: TEdit;
    Label21: TLabel;
    BuyAddress: TEdit;
    v1Column3: TcxGridDBColumn;
    Label8: TLabel;
    SellTel: TEdit;
    Label23: TLabel;
    SellFax: TEdit;
    CDS_Type: TClientDataSet;
    Label5: TLabel;
    Label16: 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;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Salesman: TBtnEditC;
    Label38: TLabel;
    Label39: TLabel;
    ZhiLiangNote: TMemo;
    QtyNote: TBtnEditC;
    PZFYNote: TMemo;
    ChuanYangNote: TMemo;
    YSBiaoZhunNote: TMemo;
    Payment: TMemo;
    YiYiNote: TMemo;
    Note: TMemo;
    v1Column1: TcxGridDBColumn;
    BuyBankNo: TEdit;
    v1Column8: TcxGridDBColumn;
    Label1: TLabel;
    DlyNote: TBtnEditC;
    Label2: TLabel;
    DlyPlace: TBtnEditC;
    v1Column9: TcxGridDBColumn;
    Label11: TLabel;
    Port: TBtnEditC;
    Label12: TLabel;
    ToPort: TBtnEditC;
    Label13: TLabel;
    FKType: TComboBox;
    Label25: TLabel;
    YJ: TBtnEditC;
    v1Column13: TcxGridDBColumn;
    Label26: TLabel;
    Label27: TLabel;
    FKQX: TBtnEditC;
    TS: TBtnEditC;
    TsNote: 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 SalesmanBtnUpClick(Sender: TObject);
    procedure ZhiLiangNoteDblClick(Sender: TObject);
    procedure v1Column15PropertiesEditValueChanged(Sender: TObject);
    procedure SellBankNoBtnUpClick(Sender: TObject);
    procedure SellNameBtnUpClick(Sender: TObject);
    procedure PortBtnUpClick(Sender: TObject);
    procedure ToPortBtnUpClick(Sender: TObject);
    procedure YJBtnUpClick(Sender: TObject);
    procedure DlyNoteBtnUpClick(Sender: TObject);
    procedure FKQXBtnUpClick(Sender: TObject);
    procedure TSBtnUpClick(Sender: TObject);
    procedure v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure v1Column8PropertiesEditValueChanged(Sender: TObject);
  private
    fuserName: string;
    procedure InitData();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    procedure GetSell(MSellName: string);
    function TestData(): Boolean;
    function SaveData(): Boolean;
    { Private declarations }
  public
    CopyInt: Integer;
    PState: string;
    FMainId, FFMainId: string;
    canshu1: string;
    { Public declarations }
  end;

var
  frmConInPutWX: TfrmConInPutWX;
  newh: hwnd;

implementation

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

{$R *.dfm}
procedure TfrmConInPutWX.GetSell(MSellName: string);
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select top 1 A.* ');
    sql.Add(' from SalesContract_Main A  ');
    SQL.Add('where  A.SCMType=''外销'' and A.SellName=' + quotedstr(trim(MSellName)));
    sql.Add(' order by  A.OrdDate desc ');
    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 TfrmConInPutWX.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 Order_Sub.IsEmpty then
      raise Exception.Create('明细不能为空！');
    if Order_Sub.Locate('SCSCode', null, []) then
      raise Exception.Create('产品编号不能为空！');
    if Order_Sub.Locate('SCSCode', '', []) then
      raise Exception.Create('产品编号不能为空！');
    if Order_Sub.Locate('SCSName', null, []) then
      raise Exception.Create('品名不能为空！');
    if Order_Sub.Locate('SCSName', '', []) 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 TfrmConInPutWX.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(trim(self.Caption), Tv1, '销售合同管理');
end;

procedure TfrmConInPutWX.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 * from SalesContract_Main where MainId=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCSHDataNew(ADOTemp, ScrollBox1, 2);
  BuyName.TxtCode :=ADOTemp.FieldByName('buyno').AsString ;
  if PState = '新增' then
  begin
    OrdDate.DateTime := SGetServerDateTime(ADOTemp);
    DlyDate.DateTime := OrdDate.DateTime;
    ConNo.Text := '自动生成';

  end;

  if PState = '复制' then
  begin

    PState := '新增';
    FMainId := '';
    OrdDate.DateTime := SGetServerDateTime(ADOTemp);
    DlyDate.DateTime := OrdDate.DateTime;
    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 TfrmConInPutWX.ZDYHelp(FButn: TcxButtonEdit; LType: string);
var
  FType, ZDYName, FText: string;
begin
end;

procedure TfrmConInPutWX.FormShow(Sender: TObject);
begin
  readCxGrid(trim(self.Caption), Tv1, '销售合同管理');
  InitData();
end;

function TfrmConInPutWX.SaveData(): Boolean;
var
  maxno: 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;
      if trim(ConNo.Text) = '自动生成' then
      begin
        if GetLSNo(ADOCmd, fconNO, 'LH', 'SalesContract_Main', 2, 1) = False then
        begin
          ADOCmd.Connection.RollbackTrans;
          Application.MessageBox('取最合同编号失败!', '提示', 0);
          Exit;
        end;
        ConNo.Text := fconNO;
      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 := '外销';
      FieldByName('buyno').Value := BuyName.TxtCode;
      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;

    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, 'SCS', 'SalesContract_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 SalesContract_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, '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;

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

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

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

  if TestData() = false then
    exit;

  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
  end;
end;

procedure TfrmConInPutWX.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 TfrmConInPutWX.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('SCSColor').Value := '';
    FieldByName('SCSQty').Value := null;
    FieldByName('SCSCurrency').Value := 'USD';
    FieldByName('huilv').Value := 1;

    Post;
  end;
end;

procedure TfrmConInPutWX.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from  JYOrder_sub where conSubId=''' + Trim(Order_Sub.fieldbyname('SubId').AsString) + '''');
    open;
  end;
  if ADOTemp.IsEmpty = false then
  begin
    exit;
    application.MessageBox('该明细已经在生产！', '提示信息');
  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 TfrmConInPutWX.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.BuyAddress.Text := Trim(CDS_HZ.fieldbyname('CoAddress').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.Salesman.Text := Trim(CDS_HZ.fieldbyname('Salesman').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

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

procedure TfrmConInPutWX.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 TfrmConInPutWX.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 TfrmConInPutWX.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 TfrmConInPutWX.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 TfrmConInPutWX.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 TfrmConInPutWX.v1Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  MCYNo: string;
begin
  frmCPManage := TfrmCPManage.create(self);
  with frmCPManage 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('SCSCode').Value := MCYNo;
          Order_Sub.fieldbyname('SCSName').Value := CDS_Main.fieldbyname('CYName').asstring;
          Order_Sub.fieldbyname('SCSSpec').Value := CDS_Main.fieldbyname('CYSpec').asstring;
          Order_Sub.fieldbyname('SCSCF').Value := CDS_Main.fieldbyname('CYCF').asstring;
          Order_Sub.fieldbyname('SCSColor').Value := CDS_Main.fieldbyname('CYColor').asstring;
          Order_Sub.fieldbyname('SCSHX').Value := CDS_Main.fieldbyname('CYHX').asstring;
          Order_Sub.fieldbyname('SCSMF').Value := CDS_Main.fieldbyname('CYMF').asstring;
          Order_Sub.fieldbyname('SCSKZ').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 TfrmConInPutWX.SalesmanBtnUpClick(Sender: TObject);
var
  fsj,FFKType: 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 TfrmConInPutWX.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 TfrmConInPutWX.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 TfrmConInPutWX.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 TfrmConInPutWX.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);
      if ShowModal = 1 then
      begin
        SellName.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
    GetSell(SellName.Text);

  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPutWX.PortBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'gangkou';
      flagname := '港口';
      if ShowModal = 1 then
      begin

        Port.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

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

procedure TfrmConInPutWX.ToPortBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'mubiaogangkou';
      flagname := '目标港口';
      if ShowModal = 1 then
      begin

        ToPort.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

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

procedure TfrmConInPutWX.YJBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'yongjin';
      flagname := '佣金';
      if ShowModal = 1 then
      begin

        YJ.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

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

procedure TfrmConInPutWX.DlyNoteBtnUpClick(Sender: TObject);
var
  fsj,FFKType: string;
  FWZ: Integer;
begin

  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'WDlyNote'+FKType.Text;
      flagname := '交期说明';
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;
procedure TfrmConInPutWX.FKQXBtnUpClick(Sender: TObject);
var
  fsj,FFKType: string;
  FWZ: Integer;
begin

  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'FKQX'+FKType.Text;
      flagname := '付款期限';
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmConInPutWX.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 TfrmConInPutWX.v1PRTOrderQtyPropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue, FFieldName: string;
  FQty, FPrice, FMxMoney: double;
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 := Trim(mvalue);
    Post;
  end;
  with Order_Sub do
  begin
    Edit;
    FQty := FieldByName('SCSQty').AsFloat;
    FPrice := FieldByName('SCSPrice').AsFloat;
    Post;
  end;
  FMxMoney := strtofloat(format('%.2f', [FQty * FPrice]));
  with Order_Sub do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    FieldbyName('SCSMxMoney').Value := FMxMoney;
    Post;
  end;
  tv1.Controller.EditingController.ShowEdit();
 // HJJE();
end;

procedure TfrmConInPutWX.v1Column8PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue, FFieldName: string;
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 := Trim(mvalue);
    Post;
  end;
  tv1.Controller.EditingController.ShowEdit();
 // HJJE();
end;

end.

