示例#1
0
        public void UpdatePersonAccess(int id, IEnumerable <int> roomsId)
        {
            var setIds = roomsId.ToHashSet();
            var pairs  = repo.GetPersonRoomsAccess(id);

            foreach (var item in pairs)
            {
                if (!setIds.Contains(item.RoomId))
                {
                    var extraEntity = repo.FindPersonRoomPair(item.PersonId, item.RoomId);
                    if (extraEntity != null)
                    {
                        repo.DeletePersonRoomPair(extraEntity);
                    }
                }
                else
                {
                    setIds.Remove(item.RoomId);
                }
            }

            foreach (var roomIdItem in setIds)
            {
                var personRoom = new PersonRoom(id, roomIdItem);
                repo.AddPersonRoom(personRoom);
            }

            repo.SaveChanges();
        }
示例#2
0
        public void UpdateRoomConnections(int id, IEnumerable <int> roomsId)
        {
            var setIds    = roomsId.ToHashSet();
            var connected = repo.GetNeighbourRooms(id);

            foreach (var item in connected)
            {
                if (item != null)
                {
                    if (!setIds.Contains(item.Id))
                    {
                        if (item.Type == RoomType.Hall)
                        {
                            throw new Exception("Unable to disconnect room from hall");
                        }
                        var  finder      = new WayFinder(repo, item.Id);
                        Room extraEntity = null; //= repo.FindRoom(item.Id);

                        if (extraEntity != null)
                        {
                            var door = repo.GetDoorOfRooms(item.Id, id);
                            if (door != null)
                            {
                                repo.DeleteDoor(door);
                            }
                        }
                    }
                    else
                    {
                        setIds.Remove(item.Id);
                    }
                }
                else
                {
                    if (!setIds.Contains(-1))
                    {
                        var extraEntity = repo.GetDoorOfRooms(id, null);
                    }
                    else
                    {
                        setIds.Remove(-1);
                    }
                }
            }

            foreach (var roomIdItem in setIds)
            {
                var personRoom = new PersonRoom(id, roomIdItem);
                repo.AddPersonRoom(personRoom);
            }

            repo.SaveChanges();
        }
示例#3
0
 public void DeletePersonRoomPair(PersonRoom personRoom)
 {
     db.PersonRoom.Remove(personRoom);
 }
示例#4
0
 public void AddPersonRoom(PersonRoom pr)
 {
     db.PersonRoom.Add(pr);
 }
示例#5
0
        public void GenerateData()
        {
            var people = new Person[]
            {
                new Person {
                    Name = "Ivan Prokopenko", CardKey = "ewr1", CardValidTil = DateTime.Parse("24.03.2021")
                },
                new Person {
                    Name = "Ihor Karavaev", CardKey = "ewr2", CardValidTil = DateTime.Parse("24.03.2021")
                },
                new Person {
                    Name = "Potap Pavlenko", CardKey = "ewr3", CardValidTil = DateTime.Parse("24.03.2021")
                }

                /*
                 * new Person{Name = "Anna Melnyk", CardKey = "ewr4", CardValidTil=DateTime.Parse("24.03.2021")},
                 * new Person{Name = "Serhii Kyrylenko", CardKey = "ewr5", CardValidTil=DateTime.Parse("24.03.2021")},
                 * new Person{Name = "Anton Shevchenko", CardKey = "ewr6", CardValidTil=DateTime.Parse("24.03.2021")},
                 * new Person{Name = "Ivan Bondarenko", CardKey = "ewr7", CardValidTil=DateTime.Parse("24.03.2021")},
                 * new Person{Name = "Petro Koval", CardKey = "ewr8", CardValidTil=DateTime.Parse("24.03.2021")},
                 * new Person{Name = "Pavlo Shevchenko", CardKey = "ewr9", CardValidTil=DateTime.Parse("24.03.2021")},
                 * new Person{Name = "Ksenia Tkachuk", CardKey = "ewr10", CardValidTil=DateTime.Parse("24.03.2021")},
                 * new Person{Name = "Viktor Moroz", CardKey = "ewr11", CardValidTil=DateTime.Parse("24.03.2021")},
                 * new Person{Name = "Zlata Rudenko", CardKey = "ewr12", CardValidTil=DateTime.Parse("24.03.2021")},
                 * new Person{Name = "Andrii Prokopenko", CardKey = "ewr13", CardValidTil=DateTime.Parse("24.03.2021")},
                 * new Person{Name = "Oleksii Prokopenko", CardKey = "ewr14", CardValidTil=DateTime.Parse("24.03.2021")},
                 * new Person{Name = "Viktoria Tkach", CardKey = "ewr15", CardValidTil=DateTime.Parse("24.03.2021")}
                 */
            };

            repo.AddPeople(people);

            var rooms = new Room[]
            {
                new Room {
                    Name = "Main hall", Type = RoomType.Hall, Area = 500
                },
                new Room {
                    Name = "Room 2", Type = RoomType.Ordinary, Area = 134
                },
                new Room {
                    Name = "Room 3", Type = RoomType.Ordinary, Area = 138
                },
                new Room {
                    Name = "Room 4", Type = RoomType.Ordinary, Area = 114
                },
                new Room {
                    Name = "Room 5", Type = RoomType.Ordinary, Area = 185
                },
                new Room {
                    Name = "Room 6", Type = RoomType.Ordinary, Area = 147
                },
                new Room {
                    Name = "Kitchen", Type = RoomType.Ordinary, Area = 192
                },
                new Room {
                    Name = "Stockroom", Type = RoomType.Ordinary, Area = 212
                },
                new Room {
                    Name = "Security room", Type = RoomType.Ordinary, Area = 115
                },
                new Room {
                    Name = "Server room", Type = RoomType.Ordinary, Area = 121
                }
            };

            repo.AddRooms(rooms);

            var readers = new Reader[]
            {
                new Reader {
                    CurrentLoc = rooms[0], NextLoc = rooms[1]
                },
                new Reader {
                    CurrentLoc = rooms[0], NextLoc = rooms[2]
                },
                new Reader {
                    CurrentLoc = rooms[0], NextLoc = rooms[4]
                },
                new Reader {
                    CurrentLocId = null, NextLoc = rooms[0]
                },
                new Reader {
                    CurrentLoc = rooms[0], NextLoc = rooms[3]
                },
                new Reader {
                    CurrentLoc = rooms[1], NextLoc = rooms[6]
                },
                new Reader {
                    CurrentLoc = rooms[0], NextLoc = rooms[5]
                },
                new Reader {
                    CurrentLoc = rooms[5], NextLoc = rooms[7]
                },
                new Reader {
                    CurrentLoc = rooms[7], NextLoc = rooms[9]
                },
                new Reader {
                    CurrentLoc = rooms[7], NextLoc = rooms[8]
                },

                new Reader {
                    CurrentLoc = rooms[1], NextLoc = rooms[0]
                },
                new Reader {
                    CurrentLoc = rooms[2], NextLoc = rooms[0]
                },
                new Reader {
                    CurrentLoc = rooms[4], NextLoc = rooms[0]
                },
                new Reader {
                    CurrentLoc = rooms[0], NextLocId = null
                },
                new Reader {
                    CurrentLoc = rooms[3], NextLoc = rooms[0]
                },
                new Reader {
                    CurrentLoc = rooms[6], NextLoc = rooms[1]
                },
                new Reader {
                    CurrentLoc = rooms[5], NextLoc = rooms[0]
                },
                new Reader {
                    CurrentLoc = rooms[7], NextLoc = rooms[5]
                },
                new Reader {
                    CurrentLoc = rooms[9], NextLoc = rooms[7]
                },
                new Reader {
                    CurrentLoc = rooms[8], NextLoc = rooms[7]
                }
            };

            repo.AddReaders(readers);
            var personRoomPairs = new List <PersonRoom>();

            foreach (var person in people)
            {
                for (int i = 0; i < 7; i++)
                {
                    var pair = new PersonRoom(person.Id, rooms[i].Id);
                    personRoomPairs.Add(pair);
                }
            }
            personRoomPairs.Add(new PersonRoom(1, rooms[7].Id));
            personRoomPairs.Add(new PersonRoom(2, rooms[7].Id));
            personRoomPairs.Add(new PersonRoom(3, rooms[7].Id));
            personRoomPairs.Add(new PersonRoom(1, rooms[8].Id));
            personRoomPairs.Add(new PersonRoom(2, rooms[8].Id));
            personRoomPairs.Add(new PersonRoom(1, rooms[9].Id));
            repo.AddPersonRoomPairs(personRoomPairs);

            var relocations = new List <Relocation>();
            var rand        = new Random();


            foreach (var person in people)
            {
                var currentDate = DateTime.Now;
                currentDate = currentDate.AddDays(-7);
                int randMin;
                int randSec;
                for (int i = 0; i < 1; i++)
                {
                    string stringDate = currentDate.ToString("d");
                    randMin = rand.Next(1, 59);
                    randSec = rand.Next(1, 59);
                    relocations.Add(
                        new Relocation
                    {
                        FromLocId   = null,
                        ToLocId     = rooms[0].Id,
                        PersonId    = person.Id,
                        Success     = true,
                        DateAndTime = DateTime.Parse($"{stringDate} 10:{randMin}:{randSec}")
                    });

                    int secondRoomId = 0;
                    if (person.Id % 3 == 0)
                    {
                        secondRoomId = rooms[1].Id;
                    }
                    if (person.Id % 3 == 1)
                    {
                        secondRoomId = rooms[2].Id;
                    }
                    if (person.Id % 3 == 2)
                    {
                        secondRoomId = rooms[4].Id;
                    }
                    randMin = rand.Next(1, 59);
                    randSec = rand.Next(1, 59);
                    relocations.Add(
                        new Relocation
                    {
                        FromLocId   = rooms[0].Id,
                        ToLocId     = secondRoomId,
                        PersonId    = person.Id,
                        Success     = true,
                        DateAndTime = DateTime.Parse($"{stringDate} 11:{randMin}:{randSec}")
                    });

                    randMin = rand.Next(1, 59);
                    randSec = rand.Next(1, 59);
                    relocations.Add(
                        new Relocation
                    {
                        FromLocId   = secondRoomId,
                        ToLocId     = rooms[0].Id,
                        PersonId    = person.Id,
                        Success     = true,
                        DateAndTime = DateTime.Parse($"{stringDate} 12:{randMin}:{randSec}")
                    });

                    randMin = rand.Next(1, 59);
                    randSec = rand.Next(1, 59);
                    relocations.Add(
                        new Relocation
                    {
                        FromLocId   = rooms[0].Id,
                        ToLocId     = null,
                        PersonId    = person.Id,
                        Success     = true,
                        DateAndTime = DateTime.Parse($"{stringDate} 13:{randMin}:{randSec}")
                    });
                    currentDate = currentDate.AddDays(1);
                }
            }
            repo.AddRelocations(relocations);
        }
示例#6
0
        private void Add2DB(List <string> data)
        {
            //if (data.Count > 0)
            for (_i = 0; _i < data.Count; _i++)
            {
                _currentLine = data[_i];
                string[] item = _currentLine.Split(',');
                //string[] item = data[0].Split(',');
                if (IsEmpty(item, 7))
                {
                    continue;
                }

                CheckAllValue(item, 7);

                using (var context = new StreetContext())
                {
                    //街道

                    StreetUnit street = context.Streets.SingleOrDefault(s => s.Name == "徐家棚");

                    if (street == null)
                    {
                        street = new StreetUnit {
                            Name = "徐家棚"
                        };
                        context.Streets.Add(street);
                    }

                    //社区
                    var community = context.Communitys.SingleOrDefault(s => s.Name == item[0].Replace("社区", ""));
                    if (community == null)
                    {
                        //CheckValue(item,0);
                        community = new Community {
                            Name = item[0].Replace("社区", "")
                        };
                        community.Street = street;
                        //street.Communities.Add(community);
                        context.Communitys.Add(community);
                    }

                    //网格
                    var netGrid = context.NetGrids.SingleOrDefault(s => s.Community.Id == community.Id && s.Name == item[1].Replace("网格", ""));
                    if (netGrid == null)
                    {
                        // CheckValue(item, 1);
                        netGrid = new NetGrid {
                            Name = item[1].Replace("网格", "")
                        };
                        netGrid.Community = community;
                        context.NetGrids.Add(netGrid);
                    }


                    //小区
                    var subdivision = context.Subdivisions.SingleOrDefault(s => s.Name == item[3].Replace("小区", ""));
                    if (subdivision == null)
                    {
                        //CheckValue(item,3);
                        subdivision = new Subdivision {
                            Name = item[3].Replace("小区", "")
                        };
                        subdivision.Street = street;
                        context.Subdivisions.Add(subdivision);
                    }

                    //楼栋

                    //var building = netGrid.Buildings.SingleOrDefault(s => s.Name == item[4]);
                    var building = context.Buildings.SingleOrDefault(s => s.Subdivision.Id == subdivision.Id && s.Name == item[4].Replace("栋", ""));
                    if (building == null)
                    {
                        building = new Building
                        {
                            Name = item[4].Replace("栋", ""),
                            //房屋地址
                            Address = item[2],
                        };
                        building.NetGrid     = netGrid;
                        building.Subdivision = subdivision;
                        context.Buildings.Add(building);
                        //subdivision.Buildings.Add(building);
                    }

                    //房屋
                    string roomName = $"{item[5].Replace("单元", "")}-{item[6].Replace("号", "")}";
                    var    room     = context.Rooms.SingleOrDefault(r => r.Building.Id == building.Id && r.Name == roomName);
                    if (room == null)
                    {
                        room = new Room
                        {
                            Name     = roomName,
                            Category = item[7],
                            Use      = item[8],
                            Area     = item[10],
                            Other    = item[9],
                        };
                        room.Building = building;
                        context.Rooms.Add(room);
                    }

                    //单位信息
                    //  var companyinfo = new CompanyInfo { };
                    if (item[11] != "")
                    {
                        var companyinfo = new CompanyInfo
                        {
                            Name          = item[11],
                            Character     = item[12],
                            SocialId      = item[13],
                            ContactPerson = item[14],
                            PersonId      = item[15],
                            Phone         = item[16],
                            Area          = item[17]
                        };
                        companyinfo.Room = room;
                        context.CompanyInfos.Add(companyinfo);
                    }



                    //人
                    var person = context.Persons.SingleOrDefault(p => p.PersonId == item[20]);

                    //检测空名空身份证号
                    if (!CheckItem(item))
                    {
                        continue;
                    }
                    //检测同身份证号不同名
                    if (!CheckPerson(person, item))
                    {
                        continue;
                    }

                    if (person == null)
                    {
                        person = new Person
                        {
                            Name         = item[18],
                            EthnicGroups = item[19].Replace("族", ""),
                            PersonId     = item[20],
                            Phone        = item[21],
                            //户籍地址
                            DomicileAddress = item[22],

                            Company                = item[27],
                            PoliticalState         = item[28],
                            OrganizationalRelation = item[29],
                            IsOverseasChinese      = (item[30] == "是"),
                            MerriedStatus          = item[31],
                        };
                        // person.CompanyInfo = companyinfo;
                        context.Persons.Add(person);


                        //单位信息
                        //if (item[11] != "")
                        //{
                        //    var companyinfo = new CompanyInfo
                        //    {
                        //        Name = item[11],
                        //        Character = item[12],
                        //        SocialId = item[13],
                        //        ContactPerson = item[14],
                        //        PersonId = item[15],
                        //        Phone = item[16],
                        //        Area = item[17]
                        //    };
                        //    context.CompanyInfos.Add(companyinfo);
                        //}
                        //特殊人群

                        if (item[34] != "")
                        {
                            //var specialGroup = context.SpecialGroups.SingleOrDefault(s => s.PersonId == item[20]);
                            //if (specialGroup == null)
                            var specialGroup = new SpecialGroup {
                                PersonId = item[20], Type = item[34]
                            };
                            context.SpecialGroups.Add(specialGroup);
                        }

                        // 困难人群
                        if (item[35] != "")
                        {
                            var poorPeople = new PoorPeople
                            {
                                PersonId    = item[20],
                                Type        = item[35],
                                Child       = item[36],
                                Youngsters  = item[37],
                                SpecialHelp = item[38]
                            };
                            context.PoorPeoples.Add(poorPeople);
                        }
                        //服役状况
                        if (item[39] != "")
                        {
                            var militaryService = new MilitaryService {
                                PersonId = item[20], Type = item[39]
                            };
                            context.MilitaryService.Add(militaryService);
                        }

                        //残疾
                        //var disability = context.Disabilitys.SingleOrDefault(s => s.PersonId == item[20]);
                        //if (disability == null)
                        if (item[40] != "")
                        {
                            var disability = new Disability
                            {
                                PersonId = item[20],
                                Type     = item[40],
                                Class    = item[41],
                            };
                            context.Disability.Add(disability);
                        }

                        //其他信息
                        //var otherInfos = context.OtherInfos.SingleOrDefault(s => s.PersonId == item[20]);
                        // if (otherInfos == null)
                        if (item[42] != "")
                        {
                            var otherInfos = new OtherInfos
                            {
                                PersonId = item[20],
                                //Key = item[42],
                                Value = item[42],
                            };
                            context.OtherInfos.Add(otherInfos);
                        }
                    }
                    //personroom 人房信息
                    var personHouse = new PersonRoom
                    {
                        PersonId                = item[20],
                        IsHouseholder           = (item[23] == "是"),
                        RelationWithHouseholder = item[24],
                        IsOwner             = (item[25] == "是"),
                        IsLiveHere          = (item[26] == "是"),
                        PopulationCharacter = item[32],
                        LodgingReason       = item[33]
                    };

                    personHouse.Person = person;
                    personHouse.Room   = room;
                    context.PersonRooms.Add(personHouse);



                    context.SaveChanges();
                    _preItem = item;
                }
            }
            // tbInfo_err.Text = "";
            tbInfo.Text      = "Add personroomdata OK!";
            tbInfo_err.Text += _errorMessage;
        }