赞
踩
这是我大二数据库和 Java 的课设,是一个单机柜台式的书店租赁系统,若是想要联网自助式添加多种权限就可以了,这个系统总的来说不是很完善,但是对于Java和数据库的初学者来说,已经可以作为课设来使用了。
感谢大家的支持 ~~~///(^v^)\\\~~~ 希望大家多多点赞、收藏、加关注!
(一)Java连接数据库模块DateBaseManager实现代码
当今时代是飞速发展的信息时代。在各行各业中离不开信息处理,计算机在各行各业的应用也越来越广泛,为了满足时代的需要,我们开发了许多与实际相应的应用系统。计算机的最大好处在于利用它能够进行信息管理。使用计算机进行信息控制,不仅提高了工作效率,而且大大的提高了其安全性。
关键词:数据库应用;书店租赁系统;Java;SQL sever
书店作为一种信息资源的集散地,图书和用户借阅资料繁多,包含很多的信息数据的管理,现今己有很多书店都配备了书店租赁管理系统,方便店家对图书借阅信息和会员的管理。
据调查,在未引入书店租赁管理系统之前,书店对信息管理的主要方式是基于文本、表格等纸介质的手工处理,缺乏系统,规范的信息管理手段。因此,随着技术的发展,开发适合书店自身情况的书店租赁管理系统便成了一种趋势。
后端数据库采用SQL SERVER建立,通过java swing设计界面,连接数据库,使系统有登录功能,对数据表进行增删改查操作,建立一个完整的书店租赁管理系统。
按照关系型数据库的基本原理,综合运用所学的基本知识,设计开发一个小型的管理系统。巩固Java语言的基础知识,进一步加深对Java可视化程序设计的理解和掌握;将课本上的理论知识和实际有机的结合起来,锻炼学生的分析解决实际问题的能力。
如今人们的生活可谓是五彩缤纷,大部分人开始追求精神上享受,阅读便成为人们精神美餐的一部分。但是有些人又不想买大量的书,读过之后就不去翻开了。因此,图书租赁便开始产生并且不断地发展成为潮流,为了方便租赁型书店的管理人员的管理和提高工作效率,因此我开发了书店租赁管理系统。
许多中小型书店对书店里的图书信息、租赁信息以及会员信息都是采用人工笔记的方式,这是比较传统的、低效率的方法。而如今的计算机技术非常发达,为了给书店提高效率和经济效益,因此利用相关计算机技术开发出一个书店租赁管理系统是很必要的。
在本系统中管理员应该完成如下操作:
如图1所示为功能结构图
如图2所示为数据流图
如表1所示为数据项表
列名 | 数据类型 | 长度 | 是否为空 | 说明 |
Hnum | int | NOT NULL | 会员号,主键,自增 | |
Hname | varchar | 20 | NOT NULL | 会员姓名 |
sex | char | 2 | NOT NULL | 会员性别 |
zhanghu | money | NOT NULL | 会员账户余额 | |
Ddate | datetime | NOT NULL | 会员登记日期 | |
num | varchar | 50 | NOT NULL | 会员电话 |
Bnum | int | NOT NULL | 书号,主键,自增 | |
book | varchar | 20 | NOT NULL | 书名 |
Bname | varchar | 20 | NOT NULL | 书籍作者 |
chubanshe | varchar | 50 | NULL | 书籍出版社 |
jiage | money | NOT NULL | 书籍价格 | |
kucun | int | NOT NULL | 书籍库存量 | |
Bbeizhu | varchar | 50 | NULL | 书籍备注 |
Znum | int | NOT NULL | 租赁号,主键,自增 | |
Jdate | datetime | NOT NULL | 借书日期 | |
Hdate | datetime | NULL | 还书日期 | |
Zbeizhu | varchar | 50 | NULL | 租赁信息备注 |
Gnum | int | NOT NULL | 管理员编号,主键,自增 | |
account | varchar | 40 | NOT NULL | 管理员账号 |
Gpassword | varchar | 40 | NOT NULL | 管理员密码 |
Snum | int | NOT NULL | 收入编号,主键,自增 | |
Sdate | datetime | NOT NULL | 收入日期 | |
sr | money | NOT NULL | 收入 |
如表2所示为数据结构表
名称 | 含义 |
会员信息表(HYXX) | 会员的基本信息 |
书籍信息表(SJXX) | 书籍的基本信息 |
租赁信息表(ZLXX) | 租赁信息 |
管理员信息表(GLYXX) | 管理员的账号和密码 |
收入信息表(SRXX) | 收入情况信息 |
(1)如图3所示为会员E-R图
(2)如图4所示为书籍E-R图
(3)如图5所示为管理员E-R图
如图6所示为总E-R图
本管理系统采用索引存取方法,以下为本系统建立的索引:
- create unique index HYXX_num on HYXX(Hnum);
- create unique index SJXX_num on SJXX(Bnum);
- create unique index ZLXX_num on ZLXX(Znum);
- create unique index GLYXX_num on GLYXX(Gnum);
- create unique index SRXX_num on SRXX(Snum);
在会员号,书号,租赁号,管理员编号和收入编号上建立索引,加快查询速度
根据系统需求,建立会员信息表(HYXX),书籍信息表(SJXX),租赁信息表(ZLXX),管理员信息表(GLYXX),收入信息表(SRXX)共5张表。
如表3所示为会员信息(HYXX)表
列名 | 数据类型 | 长度 | 是否为空 | 说明 |
Hnum | int | NOT NULL | 会员号,主键,自增 | |
Hname | varchar | 20 | NOT NULL | 姓名 |
sex | char | 2 | NOT NULL | 性别 |
zhanghu | money | NOT NULL | 账户余额 | |
Ddate | datetime | NOT NULL | 登记日期 | |
num | varchar | 50 | NOT NULL | 电话 |
如表4所示为书籍信息(SJXX)表
列名 | 数据类型 | 长度 | 是否为空 | 说明 |
Bnum | int | NOT NULL | 书号,主键,自增 | |
book | varchar | 20 | NOT NULL | 书名 |
Bname | varchar | 20 | NOT NULL | 作者 |
chubanshe | varchar | 50 | NULL | 出版社 |
jiage | money | NOT NULL | 价格 | |
kucun | int | NOT NULL | 库存量 | |
Bbeizhu | varchar | 50 | NULL | 备注 |
如表5所示为租赁信息(ZLXX)表
列名 | 数据类型 | 长度 | 是否为空 | 说明 |
Znum | int | NOT NULL | 租赁号,主键,自增 | |
Hnum | int | NOT NULL | 会员号,外键,主键 | |
Hname | varchar | 20 | NOT NULL | 会员姓名 |
Bnum | int | NOT NULL | 书号,外键,主键 | |
book | varchar | 20 | NOT NULL | 书籍名称 |
Bname | varchar | 20 | NOT NULL | 书籍作者 |
chubanshe | varchar | 50 | NULL | 书籍出版社 |
Jdate | datetime | NOT NULL | 借书日期 | |
Hdate | datetime | NULL | 还书日期 | |
jiage | money | NOT NULL | 价格 | |
Zbeizhu | varchar | 50 | NULL | 备注 |
如表6所示为管理员信息(GLYXX)表
列名 | 数据类型 | 长度 | 是否为空 | 说明 |
Gnum | int | NOT NULL | 管理员编号,主键,自增 | |
account | varchar | 40 | NOT NULL | 管理员账号 |
Gpassword | varchar | 40 | NOT NULL | 管理员密码 |
如表7所示为收入信息(SRXX)表
列名 | 数据类型 | 长度 | 是否为空 | 说明 |
Snum | int | NOT NULL | 收入编号,主键,自增 | |
Znum | int | NOT NULL | 租赁号,外键 | |
Hnum | int | NOT NULL | 会员号,外键 | |
Bnum | int | NOT NULL | 书号,外键 | |
Sdate | datetime | NOT NULL | 收入日期 | |
sr | money | NOT NULL | 收入 |
数据文件及日志存放位置为:D:\SDZL
数据文件:逻辑文件名为 SDZL_data,物理文件名为 SDZL.mdf,初始大小为10MB,最大尺寸为无限大,增长速度为20%。
日志文件:逻辑文件名为 SDZL_log ,物理文件名为 SDZL.ldf,初始容量为3MB,最大容量为10MB,增长速度为2MB。
实现代码:
- on
- (
- name = SDZL_data,
- filename = 'D:\SDZL\SDZL.mdf',
- size = 10MB,
- filegrowth = 20%
- )
- log on
- (
- name = SDZL_log,
- filename = 'D:\SDZL\SDZL.ldf',
- size = 3MB,
- maxsize = 10MB,
- filegrowth = 2MB
- )
关系中的主属性不能为空,在数据库中使用 Primary Key 实现。
会员信息表(HYXX)中电话号码(num)设置为唯一约束
租赁信息表(ZLXX)中设置会员号(Hnum)和书号(Bnum)为外码,限制租赁信息表中出现非法的数据;
收入信息表(SRXX)中设置租赁号(Znum)、会员号(Hnum)、书号(Bnum)为外码,限制收入信息表中出现非法的数据。
会员信息表(HYXX)中设置性别(sex)只能为’男’或’女’。
会员信息表(HYXX)中设置性别(sex)默认值为’男’。
(1)SR触发器
在租赁信息表(ZLXX)中建立触发器当会员还书时,实现自动为收入信息表(SRXX)添加收入的相关信息且修改会员信息表(HYXX)中的账户余额,实现代码:
- go
- create trigger SR on ZLXX
- after update
- as
- begin
- declare @znum int
- declare @hnum int
- declare @bnum int
- declare @hdate datetime
- declare @sr money
- select @znum=Znum,@hnum=Hnum,@bnum=Bnum,@hdate=Hdate,@sr=jiage from inserted
- insert into SRXX values (@znum,@hnum,@bnum,@hdate,@sr)
- update HYXX set zhanghu=zhanghu-@sr where Hnum=@hnum
- end
(2)XG触发器
在租赁信息表(ZLXX)中建立触发器,当删除租赁信息时,实现租赁信息表(ZLXX)和收入信息表(SRXX)的级联删除,实现代码:
- go
- create trigger XG on ZLXX
- instead of delete
- as
- begin
- declare @znum int
- select @znum=Znum from deleted
- delete from SRXX where Znum=@znum
- delete from ZLXX where Znum=@znum
- end
将会员信息表(HYXX)、书籍信息表(SJXX)、租赁信息表(ZLXX)建立名为XX的视图,方便查询,实现代码:
- go
- create view XX
- as
- select ZLXX.Znum,HYXX.Hnum,HYXX.Hname,SJXX.Bnum,SJXX.book,ZLXX.Jdate,ZLXX.Hdate,ZLXX.jiage,ZLXX.Zbeizhu
- from HYXX,SJXX,ZLXX
- where HYXX.Hnum = ZLXX.Hnum AND SJXX.Bnum = ZLXX.Bnum
为更方便的进行增删改操作,本系统共设计9种存储过程
接收会员个人信息,自动向会员信息表(HYXX)插入新的记录,实现代码:
- go
- CREATE procedure addh
- @Hname varchar(20),@sex char(2),@zhanghu money,@num varchar(50)
- as
- begin
- INSERT INTO HYXX values (@Hname,@sex,@zhanghu,GETDATE(),@num);
- end
接收会员号,修改会员信息表(HYXX)中的记录,实现代码:
- go
- CREATE procedure modh
- @Hnum int,@Hname varchar(20),@sex char(2),@zhanghu money,@num varchar(50)
- as
- begin
- update HYXX set Hname=@Hname,sex=@sex,zhanghu=@zhanghu,num=@num
- where Hnum=@Hnum;
- end
接收会员号,删除指定会员在会员信息表(HYXX)中的记录,实现代码:
- go
- CREATE procedure delh
- @Hnum int
- as
- begin
- delete from HYXX where Hnum=@Hnum
- end
接收书籍的信息,自动向书籍信息表(SJXX)中添加记录,实现代码:
- go
- CREATE procedure addb
- @book varchar(20),@Bname varchar(20),@chubanshe varchar(50),@jiage money,@kucun int,@Bbeizhu varchar(50)
- as
- begin
- INSERT INTO SJXX values (@book,@Bname,@chubanshe,@jiage,@kucun,@Bbeizhu)
- end
根据指定书号对指定书籍的信息进行修改,实现代码:
- go
- CREATE procedure modb
- @Bnum int,@book varchar(20),@Bname varchar(20),@chubanshe varchar(50),@jiage money,@kucun int,@Bbeizhu varchar(50)
- as
- begin
- update SJXX
- set book=@book,Bname=@Bname,chubanshe=@chubanshe,jiage=@jiage,kucun=@kucun,Bbeizhu=@Bbeizhu
- where Bnum=@Bnum;
- end
根据指定书号对于指定的书籍进行删除,实现代码:
- go
- CREATE procedure delb
- @Bnum int
- as
- begin
- delete from SJXX where Bnum=@Bnum
- end
接收相应的数据,向租赁信息表(ZLXX)插入新的记录,实现代码:
- go
- CREATE procedure jbook
- @Hnum int,@Hname varchar(20),@Bnum int,@book varchar(20),@Zbeizhu varchar(50)
- as
- begin
- INSERT INTO ZLXX values (@Hnum,@Hname,@Bnum,@book,
- (select Bname from SJXX where Bnum=@Bnum),
- (select chubanshe from SJXX where Bnum=@Bnum),
- GETDATE(),null,(select jiage from SJXX where Bnum=@Bnum),
- @Zbeizhu)
- update SJXX set kucun=kucun-1 where Bnum=@Bnum;
- end
根据租赁号和书号进行还书操作,实现代码:
- go
- CREATE procedure hbook
- @Znum int,@Bnum int
- as
- begin
- update ZLXX set Hdate=GETDATE() where Znum=@Znum;
- update SJXX set kucun=kucun+1 where Bnum=@Bnum;
- end
根据租赁号和书号进行删除租赁信息操作,实现代码:
- go
- CREATE procedure dbook
- @Znum int,@Bnum int
- as
- begin
- if((select Hdate from ZLXX where Znum=@Znum) is null )
- begin
- update SJXX set kucun=kucun+1 where Bnum=@Bnum;
- delete from ZLXX where Znum=@Znum;
- end
- else
- delete from ZLXX where Znum=@Znum;
- end
创建SQL sever登录用户AYQ,用于前端连接,实现代码:
- create LOGIN AYQ
- WITH password='123456',
- DEFAULT_DATABASE=SDZL;
创建数据库用户GLY,并赋予GLY数据库所有者权限,实现代码:
- create USER GLY
- FROM LOGIN AYQ
- WITH DEFAULT_SCHEMA = dbo;
- exec sp_addrolemember 'db_owner','GLY'
为本程序的主界面,通过此界面来进行与其他模块的连接。
为本程序的初始界面,通过此界面与数据库中的管理员信息(GLYXX)表进行连接判断是否可以登录本系统。
输入新会员的信息,将信息传输到数据库中,调用存储过程 addh 进行添加会员操作。
查询并显示会员信息,手动进行更改,将更改后的数据存传输到数据库中,调用 modh 进行修改会员信息操作。
输入要删除会员信息的会员号和电话号码,确定身份后,将输入的电话和会员号存传输到数据库中,调用 delh 进行删除会员信息操作。
输入要添加书籍的信息,将信息传输到数据库中,调用存储过程 addb 进行添加书籍操作。
查询并显示书籍信息,操作者进行更改,将更改后的数据存传输到数据库中,调用 modb 进行修改书籍信息操作。
输入要删除的书号,将书号传输到数据库中,调用存储过程 delb 进行删除书籍操作。
输入书号、会员号等信息,核对书籍和会员信息,将信息传输到数据库,调用存储过程 jbook 进行借出书籍操作。
输入书号、会员号、借阅号等信息,对书籍和会员信息,将信息传输到数据库,调用存储过程 hbook 进行还入书籍操作。
输入租赁号、书号、会员号等信息,查询租赁信息,进行更改,将更改后的数据存传输到数据库中,调用 dbook 进行修改租赁信息操作。
进入数据库调出所有的会员信息,输出到界面。
输入要查询书籍的相关信息,进入数据库调出的相关信息,输出到界面。
输入要查询书籍的相关信息,进入数据库调出的相关信息,输出到界面。
输入要查询书籍的相关信息,进入数据库调出的相关信息,输出到界面。
- public class DataBaseManager {
- Connection con = null;
- ResultSet rs = null;
- Statement stmt;
-
- public DataBaseManager() {
- try {
- String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=SDZL";
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- String user="AYQ";
- String password="123456";
- con= DriverManager.getConnection(url,user,password);
- stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (ClassNotFoundException cnfex) {
- cnfex.printStackTrace();
- }
- }
-
- public ResultSet getResult(String strSQL) {
- try {
- rs = stmt.executeQuery(strSQL);
- return rs;
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- return null;
- }
-
- }
-
- public int updateSql(String strSQL) {
- try {
- int i = stmt.executeUpdate(strSQL);
- con.commit();
- return i;
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- return -1;
- }
- }
-
- public void closeConnection() {
- if (rs != null) {
- try {
- rs.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- if (stmt != null) {
- try {
- stmt.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- if (con != null) {
- try {
- con.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- public class MainFrame extends JFrame implements ActionListener {
- JPanel panel1;
- Container c;
- JMenuBar menuB;
- JMenu HYXXMenu, SJXXMenu, ZLXXMenu, XXMenu;
- JMenuItem addHYXXMenu, modifyHYXXMenu, deleteHYXXMenu,
- addSJXXMenu, modifySJXXMenu, deleteSJXXMenu,
- borrowBookMenu, returnBookMenu, modifyZLXXMenu,
- HYXXListMenu, SJXXListMenu, ZLXXListMenu, SRXXListMenu;
- public MainFrame() {
- super("书店租赁管理系统");
- menuB = new JMenuBar();
- //会员信息管理菜单
- HYXXMenu = new JMenu("会员信息管理");
- addHYXXMenu = new JMenuItem("添加会员");
- modifyHYXXMenu= new JMenuItem("修改会员信息");
- deleteHYXXMenu = new JMenuItem("删除会员");
- HYXXMenu.add(addHYXXMenu);
- HYXXMenu.add(modifyHYXXMenu);
- HYXXMenu.add(deleteHYXXMenu);
- addHYXXMenu.addActionListener(this);
- modifyHYXXMenu.addActionListener(this);
- deleteHYXXMenu.addActionListener(this);
- menuB.add(HYXXMenu);
- //书籍信息管理菜单
- SJXXMenu = new JMenu("书籍信息管理");
- addSJXXMenu = new JMenuItem("添加书籍");
- modifySJXXMenu = new JMenuItem("修改书籍信息");
- deleteSJXXMenu = new JMenuItem("删除书籍信息");
- SJXXMenu.add(addSJXXMenu);
- SJXXMenu.add(modifySJXXMenu);
- SJXXMenu.add(deleteSJXXMenu);
- addSJXXMenu.addActionListener(this);
- modifySJXXMenu.addActionListener(this);
- deleteSJXXMenu.addActionListener(this);
- menuB.add(SJXXMenu);
- //租赁信息管理菜单
- ZLXXMenu = new JMenu("租赁信息管理");
- borrowBookMenu = new JMenuItem("借出书籍");
- returnBookMenu = new JMenuItem("还入书籍");
- modifyZLXXMenu = new JMenuItem("修改租赁信息");
- ZLXXMenu.add(borrowBookMenu);
- ZLXXMenu.add(returnBookMenu);
- ZLXXMenu.add(modifyZLXXMenu);
- borrowBookMenu.addActionListener(this);
- returnBookMenu.addActionListener(this);
- modifyZLXXMenu.addActionListener(this);
- menuB.add(ZLXXMenu);
- //信息查询管理菜单
- XXMenu = new JMenu("信息查询管理");
- HYXXListMenu = new JMenuItem("会员信息查询");
- SJXXListMenu = new JMenuItem("书籍信息查询");
- ZLXXListMenu = new JMenuItem("借阅信息查询");
- SRXXListMenu = new JMenuItem("收入信息查询");
- XXMenu.add(HYXXListMenu);
- XXMenu.add(SJXXListMenu);
- XXMenu.add(ZLXXListMenu);
- XXMenu.add(SRXXListMenu);
- HYXXListMenu.addActionListener(this);
- SJXXListMenu.addActionListener(this);
- ZLXXListMenu.addActionListener(this);
- SRXXListMenu.addActionListener(this);
- menuB.add(XXMenu);
-
- setJMenuBar(menuB);
- c = getContentPane();
- c.setLayout(new BorderLayout());
- panel1 = new JPanel();
- panel1.setLayout(new BorderLayout());
- c.add(panel1, BorderLayout.CENTER);
- }
-
- //设置每个菜单点击后出现的窗口和窗口显示的位置
- public void actionPerformed(ActionEvent e) {
- if (e.getActionCommand() == "添加会员") {
- AddHYXX UserAddFrame = new AddHYXX();
- Dimension FrameSize = UserAddFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- UserAddFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- UserAddFrame.pack();
- UserAddFrame.show();
- }
- else if (e.getActionCommand() == "修改会员信息") {
- ModifyHYXX UserModifyFrame = new ModifyHYXX();
- Dimension FrameSize = UserModifyFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- UserModifyFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- UserModifyFrame.pack();
- UserModifyFrame.show();
- }
- else if (e.getActionCommand() == "删除会员") {
- DeleteHYXX UserDeleteFrame = new DeleteHYXX();
- Dimension FrameSize = UserDeleteFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- UserDeleteFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- UserDeleteFrame.pack();
- UserDeleteFrame.show();
- }
- else if (e.getActionCommand() == "添加书籍") {
- AddSJXX BookAddFrame = new AddSJXX();
- Dimension FrameSize = BookAddFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- BookAddFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- BookAddFrame.pack();
- BookAddFrame.show();
- }
- else if (e.getActionCommand() == "修改书籍信息") {
- ModfiySJXX BookDeleteFrame = new ModfiySJXX();
- Dimension FrameSize = BookDeleteFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- BookDeleteFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- BookDeleteFrame.pack();
- BookDeleteFrame.show();
- }
- else if (e.getActionCommand() == "删除书籍信息") {
- DeleteSJXX BookDeleteFrame = new DeleteSJXX();
- Dimension FrameSize = BookDeleteFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- BookDeleteFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- BookDeleteFrame.pack();
- BookDeleteFrame.show();
- }
- else if (e.getActionCommand() == "借出书籍") {
- BorrowZLXX BookDeleteFrame = new BorrowZLXX();
- Dimension FrameSize = BookDeleteFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- BookDeleteFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- BookDeleteFrame.pack();
- BookDeleteFrame.show();
- }
- else if (e.getActionCommand() == "还入书籍") {
- ReturnZLXX BookDeleteFrame = new ReturnZLXX();
- Dimension FrameSize = BookDeleteFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- BookDeleteFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- BookDeleteFrame.pack();
- BookDeleteFrame.show();
- }
- else if (e.getActionCommand() == "修改租赁信息") {
- ModfiyZLXX BookDeleteFrame = new ModfiyZLXX();
- Dimension FrameSize = BookDeleteFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- BookDeleteFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- BookDeleteFrame.pack();
- BookDeleteFrame.show();
- }
- else if (e.getActionCommand() == "会员信息查询") {
- ListHYXX BookDeleteFrame = new ListHYXX();
- Dimension FrameSize = BookDeleteFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- BookDeleteFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- BookDeleteFrame.pack();
- BookDeleteFrame.show();
- }
- else if (e.getActionCommand() == "书籍信息查询") {
- ListSJXX BookDeleteFrame = new ListSJXX();
- Dimension FrameSize = BookDeleteFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- BookDeleteFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- BookDeleteFrame.pack();
- BookDeleteFrame.show();
- }
- else if (e.getActionCommand() == "借阅信息查询") {
- ListZLXX BookDeleteFrame = new ListZLXX();
- Dimension FrameSize = BookDeleteFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- BookDeleteFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- BookDeleteFrame.pack();
- BookDeleteFrame.show();
- }
- else if (e.getActionCommand() == "收入信息查询") {
- ListSRXX BookDeleteFrame = new ListSRXX();
- Dimension FrameSize = BookDeleteFrame.getPreferredSize();
- Dimension MainFrameSize = getSize();
- Point loc = getLocation();
- BookDeleteFrame.setLocation( (MainFrameSize.width - FrameSize.width) / 2 + loc.x,
- (MainFrameSize.height - FrameSize.height) / 2 + loc.y);
- BookDeleteFrame.pack();
- BookDeleteFrame.show();
- }
- }
- }
- public class LoginFrame extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- JPanel panel1, panel2;
- JLabel userLabel, passwordLabel;
- JTextField userTextField;
- JPasswordField passwordTextField;
- JButton yesBtn, cancelBtn;
- Container c;
- ResultSet rs;
- static String username,passwordSTR;
- static Statement stmt;
- public LoginFrame() {
- super("程序登录");
- //添加Label
- userLabel = new JLabel("账户", JLabel.CENTER);
- passwordLabel = new JLabel("密码", JLabel.CENTER);
- //添加TextField
- userTextField = new JTextField(20);
- passwordTextField = new JPasswordField(20);
- //添加Button
- yesBtn = new JButton("确定");
- cancelBtn = new JButton("取消");
- yesBtn.addActionListener(this);
- cancelBtn.addActionListener(this);
- //填充容器
- panel1 = new JPanel();
- panel1.setLayout(new GridLayout(2, 2));
- panel2 = new JPanel();
- c = getContentPane();
- c.setLayout(new BorderLayout());
- panel1.add(userLabel);
- panel1.add(userTextField);
- panel1.add(passwordLabel);
- panel1.add(passwordTextField);
- userTextField.setText("AYQ");
- c.add(panel1, BorderLayout.CENTER);
- panel2.add(yesBtn);
- panel2.add(cancelBtn);
- c.add(panel2, BorderLayout.SOUTH);
- setSize(240, 140);
-
- }
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == cancelBtn) {
- this.dispose();
- } else {
- char[] password = passwordTextField.getPassword();
- username = userTextField.getText().trim();
- passwordSTR = new String(password);
- if (userTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "用户名不可为空!");
- return;
- }
- if (passwordSTR.equals("")) {
- JOptionPane.showMessageDialog(null, "密码不可为空!");
- return;
- }
- String strSQL;
- strSQL = "select * from GLYXX where account='" + username + "'and Gpassword='" + passwordSTR + "'";
- rs = db.getResult(strSQL);
- boolean isExist = false;
- try {
- isExist = rs.first();
- } catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- if (!isExist) {
- JOptionPane.showMessageDialog(null, "账户或密码输入错误!");
-
- } else {
- try {
- rs.first();
- JOptionPane.showMessageDialog(null, "登陆成功");
- this.dispose();
- MainFrame mainFrame = new MainFrame();
- mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- mainFrame.setSize(500,400);
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
- mainFrame.setLocation( (d.width - mainFrame.getSize().width) / 2,
- (d.height - mainFrame.getSize().height) / 2);
- mainFrame.show();
- } catch (SQLException sqle2) {
- System.out.println(sqle2.toString());
- }
- }
- }
- }
- public static void main(String args[]) {
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- }
- catch (Exception e) {
- e.printStackTrace();
- }
-
- LoginFrame loginframe = new LoginFrame();
- loginframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
- loginframe.setLocation( (d.width - loginframe.getSize().width) / 2,
- (d.height - loginframe.getSize().height) / 2);
- loginframe.pack();
- loginframe.show();
- }
- }
- public class AddHYXX extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- Container c;
- JPanel panel1, panel2;
- JLabel HnameLabel, sexLabel, zhanghuLabel, numLabel;
- JTextField HnameTextField, zhanghuTextField, numTextField;
- JComboBox sexComboBox;
- JButton addBtn, cancelBtn;
- public AddHYXX() { //构建界面
- super("添加会员");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- //添加label
- HnameLabel = new JLabel("姓名", JLabel.CENTER);
- sexLabel = new JLabel("性别", JLabel.CENTER);
- zhanghuLabel = new JLabel("充值金额", JLabel.CENTER);
- numLabel = new JLabel("电话号码", JLabel.CENTER);
- //添加TextField
- HnameTextField = new JTextField(20);
- zhanghuTextField = new JTextField(20);
- numTextField = new JTextField(20);
- //添加ComboBox
- sexComboBox = new JComboBox();
- sexComboBox.addItem("男");
- sexComboBox.addItem("女");
- //添加Button
- addBtn = new JButton("添加");
- cancelBtn = new JButton("取消");
- addBtn.addActionListener(this);
- cancelBtn.addActionListener(this);
- //填充容器 信息填写区
- panel1 = new JPanel();
- panel1.setLayout(new GridLayout(4, 2));
- panel1.add(HnameLabel);
- panel1.add(HnameTextField);
- panel1.add(sexLabel);
- panel1.add(sexComboBox);
- panel1.add(zhanghuLabel);
- panel1.add(zhanghuTextField);
- panel1.add(numLabel);
- panel1.add(numTextField);
- c.add(panel1, BorderLayout.CENTER);
- //下方按钮区
- panel2 = new JPanel();
- panel2.add(addBtn);
- panel2.add(cancelBtn);
- c.add(panel2, BorderLayout.SOUTH);
- setSize(250, 100);
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == cancelBtn) { //取消按钮
- db.closeConnection();
- this.dispose();
- }
- else if (e.getSource() == addBtn) { //添加按钮
- try {
- String strSQL = "select * from HYXX where num='" + numTextField.getText().trim() + "'"; //判断电话号sql语句
- if (HnameTextField.getText().trim().equals("")) { //判断姓名是否为空
- JOptionPane.showMessageDialog(null, "姓名不能为空!");
- } else if (zhanghuTextField.getText().trim().equals("")) { //判断充值金额是否为空
- JOptionPane.showMessageDialog(null, "充值金额不能为空!");
- } else if (numTextField.getText().trim().equals("")) { //判断电话号码是否为空
- JOptionPane.showMessageDialog(null, "电话号码不能为空!");
- } else {
- if (db.getResult(strSQL).first()) { //判断电话是否被注册过
- JOptionPane.showMessageDialog(null, "此电话号码已经被注册,请重新输入!");
- } else {
- //调用 添加会员信息 存储过程语句
- strSQL = "{call addh ('" +
- HnameTextField.getText().trim() + "','" +
- sexComboBox.getSelectedItem() + "'," +
- zhanghuTextField.getText().trim() + ",'" +
- numTextField.getText().trim() + "')}";
- if (db.updateSql(strSQL) > 0) { //判断是否成功执行
- //rs = db.getResult(strSQL);
- JOptionPane.showMessageDialog(null, "添加用户成功!");
- db.closeConnection();
- this.dispose();
- } else {
- JOptionPane.showMessageDialog(null, "添加用户失败!");
- db.closeConnection();
- this.dispose();
- }
- }
- }
- } catch (SQLException sqle) {
- System.out.println(sqle.toString());
- } catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- }
- }
- public class ModifyHYXX extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- JPanel panel1, panel2;
- Container c;
- JLabel HnumLabel, HnameLabel, sexLabel, zhanghuLabel, numLabel;
- JTextField HnumTextField, HnameTextField, sexTextField, zhanghuTextField, numTextField;
- JButton UpdateBtn, CancelBtn, clearBtn, selBtn;
- public ModifyHYXX() { //创建界面
- super("修改会员信息");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- //添加Label
- HnumLabel = new JLabel("会员号", JLabel.CENTER);
- HnameLabel = new JLabel("姓名", JLabel.CENTER);
- sexLabel = new JLabel("性别", JLabel.CENTER);
- zhanghuLabel = new JLabel("账户余额", JLabel.CENTER);
- numLabel = new JLabel("电话号码", JLabel.CENTER);
- //添加TextField
- HnumTextField = new JTextField(10);
- HnameTextField = new JTextField(20);
- sexTextField = new JTextField(2);
- zhanghuTextField = new JTextField(20);
- numTextField = new JTextField(20);
- //添加Button
- clearBtn = new JButton("清空");
- selBtn = new JButton("查询");
- UpdateBtn = new JButton("更新");
- CancelBtn = new JButton("取消");
- clearBtn.addActionListener(this);
- selBtn.addActionListener(this);
- UpdateBtn.addActionListener(this);
- CancelBtn.addActionListener(this);
- UpdateBtn.setEnabled(false);
- //填充容器 信息处理区
- panel1 = new JPanel();
- panel1.setLayout(new GridLayout(5, 2));
- panel1.add(HnumLabel);
- panel1.add(HnumTextField);
- panel1.add(HnameLabel);
- panel1.add(HnameTextField);
- panel1.add(sexLabel);
- panel1.add(sexTextField);
- panel1.add(zhanghuLabel);
- panel1.add(zhanghuTextField);
- panel1.add(numLabel);
- panel1.add(numTextField);
- c.add(panel1, BorderLayout.CENTER);
- //下方按钮区
- panel2 = new JPanel();
- panel2.add(clearBtn);
- panel2.add(selBtn);
- panel2.add(UpdateBtn);
- panel2.add(CancelBtn);
- c.add(panel2, BorderLayout.SOUTH);
- setSize(300, 300);
-
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == CancelBtn) { //取消按钮
- db.closeConnection();
- this.dispose();
- }
- else if (e.getSource() == clearBtn) { //清空按钮
- HnumTextField.setText("");
- HnameTextField.setText("");
- sexTextField.setText("");
- zhanghuTextField.setText("");
- numTextField.setText("");
- UpdateBtn.setEnabled(false);
- }
- else if (e.getSource() == selBtn) { //查询按钮
- try {
- String strSQL = "select * from HYXX where Hnum=" + HnumTextField.getText().trim(); //查找会员信息sql语句
- if (HnumTextField.getText().trim().equals("")) { //判断是否输入会员号
- JOptionPane.showMessageDialog(null, "请输入会员号!");
- }
- else if (!db.getResult(strSQL).first()) { //判断是否有此会员
- JOptionPane.showMessageDialog(null, "没有此会员,请重新输入!");
- }
- else { //将查询到的信息放到文本框
- rs = db.getResult(strSQL);
- rs.first();
- HnameTextField.setText(rs.getString(2).trim());
- sexTextField.setText(rs.getString(3).trim());
- zhanghuTextField.setText(rs.getString(4).trim());
- numTextField.setText(rs.getString(6).trim());
- UpdateBtn.setEnabled(true);
- }
- }
- catch (NullPointerException upe) {
- System.out.println(upe.toString());
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- else if (e.getSource() == UpdateBtn) { //更新按钮
- //调用存储过程
- try {
- String strSQL = "select * from HYXX where num='" + numTextField.getText().trim() + "'"; //判断电话号sql语句
- if (HnameTextField.getText().trim().equals("")) { //判断姓名是否为空
- JOptionPane.showMessageDialog(null, "姓名不能为空!");
- } else if (sexTextField.getText().trim().equals("")) { //判断性别是否为空
- JOptionPane.showMessageDialog(null, "性别不能为空!");
- } else if (zhanghuTextField.getText().trim().equals("")) { //判断账户余额否为空
- JOptionPane.showMessageDialog(null, "账户余额不能为空!");
- } else if (numTextField.getText().trim().equals("")) { //判断电话号码是否为空
- JOptionPane.showMessageDialog(null, "电话号码不能为空!");
- } else {
- if (db.getResult(strSQL).first()) { //判断电话是否被注册过
- JOptionPane.showMessageDialog(null, "此电话号码已经被注册,请重新输入!");
- } else {
- strSQL = "{call modh (" +
- HnumTextField.getText().trim() + ",'" +
- HnameTextField.getText().trim() + "','" +
- sexTextField.getText().trim() + "'," +
- zhanghuTextField.getText().trim() + ",'" +
- numTextField.getText().trim() + "')}";
- if (db.updateSql(strSQL) > 0) {
- //rs = db.getResult(strSQL);
- JOptionPane.showMessageDialog(null, "更新书籍信息成功!");
- db.closeConnection();
- this.dispose();
- } else {
- JOptionPane.showMessageDialog(null, "更新书籍信息失败!");
- db.closeConnection();
- this.dispose();
- }
- }
- }
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- }
- }
- public class DeleteHYXX extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- JPanel panel1, panel2;
- Container c;
- JLabel HnumLabel, HnameLabel, sexLabel, zhanghuLabel, numLabel;
- JTextField HnumTextField, HnameTextField, sexTextField, zhanghuTextField, numTextField;
-
- JButton selBtn, cancelBtn, clearBtn, deteleBtn;
- public DeleteHYXX() {
- super("删除会员");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- //添加Label
- HnumLabel = new JLabel("会员号", JLabel.CENTER);
- HnameLabel = new JLabel("姓名", JLabel.CENTER);
- sexLabel = new JLabel("性别", JLabel.CENTER);
- zhanghuLabel = new JLabel("账户余额", JLabel.CENTER);
- numLabel = new JLabel("电话号码", JLabel.CENTER);
- //添加TextField
- HnumTextField = new JTextField(10);
- HnameTextField = new JTextField(20);
- sexTextField = new JTextField(2);
- zhanghuTextField = new JTextField(20);
- numTextField = new JTextField(20);
- //添加Button
- clearBtn = new JButton("清空");
- selBtn = new JButton("查询");
- deteleBtn = new JButton("删除");
- cancelBtn = new JButton("取消");
- clearBtn.addActionListener(this);
- selBtn.addActionListener(this);
- deteleBtn.addActionListener(this);
- cancelBtn.addActionListener(this);
- deteleBtn.setEnabled(false);
- //填充容器 信息处理区
- panel1 = new JPanel();
- panel1.setLayout(new GridLayout(5, 2));
- panel1.add(HnumLabel);
- panel1.add(HnumTextField);
- panel1.add(HnameLabel);
- panel1.add(HnameTextField);
- panel1.add(sexLabel);
- panel1.add(sexTextField);
- panel1.add(zhanghuLabel);
- panel1.add(zhanghuTextField);
- panel1.add(numLabel);
- panel1.add(numTextField);
- c.add(panel1, BorderLayout.CENTER);
- //按钮区
- panel2 = new JPanel();
- panel2.add(clearBtn);
- panel2.add(selBtn);
- panel2.add(deteleBtn);
- panel2.add(cancelBtn);
- c.add(panel2, BorderLayout.SOUTH);
- setSize(300, 300);
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == cancelBtn) { //取消按钮
- db.closeConnection();
- this.dispose();
- }
- else if (e.getSource() == clearBtn) { //清空按钮
- HnumTextField.setText("");
- HnameTextField.setText("");
- sexTextField.setText("");
- zhanghuTextField.setText("");
- numTextField.setText("");
- deteleBtn.setEnabled(false);
- }
- else if (e.getSource() == selBtn) { //查询按钮
- try {
- String strSQL = "select * from HYXX where Hnum=" +
- HnumTextField.getText().trim() + "AND num='" +
- numTextField.getText().trim() + "'"; //查找会员信息sql语句
- if (HnumTextField.getText().trim().equals("")) { //判断是否输入会员号
- JOptionPane.showMessageDialog(null, "请输入会员号!");
- }
- else if (numTextField.getText().trim().equals("")) { //判断是否输入电话号
- JOptionPane.showMessageDialog(null, "请输入电话号码!");
- }
- else if (!db.getResult(strSQL).first()) { //判断是否有此会员号
- JOptionPane.showMessageDialog(null, "没有此会员,请重新输入!");
- }
- else { //将查询到的信息放到文本框
- rs = db.getResult(strSQL);
- rs.first();
- HnameTextField.setText(rs.getString(2).trim());
- sexTextField.setText(rs.getString(3).trim());
- zhanghuTextField.setText(rs.getString(4).trim());
- deteleBtn.setEnabled(true);
- }
- }
- catch (NullPointerException upe) {
- System.out.println(upe.toString());
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- else if (e.getSource() == deteleBtn) {
- try {
- String strSQL = "select * from HYXX where Hnum=" +
- HnumTextField.getText().trim() + "AND num='" +
- numTextField.getText().trim() + "'"; //查找会员信息sql语句
- if (HnumTextField.getText().trim().equals("")) { //判断是否输入会员号
- JOptionPane.showMessageDialog(null, "请输入会员号!");
- } else if (numTextField.getText().trim().equals("")) { //判断是否输入电话号
- JOptionPane.showMessageDialog(null, "请输入电话号码!");
- } else {
- if (db.getResult(strSQL).first()) {
- strSQL = "{call delh (" + HnumTextField.getText().trim() + ")}";
- if (db.updateSql(strSQL) > 0) {
- //rs = db.getResult(strSQL);
- JOptionPane.showMessageDialog(null, "删除会员信息成功!");
- db.closeConnection();
- this.dispose();
- } else {
- JOptionPane.showMessageDialog(null, "删除会员信息失败!");
- db.closeConnection();
- this.dispose();
- }
- } else {
- JOptionPane.showMessageDialog(null, "没有此会员,请重新输入!");
- }
- }
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
-
- }
- }
- public class AddSJXX extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- JPanel panel1, panel2;
- JLabel bookLabel, BnameLabel, chubansheLabel, jiageLabel, kucunLabel, BbeizhuLabel;
- JTextField bookTextField, BnameTextField, chubansheTextField, jiageTextField, kucunTextField, BbeizhuTextField;
- Container c;
- JButton clearBtn, addBtn, exitBtn;
- public AddSJXX() {
- super("添加书籍");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- //添加Label
- bookLabel = new JLabel("书名", JLabel.CENTER);
- BnameLabel = new JLabel("作者", JLabel.CENTER);
- chubansheLabel = new JLabel("出版社", JLabel.CENTER);
- jiageLabel = new JLabel("价格", JLabel.CENTER);
- kucunLabel = new JLabel("库存量", JLabel.CENTER);
- BbeizhuLabel = new JLabel("备注", JLabel.CENTER);
- //添加TextField
- bookTextField = new JTextField(25);
- BnameTextField = new JTextField(25);
- chubansheTextField = new JTextField(25);
- jiageTextField = new JTextField(25);
- kucunTextField = new JTextField(25);
- BbeizhuTextField = new JTextField(25);
- //添加Button
- addBtn = new JButton("添加");
- addBtn.addActionListener(this);
- exitBtn = new JButton("退出");
- exitBtn.addActionListener(this);
- //填充容器 信息处理区
- panel1 = new JPanel();
- panel1.setLayout(new GridLayout(6, 2));
- panel1.add(bookLabel);
- panel1.add(bookTextField);
- panel1.add(BnameLabel);
- panel1.add(BnameTextField);
- panel1.add(chubansheLabel);
- panel1.add(chubansheTextField);
- panel1.add(jiageLabel);
- panel1.add(jiageTextField);
- panel1.add(kucunLabel);
- panel1.add(kucunTextField);
- panel1.add(BbeizhuLabel);
- panel1.add(BbeizhuTextField);
- //按钮区
- panel2 = new JPanel();
- panel2.setLayout(new GridLayout(1, 2));
- panel2.add(addBtn);
- panel2.add(exitBtn);
- c.add(panel1, BorderLayout.CENTER);
- c.add(panel2, BorderLayout.SOUTH);
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == exitBtn) { //退出按钮
- db.closeConnection();
- this.dispose();
- }
- else if (e.getSource() == addBtn) { //添加按钮
- if (bookTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "书名不能为空!");
- }
- else if (BnameLabel.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "作者不能为空!");
- }
- else if (chubansheTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "出版社不能为空!");
- }
- else if (jiageTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "价格不能为空!");
- }
- else if (kucunTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "库存不能为空!");
- }
- else {
- try {
- String strSQL = "{call addb ('"+
- bookTextField.getText().trim() + "','" +
- BnameTextField.getText().trim() + "','" +
- chubansheTextField.getText().trim() + "','" +
- jiageTextField.getText().trim() + "','" +
- kucunTextField.getText().trim() + "','" +
- BbeizhuTextField.getText().trim() + "')}";
- if (db.updateSql(strSQL) > 0) { //判断是否成功执行
- //rs = db.getResult(strSQL);
- JOptionPane.showMessageDialog(null, "添加书籍成功!");
- db.closeConnection();
- this.dispose();
- } else {
- JOptionPane.showMessageDialog(null, "添加书籍失败!");
- db.closeConnection();
- this.dispose();
- }
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- }
- }
- }
- public class ModfiySJXX extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- JPanel panel1, panel2, panel3;
- JLabel TipLabel = new JLabel("输入书号点击查询,将调出此书相关信息");
- JLabel BnumLabel, bookLabel, BnameLabel, chubansheLabel, jiageLabel, kucunLabel, BbeizhuLabel;
- JTextField BnumTextField, bookTextField, BnameTextField, chubansheTextField, jiageTextField, kucunTextField, BbeizhuTextField;
- Container c;
- JButton clearBtn, selBtn, updateBtn, exitBtn;
- public ModfiySJXX() {
- super("修改书籍信息");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- //提示信息
- panel3 = new JPanel();
- panel3.add(TipLabel);
- c.add(panel3, BorderLayout.NORTH);
- //添加Label
- BnumLabel= new JLabel("书号", JLabel.CENTER);
- bookLabel = new JLabel("书名", JLabel.CENTER);
- BnameLabel = new JLabel("作者", JLabel.CENTER);
- chubansheLabel = new JLabel("出版社", JLabel.CENTER);
- jiageLabel = new JLabel("价格", JLabel.CENTER);
- kucunLabel = new JLabel("库存量", JLabel.CENTER);
- BbeizhuLabel = new JLabel("备注", JLabel.CENTER);
- //添加TextField
- BnumTextField = new JTextField(25);
- bookTextField = new JTextField(25);
- BnameTextField = new JTextField(25);
- chubansheTextField = new JTextField(25);
- jiageTextField = new JTextField(25);
- kucunTextField = new JTextField(25);
- BbeizhuTextField = new JTextField(25);
- //添加Button
- clearBtn = new JButton("清空");
- selBtn = new JButton("查询");
- updateBtn = new JButton("更新");
- exitBtn = new JButton("退出");
- clearBtn.addActionListener(this);
- selBtn.addActionListener(this);
- updateBtn.addActionListener(this);
- exitBtn.addActionListener(this);
- updateBtn.setEnabled(false);
- //填充容器 信息处理区
- panel1 = new JPanel();
- panel1.setLayout(new GridLayout(7, 2));
- panel1.add(BnumLabel);
- panel1.add(BnumTextField);
- panel1.add(bookLabel);
- panel1.add(bookTextField);
- panel1.add(BnameLabel);
- panel1.add(BnameTextField);
- panel1.add(chubansheLabel);
- panel1.add(chubansheTextField);
- panel1.add(jiageLabel);
- panel1.add(jiageTextField);
- panel1.add(kucunLabel);
- panel1.add(kucunTextField);
- panel1.add(BbeizhuLabel);
- panel1.add(BbeizhuTextField);
- //按钮区
- panel2 = new JPanel();
- panel2.setLayout(new GridLayout(1, 4));
- panel2.add(clearBtn);
- panel2.add(selBtn);
- panel2.add(updateBtn);
- panel2.add(exitBtn);
- c.add(panel1, BorderLayout.CENTER);
- c.add(panel2, BorderLayout.SOUTH);
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == exitBtn) { //退出按钮
- db.closeConnection();
- this.dispose();
- }
- else if (e.getSource() == clearBtn) { //清空按钮
- BnumTextField.setText("");
- bookTextField.setText("");
- BnameTextField.setText("");
- chubansheTextField.setText("");
- jiageTextField.setText("");
- kucunTextField.setText("");
- BbeizhuTextField.setText("");
- updateBtn.setEnabled(false);
- }
- else if (e.getSource() == selBtn) { //查询按钮
- try {
- String strSQL = "select * from SJXX where Bnum=" + BnumTextField.getText().trim();
- if (BnumTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "请输入书号!");
- }
- else if (!db.getResult(strSQL).first()) {
- JOptionPane.showMessageDialog(null, "库中没有此书!");
- }
- else {
- rs = db.getResult(strSQL);
- rs.first();
- bookTextField.setText(rs.getString(2).trim());
- BnameTextField.setText(rs.getString(3).trim());
- chubansheTextField.setText(rs.getString(4).trim());
- jiageTextField.setText(rs.getString(5).trim());
- kucunTextField.setText(rs.getString(6).trim());
- BbeizhuTextField.setText(rs.getString(7).trim());
- updateBtn.setEnabled(true);
- }
- }
- catch (NullPointerException upe) {
- System.out.println(upe.toString());
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- else if (e.getSource() == updateBtn) {
- try {
- if (BnumTextField.getText().trim().equals("")) { //判断书号是否为空
- JOptionPane.showMessageDialog(null, "书号不能为空!");
- } else if (bookTextField.getText().trim().equals("")) { //判断书名是否为空
- JOptionPane.showMessageDialog(null, "书名不能为空!");
- } else if (BnameTextField.getText().trim().equals("")) { //判断作者是否为空
- JOptionPane.showMessageDialog(null, "作者不能为空!");
- } else if (chubansheTextField.getText().trim().equals("")) { //判断出版社是否为空
- JOptionPane.showMessageDialog(null, "出版社不能为空!");
- } else if (jiageTextField.getText().trim().equals("")) { //判断价格是否为空
- JOptionPane.showMessageDialog(null, "价格不能为空!");
- } else if (kucunTextField.getText().trim().equals("")) { //判断库存是否为空
- JOptionPane.showMessageDialog(null, "库存不能为空!");
- } else {
- String strSQL = "{call modb (" +
- BnumTextField.getText().trim() + ",'" +
- bookTextField.getText().trim() + "','" +
- BnameTextField.getText().trim() + "','" +
- chubansheTextField.getText().trim() + "'," +
- jiageTextField.getText().trim() + "," +
- kucunTextField.getText().trim() + ",'" +
- BbeizhuTextField.getText().trim() + "')}";
- if (db.updateSql(strSQL) > 0) {
- //rs = db.getResult(strSQL);
- JOptionPane.showMessageDialog(null, "更新书籍信息成功!");
- db.closeConnection();
- this.dispose();
- } else {
- JOptionPane.showMessageDialog(null, "更新书籍信息失败!");
- db.closeConnection();
- this.dispose();
- }
- }
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- }
- }
- public class DeleteSJXX extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- Container c;
- JLabel TipLabel = new JLabel("请输入要删除的书号:", JLabel.CENTER);
- JTextField bookDeleteTextField = new JTextField(40);
- JButton yesBtn, exitBtn;
- JPanel panel1 = new JPanel();
- public DeleteSJXX() {
- super("删除书籍信息");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- c.add(TipLabel, BorderLayout.NORTH);
- c.add(bookDeleteTextField, BorderLayout.CENTER);
- yesBtn = new JButton("确定");
- exitBtn = new JButton("退出");
- yesBtn.addActionListener(this);
- exitBtn.addActionListener(this);
- panel1.add(yesBtn);
- panel1.add(exitBtn);
- c.add(panel1, BorderLayout.SOUTH);
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == exitBtn) {
- db.closeConnection();
- this.dispose();
- }
- else if (e.getSource() == yesBtn) {
- try {
- String strSQL = "select * from SJXX where Bnum=" + bookDeleteTextField.getText().trim();
- if (bookDeleteTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "请输入书号!");
- } else if (!db.getResult(strSQL).first()) {
- JOptionPane.showMessageDialog(null, "书库里没有你要删除的书!");
- } else {
- strSQL = "select * from ZLXX where Bnum=" + bookDeleteTextField.getText().trim() + "and Hdate is null";
- if (db.getResult(strSQL).first()) {
- JOptionPane.showMessageDialog(null, "此书还有会员没有还!\n现在还不能从书库中删除!");
- } else {
- strSQL = "{call delb (" + bookDeleteTextField.getText().trim() + ")}";
- if (db.updateSql(strSQL) > 0) {
- JOptionPane.showMessageDialog(null, "删除成功!");
- db.closeConnection();
- this.dispose();
- } else {
- JOptionPane.showMessageDialog(null, "删除失败!");
- db.closeConnection();
- this.dispose();
- }
- }
- }
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- }
- }
- public class BorrowZLXX extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- JPanel panel1, panel2;
- Container c;
- JLabel HnumLabel, HnameLabel, BnumLabel, bookLabel, ZbeizhuLabel;
- JTextField HnumTextField, HnameTextField, BnumTextField, ZbeizhuTextField;
- JButton clearBtn, yesBtn, cancelBtn;
- JComboBox bookComboBox = new JComboBox();
- public BorrowZLXX() {
- super("借出书籍");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- //添加Label
- HnumLabel = new JLabel("会员号", JLabel.CENTER);
- HnameLabel = new JLabel("姓名", JLabel.CENTER);
- BnumLabel = new JLabel("书号", JLabel.CENTER);
- bookLabel = new JLabel("书名", JLabel.CENTER);
- ZbeizhuLabel = new JLabel("备注", JLabel.CENTER);
- //添加TextField
- HnumTextField = new JTextField(25);
- HnameTextField = new JTextField(25);
- BnumTextField = new JTextField(25);
- ZbeizhuTextField = new JTextField(25);
- //查询书名 添加ComboBox
- try {
- String strSQL =
- "select book from SJXX where kucun > 0";
- rs = db.getResult(strSQL);
- while (rs.next()) {
- bookComboBox.addItem(rs.getString(1).trim());
- }
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- //填充容器 信息处理区
- panel1 = new JPanel();
- panel1.setLayout(new GridLayout(5, 2));
- panel1.add(HnumLabel);
- panel1.add(HnumTextField);
- panel1.add(HnameLabel);
- panel1.add(HnameTextField);
- panel1.add(BnumLabel);
- panel1.add(BnumTextField);
- panel1.add(bookLabel);
- panel1.add(bookComboBox);
- panel1.add(ZbeizhuLabel);
- panel1.add(ZbeizhuTextField);
- c.add(panel1, BorderLayout.CENTER);
- //按钮区
- panel2 = new JPanel();
- panel2.setLayout(new GridLayout(1, 3));
- yesBtn = new JButton("确定");
- cancelBtn = new JButton("取消");
- yesBtn.addActionListener(this);
- cancelBtn.addActionListener(this);
- panel2.add(yesBtn);
- panel2.add(cancelBtn);
- c.add(panel2, BorderLayout.SOUTH);
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == cancelBtn) { //取消按钮
- db.closeConnection();
- this.dispose();
- } else if (e.getSource() == yesBtn) { //确定按钮
- if (HnumTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "请输入会员号!");
- } else if(HnameTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "请输入会员姓名!");
- } else if(BnumTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "请输入书号!");
- } else if (bookComboBox.getSelectedItem().equals("")) {
- JOptionPane.showMessageDialog(null, "对不起,现在书库里没有书,\n你现在不能借书!");
- }
- else {
- try {
- String strSQL = "select * from HYXX where Hnum=" +
- HnumTextField.getText().trim() + "and Hname='" +
- HnameTextField.getText().trim() + "'";
- if(!db.getResult(strSQL).first()){
- JOptionPane.showMessageDialog(null, "未查到此会员信息!");
- } else {
- strSQL = "select * from SJXX where Bnum=" +
- BnumTextField.getText().trim() + "and book='" +
- bookComboBox.getSelectedItem() + "'";
- if (!db.getResult(strSQL).first()) {
- JOptionPane.showMessageDialog(null, "书号填写错误!");
- } else {
- strSQL = "{call jbook (" +
- HnumTextField.getText().trim() + ",'" +
- HnameTextField.getText().trim() + "'," +
- BnumTextField.getText().trim() + ",'" +
- bookComboBox.getSelectedItem() + "','" +
- ZbeizhuTextField.getText().trim() + "')}";
- if (db.updateSql(strSQL) > 0) { //判断是否成功执行
- //rs = db.getResult(strSQL);
- JOptionPane.showMessageDialog(null, "借阅成功!");
- db.closeConnection();
- this.dispose();
- } else {
- JOptionPane.showMessageDialog(null, "借阅失败!");
- db.closeConnection();
- this.dispose();
- }
- }
- }
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- }
- }
- }
- public class ReturnZLXX extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- JPanel panel1, panel2;
- Container c;
- JLabel HnumLabel,BnumLabel, bookLabel, ZnumLabel;
- JTextField HnumTextField, BnumTextField, ZnumTextField;
- JButton yesBtn, cancelBtn;
- JComboBox bookComboBox = new JComboBox();
- public ReturnZLXX() {
- super("书籍还入");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- //添加Label
- HnumLabel = new JLabel("会员号", JLabel.CENTER);
- BnumLabel = new JLabel("书号", JLabel.CENTER);
- bookLabel = new JLabel("书名", JLabel.CENTER);
- ZnumLabel = new JLabel("租赁号", JLabel.CENTER);
- //添加TextField
- HnumTextField = new JTextField(20);
- BnumTextField = new JTextField(20);
- ZnumTextField = new JTextField(20);
- //查询书名 添加ComboBox
- try {
- String strSQL = "select DISTINCT book from ZLXX where Hdate is null";
- rs = db.getResult(strSQL);
- while (rs.next()) {
- bookComboBox.addItem(rs.getString(1));
- }
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- //填充容器 信息处理区
- panel1 = new JPanel();
- panel1.setLayout(new GridLayout(4, 2));
- panel1.add(HnumLabel);
- panel1.add(HnumTextField);
- panel1.add(BnumLabel);
- panel1.add(BnumTextField);
- panel1.add(bookLabel);
- panel1.add(bookComboBox);
- panel1.add(ZnumLabel);
- panel1.add(ZnumTextField);
- c.add(panel1, BorderLayout.CENTER);
- //按钮区
- panel2 = new JPanel();
- panel2.setLayout(new GridLayout(1, 2));
- yesBtn = new JButton("确定");
- cancelBtn = new JButton("取消");
- yesBtn.addActionListener(this);
- cancelBtn.addActionListener(this);
- panel2.add(yesBtn);
- panel2.add(cancelBtn);
- c.add(panel2, BorderLayout.SOUTH);
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == cancelBtn) { //取消按钮
- db.closeConnection();
- this.dispose();
- }
- else if (e.getSource() == yesBtn) { //确定按钮
- if (HnumTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "请输入会员号!");
- }
- else if (BnumTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "请输入书号!");
- }
- else if (ZnumTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "请输入租赁号!");
- }
- else if (bookComboBox.getSelectedItem().equals("")) {
- JOptionPane.showMessageDialog(null, "没有出借过书!");
- }
- else {
- try {
- String strSQL = "select * from ZLXX where Znum=" +
- ZnumTextField.getText().trim() + " and Hnum=" +
- HnumTextField.getText().trim() + " and Bnum=" +
- BnumTextField.getText().trim() + " and book='" +
- bookComboBox.getSelectedItem() + "'";
- if(!db.getResult(strSQL).first()){
- JOptionPane.showMessageDialog(null, "会员没有借过此书!");
- } else {
- strSQL = "{call hbook (" +
- ZnumTextField.getText().trim() + "," +
- BnumTextField.getText().trim() + ")}";
- if (db.updateSql(strSQL) > 0) {
- //rs = db.getResult(strSQL);
- JOptionPane.showMessageDialog(null, "还书完成!");
- db.closeConnection();
- this.dispose();
- } else {
- JOptionPane.showMessageDialog(null, "还书失败!");
- db.closeConnection();
- this.dispose();
- }
- }
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- }
- }
- }
- public class ModfiyZLXX extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- Container c;
- JLabel TipLabel = new JLabel("输入书号点击查询,将调出此书相关信息");
- JLabel ZnumLabel,
- HnumLabel, HnameLabel,
- BnumLabel, bookLabel, BnameLabel,chubansheLabel,
- jiageLabel,ZbeizhuLabel;
- JTextField ZnumTextField,
- HnumTextField, HnameTextField,
- BnumTextField, bookTextField, BnameTextField, chubansheTextField,
- jiageTextField, ZbeizhuTextField;
- JButton selBtn, exitBtn, clearBtn, deleteBtn;
- JPanel panel1, panel2, panel3;
- public ModfiyZLXX() {
- super("修改租赁信息");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- //提示信息
- panel3 = new JPanel();
- panel3.add(TipLabel);
- c.add(panel3, BorderLayout.NORTH);
- //添加Label
- ZnumLabel = new JLabel("租赁号", JLabel.CENTER);
- HnumLabel = new JLabel("会员号", JLabel.CENTER);
- HnameLabel = new JLabel("姓名", JLabel.CENTER);
- BnumLabel= new JLabel("书号", JLabel.CENTER);
- bookLabel = new JLabel("书名", JLabel.CENTER);
- BnameLabel = new JLabel("作者", JLabel.CENTER);
- chubansheLabel = new JLabel("出版社", JLabel.CENTER);
- jiageLabel = new JLabel("价格", JLabel.CENTER);
- ZbeizhuLabel = new JLabel("备注", JLabel.CENTER);
- //添加TextField
- ZnumTextField = new JTextField(25);
- HnumTextField = new JTextField(25);
- HnameTextField = new JTextField(25);
- BnumTextField = new JTextField(25);
- bookTextField = new JTextField(25);
- BnameTextField = new JTextField(25);
- chubansheTextField = new JTextField(25);
- jiageTextField = new JTextField(25);
- ZbeizhuTextField = new JTextField(25);
- //添加Button
- clearBtn = new JButton("清空");
- selBtn = new JButton("查询");
- deleteBtn = new JButton("删除");
- exitBtn = new JButton("退出");
- clearBtn.addActionListener(this);
- selBtn.addActionListener(this);
- deleteBtn.addActionListener(this);
- exitBtn.addActionListener(this);
- deleteBtn.setEnabled(false);
- //填充容器 信息处理区
- panel1 = new JPanel();
- panel1.setLayout(new GridLayout(9, 2));
- panel1.add(ZnumLabel);
- panel1.add(ZnumTextField);
- panel1.add(HnumLabel);
- panel1.add(HnumTextField);
- panel1.add(HnameLabel);
- panel1.add(HnameTextField);
- panel1.add(BnumLabel);
- panel1.add(BnumTextField);
- panel1.add(bookLabel);
- panel1.add(bookTextField);
- panel1.add(BnameLabel);
- panel1.add(BnameTextField);
- panel1.add(chubansheLabel);
- panel1.add(chubansheTextField);
- panel1.add(jiageLabel);
- panel1.add(jiageTextField);
- panel1.add(ZbeizhuLabel);
- panel1.add(ZbeizhuTextField);
- //按钮区
- panel2 = new JPanel();
- panel2.setLayout(new GridLayout(1, 4));
- panel2.add(clearBtn);
- panel2.add(selBtn);
- panel2.add(deleteBtn);
- panel2.add(exitBtn);
- c.add(panel1, BorderLayout.CENTER);
- c.add(panel2, BorderLayout.SOUTH);
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == exitBtn) { //退出按钮
- db.closeConnection();
- this.dispose();
- }
- else if (e.getSource() == clearBtn) { //清空按钮
- ZnumTextField.setText("");
- HnumTextField.setText("");
- HnameTextField.setText("");
- BnumTextField.setText("");
- bookTextField.setText("");
- BnameTextField.setText("");
- chubansheTextField.setText("");
- jiageTextField.setText("");
- ZbeizhuTextField.setText("");
- deleteBtn.setEnabled(false);
- }
- else if (e.getSource() == selBtn) { //查询按钮
- try {
- String strSQL = "select * from ZLXX where Znum=" + ZnumTextField.getText().trim();
- if (ZnumTextField.getText().trim().equals("")) {
- JOptionPane.showMessageDialog(null, "请输入租赁号!");
- }
- else if (!db.getResult(strSQL).first()) {
- JOptionPane.showMessageDialog(null, "没有此租赁信息!");
- }
- else {
- rs = db.getResult(strSQL);
- rs.first();
- HnumTextField.setText(rs.getString(2).trim());
- HnameTextField.setText(rs.getString(3).trim());
- BnumTextField.setText(rs.getString(4).trim());
- bookTextField.setText(rs.getString(5).trim());
- BnameTextField.setText(rs.getString(6).trim());
- chubansheTextField.setText(rs.getString(7).trim());
- jiageTextField.setText(rs.getString(10).trim());
- ZbeizhuTextField.setText(rs.getString(11).trim());
- deleteBtn.setEnabled(true);
- }
- }
- catch (NullPointerException upe) {
- System.out.println(upe.toString());
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- else if (e.getSource() == deleteBtn) {
- try {
- if (ZnumTextField.getText().trim().equals("")) { //判断租赁号是否为空
- JOptionPane.showMessageDialog(null, "租赁号不能为空!");
- } else if (BnumTextField.getText().trim().equals("")) { //判断书名是否为空
- JOptionPane.showMessageDialog(null, "书号不能为空!");
- } else {
- String strSQL = "{call dbook (" +
- ZnumTextField.getText().trim() + "," +
- BnumTextField.getText().trim() + ")}";
- if (db.updateSql(strSQL) > 0) {
- //rs = db.getResult(strSQL);
- JOptionPane.showMessageDialog(null, "成功修改信息!");
- db.closeConnection();
- this.dispose();
- } else {
- JOptionPane.showMessageDialog(null, "修改信息失败!");
- db.closeConnection();
- this.dispose();
- }
- }
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- }
- }
- public class ListHYXX extends JFrame {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- Container c;
- JTable table = null;
- DefaultTableModel defaultModel = null;
- public ListHYXX() {
- super("会员信息");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- String[] name = {"会员号","姓名","性别","账户余额","登记日期","电话号码"};
- String[][] data = new String[0][0];
- defaultModel = new DefaultTableModel(data, name);
- table = new JTable(defaultModel);
- table.setPreferredScrollableViewportSize(new Dimension(700, 300));
- JScrollPane s = new JScrollPane(table);
- c.add(s);
- try {
- String strSql = "select * from HYXX";
- rs = db.getResult(strSql);
- while (rs.next()) {
- Vector insertRow = new Vector();
- insertRow.addElement(rs.getString(1));
- insertRow.addElement(rs.getString(2));
- insertRow.addElement(rs.getString(3));
- insertRow.addElement(rs.getString(4));
- insertRow.addElement(rs.getString(5));
- insertRow.addElement(rs.getString(6));
- defaultModel.addRow(insertRow);
- }
- table.revalidate();
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- }
- public class ListSJXX extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- Container c;
- JPanel panel1, panel2, panel3;
- JLabel BnumLabel, bookLabel, BnameLabel, chubansheLabel;
- JTextField BnumTextField, bookTextField, BnameTextField, chubansheTextField;
- JButton searchBtn, exitBtn;
- JTable table = null;
- DefaultTableModel defaultModel = null;
- public ListSJXX() {
- super("书籍信息");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- //添加label
- BnumLabel = new JLabel("书号:", JLabel.CENTER);
- bookLabel = new JLabel("书名:", JLabel.CENTER);
- BnameLabel = new JLabel("作者:", JLabel.CENTER);
- chubansheLabel = new JLabel("出版社:", JLabel.CENTER);
- //添加TextField
- BnumTextField = new JTextField(15);
- bookTextField = new JTextField(15);
- BnameTextField = new JTextField(15);
- chubansheTextField = new JTextField(15);
- //添加Button
- searchBtn = new JButton("查询");
- searchBtn.addActionListener(this);
- exitBtn = new JButton("退出");
- exitBtn.addActionListener(this);
- //填充容器
- panel1 = new JPanel();
- panel3 = new JPanel();
- panel1.add(BnumLabel);
- panel1.add(BnumTextField);
- panel1.add(bookLabel);
- panel1.add(bookTextField);
- panel1.add(BnameLabel);
- panel1.add(BnameTextField);
- panel1.add(chubansheLabel);
- panel1.add(chubansheTextField);
- panel3.add(searchBtn);
- panel3.add(exitBtn);
- String[] name = {"书号","书名", "作者","出版社", "价格", "库存", "备注"};
- String[][] data = new String[0][0];
- defaultModel = new DefaultTableModel(data, name);
- table = new JTable(defaultModel);
- table.setPreferredScrollableViewportSize(new Dimension(800, 120));
- JScrollPane s = new JScrollPane(table);
- panel2 = new JPanel();
- panel2.add(s);
- c.add(panel1, BorderLayout.NORTH);
- c.add(panel3, BorderLayout.CENTER);
- c.add(panel2, BorderLayout.SOUTH);
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == searchBtn) { //查询按钮
- String strSQL = "select * from SJXX";
- String strSql = null;
- if (BnumTextField.getText().trim().equals("") &&
- bookTextField.getText().trim().equals("") &&
- BnameTextField.getText().trim().equals("") &&
- chubansheTextField.getText().trim().equals("")) {
- strSql = strSQL;
- }
- else if (BnumTextField.getText().trim().equals("") &&
- bookTextField.getText().trim().equals("") &&
- BnameTextField.getText().trim().equals("")) {
- strSql = strSQL + " where chubanshe='" + chubansheTextField.getText().trim() + "'";
- }
- else if (BnumTextField.getText().trim().equals("") &&
- bookTextField.getText().trim().equals("") &&
- chubansheTextField.getText().trim().equals("")) {
- strSql = strSQL + " where Bname='" + BnameTextField.getText().trim() + "'";
- }
- else if (BnumTextField.getText().trim().equals("") &&
- BnameTextField.getText().trim().equals("") &&
- chubansheTextField.getText().trim().equals("")) {
- strSql = strSQL + " where book='" + bookTextField.getText().trim() + "'";
- }
- else if (bookTextField.getText().trim().equals("") &&
- BnameTextField.getText().trim().equals("") &&
- chubansheTextField.getText().trim().equals("")) {
- strSql = strSQL + " where Bnum=" + BnumTextField.getText().trim();
- }
- else if (BnumTextField.getText().trim().equals("") &&
- bookTextField.getText().trim().equals("")) {
- strSql = strSQL + " where chubanshe='" +
- chubansheTextField.getText().trim() + "' and Bname='" +
- BnameTextField.getText().trim().equals("") + "'";
- }
- else if (BnumTextField.getText().trim().equals("") &&
- BnameTextField.getText().trim().equals("")) {
- strSql = strSQL + " where chubanshe='" +
- chubansheTextField.getText().trim() + "' and book='" +
- bookTextField.getText().trim().equals("") + "'";
- }
- else if (bookTextField.getText().trim().equals("") &&
- BnameTextField.getText().trim().equals("")) {
- strSql = strSQL + " where chubanshe='" +
- chubansheTextField.getText().trim() + "' and Bnum=" +
- BnumTextField.getText().trim().equals("");
- }
- else if (BnumTextField.getText().trim().equals("") &&
- chubansheTextField.getText().trim().equals("")) {
- strSql = strSQL + " where Bname='" +
- BnameTextField.getText().trim() + "' and book='" +
- bookTextField.getText().trim().equals("") + "'";
- }
- else if (bookTextField.getText().trim().equals("") &&
- chubansheTextField.getText().trim().equals("")) {
- strSql = strSQL + " where Bname='" +
- BnameTextField.getText().trim() + "' and Bnum=" +
- BnumTextField.getText().trim().equals("");
- }
- else if (BnameTextField.getText().trim().equals("") &&
- chubansheTextField.getText().trim().equals("")) {
- strSql = strSQL + " where book='" +
- bookTextField.getText().trim() + "' and Bnum=" +
- BnumTextField.getText().trim().equals("");
- }
- else if (BnumTextField.getText().trim().equals("")) {
- strSql = strSQL + " where Bname='" +
- BnameTextField.getText().trim() + "' and book='" +
- bookTextField.getText().trim().equals("") + "' and chubanshe='" +
- chubansheTextField.getText().trim().equals("") + "'";
- }
- else if (BnameTextField.getText().trim().equals("")) {
- strSql = strSQL + " where Bnum=" +
- BnumTextField.getText().trim() + " and book='" +
- bookTextField.getText().trim().equals("") + "' and chubanshe='" +
- chubansheTextField.getText().trim().equals("") + "'";
- }
- else if (bookTextField.getText().trim().equals("")) {
- strSql = strSQL + " where Bnum=" +
- BnumTextField.getText().trim() + " and Bname='" +
- BnameTextField.getText().trim().equals("") + "' and chubanshe='" +
- chubansheTextField.getText().trim().equals("") + "'";
- }
- else if (chubansheTextField.getText().trim().equals("")) {
- strSql = strSQL + " where Bnum=" +
- BnumTextField.getText().trim() + " and Bname='" +
- BnameTextField.getText().trim().equals("") + "' and book='" +
- bookTextField.getText().trim().equals("") + "'";
- }
- else {
- strSql = strSQL + " where Bnum=" +
- BnumTextField.getText().trim() + " and Bname='" +
- BnameTextField.getText().trim().equals("") + "' and book='" +
- bookTextField.getText().trim().equals("") + "' and chubanshe='" +
- chubansheTextField.getText().trim().equals("") + "'";
- }
- try {
- //初始化表格
- int rowCount = defaultModel.getRowCount() - 1;
- int j = rowCount;
- for (int i = 0; i <= rowCount; i++) {
- defaultModel.removeRow(j);
- defaultModel.setRowCount(j);
- j = j - 1;
- }
- rs = db.getResult(strSql);
- while (rs.next()) {
- Vector data = new Vector();
- data.addElement(rs.getString(1));
- data.addElement(rs.getString(2));
- data.addElement(rs.getString(3));
- data.addElement(rs.getString(4));
- data.addElement(rs.getString(5));
- data.addElement(rs.getString(6));
- data.addElement(rs.getString(7));
- defaultModel.addRow(data);
- }
- table.revalidate();
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- else if (e.getSource() == exitBtn) { //取消按钮
- db.closeConnection();
- this.dispose();
- }
- }
- }
- public class ListZLXX extends JFrame implements ActionListener {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- Container c;
- JPanel panel1, panel2;
- JLabel BnumLabel, HnumLabel;
- JTextField BnumTextField, HnumTextField;
- JButton searchBtn, exitBtn;
- JTable table = null;
- DefaultTableModel defaultModel = null;
- public ListZLXX() {
- super("借阅信息");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- BnumLabel = new JLabel("书号:", JLabel.CENTER);
- HnumLabel = new JLabel("会员号:", JLabel.CENTER);
- BnumTextField = new JTextField(15);
- HnumTextField = new JTextField(15);
- searchBtn = new JButton("查询");
- exitBtn = new JButton("退出");
- searchBtn.addActionListener(this);
- exitBtn.addActionListener(this);
- panel1 = new JPanel();
- panel1.add(BnumLabel);
- panel1.add(BnumTextField);
- panel1.add(HnumLabel);
- panel1.add(HnumTextField);
- panel1.add(searchBtn);
- panel1.add(exitBtn);
- panel2 = new JPanel();
- String[] name = {"租赁号", "会员号", "姓名", "书号", "书名", "借书日期", "还书日期", "价格", "备注"};
- String[][] data = new String[0][0];
- defaultModel = new DefaultTableModel(data, name);
- table = new JTable(defaultModel);
- table.setPreferredScrollableViewportSize(new Dimension(600, 120));
- JScrollPane s = new JScrollPane(table);
- panel2.add(s);
- c.add(panel1, BorderLayout.NORTH);
- c.add(panel2, BorderLayout.SOUTH);
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == exitBtn) { //退出按钮
- db.closeConnection();
- this.dispose();
- }
- else if (e.getSource() == searchBtn) { //查询按钮
-
- String strSQL = "select * from XX";
- String strSql = null;
- if (BnumTextField.getText().trim().equals("") &&
- HnumTextField.getText().trim().equals("")) {
- strSql = strSQL;
- }
- else if (BnumTextField.getText().trim().equals("")) {
- strSql = strSQL + " where Hnum=" + HnumTextField.getText().trim();
- }
- else if (HnumTextField.getText().trim().equals("")) {
- strSql = strSQL + " where Bnum=" + BnumTextField.getText().trim();
- }
- else {
- strSql = strSQL + " where Username=" +
- HnumTextField.getText().trim() + " and bookName=" +
- BnumTextField.getText().trim();
- }
- try {
- //初始化表格
- int rowCount = defaultModel.getRowCount() - 1;
- int j = rowCount;
- for (int i = 0; i <= rowCount; i++) {
- defaultModel.removeRow(j);
- defaultModel.setRowCount(j);
- j = j - 1;
- }
- rs = db.getResult(strSql);
- while (rs.next()) {
- Vector data = new Vector();
- data.addElement(rs.getString(1));
- data.addElement(rs.getString(2));
- data.addElement(rs.getString(3));
- data.addElement(rs.getString(4));
- data.addElement(rs.getString(5));
- data.addElement(rs.getString(6));
- data.addElement(rs.getString(7));
- data.addElement(rs.getString(8));
- data.addElement(rs.getString(9));
- defaultModel.addRow(data);
- }
- table.revalidate();
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- }
- }
- public class ListSRXX extends JFrame {
- DataBaseManager db = new DataBaseManager();
- ResultSet rs;
- Container c;
- JTable table = null;
- DefaultTableModel defaultModel = null;
- public ListSRXX() {
- super("收入信息");
- c = getContentPane();
- c.setLayout(new BorderLayout());
- String[] name = {"收入号","租赁号","会员号","书号","日期","收入"};
- String[][] data = new String[0][0];
- defaultModel = new DefaultTableModel(data, name);
- table = new JTable(defaultModel);
- table.setPreferredScrollableViewportSize(new Dimension(700, 300));
- JScrollPane s = new JScrollPane(table);
- c.add(s);
- try {
- String strSql = "select * from SRXX";
- rs = db.getResult(strSql);
- while (rs.next()) {
- Vector insertRow = new Vector();
- insertRow.addElement(rs.getString(1));
- insertRow.addElement(rs.getString(2));
- insertRow.addElement(rs.getString(3));
- insertRow.addElement(rs.getString(4));
- insertRow.addElement(rs.getString(5));
- insertRow.addElement(rs.getString(6));
- defaultModel.addRow(insertRow);
- }
- table.revalidate();
- }
- catch (SQLException sqle) {
- System.out.println(sqle.toString());
- }
- catch (Exception ex) {
- System.out.println(ex.toString());
- }
- }
- }
(输入的账号或密码错误,弹出提示框)
(1)如图28所示为添加会员功能
(2)如图29所示为修改会员信息功能
(3)如图30所示为删除会员功能
(1)如图32所示为添加书籍功能
(2)如图33所示为修改书籍信息功能
(3)如图34所示为删除书籍信息功能
(1)如图36所示为借出书籍功能
(2)如图37所示为书籍还入功能
(3)如图38所示为修改租赁信息功能
(1)如图40所示为会员信息查询功能
(2)如图41所示为书籍信息查询功能
(3)如图42所示为借阅信息查询
(4)图43所示为收入信息查询
本次数据库大作业对于我来说非常具有挑战性, 因为我对Java的JDBC和swing没有深入了解过。在设计过程中可以来说是困难重重,因为对Java的JDBC功能不是很熟悉,所以要不断的查找Java的API文档才能了解它的工作原理,在重复无数次后最终实现了与数据库的链接。
关于图形界面上我用Java swing来实现,对于swing我也不是很了解,算是从头学起,在这个系统中只是简单设计了一下图形界面,包括各个菜单选项的实现,比较简洁的风格。
这次在数据库的链接方面花了很大功夫,主要是不明白JDBC如何才能连上SQL Server,通过不断的找资料和上网查资料最后明白了,虽然花了两天功夫才弄明白,不过我觉得还是值得的,毕竟我以后就不会再犯同样的错误了,而且对于Java有了更深的了解了。
通过这次课程设计发现这其中需要的很多知识我们没有接触过,还有很多需要我们掌握的东西我们不明白。同时也发现有很多已经学过的东西我们没有理解到位,不能灵活运用于实际,不能很好的用来解决问题,这就需要我们不断的大量的实践,通过不断的自学,不断地发现问题,思考问题,进而解决问题。从种文档的阅读到开始的需求分析、概念结构设计、逻辑结构设计、物理结构设计。亲身体验了一回系统的设计开发过程。很多东西书上写的很清楚,貌似看着也很简单,操作起来要考虑到方方面面,这还只是一个比较简单的系统,可想可知在我们生活中应用的数据库会有多么复杂。
[1] 倪春迪.数据库原理及应用[M].北京:清华大学出版社,2015.
[2] 耿祥义、张跃平.Java 2实用教程(第5版)[M].北京:清华大学出版社,2017.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。