parent
0b3f119a51
commit
5f489e35c3
@ -1 +0,0 @@
|
|||||||
Subproject commit 79e6a92078324050b29977f7767f1f03c53f085b
|
|
@ -1,53 +0,0 @@
|
|||||||
import json
|
|
||||||
class MysqlDatabase:
|
|
||||||
def __init__(self):
|
|
||||||
self.users = json.loads(open('users.json', mode='r',encoding='utf-8').read())
|
|
||||||
self.students = json.loads(open('students.json', mode='r', encoding='utf-8').read())
|
|
||||||
|
|
||||||
|
|
||||||
def check_login(self,username,password):
|
|
||||||
for user in self.users:
|
|
||||||
if username == user['username']:
|
|
||||||
if password == user['password']:
|
|
||||||
return True,'登陆成功'
|
|
||||||
else:
|
|
||||||
return False,'登录失败,密码错误'
|
|
||||||
return False,'登录失败,用户不存在'
|
|
||||||
|
|
||||||
def all(self):
|
|
||||||
return self.students
|
|
||||||
|
|
||||||
def insert(self,student):
|
|
||||||
self.students.append(student)
|
|
||||||
|
|
||||||
def delete_by_username(self,name):
|
|
||||||
for student in self.students:
|
|
||||||
print(student)
|
|
||||||
if student['name'] == name:
|
|
||||||
self.students.remove(student)
|
|
||||||
return True,f'{name}删除学生成功'
|
|
||||||
return False,f'{name}学生不存在'
|
|
||||||
|
|
||||||
def search_by_username(self,name):
|
|
||||||
for student in self.students:
|
|
||||||
if student['name'] == name:
|
|
||||||
return True, student
|
|
||||||
return False,f'{name}学生不存在'
|
|
||||||
|
|
||||||
def update(self,stu):
|
|
||||||
for student in self.students:
|
|
||||||
if student['name'] == stu['name']:
|
|
||||||
student.update(stu)
|
|
||||||
return True,f'{stu["name"]} 学生数据修改成功'
|
|
||||||
return False,f'{stu["name"]} 学生不存在'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
db = MysqlDatabase()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
db.check_login('admin','password')
|
|
||||||
print(db.all())
|
|
Loading…
Reference in new issue