def OnCloseWindow(self, event): "如果进行关闭的时候,把bool_id重新修改为0,因为等于1是正在进行的操作" # self._accounts.Close(True) # self.__accounts.Close(True) # self._balance.Close(True) # self._details.Close(True) # self.___details.Close(True) # self.___details.Close(True) conn = Mysql_All_is_Use() conn = conn.getConn() sql_update = sql_update = "update bank_user set bool_id = 0 where bool_id != 0;" cursor = conn.cursor() try: cursor.execute(sql_update) conn.commit() except Exception as e: print e conn.rollback() finally: cursor.close() conn.close() self.Destroy() self.signin_Frame.Show(True)
def OnButton_1(self, event): "修改两个数据库,一个是bank_user,一个是some_operation" conn = Mysql_All_is_Use() conn = conn.getConn() sql_select1 = "select username from bank_user where bool_id = 1;" sql_update1 = "update bank_user set money = money + %d where bool_id = 1;" sql_insert2 = "insert into some_operation(username, money) values('%s', %d);" cur = conn.cursor() try: # 输入的钱数 the_money = int(self.user_ctrl.GetValue()) st = sql_update1 % the_money cur.execute(st) cur.execute(sql_select1) rs = cur.fetchall() username = rs[0][0] # print(username) st = sql_insert2 % (username, the_money) cur.execute(st) conn.commit() except Exception as e: print e conn.rollback() finally: cur.close() conn.close() # 点击确定以后就及时关闭该窗口,防止多次点击 self.Destroy() self.input_accounts.Enable(True)
def __init__(self, username, password): self.username = username self.password = password self.flag = False conn = Mysql_All_is_Use() conn = conn.getConn() cursor = conn.cursor() sql_insert = "insert into bank_user(username, password) values('%s', '%s');" % ( self.username, self.password) sql_select = "select username, password from bank_user;" try: cursor.execute(sql_select) rs = cursor.fetchall() for r in rs: if r[0] == self.username: wx.MessageBox(u"当前用户名存在,请重新输入", u"错误信息", style=wx.OK) self.flag = True if self.flag == False: # 上述操作没有问题则提交数据库 cursor.execute(sql_insert) conn.commit() except Exception as e: print e # 出错的话数据库回滚 conn.rollback() finally: cursor.close() conn.close()
def OnButton(self, event): "实现点击的时候删除账户的功能" conn = Mysql_All_is_Use() conn = conn.getConn() print(self.text1_ctrl.GetValue()) sql_delete = "delete from bank_user where username = '******';" % self.text1_ctrl.GetValue( ) sql_select = "select username from bank_user;" cur = conn.cursor() try: cur.execute(sql_select) self.rs1 = cur.fetchall() cur.execute(sql_delete) conn.commit() except Exception as e: print e finally: cur.execute(sql_select) rs2 = cur.fetchall() if len(self.rs1) == len(rs2) + 1: wx.MessageBox(u"删除成功", u"删除结果", style=wx.OK) else: wx.MessageBox(u"删除失败", u"删除结果", style=wx.OK) cur.close() conn.close()
def OnButton_1(self, event): sql_select1 = "select username, money from bank_user where bool_id = 1;" sql_update1 = "update bank_user set money = money %c %d where username = '******';" sql_insert2 = "insert into some_operation(username, money, receive_username) values('%s', %d, '%s');" conn = Mysql_All_is_Use() conn = conn.getConn() cur = conn.cursor() try: cur.execute(sql_select1) rs1 = cur.fetchall() # 返回的是一个元祖,而表示每一个数据的也是元组,所以用二维 username = rs1[0][0] true_money = int(rs1[0][1]) # 转账的钱数 the_money = int(self.user_ctrl.GetValue()) receive_username = self.receive_username.GetValue() print(username, the_money, receive_username) if (the_money > true_money): self.user_ctrl.SetValue(u"请重新输入金额") wx.MessageBox(u"转账金额大于现有钱数", u"错误信息", style=wx.OK) else: st = sql_insert2 % (username, -the_money, receive_username) cur.execute(st) st = sql_insert2 % (receive_username, the_money, username) cur.execute(st) st = sql_update1 % ('-', the_money, username) cur.execute(st) st = sql_update1 % ('+', the_money, receive_username) cur.execute(st) conn.commit() except Exception as e: print e conn.rollback() finally: cur.close() conn.close() # 点击确定以后就及时关闭该窗口,防止多次点击 self.Destroy() self.ouput_accounts.Enable(True)
def __init__(self): dlg = wx.TextEntryDialog(None, u"请输入要查找账户:", u"查找账户", u"") if dlg.ShowModal() == wx.ID_OK: conn = Mysql_All_is_Use() conn = conn.getConn() cur = conn.cursor() sql_select = "select username, money from bank_user;" try: cur.execute(sql_select) rs = cur.fetchall() flag = False for r in rs: if r[0] == dlg.GetValue(): wx.MessageBox(u"用户的钱数为:%d元" % r[1], u"查询结果", style=wx.OK) flag = True break if flag == False: wx.MessageBox(u"当前用户名不存在", u"查询结果", style=wx.OK) except Exception as e: print e finally: cur.close() conn.close()
def __init__(self, username, password, flag): self.username = username self.password = password self.flag = flag self.f = True conn = Mysql_All_is_Use() conn = conn.getConn() cursor = conn.cursor() if self.flag == True: # 证明是普通用户 sql = "select username, password from bank_user;" else: sql = "select username, password from bank_manager;" self.flag = False try: cursor.execute(sql) rs = cursor.fetchall() # print rs for r in rs: if r[0] == self.username and r[1] == self.password: self.flag = True self.SetFlag(True) break if self.flag == False: wx.MessageBox(u"用户名或者密码输入错误", u"错误信息", style=wx.OK) self.SetFlag(False) except Exception as e: print e finally: cursor.close() conn.close()
def __init__(self, parent): super(MyGrid, self).__init__(parent, -1) lable_list = [u"用户名", u"账户金额", u"操作时间"] # 用CreateGrid来实现,以网格的形式来显示 conn = Mysql_All_is_Use() conn = conn.getConn() sql_select = "select username, money, create_time from bank_user;" cursor = conn.cursor() try: cursor.execute(sql_select) rs = cursor.fetchall() self.CreateGrid(len(rs), 3) for x, y in enumerate(lable_list): self.SetColLabelValue(x, y) for x, r in enumerate(rs): # print x, r self.SetCellValue(x, 0, r[0]) self.SetCellValue(x, 1, str(r[1])) self.SetCellValue(x, 2, str(r[2])) except Exception as e: print e finally: cursor.close() conn.close()
def OnButton_3(self, event): "用户登录界面" st = self.GetTitle() username = self.user_ctrl.GetValue() password = self.password_ctrl.GetValue() if st == u"用户登录界面": users = User_Frame(self) rs = Enter_UseMysql(username, password, True) if rs.GetFlag() == False: # 登录不成功 return # 登录成功获取登录的用户名 # 如果登录成功,则把当前列的bool_id修改为1 conn = Mysql_All_is_Use() conn = conn.getConn() sql_update = sql_update = "update bank_user set bool_id = 1 where username = '******';" % ( username) cursor = conn.cursor() try: cursor.execute(sql_update) conn.commit() except Exception as e: print e conn.rollback() finally: cursor.close() conn.close() self.get_username = username users.Show(True) self.Show(False) else: admin = Admin_Frame(self) rs = Enter_UseMysql(username, password, False) if rs.GetFlag() == False: return admin.Show(True) self.Show(False)
def __init__(self, all_balance): super(Balance_Frame, self).__init__( None, -1, u"账户余额", size=(300, 200), pos=(400, 100), style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX)) self.all_balance = all_balance panel = wx.Panel(self, -1) topLbl = wx.StaticText(panel, -1, u"用户剩余钱数") topLbl.SetFont(wx.Font(13, wx.SWISS, wx.NORMAL, wx.BOLD)) text1 = wx.StaticText(panel, -1, u"账户余额:") self.text1_ctrl = wx.TextCtrl(panel, -1, "") self.text1_ctrl.Enable(False) conn = Mysql_All_is_Use() conn = conn.getConn() cursor = conn.cursor() # 已经登录成功后,用户名肯定存在,此时直接查看钱数 sql = "select username, money, bool_id from bank_user;" try: cursor.execute(sql) rs = cursor.fetchall() for r in rs: if int(r[2]) == 1: self.text1_ctrl.SetValue(u"%d元" % r[1]) break except Exception as e: print e finally: cursor.close() conn.close() mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(topLbl, 0, wx.ALL, 5) mainSizer.Add(wx.StaticLine(panel), 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5) addSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5) addSizer.AddGrowableCol(1) addSizer.Add(text1, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) addSizer.Add(self.text1_ctrl, 0, wx.EXPAND) mainSizer.Add(addSizer, 0, wx.EXPAND | wx.ALL, 10) panel.SetSizer(mainSizer) self.Bind(wx.EVT_CLOSE, self.OnExit)
def OnButton_1(self, event): conn = Mysql_All_is_Use() conn = conn.getConn() cursor = conn.cursor() sql = "select username, password from bank_user;" try: cursor.execute(sql) rs = cursor.fetchall() flag = False for r in rs: if r[0] == self.user_ctrl.GetValue(): wx.MessageBox("%s" % r[1], u"所得密码如下", wx.OK) flag = True break if flag == False: wx.MessageBox(u"当前用户名不存在", u"错误信息", style=wx.OK) except Exception as e: print(self.__doc__) print e finally: cursor.close() conn.close()
def __init__(self, details, label): super(Details_Frame, self).__init__( None, -1, label, size=(400, 200), pos=(400, 100), style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX)) self.details = details self.label = label sql_select1 = "select username from bank_user where bool_id = 1;" # 银行转账的情况 sql_select2 = "select username, money, receive_username, time_operate from some_operation;" # 他人转账时收入的情况 sql_select3 = "select username, money, receive_username, time_operate from some_operation where money >= 0;" # 转出的情况 sql_select4 = "select username, money, receive_username, time_operate from some_operation where money <= 0;" conn = Mysql_All_is_Use() conn = conn.getConn() cur = conn.cursor() try: # 首先获取操作的用户名 cur.execute(sql_select1) rs = cur.fetchall() # 获得用户名 rs = rs[0][0] # print rs # print self.label if self.label == u"银行转账": cur.execute(sql_select2) all_rs = cur.fetchall() # print all_rs the_all = [] for r in all_rs: # print r # print r[2] if r[2] is None: s = (r[0], r[1], r[3]) the_all.append(s) # print the_all label_list = [u"用户名", u"银行转账", u"操作时间"] MyGrid(self, the_all, rs, label_list) elif self.label == u"转出的钱": cur.execute(sql_select4) all_rs = cur.fetchall() the_all = [] for r in all_rs: # print r if r[0] == rs and r[2] is not None: s = (r[2], r[1], r[3]) the_all.append(s) label_list = [u"转出账户", u"转出的钱", u"操作时间"] MyGrid(self, the_all, rs, label_list) else: cur.execute(sql_select3) all_rs = cur.fetchall() the_all = [] for r in all_rs: # print r if r[0] == rs and r[2] is not None: s = (r[2], r[1], r[3]) the_all.append(s) label_list = [u"转入账户", u"转入金额", u"操作时间"] MyGrid(self, the_all, rs, label_list) except Exception as e: print e finally: cur.close() conn.close() self.Bind(wx.EVT_CLOSE, self.OnExit)