def borrow(self): #查询是否还有借书条件 self.my_is = Mysql_demo() sql = 'select borrow from user where id="{0}";'.format(self.acount) data = self.my_is.search(sql)[0][0] if data > 0: #获取当前时间戳 time1 = time.time() #获取20天后的时间戳 time2 = time.time() + 20 * 24 * 60 * 60 time_b = time.strftime("%Y/%m/%d %H:%M", time.localtime(time1)) time_r = time.strftime("%Y/%m/%d %H:%M", time.localtime(time2)) self.my = Mysql_demo() sql = 'insert into bor_book values ("{0}","{1}","{2}","{3}","{4}");'.format( self.acount, self.name, time_b, time_r, self.bor_name) self.my.insert(sql) # 修改自己借书数目 self.my_g = Mysql_demo() sql = 'update user set borrow={0} where id="{1}";'.format( data - 1, self.acount) self.my_g.update(sql) self.hnn = tkinter.messagebox.showinfo( '提示', '借书成功,请在{0}之前归还'.format(time_r)) #修改书的剩余量 my = Mysql_demo() sql = 'update book set re_qu=re_qu-1 where title={0};'.format( self.book_name) my.update(sql) self.base.destroy() else: self.hnt = tkinter.messagebox.showinfo('提示', '您借书已超过上限,无法再次借书!') self.base.destroy()
def to_mysql(self): self.my = Mysql_demo() self.sql = 'insert into user values ("{0}","{1}","{2}","{3}","{4}")'.format(self.tel,self.pwd,self.name,self.gender,3) self.my.insert(self.sql) #提示框 self.hnt = tkinter.messagebox.showinfo('提示', '注册成功,前往登录') self.base.destroy()
def button_1(self): my = Mysql_demo() sql = 'insert into book(title,author,publisher,recolagu,href,drop_type) values ("{0}","{1}","{2}","{3}","{4}","{5}");'.format( self.entry1.get(), self.entry2.get(), self.entry3.get(), self.entry4.get(), self.entry5.get(), self.entry6.get()) my.insert(sql) hnt = tkinter.messagebox.showinfo('提示', '{0} 插入成功'.format(self.entry1.get()))
def __init__(self, acount, name, book_name, drop_type): self.acount = acount self.name = name[0][0] self.book_name = book_name a = Mysql_demo() sql = 'insert into book_dian(book_name,drop_type) values ("{0}","{1}")'.format( self.book_name, drop_type) a.insert(sql)
def root_bor(self): datas = list() a = Mysql_demo() sql = 'select acount,b_date,book_name from bor_book;' data = a.search(sql) for i in range(len(data)): datas.append(data[i][0] + ' ' + data[i][1] + ' ' + str(data[i][2])) datas = tuple(datas) return datas
def root_user(self): datas = list() a = Mysql_demo() sql = 'select id,borrow from user;' data = a.search(sql) for i in range(len(data)): datas.append(data[i][0] + ' ' + str(data[i][1])) datas = tuple(datas) return datas
def first_book_list(self): datas = list() self.rand_num = [random.randint(830, 100000) for _ in range(0, 30)] a = Mysql_demo() for i in self.rand_num: self.sql = 'select title,author from book where _id={0};'.format(i) data = a.search(self.sql) datas.append(data[0][0] + ' ' + data[0][1]) datas = tuple(datas) return datas
def type_book_list(self, type_name): datas = list() a = Mysql_demo() sql = 'select title,author from book where drop_type="{0}";'.format( type_name) data = a.search(sql) for i in range(len(data)): datas.append(data[i][0] + ' ' + data[i][1]) datas = tuple(datas) return datas
def print_item(self, event): # try: self.book_name = ((self.lb.get( self.lb.curselection())).split(' ')[0]).replace('\n', '').strip() print(self.book_name) #根据book_name查找 self.my_s = Mysql_demo() self.sql_s = 'select title,author,publisher,recolagu,href,drop_type from book where title="{0}";'.format( self.book_name) self.book_data = self.my_s.search(self.sql_s) print(self.book_data) self.bde = Book_det(self.id, self.name, self.book_name, self.book_data[0][5]) self.bde.start(self.book_data)
def to_mysql(self): if self.id == '' or self.pwd == '': self.hnt = tkinter.messagebox.showerror('错误', '请输入账号密码') else: self.my = Mysql_demo() self.sql = 'select name from user where id="{0}" and pwd="{1}";'.format( self.id, self.pwd) self.name = self.my.search(self.sql) if self.name != False: self.hnt = tkinter.messagebox.showinfo( '提示', '登录成功,欢迎,{0}'.format(self.name[0][0])) self.bases.destroy() #登录后变化 self.lable.destroy() self.Button_submit.destroy() self.Button_register.destroy() self.lable = tkinter.Label(self.base, text='欢迎,{0}'.format( self.name[0][0]), font=("微软雅黑", 18)) self.lable_title = tkinter.Label(self.base, text='Welcome Book World', font=("微软雅黑", 18), fg='orange') self.Button_per = tkinter.Button(self.base, text="退出登录", font=("隶书", 18), bg='cyan', command=self.person) self.Button_per.place(x=550, y=0) self.Button_huan = tkinter.Button(self.base, text="还书系统", font=("隶书", 18), bg='lawngreen', command=self.return_boo) self.Button_huan.place(x=680, y=0) self.lable_title.place(x=0, y=0) self.lable.place(x=300, y=0, width=200, height=40) else: self.hnt = tkinter.messagebox.showerror('错误', '账号或密码出错了')
def __init__(self): # 数据分析跟数据可视化 self.my = Mysql_demo() sql = 'select book_name,count(*) from bor_book GROUP BY book_name;' datas = self.my.search(sql) data1 = list() data2 = list() if len(datas) > 5: for i in range(5): data1.append(datas[i][0]) data2.append(datas[i][1]) else: for i in range(len(datas)): data1.append(datas[i][0]) data2.append(datas[i][1]) data = {"书名": data1, "数量": data2} data = json.dumps(data) student = pd.read_json(data) # print(student) student.plot.line(x='书名', y='数量') plt.savefig('D:\\pythonproject\\MySQL_project\\data_a\\test2.jpg')
def __init__(self): # 数据分析跟数据可视化 try: self.my = Mysql_demo() sql = 'select drop_type,count(*) from book_dian GROUP BY drop_type ORDER BY count(*) desc;' datas = self.my.search(sql) data1 = list() data2 = list() if len(datas) > 10: for i in range(10): data1.append(datas[i][0]) data2.append(datas[i][1]) else: for i in range(len(datas)): data1.append(datas[i][0]) data2.append(datas[i][1]) data = {"书名": data1, "数量": data2} data = json.dumps(data) student = pd.read_json(data) # print(student) student.plot.pie(x='书名', y='数量', labels=data1) plt.savefig('D:\\pythonproject\\MySQL_project\\data_a\\test1.jpg') except Exception as ex: print(ex)
def my_sql(self): self.b = Mysql_demo() self.sql = 'select id from user' self.data = self.b.search(self.sql) return len(self.data)