Unit BLLCompany;

interface
Uses SysUtils,Classes,ADODB,DB,BaseModel,DZModelCompany;
Const Tablename='Company';
Type
TBLLCompany=Class 
Private
 FadoConnection:TadoConnection;
 Fadoqry:TadoQuery;
 FautoClose:Boolean;
Public
  Constructor Create(constr:string);Overload;
  Constructor Create(con:TadoConnection);Overload;
  Destructor Destroy;
  Function Add(Value:TModelCompany):boolean;
  Function Exists(CmpID:Integer):boolean;Overload;
  Function GetModel(CmpID:Integer):TModelCompany;Overload;
  Function DeleteModel(CmpID:Integer):boolean;Overload;
  Function Update(CmpID:Integer;Value:TModelCompany):boolean;Overload;
  Function Exists(CmpGuid:String):boolean;Overload;
  Function GetModel(CmpGuid:String):TModelCompany;Overload;
  Function DeleteModel(CmpGuid:String):boolean;Overload;
  Function Update(CmpGuid:String;Value:TModelCompany):boolean;Overload;
  Procedure GetDataSet(StrWhere:string;Qry:Tadoquery);Overload;
  Procedure GetDataSet(Top:integer;StrWhere,orderby:string;Qry:Tadoquery);Overload;
  Function DeleteList(Model:TmodelCompany):Boolean;//删除记录条件为and方式
  Function DeleteListOr(Model:TmodelCompany):Boolean;//删除记录条件为or方式
  Function DeleteByWhere(StrWhere:string):Boolean;//删除记录条件为or方式
End;

implementation

Constructor TBLLCompany.Create(constr:string);
Begin
 self.FadoConnection:=TadoConnection.Create(nil);
 self.FadoConnection.LoginPrompt:=False;
 self.FadoConnection.KeepConnection:=True;
 self.FadoConnection.ConnectionString:=Constr;
 self.Fadoqry:=TadoQuery.Create(nil);
 self.Fadoqry.Connection:=FadoConnection;
 FautoClose:=true;
end;
Constructor TBLLCompany.Create(con:TadoConnection);
Begin
 self.FadoConnection:=con;
 self.Fadoqry:=TadoQuery.Create(nil);
 self.Fadoqry.Connection:=FadoConnection;
end;
Destructor TBLLCompany.Destroy;
Begin
  self.Fadoqry.free;
  if Self.FautoClose then FadoConnection.free;
  Inherited;
End;
Function TBLLCompany.Add(Value:TModelCompany):boolean;
Var Sqlstr,values:string;Valued:Boolean;
Begin
  Sqlstr:='Insert into Company(';
  values:='values(';
  Valued:=False;
  Result:=False;
  with value do begin
    If (Not CmpID.IsNull) and (CmpID.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'CmpID,';
    Valued:=True;
    values:=values+CmpID.ValueToString+',';  end;
    If (Not CmpGuid.IsNull) and (CmpGuid.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'CmpGuid,';
    Valued:=True;
    values:=values+CmpGuid.ValueToString+',';  end;
    If (Not CmpLogo.IsNull) and (CmpLogo.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'CmpLogo,';
    Valued:=True;
    values:=values+CmpLogo.ValueToString+',';  end;
    If (Not CmpName.IsNull) and (CmpName.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'CmpName,';
    Valued:=True;
    values:=values+CmpName.ValueToString+',';  end;
    If (Not IndustryID.IsNull) and (IndustryID.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'IndustryID,';
    Valued:=True;
    values:=values+IndustryID.ValueToString+',';  end;
    If (Not CmpTypeID.IsNull) and (CmpTypeID.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'CmpTypeID,';
    Valued:=True;
    values:=values+CmpTypeID.ValueToString+',';  end;
    If (Not Web.IsNull) and (Web.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'Web,';
    Valued:=True;
    values:=values+Web.ValueToString+',';  end;
    If (Not Introduct.IsNull) and (Introduct.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'Introduct,';
    Valued:=True;
    values:=values+Introduct.ValueToString+',';  end;
    If (Not CityID.IsNull) and (CityID.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'CityID,';
    Valued:=True;
    values:=values+CityID.ValueToString+',';  end;
    If (Not LinkMan.IsNull) and (LinkMan.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'LinkMan,';
    Valued:=True;
    values:=values+LinkMan.ValueToString+',';  end;
    If (Not Tel.IsNull) and (Tel.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'Tel,';
    Valued:=True;
    values:=values+Tel.ValueToString+',';  end;
    If (Not Fax.IsNull) and (Fax.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'Fax,';
    Valued:=True;
    values:=values+Fax.ValueToString+',';  end;
    If (Not Mobile.IsNull) and (Mobile.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'Mobile,';
    Valued:=True;
    values:=values+Mobile.ValueToString+',';  end;
    If (Not Email.IsNull) and (Email.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'Email,';
    Valued:=True;
    values:=values+Email.ValueToString+',';  end;
    If (Not Address.IsNull) and (Address.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'Address,';
    Valued:=True;
    values:=values+Address.ValueToString+',';  end;
    If (Not PostCode.IsNull) and (PostCode.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'PostCode,';
    Valued:=True;
    values:=values+PostCode.ValueToString+',';  end;
    If (Not QQ.IsNull) and (QQ.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'QQ,';
    Valued:=True;
    values:=values+QQ.ValueToString+',';  end;
    If (Not MSN.IsNull) and (MSN.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'MSN,';
    Valued:=True;
    values:=values+MSN.ValueToString+',';  end;
    If (Not Createtime.IsNull) and (Createtime.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'Createtime,';
    Valued:=True;
    values:=values+Createtime.ValueToString+',';  end;
    If (Not CmpStatus.IsNull) and (CmpStatus.DType<>ftAutoInc) Then Begin
    Sqlstr:=Sqlstr+'CmpStatus,';
    Valued:=True;
    values:=values+CmpStatus.ValueToString+',';  end;
    If Not Valued then Exit;
    Delete(Sqlstr,Length(Sqlstr),1);
    Sqlstr:=Sqlstr+')';
    Delete(values,Length(values),1);
    values:=values+')';
  End;
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr+values;
  try
  Result:=Fadoqry.ExecSQL>0;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Function TBLLCompany.Exists(CmpID:Integer):Boolean;
Var Sqlstr:string;
Begin
Sqlstr:='Select CmpID From Company Where CmpID='+InttoStr(CmpID);
  try
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr;
  Fadoqry.Open;
  Result:=Fadoqry.recordCount>0;
  Fadoqry.Close;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Function TBLLCompany.GetModel(CmpID:Integer):TModelCompany;
Var Sqlstr:string;
Begin
  Result:=nil;
  Sqlstr:='Select CmpID,CmpGuid,CmpLogo,CmpName,IndustryID,'+
  'CmpTypeID,Web,Introduct,CityID,LinkMan,'+
  'Tel,Fax,Mobile,Email,Address,'+
  'PostCode,QQ,MSN,Createtime,CmpStatus From Company Where CmpID='+InttoStr(CmpID);
  try
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr;
  Fadoqry.Open;
  if Fadoqry.recordCount>0 then begin
     Result:=TModelCompany.Create;
     Result.CmpID.Value:=Fadoqry.Fieldbyname('CmpID').Value;
     Result.CmpGuid.Value:=Fadoqry.Fieldbyname('CmpGuid').Value;
     Result.CmpLogo.Value:=Fadoqry.Fieldbyname('CmpLogo').Value;
     Result.CmpName.Value:=Fadoqry.Fieldbyname('CmpName').Value;
     Result.IndustryID.Value:=Fadoqry.Fieldbyname('IndustryID').Value;
     Result.CmpTypeID.Value:=Fadoqry.Fieldbyname('CmpTypeID').Value;
     Result.Web.Value:=Fadoqry.Fieldbyname('Web').Value;
     Result.Introduct.Value:=Fadoqry.Fieldbyname('Introduct').Value;
     Result.CityID.Value:=Fadoqry.Fieldbyname('CityID').Value;
     Result.LinkMan.Value:=Fadoqry.Fieldbyname('LinkMan').Value;
     Result.Tel.Value:=Fadoqry.Fieldbyname('Tel').Value;
     Result.Fax.Value:=Fadoqry.Fieldbyname('Fax').Value;
     Result.Mobile.Value:=Fadoqry.Fieldbyname('Mobile').Value;
     Result.Email.Value:=Fadoqry.Fieldbyname('Email').Value;
     Result.Address.Value:=Fadoqry.Fieldbyname('Address').Value;
     Result.PostCode.Value:=Fadoqry.Fieldbyname('PostCode').Value;
     Result.QQ.Value:=Fadoqry.Fieldbyname('QQ').Value;
     Result.MSN.Value:=Fadoqry.Fieldbyname('MSN').Value;
     Result.Createtime.Value:=Fadoqry.Fieldbyname('Createtime').Value;
     Result.CmpStatus.Value:=Fadoqry.Fieldbyname('CmpStatus').Value;
  end;
  Fadoqry.Close;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Function TBLLCompany.DeleteModel(CmpID:Integer):Boolean;
Var Sqlstr:string;
Begin
Sqlstr:='Delete  From Company Where CmpID='+InttoStr(CmpID);
  try
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr;
  Result:=Fadoqry.ExecSql>0;
  Fadoqry.Close;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Function TBLLCompany.Update(CmpID:Integer;Value:TModelCompany):Boolean;
Var Sqlstr:string;
Begin
  Sqlstr:='Update Company Set ';
  Sqlstr:=Sqlstr+  'CmpID='+Value.CmpID.ValueToString+','+
  'CmpGuid='+Value.CmpGuid.ValueToString+','+
  'CmpLogo='+Value.CmpLogo.ValueToString+','+
  'CmpName='+Value.CmpName.ValueToString+','+
  'IndustryID='+Value.IndustryID.ValueToString+','+
  'CmpTypeID='+Value.CmpTypeID.ValueToString+','+
  'Web='+Value.Web.ValueToString+','+
  'Introduct='+Value.Introduct.ValueToString+','+
  'CityID='+Value.CityID.ValueToString+','+
  'LinkMan='+Value.LinkMan.ValueToString+','+
  'Tel='+Value.Tel.ValueToString+','+
  'Fax='+Value.Fax.ValueToString+','+
  'Mobile='+Value.Mobile.ValueToString+','+
  'Email='+Value.Email.ValueToString+','+
  'Address='+Value.Address.ValueToString+','+
  'PostCode='+Value.PostCode.ValueToString+','+
  'QQ='+Value.QQ.ValueToString+','+
  'MSN='+Value.MSN.ValueToString+','+
  'Createtime='+Value.Createtime.ValueToString+','+
  'CmpStatus='+Value.CmpStatus.ValueToString+' Where CmpID='+InttoStr(CmpID);
  try
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr;
  Result:=Fadoqry.ExecSql>0;
  Fadoqry.Close;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Function TBLLCompany.Exists(CmpGuid:String):Boolean;
Var Sqlstr:string;
Begin
Sqlstr:='Select CmpGuid From Company Where CmpGuid='+''''+CmpGuid+'''';
  try
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr;
  Fadoqry.Open;
  Result:=Fadoqry.recordCount>0;
  Fadoqry.Close;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Function TBLLCompany.GetModel(CmpGuid:String):TModelCompany;
Var Sqlstr:string;
Begin
  Result:=nil;
  Sqlstr:='Select CmpID,CmpGuid,CmpLogo,CmpName,IndustryID,'+
  'CmpTypeID,Web,Introduct,CityID,LinkMan,'+
  'Tel,Fax,Mobile,Email,Address,'+
  'PostCode,QQ,MSN,Createtime,CmpStatus From Company Where CmpGuid='+''''+CmpGuid+'''';
  try
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr;
  Fadoqry.Open;
  if Fadoqry.recordCount>0 then begin
     Result:=TModelCompany.Create;
     Result.CmpID.Value:=Fadoqry.Fieldbyname('CmpID').Value;
     Result.CmpGuid.Value:=Fadoqry.Fieldbyname('CmpGuid').Value;
     Result.CmpLogo.Value:=Fadoqry.Fieldbyname('CmpLogo').Value;
     Result.CmpName.Value:=Fadoqry.Fieldbyname('CmpName').Value;
     Result.IndustryID.Value:=Fadoqry.Fieldbyname('IndustryID').Value;
     Result.CmpTypeID.Value:=Fadoqry.Fieldbyname('CmpTypeID').Value;
     Result.Web.Value:=Fadoqry.Fieldbyname('Web').Value;
     Result.Introduct.Value:=Fadoqry.Fieldbyname('Introduct').Value;
     Result.CityID.Value:=Fadoqry.Fieldbyname('CityID').Value;
     Result.LinkMan.Value:=Fadoqry.Fieldbyname('LinkMan').Value;
     Result.Tel.Value:=Fadoqry.Fieldbyname('Tel').Value;
     Result.Fax.Value:=Fadoqry.Fieldbyname('Fax').Value;
     Result.Mobile.Value:=Fadoqry.Fieldbyname('Mobile').Value;
     Result.Email.Value:=Fadoqry.Fieldbyname('Email').Value;
     Result.Address.Value:=Fadoqry.Fieldbyname('Address').Value;
     Result.PostCode.Value:=Fadoqry.Fieldbyname('PostCode').Value;
     Result.QQ.Value:=Fadoqry.Fieldbyname('QQ').Value;
     Result.MSN.Value:=Fadoqry.Fieldbyname('MSN').Value;
     Result.Createtime.Value:=Fadoqry.Fieldbyname('Createtime').Value;
     Result.CmpStatus.Value:=Fadoqry.Fieldbyname('CmpStatus').Value;
  end;
  Fadoqry.Close;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Function TBLLCompany.DeleteModel(CmpGuid:String):Boolean;
Var Sqlstr:string;
Begin
Sqlstr:='Delete  From Company Where CmpGuid='+''''+CmpGuid+'''';
  try
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr;
  Result:=Fadoqry.ExecSql>0;
  Fadoqry.Close;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Function TBLLCompany.Update(CmpGuid:String;Value:TModelCompany):Boolean;
Var Sqlstr:string;
Begin
  Sqlstr:='Update Company Set ';
  Sqlstr:=Sqlstr+  'CmpID='+Value.CmpID.ValueToString+','+
  'CmpGuid='+Value.CmpGuid.ValueToString+','+
  'CmpLogo='+Value.CmpLogo.ValueToString+','+
  'CmpName='+Value.CmpName.ValueToString+','+
  'IndustryID='+Value.IndustryID.ValueToString+','+
  'CmpTypeID='+Value.CmpTypeID.ValueToString+','+
  'Web='+Value.Web.ValueToString+','+
  'Introduct='+Value.Introduct.ValueToString+','+
  'CityID='+Value.CityID.ValueToString+','+
  'LinkMan='+Value.LinkMan.ValueToString+','+
  'Tel='+Value.Tel.ValueToString+','+
  'Fax='+Value.Fax.ValueToString+','+
  'Mobile='+Value.Mobile.ValueToString+','+
  'Email='+Value.Email.ValueToString+','+
  'Address='+Value.Address.ValueToString+','+
  'PostCode='+Value.PostCode.ValueToString+','+
  'QQ='+Value.QQ.ValueToString+','+
  'MSN='+Value.MSN.ValueToString+','+
  'Createtime='+Value.Createtime.ValueToString+','+
  'CmpStatus='+Value.CmpStatus.ValueToString+' Where CmpGuid='+''''+CmpGuid+'''';
  try
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr;
  Result:=Fadoqry.ExecSql>0;
  Fadoqry.Close;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Procedure TBLLCompany.GetDataSet(strWhere:string;Qry:Tadoquery);
Var Sqlstr:string;
Begin
  Sqlstr:='Select CmpID,CmpGuid,CmpLogo,CmpName,IndustryID,'+
  'CmpTypeID,Web,Introduct,CityID,LinkMan,'+
  'Tel,Fax,Mobile,Email,Address,'+
  'PostCode,QQ,MSN,Createtime,CmpStatus From Company';
  If Trim(strWhere)<>'' then 
  Sqlstr:=Sqlstr+' where '+sTrWhere;
  Qry.Close;
  if not assigned(Qry.Connection) then
  begin
    qry.Connection:=self.FadoConnection ;
    If FadoConnection.Connected=False then
    FadoConnection.Connected:=True;
  end;
  Qry.Sql.text:=Sqlstr;
  try
  Qry.Open;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Procedure TBLLCompany.GetDataSet(Top:integer;StrWhere,orderby:string;Qry:Tadoquery);
Var Sqlstr:string;
Begin
  Sqlstr:='Select ';
  If Top>0 then Sqlstr:=Sqlstr+'Top '+inttostr(Top);
  Sqlstr:=Sqlstr+' CmpID,CmpGuid,CmpLogo,CmpName,IndustryID,'+
  'CmpTypeID,Web,Introduct,CityID,LinkMan,'+
  'Tel,Fax,Mobile,Email,Address,'+
  'PostCode,QQ,MSN,Createtime,CmpStatus From Company';
  If Trim(strWhere)<>'' then 
  Sqlstr:=Sqlstr+' where '+sTrWhere;
  If Trim(orderby)<>'' then 
  Sqlstr:=Sqlstr+' Order by '+orderby;
  Qry.Close;
  if not assigned(Qry.Connection) then
  begin
    qry.Connection:=self.FadoConnection ;
    If FadoConnection.Connected=False then
    FadoConnection.Connected:=True;
  end;
  Qry.Sql.text:=Sqlstr;
  try
  Qry.Open;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Function TBLLCompany.DeleteList(Model:TmodelCompany):Boolean;
Var Sqlstr,strwhere:string;
Begin
Sqlstr:='Delete From Company';
StrWhere:='';
  with Model do begin
    If (Not CmpID.IsNull) Then 
    StrWhere:=StrWhere+'(CmpID='+CmpID.ValueToString+')and';
    If (Not CmpGuid.IsNull) Then 
    StrWhere:=StrWhere+'(CmpGuid='+CmpGuid.ValueToString+')and';
    If (Not CmpLogo.IsNull) Then 
    StrWhere:=StrWhere+'(CmpLogo='+CmpLogo.ValueToString+')and';
    If (Not CmpName.IsNull) Then 
    StrWhere:=StrWhere+'(CmpName='+CmpName.ValueToString+')and';
    If (Not IndustryID.IsNull) Then 
    StrWhere:=StrWhere+'(IndustryID='+IndustryID.ValueToString+')and';
    If (Not CmpTypeID.IsNull) Then 
    StrWhere:=StrWhere+'(CmpTypeID='+CmpTypeID.ValueToString+')and';
    If (Not Web.IsNull) Then 
    StrWhere:=StrWhere+'(Web='+Web.ValueToString+')and';
    If (Not Introduct.IsNull) Then 
    StrWhere:=StrWhere+'(Introduct='+Introduct.ValueToString+')and';
    If (Not CityID.IsNull) Then 
    StrWhere:=StrWhere+'(CityID='+CityID.ValueToString+')and';
    If (Not LinkMan.IsNull) Then 
    StrWhere:=StrWhere+'(LinkMan='+LinkMan.ValueToString+')and';
    If (Not Tel.IsNull) Then 
    StrWhere:=StrWhere+'(Tel='+Tel.ValueToString+')and';
    If (Not Fax.IsNull) Then 
    StrWhere:=StrWhere+'(Fax='+Fax.ValueToString+')and';
    If (Not Mobile.IsNull) Then 
    StrWhere:=StrWhere+'(Mobile='+Mobile.ValueToString+')and';
    If (Not Email.IsNull) Then 
    StrWhere:=StrWhere+'(Email='+Email.ValueToString+')and';
    If (Not Address.IsNull) Then 
    StrWhere:=StrWhere+'(Address='+Address.ValueToString+')and';
    If (Not PostCode.IsNull) Then 
    StrWhere:=StrWhere+'(PostCode='+PostCode.ValueToString+')and';
    If (Not QQ.IsNull) Then 
    StrWhere:=StrWhere+'(QQ='+QQ.ValueToString+')and';
    If (Not MSN.IsNull) Then 
    StrWhere:=StrWhere+'(MSN='+MSN.ValueToString+')and';
    If (Not Createtime.IsNull) Then 
    StrWhere:=StrWhere+'(Createtime='+Createtime.ValueToString+')and';
    If (Not CmpStatus.IsNull) Then 
    StrWhere:=StrWhere+'(CmpStatus='+CmpStatus.ValueToString+')and';
  End;
  if trim(StrWhere)<>'' then begin delete(StrWhere,length(Strwhere)-2,3);
  StrWhere:=' where'+StrWhere;
  End;
  try
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr+StrWhere;
  Result:=Fadoqry.ExecSql>0;
  Fadoqry.Close;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Function TBLLCompany.DeleteListOr(Model:TmodelCompany):Boolean;
Var Sqlstr,strwhere:string;
Begin
Sqlstr:='Delete From Company';
StrWhere:='';
  with Model do begin
    If (Not CmpID.IsNull) Then 
    StrWhere:=StrWhere+'(CmpID='+CmpID.ValueToString+')Or';
    If (Not CmpGuid.IsNull) Then 
    StrWhere:=StrWhere+'(CmpGuid='+CmpGuid.ValueToString+')Or';
    If (Not CmpLogo.IsNull) Then 
    StrWhere:=StrWhere+'(CmpLogo='+CmpLogo.ValueToString+')Or';
    If (Not CmpName.IsNull) Then 
    StrWhere:=StrWhere+'(CmpName='+CmpName.ValueToString+')Or';
    If (Not IndustryID.IsNull) Then 
    StrWhere:=StrWhere+'(IndustryID='+IndustryID.ValueToString+')Or';
    If (Not CmpTypeID.IsNull) Then 
    StrWhere:=StrWhere+'(CmpTypeID='+CmpTypeID.ValueToString+')Or';
    If (Not Web.IsNull) Then 
    StrWhere:=StrWhere+'(Web='+Web.ValueToString+')Or';
    If (Not Introduct.IsNull) Then 
    StrWhere:=StrWhere+'(Introduct='+Introduct.ValueToString+')Or';
    If (Not CityID.IsNull) Then 
    StrWhere:=StrWhere+'(CityID='+CityID.ValueToString+')Or';
    If (Not LinkMan.IsNull) Then 
    StrWhere:=StrWhere+'(LinkMan='+LinkMan.ValueToString+')Or';
    If (Not Tel.IsNull) Then 
    StrWhere:=StrWhere+'(Tel='+Tel.ValueToString+')Or';
    If (Not Fax.IsNull) Then 
    StrWhere:=StrWhere+'(Fax='+Fax.ValueToString+')Or';
    If (Not Mobile.IsNull) Then 
    StrWhere:=StrWhere+'(Mobile='+Mobile.ValueToString+')Or';
    If (Not Email.IsNull) Then 
    StrWhere:=StrWhere+'(Email='+Email.ValueToString+')Or';
    If (Not Address.IsNull) Then 
    StrWhere:=StrWhere+'(Address='+Address.ValueToString+')Or';
    If (Not PostCode.IsNull) Then 
    StrWhere:=StrWhere+'(PostCode='+PostCode.ValueToString+')Or';
    If (Not QQ.IsNull) Then 
    StrWhere:=StrWhere+'(QQ='+QQ.ValueToString+')Or';
    If (Not MSN.IsNull) Then 
    StrWhere:=StrWhere+'(MSN='+MSN.ValueToString+')Or';
    If (Not Createtime.IsNull) Then 
    StrWhere:=StrWhere+'(Createtime='+Createtime.ValueToString+')Or';
    If (Not CmpStatus.IsNull) Then 
    StrWhere:=StrWhere+'(CmpStatus='+CmpStatus.ValueToString+')Or';
  End;
  if trim(StrWhere)<>'' then begin delete(StrWhere,length(Strwhere)-1,2);
  StrWhere:=' where'+StrWhere;
  End;
  try
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr+StrWhere;
  Result:=Fadoqry.ExecSql>0;
  Fadoqry.Close;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
Function TBLLCompany.DeleteByWhere(StrWhere:string):Boolean;
Var Sqlstr:string;
Begin
  If Trim(StrWhere)='' then raise exception.Create('条件不能为空');
  Sqlstr:='Delete  From Company Where '+StrWhere;
  try
  If FadoConnection.Connected=False then 
  FadoConnection.Connected:=True;
  Fadoqry.Close;
  Fadoqry.Sql.text:=Sqlstr;
  Result:=Fadoqry.ExecSql>0;
  Fadoqry.Close;
  except
  On e:exception do raise exception.Create(e.message);
  end;
End;
End.
