def FN_RESET_USER_MAIN(self): mycursor = self.conn.cursor() if CL_validation.FN_isEmpty(self.LE_password.text()): QtWidgets.QMessageBox.warning(self, "Error", "Enter Password Please") elif CL_validation.FN_isEmpty(self.LE_password2.text()): QtWidgets.QMessageBox.warning(self, "Error", " RePassword Please") elif CL_validation.FN_validation_password( self, self.LE_password.text()) == False: changeDate = str(datetime.today().strftime('%Y-%m-%d-%H:%M-%S')) if self.LE_password.text() == self.LE_password2.text(): sql_select_Query = "select * from SYS_USER where USER_NAME = '" + self.LE_username.currentText( ) + "' and USER_STATUS = 1" mycursor = self.conn.cursor() mycursor.execute(sql_select_Query) print(sql_select_Query) record = mycursor.fetchone() print(record) if mycursor.rowcount > 0: sql = "UPDATE SYS_USER set USER_PASSWORD= %s , USER_CHANGED_ON = %s , USER_CHANGED_BY = %s where USER_NAME= %s" val = (self.LE_password.text(), changeDate, self.LE_username.currentText(), self.LE_username.currentText()) print(sql) mycursor.execute(sql, val) mycursor.close() db1.connectionCommit(self.conn) print(mycursor.rowcount, "password changed") QtWidgets.QMessageBox.information( self, "Success", "Password is reset successfully") db1.connectionClose(self.conn) self.close() else: QtWidgets.QMessageBox.warning(self, "Error", "Incorrect Username ") print("Please Enter Correct Username and Password") else: QtWidgets.QMessageBox.warning( self, "Error", "Please enter 2 different Passwords")
def FN_CREATE_USER(self): try: sql_select_Query = "select * from SYS_USER where USER_NAME = '" + self.LE_name.text( ) + "' and USER_STATUS = 1" print(sql_select_Query) mycursor = self.conn.cursor() mycursor.execute(sql_select_Query) print(mycursor.fetchall()) if mycursor.rowcount > 0: QtWidgets.QMessageBox.warning(self, "Error", "Username is already exists") else: self.name = self.LE_name.text().strip() self.password = self.LE_password.text().strip() print(self.CMB_branch.currentData()[0]) self.branch = self.CMB_branch.currentData()[0] self.fullName = self.LE_fullName.text().strip() self.hrId = self.LE_hrId.text().strip() self.userType = self.CMB_userType.currentText() self.status = self.CMB_userStatus.currentText() if self.status == 'Active': self.status = 1 else: self.status = 0 mycursor = self.conn.cursor() mycursor.execute( "SELECT max(cast(USER_ID AS UNSIGNED)) FROM SYS_USER") myresult = mycursor.fetchone() if myresult[0] == None: self.id = "1" else: self.id = int(myresult[0]) + 1 creationDate = str( datetime.today().strftime('%Y-%m-%d-%H:%M-%S')) if CL_validation.FN_isEmpty( self.name) or CL_validation.FN_isEmpty( self.password) or CL_validation.FN_isEmpty( self.fullName) or CL_validation.FN_isEmpty( self.hrId): QtWidgets.QMessageBox.warning( self, "Error", "Please enter all required fields") else: if CL_validation.FN_validation_password( self, self.password) == False: sql = "INSERT INTO SYS_USER (USER_ID, BRANCH_NO, USER_NAME, USER_PASSWORD, USER_FULLNAME, USER_HR_ID, USER_CREATED_ON, USER_CREATED_BY, USER_CHANGED_ON, USER_CHANGED_BY,USER_STATUS, USERTYPE_ID) VALUES ( %s, %s, %s, %s,%s, %s, %s, %s, %s, %s, %s, %s)" val = (self.id, self.branch, self.name, self.password, self.fullName, self.hrId, creationDate, CL_userModule.user_name, '', '', self.status, self.userType) mycursor.execute(sql, val) for i in range(len(self.CMB_branch.currentData())): sql2 = "INSERT INTO SYS_USER_BRANCH (USER_ID, COMPANY_ID, BRANCH_NO, STATUS) VALUES ( %s, %s, %s, %s)" val = (self.id, '1', self.CMB_branch.currentData()[i], '1') mycursor.execute(sql2, val) if self.checkBox.isChecked(): for i in range(len( self.CMB_section.currentData())): sql = "INSERT INTO SYS_USER_SECTION (USER_ID, SECTION_ID, STATUS) VALUES (%s, %s, %s)" val = (self.id, self.CMB_section.currentData()[i], '1') mycursor.execute(sql, val) mycursor.close() print(mycursor.rowcount, "record inserted.") QtWidgets.QMessageBox.information( self, "Success", "User is created successfully") db1.connectionCommit(self.conn) db1.connectionClose(self.conn) self.close() except: print(sys.exc_info())
def FN_MODIFY_USER(self): try: self.id = self.LB_userID.text() self.name = self.LE_name.text().strip() self.password = self.LE_password.text().strip() self.branch = self.CMB_branch.currentData()[0] self.fullName = self.LE_fullName.text().strip() self.hrId = self.LE_hrId.text().strip() self.userType = self.CMB_userType.currentText() self.status = self.CMB_userStatus.currentText() if self.status == 'Active': self.status = 1 else: self.status = 0 if CL_validation.FN_isEmpty(self.name) or CL_validation.FN_isEmpty( self.password) or CL_validation.FN_isEmpty( self.fullName) or CL_validation.FN_isEmpty(self.hrId): QtWidgets.QMessageBox.warning( self, "Error", "Please enter all required fields") else: if CL_validation.FN_validation_password( self, self.password) == False: mycursor = self.conn.cursor() if len(self.CMB_branch.currentData()) > 0: for i in self.CMB_branch.currentData(): self.new_branch_list.append(i) if len(self.CMB_section.currentData()) > 0: for i in self.CMB_section.currentData(): self.new_section_list.append(i) changeDate = str( datetime.today().strftime('%Y-%m-%d-%H:%M-%S')) sql = "UPDATE SYS_USER set USER_NAME= %s , USER_PASSWORD= %s , BRANCH_NO = %s, USER_FULLNAME = %s , USER_HR_ID = %s, USER_CHANGED_ON = %s , USER_CHANGED_BY = %s, USER_STATUS = %s, USERTYPE_ID = %s where USER_id= %s " val = (self.name, self.password, self.branch, self.fullName, self.hrId, changeDate, CL_userModule.user_name, self.status, self.userType, self.id) mycursor.execute(sql, val) if len(self.branch_list) > len(self.new_branch_list): for row in self.branch_list: print(row) if row in self.new_branch_list: print("found") else: print("not found") mycursor = self.conn.cursor() sql5 = "update SYS_USER_BRANCH set STATUS= 0 where USER_ID='" + self.userid + "' and BRANCH_NO = '" + row + "'" mycursor.execute(sql5) else: for row in self.new_branch_list: print(row) if row in self.branch_list: print("found") else: mycursor = self.conn.cursor() mycursor.execute( "SELECT * FROM SYS_USER_BRANCH where BRANCH_NO='" + row + "' and USER_ID='" + self.userid + "'") record = mycursor.fetchall() if mycursor.rowcount > 0: mycursor = self.conn.cursor() sql8 = "update SYS_USER_BRANCH set STATUS= 1 where USER_ID='" + self.userid + "' and BRANCH_NO = '" + row + "'" mycursor.execute(sql8) print(sql8) else: mycursor = self.conn.cursor() sql6 = "INSERT INTO SYS_USER_BRANCH (USER_ID,COMPANY_ID,BRANCH_NO,STATUS) VALUES (%s,%s,%s,%s)" val6 = (self.userid, '1', row, '1') mycursor.execute(sql6, val6) if len(self.section_list) > len(self.new_section_list): for row in self.section_list: print(row) if row in self.new_section_list: print("found") else: print("not found") mycursor = self.conn.cursor() sql5 = "update SYS_USER_SECTION set STATUS= 0 where USER_ID='" + self.userid + "' and SECTION_ID = '" + row + "'" mycursor.execute(sql5) else: for row in self.new_section_list: print(row) if row in self.section_list: print("found") else: mycursor = self.conn.cursor() mycursor.execute( "SELECT * FROM SYS_USER_SECTION where SECTION_ID='" + row + "' and USER_ID='" + self.userid + "'") record = mycursor.fetchall() if mycursor.rowcount > 0: mycursor = self.conn.cursor() sql8 = "update SYS_USER_SECTION set STATUS= 1 where USER_ID='" + self.userid + "' and SECTION_ID = '" + row + "'" mycursor.execute(sql8) print(sql8) else: mycursor = self.conn.cursor() sql6 = "INSERT INTO SYS_USER_SECTION (USER_ID,SECTION_ID,STATUS) VALUES (%s,%s,%s)" val6 = (self.userid, row, '1') mycursor.execute(sql6, val6) mycursor.close() db1.connectionCommit(self.conn) print(mycursor.rowcount, "record Modified.") QtWidgets.QMessageBox.information( self, "Success", "User is modified successfully") db1.connectionClose(self.conn) self.close() except: print(sys.exc_info())