public void GetAllRooms() { using (DataBaseConnector dbService = new DataBaseConnector()) { if (RoomList != null) { RoomList = dbService.GetAllRecords<IRoom>(); } } }
private void FullFillDBWithFurniture() { IRoomFurniture roomfurn; List<IRoom> rooms = new List<IRoom>(); using (DataBaseConnector dbService = new DataBaseConnector()) { rooms = dbService.GetAllRecords<IRoom>(); foreach ( var room in rooms) { roomfurn = new RoomFurnitureDBModel(); roomfurn.UUID = Guid.NewGuid().ToString(); roomfurn.RoomUUID = room.UUID; roomfurn.FurnitureUnit = "Кровать"; roomfurn.Quantity = 2; dbService.HandleRoomFurnituresTable(roomfurn,null,RecordActions.Inserted); roomfurn.UUID = Guid.NewGuid().ToString(); roomfurn.FurnitureUnit = "Стул"; roomfurn.Quantity = 2; dbService.HandleRoomFurnituresTable(roomfurn, null, RecordActions.Inserted); roomfurn.UUID = Guid.NewGuid().ToString(); roomfurn.FurnitureUnit = "Стол"; roomfurn.Quantity = 1; dbService.HandleRoomFurnituresTable(roomfurn, null, RecordActions.Inserted); roomfurn.UUID = Guid.NewGuid().ToString(); roomfurn.FurnitureUnit = "Шкаф"; roomfurn.Quantity = 2; dbService.HandleRoomFurnituresTable(roomfurn, null, RecordActions.Inserted); roomfurn.UUID = Guid.NewGuid().ToString(); roomfurn.FurnitureUnit = "Полочка"; roomfurn.Quantity = 3; dbService.HandleRoomFurnituresTable(roomfurn, null, RecordActions.Inserted); } dbService.SaveChanges(); } }
private void LoginWin_onKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { //FullFillDBWithRooms(); //FullFillDBWithFurniture(); try { using (DataBaseConnector dbService = new DataBaseConnector(5)) { PersonInfoModel viewPerson; IRoom dbRoom; List<IRoom> tempRoomList = new List<IRoom>(); PersonInfoListView hb = new PersonInfoListView(); ObservableCollection<PersonInfoModel> viewPersons = new ObservableCollection<PersonInfoModel>(); List<IPersonInfo> dbPersons = dbService.GetAllRecords<IPersonInfo>(); List<IRoom> dbRoomList = dbService.GetAllRecords<IRoom>(); PropertyInfo[] propInfos = typeof(IPersonInfo).GetProperties(); foreach (var dbPer in dbPersons) { viewPerson = new PersonInfoModel(); foreach (var curPropt in propInfos) { curPropt.SetValue(viewPerson, curPropt.GetValue(dbPer)); } tempRoomList = dbRoomList.Where(t => t.UUID == viewPerson.RoomUUID).ToList(); if (tempRoomList.Count>0) { dbRoom = tempRoomList[0]; viewPerson.RoomNumber = dbRoom.RoomNumber; } viewPersons.Add(viewPerson); } PersonInfoListViewModel hbViewModel = new PersonInfoListViewModel(viewPersons); hb.NewButton.Click += hbViewModel.NewButton_Click; hb.ManagerButton.Click += hbViewModel.ManagerButton_Click; hb.SchemeButton.Click += hbViewModel.SchemeButton_Click; hb.Redirect_HabitantsGridRow_DoubleClick += hbViewModel.Row_DoubleClick; hb.Redirect_HabitantsGridRow_MouseLeftButtonDown += hbViewModel.Row_MouseLeftButtonDown; hb.DataContext = hbViewModel; hb.Show(); } } catch (SqlException ex) { MessageBox.Show(ex.Message); } finally { this.Close(); } } }
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); } } } } }