def checkFirstLogin(self): f = QFile("config/global.config") if f.open(QIODevice.ReadWrite | QIODevice.Text): isFirstLogin = str(f.readLine())[18:-3] == "True" f.close() if isFirstLogin: f.remove("config/global.config") if f.open(QIODevice.ReadWrite | QIODevice.Text): stream = QTextStream(f) stream << "is_first_login: False" f.close() dbconfig = DBConfig() dbconfig.exec_() createTables = tablesRun()
def DelUser(self): dbc = DBConfig() dbm = DBManager(dbc.getHostname(), dbc.getName(), dbc.getUsername(), dbc.getPassword(), dbc.getPort()) column = self.tableUsers.currentColumn() row = self.tableUsers.currentRow() id = self.tableUsers.item(row, 0).text() self.tableUsers.removeRow(row) dbm.delete("users", id)
def addUser(self): dbc = DBConfig() dbm = DBManager(dbc.getHostname(), dbc.getName(), dbc.getUsername(), dbc.getPassword(), dbc.getPort()) if self.roleCB.currentIndex() == 0: role = "Student" if self.roleCB.currentIndex() == 1: role = "Teacher" if self.roleCB.currentIndex() == 2: role = "Admin" dbm.insert("users", (("username", self.usernameLE.text()), ("password", self.passwordLE.text()), ("role", role), ("name", self.nameLE.text()), ("firstSurname", self.firstSurnameLE.text()), ("secondSurname", self.secondSurnameLE.text()), ("email", self.emailLE.text()), ("phone", self.phoneLE.text()), ("address", self.addressTE.toPlainText()))) #dbm.close(); self.views.setCurrentIndex(0) self.tableUsers.setColumnCount(10) self.tableUsers.setHorizontalHeaderLabels([ "id", "usuario", "contraseña", "rol", "nombre", "apellido paterno", "apellido materno", "email", "telefono", "direccion" ]) values = dbm.select("users", 10) row = 0 for value in values: self.tableUsers.insertRow(row) id = QTableWidgetItem(str(value[0])) self.tableUsers.setItem(row, 0, id) username = QTableWidgetItem(value[1]) self.tableUsers.setItem(row, 1, username) password = QTableWidgetItem(value[2]) self.tableUsers.setItem(row, 2, password) role = QTableWidgetItem(value[3]) self.tableUsers.setItem(row, 3, role) name = QTableWidgetItem(value[4]) self.tableUsers.setItem(row, 4, name) firstSurname = QTableWidgetItem(value[5]) self.tableUsers.setItem(row, 5, firstSurname) secondSurname = QTableWidgetItem(value[6]) self.tableUsers.setItem(row, 6, secondSurname) email = QTableWidgetItem(value[7]) self.tableUsers.setItem(row, 7, email) phone = QTableWidgetItem(str(value[8])) self.tableUsers.setItem(row, 8, phone) address = QTableWidgetItem(value[9]) self.tableUsers.setItem(row, 9, address) row += 1 self.userManagerBtn.setEnabled(False) self.views.setCurrentIndex(0)
def isLogged(self): dbconfig = DBConfig() db = DBManager(dbconfig.getHostname(), dbconfig.getName(), dbconfig.getUsername(), dbconfig.getPassword(), dbconfig.getPort()) db.connect() if db.isValid("users", "username", self.user.text()) and db.isValid( "users", "password", self.password.text()): self.userData = db.selectAllWhere( "users", "username = '******'", 9) self.close() return True else: return False
def EditUser(self): dbc = DBConfig() dbm = DBManager(dbc.getHostname(), dbc.getName(), dbc.getUsername(), dbc.getPassword(), dbc.getPort()) column = self.tableUsers.currentColumn() row = self.tableUsers.currentRow() id = self.tableUsers.item(row, 0).text() value = self.tableUsers.currentItem().text() dbm.update("users", (("username", self.tableUsers.item(row, 1).text()), ("password", self.tableUsers.item(row, 2).text()), ("role", self.tableUsers.item(row, 3).text()), ("name", self.tableUsers.item(row, 4).text()), ("firstSurname", self.tableUsers.item(row, 5).text()), ("secondSurname", self.tableUsers.item(row, 6).text()), ("email", self.tableUsers.item(row, 7).text()), ("phone", self.tableUsers.item(row, 8).text()), ("address", self.tableUsers.item(row, 9).text())), id)
def userManagerClicked(self): self.views.setCurrentIndex(0) self.tableUsers.setColumnCount(10) self.tableUsers.setHorizontalHeaderLabels([ "id", "usuario", "contraseña", "rol", "nombre", "apellido paterno", "apellido materno", "email", "telefono", "direccion" ]) dbc = DBConfig() db = DBManager(dbc.getHostname(), dbc.getName(), dbc.getUsername(), dbc.getPassword(), dbc.getPort()) values = db.select("users", 10) row = 0 for value in values: self.tableUsers.insertRow(row) id = QTableWidgetItem(str(value[0])) self.tableUsers.setItem(row, 0, id) username = QTableWidgetItem(value[1]) self.tableUsers.setItem(row, 1, username) password = QTableWidgetItem(value[2]) self.tableUsers.setItem(row, 2, password) role = QTableWidgetItem(value[3]) self.tableUsers.setItem(row, 3, role) name = QTableWidgetItem(value[4]) self.tableUsers.setItem(row, 4, name) firstSurname = QTableWidgetItem(value[5]) self.tableUsers.setItem(row, 5, firstSurname) secondSurname = QTableWidgetItem(value[6]) self.tableUsers.setItem(row, 6, secondSurname) email = QTableWidgetItem(value[7]) self.tableUsers.setItem(row, 7, email) phone = QTableWidgetItem(str(value[8])) self.tableUsers.setItem(row, 8, phone) address = QTableWidgetItem(value[9]) self.tableUsers.setItem(row, 9, address) row += 1 self.userManagerBtn.setEnabled(False)
def dbConfigDialog(self): dbconfig = DBConfig() dbconfig.exec_()
def __init__(self): dbc = DBConfig(); dbm = DBManager(dbc.getHostname(), dbc.getName(), dbc.getUsername(), dbc.getPassword(), dbc.getPort()); dbm.connect(); SQL = ("" +"CREATE TABLE USERS( " +"id integer(7) PRIMARY KEY NOT NULL AUTO_INCREMENT, " +"username varchar(20) UNIQUE, " +"password varchar(20) NOT NULL, " +"role varchar(12) NOT NULL, " +"name varchar(40), " +"firstSurname varchar(40), " +"secondSurname varchar(40), " +"email varchar(40), " +"phone varchar(32), " +"address varchar(40) " +"); " +"CREATE TABLE admins ( " +"admins_id integer(7) PRIMARY KEY NOT NULL, " +"FOREIGN KEY (admins_id) REFERENCES users(id) " +"); " +"CREATE TABLE teachers ( " +"teacher_id integer(7) PRIMARY KEY NOT NULL, " +"maestria varchar(40), " +"FOREIGN KEY (teacher_id) REFERENCES users(id) " +"); " +"CREATE TABLE students ( " +"students_id integer(7) NOT NULL, " +"teacher_id integer(7) NOT NULL, " +"carrera varchar(40), " +"FOREIGN KEY (teacher_id) REFERENCES users(id), " +"FOREIGN KEY (students_id) REFERENCES users(id) " +"); " +"CREATE TABLE schedule ( " +"id integer(2) PRIMARY KEY NOT NULL AUTO_INCREMENT, " +"monday varchar(64), " +"tuesday varchar(64), " +"wednesday varchar(64), " +"thursday varchar(64), " +"friday varchar(64), " +"saturday varchar(64), " +"sunday varchar(64) " +"); "); dbm.query(SQL); dbm.insert("users", ( ("username", "Owner"), ("password", "Renwo"), ("role", "Admin"), ("name", "Owner"), ("firstSurname", ""), ("secondSurname", ""), ("email", "*****@*****.**"), ("phone", "5555555555"), ("address", "Owner Residence s.t.") )); for i in range(0, 14): dbm.insert("schedule", ( ("monday", ""), ("tuesday", ""), ("wednesday", ""), ("thursday", ""), ("friday", ""), ("saturday", ""), ("sunday", "") ));