Example #1
0
 def __init__(self, parent=None):
     QDialog.__init__(self, parent)
     super().__init__()
     self.setupUi(self)
     self.lineEdit_new_item_discount.setValidator(
         QRegExpValidator(QRegExp("\d+")))
     self.lineEdit_new_item_unitprice.setValidator(
         QRegExpValidator(QRegExp("\d+")))
     self.selected_order_id = None
     self.selected_item: Optional[Union[FoodItem, DrinkItem]] = None
     self.timer = QTimer(self)
     self.timer.timeout.connect(self.update_timer_label)
     self.timer.start(1000)
     self.refresh_timer = QTimer(self)
     self.refresh_timer.timeout.connect(self.get_actual_orders)
     self.refresh_timer.start(30000)
     self.message_box = Messagebox()
     self.sql = SqliteController()
     self.soup_list: List[FoodItem] = []
     self.salad_list: List[FoodItem] = []
     self.meat_list: List[FoodItem] = []
     self.dessert_list: List[FoodItem] = []
     self.fishfood_list: List[FoodItem] = []
     self.coffee_tee_list: List[DrinkItem] = []
     self.soft_drinks_list: List[DrinkItem] = []
     self.beer_list: List[DrinkItem] = []
     self.wein_list: List[DrinkItem] = []
     self.shoot_list: List[DrinkItem] = []
     self.restaurant_order_list: List[RestaurantOrder] = []
     self.get_soups()
     self.get_actual_orders()
     self.comboBox_new_item_type.addItems(['Ételek', 'Italok'])
     self.comboBox_item_types.addItems(['Ételek', 'Italok'])
     self.refresh_category()
     self.refresh_items()
     self.refresh_category_in_new_item_form()
     self.get_selected_item_details()
     """Method connections"""
     self.table_orders.cellClicked.connect(self.get_selected_order_details)
     self.server_tabwidget.currentChanged.connect(
         self.get_selected_tabwidget_on_main)
     self.all_items_tab.currentChanged.connect(
         self.get_selected_tabwidget_on_secondary)
     self.btn_order_delete.clicked.connect(self.delete_actual_order)
     self.btn_paid.clicked.connect(self.set_paid)
     self.comboBox_item_types.currentTextChanged.connect(
         self.refresh_category)
     self.comboBox_item_category.currentTextChanged.connect(
         self.refresh_items)
     self.comboBox_new_item_type.currentTextChanged.connect(
         self.refresh_category_in_new_item_form)
     self.comboBox_items.currentTextChanged.connect(
         self.get_selected_item_details)
     self.btn_save_new_item.clicked.connect(self.save_new_item)
     self.btn_save_modification.clicked.connect(self.save_modification)
Example #2
0
 def __init__(self):
     super(base_login, self).__init__()
     self.setupUi(self)
     self.config_object = Config()
     self.message_box = Messagebox()
     self.btn_server.clicked.connect(lambda: self.login_into_server(
         self.username_textbox.text(), self.password_textbox.text()))
     self.btn_client.clicked.connect(lambda: self.login_into_client(
         self.username_textbox.text(), self.password_textbox.text()))
     self.btn_new_reg.clicked.connect(lambda: self.new_user_reg(
         self.new_username_textbox.text(), self.new_password_textbox.text(),
         self.new_confirmed_passw_textbox.text()))
     self.btn_login_cancel.clicked.connect(self.close_main_window)
     self.btn_reg_cancel.clicked.connect(self.close_main_window)
     self.configuration_start()
     self.db_path = self.config_object.get_db_path()
     self.sql = SqliteController()
Example #3
0
 def __init__(self, parent=None):
     QDialog.__init__(self, parent)
     super().__init__()
     self.message_box = Messagebox()
     self.drinks_list: List[DrinkItem] = []
     self.food_list: List[FoodItem] = []
     self.order_table_list: List[Union[DrinkItem, FoodItem]] = []
     self.ordered_dict_for_order_qtable: dict = {}
     self.setupUi(self)
     self.actual_list_type = ItemType.DRINK
     self.table_item_list.setRowCount(0)
     self.sql = SqliteController()
     self.get_drinks()
     self.btn_drinks.clicked.connect(self.get_drinks)
     self.btn_food.clicked.connect(self.get_food)
     self.table_item_list.cellClicked.connect(self.add_item_to_order)
     self.table_item_list.setEditTriggers(
         QtGui.QAbstractItemView.NoEditTriggers)
     self.table_order_list.cellClicked.connect(self.delete_item_from_order)
     self.btn_order_items.clicked.connect(self.send_order)
     self.btn_menu_cancel.clicked.connect(self.close_menu_window)
Example #4
0
class MenuWindow(QDialog, Ui_menu_dialog):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        super().__init__()
        self.message_box = Messagebox()
        self.drinks_list: List[DrinkItem] = []
        self.food_list: List[FoodItem] = []
        self.order_table_list: List[Union[DrinkItem, FoodItem]] = []
        self.ordered_dict_for_order_qtable: dict = {}
        self.setupUi(self)
        self.actual_list_type = ItemType.DRINK
        self.table_item_list.setRowCount(0)
        self.sql = SqliteController()
        self.get_drinks()
        self.btn_drinks.clicked.connect(self.get_drinks)
        self.btn_food.clicked.connect(self.get_food)
        self.table_item_list.cellClicked.connect(self.add_item_to_order)
        self.table_item_list.setEditTriggers(
            QtGui.QAbstractItemView.NoEditTriggers)
        self.table_order_list.cellClicked.connect(self.delete_item_from_order)
        self.btn_order_items.clicked.connect(self.send_order)
        self.btn_menu_cancel.clicked.connect(self.close_menu_window)

    def add_item_to_order(self, row, column):
        print(f'Row: {row}')
        print(f'Column: {column}')
        if self.actual_list_type == ItemType.FOOD:
            self.order_table_list.append(self.food_list[row])
        elif self.actual_list_type == ItemType.DRINK:
            self.order_table_list.append(self.drinks_list[row])
        self.refresh_order_table()

    def delete_item_from_order(self, row, column):
        item = self.table_order_list.item(row, column)
        not_deleted = True
        i = 0
        while (not_deleted):
            if type(self.order_table_list[i]
                    ) is DrinkItem and self.order_table_list[
                        i].drink_item_name == item.text():
                self.order_table_list.pop(i)
                not_deleted = False
            elif type(self.order_table_list[i]
                      ) is FoodItem and self.order_table_list[
                          i].food_item_name == item.text():
                self.order_table_list.pop(i)
                not_deleted = False
            else:
                i += 1
        self.refresh_order_table()

    def get_drinks(self):
        self.clear_item_table_list()
        self.actual_list_type = ItemType.DRINK
        try:
            rows = self.sql.execute_command(Operation.SELECT, 'DrinkItem', [])
            for index_i, row in enumerate(rows):
                drink_item = DrinkItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                if drink_item not in self.drinks_list:
                    self.drinks_list.append(drink_item)
                    self.table_item_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_item_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
            self.table_item_list.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_food(self):
        self.clear_item_table_list()
        self.actual_list_type = ItemType.FOOD
        widget = QTableWidgetItem('Hello')
        try:
            rows = self.sql.execute_command(Operation.SELECT, 'FoodItem', [])
            for index_i, row in enumerate(rows):
                food_item = FoodItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                if food_item not in self.food_list:
                    self.food_list.append(food_item)
                    self.table_item_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_item_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_finally_price(self):
        final_price = 0
        for key, value in self.ordered_dict_for_order_qtable.items():
            key: Union[DrinkItem, FoodItem]
            if type(key) is DrinkItem:
                final_price += int(key.drink_price) * value
            elif type(key) is FoodItem:
                final_price += int(key.food_price) * value
        return final_price

    def refresh_order_table(self):
        self.clear_order_table()
        self.collect_order_items_into_ordered_list()
        for index_i, key_element in enumerate(
                self.ordered_dict_for_order_qtable.keys()):
            key_element: Union[DrinkItem, FoodItem]
            self.table_order_list.insertRow(index_i)
            if type(key_element) == DrinkItem:
                self.table_order_list.setItem(
                    index_i, 0, QTableWidgetItem(key_element.drink_item_name))
                self.table_order_list.setItem(
                    index_i, 1,
                    QTableWidgetItem(
                        str(self.ordered_dict_for_order_qtable[key_element])))
                self.table_order_list.setItem(
                    index_i, 2,
                    QTableWidgetItem(
                        str(
                            int(key_element.drink_price) *
                            self.ordered_dict_for_order_qtable[key_element])))
            elif type(key_element) == FoodItem:
                self.table_order_list.setItem(
                    index_i, 0, QTableWidgetItem(key_element.food_item_name))
                self.table_order_list.setItem(
                    index_i, 1,
                    QTableWidgetItem(
                        str(self.ordered_dict_for_order_qtable[key_element])))
                self.table_order_list.setItem(
                    index_i, 2,
                    QTableWidgetItem(
                        str(
                            int(key_element.food_price) *
                            self.ordered_dict_for_order_qtable[key_element])))
        self.table_order_list.resizeColumnsToContents()
        self.label_final_price.setText(str(self.get_finally_price()))

    def clear_order_table(self):
        while (self.table_order_list.rowCount() > 0):
            {self.table_order_list.removeRow(0)}

    def clear_item_table_list(self):
        while (self.table_item_list.rowCount() > 0):
            {self.table_item_list.removeRow(0)}
        self.drinks_list = []
        self.food_list = []

    def collect_order_items_into_ordered_list(self):
        self.ordered_dict_for_order_qtable = {}
        for order_item in self.order_table_list:
            if self.ordered_dict_for_order_qtable:
                if order_item in self.ordered_dict_for_order_qtable.keys():
                    self.ordered_dict_for_order_qtable[
                        order_item] = self.ordered_dict_for_order_qtable[
                            order_item] + 1
                else:
                    self.ordered_dict_for_order_qtable[order_item] = 1
            else:
                self.ordered_dict_for_order_qtable[order_item] = 1
        print('OK')

    def send_order(self):
        self.sql.execute_command(
            Operation.INSERT,
            'RestaurantOrder',
            insertion_value_dict={
                'StartTime':
                str(datetime.today()).split('.')[0].replace('-', '.'),
                'EndTime': '',
                'Price': str(self.get_finally_price()),
                'Making': 1,
                'Served': 0,
                'Paid': 0
            })
        order_id = self.sql.execute_command(Operation.SELECT,
                                            'RestaurantOrder',
                                            ['RestaurantOrderID'])[-1]
        for key, value in self.ordered_dict_for_order_qtable.items():
            key: Union[DrinkItem, FoodItem]
            if type(key) is DrinkItem:
                print('DrinItem sent')
                self.sql.execute_command(Operation.INSERT,
                                         'RestaurantDrinkOrderItem',
                                         insertion_value_dict={
                                             'RestaurantOrderID':
                                             str(order_id[0]),
                                             'DrinkItemID': key.drink_item_id,
                                             'Quantity': value
                                         })
            elif type(key) is FoodItem:
                print('FoodItem sent')
                self.sql.execute_command(Operation.INSERT,
                                         'RestaurantFoodOrderItem',
                                         insertion_value_dict={
                                             'RestaurantOrderID':
                                             str(order_id[0]),
                                             'FoodItemID': key.food_item_id,
                                             'Quantity': value
                                         })
        self.clear_order_table()
        self.clear_item_table_list()
        self.label_final_price.setText('')
        self.ordered_dict_for_order_qtable = {}
        self.order_table_list = []
        self.get_drinks()

    def close_menu_window(self):
        sys.exit()
Example #5
0
class ServerWindow(QDialog, Ui_server_window):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        super().__init__()
        self.setupUi(self)
        self.lineEdit_new_item_discount.setValidator(
            QRegExpValidator(QRegExp("\d+")))
        self.lineEdit_new_item_unitprice.setValidator(
            QRegExpValidator(QRegExp("\d+")))
        self.selected_order_id = None
        self.selected_item: Optional[Union[FoodItem, DrinkItem]] = None
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update_timer_label)
        self.timer.start(1000)
        self.refresh_timer = QTimer(self)
        self.refresh_timer.timeout.connect(self.get_actual_orders)
        self.refresh_timer.start(30000)
        self.message_box = Messagebox()
        self.sql = SqliteController()
        self.soup_list: List[FoodItem] = []
        self.salad_list: List[FoodItem] = []
        self.meat_list: List[FoodItem] = []
        self.dessert_list: List[FoodItem] = []
        self.fishfood_list: List[FoodItem] = []
        self.coffee_tee_list: List[DrinkItem] = []
        self.soft_drinks_list: List[DrinkItem] = []
        self.beer_list: List[DrinkItem] = []
        self.wein_list: List[DrinkItem] = []
        self.shoot_list: List[DrinkItem] = []
        self.restaurant_order_list: List[RestaurantOrder] = []
        self.get_soups()
        self.get_actual_orders()
        self.comboBox_new_item_type.addItems(['Ételek', 'Italok'])
        self.comboBox_item_types.addItems(['Ételek', 'Italok'])
        self.refresh_category()
        self.refresh_items()
        self.refresh_category_in_new_item_form()
        self.get_selected_item_details()
        """Method connections"""
        self.table_orders.cellClicked.connect(self.get_selected_order_details)
        self.server_tabwidget.currentChanged.connect(
            self.get_selected_tabwidget_on_main)
        self.all_items_tab.currentChanged.connect(
            self.get_selected_tabwidget_on_secondary)
        self.btn_order_delete.clicked.connect(self.delete_actual_order)
        self.btn_paid.clicked.connect(self.set_paid)
        self.comboBox_item_types.currentTextChanged.connect(
            self.refresh_category)
        self.comboBox_item_category.currentTextChanged.connect(
            self.refresh_items)
        self.comboBox_new_item_type.currentTextChanged.connect(
            self.refresh_category_in_new_item_form)
        self.comboBox_items.currentTextChanged.connect(
            self.get_selected_item_details)
        self.btn_save_new_item.clicked.connect(self.save_new_item)
        self.btn_save_modification.clicked.connect(self.save_modification)

    def get_selected_tabwidget_on_main(self, index=0):
        if index == 0:
            self.get_actual_orders()
            self.get_soups()
        elif index == 1:
            self.check_status()

    def get_selected_tabwidget_on_secondary(self, index):
        if index == 0:
            self.get_soups()
        elif index == 1:
            self.get_salads()
        elif index == 2:
            self.get_roast_meat()
        elif index == 3:
            self.get_fish_mains()
        elif index == 4:
            self.get_desserts()
        elif index == 5:
            self.get_coffee_tee()
        elif index == 6:
            self.get_soft_drinks()
        elif index == 7:
            self.get_beers()
        elif index == 8:
            self.get_wein()
        elif index == 9:
            self.get_shoots()

    def get_soups(self):
        try:
            soupsID = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodCategory',
                column_names=['FoodCategoryID'],
                where_condition={'FoodCategoryName': 'Levesek'})
            print(soupsID[0][0])
            rows = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodItem',
                where_condition={'FoodCategory': f"{soupsID[0][0]}"})
            pass
            for index_i, row in enumerate(rows):
                food_item = FoodItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                food_item.food_category_id = 'Levesek'
                if food_item not in self.soup_list:
                    self.soup_list.append(food_item)
                    self.table_soup_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_soup_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
            self.table_soup_list.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_salads(self):
        try:
            saladsID = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodCategory',
                column_names=['FoodCategoryID'],
                where_condition={'FoodCategoryName': 'Saláták'})
            print(saladsID[0][0])
            rows = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodItem',
                where_condition={'FoodCategory': f"{saladsID[0][0]}"})
            pass
            for index_i, row in enumerate(rows):
                food_item = FoodItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                food_item.food_category_id = 'Saláták'
                if food_item not in self.salad_list:
                    self.salad_list.append(food_item)
                    self.table_salad_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_salad_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
            self.table_salad_list.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_roast_meat(self):
        try:
            roast_meatID = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodCategory',
                column_names=['FoodCategoryID'],
                where_condition={'FoodCategoryName': 'Sültek'})
            print(roast_meatID[0][0])
            rows = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodItem',
                where_condition={'FoodCategory': f"{roast_meatID[0][0]}"})
            pass
            for index_i, row in enumerate(rows):
                food_item = FoodItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                food_item.food_category_id = 'Sültek'
                if food_item not in self.meat_list:
                    self.meat_list.append(food_item)
                    self.table_meat_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_meat_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
            self.table_meat_list.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_fish_mains(self):
        try:
            fish_mainID = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodCategory',
                column_names=['FoodCategoryID'],
                where_condition={'FoodCategoryName': 'Halételek'})
            print(fish_mainID[0][0])
            rows = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodItem',
                where_condition={'FoodCategory': f"{fish_mainID[0][0]}"})
            pass
            for index_i, row in enumerate(rows):
                food_item = FoodItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                food_item.food_category_id = 'Halételek'
                if food_item not in self.fishfood_list:
                    self.fishfood_list.append(food_item)
                    self.table_fishfood_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_fishfood_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
            self.table_fishfood_list.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_desserts(self):
        try:
            dessertID = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodCategory',
                column_names=['FoodCategoryID'],
                where_condition={'FoodCategoryName': 'Desszertek'})
            print(dessertID[0][0])
            rows = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodItem',
                where_condition={'FoodCategory': f"{dessertID[0][0]}"})
            pass
            for index_i, row in enumerate(rows):
                food_item = FoodItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                food_item.food_category_id = 'Desszertek'
                if food_item not in self.dessert_list:
                    self.dessert_list.append(food_item)
                    self.table_dessert_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_dessert_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
            self.table_dessert_list.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_coffee_tee(self):
        try:
            coffee_teeID = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkCategory',
                column_names=['DrinkCategoryID'],
                where_condition={'DrinkCategoryName': 'Kávé/Tea'})
            print(coffee_teeID[0][0])
            rows = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkItem',
                where_condition={'DrinkCategory': f"{coffee_teeID[0][0]}"})
            pass
            for index_i, row in enumerate(rows):
                drink_item = DrinkItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                drink_item.drink_category_id = 'Kávé/Tea'
                if drink_item not in self.coffee_tee_list:
                    self.coffee_tee_list.append(drink_item)
                    self.table_coffee_tee_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_coffee_tee_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
            self.table_coffee_tee_list.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_soft_drinks(self):
        try:
            soft_drinkID = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkCategory',
                column_names=['DrinkCategoryID'],
                where_condition={'DrinkCategoryName': 'Üditők'})
            print(soft_drinkID[0][0])
            rows = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkItem',
                where_condition={'DrinkCategory': f"{soft_drinkID[0][0]}"})
            pass
            for index_i, row in enumerate(rows):
                drink_item = DrinkItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                drink_item.drink_category_id = 'Kávé/Tea'
                if drink_item not in self.soft_drinks_list:
                    self.soft_drinks_list.append(drink_item)
                    self.table_soft_drinks_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_soft_drinks_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
            self.table_soft_drinks_list.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_beers(self):
        try:
            beerID = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkCategory',
                column_names=['DrinkCategoryID'],
                where_condition={'DrinkCategoryName': 'Sörök'})
            print(beerID[0][0])
            rows = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkItem',
                where_condition={'DrinkCategory': f"{beerID[0][0]}"})
            pass
            for index_i, row in enumerate(rows):
                drink_item = DrinkItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                drink_item.drink_category_id = 'Sörök'
                if drink_item not in self.beer_list:
                    self.beer_list.append(drink_item)
                    self.table_beer_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_beer_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
            self.table_beer_list.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_wein(self):
        try:
            weinID = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkCategory',
                column_names=['DrinkCategoryID'],
                where_condition={'DrinkCategoryName': 'Borok'})
            print(weinID[0][0])
            rows = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkItem',
                where_condition={'DrinkCategory': f"{weinID[0][0]}"})
            pass
            for index_i, row in enumerate(rows):
                drink_item = DrinkItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                drink_item.drink_category_id = 'Borok'
                if drink_item not in self.wein_list:
                    self.wein_list.append(drink_item)
                    self.table_wein_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_wein_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
            self.table_wein_list.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_shoots(self):
        try:
            shootID = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkCategory',
                column_names=['DrinkCategoryID'],
                where_condition={'DrinkCategoryName': 'Tömények'})
            print(shootID[0][0])
            rows = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkItem',
                where_condition={'DrinkCategory': f"{shootID[0][0]}"})
            pass
            for index_i, row in enumerate(rows):
                drink_item = DrinkItem(
                    *[str(inf) if type(inf) == int else inf for inf in row])
                drink_item.drink_category_id = 'Tömények'
                if drink_item not in self.shoot_list:
                    self.shoot_list.append(drink_item)
                    self.table_shoot_list.insertRow(index_i)
                    for index_j, data in enumerate(row):
                        if data == None:
                            data = ''
                        self.table_shoot_list.setItem(
                            index_i, index_j, QTableWidgetItem(str(data)))
            self.table_shoot_list.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)
        self.table_shoot_list.resizeColumnsToContents()

    def update_timer_label(self):
        self.label_actual_time.setText(
            datetime.strftime(datetime.now(), "%Y.%m.%d %H:%M:%S"))

    def get_actual_orders(self):
        try:
            rows = self.sql.execute_command(Operation.SELECT,
                                            main_table_name='RestaurantOrder')
            del self.restaurant_order_list[:]
            self.clear_orders_table()
            for index_i, row in enumerate(rows):
                restaurant_order = RestaurantOrder(*[inf for inf in row])
                self.restaurant_order_list.append(restaurant_order)
                self.table_orders.insertRow(index_i)
                self.table_orders.setItem(
                    index_i, 0,
                    QTableWidgetItem(str(
                        restaurant_order.restaurant_order_id)))
                self.table_orders.setItem(
                    index_i, 1, QTableWidgetItem(restaurant_order.start_time))
                self.table_orders.setItem(
                    index_i, 2, QTableWidgetItem(restaurant_order.end_time))
                self.table_orders.setItem(
                    index_i, 3, QTableWidgetItem(str(restaurant_order.price)))
                if restaurant_order.paid == 0:
                    if restaurant_order.making == 1 and restaurant_order.served == 0:
                        self.table_orders.setItem(index_i, 4,
                                                  QTableWidgetItem('Készül'))
                    if restaurant_order.making == 0 and restaurant_order.served == 1:
                        self.table_orders.setItem(
                            index_i, 4, QTableWidgetItem('Felszolgálva'))
                    self.table_orders.setItem(
                        index_i, 5, QTableWidgetItem('Nincs fizetve'))
                else:
                    self.table_orders.setItem(index_i, 4,
                                              QTableWidgetItem('Végzett'))
                    self.table_orders.setItem(index_i, 5,
                                              QTableWidgetItem('Fizetve'))
            self.table_orders.resizeColumnsToContents()
        except Exception as e:
            self.message_box.window_execution(
                f'Hiba a tábla feltöltésénél: \n{e}', MessageBoxType.ERROR)

    def get_selected_order_details(self, row=None, column=None):
        self.clear_item_table_list()
        if not row:
            row = 0
        if self.table_orders.item(row, 0):
            self.selected_order_id = self.table_orders.item(row, 0).text()
            drink_tuple_list = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='RestaurantDrinkOrderItem',
                where_condition={
                    'RestaurantOrderID':
                    str(self.table_orders.item(row, 0).text())
                })
            drink_itemID_count_pairs = [
                tuple(y for y in x[2:]) for x in drink_tuple_list
            ]
            food_tuple_list = self.sql.execute_command(
                Operation.SELECT,
                main_table_name='RestaurantFoodOrderItem',
                where_condition={
                    'RestaurantOrderID':
                    str(self.table_orders.item(row, 0).text())
                })
            food_itemID_count_pairs = [
                tuple(y for y in x[2:]) for x in food_tuple_list
            ]
            self.label_order_id.setText(self.selected_order_id)
            self.label_order_status.setText(
                self.table_orders.item(row, 4).text())
            self.label_result.setText(self.table_orders.item(row, 3).text())
            self.label_order_time.setText(
                self.table_orders.item(row, 1).text())
            self.check_status()

            for index, tuple_data in enumerate(drink_itemID_count_pairs):
                self.table_order_details.insertRow(index)
                drink_obj = DrinkItem(*list(
                    self.sql.execute_command(
                        Operation.SELECT,
                        main_table_name='DrinkItem',
                        where_condition={'DrinkItemID': str(tuple_data[0])})
                    [0]))
                self.table_order_details.setItem(
                    index, 0, QTableWidgetItem(str(tuple_data[1])))
                self.table_order_details.setItem(
                    index, 1, QTableWidgetItem(drink_obj.drink_item_name))
                self.table_order_details.setItem(
                    index, 2,
                    QTableWidgetItem(str(drink_obj.drink_price *
                                         tuple_data[1])))

            for index, tuple_data in enumerate(food_itemID_count_pairs):
                shifted_index = index + len(drink_itemID_count_pairs)
                self.table_order_details.insertRow(shifted_index)
                food_obj = FoodItem(*list(
                    self.sql.execute_command(
                        Operation.SELECT,
                        main_table_name='FoodItem',
                        where_condition={'FoodItemID': str(tuple_data[0])})
                    [0]))
                self.table_order_details.setItem(
                    shifted_index, 0, QTableWidgetItem(str(tuple_data[1])))
                self.table_order_details.setItem(
                    shifted_index, 1,
                    QTableWidgetItem(food_obj.food_item_name))
                self.table_order_details.setItem(
                    shifted_index, 2,
                    QTableWidgetItem(str(food_obj.food_price * tuple_data[1])))

    def clear_item_table_list(self):
        while (self.table_order_details.rowCount() > 0):
            {self.table_order_details.removeRow(0)}

    def clear_orders_table(self):
        while (self.table_orders.rowCount() > 0):
            {self.table_orders.removeRow(0)}

    def delete_actual_order(self):
        self.sql.execute_command(Operation.DELETE,
                                 main_table_name='RestaurantOrder',
                                 set_id=self.selected_order_id)
        self.sql.execute_command(Operation.DELETE,
                                 main_table_name='RestaurantDrinkOrderItem',
                                 set_id=self.selected_order_id)
        self.sql.execute_command(Operation.DELETE,
                                 main_table_name='RestaurantFoodOrderItem',
                                 set_id=self.selected_order_id)
        self.clear_item_table_list()
        self.label_result.setText('-')
        self.label_order_time.setText('-')
        self.label_order_status.setText('-')
        self.label_order_id.setText('-')
        selected_index = None
        for index, order in enumerate(self.restaurant_order_list):
            if order.restaurant_order_id == int(self.selected_order_id):
                selected_index = index
        self.restaurant_order_list.pop(selected_index)
        self.table_orders.removeRow(selected_index)
        self.get_actual_orders()
        self.check_status()

    def set_paid(self):
        self.sql.execute_command(
            Operation.UPDATE,
            main_table_name='RestaurantOrder',
            set_id=self.selected_order_id,
            update_value_dict={
                'Making': '0',
                'Served': '0',
                'Paid': '1',
                'EndTime':
                str(datetime.today()).split('.')[0].replace('-', '.')
            })
        self.label_order_status.setText('Végzett')
        self.get_actual_orders()
        self.check_status()

    def check_status(self):
        if self.label_order_status.text(
        ) == 'Végzett' or self.label_order_status.text() == '-':
            self.btn_paid.setEnabled(False)
        else:
            self.btn_paid.setEnabled(True)

    def refresh_category(self):
        if self.comboBox_item_types.currentText() == 'Ételek':
            self.comboBox_item_category.clear()
            self.comboBox_item_category.addItems(self.get_food_categories())
            self.comboBox_selected_item_category.addItems(
                self.get_food_categories())
        elif self.comboBox_item_types.currentText() == 'Italok':
            self.comboBox_item_category.clear()
            self.comboBox_item_category.addItems(self.get_drink_categories())
            self.comboBox_selected_item_category.addItems(
                self.get_drink_categories())

    def refresh_items(self):
        if self.comboBox_item_types.currentText() == 'Ételek':
            self.comboBox_items.clear()
            if self.comboBox_item_category:
                self.comboBox_items.addItems(
                    self.get_fooditems_by_category_id(
                        self.comboBox_item_category.currentText()))
        elif self.comboBox_item_types.currentText() == 'Italok':
            self.comboBox_items.clear()
            if self.comboBox_item_category:
                self.comboBox_items.addItems(
                    self.get_drinkitems_by_category_id(
                        self.comboBox_item_category.currentText()))

    def get_selected_item_details(self):
        if self.comboBox_item_types.currentText() == 'Ételek':
            if self.comboBox_items:
                datas = self.sql.execute_command(
                    Operation.SELECT,
                    main_table_name='FoodItem',
                    where_condition={
                        'FoodName': self.comboBox_items.currentText()
                    })[0]
                food_item = FoodItem(*datas)
                self.lineEdit_item_name.setText(food_item.food_item_name)
                self.lineEdit_description.setText(food_item.food_description)
                self.lineEdit_item_unitprice.setText(str(food_item.food_price))
                self.lineEdit_item_discount.setText(
                    str(food_item.food_discount))
                self.selected_item = food_item
        if self.comboBox_item_types.currentText() == 'Italok':
            if self.comboBox_items:
                datas = self.sql.execute_command(
                    Operation.SELECT,
                    main_table_name='DrinkItem',
                    where_condition={
                        'DrinkItemName': self.comboBox_items.currentText()
                    })[0]
                drink_item = DrinkItem(*datas)
                self.lineEdit_item_name.setText(drink_item.drink_item_name)
                self.lineEdit_description.setText(drink_item.drink_description)
                self.lineEdit_item_unitprice.setText(
                    str(drink_item.drink_price))
                self.lineEdit_item_discount.setText(
                    str(drink_item.drink_discount))
                self.selected_item = drink_item

    def save_modification(self):
        if self.item_details_changed:
            selected_item: Union[DrinkItem, FoodItem] = self.selected_item
            if type(selected_item) is FoodItem:
                self.sql.execute_command(
                    Operation.UPDATE,
                    main_table_name='FoodItem',
                    update_value_dict=self.item_details_changed(),
                    set_id=selected_item.food_item_id)
            elif type(selected_item) is DrinkItem:
                self.sql.execute_command(
                    Operation.UPDATE,
                    main_table_name='DrinkItem',
                    update_value_dict=self.item_details_changed(),
                    set_id=selected_item.drink_item_id)
            self.message_box.window_execution('Módosítás sikeres volt!',
                                              MessageBoxType.REGULAR_INFO)
            self.get_selected_item_details()
        else:
            self.message_box.window_execution('Nem történt változtatás!',
                                              MessageBoxType.ERROR)

    def item_details_changed(self) -> Union[bool, dict]:
        item: Union[DrinkItem, FoodItem] = self.selected_item
        changes_dict = {}
        if type(item) is DrinkItem:
            if item.drink_item_name != self.lineEdit_item_name.text():
                changes_dict['DrinkItemName'] = self.lineEdit_item_name.text()
            if item.drink_description != self.lineEdit_description.text():
                changes_dict['Description'] = self.lineEdit_description.text()
            if str(item.drink_price) != self.lineEdit_item_unitprice.text():
                changes_dict['UnitPrice'] = self.lineEdit_item_unitprice.text()
            if str(item.drink_discount) != self.lineEdit_item_discount.text():
                changes_dict['Discount'] = self.lineEdit_item_discount.text()
            if self.comboBox_item_category.currentText(
            ) != self.comboBox_selected_item_category.currentText():
                changes_dict[
                    'DrinkCategory'] = self.comboBox_selected_item_category.currentText(
                    )
            return changes_dict
        elif type(item) is FoodItem:
            if item.food_item_name != self.lineEdit_item_name.text():
                changes_dict['FoodName'] = self.lineEdit_item_name.text()
            if item.food_description != self.lineEdit_description.text():
                changes_dict['Description'] = self.lineEdit_description.text()
            if str(item.food_price) != self.lineEdit_item_unitprice.text():
                changes_dict['UnitPrice'] = self.lineEdit_item_unitprice.text()
            if str(item.food_discount) != self.lineEdit_item_discount.text():
                changes_dict['Discount'] = self.lineEdit_item_discount.text()
            if self.comboBox_item_category.currentText(
            ) != self.comboBox_selected_item_category.currentText():
                changes_dict[
                    'FoodCategory'] = self.comboBox_selected_item_category.currentText(
                    )
            return changes_dict
        else:
            return False

    def get_fooditems_by_category_id(self, category_name) -> List[str]:
        food_list = None
        category_id = [
            id[0] for id in self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodCategory',
                column_names=['FoodCategoryID'],
                where_condition={'FoodCategoryName': category_name})
        ][0]
        food_list = [
            name[0] for name in self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodItem',
                column_names=['FoodName'],
                where_condition={'FoodCategory': category_id})
        ]
        return food_list

    def get_drinkitems_by_category_id(self, category_name) -> List[str]:
        drink_list = None
        category_id = [
            id[0] for id in self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkCategory',
                column_names=['DrinkCategoryID'],
                where_condition={'DrinkCategoryName': category_name})
        ][0]
        drink_list = [
            name[0] for name in self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkItem',
                column_names=['DrinkItemName'],
                where_condition={'DrinkCategory': category_id})
        ]
        return drink_list

    def get_drink_categories(self) -> List[str]:
        drinks_categories = [
            name[0] for name in self.sql.execute_command(
                Operation.SELECT,
                main_table_name='DrinkCategory',
                column_names=['DrinkCategoryName'])
        ]
        return drinks_categories

    def get_food_categories(self):
        food_categories = [
            name[0] for name in self.sql.execute_command(
                Operation.SELECT,
                main_table_name='FoodCategory',
                column_names=['FoodCategoryName'])
        ]
        return food_categories

    def refresh_category_in_new_item_form(self):
        if self.comboBox_item_types.currentText() == 'Ételek':
            self.comboBox_new_item_category.clear()
            self.comboBox_new_item_category.addItems(
                self.get_food_categories())
        elif self.comboBox_item_types.currentText() == 'Italok':
            self.comboBox_new_item_category.clear()
            self.comboBox_new_item_category.addItems(
                self.get_drink_categories())

    def get_category_id_by_name(self, table_name, cat_name):
        return [
            id[0] for id in self.sql.execute_command(
                Operation.SELECT,
                main_table_name=table_name,
                column_names=[table_name + "ID"],
                where_condition={table_name + 'Name': cat_name})
        ][0]

    def save_new_item(self):
        main_table = None
        dict_structure = {}
        if self.check_all_details():
            if self.comboBox_new_item_type.currentText() == 'Ételek':
                main_table = 'FoodItem'
            elif self.comboBox_new_item_type.currentText() == 'Italok':
                main_table = 'DrinkItem'
            if main_table:
                column_names = self.sql.execute_command(
                    Operation.SELECT_COLUMNS, main_table_name=main_table)
            dict_structure = {
                column_names[1]:
                self.lineEdit_new_item_name.text(),
                column_names[2]:
                self.lineEdit_new_item_description.text(),
                column_names[3]:
                self.lineEdit_new_item_unitprice.text(),
                column_names[4]:
                self.get_category_id_by_name(
                    "FoodCategory"
                    if self.comboBox_new_item_type.currentText() == "Ételek"
                    else "DrinkCategory",
                    self.comboBox_new_item_category.currentText()),
                column_names[5]:
                self.lineEdit_new_item_discount.text()
            }
            if main_table and dict_structure:
                self.sql.execute_command(Operation.INSERT,
                                         main_table_name=main_table,
                                         insertion_value_dict=dict_structure)
                self.set_details_empty([
                    self.lineEdit_new_item_name,
                    self.lineEdit_new_item_unitprice,
                    self.lineEdit_new_item_description,
                    self.lineEdit_new_item_discount
                ])
        else:
            self.message_box.window_execution("Nincs kitöltve az összes mező!",
                                              MessageBoxType.ERROR)

    def check_all_details(self) -> bool:
        if any(
                self.is_empty([
                    self.lineEdit_new_item_name.text(),
                    self.lineEdit_new_item_unitprice.text(),
                    self.comboBox_new_item_category.currentText(),
                    self.comboBox_new_item_type.currentText(),
                    self.lineEdit_new_item_description.text()
                ])):
            return False
        else:
            return True

    def is_empty(self, texts_list: List[str]) -> Optional[List[bool]]:
        results: List[bool] = []
        if texts_list:
            for text in texts_list:
                if text:
                    results.append(False)
                else:
                    results.append(True)
            return results

    def set_details_empty(self, item_list: List[QLineEdit]):
        for item in item_list:
            item.setText('')
Example #6
0
class MainWindow(base_login, form_login):
    def __init__(self):
        super(base_login, self).__init__()
        self.setupUi(self)
        self.config_object = Config()
        self.message_box = Messagebox()
        self.btn_server.clicked.connect(lambda: self.login_into_server(
            self.username_textbox.text(), self.password_textbox.text()))
        self.btn_client.clicked.connect(lambda: self.login_into_client(
            self.username_textbox.text(), self.password_textbox.text()))
        self.btn_new_reg.clicked.connect(lambda: self.new_user_reg(
            self.new_username_textbox.text(), self.new_password_textbox.text(),
            self.new_confirmed_passw_textbox.text()))
        self.btn_login_cancel.clicked.connect(self.close_main_window)
        self.btn_reg_cancel.clicked.connect(self.close_main_window)
        self.configuration_start()
        self.db_path = self.config_object.get_db_path()
        self.sql = SqliteController()

    def configuration_start(self):
        self.config_object.check_db_folder_exist()

    def login_into_server(self, login_user_name: str, login_passw: str):
        if self.username_textbox.text() != '' or self.password_textbox.text(
        ) != '':
            if len(
                    self.sql.execute_command(Operation.SELECT, 'User',
                                             [{
                                                 'UserName': login_user_name,
                                                 'Password': login_passw,
                                                 'UserID': '1'
                                             }])) > 0:
                print('Server login done!')
                self.main = ServerWindow()
                self.main.show()
                self.close()
            else:
                self.message_box.window_execution(
                    'Hibás jelszó vagy felhasználónév!', MessageBoxType.ERROR)
        else:
            self.message_box.window_execution(
                'Minden mező kitöltése kötelező!', MessageBoxType.ERROR)

    def login_into_client(self, login_user_name: str, login_passw: str):
        if self.username_textbox.text() != '' or self.password_textbox.text(
        ) != '':
            if len(
                    self.sql.execute_command(Operation.SELECT, 'User',
                                             [{
                                                 'UserName': login_user_name,
                                                 'Password': login_passw
                                             }])) > 0:
                print('Client login done!')
                self.main = MenuWindow()
                self.main.show()
                self.close()
            else:
                self.message_box.window_execution(
                    'Hibás jelszó vagy felhasználónév!', MessageBoxType.ERROR)
        else:
            self.message_box.window_execution(
                'Minden mező kitöltése kötelező!', MessageBoxType.ERROR)

    def new_user_reg(self, login_user_name: str, login_passw: str,
                     confirm_passw: str):
        if self.new_username_textbox.text(
        ) != '' or self.new_confirmed_passw_textbox.text(
        ) != '' or self.new_password_textbox.text() != '':
            if login_passw != confirm_passw:
                self.message_box.window_execution(
                    'A megadott jelszavak nem egyeznek meg!',
                    MessageBoxType.REGULAR_INFO)
            elif len((self.sql.execute_command(Operation.SELECT, 'User',
                                               [{
                                                   'UserName': login_user_name
                                               }]))) > 0:
                self.message_box.window_execution('Már létező felhasználónév!',
                                                  MessageBoxType.REGULAR_INFO)
                self.new_username_textbox: QLineEdit()
                self.new_username_textbox.setText('')
            else:
                try:
                    self.sql.execute_command(Operation.INSERT, 'User',
                                             [{
                                                 'UserName': login_user_name,
                                                 'Password': login_passw
                                             }])
                    self.message_box.window_execution(
                        'Sikeres regisztráció!', MessageBoxType.REGULAR_INFO)
                except Exception as e:
                    self.message_box.window_execution(f'Hiba: {e}',
                                                      MessageBoxType.ERROR)
        else:
            self.message_box.window_execution(
                'Összes mező kitöltése kötelező!', MessageBoxType.ERROR)
        # query = f'{login_user_name, login_passw, confirm_passw}'
        # self.connect_to_sql(query)
        # print(query)

    def close_main_window(self):
        sys.exit()
    def setupUi(self, login_reg_mainwindow):
        login_reg_mainwindow.setObjectName("login_reg_mainwindow")
        login_reg_mainwindow.resize(417, 224)
        self.centralwidget = QtWidgets.QWidget(login_reg_mainwindow)
        self.centralwidget.setObjectName("centralwidget")
        self.login_reg_tab_widget = QtWidgets.QTabWidget(self.centralwidget)
        self.login_reg_tab_widget.setGeometry(QtCore.QRect(10, 0, 401, 221))
        self.login_reg_tab_widget.setTabPosition(QtWidgets.QTabWidget.North)
        self.login_reg_tab_widget.setTabShape(QtWidgets.QTabWidget.Rounded)
        self.login_reg_tab_widget.setObjectName("login_reg_tab_widget")
        self.tab_login = QtWidgets.QWidget()
        self.tab_login.setObjectName("tab_login")
        self.login_groupbox = QtWidgets.QGroupBox(self.tab_login)
        self.login_groupbox.setGeometry(QtCore.QRect(10, 10, 381, 161))
        self.login_groupbox.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.login_groupbox.setObjectName("login_groupbox")
        self.verticalLayoutWidget = QtWidgets.QWidget(self.login_groupbox)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 20, 361, 131))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.username_label = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.username_label.setObjectName("username_label")
        self.horizontalLayout_4.addWidget(self.username_label)
        self.username_textbox = QtWidgets.QLineEdit(self.verticalLayoutWidget)
        self.username_textbox.setObjectName("username_textbox")
        self.horizontalLayout_4.addWidget(self.username_textbox)
        self.verticalLayout.addLayout(self.horizontalLayout_4)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.password_label = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.password_label.setObjectName("password_label")
        self.horizontalLayout_3.addWidget(self.password_label)
        self.password_textbox = QtWidgets.QLineEdit(self.verticalLayoutWidget)
        self.password_textbox.setEchoMode(QtWidgets.QLineEdit.Password)
        self.password_textbox.setObjectName("password_textbox")
        self.horizontalLayout_3.addWidget(self.password_textbox)
        self.verticalLayout.addLayout(self.horizontalLayout_3)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.btn_server = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.btn_server.setObjectName("btn_server")
        self.horizontalLayout.addWidget(self.btn_server)
        self.btn_client = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.btn_client.setObjectName("btn_client")
        self.horizontalLayout.addWidget(self.btn_client)
        self.btn_login_cancel = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.btn_login_cancel.setObjectName("btn_login_cancel")
        self.horizontalLayout.addWidget(self.btn_login_cancel)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.login_reg_tab_widget.addTab(self.tab_login, "")
        self.tab_reg = QtWidgets.QWidget()
        self.tab_reg.setObjectName("tab_reg")
        self.reg_groupbox = QtWidgets.QGroupBox(self.tab_reg)
        self.reg_groupbox.setGeometry(QtCore.QRect(10, 10, 381, 171))
        self.reg_groupbox.setObjectName("reg_groupbox")
        self.verticalLayoutWidget_2 = QtWidgets.QWidget(self.reg_groupbox)
        self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(10, 20, 371, 141))
        self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
        self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.new_username_label = QtWidgets.QLabel(self.verticalLayoutWidget_2)
        self.new_username_label.setObjectName("new_username_label")
        self.horizontalLayout_6.addWidget(self.new_username_label)
        self.new_username_textbox = QtWidgets.QLineEdit(self.verticalLayoutWidget_2)
        self.new_username_textbox.setObjectName("new_username_textbox")
        self.horizontalLayout_6.addWidget(self.new_username_textbox)
        self.verticalLayout_2.addLayout(self.horizontalLayout_6)
        self.horizontalLayout_9 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_9.setObjectName("horizontalLayout_9")
        self.new_password_label = QtWidgets.QLabel(self.verticalLayoutWidget_2)
        self.new_password_label.setObjectName("new_password_label")
        self.horizontalLayout_9.addWidget(self.new_password_label)
        self.new_password_textbox = QtWidgets.QLineEdit(self.verticalLayoutWidget_2)
        self.new_password_textbox.setObjectName("new_password_textbox")
        self.horizontalLayout_9.addWidget(self.new_password_textbox)
        self.verticalLayout_2.addLayout(self.horizontalLayout_9)
        self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_7.setObjectName("horizontalLayout_7")
        self.new_confirmed_passw_label = QtWidgets.QLabel(self.verticalLayoutWidget_2)
        self.new_confirmed_passw_label.setObjectName("new_confirmed_passw_label")
        self.horizontalLayout_7.addWidget(self.new_confirmed_passw_label)
        self.new_confirmed_passw_textbox = QtWidgets.QLineEdit(self.verticalLayoutWidget_2)
        self.new_confirmed_passw_textbox.setObjectName("new_confirmed_passw_textbox")
        self.horizontalLayout_7.addWidget(self.new_confirmed_passw_textbox)
        self.verticalLayout_2.addLayout(self.horizontalLayout_7)
        self.horizontalLayout_8 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_8.setObjectName("horizontalLayout_8")
        self.btn_new_reg = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
        self.btn_new_reg.setObjectName("btn_new_reg")
        self.horizontalLayout_8.addWidget(self.btn_new_reg)
        self.btn_reg_cancel = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
        self.btn_reg_cancel.setObjectName("btn_reg_cancel")
        self.horizontalLayout_8.addWidget(self.btn_reg_cancel)
        self.verticalLayout_2.addLayout(self.horizontalLayout_8)
        self.login_reg_tab_widget.addTab(self.tab_reg, "")
        login_reg_mainwindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(login_reg_mainwindow)
        self.statusbar.setObjectName("statusbar")
        login_reg_mainwindow.setStatusBar(self.statusbar)

        """My code"""
        self.config_object = Config()
        self.client_dialog = MenuWindow()
        self.server_dialog = ServerWindow()
        self.message_box = Messagebox()
        self.btn_server.clicked.connect(
            lambda: self.login_into_server(self.username_textbox.text(), self.password_textbox.text()))
        self.btn_client.clicked.connect(
            lambda: self.login_into_client(self.username_textbox.text(), self.password_textbox.text()))
        self.btn_new_reg.clicked.connect(
            lambda: self.new_user_reg(self.new_username_textbox.text(), self.new_password_textbox.text(),
                                      self.new_confirmed_passw_textbox.text()))
        self.btn_login_cancel.clicked.connect(self.close_main_window)
        self.btn_reg_cancel.clicked.connect(self.close_main_window)
        self.configuration_start()
        self.db_path = self.config_object.get_db_path()
        self.sql = SqliteController()
        self.btn_client.clicked.connect(
            lambda: self.login_into_client(self.username_textbox.text(), self.password_textbox.text()))
        self.btn_server.clicked.connect(
            lambda: self.login_into_server(self.username_textbox.text(), self.password_textbox.text()))
        self.btn_new_reg.clicked.connect(
            lambda: self.new_user_reg(self.new_username_textbox.text(), self.new_password_textbox.text(),
                                      self.new_confirmed_passw_textbox.text()))

        self.retranslateUi(login_reg_mainwindow)
        self.login_reg_tab_widget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(login_reg_mainwindow)
class Ui_login_reg_mainwindow(object):
    def setupUi(self, login_reg_mainwindow):
        login_reg_mainwindow.setObjectName("login_reg_mainwindow")
        login_reg_mainwindow.resize(417, 224)
        self.centralwidget = QtWidgets.QWidget(login_reg_mainwindow)
        self.centralwidget.setObjectName("centralwidget")
        self.login_reg_tab_widget = QtWidgets.QTabWidget(self.centralwidget)
        self.login_reg_tab_widget.setGeometry(QtCore.QRect(10, 0, 401, 221))
        self.login_reg_tab_widget.setTabPosition(QtWidgets.QTabWidget.North)
        self.login_reg_tab_widget.setTabShape(QtWidgets.QTabWidget.Rounded)
        self.login_reg_tab_widget.setObjectName("login_reg_tab_widget")
        self.tab_login = QtWidgets.QWidget()
        self.tab_login.setObjectName("tab_login")
        self.login_groupbox = QtWidgets.QGroupBox(self.tab_login)
        self.login_groupbox.setGeometry(QtCore.QRect(10, 10, 381, 161))
        self.login_groupbox.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.login_groupbox.setObjectName("login_groupbox")
        self.verticalLayoutWidget = QtWidgets.QWidget(self.login_groupbox)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 20, 361, 131))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.username_label = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.username_label.setObjectName("username_label")
        self.horizontalLayout_4.addWidget(self.username_label)
        self.username_textbox = QtWidgets.QLineEdit(self.verticalLayoutWidget)
        self.username_textbox.setObjectName("username_textbox")
        self.horizontalLayout_4.addWidget(self.username_textbox)
        self.verticalLayout.addLayout(self.horizontalLayout_4)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.password_label = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.password_label.setObjectName("password_label")
        self.horizontalLayout_3.addWidget(self.password_label)
        self.password_textbox = QtWidgets.QLineEdit(self.verticalLayoutWidget)
        self.password_textbox.setEchoMode(QtWidgets.QLineEdit.Password)
        self.password_textbox.setObjectName("password_textbox")
        self.horizontalLayout_3.addWidget(self.password_textbox)
        self.verticalLayout.addLayout(self.horizontalLayout_3)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.btn_server = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.btn_server.setObjectName("btn_server")
        self.horizontalLayout.addWidget(self.btn_server)
        self.btn_client = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.btn_client.setObjectName("btn_client")
        self.horizontalLayout.addWidget(self.btn_client)
        self.btn_login_cancel = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.btn_login_cancel.setObjectName("btn_login_cancel")
        self.horizontalLayout.addWidget(self.btn_login_cancel)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.login_reg_tab_widget.addTab(self.tab_login, "")
        self.tab_reg = QtWidgets.QWidget()
        self.tab_reg.setObjectName("tab_reg")
        self.reg_groupbox = QtWidgets.QGroupBox(self.tab_reg)
        self.reg_groupbox.setGeometry(QtCore.QRect(10, 10, 381, 171))
        self.reg_groupbox.setObjectName("reg_groupbox")
        self.verticalLayoutWidget_2 = QtWidgets.QWidget(self.reg_groupbox)
        self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(10, 20, 371, 141))
        self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
        self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.new_username_label = QtWidgets.QLabel(self.verticalLayoutWidget_2)
        self.new_username_label.setObjectName("new_username_label")
        self.horizontalLayout_6.addWidget(self.new_username_label)
        self.new_username_textbox = QtWidgets.QLineEdit(self.verticalLayoutWidget_2)
        self.new_username_textbox.setObjectName("new_username_textbox")
        self.horizontalLayout_6.addWidget(self.new_username_textbox)
        self.verticalLayout_2.addLayout(self.horizontalLayout_6)
        self.horizontalLayout_9 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_9.setObjectName("horizontalLayout_9")
        self.new_password_label = QtWidgets.QLabel(self.verticalLayoutWidget_2)
        self.new_password_label.setObjectName("new_password_label")
        self.horizontalLayout_9.addWidget(self.new_password_label)
        self.new_password_textbox = QtWidgets.QLineEdit(self.verticalLayoutWidget_2)
        self.new_password_textbox.setObjectName("new_password_textbox")
        self.horizontalLayout_9.addWidget(self.new_password_textbox)
        self.verticalLayout_2.addLayout(self.horizontalLayout_9)
        self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_7.setObjectName("horizontalLayout_7")
        self.new_confirmed_passw_label = QtWidgets.QLabel(self.verticalLayoutWidget_2)
        self.new_confirmed_passw_label.setObjectName("new_confirmed_passw_label")
        self.horizontalLayout_7.addWidget(self.new_confirmed_passw_label)
        self.new_confirmed_passw_textbox = QtWidgets.QLineEdit(self.verticalLayoutWidget_2)
        self.new_confirmed_passw_textbox.setObjectName("new_confirmed_passw_textbox")
        self.horizontalLayout_7.addWidget(self.new_confirmed_passw_textbox)
        self.verticalLayout_2.addLayout(self.horizontalLayout_7)
        self.horizontalLayout_8 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_8.setObjectName("horizontalLayout_8")
        self.btn_new_reg = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
        self.btn_new_reg.setObjectName("btn_new_reg")
        self.horizontalLayout_8.addWidget(self.btn_new_reg)
        self.btn_reg_cancel = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
        self.btn_reg_cancel.setObjectName("btn_reg_cancel")
        self.horizontalLayout_8.addWidget(self.btn_reg_cancel)
        self.verticalLayout_2.addLayout(self.horizontalLayout_8)
        self.login_reg_tab_widget.addTab(self.tab_reg, "")
        login_reg_mainwindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(login_reg_mainwindow)
        self.statusbar.setObjectName("statusbar")
        login_reg_mainwindow.setStatusBar(self.statusbar)

        """My code"""
        self.config_object = Config()
        self.client_dialog = MenuWindow()
        self.server_dialog = ServerWindow()
        self.message_box = Messagebox()
        self.btn_server.clicked.connect(
            lambda: self.login_into_server(self.username_textbox.text(), self.password_textbox.text()))
        self.btn_client.clicked.connect(
            lambda: self.login_into_client(self.username_textbox.text(), self.password_textbox.text()))
        self.btn_new_reg.clicked.connect(
            lambda: self.new_user_reg(self.new_username_textbox.text(), self.new_password_textbox.text(),
                                      self.new_confirmed_passw_textbox.text()))
        self.btn_login_cancel.clicked.connect(self.close_main_window)
        self.btn_reg_cancel.clicked.connect(self.close_main_window)
        self.configuration_start()
        self.db_path = self.config_object.get_db_path()
        self.sql = SqliteController()
        self.btn_client.clicked.connect(
            lambda: self.login_into_client(self.username_textbox.text(), self.password_textbox.text()))
        self.btn_server.clicked.connect(
            lambda: self.login_into_server(self.username_textbox.text(), self.password_textbox.text()))
        self.btn_new_reg.clicked.connect(
            lambda: self.new_user_reg(self.new_username_textbox.text(), self.new_password_textbox.text(),
                                      self.new_confirmed_passw_textbox.text()))

        self.retranslateUi(login_reg_mainwindow)
        self.login_reg_tab_widget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(login_reg_mainwindow)

    """My methods"""

    def configuration_start(self):
        self.config_object.check_db_folder_exist()

    def login_into_server(self, login_user_name: str, login_passw: str):
        if self.username_textbox.text() != '' or self.password_textbox.text() != '':
            if len(self.sql.execute_command(operation=Operation.SELECT, main_table_name='User',
                                            where_condition={'UserName': login_user_name, 'Password': login_passw,
                                                             'UserID': '1'})) > 0:
                print('Server login done!')
                self.open_server_dialog()
            else:
                self.message_box.window_execution('Hibás jelszó vagy felhasználónév!', MessageBoxType.ERROR)
        else:
            self.message_box.window_execution('Minden mező kitöltése kötelező!', MessageBoxType.ERROR)

    def login_into_client(self, login_user_name: str, login_passw: str):
        if self.username_textbox.text() != '' or self.password_textbox.text() != '':
            if len(self.sql.execute_command(Operation.SELECT, main_table_name='User', where_condition=
            {'UserName': login_user_name, 'Password': login_passw})) > 0:
                print('Client login done!')
                self.open_client_dialog()
            else:
                self.message_box.window_execution('Hibás jelszó vagy felhasználónév!', MessageBoxType.ERROR)
        else:
            self.message_box.window_execution('Minden mező kitöltése kötelező!', MessageBoxType.ERROR)

    def new_user_reg(self, login_user_name: str, login_passw: str, confirm_passw: str):
        if self.new_username_textbox.text() != '' or self.new_confirmed_passw_textbox.text() != '' or self.new_password_textbox.text() != '':
            if login_passw != confirm_passw:
                self.message_box.window_execution('A megadott jelszavak nem egyeznek meg!', MessageBoxType.REGULAR_INFO)
            elif len((self.sql.execute_command(Operation.SELECT, main_table_name='User',
                                               where_condition={'UserName': login_user_name}))) > 0:
                self.message_box.window_execution('Már létező felhasználónév!', MessageBoxType.REGULAR_INFO)
                self.new_username_textbox: QLineEdit()
                self.new_username_textbox.setText('')
            else:
                try:
                    self.sql.execute_command(Operation.INSERT, main_table_name='User', where_condition=
                    {'UserName': login_user_name, 'Password': login_passw})
                    self.message_box.window_execution('Sikeres regisztráció!',
                                                      MessageBoxType.REGULAR_INFO)
                except Exception as e:
                    self.message_box.window_execution(f'Hiba: {e}', MessageBoxType.ERROR)
        else:
            self.message_box.window_execution('Összes mező kitöltése kötelező!', MessageBoxType.ERROR)

    def close_main_window(self):
        sys.exit()

    def exit_program(self):
        sys.exit()

    def open_client_dialog(self):
        self.btn_server.setEnabled(False)
        self.btn_client.setEnabled(False)
        self.password_textbox.setReadOnly(True)
        self.username_textbox.setReadOnly(True)
        self.tab_reg.setEnabled(False)
        self.client_dialog.show()

    def open_server_dialog(self):
        self.btn_server.setEnabled(False)
        self.btn_client.setEnabled(False)
        self.password_textbox.setReadOnly(True)
        self.username_textbox.setReadOnly(True)
        self.tab_reg.setEnabled(False)
        self.server_dialog.show()

    def retranslateUi(self, login_reg_mainwindow):
        _translate = QtCore.QCoreApplication.translate
        login_reg_mainwindow.setWindowTitle(_translate("login_reg_mainwindow", "MainWindow"))
        self.login_groupbox.setTitle(_translate("login_reg_mainwindow", "Már regisztrált felhasználó számára"))
        self.username_label.setText(_translate("login_reg_mainwindow", "Felhasználónév:"))
        self.password_label.setText(_translate("login_reg_mainwindow", "Jelszó:"))
        self.btn_server.setText(_translate("login_reg_mainwindow", "Szerver"))
        self.btn_client.setText(_translate("login_reg_mainwindow", "Kliens"))
        self.btn_login_cancel.setText(_translate("login_reg_mainwindow", "Kilép"))
        self.login_reg_tab_widget.setTabText(self.login_reg_tab_widget.indexOf(self.tab_login),
                                             _translate("login_reg_mainwindow", "Bejelentkezés"))
        self.reg_groupbox.setTitle(_translate("login_reg_mainwindow", "GroupBox"))
        self.new_username_label.setText(_translate("login_reg_mainwindow", "Felhasználónév:"))
        self.new_password_label.setText(_translate("login_reg_mainwindow", "Jelszó: "))
        self.new_confirmed_passw_label.setText(_translate("login_reg_mainwindow", "Jelszó ismét: "))
        self.btn_new_reg.setText(_translate("login_reg_mainwindow", "Regisztráció"))
        self.btn_reg_cancel.setText(_translate("login_reg_mainwindow", "Kilép"))
        self.login_reg_tab_widget.setTabText(self.login_reg_tab_widget.indexOf(self.tab_reg),
                                             _translate("login_reg_mainwindow", "Regisztráció"))