Delphi7第八天---小型图书管理系统

Delphi 7 同时被 2 个专栏收录
27 篇文章 2 订阅

前两天试着玩GitHub,熟悉了英语,却把头脑给弄大了。

文件夹上传到GitHub总不成功,启动Gitshell后,不到一会,系统就崩了,explorer.exe无法工作,只得重启。

昨天关机、开机试了不少于10次,问题还没解决,先搁在那,等心缓一缓再弄。

有收获的是知道怎么从GitHub中拷贝别人的项目文件。

今天终于把搁置了几天的图书管理系统搞定了,完成了图书查询借阅功能和还书功能两大功能。

现在对这个小型系统做一个总结。

该系统由8个窗体构成,如下表所示:


窗体设计对照表
窗体名称Unit文件窗体功能
Welcomeformwelcome.pas用户登录
MasterformMaster.pas图书管理界面
updatebookformUpdatebook.pas修改图书记录
updatepasswordformupdatepassword.pas修改密码
updatereaderformupdatereader.pas修改读者记录
readerformreader.pas读者服务界面
readerselectformreaderselect.pas图书查询与借阅
readerbackformreaderback.pas图书归还

一、登录功能模块的实现

1、登录模块窗体的设计

radiogroup控件的边框没找到方法隐藏,如果你知道,麻烦在回复中告知。

2、登录模块的代码设计

unit Welcome;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB, ExtCtrls;
//uses master;
type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Label2: TLabel;
    Edit2: TEdit;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    RadioGroup1: TRadioGroup;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses master, reader;    //引用加在实现部分。

{$R *.dfm}
var
  time:Integer=0;
procedure TForm1.Button1Click(Sender: TObject);
var
  str:string;
  results:variant; //16字节可变类型
begin
   ADOTable1.Active:=true;
   {
   if (edit2.Text='admin') and (edit1.Text='123456') then
      showmessage('登陆成功!')
   }
   str:=Edit2.Text;

   results:=ADOTable1.Lookup('LoadName',edit2.Text,'LoadPassword');
   //showmessage(BoolToStr(results=edit1.Text,true));
   if edit2.Text='' then
      begin
         Application.MessageBox('用户名不能为空!','提示',mb_ok);
         edit2.SetFocus;
      end
   else
   if  not ADOTable1.Locate('LoadName',str,[loCaseInsensitive]) then
     begin
        Application.MessageBox('用户名不存在!','提示',mb_ok);
        edit2.Text:='';
        edit1.Text:='';
        edit2.SetFocus;
     end
   else
   if edit1.Text='' then
        Application.MessageBox('密码不能为空!','提示',mb_ok)
   else
   if (results=edit1.Text) then        //重建数据表才验证成功(开始以为是类型转化不对,其实不然)
      begin
        //showmessage('登陆成功!')
        case RadioGroup1.ItemIndex of    //RadioGroup的使用方法
        0:
             masterform.show;
            //form1.Visible:=false;
        1:
            readerform.show;
        end;
      end
   else
      begin
        time:=time+1;
        if time<5 then
          begin
            showmessage('密码错误,请重新输入!');
            edit1.Text:='';
            //edit2.Text:='';
            edit1.SetFocus;  //焦点重新回到edit2
          end
        else
          begin
            messageDlg('对不起,密码输入错误达到5次!请退出。',mtInformation,[mbok],0);
            application.Terminate;
          end;
      end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   close;   //关闭登陆窗口
end;

end.

二、管理员控制模块的实现

1、主界面

1.1、主界面窗体设计


1.2、代码设计

unit master;

interface

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

type
  Tmasterform = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    //procedure Button2Click(Sender: TObject);
    //procedure Button3Click(Sender: TObject);
    //procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  masterform: Tmasterform;

implementation

uses updatebook,updatereader, updatepassword;

{$R *.dfm}

procedure Tmasterform.Button1Click(Sender: TObject);
begin
  updatebookform.show;
end;

procedure Tmasterform.Button2Click(Sender: TObject);
begin
  updatereaderform.Show;
end;

procedure Tmasterform.Button3Click(Sender: TObject);
begin
  updatepasswordform.show;
end;

procedure Tmasterform.Button4Click(Sender: TObject);
begin
    close;
end;

end.

2、子功能模块的实现

2.1 修改图书记录

2.1.1 窗体设计

2.1.2 代码实现

unit updatebook;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB, Mask, DBCtrls, ExtCtrls;

type
  Tupdatebookform = class(TForm)
    Button1: TButton;
    DBNavigator1: TDBNavigator;
    DBEdit1: TDBEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    Button2: TButton;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    Label5: TLabel;
    DBEdit5: TDBEdit;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  updatebookform: Tupdatebookform;

implementation

{$R *.dfm}

procedure Tupdatebookform.Button2Click(Sender: TObject);
begin
  if
    messageDlg('确实要取消吗?',mtinformation,[mbok,mbcancel],0)=mrOk
  then
    begin
      ADOTable1.CancelUpdates;  //取消数据修改
      updatebookform.Close;                   //关闭窗口
    end;
end;

procedure Tupdatebookform.Button1Click(Sender: TObject);
begin
  //ADOTable1.Append;//增加一条空记录
  //ADOTable1.UpdateBatch;//不用post,自动更改
  ADOTable1.UpdateRecord;
  ADOTable1.Post;
end;



end.

2.2 修改读者记录

2.2.1 窗体设计

2.2.2代码设计

unit updatereader;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, StdCtrls, Mask, DBCtrls, ExtCtrls;

type
  Tupdatereaderform = class(TForm)
    DBNavigator1: TDBNavigator;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  updatereaderform: Tupdatereaderform;

implementation

{$R *.dfm}

procedure Tupdatereaderform.Button2Click(Sender: TObject);
begin
  if
    messageDlg('确实要取消吗?',mtinformation,[mbok,mbcancel],0)=mrOk
  then
    begin
      ADOTable1.CancelUpdates;  //取消数据修改
      updatereaderform.Close;                   //关闭窗口
    end;
end;

procedure Tupdatereaderform.Button1Click(Sender: TObject);
begin
    ADOTable1.UpdateBatch;
end;

end.

2.3 修改密码

2.3.1 窗体设计

2.3.2 代码设计

unit updatepassword;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, DBCtrls, ExtCtrls, DB, ADODB;

type
  Tupdatepasswordform = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    Button2: TButton;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    DBNavigator1: TDBNavigator;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  updatepasswordform: Tupdatepasswordform;

implementation

{$R *.dfm}

procedure Tupdatepasswordform.Button2Click(Sender: TObject);
begin
  if
    messageDlg('确实要取消吗?',mtinformation,[mbok,mbcancel],0)=mrOk
  then
    begin
      ADOTable1.CancelUpdates;  //取消数据修改
      updatepasswordform.Close;                   //关闭窗口
    end;
end;

procedure Tupdatepasswordform.Button1Click(Sender: TObject);
begin
  ADOTable1.UpdateBatch;
end;

end.


三、读者服务模块

1、主界面

1.1 主界面窗体设计

1.2 代码设计

unit reader;

interface

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

type
  Treaderform = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Button2: TButton;
    Button3: TButton;
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  readerform: Treaderform;

implementation

uses readerselect, readerback;



{$R *.dfm}

procedure Treaderform.Button3Click(Sender: TObject);
begin
    close;
end;

procedure Treaderform.Button1Click(Sender: TObject);
begin
    readerselectform.show;
end;

procedure Treaderform.Button2Click(Sender: TObject);
begin
   readerbackform.show;
end;

end.
2、子功能模块的实现

2.1  读者查询

2.1.1 窗体设计

2.1.2 代码设计

unit readerselect;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, DBCtrls, ExtCtrls, DB, ADODB;

type
  Treaderselectform = class(TForm)
    Button1: TButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Label6: TLabel;
    Edit1: TEdit;
    Button2: TButton;
    Button3: TButton;
    Label7: TLabel;
    Edit2: TEdit;
    Button4: TButton;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    ADOTable2: TADOTable;
    ADOTable3: TADOTable;
    DataSource1: TDataSource;
    DBEdit5: TDBEdit;
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    p:bool;
    time:tdatetime;
  public
    { Public declarations }
  end;

var
  readerselectform: Treaderselectform;

implementation

{$R *.dfm}

procedure Treaderselectform.Button3Click(Sender: TObject);
begin
  ADOTable1.IndexFieldNames:='bookname';  // 显示数据库表格所采用的索引排序的字段名,从书名索引
  ADOTable1.Open;    //打开数据表
  if ADOTable1.Locate('bookname',edit1.Text,[]) then      //locate 返回ture或false
    p:=true       //如果定位成功则返回true,判断的一个依据
  else
    if MessageDlg('无完全吻合记录,是否查找相似记录',mtConfirmation,[mbYes,mbNo],0)=mryes then
      begin
          if ADOTable1.Locate('bookname',edit1.Text,[loCaseInsensitive ,loPartialKey]) then
            p:=true
          else
            MessageDlg('无法查到您需要的记录,请重新查找',mtConfirmation,[mbYes,mbNo],0);
            edit1.Text:='';
      end;
end;

procedure Treaderselectform.FormCreate(Sender: TObject);
begin
  p:=false;
end;

procedure Treaderselectform.Button2Click(Sender: TObject);
begin
  close;
end;

procedure Treaderselectform.Button4Click(Sender: TObject);
begin
ADOTable1.IndexFieldNames:='author';
  ADOTable1.Open;
  if ADOTable1.Locate('author',edit2.Text,[]) then      //locate 返回ture或false
    p:=true       //如果定位成功则返回true,判断的一个依据
  else
    if MessageDlg('无完全吻合记录,是否查找相似记录',mtConfirmation,[mbYes,mbNo],0)=mryes then
      begin
          if ADOTable1.Locate('author',edit2.Text,[loCaseInsensitive ,loPartialKey]) then
            p:=true
          else
            MessageDlg('无法查到您需要的记录,请重新查找',mtConfirmation,[mbYes,mbNo],0);
            edit1.Text:='';
      end;
end;

procedure Treaderselectform.Button1Click(Sender: TObject);
var
  readersn:string;
begin
   if p=false then
      MessageDlg('请先查找您需要的书。',mtConfirmation,[mbYes],0)
   else
      begin
        if strToint(dbedit5.Text)>0 then
          begin
           inputQuery('输入读者编号','编号为',readersn);
           ADOTable2.IndexFieldNames:='ReaderNo';
           ADOTable2.Open;
           if ADOTable2.Locate('ReaderNo',readersn,[])=false then
              MessageDlg('读者编号错误,请重新输入',mtConfirmation,[mbYes],0)
           else
             begin
               if ADOTable3.lookup('ReaderNo',readersn,'BookNo')=dbedit1.Text then
                 begin
                   MessageDlg('您已借此书,请按时归还!',mtConfirmation,[mbYes],0);
                 end
               else
                 begin
                   ADOTable3.Open;
                   ADOTable3.IndexFieldNames:='BookNo';
                   ADOTable3.Insert;
                   time:=now;
                   ADOTable3.AppendRecord([DBEdit1.Text,readersn,time]);
                   ADOTable1.Edit;
                   ADOTable1.FieldByName('BookState').AsString:=inttostr(strTOint(DBEdit5.Text)-1);
                   ADOTable1.Post;
                   MessageDlg('借书成功!',mtConfirmation,[mbYes],0);
                 end;
               end;
            end
        else
          MessageDlg('该书已借完,请预定。',mtConfirmation,[mbYes],0);
      end;
      end;
end.

2.2还书模块的设计

2.2.1 窗体设计

2.2.2 代码设计

unit readerback;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB, Buttons, Grids, DBGrids;

type
  TReaderbackform = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    DBGrid1: TDBGrid;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    procedure Button1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Readerbackform: TReaderbackform;

implementation

{$R *.dfm}

procedure TReaderbackform.Button1Click(Sender: TObject);
var
  str:string;
begin
  //ADOTable1.Locate('ReaderNo',edit1.Text,[])  trim(Edit1.Text)
  str:=trim(Edit1.Text);
  ADOQUERY1.Close;
  ADOQuery1.SQL.Clear;  //先要设置ADOQuery1的SQL属性
  ADOQUERY1.SQL.Add('select * from Borrow where ReaderNo=:ReaderNo'); //只有这一行不能显示数据,必须加上下面一行
  ADOQuery1.Parameters.ParamByName('ReaderNo').Value:=str;
  ADOQUERY1.Open;
  //showmessage(inttostr(ADOQuery1.RecordCount));   //测试是否有数据
  ADOQUERY1.First;
end;

procedure TReaderbackform.BitBtn2Click(Sender: TObject);
begin
   close;
end;

procedure TReaderbackform.BitBtn1Click(Sender: TObject);
var
  bnum,bname:variant;
  bno,strfield:string;
 // i:integer;
begin
   //i:=4;
   // Rno:=edit1.Text;
    //b1:=ADOQuery1.lookup('ReaderNo',bno,'Bookno');
    //bname:=ADOTable1.lookup('BookNo',b1,'BookName');
    //bnum:=ADOTable1.lookup('BookNo',b1,'BookState');
    //ADOTable1.Locate('Bookname',bname,[]);
    //showmessage(IntToStr(bnum+i));
    //ADOTable1.Locate('Bookno',b1,[]);
    //showmessage('书籍的名称为: '+bname);
      strfield:=DBGrid1.SelectedField.FieldName; //鼠标选中某个字段
      //ShowMessage(ADOQuery1.FieldByName(strfield).AsString);显示选中字段的值
      bno:=ADOQuery1.FieldByName('BookNo').AsString;
      bname:=ADOTable1.lookup('BookNo',bno,'BookName');
      showmessage('书籍的名称为: '+bname);
      bnum:=ADOTable1.lookup('BookNo',bno,'BookState');
   if messagedlg('是否要还书?',mtinformation,[mbyes,mbno],0)=mryes then
     begin

      ADOTable1.Locate('Bookno',bno,[]); //定位到这一行
      //ADOTable1.Locate('Bookname',bname,[]);
      //ADOQuery1.Delete;  //放到这,出现逻辑上的错误,下一种类的书数量加1
      ADOTable1.Edit;  //必须在要修改的命令行之前,中间不能有其他语句
      ADOTable1.FieldByName('BookState').AsInteger:=strtoint(bnum+1);
      ADOTable1.Post;
      ADOQuery1.Delete;  //放的位置对结果有影响
     end;
end;

end.

-------------------------------------------------------------------------------------------------------------------------

系统创建过程中遇到的一些问题及解决方法:



问题分析及解决:SQL服务未开,手动开启。另外,设置ADOTable1.active=true

 


解决方案:修改Data下文件夹权限。具体可见:

http://blog.csdn.net/alisa525/article/details/38702137

 


解决方法:在ADOQuerySQL属性中加上 select * from table1,就可以显示数据,

通过下列方式查询:

ADOQUERY1.SQL.Add('select * from Borrow where ReaderNo=:ReaderNo'); //只有这一行不能显示数据,必须加上下面一行

 ADOQuery1.Parameters.ParamByName('ReaderNo').Value:=str;

 

解决方法:variant是无类型数据,可自适应,出现该错误,先测试,测试见:

b1:=ADOQuery1.lookup('ReaderNo',bno,'Bookno');

bnum:=ADOTable1.lookup('BookNo',b1,'BookState');

showmessage(IntToStr(bnum+i));测试语句

参考网站:http://www.cnblogs.com/youshan/archive/2011/07/10/2102455.html

 

解决方法:在修改语句的上一行加上ADOTable1.edit;

ADOTable1.Edit;  //必须在要修改的命令行之前,中间不能有其他语句

ADOTable1.FieldByName('BookState').AsInteger:=strtoint(bnum+1);

ADOTable1.Post;

-------------------------------------------------------------------------------------------------------------------

码到这了、有不对的地方、麻烦指出。

写代码是会写出感情的、come on.




  • 5
    点赞
  • 0
    评论
  • 10
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

5.4 用户登录窗体的的实现 本窗体是为三种不同的用户(一般用户,工作人员,管理员)提供选择以进入不同的模块,满足不同用户的 需求。源代码比较简单,略。 5.5 用户密码认证窗体的的实现 本窗体是为了让工作人员或图书管理员按照用户名和密码进行登录,并且跟据用户名检查Keyer表中的“权限”字段,以分辩进入图书管理人员模块还是进入工作人员模块。窗体界面、源代码见附录。 5.6 借阅者服务模块的实现 借阅者服务窗体的功能主要是图书的查询,个人借阅情况查看及个人部分信息的修改。 5.6.1 图书查询功能的实现 在这个本系统中,是由本人负责图书查询功能,在系统中任何人都有权限使用查询功能,不做任何限制。由于实现的查询功能有多种,如按图书编号、图书名称等字段进行完全体配查找和部分体配的模糊查找,还有按多个条件进行逻辑与或是逻辑或的多条件查找。其中实现的方法者差不多。 5.6.2 借阅者登录功能的实现 这个功能的实现与工作人员和管理人员登录功能实现的方法大致一样,并且还要简单。是从User表中查到到借阅证号与密码,看与用户输入的是否一致。如果一致,那么用户就可查看自已的借阅情况并维护自己的部分信息。源代码与借阅者登录界面都略。 5.6.3 借阅者借阅情况功能的实现
©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值