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

📄 dmunit.~pas

📁 图书馆管理系统,非常有用,希望给你带来帮助
💻 ~PAS
字号:
unit DMUnit;

interface

uses
  Forms,SysUtils, Classes, DB, ADODB;

type
  TDM = class(TDataModule)
    ADOConn: TADOConnection;
    ADOQuery: TADOQuery;
    OtherInfo: TADOQuery;
    LogQuery: TADOQuery;
    BuyQuery: TADOQuery;
    LendQuery: TADOQuery;
    ReadQuery: TADOQuery;
    ReturnQuery: TADOQuery;
    UserQuery: TADOQuery;
    procedure DataModuleCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function GetAuth():TStrings;//取得数据库中所有的作者名
    function GetPub():TStrings;//取得数据库中所有的出版社名称
    function GetTypeSno():TStrings;//取得数据库中所有的类型编号
    function GetTypeGen():TStrings;//取得数据库中所有的总分类名
    function GetTypeTyp(gen:string):TStrings;//根据传入的总分类名取得其下的所有子分类名
    function Getreadid():TStrings;//取得数据库中所有的读者编号
    function GetSno(gen,typ:string):string;//根据传入的总分类名和子分类名取得对应的编号
    function GetReadTyp():TStrings;//取得库存中所有的读者类型编号
    function GetAllReadID():TStrings; //取得库存中所有的读者编号
    function ValRead(id:string):boolean;//查询库存中是否存在此读者
    function ValReadType(sno:string):boolean;//查询库存中是否存在指定的读者类型编号
    function GetUserName():TStrings;//得到数据库中所有的用户名
    function ValUserName(username:string):boolean;//验证用户名
    function ValUser(username,password:string):Boolean;//验证输入的用户名和密码是否正确
    function SetUserPass(username,password:string):boolean;//更改用户密码
    procedure SaveLogIn(username:string);//保存登录日志
    function GetMenu(username:string):TStrings;//取得用户可用菜单
    function ValReadId(readin:string):boolean;//验证是否存在传入的读者编号
    function ValBook(isbn:string):string;//验证是否存在传入的图书编号,有则返回书名
  end;

var
  DM: TDM;

implementation

{$R *.dfm}

///////取得数据库中所有的作者名///////
function TDM.GetAuth: TStrings;
begin
  Result:=TStringList.Create;
  ADOQuery.SQL.Text:='select auth_name from auth_info';
  ADOQuery.Prepared;
  ADOQuery.Open;
  while not ADOQuery.Eof do
  begin
    Result.Add(ADOquery.Fields[0].AsString);
    ADOQuery.Next;
  end;
  ADOQuery.Close;
end;

///////取得数据库中所有的出版社名称///////
function TDM.GetPub: TStrings;
begin
  Result:=TStringList.Create;
  ADOquery.SQL.Text:='select pub_name from pub_info';
  ADOQuery.Prepared;
  ADOQuery.Open;
  while not ADOQuery.Eof do
  begin
    Result.Add(ADOQuery.Fields[0].AsString);
    ADOQuery.Next;
  end;
  ADOQuery.Close;
end;

///////取得数据库中所有的类型编号///////
function TDM.GetTypeSno: TStrings;
begin
  Result:=TStringList.Create;
  ADOQuery.SQL.Text:='select type_sno from book_type';
  ADOQuery.Prepared;
  ADOquery.Open;
  while not ADOQuery.Eof do
  begin
    Result.Add(ADOquery.Fields[0].AsString);
    ADOQuery.Next;
  end;
  ADOQuery.Close;
end;

/////////取得数据库中所有的总分类名///////
function TDM.GetTypeGen: TStrings;
begin
  Result:=TStringList.Create;
  ADOQuery.SQL.Text:='select type_gen from book_type group by type_gen';
  ADOquery.Prepared;
  ADOQuery.Open;
  while not ADOQuery.Eof do
  begin
    Result.Add(ADOQuery.Fields[0].AsString);
    ADOQuery.Next;
  end;
  ADOquery.Close;
end;

///////根据传入的总分类名取得其下的所有子分类名///////
function TDM.GetTypeTyp(gen: string): TStrings;
begin
  Result:=TStringList.Create;
  ADOQuery.SQL.Text:='select type_typ from book_type where type_gen=:gen';
  ADOQuery.Parameters.ParamByName('gen').Value:=gen;
  ADOquery.Prepared;
  ADOQuery.Open;
  while not ADOQuery.Eof do
  begin
    Result.Add(ADOQuery.Fields[0].AsString);
    ADOQuery.Next;
  end;
  ADOquery.Close;
end;

///////取得数据库中所有的读者编号///////
function TDM.Getreadid: TStrings;
begin
  Result:=TStringList.Create;
  ADOQuery.SQL.Text:='select read_id from read_info';
  ADOQuery.Prepared;
  ADOquery.Open;
  while not ADOQuery.Eof do
  begin
    Result.Add(ADOQuery.Fields[0].AsString);
    ADOQuery.Next;
  end;
  ADOquery.Close;
end;

///////根据传入的总分类名和子分类名取得对应的编号///////
function TDM.GetSno(gen, typ: string): string;
begin
  ADOQuery.SQL.Text:='select type_sno from book_type where type_gen=:in0 and '+
                     ' type_typ=:in1';
  ADOQuery.Parameters[0].Value:=gen;
  ADOquery.Parameters[1].Value:=typ;
  ADOquery.Prepared;
  ADOquery.Open;
  if ADOquery.RecordCount=1 then
    Result:=ADOquery.Fields[0].AsString
  else
    Result:='';
  ADOquery.Close;
end;

///////取得库存中所有的读者类型编号///////
function TDM.GetReadTyp: TStrings;
begin
  Result:=TStringList.Create;
  ADOQuery.SQL.Text:='select type_sno from read_type';
  ADOquery.Prepared;
  ADOquery.Open;
  while not ADOquery.Eof do
  begin
    Result.Add(ADOquery.Fields[0].asstring);
    ADOquery.Next;
  end;
  ADOquery.Close;
end;

///////取得库存中所有的读者编号///////
function TDM.GetAllReadID: TStrings;
begin
  Result:=TStringList.Create;
  ADOquery.SQL.Text:='select read_id from read_info';
  ADOquery.Prepared;
  ADOquery.Open;
  while not ADOQuery.Eof do
  begin
    Result.Add(ADOquery.Fields[0].AsString);
    ADOquery.Next;
  end;
  ADOquery.Close;
end;

function TDM.ValRead(id: string): boolean;
begin
  ADOQuery.SQL.Text:='select read_id from read_info where read_id=:in0';
  ADOquery.Parameters[0].Value:=id;
  ADOquery.Prepared;
  ADOquery.Open;
  if ADOquery.RecordCount=1 then
    Result:=True
  else
    Result:=False;
  ADOquery.Close;
end;

///////查询库存中是否存在指定的读者类型编号///////
function TDM.ValReadType(sno: string): boolean;
begin
  ADOQuery.SQL.Text:='select type_sno from read_type where type_sno=:in0';
  ADOQuery.Parameters[0].Value:=sno;
  ADOquery.Prepared;
  ADOquery.Open;
  if ADOQuery.RecordCount=1 then
    Result:=True
  else
    Result:=False;
  ADOquery.Close;
end;

///////得到数据库中所有的用户名///////
function TDM.GetUserName: TStrings;
begin
  Result:=TStringList.Create;
  ADOQuery.SQL.Text:='select man_id from man_info';
  ADOQuery.Prepared;
  ADOquery.Open;
  while not ADOQuery.Eof do
  begin
    Result.Add(ADOQuery.Fields[0].AsString);
    ADOQuery.Next;
  end;
  ADOQuery.Close;
end;

///////检验输入的用户名是否存在///////
function TDM.ValUserName(username: string): boolean;
begin
  ADOQuery.SQL.Text:='select man_id from man_info where man_id=:in0';
  ADOquery.Parameters[0].Value:=username;
  ADOquery.Prepared;
  ADOquery.Open;
  if ADOquery.RecordCount=1 then
    Result:=True
  else
    Result:=False;
  ADOquery.Close;
end;

///////验证输入的用户名和密码是否正确////////
function TDM.ValUser(username, password: string): Boolean;
begin
  ADOQuery.SQL.Text:='select man_id from man_info where man_id=:in0 and man_pass=:in1';
  ADOQuery.Parameters[0].Value:=username;
  ADOquery.Parameters[1].Value:=password;
  ADOquery.Prepared;
  ADOquery.Open;
  if ADOquery.RecordCount=1 then
    Result:=True
  else
    Result:=False;
  ADOquery.Close;
end;

///////更改用户密码///////
function TDM.SetUserPass(username, password: string): boolean;
begin
  ADOConn.BeginTrans;
  try
    ADOQuery.SQL.Text:='update man_info set man_pass=:in0 where man_id=:in1';
    ADOquery.Parameters[0].Value:=password;
    ADOquery.Parameters[1].Value:=username;
    ADOquery.Prepared;
    ADOQuery.ExecSQL;
    ADOConn.CommitTrans;
    Result:=True;
  except
    ADOConn.RollbackTrans;
    Result:=False;
  end;
  ADOQuery.Close;
end;

///////保存登录日志///////
procedure TDM.SaveLogIn(username: string);
begin
  ADOConn.BeginTrans;
  try
    ADOQuery.SQL.Text:='insert into entry_log(man_id,entry_date) values(:in0,:in1)';
    ADOquery.Parameters[0].Value:=username;
    ADOquery.Parameters[1].Value:=Now;
    ADOquery.Prepared;
    ADOquery.ExecSQL;
    ADOConn.CommitTrans;
  except
    ADOConn.RollbackTrans;
    raise;
  end;
  ADOquery.Close;
end;

///////取得用户可用菜单/////
function TDM.GetMenu(username: string): TStrings;
var
  i:byte;
begin
  Result:=TstringList.Create;
  ADOquery.SQL.Text:='select lend_reg,return_reg,book_buy,book_query,lend_man,'+
                     'user_man,other_man,log_query from man_info where man_id=:in0';
  ADOquery.Parameters[0].Value:=username;
  ADOquery.Prepared;
  ADOquery.Open;
  for i:=0 to 7 do
    Result.Add(ADOquery.Fields[i].AsString);
  ADOquery.Close;
end;

function TDM.ValReadId(readin: string): boolean;
begin
  ADOQuery.SQL.Text:='select read_id from read_info where read_id=:in0';
  ADOquery.Parameters[0].Value:=readin;
  ADOQuery.Prepared;
  ADOquery.Open;
  if ADOquery.RecordCount=1 then
    Result:=True
  else
    Result:=False;
  ADOquery.Close;
end;

function TDM.ValBook(isbn: string): string;
begin
  ADOQuery.SQL.Text:='select book_name from book_stock where book_isbn=:in0 and lendout="n"';
  ADOQuery.Parameters[0].Value:=isbn;
  ADOquery.Prepared;
  ADOQuery.Open;
  if ADOquery.RecordCount=1 then
    Result:=ADOquery.Fields[0].AsString
  else
    Result:='';
  ADOquery.Close;
end;

procedure TDM.DataModuleCreate(Sender: TObject);
var
  datapath:string;
begin
  DM.ADOConn.Connected:=False;
  datapath:=ExtractFilePath(application.ExeName)+'library.mdb';//动态设置数据库的路径,使得数据库路径为程序的路径
  DM.ADOConn.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+datapath+';Persist Security Info=False';
  DM.ADOConn.Connected:=True;
end;

end.

⌨️ 快捷键说明

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