def set_floor_combobox_data_change_search(building_combobox, floor_combobox, type_of_floor, database):
    building_object = building_combobox.currentData()
    if building_object:
        building_id = building_object.pk
        floor_combobox.clear()
        if type_of_floor:
            query_select_floor = '''
                select f.id, f.name as 'floor', b.name as 'building' ,t.name as 'type_of_floor', 
                f.number_of_apartment as 'number_of_apartment' from floor as f
                join building as b on f.building = b.id
                join type_of_floor as t on f.type_of_floor = t.id
                where b.id = {} and t.id = {}
            '''
            data_floor = get_list_model(database, my_model.Floor, query_select_floor.format(building_id, type_of_floor))
        else:
            query_select_floor = '''
                select f.id, f.name as 'floor', b.name as 'building' ,t.name as 'type_of_floor', 
                f.number_of_apartment as 'number_of_apartment' from floor as f
                join building as b on f.building = b.id
                join type_of_floor as t on f.type_of_floor = t.id
                where b.id = {}
            '''
            data_floor = get_list_model(database, my_model.Floor, query_select_floor.format(building_id))

        for floor in data_floor:
            floor_object = my_model.Floor(*floor)
            floor_name = 'Tầng ' + str(floor[1])+' Tòa Nhà ' + floor[2]
            floor_combobox.addItem(floor_name, floor_object)
    else:
        floor_combobox.clear()
        floor_combobox.addItem('')
Esempio n. 2
0
def resident_manage_staff_tab_data_change_floor_combobox(self):
    building_object = self.comboBox_company_staff_building.currentData()
    if building_object:
        building_id = building_object.pk
        self.comboBox_company_staff_floor.clear()
        cursor = self.database.cursor()
        query_select_floor = '''
            select f.id, f.name as 'floor', b.name as 'building' ,t.name as 'type_of_floor', f.number_of_apartment as 'number_of_apartment' from floor as f
            join building as b on f.building = b.id
            join type_of_floor as t on f.type_of_floor = t.id
            where b.id = %s and t.id = 1
        '''
        cursor.execute(query_select_floor, (building_id, ))
        data_floor = cursor.fetchall()
        for floor in data_floor:
            floor_object = my_model.Floor(floor[0], floor[1], floor[2],
                                          floor[3], floor[4])
            floor_name = 'Tầng ' + str(floor[1]) + ' Tòa Nhà ' + floor[2]
            self.comboBox_company_staff_floor.addItem(floor_name, floor_object)