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;
    JiaoHuoNote: TRichEdit;
    Label8: TLabel;
    Label9: TLabel;
    NoKangLiNote: TRichEdit;
    Label10: TLabel;
    WeiYueNote: TRichEdit;
    Label13: TLabel;
    Note: TRichEdit;
    FactoryNoName: TBtnEditA;
    CompanyName: TBtnEditA;
    JieSuanNote: TBtnEditA;
    PRTZhiLiang: TBtnEditA;
    QtyNote: TBtnEditA;
    PayMent: TBtnEditA;
    v1Column3: TcxGridDBColumn;
    ConType: TComboBox;
    Label14: TLabel;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    Label15: TLabel;
    ConTypeOther: TBtnEditA;
    Panel1: TPanel;
    Label30: TLabel;
    Label29: TLabel;
    Label31: TLabel;
    ClothOneQty: TEdit;
    OneQtyUnit: TComboBox;
    MPRTOneQty: TEdit;
    cxGridPopupMenu1: TcxGridPopupMenu;
    procedure TBCloseClick(Sender: TObject);
    procedure PRTCodeNameKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    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 FactoryNoNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    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 ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure v1Column3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure JieSuanNotePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure PRTZhiLiangPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure QtyNotePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    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 ConTypeOtherBtnClick(Sender: TObject);
    procedure ConNoExit(Sender: TObject);
    procedure v1Column3PropertiesEditValueChanged(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_GYSList,U_ZDYHelpSel, U_GYSSelList;

{$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;
  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;
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(ConNo.Text)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,Panel1,2);
end;

procedure TfrmClothContractInPutSXMX.ZDYHelp(FButn:TcxButtonEdit;LType:string);
var
  FType,ZDYName,FText:String;
begin

  with ADOZDY do
  begin
    Filtered:=False;
    Close;
    SQL.Clear;
    SQL.Add('select RTrim(ZDYNo) ZDYNo,RTrim(ZDYName) ZDYName from KH_ZDY where Type='''+Trim(LType)+'''');
    Open;
  end;
  FText:=Trim(FButn.Text);
  if FText<>'' then
    SDofilter(ADOZDY,' ZDYName like '+QuotedStr('%'+Trim(FText)+'%'))
  else
    SDofilter(ADOZDY,'');
end;

procedure TfrmClothContractInPutSXMX.PRTCodeNameKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  {if (key=vk_return) or (Key=vk_Down) then
  begin
    if ADOZDY.Active then
      CXGridZDY.SetFocus;
  end; }
end;

procedure TfrmClothContractInPutSXMX.FormShow(Sender: TObject);
var
  FSJ:String;
begin
  {if Trim(DParameters1)='1' then
  begin
    v1Price.Visible:=False;
    v1ClothQty.Visible:=False;
    v1PRTQty.Visible:=False;
  end else
  begin
    v1Price.Visible:=True;
    v1ClothQty.Visible:=True;
    v1PRTQty.Visible:=True;
  end;  }
  ReadCxGrid('采购加工合同录入11',Tv1,'采购加工合同');

  FSJ:='select ZdyName Name,ZdyName Code from KH_Zdy where TYpe=''JGGX''  ';
  SInitComBoxBySql(ADOTemp,ConType,False,Fsj);
  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;
  if Trim(canshu1)<>'高权限' then
  begin
    if PState=1 then
    begin
     
      v1Price.Options.Editing:=False;
    end;
    if EditInt=9 then
    begin
      
      v1Price.Options.Editing:=True;
    end;
  end;
  if Trim(FMainId)<>'' then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main_MD where ConMainId='''+Trim(FMainId)+'''');
      Open;
    end;
    if ADOTemp.RecordCount>0 then
    begin
      ConNo.ReadOnly:=True;
    end;
  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,'CM','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('FactoryNo').Value:=Trim(FactoryNoName.TxtCode);
      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;
      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);
          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(ConNo.Text)='' then
  begin
    Application.MessageBox('合同编号不能为空！','提示',0);
    Exit;
  end;
  if Trim(ConType.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('ConQty',null,[]) then
  begin
    Application.MessageBox('合同数量不能为空!','提示',0);
    Exit;
  end;
  if Order_Sub.Locate('ConUnit',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.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 TfrmClothContractInPutSXMX.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 TfrmClothContractInPutSXMX.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 TfrmClothContractInPutSXMX.ToolButton1Click(Sender: TObject);
begin
  CopyAddRow(Tv1,Order_Sub);
  with Order_Sub do
  begin
    Edit;
    FieldByName('SubId').Value:='';
    Post;
  end;
  if Order_Sub.RecordCount=1 then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(ConNo.Text)+'''');
      Open;
    end;
    if ADOTemp.IsEmpty=False then
    begin
      with Order_Sub do
      begin
        Edit;
        FieldByName('C_Code').Value:=Trim(ADOTemp.fieldbyname('MPRTCode').AsString);//+
                                    // Trim(ADOTemp.fieldbyname('MPRTGY').AsString);
        FieldByName('C_CodeName').Value:=Trim(ADOTemp.fieldbyname('MPRTCodeName').AsString);
        FieldByName('C_Spec').Value:=Trim(ADOTemp.fieldbyname('MPRTSpec').AsString);
        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.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 JYOrder_Main_MD where COnSubId='''+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.FactoryNoNamePropertiesButtonClick(
  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 ContractSX_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:='YCLFactory';
      if ShowModal=1 then
      begin
        FXS:=99;
        FactoryNoName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        FactoryNoName.Hint:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.v1Column1PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  if Trim(ConType.Text)='' then
  begin
    Application.MessageBox('合同类型不能为空!','提示',0);
    Exit;
  end;
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ClothHT';
      flagname:='产品名称';
      MainType:=Trim(ConType.Text);
      fnote:=True;
      V1Note.Caption:='编号';
      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('note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.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 TfrmClothContractInPutSXMX.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 TfrmClothContractInPutSXMX.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 TfrmClothContractInPutSXMX.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 TfrmClothContractInPutSXMX.FactoryNoNamePropertiesChange(
  Sender: TObject);
begin
  {if FXS=99 then
  begin
    PanZDY.Visible:=False;
    FXS:=0;
    Exit;
  end;
  ZDYHelp(FactoryNoName,'FactoryNo1Name');  }
end;

procedure TfrmClothContractInPutSXMX.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 TfrmClothContractInPutSXMX.ConNoKeyPress(Sender: TObject;
  var Key: Char);
begin
  {if Key=#13 then
  begin
    if Trim(ConNo.Text)<>'' then
    begin
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select Top 1* from JYOrder_Main where OrderNo='''+Trim(ConNo.Text)+'''');
        Open;
      end;
      FactoryNoName.Text:=Trim(ADOTemp.fieldbyname('YCLFactory').AsString);
    end;
  end;  }
end;

procedure TfrmClothContractInPutSXMX.v1Column3PropertiesButtonClick(
  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 ContractSX_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:='YCLFactory';
      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 TfrmClothContractInPutSXMX.JieSuanNotePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
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.PRTZhiLiangPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
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.QtyNotePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
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.CompanyNameBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='GSTT';
      flagname:='公司抬头';
      V1ZdyStr1.Visible:=True;
      V1ZdyStr2.Visible:=True;
      V1ZdyStr3.Visible:=True;
      V1ZdyStr4.Visible:=True;
      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
    frmGYSSelList:=TfrmGYSSelList.Create(Application);
    with frmGYSSelList do
    begin
      if ShowModal=1 then
      begin
        FactoryNoName.Text:=Trim(frmGYSSelList.Order_Main.fieldbyname('KHNameJC').AsString);
        FactoryNoName.TxtCode:=Trim(frmGYSSelList.Order_Main.fieldbyname('ZKId').AsString);
      end;
    end;
  finally
    frmGYSSelList.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.ConTypeOtherBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ConTypeOther';
      flagname:='采购加工合同类型';
      if ShowModal=1 then
      begin
        ConTypeOther.Text:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothContractInPutSXMX.ConNoExit(Sender: TObject);
begin
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(ConNo.Text)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,Panel1,2);
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('C_Code').Value:=Trim(ADOTemp.fieldbyname('MPRTCode').AsString)+
                                     Trim(ADOTemp.fieldbyname('MPRTGY').AsString);}
       // FieldByName('C_CodeName').Value:=Trim(ADOTemp.fieldbyname('MPRTCodeName').AsString);
        //FieldByName('C_Spec').Value:=Trim(ADOTemp.fieldbyname('MPRTSpec').AsString);
        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;

end.
