class Setting(QWidget): def __init__(self): super().__init__() self.ui = uic.loadUi('ui/user_setting.ui') self.ui.lbl_id.setText('a') self.ui.le_pass.setEchoMode(QLineEdit.Password) self.ui.btn_ok.clicked.connect(self.update) self.ui.btn_can.clicked.connect(self.exit) self.ui.show() def update(self): name = self.ui.le_name.text() password = self.ui.le_pass.text() email = self.ui.le_email.text() self.idt = IDDao() print(self.idt.select_item_id(self.ui.lbl_id.text())[0][1]) self.idt.update_setting(self.ui.lbl_id.text(), name, password, email) self.ui.lbl_name.setText( self.idt.select_item_id(self.ui.lbl_id.text())[0][0]) QMessageBox.information(self, '사용자 정보', '변경되었습니다.', QMessageBox.Ok) def exit(self): self.ui.close()
def __init__(self): super().__init__() self.ui = uic.loadUi("ui/manager.ui") self.idt = IDDao() self.ui.btn_edit_user.setEnabled(False) self.table_user = create_table(table=self.ui.table_user, data=['ID', '이름', '권한', '이메일']) self.load_user() self.ui.le_pass.setEchoMode(QLineEdit.Password) self.ui.com_grant.addItem('--select--') for i in range(len(self.idt.select_mode())): self.ui.com_grant.addItems(self.idt.select_mode()[i]) self.set_context_menu(self.ui.table_user) self.ui.btn_init.clicked.connect(self.coffee_init) self.ui.btn_backup.clicked.connect(self.Backup) self.ui.btn_restore.clicked.connect(self.Restore) self.ui.btn_del_user.clicked.connect(self.del_user) self.ui.btn_insert_user.clicked.connect(self.ins_user) self.ui.btn_edit_user.clicked.connect(self.edit_user) self.ui.btn_exit.clicked.connect(self.exit) self.ui.show()
def __init__(self, *args, **kwargs): super().__init__() self.pdt = ProductDao() self.idt = IDDao() self.sdt = SaleDao() self.ui = uic.loadUi("ui/main_menu.ui", self) self.month_count = 14 self.graphcount = 0 # combobox self.combobox_setting() # graph self.graph() # table self.table_pro = create_table(table=self.ui.table_pro, data=['제품코드', '제품명', '종류', '제품가격', '마진율(%)']) self.sale_pro = create_table(table=self.ui.table_sale, data=['제품명', '판매량', '판매금액', '판매일']) self.load_pro_all() self.load_sale_all() self.ui.btn_out.clicked.connect(self.exit) # logout self.ui.btn_manage.clicked.connect(self.manage) self.ui.btn_sale.clicked.connect(self.sale_manage) self.ui.btn_exit.clicked.connect(self.exit) self.ui.btn_set.clicked.connect(self.user_setting) self.ui.combo_menu.currentIndexChanged.connect(self.select_menu) self.ui.combo_sale_year.currentIndexChanged.connect(self.select_sale) self.ui.combo_sale_month.currentIndexChanged.connect(self.select_month) self.ui.show()
def sale_manage(self): self.sale = SaleMenu() grant = [] for i in range(len(IDDao().select_grant('admin'))): a = IDDao().select_grant(self.ui.lbl_mode.text()).count(IDDao().select_grant('admin')[i]) grant.append(a) if grant[2] == 0: self.sale.ui.tab_product.removeTab(0)
def __init__(self): super().__init__() self.idt = IDDao() self.ui = uic.loadUi('ui/findpass.ui') self.ui.btn_exit.clicked.connect(self.exit) self.ui.btn_find.clicked.connect(self.find) self.ui.show()
def update(self): name = self.ui.le_name.text() password = self.ui.le_pass.text() email = self.ui.le_email.text() self.idt = IDDao() print(self.idt.select_item_id(self.ui.lbl_id.text())[0][1]) self.idt.update_setting(self.ui.lbl_id.text(), name, password, email) self.ui.lbl_name.setText( self.idt.select_item_id(self.ui.lbl_id.text())[0][0]) QMessageBox.information(self, '사용자 정보', '변경되었습니다.', QMessageBox.Ok)
def check_grant(self): grant = [] for i in range(len(IDDao().select_grant('admin'))): a = IDDao().select_grant(self.ui.lbl_mode.text()).count( IDDao().select_grant('admin')[i]) grant.append(a) if grant[4] == 0: self.ui.tab_manage.removeTab(1) if grant[3] == 0: self.ui.tab_manage.removeTab(0)
class Find(QWidget): def __init__(self): super().__init__() self.idt = IDDao() self.ui = uic.loadUi('ui/findpass.ui') self.ui.btn_exit.clicked.connect(self.exit) self.ui.btn_find.clicked.connect(self.find) self.ui.show() def exit(self): self.ui.close() def find(self): id = self.ui.le_ID.text() name = self.ui.le_name.text() email = self.ui.le_email.text() try: count = 0 if id == self.idt.select_data(id, type='user_id')[0][0]: count = 1 if name == self.idt.select_data(name, type='name')[0][1]: count = 2 if email == self.idt.select_data(email, type='email')[0][2]: _LENGTH = 15 _string = string.ascii_letters + string.digits password = "" for i in range(_LENGTH): password += random.choice(_string) QMessageBox.information( self, '비밀번호 찾기', '비밀번호는 ' + password + ' 로 변경되었습니다.', QMessageBox.Ok) self.idt.find_pass(password, id, name, email) except: if count == 0: QMessageBox.information(self, '비밀번호 찾기', '아이디가 틀렸습니다', QMessageBox.Ok) elif count == 1: QMessageBox.information(self, '비밀번호 찾기', '이름이 틀렸습니다', QMessageBox.Ok) elif count == 2: QMessageBox.information(self, '비밀번호 찾기', '이메일이 틀렸습니다', QMessageBox.Ok)
def __init__(self): super().__init__() self.ui = uic.loadUi("ui/User_registration.ui") self.idt = IDDao() self.idt.select_item() self.ui.le_pass.setEchoMode(QLineEdit.Password) self.ui.com_grant.addItem('--select--') for i in range(len(self.idt.select_mode()) - 1): self.ui.com_grant.addItems(self.idt.select_mode()[i + 1]) self.ui.btn_ok.clicked.connect(self.sign_up) self.ui.btn_can.clicked.connect(self.exit) self.ui.le_pass.returnPressed.connect(self.sign_up) self.ui.le_id.returnPressed.connect(self.sign_up) self.ui.le_name.returnPressed.connect(self.sign_up) self.ui.le_email.returnPressed.connect(self.sign_up) self.ui.show()
class Main(QtWidgets.QMainWindow): def __init__(self, *args, **kwargs): super().__init__() self.pdt = ProductDao() self.idt = IDDao() self.sdt = SaleDao() self.ui = uic.loadUi("ui/main_menu.ui", self) self.month_count = 14 self.graphcount = 0 # combobox self.combobox_setting() # graph self.graph() # table self.table_pro = create_table(table=self.ui.table_pro, data=['제품코드', '제품명', '종류', '제품가격', '마진율(%)']) self.sale_pro = create_table(table=self.ui.table_sale, data=['제품명', '판매량', '판매금액', '판매일']) self.load_pro_all() self.load_sale_all() self.ui.btn_out.clicked.connect(self.exit) # logout self.ui.btn_manage.clicked.connect(self.manage) self.ui.btn_sale.clicked.connect(self.sale_manage) self.ui.btn_exit.clicked.connect(self.exit) self.ui.btn_set.clicked.connect(self.user_setting) self.ui.combo_menu.currentIndexChanged.connect(self.select_menu) self.ui.combo_sale_year.currentIndexChanged.connect(self.select_sale) self.ui.combo_sale_month.currentIndexChanged.connect(self.select_month) self.ui.show() # button ui def manage(self): self.ms = management_system() self.ms.ui.lbl_ID.setText(self.ui.lbl_ID.text()) self.ms.ui.lbl_mode.setText(list(self.idt.select_item(self.ui.lbl_ID.text()))[0][1]) self.ms.check_grant() def sale_manage(self): self.sale = SaleMenu() grant = [] for i in range(len(IDDao().select_grant('admin'))): a = IDDao().select_grant(self.ui.lbl_mode.text()).count(IDDao().select_grant('admin')[i]) grant.append(a) if grant[2] == 0: self.sale.ui.tab_product.removeTab(0) def logout(self): self.ui.close() def exit(self): self.ui.close() def combobox_setting(self): self.ui.combo_menu.addItem('all') self.ui.combo_sale_year.addItem('all') self.ui.combo_sale_month.addItem('년도를 선택해주세요') for i in range(len(self.pdt.select_category())): self.ui.combo_menu.addItems(self.pdt.select_category()[i]) for i in range(len(self.sdt.select_item(True))): self.ui.combo_sale_year.addItems(tuple(self.sdt.select_item(True)[i])) # product table def select_menu(self): if self.ui.combo_menu.currentText() == 'all': self.load_pro_all() else: res = list(self.pdt.select_menu(self.ui.combo_menu.currentText())) self.load_pro(res) def load_pro(self, res): self.ui.table_pro.setRowCount(0) for (code, name, price, marginrate, category) in res: item_code, item_name, item_price, item_marginrate, item_category = self.pro_create_item(code, name, price, marginrate, category) nextIdx = self.ui.table_pro.rowCount() self.ui.table_pro.insertRow(nextIdx) self.ui.table_pro.setItem(nextIdx, 0, item_code) self.ui.table_pro.setItem(nextIdx, 1, item_name) self.ui.table_pro.setItem(nextIdx, 2, item_category) self.ui.table_pro.setItem(nextIdx, 3, item_price) self.ui.table_pro.setItem(nextIdx, 4, item_marginrate) def pro_create_item(self, code, name, price, marginrate, category): item_code = QTableWidgetItem() item_code.setTextAlignment(Qt.AlignCenter) item_code.setData(Qt.DisplayRole, code) item_name = QTableWidgetItem() item_name.setTextAlignment(Qt.AlignCenter) item_name.setData(Qt.DisplayRole, name) item_price = QTableWidgetItem() item_price.setTextAlignment(Qt.AlignRight) if price != None: item_price.setData(Qt.DisplayRole, format(int(price), ',d')) else: item_price.setData(Qt.DisplayRole, '-') item_marginrate = QTableWidgetItem() item_marginrate.setTextAlignment(Qt.AlignRight) if marginrate != None: item_marginrate.setData(Qt.DisplayRole, (marginrate)) else: item_marginrate.setData(Qt.DisplayRole, '-') item_category = QTableWidgetItem() item_category.setTextAlignment(Qt.AlignCenter) item_category.setData(Qt.DisplayRole, category) return item_code, item_name, item_price, item_marginrate, item_category def load_pro_all(self): self.ui.table_pro.setRowCount(0) res = self.pdt.select_menu2() for (code, name, price, marginrate, category) in res: item_code, item_name, item_price, item_marginrate, item_category = self.pro_create_item(code, name, price, marginrate, category) nextIdx = self.ui.table_pro.rowCount() self.ui.table_pro.insertRow(nextIdx) self.ui.table_pro.setItem(nextIdx, 0, item_code) self.ui.table_pro.setItem(nextIdx, 1, item_name) self.ui.table_pro.setItem(nextIdx, 2, item_category) self.ui.table_pro.setItem(nextIdx, 3, item_price) self.ui.table_pro.setItem(nextIdx, 4, item_marginrate) # sale_table def sale_create_item(self, name, salecnt, sale_price, date): item_name = QTableWidgetItem() item_name.setTextAlignment(Qt.AlignCenter) item_name.setData(Qt.DisplayRole, name) item_salecnt = QTableWidgetItem() item_salecnt.setTextAlignment(Qt.AlignCenter) item_salecnt.setData(Qt.DisplayRole, salecnt) item_sale_price = QTableWidgetItem() item_sale_price.setTextAlignment(Qt.AlignRight) item_sale_price.setData(Qt.DisplayRole, format(int(sale_price), ',d')) item_date = QTableWidgetItem() item_date.setTextAlignment(Qt.AlignCenter) item_date.setData(Qt.DisplayRole, date) return item_name, item_salecnt, item_sale_price, item_date def load_sale_all(self): self.ui.table_sale.setRowCount(0) res = self.sdt.select_item() for (name, salecnt, sale_price, date) in res: item_name, item_salecnt, item_sale_price, item_date = self.sale_create_item(name, salecnt, sale_price, date) nextIdx = self.ui.table_sale.rowCount() self.ui.table_sale.insertRow(nextIdx) self.ui.table_sale.setItem(nextIdx, 0, item_name) self.ui.table_sale.setItem(nextIdx, 1, item_salecnt) self.ui.table_sale.setItem(nextIdx, 2, item_sale_price) self.ui.table_sale.setItem(nextIdx, 3, item_date) def select_sale(self): if self.ui.combo_sale_year.currentText() == 'all': for i in range(0, self.month_count): self.ui.combo_sale_month.removeItem(0) self.ui.combo_sale_month.addItem('년도를 선택해주세요') self.load_sale_all() else: res = list(self.sdt.select_date(self.ui.combo_sale_year.currentText())) for i in range(0, self.month_count): self.ui.combo_sale_month.removeItem(0) self.ui.combo_sale_month.addItem('all') self.load_sale(res) for i in range(len(self.sdt.select_date(self.ui.combo_sale_year.currentText(), 2))): self.ui.combo_sale_month.addItems(self.sdt.select_date(self.ui.combo_sale_year.currentText(), 2)[i]) def load_sale(self, res): self.ui.table_sale.setRowCount(0) for (name, salecnt, sale_price, date) in res: item_name, item_salecnt, item_sale_price, item_date = self.sale_create_item(name, salecnt, sale_price, date) nextIdx = self.ui.table_sale.rowCount() self.ui.table_sale.insertRow(nextIdx) self.ui.table_sale.setItem(nextIdx, 0, item_name) self.ui.table_sale.setItem(nextIdx, 1, item_salecnt) self.ui.table_sale.setItem(nextIdx, 2, item_sale_price) self.ui.table_sale.setItem(nextIdx, 3, item_date) def select_month(self, res): if self.ui.combo_sale_month.currentText() is None or self.ui.combo_sale_month.currentText() == 'all': self.load_sale(self.sdt.select_date(self.ui.combo_sale_year.currentText())) else: date = self.sdt.select_date( self.ui.combo_sale_year.currentText() + ' ' + self.ui.combo_sale_month.currentText(), 3) self.load_sale(date) # 계정관리 def user_setting(self): self.set = Setting() self.set.ui.lbl_id.setText(self.ui.lbl_ID.text()) self.set.ui.lbl_name.setText(self.idt.select_item_id(self.ui.lbl_ID.text())[0][0]) self.set.ui.lbl_mode.setText(self.idt.select_item_id(self.ui.lbl_ID.text())[0][1]) # graph def graph(self): # 글꼴 mpl.rcParams['font.family'] = 'NanumGothic' mpl.rcParams['axes.unicode_minus'] = False # data name, price = self.sdt.select_graph() fig, ax1 = plt.subplots() # plot self.plotWidget = FigureCanvas(fig) ax1.set_title("커피 판매량") self.lay = QtWidgets.QVBoxLayout(self.ui.content_plot) self.lay.addWidget(self.plotWidget) ax1.pie(price, labels=name, autopct=lambda pct: self.func(pct, price), shadow=False, startangle=90, radius=1.0) def func(self, pct, data): absolute = round(int(pct * float(math.ceil(np.sum(data)))) / 100) return "{:.1f}%\n({:,d})".format(pct, absolute)
class Sign_up(QWidget): def __init__(self): super().__init__() self.ui = uic.loadUi("ui/User_registration.ui") self.idt = IDDao() self.idt.select_item() self.ui.le_pass.setEchoMode(QLineEdit.Password) self.ui.com_grant.addItem('--select--') for i in range(len(self.idt.select_mode()) - 1): self.ui.com_grant.addItems(self.idt.select_mode()[i + 1]) self.ui.btn_ok.clicked.connect(self.sign_up) self.ui.btn_can.clicked.connect(self.exit) self.ui.le_pass.returnPressed.connect(self.sign_up) self.ui.le_id.returnPressed.connect(self.sign_up) self.ui.le_name.returnPressed.connect(self.sign_up) self.ui.le_email.returnPressed.connect(self.sign_up) self.ui.show() def sign_up(self): check = 0 id = self.ui.le_id.text() password = self.ui.le_pass.text() mode = self.ui.com_grant.currentText() name = self.ui.le_name.text() email = self.ui.le_email.text() if mode == '--select--': QMessageBox.information(self, '사용자 등록', '유저 권한을 설정해 주세요.', QMessageBox.Ok) else: if self.idt.select_item('{}'.format(id)): QMessageBox.information(self, '사용자 등록', '해당 아이디가 이미 있습니다.', QMessageBox.Ok) check = 1 if id == '': QMessageBox.information(self, '사용자 등록', '아이디를 입력해주세요.', QMessageBox.Ok) if email == '': QMessageBox.information(self, '사용자 등록', '이메일를 입력해주세요.', QMessageBox.Ok) if name == '': QMessageBox.information(self, '사용자 등록', '이름를 입력해주세요.', QMessageBox.Ok) else: if check == 0: QMessageBox.information(self, '사용자 등록', '등록되었습니다.', QMessageBox.Ok) self.idt.insert_item(id, password, mode, name, email) self.idt.select_item() self.clear() def exit(self): self.clear() self.ui.close() def clear(self): self.ui.le_pass.clear() self.ui.le_id.clear() self.ui.le_name.clear() self.ui.le_email.clear()
class management_system(QWidget): def __init__(self): super().__init__() self.ui = uic.loadUi("ui/manager.ui") self.idt = IDDao() self.ui.btn_edit_user.setEnabled(False) self.table_user = create_table(table=self.ui.table_user, data=['ID', '이름', '권한', '이메일']) self.load_user() self.ui.le_pass.setEchoMode(QLineEdit.Password) self.ui.com_grant.addItem('--select--') for i in range(len(self.idt.select_mode())): self.ui.com_grant.addItems(self.idt.select_mode()[i]) self.set_context_menu(self.ui.table_user) self.ui.btn_init.clicked.connect(self.coffee_init) self.ui.btn_backup.clicked.connect(self.Backup) self.ui.btn_restore.clicked.connect(self.Restore) self.ui.btn_del_user.clicked.connect(self.del_user) self.ui.btn_insert_user.clicked.connect(self.ins_user) self.ui.btn_edit_user.clicked.connect(self.edit_user) self.ui.btn_exit.clicked.connect(self.exit) self.ui.show() def exit(self): self.ui.close() def msgbox1(self): QMessageBox.information(self, "Success", "초기화 성공") def msgbox2(self): QMessageBox.information(self, "Failed", "초기화 실패") def msgbox3(self): QMessageBox.information(self, "Success", "백업 성공") def msgbox3_1(self): QMessageBox.information(self, "Failed", "백업 실패") def msgbox4(self): QMessageBox.information(self, "Success", "복구 성공") def msgbox4_1(self): QMessageBox.information(self, "Failed", "복구 실패") def coffee_init(self): db = DbInit() if db.service() == 0: self.msgbox1() else: self.msgbox2() def Backup(self): br = BackupRestore() now_date = time.strftime('%Y-%m-%d', time.localtime(time.time())) mkdir_backup = '/tmp/backup/' + now_date try: os.system('mkdir /tmp/backup') except: pass os.system('mkdir ' + mkdir_backup) os.system('chmod 777 ' + mkdir_backup) tablename = [ 'product', 'sale', 'sale_detail', 'mode_grant', 'category', 'user_data', 'user_mode' ] try: for i in range(len(tablename)): br.data_backup(table_name=tablename[i]) except: pass def Restore(self): br = BackupRestore() tablename = [ 'product', 'sale', 'sale_detail', 'mode_grant', 'category', 'user_data', 'user_mode' ] for i in range(len(tablename)): br.data_restore(table_name=tablename[i]) def check_grant(self): grant = [] for i in range(len(IDDao().select_grant('admin'))): a = IDDao().select_grant(self.ui.lbl_mode.text()).count( IDDao().select_grant('admin')[i]) grant.append(a) if grant[4] == 0: self.ui.tab_manage.removeTab(1) if grant[3] == 0: self.ui.tab_manage.removeTab(0) # table def load_user(self): self.ui.table_user.setRowCount(0) res = self.idt.select_item_mode() for (ID, name, mode, email) in res: item_ID, item_name, item_mode, item_email = self.user_create_item( ID, name, mode, email) nextIdx = self.ui.table_user.rowCount() self.ui.table_user.insertRow(nextIdx) self.ui.table_user.setItem(nextIdx, 0, item_ID) self.ui.table_user.setItem(nextIdx, 1, item_name) self.ui.table_user.setItem(nextIdx, 2, item_mode) self.ui.table_user.setItem(nextIdx, 3, item_email) def user_create_item(self, ID, name, mode, email): item_code = QTableWidgetItem() item_code.setTextAlignment(Qt.AlignCenter) item_code.setData(Qt.DisplayRole, ID) item_name = QTableWidgetItem() item_name.setTextAlignment(Qt.AlignCenter) item_name.setData(Qt.DisplayRole, name) item_mode = QTableWidgetItem() item_mode.setTextAlignment(Qt.AlignCenter) item_mode.setData(Qt.DisplayRole, mode) item_email = QTableWidgetItem() item_email.setTextAlignment(Qt.AlignCenter) item_email.setData(Qt.DisplayRole, email) return item_code, item_name, item_mode, item_email # user_manage def del_user(self): selectionIdxs = self.ui.table_user.selectedIndexes()[0] user_id = self.ui.table_user.item(selectionIdxs.row(), 0).text() self.ui.table_user.removeRow(selectionIdxs.row()) self.idt.delete_item(user_id) def ins_user(self): item_mode = self.ui.com_grant.currentText() count = 0 if item_mode == '--select--': QMessageBox.information(self, '사용자 관리', '유저 권한을 설정해 주세요.', QMessageBox.Ok) else: item_id = self.ui.le_user_id.text() item_name = self.ui.le_name.text() item_email = self.ui.le_email.text() item_pass = self.ui.le_pass.text() if item_id == '': QMessageBox.information(self, '사용자 관리', '아이디를 입력해주세요.', QMessageBox.Ok) count = 1 if item_name == '': QMessageBox.information(self, '사용자 관리', '이름을 입력해주세요.', QMessageBox.Ok) count = 1 if item_email == '': QMessageBox.information(self, '사용자 관리', '이메일을 입력해주세요.', QMessageBox.Ok) count = 1 if count == 0: self.idt.insert_item(item_id, item_pass, item_mode, item_name, item_email) self.load_user() def edit_user(self): id = self.ui.le_user_id.text() mode = self.ui.com_grant.currentText() name = self.ui.le_name.text() email = self.ui.le_email.text() if mode == '--select--': QMessageBox.information(self, '사용자 관리', '유저 권한을 설정해 주세요.', QMessageBox.Ok) else: item_id, item_name, item_mode, item_email = self.user_create_item( id, name, mode, email) selectionIdxs = self.ui.table_user.selectedIndexes()[0] self.ui.table_user.setItem(selectionIdxs.row(), 0, item_id) self.ui.table_user.setItem(selectionIdxs.row(), 1, item_name) self.ui.table_user.setItem(selectionIdxs.row(), 2, item_mode) self.ui.table_user.setItem(selectionIdxs.row(), 3, item_email) self.ui.btn_del_user.setEnabled(True) self.ui.btn_init.setEnabled(True) self.ui.btn_insert_user.setEnabled(True) self.ui.btn_edit_user.setEnabled(False) self.ui.le_pass.setEnabled(True) self.clear() self.idt.update_item(id, mode, name, email) QMessageBox.information(self, '사용자 관리', '확인', QMessageBox.Ok) def clear(self): self.ui.le_user_id.clear() self.ui.le_name.clear() self.ui.le_email.clear() self.ui.le_pass.clear() def update(self): selectionIdxs = self.ui.table_user.selectedIndexes()[0] returnIdxs1 = self.ui.table_user.item(selectionIdxs.row(), 0).text() returnIdxs2 = self.ui.table_user.item(selectionIdxs.row(), 1).text() returnIdxs3 = self.ui.table_user.item(selectionIdxs.row(), 2).text() returnIdxs4 = self.ui.table_user.item(selectionIdxs.row(), 3).text() self.ui.le_user_id.setText(returnIdxs1) self.ui.le_name.setText(returnIdxs2) self.ui.le_email.setText(returnIdxs4) self.ui.btn_edit_user.setEnabled(True) self.ui.btn_del_user.setEnabled(False) self.ui.btn_init.setEnabled(False) self.ui.btn_insert_user.setEnabled(False) self.ui.le_pass.setEnabled(False) def set_context_menu(self, tv): tv.setContextMenuPolicy(Qt.ActionsContextMenu) update_action = QAction('수정', tv) tv.addAction(update_action) update_action.triggered.connect(self.update)