예제 #1
0
    def deleteuser(self):
        if self.tableView.currentIndex().row()>-1:
            indexs = self.tableView.selectionModel().selection().indexes()  # 将所有单元格按顺序存储
            if QMessageBox.Yes == QMessageBox.question(self, "提示", "确实删除用户吗?删除后不可恢复!"):
                prio = ["一般用户", "管理员", "超级管理员"]
                ls_row_num = []
                for i in range(0, len(indexs), 8):
                    account = indexs[i].data()  # 用户名
                    if self.currentusername == account:
                        QMessageBox.about(self, "提示", "不能删除本人!")
                        continue
                    d = indexs[i+7].data()  # 用户权限
                    current_priority = self.users[self.currentusername][-1]
                    if prio.index(d) < prio.index(current_priority):
                        ls_row_num.append(indexs[i])
                        # self.model.removeRows(indexs[x].row(), 1)   # 由于这里删除一行,前面自动没有了,所以每次都从0行开始
                        self.users.pop(account)
                    else:
                        QMessageBox.about(self, "提示", "你没有操作权限!不能删除用户【"+account+"】")
                # 删除表中显示
                ls_row_num.reverse()
                for index in ls_row_num:
                    self.model.removeRow(index.row())
                writejson("data/userinfo.json", self.users)
                self.user_changed_singal.emit()

        self.tableView.setCurrentIndex(QModelIndex())  # 设置当前索引行为空
        self.pushButton.setEnabled(False)
        self.pushButton_2.setEnabled(False)
예제 #2
0
 def clearpaper(self):
     if QMessageBox.question(self, "清空试卷",
                             "确定清空题库吗?清空后不可恢复!") == QMessageBox.Yes:
         # 清空所有试卷
         self.model.removeRows(0, self.model.rowCount())
         # self.label_2.setText("默认试卷:无")
         writejson("data/shijuan_all.json", {})
         writejson("data/defaulttest.json", {})
         self.delete_testpaper.emit()
     else:
         pass
예제 #3
0
    def addusertotable(self, list_user):
        # list_user=['name', 'p', '丁莉莉', '男', '1', '22', '333', '202005161734']
        users = readjson("data/userinfo.json")
        if len(users) == 0:
            users = {}
        if list_user[0] in users:
            QMessageBox.about(self, "提示", "用户已存在!")
        else:
            users[list_user[0]] = list_user[1:] + ["一般用户"]
        writejson("data/userinfo.json", users)
        self.user_changed_singal.emit()

        self.initUi()
예제 #4
0
    def setdefault(self):
        indexs = self.tableView.selectionModel().selection().indexes()
        if len(indexs) > 0:
            # 获取当前试卷名称
            s_name = str(indexs[2].data()) + "-" + str(indexs[1].data())

            default = {}
            default[s_name] = self.shijuan[s_name]
            writejson("data/defaulttest.json", default)
            QMessageBox.about(self, "设置默认试卷", "设置成功!")

            # 设置默认后,行不选中,按钮不可用
            self.tableView.setCurrentIndex(QModelIndex())  # 设置当前不选中行
            self.pushButton_2.setEnabled(False)
예제 #5
0
    def deleterow(self):
        indexs = self.tableView.selectionModel().selection().indexes()

        if len(indexs) > 0:
            # 删除试卷,修改试卷文件
            s_name = str(indexs[2].data()) + "-" + str(indexs[1].data())
            if QMessageBox.Yes == QMessageBox.question(self, "删除",
                                                       "是否删除试卷->" + s_name):
                self.model.removeRows(indexs[0].row(),
                                      1)  # 从指定行索引开始删除指定行数,此处1行
                self.shijuan.pop(s_name)
                writejson("data/shijuan_all.json", self.shijuan)
                self.delete_testpaper.emit()

            # 删除后,设置按钮不可用
            self.tableView.setCurrentIndex(QModelIndex())  # 设置当前不选中行
            self.pushButton_2.setEnabled(False)
예제 #6
0
    def on_ok(self):
        if QMessageBox.No == QMessageBox.question(self, "提示", "是否保存更改?"):
            return

        rowcount = self.model.rowCount()
        colcount = self.model.columnCount()
        ls1 = {}
        for i in range(rowcount):
            ls = []
            for j in range(colcount):
                index = self.model.index(i, j)
                s = self.model.data(index)
                if s != "" or j == colcount - 1:
                    ls.append(s)
            ls1[str(i)] = ls
        # print(ls1)
        writejson("data/tiku.json", ls1)
        self.tk_guanli_complete.emit()
        self.close()
예제 #7
0
    def updatepriority(self):
        indexs = self.tableView.selectionModel().selection().indexes()  # 将所有单元格按顺序存储
        prio = ["一般用户", "管理员", "超级管理员"]
        current_priority = self.users[self.currentusername][-1]
        for i in range(int(len(indexs)/8)):
            d = indexs[8 * i + 7].data()
            if d in prio[:-1] and current_priority in prio[1:]:
                if prio.index(d) < prio.index(current_priority):
                    s = prio[1+prio.index(d)]
                    self.model.setData(indexs[8 * i + 7], s)
                    self.users[indexs[8 * i].data()][-1] = s
                    QMessageBox.about(self, "提示", "操作成功!")
                else:
                    QMessageBox.about(self, "提示", "你没有操作权限!")
            else:
                QMessageBox.about(self, "提示", "你没有操作权限!")
        self.tableView.setCurrentIndex(QModelIndex())
        self.pushButton.setEnabled(False)
        self.pushButton_2.setEnabled(False)

        # 存储用户权限
        writejson("data/userinfo.json", self.users)
예제 #8
0
    def on_clicked(self):
        list_num = [self.lineEdit_num_1, self.lineEdit_num_2, self.lineEdit_num_3, self.lineEdit_num_4, self.lineEdit_num_5]
        list_val = [self.lineEdit_val_1, self.lineEdit_val_2, self.lineEdit_val_3, self.lineEdit_val_4, self.lineEdit_val_5]
        l1, l2 = [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]
        for i in range(5):
            try:
                l1[i] = int(list_num[i].text())
            except:
                list_num[i].clear()
                list_num[i].setPlaceholderText("Error")
                list_num[i].setFocus()
                return
            try:
                l2[i] = int(list_val[i].text())
            except:
                list_val[i].clear()
                list_val[i].setPlaceholderText("Error")
                list_val[i].setFocus()
                return

        writejson("data/suiji_set.json", [l1, l2])
        QMessageBox.about(self, "提示", "随机设置成功!")
        self.close()