Пример #1
0
        public void InsertRowIntoManager(List<IPersonInfo> pInfoList)
        {
            SettledListModel settle;
            PropertyInfo[] propInfos;

            if (pInfoList != null)
            {
                using (DataBaseConnector dbService = new DataBaseConnector())
                {
                    propInfos = typeof(ISettledList).GetProperties();
                    foreach (var pInfo in pInfoList)
                    {
                        if (settledAllList==null)
                        {
                            settledAllList = new ObservableCollection<SettledListModel>();
                            List<ISettledList>  tempSettleList = dbService.GetAllRecords<ISettledList>();
                            foreach (var setUnit in tempSettleList)
                            {
                                settle = new SettledListModel();
                                foreach (var curPropt in propInfos)
                                {
                                    curPropt.SetValue(settle, curPropt.GetValue(setUnit));
                                }
                                /*IPersonInfo pi = dbService.GetPersonRecords(t=>t.UUID==settle.PersonUUID).First();
                                if (pi!=null)
                                {
                                    settle.FirstName = pi.FirstName;
                                    settle.LastName = pi.LastName;
                                    settle.Sex = pi.Sex;
                                }*/
                                IRoom room = dbService.GetRoomRecords(t => t.UUID == settle.RoomUUID).First();
                                if (room!=null)
                                {
                                    settle.RoomNumber = room.RoomNumber;
                                }
                                settledAllList.Add(settle);
                            }
                            if (oldSettleAllListKeeper == null)
                                oldSettleAllListKeeper = new BinaryFormatter();
                            if (ms == null)
                                ms = new MemoryStream();
                            else
                                ms.Position = 0;
                            oldSettleAllListKeeper.Serialize(ms, settledAllList);
                        }
                        List<SettledListModel> curSettleList = settledAllList.Where(t => t.PersonUUID == pInfo.UUID).ToList<SettledListModel>();
                        if (curSettleList.Count > 1)
                        {
                            MessageBox.Show("Невозможно добавить строку в менеджер поселения");
                        }
                        else
                        {

                            if (curSettleList.Count == 1)
                            {
                                settle = curSettleList[0];
                                settle.FirstName = pInfo.FirstName;
                                settle.LastName = pInfo.LastName;
                                settle.Sex = pInfo.Sex;
                            }
                            else
                            {
                                settle = new SettledListModel();
                                settle.UUID = Guid.NewGuid().ToString();
                                settle.PersonUUID = pInfo.UUID;
                                settle.FirstName = pInfo.FirstName;
                                settle.LastName = pInfo.LastName;
                                settle.Sex = pInfo.Sex;
                            }
                            ManagerList.Add(settle);
                        }
                    }
                }
            }
        }
 //public void RefreshButton_Click(object sender, RoutedEventArgs e)
 public void RefreshButton_Click()
 {
     using (DataBaseConnector dbService = new DataBaseConnector())
     {
         List<ISettledList> tempSettledList = new List<ISettledList>();
         List<IRoom> tempRoomList = new List<IRoom>();
         foreach (var dbPer in Habitants)
         {
             bool foundf = false;
             tempSettledList = dbService.GetSettledListRecords(t => t.PersonUUID == dbPer.UUID).ToList();
             if (tempSettledList.Count > 0)
             {
                 string roomUUID = tempSettledList[0].RoomUUID;
                 tempRoomList = dbService.GetRoomRecords(t => t.UUID == roomUUID).ToList();
                 if (tempRoomList.Count > 0)
                 {
                     dbPer.RoomNumber = tempRoomList[0].RoomNumber;
                     dbPer.SettledDate = tempSettledList[0].SettledDate;
                     foundf = true;
                 }
             }
             if (foundf==false)
             {
                 dbPer.RoomNumber = "";
                 dbPer.SettledDate = DateTime.MinValue;
             }
         }
     }
 }