def editor_user(self): old_name = self.old_user_name.text() new_name = self.editor_user_name.text() new_email = self.editor_user_email.text() user_pwd = self.eidtor_user_pwd.text() user_confirm_pwd = self.editor_user_confirm_pwd.text() if user_pwd == user_confirm_pwd: # 数据库操作流程 # 1、获取连接 conn = get_conn() # 2、获取cursor cur = conn.cursor() if user_pwd == user_confirm_pwd: # 加盐 hash = hashlib.md5(bytes("禾木AI", encoding="utf-8")) hash.update(bytes(user_pwd, encoding="utf-8")) user_pwd_hash = hash.hexdigest() sql = "update users set user_name=%s, user_email=%s, user_pwd=%s where user_name=%s" # 4、执行语句 cur.execute(sql, (new_name, new_email, user_pwd_hash, old_name)) # 5、insert、update、delete必须显示提交 conn.commit() # 6、关闭资源 close_conn(conn, cur) self.statusBar().showMessage('用户修改成功!') self.user_groupBox.setEnabled(False) else: self.statusBar().showMessage('两次密码不一致!')
def editor_client(self): old_client_id = self.old_client_id.text() client_name = self.editor_client_name.text() client_phone = self.editor_client_phone.text() client_id = self.editor_client_id.text() regex = re.compile(r"(^0\d{2,3}-\d{7,8}$)") if re.match(regex, client_phone): conn = get_conn() # 2、获取cursor cur = conn.cursor() # 3、SQl语句 sql = "update client set client_name=%s, client_phone=%s, client_id=%s " \ "where client_id=%s" # 4、执行语句 cur.execute(sql, (client_name, client_phone, client_id, old_client_id)) # 5、insert、update、delete必须显示提交 conn.commit() # 6、关闭资源 close_conn(conn, cur) self.statusBar().showMessage("修改成功!") self.show_client() else: self.statusBar().showMessage("电话格式位区号-电话")
def add_user(self): # 数据库操作流程 # 1、获取连接 conn = get_conn() # 2、获取cursor cur = conn.cursor() # 3、SQl语句 sql = "insert into users(user_name, user_pwd, user_email) values(%s, %s, %s)" user_name = self.add_user_name.text() user_email = self.add_user_email.text() user_pwd = self.add_user_pwd.text() user_confirm_pwd = self.add_user_confirm_pwd.text() self.error_message.setText("") if user_pwd == user_confirm_pwd: # 加盐 hash = hashlib.md5(bytes("禾木AI", encoding="utf-8")) hash.update(bytes(user_pwd, encoding="utf-8")) user_pwd_hash = hash.hexdigest() # 4、执行语句 cur.execute(sql, (user_name, user_pwd_hash, user_email)) # 5、insert、update、delete必须显示提交 conn.commit() # 6、关闭资源 close_conn(conn, cur) # 7、消息提示 self.statusBar().showMessage('用户添加成功!') self.add_user_name.setText('') self.add_user_email.setText('') self.add_user_pwd.setText('') self.add_user_confirm_pwd.setText('') else: self.error_message.setText("两次密码不一致") self.add_user_pwd.setText('') self.add_user_confirm_pwd.setText('')
def add_book(self): # 数据库操作流程 # 1、获取连接 conn = get_conn() # 2、获取cursor cur = conn.cursor() # 3、SQl语句 sql = "insert into book(book_name, book_description, book_code,book_category, " \ "book_author, book_publisher, book_price) values(%s, %s, %s, %s, %s, %s, %s)" book_name = self.add_book_name.text() book_description = self.add_book_desc.toPlainText() book_code = self.add_book_code.text() book_category = self.add_book_category.currentText() book_author = self.add_book_author.currentText() book_publisher = self.add_book_publisher.currentText() book_price = self.add_book_price.text() # 4、执行语句 cur.execute(sql, (book_name, book_description, book_code, book_category, book_author, book_publisher, book_price)) # 5、insert、update、delete必须显示提交 conn.commit() # 6、关闭资源 close_conn(conn, cur) self.add_book_name.setText('') self.add_book_desc.setPlainText('') self.add_book_code.setText('') self.add_book_category.setCurrentIndex(0) self.add_book_author.setCurrentIndex(0) self.add_book_publisher.setCurrentIndex(0) self.add_book_price.setText('') self.statusBar().showMessage('图书添加成功!') self.add_publisher_name.setText('') self.show_books()
def delete_book(self): # 数据库操作流程 # 1、获取连接 conn = get_conn() # 2、获取cursor cur = conn.cursor() sql = "delete from book where book_name = %s" book_name = self.editor_book_name.text() warning = QMessageBox.warning(self, '删除图书', '你确定要删除', QMessageBox.Yes | QMessageBox.No) if warning == QMessageBox.Yes: cur.execute(sql, (book_name, )) conn.commit() close_conn(conn, cur) self.show_books() self.statusBar().showMessage('图书成功删除')
def delete_client(self): old_client_id = self.old_client_id.text() warning = QMessageBox.warning(self, "删除客户", "你确定删除吗?", QMessageBox.Yes | QMessageBox.No) if warning == QMessageBox.Yes: conn = get_conn() # 2、获取cursor cur = conn.cursor() # 3、SQl语句 sql = "delete from client where client_id = %s" # 4、执行语句 cur.execute(sql, (old_client_id, )) # 5、insert、update、delete必须显示提交 conn.commit() close_conn(cur, conn) self.statusBar().showMessage("删除客户成功!") self.show_client()
def handel_day_operation(self): book_name = self.book_name.text() client_name = self.client_name.text() operate_type = self.tpye_combox.currentText() day_number = self.day_combox.currentIndex() + 1 today_date = datetime.date.today() to_day = today_date + datetime.timedelta(days=day_number) # 数据库操作 conn = get_conn() cur = conn.cursor() sql = "insert into dayoperations(book_name, client_name, type, days, day_from, day_to)" \ "values(%s, %s, %s, %s, %s, %s)" cur.execute(sql, (book_name, client_name, operate_type, day_number, today_date, to_day)) conn.commit() close_conn(conn, cur) self.statusBar().showMessage("操作添加成功!") self.show_all_operations()
def add_publisher(self): # 数据库操作流程 # 1、获取连接 conn = get_conn() # 2、获取cursor cur = conn.cursor() # 3、SQl语句 sql = "insert into publisher(publisher_name) values(%s)" publisher_name = self.add_publisher_name.text() # 4、执行语句 cur.execute(sql, (publisher_name, )) # 5、insert、update、delete必须显示提交 conn.commit() # 6、关闭资源 close_conn(conn, cur) # 7、消息提示 self.statusBar().showMessage('作者添加成功!') self.add_publisher_name.setText('') self.show_publisher()
def add_client(self): # 数据库操作流程 # 1、获取连接 conn = get_conn() # 2、获取cursor cur = conn.cursor() # 3、SQl语句 sql = "insert into client(client_name, client_phone, client_id) values(%s, %s, %s)" client_name = self.add_client_name.text() client_phone = self.add_client_phone.text() client_id = self.add_client_id.text() # 4、执行语句 cur.execute(sql, (client_name, client_phone, client_id)) # 5、insert、update、delete必须显示提交 conn.commit() # 6、关闭资源 close_conn(conn, cur) # 7、消息提示 self.statusBar().showMessage('客户添加成功!') self.add_client_name.setText('') self.add_client_phone.setText('') self.add_client_id.setText('') self.show_client()