unit U_ConInPutCG;

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;

type
  TfrmConInPutCG = 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;
    Label6: TLabel;
    Label15: TLabel;
    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;
    Label16: TLabel;
    Label28: TLabel;
    Label22: TLabel;
    Label24: TLabel;
    BuyTel: TEdit;
    BuyFax: TEdit;
    Label31: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    BuyBankName: TEdit;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    YwyName: TBtnEditC;
    Label38: TLabel;
    Label39: TLabel;
    ZLNote: TMemo;
    QtyNote: TBtnEditC;
    PZFYNote: TMemo;
    CYNote: TMemo;
    YSBZNote: TMemo;
    Payment: TMemo;
    YYNote: TMemo;
    Note: TMemo;
    v1Column1: TcxGridDBColumn;
    BuyBankNo: TEdit;
    Label1: TLabel;
    JHNote: TMemo;
    Label2: TLabel;
    hlshNote: TMemo;
    Label11: TLabel;
    jsfsNote: TMemo;
    Label12: TLabel;
    wyzrNote: TMemo;
    v1Column19: TcxGridDBColumn;
    ToolButton3: TToolButton;
    Label25: TLabel;
    TsNote: TEdit;
    BuyName: TBtnEditC;
    SellName: TBtnEditC;
    v1Column3: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    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 YwyNameBtnUpClick(Sender: TObject);
    procedure ZLNoteDblClick(Sender: TObject);
    procedure v1Column15PropertiesEditValueChanged(Sender: TObject);
    procedure SellBankNoBtnUpClick(Sender: TObject);
    procedure SellNameBtnUpClick(Sender: TObject);
    procedure v1Column18PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure v1Column19PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure TSBtnUpClick(Sender: TObject);
  private
    fuserName: string;
    procedure InitData();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    procedure GetSell(MSellName: string);
    function TestData(): Boolean;
    function SaveData(): Boolean;
//    procedure HJJE();
    { Private declarations }
  public
    CopyInt: Integer;
    PState: string;
    FMainId, FFMainId: string;
    canshu1, FGSTT: string;
    { Public declarations }
  end;

var
  frmConInPutCG: TfrmConInPutCG;
  newh: hwnd;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ZDYHelpSel, U_CPManageFMSel, U_ZdyAttachment,
  U_FactoryGYS, U_SCJHOrderList, U_CPSel;

{$R *.dfm}

//procedure TfrmConInPutCG.HJJE();
//var
//  FMoney, FHuiLv, FBBMoney: double;
//begin
//  if TV1.DataController.Summary.FooterSummaryValues[1] <> NULL then
//    FMoney := TV1.DataController.Summary.FooterSummaryValues[1]
//  else
//    FMoney := 0;
//
//  FHuiLv := strtofloat(HuiLv.Text);
//  if FHuiLv = 0 then
//    FHuiLv := 1;
//  FBBMoney := FHuiLv * FMoney;
//  Money.Text := floattostr(FMoney);
//  HuiLv.Text := floattostr(FHuiLv);
//  BBMoney.Text := floattostr(FBBMoney);
//end;

procedure TfrmConInPutCG.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;
  BuyAddress.Text := trim(ADOTemp.FieldByName('SellAddress').AsString);
  BuyTel.Text := trim(ADOTemp.FieldByName('SellTel').AsString);
  BuyBankNo.Text := trim(ADOTemp.FieldByName('SellBankNo').AsString);
  BuyBankName.Text := trim(ADOTemp.FieldByName('SellBankName').AsString);
  BuyFax.Text := trim(ADOTemp.FieldByName('SellFax').AsString);
  SellName.Text := trim(MSellName);
end;

function TfrmConInPutCG.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('P_Code', null, []) then
//      raise Exception.Create('产品编号不能为空！');
//    if Order_Sub.Locate('P_Code', '', []) then
//      raise Exception.Create('产品编号不能为空！');
    if Order_Sub.Locate('P_Name', null, []) then
      raise Exception.Create('品名不能为空！');
    if Order_Sub.Locate('P_Name', '', []) 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('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 TfrmConInPutCG.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(trim(self.Caption), Tv1, '销售合同管理');
end;

procedure TfrmConInPutCG.InitData();
begin
  //刷新产品信息
  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from Contract_Sub ');
    sql.Add('where ConMainId=''' + 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 Contract_Main where ConMainId=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCSHDataNew(ADOTemp, ScrollBox1, 2);

  if PState = '新增' then
  begin
    ConDate.DateTime := SGetServerDateTime(ADOTemp);
    DlyDate.DateTime := ConDate.DateTime;
    ConNo.Text := '自动生成';
    GetSell(FGSTT);
  end;

  if PState = '复制' then
  begin

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

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

  InitData();
  SellName.Text := '庞涛';
end;

function TfrmConInPutCG.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
        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);
      SSetsaveSqlNew(ADOCmd, 'Contract_Main', ScrollBox1, 2);
      FieldByName('ConType').Value := '采购';
      FieldByName('buyno').Value := BuyName.TxtCode;
      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('ConSubId').Value := Trim(maxno);
          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'Contract_Sub', 0);
//          fieldbyname('huilv').Value := Order_Sub.fieldbyname('huilv').AsFloat;
          Post;
        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 TfrmConInPutCG.TBSaveClick(Sender: TObject);
begin
  ConDate.SetFocus;

  if TestData() = false then
    exit;

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

procedure TfrmConInPutCG.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('SCSColor').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 TfrmConInPutCG.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('Qty').Value := null;
    FieldByName('BZType').Value := 'RMB';
    FieldByName('QtyUnit').Value := 'Kg';
    Post;
  end;
end;

procedure TfrmConInPutCG.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from  Contract_Sub where conSubId=''' + Trim(Order_Sub.fieldbyname('conSubId').AsString) + '''');
    open;
  end;
  if ADOTemp.IsEmpty = false then
  begin
    exit;
    application.MessageBox('该明细已经在生产！', '提示信息');
  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 TfrmConInPutCG.BuyNameBtnUpClick(Sender: TObject);
begin
  try
    frmFactoryGYS := TfrmFactoryGYS.Create(Application);
    with frmFactoryGYS 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.SellAddress.Text := Trim(CDS_HZ.fieldbyname('Address').AsString);
        self.SellTel.Text := Trim(CDS_LXR.fieldbyname('Telephone').AsString);
        self.SellFax.Text := Trim(CDS_LXR.fieldbyname('Fax').AsString);
//        self.BuyBankNo.Text := Trim(CDS_LXR.fieldbyname('BankNo').AsString);
//        self.BuyBankName.Text := Trim(CDS_LXR.fieldbyname('BankName').AsString);

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

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

procedure TfrmConInPutCG.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 TfrmConInPutCG.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 TfrmConInPutCG.v1Column4PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'SXYCLName';
      flagname := '纱线名称';
      if ShowModal = 1 then
      begin
        with Self.Order_Sub do
        begin
          Edit;
          FieldByName('P_Name').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPutCG.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('P_MF').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 TfrmConInPutCG.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('P_KZ').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 TfrmConInPutCG.v1Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  MCYNo: string;
begin
  frmCPSel := TfrmCPSel.Create(self);
  with frmCPSel do
  begin
    if showmodal = 1 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;
    free;
  end;

  with ADOTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select top 1 P_EName from Contract_Sub where P_Code=' + quotedstr(trim(MCYNo)));
    sql.Add(' order by Consubid desc');
    open;
    Order_Sub.Edit;
    Order_Sub.fieldbyname('P_EName').Value := ADOTemp.Fieldbyname('P_EName').asstring;
    Order_Sub.Post;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutCG.YwyNameBtnUpClick(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 TfrmConInPutCG.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 TfrmConInPutCG.v1Column15PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FYuE, Ffkje, 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;
    FMxMoney := FieldByName('SCSMxMoney').AsFloat;
    Ffkje := FieldByName('fkje').AsFloat;
    Post;
  end;
  FYuE := strtofloat(format('%.2f', [FMxMoney - Ffkje]));
  with Order_Sub do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    FieldbyName('yue').Value := FYuE;
    Post;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmConInPutCG.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 TfrmConInPutCG.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 TfrmConInPutCG.v1Column18PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'MPRTTtou';
      flagname := '抬头信息';
      if ShowModal = 1 then
      begin
        Order_Sub.Edit;
        Order_Sub.fieldbyname('SCSCGTtou').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 TfrmConInPutCG.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('Qty').AsFloat;
    FPrice := FieldByName('Price').AsFloat;
    Post;
  end;
  FMxMoney := strtofloat(format('%.2f', [FQty * FPrice]));
  with Order_Sub do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    FieldbyName('MxMoney').Value := FMxMoney;
    Post;
  end;
  tv1.Controller.EditingController.ShowEdit();
 // HJJE();
end;

procedure TfrmConInPutCG.v1Column19PropertiesEditValueChanged(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;

procedure TfrmConInPutCG.ToolButton3Click(Sender: TObject);
var
  i: Integer;
  S: string;
begin
  try
    frmProductOrderList := TfrmSCJHOrderList.Create(Application);
    with frmProductOrderList do
    begin
      if ShowModal = 1 then
      begin

        with frmProductOrderList.ADOQuerySub do
        begin

          i := Order_Sub.RecordCount;
          i := i + 1;
          with Self.Order_Sub do
          begin
            Append;
            FieldByName('XHNO').Value := i;
            S := Trim(frmProductOrderList.Order_Main.fieldbyname('MPRTCode').AsString);
            S[3] := '0';
            S[4] := '1';

            with Self.ADOCmd do
            begin
              close;
              sql.Clear;
              sql.Add('select A.* from CP_YDang A ');
              sql.Add('where CYNo =' + quotedstr(S));
                      //ShowMessage(SQL.Text);
              open;
            end;

            FieldByName('SCSCode').Value := Trim(Self.ADOCmd.fieldbyname('CYNo').AsString);
            FieldByName('SCSName').Value := Trim(Self.ADOCmd.fieldbyname('CYTypeName').AsString);
            FieldByName('SCSSpec').Value := Trim(Self.ADOCmd.fieldbyname('CYSpec').AsString);
            FieldByName('SCSMF').Value := Trim(Self.ADOCmd.fieldbyname('CYMF').AsString);
            FieldByName('SCSKZ').Value := Trim(Self.ADOCmd.fieldbyname('CYKZ').AsString);
            FieldByName('SCSColor').Value := Trim(Self.ADOCmd.fieldbyname('CYColor').AsString);
            FieldByName('SCSCurrency').Value := 'RMB';

            Post;
          end;
          next;

        end;
      end;
    end;
  finally
    frmProductOrderList.Free
  end;
end;

procedure TfrmConInPutCG.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;

end.

