import time
from colorama import Fore,Back,Style
from service.user_service import UserService
from service.news_service import NewsService
from service.role_service import RoleService
import os
import sys
__user_service = UserService()
__news_service = NewsService()
__role_service = RoleService()
# reslut = __user_service.login("admin","123456")
#
# print(reslut)
while True:
('cls')
print(Fore.LIGHTBLUE_EX,"\n"+"\t"*3+"="*80,)
print(Fore.LIGHTBLUE_EX,"\n"+"\t"*7+"新闻管理系统")
print(Fore.LIGHTBLUE_EX,"\n"+"\t"*3+"="*80,end="")
print("\n"+"\t"*3+"1.登录系统",end="")
print("\n"+"\t"*3+"2.推出系统",end="")
chooce = input("\n"+"\t"*3+"输入操作编号:")
print(Style.RESET_ALL,end="")
if chooce == "1":
username = input("\n"+"\t"*3+"用户名:")
password = input("\n"+"\t"*3+"密码:")
if __user_service.login(username,password):
while True:
('cls')
print(Fore.LIGHTBLUE_EX,"\n" + "\t" * 3 + "1.新闻管理", end="")
print(Fore.LIGHTBLUE_EX,"\n" + "\t" * 3 + "2.用户管理", end="")
print(Fore.LIGHTBLUE_EX,"\n" + "\t" * 3 + "back.推出登录", end="")
print(Fore.LIGHTBLUE_EX,"\n" + "\t" * 3 + "exit.推出系统", end="")
chooce = input("\n" + "\t" * 3 + "输入操作编号:")
# print(Style.RESET_ALL,end="")
if chooce == "1":
while True:
('cls')
print(Fore.LIGHTBLUE_EX,"\n" + "\t" * 3 + "1.审批新闻", end="")
print(Fore.LIGHTBLUE_EX,"\n" + "\t" * 3 + "2.删除新闻", end="")
print(Fore.LIGHTBLUE_EX,"\n" + "\t" * 3 + "back.返回上一层", end="")
chooce = input("\n" + "\t" * 3 + "输入操作编号:")
if chooce == "1":
page = 1
while True:
('cls')
count_page = __news_service.search_unreview_page_list()
news = __news_service.search_unreview_list(page)
for i in range(len(news)):
print(Fore.LIGHTBLUE_EX,"\n"+"\t"*3+f"%d\t%s\t%s\t%s"%(i+1,news[i][1],news[i][2],news[i][3]),end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 +"%d/%d"%(page,count_page), end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "back.返回上一层", end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "prev.上一页", end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "next.下一页", end="")
chooce = input("\n" + "\t" * 3 + "输入操作编号:")
if chooce=="back":
break
elif chooce=="prev":
if page>1:
page-=1
else:
print("当前页为首页!")
continue
elif chooce=="next":
if page<count_page:
page+=1
else:
print("当前页为尾页!!")
continue
elif int(chooce)>=1 and int(chooce)<=10:
__news_service.update_unreview_news(news[int(chooce)-1][0])
# time.sleep(3)
else:
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "输入有误!!", end="")
time.sleep(3)
elif chooce == "2":
page = 1
while True:
('cls')
count_page = __news_service.search_count_page()
news = __news_service.search_list(page)
for i in range(len(news)):
print(Fore.LIGHTBLUE_EX,"\n"+"\t"*3+f"%d\t%s\t%s\t%s\t"%(i+1,news[i][1],news[i][2],news[i][3]),news[i][4],end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 +"%d/%d"%(page,count_page), end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "back.返回上一层", end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "prev.上一页", end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "next.下一页", end="")
chooce = input("\n" + "\t" * 3 + "输入操作编号:")
if chooce=="back":
break
elif chooce=="prev":
if page>1:
page-=1
else:
print("\n\t\t\t当前页为首页!")
time.sleep(3)
continue
elif chooce=="next":
if page<count_page:
page+=1
else:
print("\n\t\t\t当前页为尾页!!")
time.sleep(3)
continue
elif int(chooce)>=1 and int(chooce)<=10:
__news_service.delete_by_id(news[int(chooce)-1][0])
# time.sleep(3)
else:
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "输入有误!!", end="")
time.sleep(3)
elif chooce == "back":
break
else:
print("\n\t\t\t输入不存在!!", end="")
time.sleep(3)
# print(Style.RESET_ALL, end="")
elif chooce == "2":
while True:
('cls')
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "1.添加用户", end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "2.修改用户", end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "3.删除用户", end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "back.推出登录", end="")
chooce = input("\n" + "\t" * 3 + "输入操作编号:")
if chooce=="1":
while True:
('cls')
username = input("\n" + "\t" * 3 + "用户名:")
password = input("\n" + "\t" * 3 + "密码:")
repassword = input("\n" + "\t" * 3 + "重复密码:")
if password==repassword:
email = input("\n" + "\t" * 3 + "邮箱:")
role_type=__role_service.search_list()
for i in range(len(role_type)):
print("\n\t\t\t%s\t%s"%(i+1,role_type[i][1]))
id = input("\n" + "\t" * 3 + "账户类型:")
role_id = role_type[int(id)][0]
confirm = input("\n\t\t\t确认添加用户信息(Y/N)")
if confirm=="Y" or confirm=="y":
__user_service.insert_user(username,password,email,role_id)
print("\n\t\t\t添加成功(3秒后返回)")
time.sleep(3)
continue
else:
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "重复密码有误!!")
time.sleep(3)
elif chooce=="2":
page=1
('cls')
count_page = __user_service.search_user_page()
users = __user_service.seach_user_list(page)
for i in range(len(users)):
print(Fore.LIGHTBLUE_EX,
"\n" + "\t" * 3 + f"%d\t%s\t%s\t%s" % (i + 1, users[i][1],users[i][2],users[i][3]),
end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "%d/%d" % (page, count_page), end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "back.返回上一层", end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "prev.上一页", end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "next.下一页", end="")
chooce = input("\n" + "\t" * 3 + "输入操作编号:")
if chooce == "back":
break
elif chooce == "prev":
if page > 1:
page -= 1
else:
print("当前页为首页!")
continue
elif chooce == "next":
if page < count_page:
page += 1
else:
print("当前页为尾页!!")
continue
elif int(chooce) >= 1 and int(chooce) < len(users):
('cls')
id=users[int(chooce)-1][0]
username = input("\n" + "\t" * 3 + "用户名:")
password = input("\n" + "\t" * 3 + "密码:")
repassword = input("\n" + "\t" * 3 + "重复密码:")
if password == repassword:
email = input("\n" + "\t" * 3 + "邮箱:")
role_type = __role_service.search_list()
for i in range(len(role_type)):
print("\n\t\t\t%s\t%s" % (i + 1, role_type[i][1]))
role_id = input("\n" + "\t" * 3 + "账户类型:")
role_id = role_type[int(role_id)-1][0]
confirm = input("\n\t\t\t确认修改用户信息(Y/N)")
if confirm == "Y" or confirm == "y":
__user_service.update(id,username, password, email, role_id)
print("\n\t\t\t修改成功(3秒后返回)")
time.sleep(3)
continue
# time.sleep(3)
else:
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "输入有误!!", end="")
time.sleep(3)
elif chooce=="3":
page = 1
('cls')
count_page = __user_service.search_user_page()
users = __user_service.seach_user_list(page)
for i in range(len(users)):
print(Fore.LIGHTBLUE_EX,
"\n" + "\t" * 3 + f"%d\t%s\t%s\t%s" % (i + 1, users[i][1], users[i][2], users[i][3]),
end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "%d/%d" % (page, count_page), end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "back.返回上一层", end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "prev.上一页", end="")
print(Fore.LIGHTBLUE_EX, "\n" + "\t" * 3 + "next.下一页", end="")
chooce = input("\n" + "\t" * 3 + "输入操作编号:")
if chooce == "back":
break
elif chooce == "prev":
if page > 1:
page -= 1
else:
print("当前页为首页!")
continue
elif chooce == "next":
if page < count_page:
page += 1
else:
print("当前页为尾页!!")
continue
elif int(chooce) >= 1 and int(chooce) < len(users):
id=users[int(chooce)-1][0]
__user_service.delete(id)
print("\n\t\t\t删除成功(3秒后返回)")
time.sleep(3)
continue
elif chooce=="back":
break
else:
print("\n\t\t\t输入不存在!!", end="")
elif chooce == "back":
break
elif chooce == "exit":
sys.exit(0)
else:
print("\n\t\t\t输入不存在!!",end="")
time.sleep(3)
else:
print("\n" + "\t" * 3 +"账号或密码错误!!3秒后将返回登录",end="")
elif chooce == "2":
sys.exit(0)
else:
print("输入不存在!!3秒后将返回登录",end="")
time.sleep(3)