⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unttfunc.pas

📁 delphi7,源代码 主要的是进行DELPHI7的源代码进行管理和维护
💻 PAS
字号:
{*******************************************************}
{                                                       }
{       单元名称: UntTFunc                              }
{       创建日期: 2005-08-17                            }
{       摘要说明: 数据表Func操作实体类                  }
{                                                       }
{       详细说明:                                       }
{                                                       }
{       参  阅:                                       }
{                                                       }
{       已知问题:                                       }
{                                                       }
{       待作事项:                                       }
{                                                       }
{       作  者: 胡孟杰                                }
{       Copyright (C) 2005 FdAuto                       }
{       当前版本: 1.0                                   }
{       版本历史:                                       }
{                                                       }
{*******************************************************}

{$DEFINE TFunc}
unit UntTFunc;

{==========================================================================
             单元接口部分
==========================================================================}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ADODB, Variants;

{==========================================================================
 类 名:    Tconfig
  功  能:    类Tconfig的定义,是类TFunc的基类
  参 数:    无
  返回值:    无
  作 者:    胡孟杰
  日 期:    2005.08.17
==========================================================================}

type
  Tconfig = class(TObject)
  public
    ADOQuery: TADOQuery;
    constructor Create(Adoconnection: TAdoconnection);
    destructor Destroy; override;
  end;

  {==========================================================================
   类 名:    TFunc
    功  能:    类TFunc的定义,继承自类Tconfig
    参 数:    无
    返回值:    无
    作 者:    胡孟杰
    日 期:    2005.08.17
  ==========================================================================}

{$IFDEF TFunc}
  TFunc = class(Tconfig)
  private
  public
    PID: integer;                       // ID号
    PType: string;                      // 类别
    PSubject: string;                   // 函数过程名称
    PUses: string;                      // 引用的单元
    PContent: string;                   // 函数过程的内容
    PRemark: string;                    // 注释与说明
    function FindRecorder(GiveValueToVariant: boolean): boolean;  //查找某一条记录,用主键值做条件
    function InsertIntoTable: boolean;  //向表中插入一条记录
    function UpdateTable: boolean;      //更新一条记录,用主键值做条件
    function DeleteTable(PromptDlg: boolean): boolean;  //删除一条记录,用主键值做条件
    function FindType: boolean;         //查找类别明细是否存在
    function UpdateType(NewType: string): boolean; //批量更新类别
    function GetMaxID: integer;         //获取最大ID
    function GetTypeByID: boolean;      //依据主键查找类别

  end;
{$ENDIF}

  {==========================================================================
                          单元实现部分
  ==========================================================================}

implementation

{ Tconfig }
{==========================================================================
 函数名:    Tconfig.create
  功  能:    类Tconfig的构造函数
  参 数:    ADOConnection:数据库连接对象
  返回值:    无
  作 者:    胡孟杰
  日 期:    2005.08.17
==========================================================================}

constructor Tconfig.create(ADOConnection: TADOConnection);
begin
  ADOQuery := TADOQuery.Create(nil);
  ADOQuery.Connection := ADOConnection;
end;

{==========================================================================
 函数名:    Tconfig.Destroy
  功  能:    类Tconfig的析构函数
  参 数:    无
  返回值:    无
  作 者:    胡孟杰
  日 期:    2005.08.17
==========================================================================}

destructor Tconfig.Destroy;
begin
  ADOQuery.Close;
  ADOQuery.Free;
  ADOQuery := nil;
  inherited;
end;

{$IFDEF TFunc}
{==========================================================================
 函数名:    TFunc.GetMaxID
  功  能:    在表Func中取得最大ID,返回ID
  参 数:    无
  返回值:    ID
  作 者:    胡孟杰
  日 期:    2005.08.21
==========================================================================}

function TFunc.GetMaxID: integer;
begin
  Result := 0;
  with ADOQuery do
    begin
      Close;
      Sql.text := ' Select Max(ID) as MaxID From Func';
      //Parameters.ParamByName('P_ID').Value:=PID ; // ID号
      Open;
      if recordcount > 0 then
        begin
          Result := Fieldbyname('MaxID').Asinteger;
        end;
    end;
end;

{==========================================================================
 函数名:    TFunc.InsertIntoTable
  功  能:    在表Func中插入一条记录,返回执行成功与否
  参 数:    各属性先行赋值
  返回值:    True,false
  作 者:    胡孟杰
  日 期:    2005.08.17
==========================================================================}

function TFunc.InsertIntoTable: boolean;
begin
  result := false;
  with ADOQuery do
    begin
      Close;
      Sql.text :=
        'Insert into Func (' +
        'ID,Type,Subject,Uses,Content,' +
        'Remark) values (' +
        ':P_ID,:P_Type,:P_Subject,:P_Uses,:P_Content,' +
        ':P_Remark) ';
      Parameters.ParamByName('P_ID').Value := PID; //ID号
      Parameters.ParamByName('P_Type').Value := Copy(PType, 1, 150); // 类别
      Parameters.ParamByName('P_Subject').Value := Copy(PSubject, 1, 250);  // 函数过程名称
      Parameters.ParamByName('P_Uses').Value := Copy(PUses, 1, 250);  // 引用的单元
      //Parameters.ParamByName('P_Content').Value:=Copy(PContent,1,5000) ;   // 函数过程的内容
      Parameters.ParamByName('P_Content').Value := PContent; // 函数过程的内容
      Parameters.ParamByName('P_Remark').Value := Copy(PRemark, 1, 25000);  // 注释与说明
      try
        EXECSql;
        result := True;
      except
        Application.MessageBox('插入存储失败!', '系统提示', MB_ICONWARNING);
      end;
    end;
end;

{==========================================================================
 函数名:    TFunc.UpdateTable
  功  能:    依据主键在表Func中更新一条记录,返回执行成功与否
  参 数:    各属性先行赋值
  返回值:    True,false
  作 者:    胡孟杰
  日 期:    2005.08.17
==========================================================================}

function TFunc.UpdateTable: boolean;
begin
  result := false;
  with ADOQuery do
    begin
      Close;
      Sql.text := ' Update Func set ' +
        'Type=:P_Type,Subject=:P_Subject,Uses=:P_Uses,Content=:P_Content,' +
        'Remark=:P_Remark' +
        ' Where (ID=:P_ID)';
      Parameters.ParamByName('P_ID').Value := PID; // ID号
      Parameters.ParamByName('P_Type').Value := Copy(PType, 1, 150); // 类别
      Parameters.ParamByName('P_Subject').Value := Copy(PSubject, 1, 250);  // 函数过程名称
      Parameters.ParamByName('P_Uses').Value := Copy(PUses, 1, 250);  // 引用的单元
      //Parameters.ParamByName('P_Content').Value:=Copy(PContent,1,5000) ;   // 函数过程的内容
      Parameters.ParamByName('P_Content').Value := PContent; // 函数过程的内容
      Parameters.ParamByName('P_Remark').Value := Copy(PRemark, 1, 25000);  // 注释与说明
      try
        EXECSql;
        result := true;
      except
        Application.MessageBox('更新存储失败!', '系统提示', MB_ICONWARNING);
      end;
    end;
end;

{==========================================================================
 函数名:    TFunc.DeleteTable
  功  能:    依据主键在表Func中删除一条记录,返回执行成功与否
  参 数:    主键属性先行赋值,PromptDlg:是否弹出确认删除对话框
  返回值:    True,false
  作 者:    胡孟杰
  日 期:    2005.08.17
==========================================================================}

function TFunc.DeleteTable(PromptDlg: boolean): boolean;
begin
  Result := false;
  with ADOQuery do
    begin
      Close;
      Sql.text := ' Delete From Func  Where ID=:P_ID';
      Parameters.ParamByName('P_ID').Value := PID; // ID号
      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;

{==========================================================================
 函数名:    TFunc.FindRecorder
  功  能:    依据主键在表Func中查找一条记录,返回执行成功与否
  参 数:    主键属性先行赋值,GiveValueToVariant:是否把检索结果赋值到各属性
  返回值:    True,false
  作 者:    胡孟杰
  日 期:    2005.08.17
==========================================================================}

function TFunc.FindRecorder(GiveValueToVariant: boolean): boolean;
begin
  Result := false;
  with ADOQuery do
    begin
      Close;
      Sql.text := ' Select * From Func Where ID=:P_ID';
      Parameters.ParamByName('P_ID').Value := PID; // ID号
      Open;
      if recordcount > 0 then
        begin
          Result := true;
          if GiveValueToVariant then
            begin
              PID := Fieldbyname('ID').AsInteger; //ID号
              PType := Fieldbyname('Type').AsString; //类别
              PSubject := Fieldbyname('Subject').AsString; //函数过程名称
              PUses := Fieldbyname('Uses').AsString; //引用的单元
              PContent := Fieldbyname('Content').AsString; //函数过程的内容
              PRemark := Fieldbyname('Remark').AsString; //注释与说明
            end;
        end;
    end;
end;

{==========================================================================
 函数名:    TFunc.FindType
  功  能:    依据主键在表Func中查找类别明细,返回执行成功与否
  参 数:    无
  返回值:    True,false
  作 者:    胡孟杰
  日 期:    2005.08.17
==========================================================================}

function TFunc.FindType: boolean;
begin
  Result := false;
  with ADOQuery do
    begin
      Close;
      Sql.text := ' Select ID From Func  Where Type=:P_Type';
      Parameters.ParamByName('P_Type').Value := PType; // Type
      Open;
      if Recordcount > 0 then
        Result := true;
    end;
end;

{==========================================================================
 函数名:    TFunc.GetTypeByID
  功  能:    依据主键在表Func中查找类别,返回执行成功与否
  参 数:    无
  返回值:    True,false
  作 者:    胡孟杰
  日 期:    2005.08.17
==========================================================================}

function TFunc.GetTypeByID: boolean;
begin
  Result := false;
  with ADOQuery do
    begin
      Close;
      Sql.text := ' Select Type From Func  Where ID=:P_ID';
      Parameters.ParamByName('P_ID').Value := PID; // ID
      Open;
      if Recordcount > 0 then
        begin
          Result := true;
          PType := Fieldbyname('Type').AsString;
        end;
    end;
end;

{==========================================================================
 函数名:    TFunc.UpdateType
  功  能:    在表Func中批量更新类别属性,返回执行成功与否
  参 数:    Type属性先行赋值,NewType:string
  返回值:    True,false
  作 者:    胡孟杰
  日 期:    2005.08.19
==========================================================================}

function TFunc.UpdateType(NewType: string): boolean;
begin
  result := false;
  with ADOQuery do
    begin
      Close;
      Sql.text := ' Update Func set ' +
        'Type=:New_Type' +
        ' Where (Type=:P_Type)';
      Parameters.ParamByName('New_Type').Value := Copy(NewType, 1, 150);  // 新类别名称
      Parameters.ParamByName('P_Type').Value := Copy(PType, 1, 150); // 类别
      try
        EXECSql;
        result := true;
      except
        Application.MessageBox('更新存储失败!', '系统提示', MB_ICONWARNING);
      end;
    end;
end;

{$ENDIF}

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -