def access_control_grant_role_add(self): if self.lineEdit_id_num_grant_role.text(): id_num = self.lineEdit_id_num_grant_role.text() door_object = self.comboBox_grant_role_door.currentData() permission_object = self.comboBox_grant_role_door_permission.currentData( ) if door_object and permission_object: person_id = common.get_single_value_from_table( 'person', 'id', "where id_card = '{}'".format(id_num), self.database) if person_id: query = 'insert into person_door_permission(person, door, permission) value (%s, %s, %s)' cursor = self.database.cursor() try: cursor.execute( query, (person_id, door_object.pk, permission_object.pk)) self.database.commit() common.data_loader_without_change_combobox( self, self.database, 'None', self.tableWidget_grant_role, fully_query_grant_role) except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "Role is existed!") cursor.close() else: message_box.MyMessageBox(QMessageBox.Critical, "Error", "Person is not exist") else: message_box.MyMessageBox(QMessageBox.Critical, "Error", "Please grant role for person in door") else: pass
def building_manage_block_manage_edit_block(self): if self.lineEdit_id_block.text(): if self.lineEdit_name_block.text().strip(): index = int(self.lineEdit_id_block.text()) name = standardized.str_standard( self.lineEdit_name_block.text()).upper() location_0 = standardized.str_standard( self.lineEdit_location_block.text()) location = location_0 if location_0 else None num_of_floor = self.spinBox_numOfFloor_block.value() acreage = self.doubleSpinBox_acreage_block.value() cursor = self.database.cursor() try: cursor.execute( "update building set name=%s, location=%s, number_of_floor=%s, acreage=%s where id=%s", (name, location, num_of_floor, acreage, index)) self.database.commit() self.statusBar().showMessage( "Building Updated With ID={}".format(index)) self.building_manage_block_manage_load() cursor.close() except db.Error as e: print(e) message_box.MyMessageBox( QMessageBox.Critical, "Error data", "name's permission exist. Please choose other").exec() else: message_box.MyMessageBox( QMessageBox.Critical, "Missing data", "Your Name Input Must Be Not Null").exec()
def building_manage_floor_manage_edit_floor(self): if self.lineEdit_id_floor.text(): index = int(self.lineEdit_id_floor.text()) if self.spinBox_name_floor.value() > 0: name = self.spinBox_name_floor.value() building = self.comboBox_floor_building.currentData().pk type_of_floor = self.comboBox_typeOfFloor.currentData().pk number_of_apartment = self.spinBox_numOfApartment.value() query = 'update floor set name=%s, building=%s, type_of_floor=%s, number_of_apartment=%s where id=%s' cursor = self.database.cursor() try: cursor.execute(query, (name, building, type_of_floor, number_of_apartment, index)) self.database.commit() common.data_loader(self, self.database, 'floor', self.tableWidget_floor, fully_query) except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The Floor Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name of floor must be number bigger than 0").exec() else: message_box.MyMessageBox(QMessageBox.Critical, "Error", "No Data!").exec()
def edit_permission(self): if self.lineEdit_permission_id.text(): if self.lineEdit_permission_name.text().strip(): index = int(self.lineEdit_permission_id.text()) if index == 1 or index == 2: message_box.MyMessageBox( QMessageBox.Critical, "Error", "This Data Cannot Modify Or Delete").exec() else: name = standardized.str_standard( self.lineEdit_permission_name.text()).upper() description_0 = standardized.str_standard( self.textEdit_permission_description.toPlainText()) description = description_0 if description_0 else None cursor = self.database.cursor() try: cursor.execute( "update permission set name=%s, description=%s where id=%s", (name, description, index)) self.database.commit() self.statusBar().showMessage( "Permission Updated With ID={}".format(index)) self.load_permission_setting() cursor.close() except db.Error as e: print(e) message_box.MyMessageBox( QMessageBox.Critical, "Error data", "name's permission exist. Please choose other").exec() else: message_box.MyMessageBox( QMessageBox.Critical, "Missing data", "Your Name Input Must Be Not Null").exec()
def apartment_manage_add_apartment(self): name_apartment = int(self.spinBox_apartment_number.value()) if name_apartment >= 1: name_apartment = self.label__prefix_apartment_number.text() + str( name_apartment) building = self.comboBox_resident_apartment_block.currentData().pk floor = self.comboBox_resident_apartment_floor.currentData().pk status = self.comboBox_resident_apartment_status.currentText() if status == 'Available': status = 0 else: status = 1 query = 'insert into apartment(name, floor, status) value (%s, %s, %s)' cursor = self.database.cursor() try: cursor.execute(query, (name_apartment, floor, status)) self.database.commit() common.data_loader(self, self.database, 'apartment', self.tableWidget_resident_apartment_table, fully_query_apartment) except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The apartment Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name of apartment must be bigger than 0").exec()
def apartment_manage_edit_apartment(self): if self.lineEdit_id_resident_apartment.text(): apartment_id = int(self.lineEdit_id_resident_apartment.text()) name = int(self.spinBox_apartment_number.value()) if name >= 1: name = self.label__prefix_apartment_number.text() + str(name) floor = self.comboBox_resident_apartment_floor.currentData().pk status = self.comboBox_resident_apartment_status.currentText() if status == 'Available': status = 0 else: status = 1 query = 'update apartment set apartment.name = %s, apartment.floor = %s, apartment.status = %s where apartment.id = %s' cursor = self.database.cursor() try: cursor.execute(query, (name, floor, status, apartment_id)) self.database.commit() common.data_loader(self, self.database, 'apartment', self.tableWidget_resident_apartment_table, fully_query_apartment) except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The apartment Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name of apartment must be bigger than 0").exec() else: pass
def apartment_manage_edit_company(self): if self.lineEdit_company_id.text(): company_id = int(self.lineEdit_company_id.text()) if self.lineEdit_company_name.text(): name = self.lineEdit_company_name.text() phone = self.lineEdit_company_phone.text() floor = self.comboBox_company_office_floor_company.currentData().pk office_new = self.comboBox_company_office_number.currentData().pk office_old = common.get_single_value_from_table( 'company', 'apartment', 'where id = {}'.format(company_id), self.database) query = 'call update_company(%s,%s, %s, %s, %s);' cursor = self.database.cursor() try: cursor.execute( query, (company_id, name, phone, office_old, office_new)) self.database.commit() common.data_loader(self, self.database, 'company', self.tableWidget_company_apartment_table, fully_query_company) except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The Company Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name of company must be not null").exec()
def building_manage_block_manage_add_block(self): if self.lineEdit_name_block.text().strip(): name = standardized.str_standard( self.lineEdit_name_block.text()).upper() location_0 = standardized.str_standard( self.lineEdit_location_block.text()) location = location_0 if location_0 else None num_of_floor = self.spinBox_numOfFloor_block.value() arceage = self.doubleSpinBox_acreage_block.value() cursor = self.database.cursor() try: cursor.execute( "insert into building(name, location, number_of_floor, acreage) values(%s, %s, %s, %s)", (name, location, num_of_floor, arceage)) self.database.commit() self.statusBar().showMessage("New Building Added") self.building_manage_block_manage_load() cursor.close() except db.Error as e: message_box.MyMessageBox( QMessageBox.Critical, "Error data", "name's type of floor exist. Please choose other").exec() else: message_box.MyMessageBox(QMessageBox.Critical, "Missing data", "Your Name Input Must Be Not Null").exec()
def access_control_grant_role_edit(self): if self.lineEdit_id_grant_role.text(): id_grant_role = int(self.lineEdit_id_grant_role.text()) id_card = self.lineEdit_id_num_grant_role.text() if id_grant_role and id_card: door_object = self.comboBox_grant_role_door.currentData() permission_object = self.comboBox_grant_role_door_permission.currentData( ) person_id = common.get_single_value_from_table( 'person', 'id', "where id_card = '{}'".format(id_card), self.database) if door_object and permission_object: query = 'update person_door_permission set door = %s, permission = %s where id = %s' cursor = self.database.cursor() try: cursor.execute( query, (door_object.pk, permission_object.pk, id_grant_role)) self.database.commit() common.data_loader_without_change_combobox( self, self.database, 'None', self.tableWidget_grant_role, fully_query_grant_role) except db.Error as e: message_box.MyMessageBox( QMessageBox.Critical, 'Error', 'This person has same role exist') else: message_box.MyMessageBox(QMessageBox.Critical, 'No Data', 'Plese choose one before edit') else: pass
def apartment_manage_add_company(self): if self.lineEdit_company_name.text(): name = self.lineEdit_company_name.text() phone = self.lineEdit_company_phone.text() floor = self.comboBox_company_office_floor_company.currentData().pk office = self.comboBox_company_office_number.currentText() if status == 'Available': status = 0 else: status = 1 query = 'call insert_company(%s, %s, %s)' cursor = self.database.cursor() try: cursor.execute(query, (name, phone, office)) self.database.commit() common.data_loader(self, self.database, 'company', self.tableWidget_company_apartment_table, fully_query_company) except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The Company Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name of company must be not null").exec()
def resident_manage_staff_tab_add_staff(self): if self.lineEdit_company_staff_name.text( ) and self.lineEdit_company_staff_id_number.text(): phone_number = self.lineEdit_company_staff_phone.text() id_number = self.lineEdit_company_staff_id_number.text() if (len(phone_number) > 0 and len(phone_number) < 10) or (len(id_number) > 0 and (len(id_number) != 9) and len(id_number) != 12): if len(phone_number) > 0 and len(phone_number) < 10: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The Phone Must Be lenght 10").exec() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The ID Number Must Be lenght = 9 or 13").exec() else: name = self.lineEdit_company_staff_name.text() birthday = self.dateEdit_company_staff_birthday.date() birthday_mysql = standardized.str_date_standard( birthday.year(), birthday.month(), birthday.day()) gender = self.comboBox_company_staff_gender.currentText() if gender == 'Male': gender = 1 else: gender = 0 id_number = self.lineEdit_company_staff_id_number.text() phone = self.lineEdit_company_staff_phone.text() village = self.textEdit_company_staff_village.toPlainText() curr_accommodation = self.textEdit_company_staff_current_accommodation.toPlainText( ) today_mysql = common.get_today_str() name_en = common.make_name(name, birthday_mysql, id_number, today_mysql) company = self.comboBox_company_staff_company.currentData().pk query = 'call insert_staff(%s, %s, %s, %s, %s, %s, %s, %s, %s)' cursor = self.database.cursor() try: cursor.execute(query, (company, name, name_en, birthday_mysql, gender, id_number, phone, village, curr_accommodation)) self.database.commit() common.data_loader(self, self.database, 'None', self.tableWidget_staff_table, full_select_staff) except db.Error as e: print(e) message_box.MyMessageBox(QMessageBox.Critical, "Error", "The ID Number Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name or ID Number must be Not Null").exec()
def resident_manage_resident_tab_edit_resident(self): if self.lineEdit_resident_id.text(): cur_id_resident = int(self.lineEdit_resident_id.text()) if self.lineEdit_resident_name.text() and self.lineEdit_resident_id_number.text(): phone_number = self.lineEdit_resident_phone.text() id_number = self.lineEdit_resident_id_number.text() if (len(phone_number) > 0 and len(phone_number) < 10) or (len(id_number) > 0 and (len(id_number) != 9) and len(id_number)!=12): if len(phone_number) > 0 and len(phone_number) < 10: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The Phone Must Be lenght 10").exec() else: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The ID Number Must Be lenght = 9 or 13").exec() else: query_get_cur_resident = ''' select p.id, a.name as 'apartment', a.id as 'apartment_id', p.name, p.birthday, if(p.gender=1, 'Male', 'Female') as 'gender', p.id_card, p.phone, p.village, p.current_accommodation from person as p join resident_apartment as r on p.id = r.resident join apartment as a on a.id = r.apartment join floor as f on a.floor = f.id join building as b on b.id = f.building join type_of_floor as t on t.id = 2 where p.is_delete = 0 and p.is_resident = 1 and p.id = {} ''' cur_resident = common.get_single_item_from_query(query_get_cur_resident.format(cur_id_resident), self.database) name = self.lineEdit_resident_name.text() birthday = self.dateEdit_resident_birthday.date() birthday_mysql = standardized.str_date_standard(birthday.year(), birthday.month(), birthday.day()) gender = self.comboBox_resident_gender.currentText() if gender == 'Male': gender = 1 else: gender = 0 id_number = self.lineEdit_resident_id_number.text() phone =self.lineEdit_resident_phone.text() village = self.textEdit_resident_village.toPlainText() curr_accommodation = self.textEdit_resident_current_accomodation.toPlainText() apartment = self.comboBox_resident_room_number.currentData().pk today_mysql = common.get_today_str() query = 'call edit_resident(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' cursor = self.database.cursor() try: cursor.execute(query,(apartment, name, birthday_mysql, gender, phone, id_number, village, curr_accommodation, cur_resident[6], cur_resident[2])) print(cursor._last_executed) self.database.commit() common.data_loader(self, self.database, 'None', self.tableWidget_resident, fully_query_resident) except db.Error as e: print(e) message_box.MyMessageBox(QMessageBox.Critical, "Error", "The ID Number Is Exist!").exec() cursor.close() else: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The name or ID Number must be Not Null").exec()
def building_manage_floor_manage_import_file_floor(self): file_path = self.pushButton_choose_import_file_floor.text() filename, file_extension = os.path.splitext(file_path) with open(file_path, mode='rb') as f: if file_extension == '.csv': reader = pd.read_csv(f) else: reader = pd.read_excel(f) header = reader.columns cursor = self.database.cursor() try: for index, row in reader.iterrows(): name = int(row['name']) building = int(row['building']) type_of_floor = int(row['type_of_floor']) number_of_apartment = int(row['number_of_apartment']) try: query = "insert into floor(name, building, type_of_floor, number_of_apartment) " cursor.execute( query + "value(%s, %s, %s, %s);", (name, building, type_of_floor, number_of_apartment)) print(cursor._last_executed) self.database.commit() except db.Error as e: print(e) cursor.close() except: message_box.MyMessageBox(QMessageBox.Critical, "Error", "Incorrect format file!").exec() self.building_manage_floor_manage_load()
def import_type_of_floor(self): file_path = self.pushButton_select_file_type_floor.text() filename, file_extension = os.path.splitext(file_path) with open(file_path, mode='rb') as f: if file_extension == '.csv': reader = pd.read_csv(f) else: reader = pd.read_excel(f) header = reader.columns try: cursor = self.database.cursor() for index, row in reader.iterrows(): name = standardized.str_standard(str(row['name'])) description = standardized.str_standard(str( row['description'])) try: cursor.execute( "insert into type_of_floor(name, description) value(%s, %s)", (name, description)) self.database.commit() except db.Error as e: pass cursor.close() except: message_box.MyMessageBox(QMessageBox.Critical, "Error", "Incorrect format file!") self.load_type_of_floor_setting()
def building_manage_door_manage_import_file_door(self): file_path = self.pushButton_select_file_door.text() filename, file_extension = os.path.splitext(file_path) with open(file_path, mode='rb') as f: if file_extension == '.csv': reader = pd.read_csv(f) else: reader = pd.read_excel(f) header = reader.columns cursor = self.database.cursor() try: for index, row in reader.iterrows(): floor = int(row['floor']) door = int(row['door']) role_door = row['permission'] try: query = "call insert_door_from_file(%s, %s, %s);" cursor.execute(query, (floor, door, role_door)) print(cursor._last_executed) self.database.commit() except db.Error as e: print(e) cursor.close() except: message_box.MyMessageBox(QMessageBox.Critical, "Error", "Incorrect format file!").exec() self.building_manage_floor_manage_load()
def access_control_person_image_add_image_capture(self): data = common.get_row_data_item_click(self.tableWidget_person_image_info) if data: person = my_model.PersonDraffInfo(*data) warning = QMessageBox.question( self, 'Choose person add image', "Would you want to add images selected for {}?".format( person.name_en), QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if warning == QMessageBox.Yes: images_selected = self.listWidget_image_capturing.selectedItems() folder_path = '/home/henry/FinalProject/face_recognition_system/src/data/dataset/processed/' last_image_for_person = common.get_single_item_from_query( select_lastest_image_for_person.format(person.pk), self.database) if last_image_for_person: last_image_name = (my_model.Image_Person( *last_image_for_person)).url.split('/')[-1] name_number = last_image_name.split('.')[0] else: name_number = 0 common.save_image(folder_path, person, images_selected, int(name_number), self.database) for image in images_selected: self.listWidget_image_capturing.takeItem( self.listWidget_image_capturing.row(image)) self.images_capture.remove(image.data(Qt.UserRole)) if len(self.images_capture) == 0: self.flag_anchor = None else: message_box.MyMessageBox( QMessageBox.Critical, 'Error', 'No Person Selected. Please select a person in the top table' ).exec()
def resident_manage_resident_tab_import_file_resident(self): file_path = self.pushButton_select_company_staff_file.text() filename, file_extension = os.path.splitext(file_path) with open(file_path, mode='rb') as f: if file_extension == '.csv': reader = pd.read_csv(f) else: reader = pd.read_excel(f) header = reader.columns cursor = self.database.cursor() try: for index, row in reader.iterrows(): apartment = row['apartment'] name = row['name'] birthday = row['birthday'] gender = row['gender'] id_card = str(row['id_card']) phone = row['phone'] village = row['village'] current_accomodation = row['current_accommodation'] cur_date = common.get_today_str() name_en = common.make_name(name, birthday, id_card, cur_date) try: query = "call insert_staff_from_file(%s, %s, %s, %s, %s, %s, %s, %s, %s);" cursor.execute(query, (apartment, name, name_en ,birthday, gender, phone, id_card, village, current_accomodation)) self.database.commit() except db.Error as e: print(e) cursor.close() except: message_box.MyMessageBox(QMessageBox.Critical, "Error", "Incorrect format file!").exec() self.resident_manage_staff_load()
def apartment_manage_import_apartment(self): file_path = self.pushButton_select_file_apartment_resident_import.text() filename, file_extension = os.path.splitext(file_path) with open(file_path, mode='rb') as f: if file_extension == '.csv': reader = pd.read_csv(f) else: reader = pd.read_excel(f) header = reader.columns cursor = self.database.cursor() try: for index, row in reader.iterrows(): building = row['building'] floor = int(row['floor']) apartment = row['apartment'] status = row['status'] try: query = "call insert_apartment_from_file(%s, %s, %s, %s);" cursor.execute(query, (building, floor, apartment, status)) print(cursor._last_executed) self.database.commit() except db.Error as e: print(e) cursor.close() except: message_box.MyMessageBox(QMessageBox.Critical, "Error", "Incorrect format file!").exec() self.apartment_manage_load_company_tab() self.statusBar().showMessage("Import Success")
def access_control_grant_role_import_file(self): file_path = self.pushButton_select_file_grant_role.text() filename, file_extension = os.path.splitext(file_path) with open(file_path, mode='rb') as f: if file_extension == '.csv': reader = pd.read_csv(f) else: reader = pd.read_excel(f) header = reader.columns cursor = self.database.cursor() try: for index, row in reader.iterrows(): building = row['building'] floor = row['floor'] door = row['door'] id_card = str(row['id_card']) permisson = row['permission'] try: query = "call insert_grant_role_from_file(%s, %s, %s, %s, %s);" cursor.execute( query, (building, floor, door, id_card, permission)) self.database.commit() except db.Error as e: print(e) cursor.close() except: message_box.MyMessageBox(QMessageBox.Critical, "Error", "Incorrect format file!").exec() self.resident_manage_staff_load()
def building_manage_floor_manage_delete_floor(self): if self.lineEdit_id_floor.text(): index = int(self.lineEdit_id_floor.text()) common.delete_item(self, 'floor', self.database, index, self.building_manage_floor_manage_load, self.building_manage_floor_manage_clear_form) else: message_box.MyMessageBox(QMessageBox.Critical, "Error", "No Data!").exec()
def building_manage_door_manage_add_role_door(self): name_role_door = self.lineEdit_role_door_name.text() if name_role_door: desc = self.textEdit_role_door_description.toPlainText() query = "insert into role_door(name, description) value(%s, %s)" cursor = self.database.cursor() try: cursor.execute(query, (name_role_door.upper(), desc)) self.database.commit() common.data_loader(self, self.database, 'role_door', self.tableWidget_role_door, "select * from role_door") except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The role door Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name of role door must be not null").exec()
def access_control_grant_role_export(self): if self.tableWidget_grant_role.rowCount(): path_file = common.select_file_export( self, self.pushButton_export_grant_role) if path_file: common.export_data_from_table_widget(self, self.tableWidget_grant_role, path_file) self.statusBar().showMessage("Export Success") else: message_box.MyMessageBox(QMessageBox.Critical, 'Error', 'No data to export')
def building_manage_door_manage_add_door(self): name_door = int(self.spinBox_name_door.value()) if name_door >= 1: building = self.comboBox_door_manage_building.currentData().pk floor = self.comboBox_door_manage_floor.currentData().pk role_door = self.comboBox_door_permission.currentData().pk query = 'insert into door(name, floor, role) value (%s, %s, %s)' cursor = self.database.cursor() try: cursor.execute(query, (name_door, floor, role_door)) self.database.commit() common.data_loader(self, self.database, 'door', self.tableWidget_door, fully_query_door) except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The door Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name of door must be bigger than 0").exec()
def add_permission(self): if self.lineEdit_permission_name.text().strip(): name = standardized.str_standard( self.lineEdit_permission_name.text()).upper() description_0 = standardized.str_standard( self.textEdit_permission_description.toPlainText()) description = description_0 if description_0 else None cursor = self.database.cursor() try: cursor.execute( "insert into permission(name, description) values(%s, %s)", (name, description)) self.database.commit() self.statusBar().showMessage("New Permission Added") self.load_permission_setting() cursor.close() except db.Error as e: message_box.MyMessageBox( QMessageBox.Critical, "Error data", "name's permssion exist. Please choose other").exec() else: message_box.MyMessageBox(QMessageBox.Critical, "Missing data", "Your Name Input Must Be Not Null").exec()
def building_manage_floor_manage_add_floor(self): if self.spinBox_name_floor.value() > 0: name = self.spinBox_name_floor.value() building = self.comboBox_floor_building.currentData().pk type_of_floor = self.comboBox_typeOfFloor.currentData().pk number_of_apartment = self.spinBox_numOfApartment.value() query = 'insert into floor(name, building, type_of_floor, number_of_apartment) value (%s, %s, %s, %s)' cursor = self.database.cursor() try: cursor.execute( query, (name, building, type_of_floor, number_of_apartment)) self.database.commit() common.data_loader(self, self.database, 'floor', self.tableWidget_floor, fully_query) except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The Floor Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name of floor must be bigger than 0").exec()
def building_manage_door_manage_edit_door(self): if self.lineEdit_id_door.text(): door_id = int(self.lineEdit_id_door.text()) name = int(self.spinBox_name_door.value()) if name >= 1: floor = self.comboBox_door_manage_floor.currentData().pk role_door = self.comboBox_door_permission.currentData().pk query = 'update door set door.name = %s, door.floor = %s, door.role = %s where door.id = %s' cursor = self.database.cursor() try: cursor.execute(query, (name, floor, role_door, door_id)) self.database.commit() common.data_loader(self, self.database, 'door', self.tableWidget_door, fully_query_door) except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The door Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name of door must be bigger than 0").exec() else: pass
def building_manage_door_manage_edit_role_door(self): role_door_id = self.lineEdit_role_door_id.text() if role_door_id: role_door_id = int(role_door_id) name_role_door = self.lineEdit_role_door_name.text() if name_role_door: desc = self.textEdit_role_door_description.toPlainText() query = "update role_door set role_door.name = %s, role_door.description = %s where role_door.id = %s" cursor = self.database.cursor() try: cursor.execute(query, (name_role_door.upper(), desc, role_door_id)) self.database.commit() common.data_loader(self, self.database, 'role_door', self.tableWidget_role_door, "select * from role_door") except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "The role door Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name of role door must be not null").exec()
def apartment_manage_delete_company(self): if self.lineEdit_company_id.text(): company_id = int(self.lineEdit_company_id.text()) office_old = common.get_single_value_from_table( 'company', 'apartment', 'where id = {}'.format(company_id), self.database) query = 'update apartment set status = 0 where id = %s' cursor = self.database.cursor() try: cursor.execute(query, (office_old)) self.database.commit() common.data_loader(self, self.database, 'apartment', self.tableWidget_company_apartment_table, fully_query_company) except db.Error as e: message_box.MyMessageBox(QMessageBox.Critical, "Error", "Wrong").exec() cursor.close() common.delete_item(self, 'company', self.database, company_id, self.apartment_manage_load_company_tab, self.apartment_manage_clear_data_form_company_form)
def delete_permission(self): if self.lineEdit_permission_id.text(): index = int(self.lineEdit_permission_id.text()) if index == 1 or index == 2: message_box.MyMessageBox( QMessageBox.Critical, "Error", "This Data Cannot Modify Or Delete").exec() else: cursor = self.database.cursor() try: cursor.execute("delete from permission where id=%s", [(index)]) self.database.commit() self.load_permission_setting() self.statusBar().showMessage( "A Permission Deleted With ID={}".format(index)) cursor.close() self.lineEdit_permission_id.setText(None) self.lineEdit_permission_name.setText(None) self.textEdit_permission_description.setPlainText(None) except db.Error as e: pass
def resident_manage_staff_tab_edit_staff(self): if self.lineEdit_company_staff_id.text(): cur_id_staff = int(self.lineEdit_company_staff_id.text()) if self.lineEdit_company_staff_name.text( ) and self.lineEdit_company_staff_id_number.text(): phone_number = self.lineEdit_company_staff_phone.text() id_number = self.lineEdit_company_staff_id_number.text() if (len(phone_number) > 0 and len(phone_number) < 10) or (len(id_number) > 0 and (len(id_number) != 9) and len(id_number) != 12): if len(phone_number) > 0 and len(phone_number) < 10: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The Phone Must Be lenght 10").exec() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The ID Number Must Be lenght = 9 or 13").exec() else: query_get_cur_staff = ''' select s.id, c.id as 'company', a.id as 'office', p.name, p.birthday, if(p.gender=1,'Male', 'Female') as 'gender' , p.id_card, p.phone, p.village, p.current_accommodation from company_staff as s join person as p on s.staff = p.id join company as c on s.company = c.id join apartment as a on a.id = c.apartment where p.is_delete = 0 and s.id = {} ''' cur_staff = common.get_single_item_from_query( query_get_cur_staff.format(cur_id_staff), self.database) name = self.lineEdit_company_staff_name.text() birthday = self.dateEdit_company_staff_birthday.date() birthday_mysql = standardized.str_date_standard( birthday.year(), birthday.month(), birthday.day()) gender = self.comboBox_company_staff_gender.currentText() if gender == 'Male': gender = 1 else: gender = 0 id_number = self.lineEdit_company_staff_id_number.text() phone = self.lineEdit_company_staff_phone.text() village = self.textEdit_company_staff_village.toPlainText() curr_accommodation = self.textEdit_company_staff_current_accommodation.toPlainText( ) company = self.comboBox_company_staff_company.currentData().pk query = 'call edit_staff(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' cursor = self.database.cursor() try: cursor.execute( query, (company, name, birthday_mysql, gender, phone, id_number, village, curr_accommodation, cur_staff[6], cur_staff[1])) self.database.commit() common.data_loader(self, self.database, 'None', self.tableWidget_staff_table, full_select_staff) except db.Error as e: print(e) message_box.MyMessageBox(QMessageBox.Critical, "Error", "The ID Number Is Exist!").exec() cursor.close() else: message_box.MyMessageBox( QMessageBox.Critical, "Error", "The name or ID Number must be Not Null").exec()