{$Define Tfssb}
unit UntDataBaseTGDZC;

interface 
uses   
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,adoDb,Variants; 
Type  
  TGDZC = class(TObject) 
  Public 
    AdoQuery :TAdoQuery;   
    constructor Create(Adoconnection:TAdoconnection);
    destructor Destroy; override ; 
  end;  
  
{$IFDEF Tfssb}
  Tfssb = class(TGDZC) 
    Private
    public
      Pid : integer; 
      Ppjbh : string; 
      Pzcno : string; 
      Ppjmc : string; 
      Pxhgg : string; 
      Pjldw : string; 
      Pgys : string; 
      Pdj : real; 
      Psl : integer; 
      Pje : real; 
      Pbz : string; 
      Pdjrq : TDatetime; 
      Pupsize_ts : variant; 
      Function FindRecorder(GiveValueToVariant:boolean):boolean;    //查找某一条记录,用主键值做条件
      Function InsertIntoTable:boolean; //向表中插入一条记录
      Function UpdateTable:boolean;     //更新一条记录,用主键值做条件
      Function DeleteTable(PromptDlg:boolean):boolean;     //删除一条记录,用主键值做条件
  End;  
{$ENDIF} 
implementation 
{ TGDZC }
constructor TGDZC.create(ADOConnection:TADOConnection) ;
begin  
   adoquery:=Tadoquery.Create(nil);  
   adoquery.Connection:= ADOConnection;   
end; 
destructor TGDZC.Destroy;
begin  
  adoquery.Free;  
  adoquery:=nil;  
  inherited; 
end;  
{$IFDEF Tfssb}
Function Tfssb.InsertIntoTable:boolean;
Begin
  result:=false; 
  With ADOQuery do  
  Begin             
    Close;          
    Sql.text:=      
    'Insert into fssb ('+
    'pjbh,zcno,pjmc,xhgg,jldw,gys,dj,sl,je,bz,djrq,'+
    'upsize_ts) values ('+
    ':P_pjbh,:P_zcno,:P_pjmc,:P_xhgg,:P_jldw,:P_gys,:P_dj,:P_sl,:P_je,:P_bz,'+
    ':P_djrq,'+
    ':P_upsize_ts) ';
    Parameters.ParamByName('P_pjbh').Value:=Copy(Ppjbh,1,100) ;   
    Parameters.ParamByName('P_zcno').Value:=Copy(Pzcno,1,100) ;   
    Parameters.ParamByName('P_pjmc').Value:=Copy(Ppjmc,1,100) ;   
    Parameters.ParamByName('P_xhgg').Value:=Copy(Pxhgg,1,200) ;   
    Parameters.ParamByName('P_jldw').Value:=Copy(Pjldw,1,40) ;   
    Parameters.ParamByName('P_gys').Value:=Copy(Pgys,1,200) ;   
    Parameters.ParamByName('P_dj').Value:=Pdj ; 
    Parameters.ParamByName('P_sl').Value:=Psl ; 
    Parameters.ParamByName('P_je').Value:=Pje ; 
    Parameters.ParamByName('P_bz').Value:=Copy(Pbz,1,2147483646) ;   
    Parameters.ParamByName('P_djrq').Value:=Pdjrq ; 
    Parameters.ParamByName('P_upsize_ts').Value:=Pupsize_ts ; 
    Try             
    EXECSql ;       
    result:=True ; 
      except        
      //Application.MessageBox('存储失败!','系统提示',MB_ICONWARNING);
    End;            
  End;              
end;  
Function Tfssb.UpdateTable:boolean;
Begin
  result:=false; 
  With ADOQuery do  
  Begin             
    Close;          
    Sql.text:=' Update fssb set '+
    'pjbh=:P_pjbh,zcno=:P_zcno,pjmc=:P_pjmc,xhgg=:P_xhgg,jldw=:P_jldw,gys=:P_gys,'+
    'dj=:P_dj,sl=:P_sl,je=:P_je,bz=:P_bz,djrq=:P_djrq,'+
    'upsize_ts=:P_upsize_ts' +  
    ' Where (id=:P_id)' ;
    Parameters.ParamByName('P_id').Value:=Pid ; 
    Parameters.ParamByName('P_pjbh').Value:=Copy(Ppjbh,1,100) ;   
    Parameters.ParamByName('P_zcno').Value:=Copy(Pzcno,1,100) ;   
    Parameters.ParamByName('P_pjmc').Value:=Copy(Ppjmc,1,100) ;   
    Parameters.ParamByName('P_xhgg').Value:=Copy(Pxhgg,1,200) ;   
    Parameters.ParamByName('P_jldw').Value:=Copy(Pjldw,1,40) ;   
    Parameters.ParamByName('P_gys').Value:=Copy(Pgys,1,200) ;   
    Parameters.ParamByName('P_dj').Value:=Pdj ; 
    Parameters.ParamByName('P_sl').Value:=Psl ; 
    Parameters.ParamByName('P_je').Value:=Pje ; 
    Parameters.ParamByName('P_bz').Value:=Copy(Pbz,1,2147483646) ;   
    Parameters.ParamByName('P_djrq').Value:=Pdjrq ; 
    Parameters.ParamByName('P_upsize_ts').Value:=Pupsize_ts ; 
    Try             
    EXECSql ;       
    result:=true; 
      except        
      Application.MessageBox('存储失败!','系统提示',MB_ICONWARNING);
    End;            
  End;              
end;  
Function Tfssb.DeleteTable(PromptDlg:boolean ):boolean;
Begin  
  result:=false; 
  With ADOQuery do  
  Begin             
    Close;          
    Sql.text:=' Delete From fssb  Where id=:P_id';
    Parameters.ParamByName('P_id').Value:=Pid ; 
    if PromptDlg then  begin 
      if application.MessageBox('你将删除选定的记录,继续吗?','系统提示', MB_OKCANCEL+MB_ICONWARNING)=1  then 
      Begin
        ExecSql;
        result:=true; 
      end;
    end else begin  
      ExecSql;
      result:=true;
    end;
  End;              
end;  
Function Tfssb.FindRecorder(GiveValueToVariant:boolean):boolean;
Begin
  result:=false; 
  With ADOQuery do  
  Begin             
    Close;          
    Sql.text:=' Select * From fssb  Where id=:P_id';
    Parameters.ParamByName('P_id').Value:=Pid ; 
    Open;
    if recordcount>0 then begin
      result:=true; 
      if GiveValueToVariant then begin 
        //Pid:=Fieldbyname('id').asinteger; //
        Ppjbh:=Fieldbyname('pjbh').asstring; //
        Pzcno:=Fieldbyname('zcno').asstring; //
        Ppjmc:=Fieldbyname('pjmc').asstring; //
        Pxhgg:=Fieldbyname('xhgg').asstring; //
        Pjldw:=Fieldbyname('jldw').asstring; //
        Pgys:=Fieldbyname('gys').asstring; //
        Pdj:=Fieldbyname('dj').asfloat; //
        Psl:=Fieldbyname('sl').asinteger; //
        Pje:=Fieldbyname('je').asfloat; //
        Pbz:=Fieldbyname('bz').asstring; //
        Pdjrq:=Fieldbyname('djrq').asdatetime; //
        Pupsize_ts:=Fieldbyname('upsize_ts').asvariant; //
      End;   
    End;   
  End;    
end;  
{$ENDIF} 
end.