|
|
import wx
|
|
|
import random
|
|
|
import pymysql
|
|
|
import time
|
|
|
import threading
|
|
|
|
|
|
from MySQL import function
|
|
|
|
|
|
|
|
|
# 所系使用的是固定位置,导致窗口拉伸的效果不是很好
|
|
|
class MyApp(wx.App): #定义一个名为MyApp的类,继承自wxPython的App类
|
|
|
def doClose(self, j):
|
|
|
time.sleep(j)
|
|
|
self.frame.Close()
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
wx.App.__init__(self)
|
|
|
self.frame = wx.Frame(parent=None, title='Login', size=(600, 460),
|
|
|
style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX)
|
|
|
# 设置窗口的左上角的图标 600, 460
|
|
|
# 其中参数type表示图片的类型,还有ico,jpgm等类型
|
|
|
icon_1 = wx.Icon(name='img\\favicon.png', type=wx.BITMAP_TYPE_PNG)
|
|
|
self.frame.SetIcon(icon_1)
|
|
|
|
|
|
panel = wx.Panel(self.frame, -1)
|
|
|
# 向panel中添加图片
|
|
|
image = wx.Image("img\\登录背景.jpg", wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
|
|
|
panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBack)
|
|
|
# 添加文本输入框
|
|
|
label_user = wx.StaticText(panel, label='用户:', pos=(120, 230))
|
|
|
label_user.SetBackgroundColour(wx.Colour(255, 255, 255))
|
|
|
self.entry_user = wx.TextCtrl(panel, -1, size=(225, 35), pos=(160, 225))
|
|
|
# style 为设置输入
|
|
|
label_pass = wx.StaticText(panel, label='密码:', pos=(120, 280))
|
|
|
label_pass.SetBackgroundColour(wx.Colour(255, 255, 255))
|
|
|
self.entry_pass = wx.TextCtrl(panel, -1, size=(225, 35), pos=(160, 270), style=wx.TE_PASSWORD)
|
|
|
# 添加按钮
|
|
|
self.but_login = wx.Button(panel, -1, "登陆", size=(130, 50), pos=(140, 340))
|
|
|
self.but_register = wx.Button(panel, -1, "注册", size=(130, 50), pos=(297, 340))
|
|
|
# 设置按钮的颜色
|
|
|
self.but_login.SetBackgroundColour("#0a74f7")
|
|
|
self.but_register.SetBackgroundColour("#0a74f7")
|
|
|
# 给按钮绑定事件
|
|
|
self.Bind(wx.EVT_BUTTON, self.on_but_login, self.but_login)
|
|
|
self.Bind(wx.EVT_BUTTON, self.on_but_register, self.but_register)
|
|
|
|
|
|
self.frame.Center()
|
|
|
self.frame.Show(True)
|
|
|
|
|
|
def OnEraseBack(self, event): #定义一个方法,用于处理窗口背景的擦除事件
|
|
|
dc = event.GetDC()
|
|
|
if not dc:
|
|
|
dc = wx.ClientDC(self)
|
|
|
rect = self.GetUpdateRegion().GetBox()
|
|
|
dc.SetClippingRect(rect)
|
|
|
dc.Clear()
|
|
|
bmp = wx.Bitmap("img\\登录背景.jpg")
|
|
|
dc.DrawBitmap(bmp, 0, 0)
|
|
|
|
|
|
# 定义一个消息弹出框的函数
|
|
|
def show_message(self, word=""):
|
|
|
dlg = wx.MessageDialog(None, word, u"错误", wx.YES_NO | wx.ICON_QUESTION)
|
|
|
|
|
|
if dlg.ShowModal() == wx.ID_YES:
|
|
|
# self.Close(True)
|
|
|
pass
|
|
|
dlg.Destroy()
|
|
|
|
|
|
def show_que(self, word=""): #定义一个方法,用于显示提示消息框,并在确认后关闭窗口
|
|
|
dlg = wx.MessageDialog(None, word, u"提示", wx.YES_NO | wx.ICON_QUESTION)
|
|
|
|
|
|
if dlg.ShowModal() == wx.ID_YES:
|
|
|
# self.Close(True)
|
|
|
t = threading.Thread(target=self.doClose, args=(0.5,))
|
|
|
t.start()
|
|
|
dlg.Destroy()
|
|
|
|
|
|
def on_but_login(self, event): #定义一个方法,用于处理登录按钮的点击事件,包括与数据库的连接和用户验证。
|
|
|
user_name = self.entry_user.GetValue()
|
|
|
pass_word = self.entry_pass.GetValue()
|
|
|
sql = """select password from card where Card_Number ='%s' """ % (user_name)
|
|
|
# 判断,查看用户名和密码名是否为空
|
|
|
# 不为空之后在进行查询和判断
|
|
|
# 不然当密码或用户名为空时会出现会导致出错
|
|
|
if user_name and pass_word:
|
|
|
print(user_name, " ", pass_word)
|
|
|
db = pymysql.connect(host="localhost", user="root",
|
|
|
password="lwh20021210...", db="atm", port=3306)
|
|
|
# 使用cursor()方法获取操作游标
|
|
|
cur = db.cursor()
|
|
|
try:
|
|
|
cur.execute(sql) # 执行sql语句
|
|
|
results = cur.fetchall() # 获取查询的所有记录
|
|
|
# 返回值是一个元组的形式
|
|
|
|
|
|
print(type(results))
|
|
|
if results:
|
|
|
# print(type(results[0][0]))
|
|
|
# print(results[0][0])
|
|
|
if results[0][0] == int(pass_word):
|
|
|
self.show_que(word="登陆成功")
|
|
|
jie = function.Jiemian(user_name)
|
|
|
jie.MainLoop()
|
|
|
# self.page1 = function.Jiemian()
|
|
|
# je=Jiemian()
|
|
|
# je.MainLoop()
|
|
|
# self.AddPage(self.page1, "xxpage")
|
|
|
else:
|
|
|
self.show_message(word="密码错误")
|
|
|
else:
|
|
|
self.show_message(word='用户名不存在')
|
|
|
except Exception as e:
|
|
|
db.rollback()
|
|
|
finally:
|
|
|
db.close() # 关闭连接
|
|
|
else:
|
|
|
self.show_message(word='账号和密码不能为空')
|
|
|
def on_but_register(self, event): #定义一个方法,用于处理注册按钮的点击事件,包括将新用户信息插入到数据库
|
|
|
user_name = self.entry_user.GetValue()
|
|
|
pass_word = self.entry_pass.GetValue()
|
|
|
sql = "INSERT INTO card (Card_Number, password,持卡人姓名,身份证号,余额,card类型) VALUES ('%s','%s','%s','%s','%s','%s')" % (
|
|
|
user_name, pass_word, '用户', 37000000000, 0, " ")
|
|
|
# 判断,查看用户名和密码名是否为空
|
|
|
# 不为空之后在进行查询和判断
|
|
|
# 不然当密码或用户名为空时会出现会导致出错
|
|
|
if user_name and pass_word:
|
|
|
print(user_name, " ", pass_word)
|
|
|
db = pymysql.connect(host="localhost", user="root",
|
|
|
password="lwh20021210...", db="atm", port=3306)
|
|
|
# 使用cursor()方法获取操作游标
|
|
|
cur = db.cursor()
|
|
|
try:
|
|
|
cur.execute(sql) # 执行sql语句
|
|
|
results = cur.rowcount # 获取查询的所有记录
|
|
|
# 返回值是一个元组的形式
|
|
|
db.commit()
|
|
|
print(type(results))
|
|
|
if results:
|
|
|
# print(type(results[0][0]))
|
|
|
if results > 0:
|
|
|
self.show_que(word="操作成功")
|
|
|
else:
|
|
|
self.show_message(word="操作失败")
|
|
|
else:
|
|
|
self.show_message(word='操作失败')
|
|
|
|
|
|
except Exception as e:
|
|
|
db.rollback()
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
db.close() # 关闭连接
|
|
|
else:
|
|
|
self.show_message(word='账号和密码不能为空')
|
|
|
|
|
|
# je=Jiemian()
|
|
|
# je.MainLoop()
|
|
|
|
|
|
# je=Jiemian()
|
|
|
# je.MainLoop()
|