Update README.md

main
p6y97m5je 1 year ago
parent be52a50b89
commit 3e39ad5cf8

@ -1,245 +0,0 @@
# ForumManagementInformationSystem
import pymysql
from datetime import datetime
class ForumManagementSystem:
def __init__(self):
try:
self.connection = pymysql.connect(
host='localhost',
user='root',
password='7368261',
database='bbs',
charset='utf8mb4'
)
self.cursor = self.connection.cursor(pymysql.cursors.DictCursor)
print("数据库连接成功")
except pymysql.Error as e:
print(f"数据库连接错误: {e}")
exit(1)
def show_main_menu(self):
print("\n=== 论坛管理系统 ===")
print("1. 用户管理")
print("2. 帖子管理")
print("3. 版块管理")
print("4. 统计查询")
print("5. 退出系统")
return input("请选择功能 (1-5): ")
def show_user_menu(self):
print("\n=== 用户管理 ===")
print("1. 查看用户列表")
print("2. 添加用户")
print("3. 修改用户信息")
print("4. 删除用户")
print("5. 查看用户活动")
print("6. 返回主菜单")
return input("请选择操作 (1-6): ")
def show_topic_menu(self):
print("\n=== 帖子管理 ===")
print("1. 查看帖子列表")
print("2. 发布新帖子")
print("3. 更新帖子点击量")
print("4. 删除帖子")
print("5. 查看热门帖子")
print("6. 搜索帖子")
print("7. 返回主菜单")
return input("请选择操作 (1-7): ")
def show_section_menu(self):
print("\n=== 版块管理 ===")
print("1. 查看版块列表")
print("2. 查看版块统计")
print("3. 查看版块帖子")
print("4. 查看版主信息")
print("5. 返回主菜单")
return input("请选择操作 (1-5): ")
def show_stats_menu(self):
print("\n=== 统计查询 ===")
print("1. 用户发帖统计")
print("2. 版块活跃度统计")
print("3. 热门帖子排行")
print("4. 返回主菜单")
return input("请选择操作 (1-4): ")
# 用户管理功能
def display_users(self):
try:
self.cursor.execute("SELECT * FROM user")
users = self.cursor.fetchall()
print("\n用户列表:")
print("ID\t用户名\t\t性别\t积分\t注册时间")
print("-" * 70)
for user in users:
print(
f"{user['uID']}\t{user['userName']}\t\t{user['userSex']}\t{user['userPoint']}\t{user['userRegDate']}")
except pymysql.Error as e:
print(f"查询失败: {e}")
def update_user_info(self):
try:
user_id = input("请输入要修改的用户ID: ")
new_username = input("请输入新用户名: ")
new_email = input("请输入新邮箱: ")
new_sex = input("请输入性别: ")
# 使用存储过程更新用户信息
self.cursor.execute("CALL UpdateUserInfo(%s, %s, %s, %s)",
(user_id, new_username, new_email, new_sex))
self.connection.commit()
print("用户信息更新成功!")
except pymysql.Error as e:
self.connection.rollback()
print(f"更新失败: {e}")
def view_user_activity(self):
try:
self.cursor.execute("SELECT * FROM user_activity")
activities = self.cursor.fetchall()
print("\n用户活动统计:")
print("用户名\t\t最后活动时间\t\t发帖数")
print("-" * 70)
for activity in activities:
print(f"{activity['userName']}\t\t{activity['lastActive']}\t\t{activity['totalPosts']}")
except pymysql.Error as e:
print(f"查询失败: {e}")
# 帖子管理功能
def view_popular_topics(self):
try:
self.cursor.execute("CALL GetPopularTopics()")
topics = self.cursor.fetchall()
print("\n热门帖子:")
print("ID\t主题\t\t点击量\t发布时间")
print("-" * 70)
for topic in topics:
print(f"{topic['tID']}\t{topic['tTopic']}\t\t{topic['tClickCount']}\t{topic['tTime']}")
except pymysql.Error as e:
print(f"查询失败: {e}")
def update_topic_clicks(self):
try:
topic_id = input("请输入帖子ID: ")
increment = input("请输入增加的点击量: ")
self.cursor.execute("CALL UpdateTopicClicks(%s, %s)", (topic_id, increment))
self.connection.commit()
print("点击量更新成功!")
except pymysql.Error as e:
self.connection.rollback()
print(f"更新失败: {e}")
# 版块管理功能
def view_section_stats(self):
try:
self.cursor.execute("SELECT * FROM section_topic_stats")
stats = self.cursor.fetchall()
print("\n版块统计:")
print("版块名\t\t帖子数\t总点击量")
print("-" * 70)
for stat in stats:
print(f"{stat['sName']}\t\t{stat['topicCount']}\t{stat['totalClicks']}")
except pymysql.Error as e:
print(f"查询失败: {e}")
def view_section_posts(self):
try:
section_id = input("请输入版块ID: ")
self.cursor.execute("CALL GetAllPostsInSection(%s)", (section_id,))
posts = self.cursor.fetchall()
print("\n版块帖子列表:")
print("ID\t主题\t\t发布时间")
print("-" * 70)
for post in posts:
print(f"{post['tID']}\t{post['tTopic']}\t\t{post['tTime']}")
except pymysql.Error as e:
print(f"查询失败: {e}")
def view_section_masters(self):
try:
self.cursor.execute("SELECT * FROM section_masters")
masters = self.cursor.fetchall()
print("\n版主信息:")
print("ID\t用户名\t\t邮箱")
print("-" * 70)
for master in masters:
print(f"{master['uID']}\t{master['userName']}\t\t{master['userEmail']}")
except pymysql.Error as e:
print(f"查询失败: {e}")
def run(self):
while True:
choice = self.show_main_menu()
if choice == '1': # 用户管理
while True:
subchoice = self.show_user_menu()
if subchoice == '1':
self.display_users()
elif subchoice == '2':
self.add_user()
elif subchoice == '3':
self.update_user_info()
elif subchoice == '4':
self.delete_user()
elif subchoice == '5':
self.view_user_activity()
elif subchoice == '6':
break
elif choice == '2': # 帖子管理
while True:
subchoice = self.show_topic_menu()
if subchoice == '1':
self.display_posts()
elif subchoice == '2':
self.add_post()
elif subchoice == '3':
self.update_topic_clicks()
elif subchoice == '4':
self.delete_post()
elif subchoice == '5':
self.view_popular_topics()
elif subchoice == '6':
self.search_topics()
elif subchoice == '7':
break
elif choice == '3': # 版块管理
while True:
subchoice = self.show_section_menu()
if subchoice == '1':
self.display_sections()
elif subchoice == '2':
self.view_section_stats()
elif subchoice == '3':
self.view_section_posts()
elif subchoice == '4':
self.view_section_masters()
elif subchoice == '5':
break
elif choice == '4': # 统计查询
while True:
subchoice = self.show_stats_menu()
if subchoice == '1':
self.view_user_activity()
elif subchoice == '2':
self.view_section_stats()
elif subchoice == '3':
self.view_popular_topics()
elif subchoice == '4':
break
elif choice == '5': # 退出系统
print("感谢使用!再见!")
self.connection.close()
break
if __name__ == '__main__':
system = ForumManagementSystem()
system.run()
Loading…
Cancel
Save