unit U_ClothContractInPutSXMX;

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, cxGridCustomPopupMenu, cxGridPopupMenu;

type
  TfrmClothContractInPutSXMX = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    ConNo: TEdit;
    Label4: TLabel;
    DLYDate: TDateTimePicker;
    Label5: TLabel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1PRTSpec: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Price: TcxGridDBColumn;
    v1ClothUnit: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    DataSource2: TDataSource;
    ADOZDY: TADOQuery;
    CDS_ZDY: TClientDataSet;
    ADOQuery1: TADOQuery;
    v1Column1: TcxGridDBColumn;
    Label2: TLabel;
    QDTime: TDateTimePicker;
    Label3: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    v1Column2: TcxGridDBColumn;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label13: TLabel;
    FactoryNoName: TBtnEditA;
    CompanyName: TBtnEditA;
    JieSuanNote: TBtnEditA;
    PRTZhiLiang: TBtnEditA;
    QtyNote: TBtnEditA;
    PayMent: TBtnEditA;
    ConTypeOther: TComboBox;
    Label14: TLabel;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1C_Note: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label15: TLabel;
    OrderNo: TBtnEditA;
    v1PiZhong: TcxGridDBColumn;
    JiaoHuoNote: TMemo;
    NoKangLiNote: TMemo;
    WeiYueNote: TMemo;
    Note: TMemo;
    v1C_Color: TcxGridDBColumn;
    v1C_SeNo: TcxGridDBColumn;
    v1OrderNo: TcxGridDBColumn;
    v1CGMoney: TcxGridDBColumn;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure CompanyNameBtnClick(Sender: TObject);
    procedure FactoryNoNameBtnClick(Sender: TObject);
    procedure JieSuanNoteBtnClick(Sender: TObject);
    procedure PRTZhiLiangBtnClick(Sender: TObject);
    procedure QtyNoteBtnClick(Sender: TObject);
    procedure PayMentBtnClick(Sender: TObject);
    procedure Label7DblClick(Sender: TObject);
    procedure Label9DblClick(Sender: TObject);
    procedure Label10DblClick(Sender: TObject);
    procedure Label13DblClick(Sender: TObject);
    procedure v1Column3PropertiesEditValueChanged(Sender: TObject);
    procedure JiaoHuoNoteDblClick(Sender: TObject);
    procedure NoKangLiNoteDblClick(Sender: TObject);
    procedure WeiYueNoteDblClick(Sender: TObject);
    procedure v1C_SeNoPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1C_ColorPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1OrderNoPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1ClothUnitPropertiesEditValueChanged(Sender: TObject);
    procedure v1PricePropertiesEditValueChanged(Sender: TObject);
  private
    FXS:Integer;
    procedure InitData();
    procedure ZDYHelp(FButn:TcxButtonEdit;LType:string);
    function  SaveData():Boolean;
    { Private declarations }
  public
    PState,PCopyInt,EditInt:Integer;
    FMainId,FConNo,FConType,canshu1:String;

    { Public declarations }
  end;

var
  frmClothContractInPutSXMX: TfrmClothContractInPutSXMX;

implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel,U_ZdyAttachGYS,U_ProductOrderListSel;

{$R *.dfm}

procedure TfrmClothContractInPutSXMX.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('采购加工合同录入11',Tv1,'采购加工合同');
end;

procedure TfrmClothContractInPutSXMX.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from Contract_Main A inner join Contract_Sub B on A.MainId=B.MainId');
    sql.Add(' where A.MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);
  if PCopyInt=1 then
  begin
    FMainId:='';
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('SubId').Value:='';
        Post;
        Next;
      end;
    end;
  end;
  if Order_Sub.IsEmpty=false then
  SCSHDataNew(ADOQuery1,ScrollBox1,0);
  FactoryNoName.TxtCode:=Trim(ADOQuery1.FieldByName('FactoryNo').AsString);
  ConTypeOther.Text:=Trim(ADOQuery1.FieldByName('ConTypeOther').AsString);
  if PState=0 then
  begin
    QDTime.DateTime:=SGetServerDate(ADOTemp);
    DLYDate.DateTime:=QDTime.DateTime;
    QDTime.Checked:=True;
    DLYDate.Checked:=False;
  end;
end;

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


end;

procedure TfrmClothContractInPutSXMX.FormShow(Sender: TObject);
var
  FSJ:String;
begin
  ReadCxGrid('采购加工合同录入11',Tv1,'采购加工合同');
  InitData();
  if PCopyInt=1 then
  begin
    FMainId:='';
    FConNo:='';
    ConNo.Text:='自动生成';
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('SubId').Value:='';
        FieldByName('ConPrice').Value:=Null;
        FieldByName('Price').Value:=Null;
        Post;
        Next;
      end;
    end;
  end;
  if PCopyInt=1 then
  begin
    PState:=0;
  end;
end;

function TfrmClothContractInPutSXMX.SaveData():Boolean;
var
  maxno,maxSubNo:String;
begin
  try
    Result:=False;
    ADOCmd.Connection.BeginTrans;
    //保存主表
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOCmd,maxno,'PB','Contract_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 Contract_Main where MainId='''+Trim(FMainId)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId)='' then
      begin
        Append;
      end
      else begin
        Edit;
      end;
      FieldByName('MainId').Value:=Trim(maxno);
      RTSetsavedata(ADOCmd,'Contract_Main',ScrollBox1,0);
      FieldByName('ConNO').Value:=Trim(maxno);
    //  FieldByName('OrderNo').Value:=Trim(OrderNo.Text);
      FieldByName('FactoryNo').Value:=Trim(FactoryNoName.TxtCode);
      if Trim(FMainId)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
      end else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
      end;
      Post;
    end;
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Contract_Main where ConNo='''+Trim(ConNo.Text)+'''');
      Open;
    end;
    if ADOTemp.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,maxSubNo,'CS','Contract_Sub',2,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 ');
          sql.Add('  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);
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'Contract_Sub',0);
          FieldByName('OrdSubid').Value:=Trim(Order_Sub.fieldbyname('OrdSubid').AsString);
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value:=Trim(maxSubNo);
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    FMainId:=Trim(maxno);
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmClothContractInPutSXMX.TBSaveClick(Sender: TObject);
begin
  DLYDate.SetFocus;
  if Trim(ConTypeOther.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 Order_Sub.Locate('C_Spec',null,[]) then
  begin
    Application.MessageBox('规格型号不能为空!','提示',0);
    Exit;
  end;}
  if PState=0 then
  begin
    if Application.MessageBox('确定要保存数据吗？数据保存后不能修改!','提示',32+4)<>IDYES then Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  end;

end;

procedure TfrmClothContractInPutSXMX.ToolButton1Click(Sender: TObject);
begin
  CopyAddRow(Tv1,Order_Sub);
  with Order_Sub do
  begin
    Edit;
    FieldByName('SubId').Value:='';
    Post;
  end;
end;

procedure TfrmClothContractInPutSXMX.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  if Trim(Order_Sub.fieldbyname('SubId').AsString)<>'' then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_SXPB_CR where CGSubId='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
      Open;
    end;
    if ADOTemp.IsEmpty=false then
    begin
      Application.MessageBox('已经录入码单不能删除数据!','提示',0);
      Exit;
    end;
    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 TfrmClothContractInPutSXMX.CompanyNameBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdDefStr2';
      flagname:='公司抬头';
      V1ZdyStr1.Visible:=False;
      V1ZdyStr2.Visible:=False;
      V1ZdyStr3.Visible:=False;
      V1ZdyStr4.Visible:=False;
      {V1ZdyStr1.Caption:='简称';
      V1ZdyStr2.Caption:='电话';
      V1ZdyStr3.Caption:='传真';
      V1ZdyStr4.Caption:='地址'; }
      //frmZDYHelp.Align:=alClient;
      if ShowModal=1 then
      begin
        CompanyName.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.FactoryNoNameBtnClick(
  Sender: TObject);
begin
  try
    frmZdyAttachGYS:=TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal=1 then
      begin
        FactoryNoName.Text:=Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyName').AsString);
        FactoryNoName.TxtCode:=Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyCode').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.JieSuanNoteBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='JieSuanNote';
      flagname:='结算说明';
      if ShowModal=1 then
      begin
        JieSuanNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.PRTZhiLiangBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PRTZhiLiang';
      flagname:='产品质量';
      if ShowModal=1 then
      begin
        PRTZhiLiang.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.QtyNoteBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='QtyNote';
      flagname:='数量说明';
      if ShowModal=1 then
      begin
        QtyNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.PayMentBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PayMentZW';
      flagname:='付款方式';
      if ShowModal=1 then
      begin
        PayMent.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.Label7DblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='JiaoHuoNote';
      flagname:='交期说明';
      frmZDYHelpSel.Align:=alClient;
      if ShowModal=1 then
      begin
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              if Trim(JiaoHuoNote.Text)='' then
                JiaoHuoNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)
              else
                JiaoHuoNote.Text:=JiaoHuoNote.Text+#13+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
            end;
            Next;
          end;
        end;
        //JiaoHuoNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.Label9DblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='NoKangLiNote';
      flagname:='不可抗力及风险承担';
      frmZDYHelpSel.Align:=alClient;
      if ShowModal=1 then
      begin
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              if Trim(NoKangLiNote.Text)='' then
                NoKangLiNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)
              else
                NoKangLiNote.Text:=NoKangLiNote.Text+#13+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
            end;
            Next;
          end;
        end;
        //JiaoHuoNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.Label10DblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='WeiYueNote';
      flagname:='违约责任';
      frmZDYHelpSel.Align:=alClient;
      if ShowModal=1 then
      begin
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              if Trim(WeiYueNote.Text)='' then
                WeiYueNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)
              else
                WeiYueNote.Text:=WeiYueNote.Text+#13+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
            end;
            Next;
          end;
        end;
        //JiaoHuoNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.Label13DblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='ConMainNote';
      flagname:='合同备注';
      frmZDYHelpSel.Align:=alClient;
      if ShowModal=1 then
      begin
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              if Trim(Note.Text)='' then
                Note.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)
              else
                Note.Text:=Note.Text+#13+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
            end;
            Next;
          end;
        end;
        //JiaoHuoNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.v1Column3PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue:String;
begin
  {mvalue:=TcxTextEdit(Sender).EditingText;
  with Order_Sub do
  begin
    Edit;
    FieldByName('C_Code').Value:=Trim(mvalue);
    Post;
  end;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(ConNo.Text)+'''');
    Open;
  end;
  if ADOTemp.IsEmpty then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select Top 1* from JYOrder_Main where RTrim(MPRTCode)+RTrim(MPRTGY)='''+Trim(mvalue)+'''');
      sql.Add(' order by FillTime desc');
      Open;
    end;
    if ADOTemp.IsEmpty=False then
    begin
      with Order_Sub do
      begin
        Edit;
        FieldByName('JGGY').Value:=Trim(ADOTemp.fieldbyname('MPRTGYHZ').AsString);
        FieldByName('MFQty').Value:=Trim(ADOTemp.fieldbyname('MPRTMF').AsString);
        FieldByName('KZQty').Value:=Trim(ADOTemp.fieldbyname('MPRTKZ').AsString);
        FieldByName('C_CF').Value:=Trim(ADOTemp.fieldbyname('MPRTSpec').AsString);
        FieldByName('C_Note').Value:=Trim(ADOTemp.fieldbyname('MPRTCF').AsString);
        Post;
      end;
    end;
  end;}
end;

procedure TfrmClothContractInPutSXMX.JiaoHuoNoteDblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='JiaoHuoNote';
      flagname:='交期说明';
      frmZDYHelpSel.Align:=alClient;
      if ShowModal=1 then
      begin
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              if Trim(JiaoHuoNote.Text)='' then
                JiaoHuoNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)
              else
                JiaoHuoNote.Text:=JiaoHuoNote.Text+#13+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.NoKangLiNoteDblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='NoKangLiNote';
      flagname:='不可抗力';
      frmZDYHelpSel.Align:=alClient;
      if ShowModal=1 then
      begin
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              if Trim(NoKangLiNote.Text)='' then
                NoKangLiNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)
              else
                NoKangLiNote.Text:=NoKangLiNote.Text+#13+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.WeiYueNoteDblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='WeiYueNote';
      flagname:='违约责任';
      frmZDYHelpSel.Align:=alClient;
      if ShowModal=1 then
      begin
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              if Trim(WeiYueNote.Text)='' then
                WeiYueNote.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)
              else
                WeiYueNote.Text:=WeiYueNote.Text+#13+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.v1C_SeNoPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='C_SeNo';
      flagname:='色号';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          edit;
          FieldByName('C_SeNo').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.v1C_ColorPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='C_Color';
      flagname:='颜色';
      if ShowModal=1 then
      begin
        with Order_Sub do
        begin
          edit;
          FieldByName('C_Color').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.v1OrderNoPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmProductOrderListSel:=TfrmProductOrderListSel.Create(Application);
    with frmProductOrderListSel do
    begin
      if ShowModal=1 then
      begin
        //Self.CompanyName.Text:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('SYRName').AsString);
        with Self.Order_Sub do
        begin
          edit;
          FieldByName('C_CodeName').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTCodeName').AsString);
          FieldByName('OrderNo').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('OrderNo').AsString);
          FieldByName('OrdSubid').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('Subid').AsString);
          FieldByName('MFQty').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTMF').AsString);
          FieldByName('KZQty').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTKZ').AsString);
          FieldByName('C_Spec').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTSpec').AsString);
          FieldByName('C_Color').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTColor').AsString);
          FieldByName('C_SeNo').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTColorNo').AsString);
          FieldByName('C_Qty').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTOrderQty').AsString);
          FieldByName('C_Unit').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('OrderUnit').AsString);
          //post;
        end;
      end;
    end;
  finally
    frmProductOrderListSel.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.v1ClothUnitPropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  with Order_Sub do
  begin
    edit;
    FieldByName('C_Qty').Value:=mavlue;
  end;
  with Order_Sub do
  begin
    edit;
    FieldByName('CGMoney').Value:=FieldByName('C_Qty').AsFloat*FieldByName('Price').AsFloat;
  end;
end;

procedure TfrmClothContractInPutSXMX.v1PricePropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  with Order_Sub do
  begin
    edit;
    FieldByName('Price').Value:=mavlue;
  end;
  with Order_Sub do
  begin
    edit;
    FieldByName('CGMoney').Value:=FieldByName('C_Qty').AsFloat*FieldByName('Price').AsFloat;
  end;
end;

end.
