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 SaveButton_Click(object sender, RoutedEventArgs e) { PersonInfoModel pInfo = (PersonInfoModel)this.DataContext; if (String.IsNullOrEmpty(pInfo.FirstName)) { MessageBox.Show("Укажите имя"); return; } if (String.IsNullOrEmpty(pInfo.LastName)) { MessageBox.Show("Укажите фамилию"); return; } if (String.IsNullOrEmpty(pInfo.Sex)) { MessageBox.Show("Укажите пол"); return; } using (DataBaseConnector dbService = new DataBaseConnector()) { bool savef = false; if (pInfo != null && pInfo.ViewModelStatus == RecordActions.Inserted) { pInfo.UUID = Guid.NewGuid().ToString(); dbService.HandlePersonInfoTable(pInfo, null, RecordActions.Inserted); savef = true; } else if (pInfo != null && pInfo.ViewModelStatus == RecordActions.Updated) { dbService.HandlePersonInfoTable(pInfo, t => (t.UUID == pInfo.UUID), RecordActions.Updated); savef = true; } if (pInfo.Payments != null && pInfo.Payments.Count > 0) { foreach (var payment in pInfo.Payments) { if (String.IsNullOrEmpty(payment.PersonUUID) == true) { payment.PersonUUID = pInfo.UUID; payment.UUID = Guid.NewGuid().ToString(); payment.ViewModelStatus = RecordActions.Inserted; } if (payment.ViewModelStatus == RecordActions.Inserted) dbService.HandlePersonPaymentsTable(payment, null, RecordActions.Inserted); else if (payment.ViewModelStatus == RecordActions.Updated) dbService.HandlePersonPaymentsTable(payment, t => (t.UUID == payment.UUID), RecordActions.Updated); } if (removedPayments.Count>0) { foreach (var payment in removedPayments) { if (String.IsNullOrEmpty(payment.UUID) == false) { dbService.HandlePersonPaymentsTable(payment, t => (t.UUID == payment.UUID), RecordActions.Deleted); } } removedPayments = new List<PersonPaymentsModel>(); } savef = true; } if (savef==true) { int result = dbService.SaveChanges(); if (result > 0) { if (ParentListView != null) ParentListView.UpdatePersonList(pInfo, pInfo.ViewModelStatus); InitialOperations(); ms.Position = 0; oldContextKeeper.Serialize(ms, pInfo); } } } }
private void DeleteButton_Click(object sender, RoutedEventArgs e) { PersonInfoModel pInfo = (PersonInfoModel)this.DataContext; using (DataBaseConnector dbService = new DataBaseConnector()) { dbService.HandlePersonInfoTable(pInfo, t => (t.UUID == pInfo.UUID), RecordActions.Deleted); if (pInfo.Payments != null && pInfo.Payments.Count > 0) { foreach (var payment in pInfo.Payments) { dbService.HandlePersonPaymentsTable(payment, t => (t.UUID == payment.UUID), RecordActions.Deleted); } if (removedPayments.Count > 0) { foreach (var payment in removedPayments) { dbService.HandlePersonPaymentsTable(payment, t => (t.UUID == payment.UUID), RecordActions.Deleted); } removedPayments = new List<PersonPaymentsModel>(); } } int result = dbService.SaveChanges(); if (result > 0) { if (ParentListView!=null) ParentListView.UpdatePersonList(pInfo, RecordActions.Deleted); this.Close(); } } }
private void FullFillDBWithRooms() { IRoom room = new RoomDBModel();; using (DataBaseConnector dbService = new DataBaseConnector()) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 12; j++) { room.UUID = Guid.NewGuid().ToString(); room.RoomNumber = (i + 1) + "-" + (j + 1); dbService.HandleRoomsTable(room, null, RecordActions.Inserted); } } dbService.SaveChanges(); } }
public void UnSettleButton_Click(object sender, RoutedEventArgs e) { if (sender.GetType() != typeof(DataGrid)) { MessageBox.Show("Невозможно определить список"); return; } var dg = sender as DataGrid; if (dg == null) { MessageBox.Show("Невозможно определить список"); return; } else { var toUnSettleList = dg.Items.OfType<SettledListModel>(); int count = 0; using (DataBaseConnector dbService = new DataBaseConnector()) { ObservableCollection<SettledListModel> settledAllListForChecks = new ObservableCollection<SettledListModel>(); if (ms != null) { ms.Position = 0; settledAllListForChecks = (ObservableCollection<SettledListModel>)oldSettleAllListKeeper.Deserialize(ms); } bool savef = false; foreach (var row in toUnSettleList) { if (String.IsNullOrEmpty(row.RoomUUID) == false) row.ViewModelStatus = RecordActions.Deleted; //checks if (row.ViewModelStatus == RecordActions.Deleted) { SettledListModel tempSettle = settledAllListForChecks.Where(t => t.UUID == row.UUID).FirstOrDefault(); if (tempSettle != null) tempSettle = row; else { MessageBox.Show("Нельзя выселить. Неопредленная запись"); MakeDataGridRowFocused(dg, count); return; } if (String.IsNullOrEmpty(row.UUID)) { MessageBox.Show("Нельзя выселить. Неопредленная запись"); MakeDataGridRowFocused(dg, count); return; } row.RoomNumber = ""; row.SettledDate = DateTime.MinValue; row.RoomUUID = ""; dbService.HandleSettledListTable(row, t => (t.UUID == row.UUID), RecordActions.Deleted); settledAllListForChecks.Remove(row); savef = true; } count++; } if (savef) { //MessageBox.Show("Saved"); int result = dbService.SaveChanges(); if (result > 0) { ms.Position = 0; settledAllList = settledAllListForChecks; oldSettleAllListKeeper.Serialize(ms, settledAllList); if (OnSettledListViewModelChanged != null) OnSettledListViewModelChanged(this, new EventArgs()); } else MessageBox.Show("Люди не выселены"); } } } }
public void SettleButton_Click(object sender, RoutedEventArgs e) { if (sender.GetType() != typeof(DataGrid)) { MessageBox.Show("Невозможно определить список"); return; } var dg = sender as DataGrid; if (dg == null) { MessageBox.Show("Невозможно определить список"); return; } else { var toSettleList = dg.Items.OfType<SettledListModel>(); int count = 0; using (DataBaseConnector dbService = new DataBaseConnector()) { ObservableCollection<SettledListModel> settledAllListForChecks = new ObservableCollection<SettledListModel>(); if (ms!=null) { ms.Position = 0; settledAllListForChecks = (ObservableCollection<SettledListModel>)oldSettleAllListKeeper.Deserialize(ms); } bool savef = false; foreach (var row in toSettleList) { if (String.IsNullOrEmpty(row.RoomNumber)) { MessageBox.Show("Укажите комнату"); MakeDataGridRowFocused(dg, count); return; } string newRoomUUID = ""; try { newRoomUUID = RoomList.Where(t => t.RoomNumber == row.RoomNumber).First().UUID; } catch(NullReferenceException nullEx) { MessageBox.Show("Такого номера команты нет в базе данных"); return; } if (String.IsNullOrEmpty(row.RoomUUID)==false && row.RoomUUID != newRoomUUID) row.ViewModelStatus = RecordActions.Updated; else if (String.IsNullOrEmpty(row.RoomUUID)) row.ViewModelStatus = RecordActions.Inserted; //checks if (row.ViewModelStatus == RecordActions.Inserted || row.ViewModelStatus == RecordActions.Updated) { SettledListModel tempSettle = settledAllListForChecks.Where(t => t.UUID == row.UUID).FirstOrDefault(); if (tempSettle != null) tempSettle = row; else settledAllListForChecks.Add(row); if (settledAllListForChecks.Where(t => t.RoomNumber == row.RoomNumber).Count() > 4) { MessageBox.Show("В комнате " + row.RoomNumber + " теперь больше четырех человек"); MakeDataGridRowFocused(dg, count); return; } string roomSex = settledAllListForChecks.Where(t => t.RoomNumber == row.RoomNumber && t.PersonUUID != row.PersonUUID).Select(t => t.Sex).Distinct().ElementAtOrDefault(0); if (String.IsNullOrEmpty(roomSex)==false && roomSex!=row.Sex) { MessageBox.Show("В одной команте не могут быть жители разного пола"); MakeDataGridRowFocused(dg, count); return; } if (settledAllListForChecks.Where(t => t.PersonUUID == row.PersonUUID).Count() > 1) { MessageBox.Show("Человек селится больше, чем в одну комнату"); MakeDataGridRowFocused(dg, count); return; } row.SettledDate = DateTime.Now; if (String.IsNullOrEmpty(row.UUID)) row.UUID = Guid.NewGuid().ToString(); row.RoomUUID = newRoomUUID; dbService.HandleSettledListTable(row, t => (t.UUID == row.UUID), row.ViewModelStatus); List<IPersonInfo> persons = dbService.GetPersonRecords(t=>t.UUID==row.PersonUUID); if (persons!=null) { IPersonInfo person = persons[0]; person.RoomUUID = row.RoomUUID; dbService.HandlePersonInfoTable(person,t=>t.UUID==person.UUID,RecordActions.Updated); } else { MessageBox.Show("Невозможно найти человека"); return; } savef = true; } count++; } if (savef) { //MessageBox.Show("Saved"); int result = dbService.SaveChanges(); if (result > 0) { ms.Position = 0; settledAllList = settledAllListForChecks; oldSettleAllListKeeper.Serialize(ms, settledAllList); if (OnSettledListViewModelChanged != null) OnSettledListViewModelChanged(this, new EventArgs()); } else MessageBox.Show("Люди не заселены"); } } } }