You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.5 KiB

6 months ago
import wx
import pymysql, time, threading
from MySQL import Make_bill, function
class Withdrawal1(wx.App):
def doClose(self, j):
time.sleep(j)
self.frame.Close()
def __init__(self, YuanZhangH):
self.YuanZhangH = YuanZhangH
wx.App.__init__(self)
self.frame = wx.Frame(parent=None, title='取 款', size=(535, 450),
style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX)
panel = wx.Panel(self.frame, -1)
panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBack)
label_pass = wx.StaticText(panel, -1, "取款金额:", pos=(80, 200))
# style 为设置输入
self.JinE = wx.TextCtrl(panel, -1, size=(250, 35), pos=(140, 190))
self.QueDing_button = wx.Button(panel, -1, "确 认", size=(80, 60), pos=(120, 280))
self.QuXiao_button = wx.Button(panel, -1, "反 回", size=(80, 60), pos=(340, 280))
self.QueDing_button.SetBackgroundColour('#0a74f7')
self.QuXiao_button.SetBackgroundColour('#0a74f7')
self.Bind(wx.EVT_BUTTON, self.QuK, self.QueDing_button)
self.Bind(wx.EVT_BUTTON, self.QU, self.QuXiao_button)
self.frame.Center()
self.frame.Show(True)
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_check(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 QuK(self, event):
# 连接到本地数据库
z2 = self.JinE.GetValue()
YuanZhangH = self.YuanZhangH
sql1 = "SELECT 余额 FROM card WHERE Card_Number = %s" % (YuanZhangH)
sql2 = "update card set 余额 = 余额-'{}' where Card_Number = '{}'".format(float(z2), YuanZhangH)
# 判断,查看用户名和密码名是否为空
# 不为空之后在进行查询和判断
# 不然当密码或用户名为空时会出现会导致出错
if z2:
db = pymysql.connect(host="localhost", user="root",
password="lwh20021210...", db="atm", port=3306)
# 使用cursor()方法获取操作游标
cur = db.cursor()
try:
cur.execute(sql1)
results = cur.fetchall()
if results[0][0] >= float(z2):
cur.execute(sql2)
db.commit()
Make_bill.Make_Bill(YuanZhangH, "取款", float(z2), "")
self.show_check(word='取款成功')
else:
self.show_message(word='余额不足')
except Exception as e:
db.rollback()
finally:
db.close() # 关闭连接
else:
self.show_message(word='取款金额不能为空')
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\\instagram.jpg')
dc.DrawBitmap(bmp, 0, 0)
def QU(self, event):
t = threading.Thread(target=self.doClose, args=(0.05,))
t.start()
jie = function.Jiemian(self.YuanZhangH)
jie.MainLoop()