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.

149 lines
5.6 KiB

import wx
import pymysql, time, threading
from MySQL import Make_bill, function
class Transfer(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_user = wx.StaticText(panel, -1, "账 号:", pos=(80, 160))
label_pass = wx.StaticText(panel, -1, "转账金额:", pos=(80, 215))
self.ZhangHao = wx.TextCtrl(panel, -1, size=(250, 35), pos=(140, 150))
# style 为设置输入
self.JinE = wx.TextCtrl(panel, -1, size=(250, 35), pos=(140, 205))
self.YanZheng_button = wx.Button(panel, -1, "验证", size=(50, 35), pos=(400, 150))
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.YanZheng_button.SetBackgroundColour('#0a74f7')
self.QueDing_button.SetBackgroundColour('#0a74f7')
self.QuXiao_button.SetBackgroundColour('#0a74f7')
self.Bind(wx.EVT_BUTTON, self.YanCard, self.YanZheng_button)
self.Bind(wx.EVT_BUTTON, self.ZhuanZhang, 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 QU(self, event):
t = threading.Thread(target=self.doClose, args=(0.05,))
t.start()
jie = function.Jiemian(self.YuanZhangH)
jie.MainLoop()
def YanCard(self, event):
z1 = self.ZhangHao.GetValue()
sql = """select 持卡人姓名,card类型 from card where Card_Number ='%s' """ % (z1)
if z1 != self.YuanZhangH:
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])
stt = "持卡人姓名:" + results[0][0] + " " + "银行类型:" + results[0][1]
self.show_check(stt)
print(results[0][0], " ", results[0][1])
else:
self.show_message(word='账号不存在')
except Exception as e:
db.rollback()
finally:
db.close() # 关闭连接
else:
self.show_message(word="转账账号不能与自己相同")
def ZhuanZhang(self, event):
# 连接到本地数据库
z1 = self.ZhangHao.GetValue()
z2 = self.JinE.GetValue()
YuanZhangH = self.YuanZhangH
# sql = """ UPDATE card set 余额=余额+z2 WHERE Card_Number= '%s' """ % (z1)
sql = "update card set 余额 = 余额+'{}' where Card_Number = '{}'".format(float(z2), z1)
sql1 = "SELECT 余额 FROM card WHERE Card_Number = %s" % (z1)
sql2 = "update card set 余额 = 余额-'{}' where Card_Number = '{}'".format(float(z2), YuanZhangH)
if z1 != self.YuanZhangH:
if z1 and 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(sql) # 执行sql语句
db.commit()
cur.execute(sql2)
db.commit()
Make_bill.Make_Bill(YuanZhangH, "转账", float(z2), z1)
self.show_check(word='转账成功')
else:
self.show_message(word='余额不足')
except Exception as e:
db.rollback()
finally:
db.close() # 关闭连接
else:
self.show_message(word='账号和转账金额不能为空')
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)
# if __name__=='__main__':
# app = Transfer("62155504510128")
# app.MainLoop()