|
|
import random
|
|
|
from datetime import datetime
|
|
|
|
|
|
import pymysql
|
|
|
|
|
|
'''
|
|
|
import pymysql
|
|
|
from PyQt5.QtGui import QStandardItem, QStandardItemModel
|
|
|
|
|
|
account_list=[]
|
|
|
password_list=[]
|
|
|
db = pymysql.connect(host='127.0.0.1', user='root', password='20021220', database='pybank')
|
|
|
cur = db.cursor()
|
|
|
cur.execute('select cid,cpsw from customer')
|
|
|
rows = cur.fetchall()
|
|
|
for row in rows:
|
|
|
account_list.append(row[0])
|
|
|
password_list.append(row[1])
|
|
|
print(account_list, password_list)
|
|
|
db.commit()
|
|
|
db.close()
|
|
|
|
|
|
#error example:
|
|
|
def login_in(self):
|
|
|
account = self.ui.login_account.text()
|
|
|
password = self.ui.login_psw.text()
|
|
|
account_list = []
|
|
|
password_list = []
|
|
|
db = pymysql.connect(host='127.0.0.1', user='root', password='20021220', database='pybank')
|
|
|
cur = db.cursor()
|
|
|
cur.execute('select cid,cpsw from customer')
|
|
|
rows = cur.fetchall()
|
|
|
print(rows)
|
|
|
for row in rows:
|
|
|
account_list.append(row[0])
|
|
|
password_list.append(row[1])
|
|
|
print(account_list, password_list)
|
|
|
db.commit()
|
|
|
db.close()
|
|
|
for i in range(len(account_list)):
|
|
|
if len(account==0) or len(password==0):
|
|
|
self.ui.stackedWidget.setCurrentIndex(2)
|
|
|
if account == account_list[i] and password == password_list[i]:
|
|
|
self.win = MainWindow()
|
|
|
self.close()
|
|
|
else:
|
|
|
self.ui.stackedWidget.setCurrentIndex(5)
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
''' def login_in(self):
|
|
|
account = self.ui.login_account.text()
|
|
|
password = self.ui.login_psw.text()
|
|
|
|
|
|
# 检查输入框是否为空
|
|
|
if not account or not password:
|
|
|
self.ui.stackedWidget.setCurrentIndex(2) # 设置当前页面索引为空输入错误页面
|
|
|
return
|
|
|
|
|
|
account_list = []
|
|
|
password_list = []
|
|
|
|
|
|
try:
|
|
|
db = pymysql.connect(host='127.0.0.1', user='root', password='20021220', database='pybank')
|
|
|
cur = db.cursor()
|
|
|
cur.execute('select cid, cpsw from customer')
|
|
|
rows = cur.fetchall()
|
|
|
db.close()
|
|
|
except Exception as e:
|
|
|
print(f"Database error: {e}")
|
|
|
self.ui.stackedWidget.setCurrentIndex(2) # 设置为数据库错误页面(可以调整索引)
|
|
|
return
|
|
|
|
|
|
for row in rows:
|
|
|
account_list.append(row[0])
|
|
|
password_list.append(row[1])
|
|
|
# 验证账号和密码
|
|
|
for i in range(len(account_list)):
|
|
|
if account == account_list[i] and password == password_list[i]: # 假设密码是字符串
|
|
|
global user_now
|
|
|
user_now = account
|
|
|
self.win = MainWindow()
|
|
|
self.win.show() # 显示新窗口
|
|
|
self.close() # 关闭当前窗口
|
|
|
return # 匹配成功,退出函数
|
|
|
|
|
|
# 如果没有匹配成功
|
|
|
self.ui.stackedWidget.setCurrentIndex(5) # 设置当前页面索引为账号或密码错误页面'''
|
|
|
|
|
|
'''
|
|
|
def register_in(self):
|
|
|
account = self.ui.register_account.text()
|
|
|
password_1 = self.ui.register_psw.text()
|
|
|
password_2 = self.ui.register_psw2.text()
|
|
|
|
|
|
# 判断是否输入为空
|
|
|
if not account or not password_1 or not password_2:
|
|
|
self.ui.stackedWidget.setCurrentIndex(2) # 设置当前页面索引为空输入错误页面
|
|
|
return
|
|
|
|
|
|
# 判断账号是否已存在
|
|
|
try:
|
|
|
db = pymysql.connect(host='127.0.0.1', user='root', password='20021220', database='pybank')
|
|
|
cur = db.cursor()
|
|
|
cur.execute('select cid from customer')
|
|
|
rows = cur.fetchall()
|
|
|
db.close()
|
|
|
except Exception as e:
|
|
|
print(f"Database error: {e}")
|
|
|
self.ui.stackedWidget.setCurrentIndex(2) # 设置为数据库错误页面(可以调整索引)
|
|
|
return
|
|
|
|
|
|
# 提取所有现有账号
|
|
|
existing_accounts = [row[0] for row in rows]
|
|
|
if account in existing_accounts:
|
|
|
self.ui.stackedWidget.setCurrentIndex(3) # 设置当前页面索引为账号已存在错误页面
|
|
|
return
|
|
|
|
|
|
# 判断两次输入密码是否正确
|
|
|
if password_1 == password_2:
|
|
|
try:
|
|
|
db = pymysql.connect(host='127.0.0.1', user='root', password='20021220', database='pybank')
|
|
|
cur = db.cursor()
|
|
|
cur.execute(f"insert into customer(cid, cpsw) values('{account}', '{password_2}')")
|
|
|
db.commit() # 提交事务
|
|
|
db.close()
|
|
|
self.ui.stackedWidget.setCurrentIndex(4) # 设置当前页面索引为注册成功页面
|
|
|
except Exception as e:
|
|
|
print(f"Database error: {e}")
|
|
|
self.ui.stackedWidget.setCurrentIndex(2) # 设置为数据库错误页面
|
|
|
return
|
|
|
else:
|
|
|
self.ui.stackedWidget.setCurrentIndex(1) # 设置当前页面索引为密码不匹配错误页面
|
|
|
return
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
''' def register_in(self):
|
|
|
account=self.ui.register_account.text()
|
|
|
password_1=self.ui.register_psw.text()
|
|
|
password_2=self.ui.register_psw2.text()
|
|
|
#判断是否输入为空
|
|
|
if not account or not password_1 or password_2:
|
|
|
self.ui.stackedWidget.setCurrentIndex(2) # 设置当前页面索引为空输入错误页面
|
|
|
return
|
|
|
#判断账号是否已存在
|
|
|
try:
|
|
|
db = pymysql.connect(host='127.0.0.1', user='root', password='20021220', database='pybank')
|
|
|
cur = db.cursor()
|
|
|
cur.execute('select cid from customer')
|
|
|
rows = cur.fetchall()
|
|
|
db.close()
|
|
|
except Exception as e:
|
|
|
print(f"Database error: {e}")
|
|
|
self.ui.stackedWidget.setCurrentIndex(2) # 设置为数据库错误页面(可以调整索引)
|
|
|
return
|
|
|
if account in rows:
|
|
|
self.ui.stackedWidget.setCurrentIndex(3)
|
|
|
return
|
|
|
#判断两次输入密码是否正确
|
|
|
if password_1==password_2:
|
|
|
self.ui.stackedWidget.setCurrentIndex(4)
|
|
|
try:
|
|
|
db = pymysql.connect(host='127.0.0.1', user='root', password='20021220', database='pybank')
|
|
|
cur = db.cursor()
|
|
|
cur.execute(f"insert into customer(cid,cpsw) values('{account}','{password_2}')")
|
|
|
db.close()
|
|
|
except Exception as e:
|
|
|
print(f"Database error: {e}")
|
|
|
return
|
|
|
else:
|
|
|
self.ui.stackedWidget.setCurrentIndex(1)
|
|
|
return
|
|
|
'''
|
|
|
|
|
|
'''
|
|
|
def info_in(self):
|
|
|
# 获取数据
|
|
|
data = self.connect_customer()
|
|
|
# 创建模型
|
|
|
model = QStandardItemModel()
|
|
|
# 设置列标题(根据你的表结构调整列标题)
|
|
|
model.setHorizontalHeaderLabels(['身份证号', '用户名', '性别', '用户年龄', '电话号码', '户籍', '登录密码'])
|
|
|
# 填充数据
|
|
|
for row in data:
|
|
|
items = [QStandardItem(str(field)) for field in row]
|
|
|
model.appendRow(items)
|
|
|
# 获取你的 QTableView 控件(假设它的名字是 tableView)
|
|
|
table_view = self.ui.tableView
|
|
|
# 将模型设置为 QTableView 的模型
|
|
|
table_view.setModel(model)
|
|
|
# 切换到包含 QTableView 的页面
|
|
|
self.ui.stackedWidget.setCurrentIndex(6)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generator_accid():
|
|
|
while True:
|
|
|
accid = random.randint(10000, 99999)
|
|
|
try:
|
|
|
db = pymysql.connect(host='127.0.0.1', user='root', password='20021220', database='pybank')
|
|
|
cur = db.cursor()
|
|
|
cur.execute('SELECT * FROM account WHERE accid = %s', (accid,))
|
|
|
rows = cur.fetchone()
|
|
|
if not rows:
|
|
|
db.close()
|
|
|
return accid
|
|
|
else:
|
|
|
print("Accid already exists. Generating a new one.")
|
|
|
db.close()
|
|
|
except Exception as e:
|
|
|
print(f"Database error: {e}")
|
|
|
return accid
|
|
|
# 调用函数并打印结果
|
|
|
print(generator_accid())
|
|
|
''' |