unit U_Contract_Sub;

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, cxDropDownEdit;

type
  TfrmContract_Sub = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    ConNo: TEdit;
    Label4: TLabel;
    DeliveryDate: TDateTimePicker;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1PRTSpec: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1C_Qty: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    DataSource2: TDataSource;
    ADOZDY: TADOQuery;
    CDS_ZDY: TClientDataSet;
    ADOQuery1: TADOQuery;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    Label2: TLabel;
    QDTime: TDateTimePicker;
    Label3: TLabel;
    CompanyName: TcxButtonEdit;
    Label6: TLabel;
    QDPalce: TEdit;
    Label8: TLabel;
    JHPlace: TcxButtonEdit;
    factoryNoName: TcxButtonEdit;
    Label10: TLabel;
    ConTK3: TcxButtonEdit;
    Label11: TLabel;
    ConTK4: TcxButtonEdit;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Qty2: TcxGridDBColumn;
    v1Price: TcxGridDBColumn;
    Label7: TLabel;
    Label9: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    ConTK5: TMemo;
    ConTk6: TMemo;
    v1C_Color: TcxGridDBColumn;
    v1Sdefstr1: TcxGridDBColumn;
    v1MainUnit: TcxGridDBColumn;
    v1JGMoney: TcxGridDBColumn;
    OrderNo: TcxButtonEdit;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PRTUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure v1Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PRTMFPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1OrderQtyPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1ClothQtyPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column2PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FactoryNoNamePropertiesChange(Sender: TObject);
    procedure CompanyNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure JHPlacePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ConTK3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ConTK4PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ConTK5PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ConTk6PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ConTk2PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column7PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column10PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FormCreate(Sender: TObject);
    procedure ConTk6Click(Sender: TObject);
    procedure ConTK5Click(Sender: TObject);
    procedure v1C_QtyPropertiesEditValueChanged(Sender: TObject);
    procedure v1Qty3PropertiesEditValueChanged(Sender: TObject);
    procedure v1JGMoneyPropertiesEditValueChanged(Sender: TObject);
    procedure OrderNoPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    FXS:Integer;
    procedure InitData();
    procedure ZDYHelp(FButn:TcxButtonEdit;LType:string);
    function  SaveData():Boolean;
    { Private declarations }
  public
    PState,PCopyInt:Integer;
    FMainId,FConNo:String;
    { Public declarations }
  end;

var
  frmContract_Sub: TfrmContract_Sub;

implementation
uses
  U_DataLink,U_ZDYHelp,U_Fun, U_ProductOrder_CX, U_ZDYHelpSel;

{$R *.dfm}

procedure TfrmContract_Sub.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmContract_Sub.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' exec ClothContract_QryList :MainId,:WSql');
    if PState=1 then
    begin
      ADOQuery1.Parameters.ParamByName('MainId').Value:=Trim(FMainId);
      ADOQuery1.Parameters.ParamByName('WSQl').Value:='';
    end;
    if PState=0 then
    begin
      ADOQuery1.Parameters.ParamByName('MainId').Value:=Trim(FMainId);
      ADOQuery1.Parameters.ParamByName('WSql').Value:=' and 1<>1 ';
    end;
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);
  SCSHData(ADOQuery1,ScrollBox1,0);
  if PState=0 then
  begin
    with ADOTemp do
    begin
      Close;
      SQL.Clear;
      sql.Add('select Top 1* from Contract_Main order by FillTime desc ');
      Open;
    end;
    QDTime.DateTime:=SGetServerDate(ADOTemp);
    DeliveryDate.DateTime:=SGetServerDate(ADOTemp);
  end;
end;

procedure TfrmContract_Sub.ZDYHelp(FButn:TcxButtonEdit;LType:string);
begin

end;

procedure TfrmContract_Sub.FormShow(Sender: TObject);
begin
  InitData();
end;

function TfrmContract_Sub.SaveData():Boolean;
var
  maxno,maxSubNo:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
        if Trim(FMainId)='' then
        begin
          if GetLSNo(ADOCmd,maxno,'JG','Contract_Main',2,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 Contract_Main where MainId='''+Trim(FMainId)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
          begin
            Append;

          end
          else begin

            Edit;
          end;
          FieldByName('MainId').Value:=Trim(maxno);
          FieldByName('HTType').Value:='加工合同';
          SSetsaveSql(ADOCmd,'Contract_Main',ScrollBox1,0);
          if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
          begin
            FieldByName('Filler').Value:=Trim(DName);
          end else
          begin
            FieldByName('Editer').Value:=Trim(DName);
            FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
          end;
          FieldByName('FactoryNoName').Value:=Trim(factoryNoName.Text);
          Post;
        end;

    with Order_Sub do
    begin
      First;
      while not Eof do
      begin

    ///保存子表

        if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
        begin
          if GetLSNo(ADOCmd,maxSubNo,'HT','Contract_Sub',3,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxSubNo:=Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Contract_Sub where MainId='''+Trim(maxno)+'''');
          sql.Add(' and SubId='''+Trim(maxSubNo)+'''');
          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(maxSubNo);
          SSetSaveDataCDSNew(ADOCmd,Tv1,Order_Sub,'Contract_Sub',0);
          FieldByName('MFQty').Value:=Order_Sub.fieldbyname('MFQty').AsFloat;
          FieldByName('C_Qty').Value:=Order_Sub.fieldbyname('C_Qty').AsFloat;
          FieldByName('KZQty').Value:=Order_Sub.fieldbyname('KZQty').AsFloat;
          FieldByName('C_Qty').Value:=Order_Sub.fieldbyname('C_Qty').AsFloat;
          FieldByName('Qty1').Value:=Order_Sub.fieldbyname('Qty1').AsFloat;
          FieldByName('Price').Value:=Order_Sub.fieldbyname('Price').AsFloat;
          FieldByName('JGMoney').Value:=Order_Sub.fieldbyname('JGMoney').AsFloat;
          FieldByName('C_Note').Value:=trim(Order_Sub.fieldbyname('C_Note').AsString);
          FieldByName('C_status').Value:='0';
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value:=Trim(maxSubNo);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmContract_Sub.TBSaveClick(Sender: TObject);
begin
  DeliveryDate.SetFocus;
  if Trim(ConNo.Text)='' then
  begin
    Application.MessageBox('合同编号不能为空！','提示',0);
    Exit;
  end;
  if Trim(factoryNoName.Text)='' then
  begin
    Application.MessageBox('加工厂不能为空！','提示',0);
    Exit;
  end;
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空！','提示',0);
    exit;
  end;
  if Order_Sub.Locate('C_Qty',null,[]) then
  begin
    Application.MessageBox('加工数量不能为空!','提示',0);
    Exit;
  end;
  if Order_Sub.Locate('C_Unit',null,[]) then
  begin
    Application.MessageBox('加工数量单位不能为空!','提示',0);
    Exit;
  end;

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

procedure TfrmContract_Sub.v1OrderUnitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdUnit';
      flagname:='单位';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('OrderUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.v1PRTUnitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdUnit';
      flagname:='单位';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PRTUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.v1PRTColorPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdColor';
      flagname:='颜色';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PRTColor').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.ToolButton1Click(Sender: TObject);
begin
  with Order_Sub do
  begin
    Append;
    Post;
  end;
end;

procedure TfrmContract_Sub.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  if Trim(Order_Sub.fieldbyname('SubId').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Contract_Sub where SubId='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
end;

procedure TfrmContract_Sub.v1Column1PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='Cloth';
      flagname:='坯布名称';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('C_CodeName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.Order_Sub.FieldByName('C_Code').Value:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.v1PRTMFPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='KZ';
      flagname:='克重单位';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('KZUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.v1OrderQtyPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MF';
      flagname:='门幅单位';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('MFUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.v1ClothQtyPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PriceUnit';
      flagname:='计价单位';
      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 TfrmContract_Sub.v1Column2PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrderUnit';
      flagname:='单位';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('C_Unit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.FactoryNoNamePropertiesChange(
  Sender: TObject);
begin
  {if FXS=99 then
  begin
    PanZDY.Visible:=False;
    FXS:=0;
    Exit;
  end;
  ZDYHelp(FactoryNoName,'FactoryNo1Name');  }
end;

procedure TfrmContract_Sub.CompanyNamePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdDefStr2';
      flagname:='抬头';
      if ShowModal=1 then
      begin
        FXS:=99;
        CompanyName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.JHPlacePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='JHPlace';
      flagname:='交货地点';
      if ShowModal=1 then
      begin
        JHPlace.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.ConTK3PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ConTK3';
      flagname:='包装要求';
      if ShowModal=1 then
      begin
        ConTK3.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.ConTK4PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ConTK4';
      flagname:='结算方式';
      if ShowModal=1 then
      begin
        ConTK4.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.ConTK5PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ConTK5';
      flagname:='验收标准、方法及提出异议期限';
      if ShowModal=1 then
      begin
        ConTK5.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.ConTk6PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ConTK6';
      flagname:='其它约定事项';
      if ShowModal=1 then
      begin
        ConTK6.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.ConTk2PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='Factory';
      flagname:='供方';
      MainType:='PBFactory';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          factoryNoName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
          FieldByName('factoryNoname').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.v1Column7PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  if Trim(FMainId)<>'' then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YF_Money_CR A where exists(');
      sql.Add('select * from Contract_Sub_MX B inner join Contract_Sub C on B.SubId=C.SubId ');
      sql.Add(' where C.Mainid='''+Trim(FMainId)+'''');
      sql.Add(' and B.MXID=A.YFTypeId)');
      Open;
    end;
    if ADOTemp.IsEmpty=False then
    begin
      Application.MessageBox('已经产生应付款不能修改供应商!','提示',0);
      Exit;
    end;
  end;

  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='Factory';
      flagname:='供方';
      MainType:='PBFactory';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('FactoryNoName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.v1Column10PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
   try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='Factory';
      flagname:='染厂';
      MainType:='PBFactory';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('Sdefstr2').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContract_Sub.FormCreate(Sender: TObject);
begin
  cxGrid1.Align:=alclient;
end;

procedure TfrmContract_Sub.ConTk6Click(Sender: TObject);
VAR i: integer;
begin
  i:=0;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='QTYDSX';
      flagname:='其他约定事项';
      if ShowModal=1 then
      begin
        ConTK6.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              i:=i+1;
              ConTK6.Lines.Add(inttostr(i)+'.'+FieldByName('ZDYName').AsString);
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmContract_Sub.ConTK5Click(Sender: TObject);
VAR i: integer;
begin
  i:=0;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='JGYQ';
      flagname:='其他约定事项';
      if ShowModal=1 then
      begin
        ConTK5.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              i:=i+1;
              ConTK5.Lines.Add(inttostr(i)+'.'+FieldByName('ZDYName').AsString);
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmContract_Sub.v1C_QtyPropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
begin
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_sub do
  begin
    edit;
    fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;
    FieldByName('JGMoney').Value:=strtofloat(format('%.2f',[Fieldbyname('C_Qty').AsFloat*Fieldbyname('Price').AsFloat ]));
    post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmContract_Sub.v1Qty3PropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
begin
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_sub do
  begin
    edit;
    fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;
    FieldByName('JGMoney').Value:=strtofloat(format('%.2f',[Fieldbyname('Price').AsFloat*Fieldbyname('C_Qty').AsFloat ]));
    post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;


procedure TfrmContract_Sub.v1JGMoneyPropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
begin
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_sub do
  begin
    edit;
    fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;
    if Fieldbyname('C_Qty').AsFloat<>0 then
    begin
      FieldByName('Price').Value:=strtofloat(format('%.2f',[Fieldbyname('JGMoney').AsFloat/Fieldbyname('C_Qty').AsFloat]));
    end;
    post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmContract_Sub.OrderNoPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
var FOrderNo: String;
begin
  FrmProductOrder_CX:=TFrmProductOrder_CX.Create(self);
  with FrmProductOrder_CX do
  begin
    if showModal=1 then
    begin
      self.ConNo.Text:=trim(Order_Main.fieldbyname('ConNo').AsString);
      self.OrderNo.Text:=trim(Order_Main.fieldbyname('OrderNo').AsString);
      self.CompanyName.Text:=trim(Order_Main.fieldbyname('SYRName').AsString);
      self.ConTK3.Text:=trim(Order_Main.fieldbyname('MPRTBZNote').AsString);
      with Order_Main do
      begin
        first;
        ForderNo:='';
        while not Eof do
        begin
          if fieldbyname('Ssel').AsBoolean then
          begin
            if FOrderNo='' then
            begin
              FOrderNo:=trim(fieldbyname('OrderNo').AsString);
            end
            else
            begin
              if FOrderNo<>trim(fieldbyname('OrderNo').AsString) then
              begin
                application.MessageBox('订单号不一致','提示',0);
                exit;
              end;
            end;
            Order_Sub.Append;
            Order_Sub.FieldByName('C_CodeName').AsString:=trim(fieldbyname('MPRTCodeName').AsString);
            Order_Sub.FieldByName('C_Spec').AsString:=trim(fieldbyname('MPRTSpec').AsString);
            Order_Sub.FieldByName('C_Color').AsString:=trim(fieldbyname('PRTColor').AsString);
            Order_Sub.FieldByName('Sdefstr1').AsString:=trim(fieldbyname('SOrddefstr1').AsString);
            Order_Sub.FieldByName('Qty2').value:=fieldbyname('PRTOrderQty').AsFloat;
            Order_Sub.FieldByName('MainUnit').AsString:=trim(fieldbyname('OrderUnit').AsString);
            order_Sub.Post;
          end;
          next;
        end;
      end;
    end;
    free;
  end;
end;

end.
