示例#1
0
    def regist_menu(self):
        user_name = self.lineEdit.text()
        user_pwd = self.lineEdit_2.text()
        user_repwd = self.lineEdit_3.text()
        if user_pwd != user_repwd:
            # 验证两次输入的密码是否相等
            #print('输入的两次密码不相等,请重新注册')
            #QApplication.setQuitOnLastWindowClosed(False)
            QMessageBox.critical(self, 'Error',
                                 'The two passwords do not match!!')
            return
        file = 'D:\\Project\\IMS\\UserInfo\\' + user_name + '.json'  # 将用户名设为json文件的文件名
        try:  # 判断用户名是否存在
            with open(file, 'r', encoding='utf-8'):
                #print('该账号已被注册,请重新注册')
                QMessageBox.critical(
                    self, 'Warning',
                    'The account has been registered and please reregistered!!'
                )

        except:
            content = {
                user_name: user_pwd,
                'student': {}
            }  # 将用户名和密码以键值对的方式写入文件
            files.basic_file_write(file, content)  # 调用文件写入函数
            #print('注册成功')
            QMessageBox.information(self, 'Information',
                                    'registered successfully!!')
            self.close()  # close child window
            self.comboBox.addItem(user_name)  # add comboBox item
            self.clear()  # clear lineedit data
示例#2
0
    def xiugai(self, Form):
        # 判断必填项不为空
        if not self.lineEdit_3.text():
            QMessageBox.information(self, '提示', '姓名不可为空')
            return
        if not self.lineEdit_4.text():
            QMessageBox.information(self, '提示', '学号不可为空')
            return
        if not self.radioButton.isChecked(
        ) and not self.radioButton_2.isChecked():
            QMessageBox.information(self, '提示', '性别不可为空')
            return

        if not self.comboBox.currentText():
            QMessageBox.information(self, '提示', '年龄不可为空')
            return
        if not self.comboBox_2.currentText():
            QMessageBox.information(self, '提示', '专业不可为空')
            return
        # 判断是否已存在对应信息
        all_content = json.loads(files.basic_file_read(self.file))
        for key in all_content['student'].keys():
            if self.lineEdit_3.text() == key:
                QMessageBox.information(self, '提示', '已有该姓名,请重新填写')
                self.lineEdit_3.setText('')
                return
            elif self.lineEdit_4.text() == all_content['student'][key]['Sno']:
                QMessageBox.information(self, '提示', '已有该学号,请重新填写')
                self.lineEdit_4.setText('')
                return
        # 新增信息
        with open(self.file, 'r', encoding='utf-8') as addstus:
            content = json.load(addstus)
            content['student'][self.lineEdit_3.text()] = {
                'Sno':
                str(self.lineEdit_4.text()),
                'age':
                self.comboBox_2.currentText(),
                'sex':
                self.radioButton.text()
                if self.radioButton.isChecked() else self.radioButton_2.text(),
                'is':
                self.comboBox.currentText(),
                'Course':
                ''
            }
        # 转换为json格式
        with open(self.file, 'w', encoding='utf-8') as f:
            json.dump(content, f,
                      ensure_ascii=False)  # ensure_ascii=False:转换时保持中文显示
        QMessageBox.information(self, '提示',
                                '{}成功'.format('修改' if self.sel == 0 else '添加'))
        Form.close()  # 关闭当前窗口
        self.tableWidget.setRowCount(0)  # 清空列表
    def addition(self):

        #判断必填项不为空
        if not self.lineEdit_3.text():
            QMessageBox.information(self, '提示', '姓名不可为空')
            return
        if not self.lineEdit_4.text():
            QMessageBox.information(self, '提示', '学号不可为空')
            return
        if not self.radioButton.isChecked() and not self.radioButton_2.isChecked():
            QMessageBox.information(self, '提示', '性别不可为空')
            return

        if not self.comboBox.currentText():
            QMessageBox.information(self, '提示', '年龄不可为空')
            return
        if not self.comboBox_2.currentText():
            QMessageBox.information(self, '提示', '专业不可为空')
            return
        #判断是否已存在对应信息
        all_content = json.loads(files.basic_file_read(self.file))
        for key in all_content['student'].keys():
            if self.lineEdit_3.text() == key:
                QMessageBox.information(self, '提示', '已有该姓名,请重新填写')
                self.lineEdit_3.setText('')
                return
            elif self.lineEdit_4.text() == all_content['student'][key]['Sno']:
                QMessageBox.information(self, '提示', '已有该学号,请重新填写')
                self.lineEdit_4.setText('')
                return
        #新增信息
        with open(self.file, 'r', encoding='utf-8') as addstus:
            content = json.load(addstus)
            content['student'][self.lineEdit_3.text()] = {'Sno':str(self.lineEdit_4.text()),
                                                          'age':self.comboBox.currentText(),
                                                          'sex':self.radioButton.text() if self.radioButton.isChecked() else self.radioButton_2.text(),
                                                          'is':self.comboBox_2.currentText(),
                                                          'Course':''}
        #转换为json格式
        with open(self.file, 'w', encoding='utf-8') as f:
            json.dump(content, f,ensure_ascii=False)  #ensure_ascii=False:转换时保持中文显示
        QMessageBox.information(self, '提示', '添加成功')
        self.lineEdit_3.setText('')
        self.lineEdit_4.setText('')
        # 清空选项
        self.radioButton.setCheckable(False)
        self.radioButton_2.setCheckable(False)
        self.comboBox.setCurrentIndex(0)
        self.comboBox_2.setCurrentIndex(0)
        #恢复可选状态
        self.radioButton.setCheckable(True)
        self.radioButton_2.setCheckable(True)
示例#4
0
    def type(self):
        i = 0
        all_content = json.loads(files.basic_file_read(self.file))
        print("com=", self.comboBox.currentIndex())
        list_all = list(all_content['student'].values())  # 字典转换为列表

        # 全部查找
        if self.comboBox.currentIndex() == 0:
            self.tableWidget.setRowCount(count(list(all_content['student'].keys())))
            for key in all_content['student'].keys():
                self.write(i, all_content, key)
                i += 1
            self.hint('')
            pass
            # 按学号查找
        if self.comboBox.currentIndex() == 1:
            self.tableWidget.setRowCount(sum(item['Sno'] == self.lineEdit.text() for item in list_all))  #计算符合条件的个数以增加行数
            for key in all_content['student'].keys():
                if all_content['student'][key]['Sno'] == self.lineEdit.text():
                    self.write(i, all_content, key)
                    i += 1
            self.hint("学号")
            pass
            # 按姓名查找
        if self.comboBox.currentIndex() == 2:
            self.tableWidget.setRowCount(sum(key == self.lineEdit.text() for key in all_content['student'].keys()))  #计算符合条件的个数以增加行数
            for key in all_content['student'].keys():
                if key == self.lineEdit.text():
                    self.write(i, all_content, key)
                    i += 1
            self.hint("姓名")
            pass
            # 按专业查找
        if self.comboBox.currentIndex() == 3:
            self.tableWidget.setRowCount(sum(item['is'] == self.lineEdit.text() for item in list_all))  #计算符合条件的个数以增加行数
            for key in all_content['student'].keys():
                if all_content['student'][key]['is'] == self.lineEdit.text():
                    self.write(i, all_content, key)
                    i += 1
            self.hint("专业")
            pass
            # 按课程名查找
        if self.comboBox.currentIndex() == 4:
            self.tableWidget.setRowCount(sum(item['Course'] == self.lineEdit.text() for item in list_all))  # 计算符合条件的个数以增加行数
            for key in all_content['student'].keys():
                if all_content['student'][key]['Course'] == self.lineEdit.text():
                    self.write(i, all_content, key)
                    i += 1
            self.hint("课程名")
            pass
示例#5
0
    def write(self):
        all_content = json.loads(files.basic_file_read(self.file))
        for key in all_content['student'].keys():
            if key == self.index:
                self.lineEdit_3.setText(key)

                self.lineEdit_4.setText(all_content['student'][key]['Sno'])

                if all_content['student'][key]['sex'] == '男':
                    self.radioButton.setChecked(True)
                else:
                    self.radioButton_2.setChecked(True)

                self.comboBox.setCurrentText(all_content['student'][key]['is'])

                self.comboBox_2.setCurrentText(
                    all_content['student'][key]['age'])
 def examine_name_pwd(self, user_name, user_psw):
     # 验证账号密码是否正确
     file = 'D:\Project\IMS\\UserInfo\\' + user_name + '.json'
     print(file)
     dict1 = {}
     try:
         dict1 = json.loads(
             files.basic_file_read(file))  # 通过loads将json格式的文件转换成python格式的字典
     except:
         QMessageBox.critical(self, 'Warning',
                              'The account is not registered!!')
         return
     if dict1[user_name] == user_psw:
         print('密码输入正确')
         MainWindow.close()
         self.menu = IMS.Menu.Ui_Form(file)  # 换成self后可正常运行
         self.menu.show()
     else:
         print('密码输入错误')
         QMessageBox.critical(self, 'Error', 'Password error!!')
         self.lineEdit.clear()  # clear lineedit data
         return