예제 #1
0
    def set_current_category(self, category):
        db = Bicycle_db()

        query = "CREATE TABLE IF NOT EXISTS cur_category (id INTEGER PRIMARY KEY AUTOINCREMENT, name_category TEXT);"
        query_2 = 'insert into cur_category(name_category) values("{}")'.format(
            category)
        db.insert(query)
        db.insert(query_2)
        db.close()
예제 #2
0
 def get_current_course(self):
     db = Bicycle_db()
     query = db.insert("SELECT value FROM settings WHERE name = 'Курс'")
     db.close()
     if len((query)) != 0 :
         course = int(query[0][0])
     else:
         course = 20.3
     self.USD_value.setText(f"USD-{str(course)}")
     return course
예제 #3
0
    def additional_actions(self, Form):
        self.add_actions(Form)

        self.fill_tree()
        self.treeWidget.setHeaderHidden(True)
        self.lineEdit_3.setEnabled(False)
        self.lineEdit_5.setEnabled(False)
        self.lineEdit_6.setEnabled(False)
        if self.values:
            # when change_item
            self.lineEdit_4.setText(self.values["Продаж"])
            self.lineEdit_3.setText(self.values["Нац"])
            self.lineEdit_3.setEnabled(False)
            self.lineEdit_2.setText(self.values["Закупка"])
            self.lineEdit_6.setText(self.values["Арт"])
            self.lineEdit_5.setText(self.values["ГРН"])
            self.lineEdit.setText(self.values["Название"])
            self.spinBox.setValue(int(self.values["Кол-во."]))

            self.label_9.setText("")
            self.comboBox.hide()
            self.label_4.hide()
            self.pushButton_2.clicked.connect(self.edit_good)
            self.pushButton_2.clicked.connect(lambda: Form.close())
            # move categories
            category = self.cur_category_handler()
            item = QtWidgets.QTreeWidgetItem(category)
            self.category_title.setText(category)
            index = self.find_element_index_in_tree(category)

            if len(index) == 1:
                pass
                # self.treeWidget.model().index(index[0])
            # handle for child or not child element

        else:
            self.lineEdit_6.setEnabled(False)
            ids_for_new_good = "SELECT MAX(article)from goods"
            db = Bicycle_db()
            query = db.insert(ids_for_new_good)[0][0] 
            good_id += 1
            self.lineEdit_6.setText(str(good_id))
            self.spinBox.setValue(1)
            self.treeWidget.setCurrentItem(QtWidgets.QTreeWidgetItem("Bci"))
            category = self.cur_category_handler()
            self.category_title.setText(category)
            self.pushButton_2.clicked.connect(self.store_good)
            db.close()
예제 #4
0
    def contextMenuEvent(self, event):
        menu = QtWidgets.QMenu(self)
        add_Action = menu.addAction("добавить")
        edit_Action = menu.addAction("редактировать")
        remove_Action = menu.addAction("удалить")
        action = menu.exec_(self.mapToGlobal(event.pos()))
        if action == add_Action:
            widget = QDialog()
            ui = GoodsForm(table=self)
            ui.setupUi(widget)
            widget.exec_()
        if action == remove_Action:
            reply = QtWidgets.QMessageBox.question(
                self,
                "Удалить товар?",
                "Вы уверенны что хотите удалить?",
                QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
                QtWidgets.QMessageBox.No,
            )
            if reply == QtWidgets.QMessageBox.Yes:
                values = self.parse_row()
                if values["Кол-во."] != "0":
                    # widget = QDialog()
                    error_dialog = QtWidgets.QErrorMessage(self)
                    error_dialog.showMessage("товар с количеством удалить нельзя")
                else:
                    db = Bicycle_db()
                    db.insert(
                        "DELETE FROM goods WHERE article LIKE '%{}%'".format(
                            values["Арт"]
                        )
                    )
                    self.update_table()
                    db.close()

        if action == edit_Action:
            widget = QDialog()
            ui = GoodsForm(
                table=self,
                values=self.parse_row(),
                category_widget=self.category_widget,
            )
            ui.setupUi(widget)
            widget.exec_()
예제 #5
0
 def get_goods(self, category_name=False, display_all=None):
     db = Bicycle_db()
     if display_all or category_name == "Всі":
         goods = db.edit("Select * from goods")
         db.close()
         return self.from_sqlgoods_to_dict(goods)
     else:
         if category_name is None:
             category_name = "Всі"
         category_id = db.select(
             'SELECT id from categories  where name like "%{}%"'.format(
                 category_name
             )
         )
         goods = db.edit(
             'Select * from goods where category like "%{}%";'.format(category_id[0])
         )
         db.close()
         return self.from_sqlgoods_to_dict(goods)
    def contextMenuEvent(self, event):
        # handle right_click
        menu = QtWidgets.QMenu(self)
        add_category_Action = menu.addAction("добавить категорию")
        add_sub_category_Action = menu.addAction("добавить подкатегорию")
        edit_category_Action = menu.addAction("редактировать категорию")
        remove_category_Action = menu.addAction("удалить категорию")
        action = menu.exec_(self.mapToGlobal(event.pos()))
        db = Bicycle_db()
        if action == add_category_Action:
            text, ok = QtWidgets.QInputDialog.getText(self,
                                                      "Добавить категорию",
                                                      "Имя для категории:")
            if ok and text != "":
                rowcount = self.topLevelItemCount()
                self.addTopLevelItem(QtWidgets.QTreeWidgetItem(rowcount))
                self.topLevelItem(rowcount).setText(0, text)
                res = db.insert(
                    'INSERT INTO categories (id,name,parent_id) values((SELECT MAX(id)from categories)+1,"{}",-1);'
                    .format(text))
                print(res)
                db.close()
        if action == remove_category_Action:
            item = self.currentItem()
            for SelectedItem in self.selectedItems():
                if SelectedItem.text(0) == item.text(0):
                    # check category is not null
                    qm = QtWidgets.QMessageBox()
                    ret = qm.question(self, "", "Удалить категорию?",
                                      qm.Yes | qm.No)
                    if ret == qm.Yes:
                        SelectedItem.removeChild(item)
                        text = item.text(0)
                        query = 'DELETE FROM categories WHERE name LIKE "%{}%";'.format(
                            text)
                        db.insert(query)
                        db.close()
        if action == edit_category_Action:
            if self.selectedItems():
                old_name = self.currentItem().text(0)
                item = self.selectedItems()[0]
                text, ok = QtWidgets.QInputDialog.getText(
                    self,
                    "Редактировать",
                    "редактировать:",
                    QtWidgets.QLineEdit.Normal,
                    item.text(0),
                )
                if ok and text != "":
                    item.setText(0, text)
                    res = db.insert(
                        'UPDATE categories set name = "{}" where name like "%{}%";'
                        .format(text, old_name))

        if action == add_sub_category_Action:
            text, ok = QtWidgets.QInputDialog.getText(self,
                                                      "Добавить подкатегорию",
                                                      "Имя для подкатегории:")
            if ok and text != "":
                db = Bicycle_db()
                if len(self.selectedItems()) > 0:
                    QtWidgets.QTreeWidgetItem(self.selectedItems()[0], [text])
                    parent_id = db.insert(
                        'select id from categories where name like "%{}%"'.
                        format(self.currentItem().text(0)))
                    db.insert(
                        'INSERT INTO categories (id,name,parent_id) values((SELECT MAX(id)from categories)+1,"{}",{});'
                        .format(text, parent_id[0][0]))
                else:
                    print("here")
                    QtWidgets.QTreeWidgetItem(self, [text])
                    res = db.insert(
                        'INSERT INTO categories (id,name,parent_id) values((SELECT MAX(id)from categories)+1,"{}",-1);'
                        .format(text))
예제 #7
0
 def closeEvent(self, event):
     db = Bicycle_db()
     db.insert("drop table if exists cur_category")
     db.close()
     event.accept()