图书管理系统毕业设计
时间: 2023-11-30 07:42:37 浏览: 98
图书管理系统是一种常见的毕业设计,其主要功能是对图书信息进行管理。下面是一个简单的图书管理系统的设计思路:
1.需求分析:首先需要明确系统的需求,包括对图书信息的增删改查、借阅归还等功能。
2.系统设计:根据需求分析,进行系统的总体设计和详细设计,包括系统的模块划分、功能实现等。
3.数据库设计:设计数据库表结构,包括图书信息表、借阅信息表等。
4.界面设计:设计用户界面,包括登录界面、主界面、图书信息管理界面等。
5.编码实现:根据系统设计和界面设计,进行编码实现。
6.测试和调试:对系统进行测试和调试,确保系统的稳定性和可靠性。
7.部署和维护:将系统部署到服务器上,并进行维护和更新。
下面是一个简单的Python图书管理系统的代码实现:
```python
# 导入必要的模块
import sqlite3
from tkinter import *
from tkinter import messagebox
# 创建数据库连接
conn = sqlite3.connect('book.db')
c = conn.cursor()
# 创建图书信息表
c.execute('''CREATE TABLE IF NOT EXISTS book
(id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
author TEXT,
publisher TEXT,
price REAL,
count INTEGER)''')
# 创建借阅信息表
c.execute('''CREATE TABLE IF NOT EXISTS borrow
(id INTEGER PRIMARY KEY AUTOINCREMENT,
book_id INTEGER,
user_id INTEGER,
borrow_date TEXT,
return_date TEXT)''')
# 定义主界面
class MainFrame(Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
# 创建控件
def create_widgets(self):
# 标签
Label(self, text='图书管理系统', font=('Arial', 20)).grid(row=0, column=0, columnspan=4, pady=10)
# 按钮
Button(self, text='图书信息管理', font=('Arial', 16), width=15, height=2, command=self.book_manage).grid(row=1, column=0, padx=10, pady=10)
Button(self, text='借阅信息管理', font=('Arial', 16), width=15, height=2, command=self.borrow_manage).grid(row=1, column=1, padx=10, pady=10)
Button(self, text='退出系统', font=('Arial', 16), width=15, height=2, command=self.master.quit).grid(row=1, column=2, padx=10, pady=10)
# 图书信息管理界面
def book_manage(self):
self.destroy()
BookFrame(self.master)
# 借阅信息管理界面
def borrow_manage(self):
self.destroy()
BorrowFrame(self.master)
# 图书信息管理界面
class BookFrame(Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
# 创建控件
def create_widgets(self):
# 标签
Label(self, text='图书信息管理', font=('Arial', 20)).grid(row=0, column=0, columnspan=4, pady=10)
# 按钮
Button(self, text='添加图书', font=('Arial', 16), width=15, height=2, command=self.add_book).grid(row=1, column=0, padx=10, pady=10)
Button(self, text='删除图书', font=('Arial', 16), width=15, height=2, command=self.del_book).grid(row=1, column=1, padx=10, pady=10)
Button(self, text='修改图书', font=('Arial', 16), width=15, height=2, command=self.modify_book).grid(row=1, column=2, padx=10, pady=10)
Button(self, text='查询图书', font=('Arial', 16), width=15, height=2, command=self.query_book).grid(row=1, column=3, padx=10, pady=10)
Button(self, text='返回主界面', font=('Arial', 16), width=15, height=2, command=self.back).grid(row=2, column=0, columnspan=4, pady=10)
# 添加图书
def add_book(self):
# 创建添加图书窗口
add_window = Toplevel(self)
add_window.title('添加图书')
add_window.geometry('300x200')
# 标签和输入框
Label(add_window, text='图书名称:').grid(row=0, column=0, pady=10)
name_entry = Entry(add_window)
name_entry.grid(row=0, column=1, pady=10)
Label(add_window, text='图书作者:').grid(row=1, column=0, pady=10)
author_entry = Entry(add_window)
author_entry.grid(row=1, column=1, pady=10)
Label(add_window, text='出版社:').grid(row=2, column=0, pady=10)
publisher_entry = Entry(add_window)
publisher_entry.grid(row=2, column=1, pady=10)
Label(add_window, text='价格:').grid(row=3, column=0, pady=10)
price_entry = Entry(add_window)
price_entry.grid(row=3, column=1, pady=10)
Label(add_window, text='数量:').grid(row=4, column=0, pady=10)
count_entry = Entry(add_window)
count_entry.grid(row=4, column=1, pady=10)
# 添加按钮
Button(add_window, text='添加', font=('Arial', 16), width=10, height=1, command=lambda:self.add_book_action(name_entry.get(), author_entry.get(), publisher_entry.get(), price_entry.get(), count_entry.get())).grid(row=5, column=0, columnspan=2, pady=10)
# 添加图书操作
def add_book_action(self, name, author, publisher, price, count):
if name == '' or author == '' or publisher == '' or price == '' or count == '':
messagebox.showerror('错误', '请填写完整信息!')
return
try:
price = float(price)
count = int(count)
except:
messagebox.showerror('错误', '价格和数量必须为数字!')
return
c.execute("INSERT INTO book (name, author, publisher, price, count) VALUES (?, ?, ?, ?, ?)", (name, author, publisher, price, count))
conn.commit()
messagebox.showinfo('提示', '添加成功!')
# 删除图书
def del_book(self):
# 创建删除图书窗口
del_window = Toplevel(self)
del_window.title('删除图书')
del_window.geometry('300x100')
# 标签和输入框
Label(del_window, text='图书ID:').grid(row=0, column=0, pady=10)
id_entry = Entry(del_window)
id_entry.grid(row=0, column=1, pady=10)
# 删除按钮
Button(del_window, text='删除', font=('Arial', 16), width=10, height=1, command=lambda:self.del_book_action(id_entry.get())).grid(row=1, column=0, columnspan=2, pady=10)
# 删除图书操作
def del_book_action(self, id):
if id == '':
messagebox.showerror('错误', '请填写图书ID!')
return
c.execute("SELECT * FROM book WHERE id=?", (id,))
book = c.fetchone()
if book is None:
messagebox.showerror('错误', '图书不存在!')
return
c.execute("DELETE FROM book WHERE id=?", (id,))
conn.commit()
messagebox.showinfo('提示', '删除成功!')
# 修改图书
def modify_book(self):
# 创建修改图书窗口
modify_window = Toplevel(self)
modify_window.title('修改图书')
modify_window.geometry('300x200')
# 标签和输入框
Label(modify_window, text='图书ID:').grid(row=0, column=0, pady=10)
id_entry = Entry(modify_window)
id_entry.grid(row=0, column=1, pady=10)
Label(modify_window, text='图书名称:').grid(row=1, column=0, pady=10)
name_entry = Entry(modify_window)
name_entry.grid(row=1, column=1, pady=10)
Label(modify_window, text='图书作者:').grid(row=2, column=0, pady=10)
author_entry = Entry(modify_window)
author_entry.grid(row=2, column=1, pady=10)
Label(modify_window, text='出版社:').grid(row=3, column=0, pady=10)
publisher_entry = Entry(modify_window)
publisher_entry.grid(row=3, column=1, pady=10)
Label(modify_window, text='价格:').grid(row=4, column=0, pady=10)
price_entry = Entry(modify_window)
price_entry.grid(row=4, column=1, pady=10)
Label(modify_window, text='数量:').grid(row=5, column=0, pady=10)
count_entry = Entry(modify_window)
count_entry.grid(row=5, column=1, pady=10)
# 修改按钮
Button(modify_window, text='修改', font=('Arial', 16), width=10, height=1, command=lambda:self.modify_book_action(id_entry.get(), name_entry.get(), author_entry.get(), publisher_entry.get(), price_entry.get(), count_entry.get())).grid(row=6, column=0, columnspan=2, pady=10)
# 修改图书操作
def modify_book_action(self, id, name, author, publisher, price, count):
if id == '':
messagebox.showerror('错误', '请填写图书ID!')
return
c.execute("SELECT * FROM book WHERE id=?", (id,))
book = c.fetchone()
if book is None:
messagebox.showerror('错误', '图书不存在!')
return
if name != '':
c.execute("UPDATE book SET name=? WHERE id=?", (name, id))
if author != '':
c.execute("UPDATE book SET author=? WHERE id=?", (author, id))
if publisher != '':
c.execute("UPDATE book SET publisher=? WHERE id=?", (publisher, id))
if price != '':
try:
price = float(price)
c.execute("UPDATE book SET price=? WHERE id=?", (price, id))
except:
messagebox.showerror('错误', '价格必须为数字!')
return
if count != '':
try:
count = int(count)
c.execute("UPDATE book SET count=? WHERE id=?", (count, id))
except:
messagebox.showerror('错误', '数量必须为数字!')
return
conn.commit()
messagebox.showinfo('提示', '修改成功!')
# 查询图书
def query_book(self):
# 创建查询图书窗口
query_window = Toplevel(self)
query_window.title('查询图书')
query_window.geometry('300x100')
# 标签和输入框
Label(query_window, text='图书名称:').grid(row=0, column=0, pady=10)
name_entry = Entry(query_window)
name_entry.grid(row=0, column=1, pady=10)
# 查询按钮
Button(query_window, text='查询', font=('Arial', 16), width=10, height=1, command=lambda:self.query_book_action(name_entry.get())).grid(row=1, column=0, columnspan=2, pady=10)
# 查询图书操作
def query_book_action(self, name):
if name == '':
c.execute("SELECT * FROM book")
else:
c.execute("SELECT * FROM book WHERE name LIKE ?", ('%'+name+'%',))
books = c.fetchall()
if len(books) == 0:
messagebox.showinfo('提示', '没有找到相关图书!')
return
# 创建查询结果窗口
result_window = Toplevel(self)
result_window.title('查询结果')
result_window.geometry('600x400')
# 标签和列表框
Label(result_window, text='查询结果', font=('Arial', 20)).pack(pady=10)
scrollbar = Scrollbar(result_window)
scrollbar.pack(side=RIGHT, fill=Y)
listbox = Listbox(result_window, font=('Arial', 16), width=50, height=20, yscrollcommand=scrollbar.set)
for book in books:
listbox.insert(END, 'ID:'+str(book[0])+',名称:'+book[1]+',作者:'+book[2]+',出版社:'+book[3]+',价格:'+str(book[4])+',数量:'+str(book[5]))
listbox.pack(side=LEFT, fill=BOTH)
scrollbar.config(command=listbox.yview)
# 返回
阅读全文