void UpdateCashBalances() { new Thread(() => { IEnumerable <CashBalanceView> source; lock (BalanceTypes) { BalanceTypes = ZooConnection.GetModels(ModelType.BalanceType); lock (cashBalances) { cashBalances = ZooConnection.GetModels(ModelType.CashBalance); source = cashBalances.Join(BalanceTypes, balance => ZooClient.GetProperty(balance, "BalanceTypeID"), type => ZooClient.GetProperty(type, "ID"), (balance, type) => new CashBalanceView() { ID = (int)ZooClient.GetProperty(balance, "ID"), SubmitDate = (DateTime)ZooClient.GetProperty(balance, "SubmitDate"), Money = (decimal)ZooClient.GetProperty(balance, "Money"), Type = (string)ZooClient.GetProperty(type, "Description"), DetailedDescription = (string)ZooClient.GetProperty(balance, "DetailedDescription") }); } } dataGridCashBalances.Dispatcher.Invoke(() => { dataGridCashBalances.ItemsSource = source.OrderByDescending(balance => balance.SubmitDate); }); }).Start(); }
void UpdateFoods(int?foodId = null) { new Thread(() => { IEnumerable <object> filtered; lock (Foods) { Foods = ZooConnection.GetModels(ModelType.Food); if (foodId.HasValue) { filtered = Foods.Where(food => (int)ZooClient.GetProperty(food, "ID") == foodId.Value); } else { filtered = Foods; } } dataGridFoods.Dispatcher.Invoke(() => { buttonModifyFood.IsEnabled = false; buttonRemoveFood.IsEnabled = false; dataGridFoods.ItemsSource = filtered; labelFoodsCount.Content = filtered.Sum(food => (double)ZooClient.GetProperty(food, "Amount")).ToString(); }); }).Start(); }
void UpdateOvertimes(int?workerId = null) { new Thread(() => { IEnumerable <object> filtered; lock (overtimes) { overtimes = ZooConnection.GetModels(ModelType.Overtime); if (workerId.HasValue) { filtered = overtimes.Where(overtime => (int)ZooClient.GetProperty(overtime, "WorkerID") == workerId.Value); } else { filtered = overtimes; } lock (workers) { filtered = filtered.Join(workers, overtime => ZooClient.GetProperty(overtime, "WorkerID"), worker => ZooClient.GetProperty(worker, "ID"), (overtime, worker) => CreateOvertimeView(overtime, worker)); } } dataGridOvertimes.Dispatcher.Invoke(() => { dataGridOvertimes.ItemsSource = filtered; }); }).Start(); }
public ModifyAnimalWindow(MainWindow parent, object selectedAnimal) { InitializeComponent(); if (selectedAnimal == null) { Logger.LogWarning("Error selecting animal to modify, process terminated.", GetType(), "ModifyAnimalWindow(parent: MainWindow, selectedAnimal: null)"); Close(); } animal = selectedAnimal; parentWindow = parent; textBoxName.Text = (string)ZooClient.GetProperty(animal, "Name"); textBoxCount.Text = ((int)ZooClient.GetProperty(animal, "Count")).ToString(); textBoxCost.Text = ((decimal)ZooClient.GetProperty(animal, "MaintenanceCost")).ToString(); dataGridPlaces.DataContext = parentWindow.ZooConnection.GetModelType(ModelType.Place); lock (parentWindow.Places) { dataGridPlaces.ItemsSource = parentWindow.Places; int id = (int)ZooClient.GetProperty(animal, "PlaceID"); dataGridPlaces.SelectedItem = parentWindow.Places.FirstOrDefault(place => (int)ZooClient.GetProperty(place, "ID") == id); } dataGridFoods.DataContext = parentWindow.ZooConnection.GetModelType(ModelType.Food); lock (parentWindow.Foods) { dataGridFoods.ItemsSource = parentWindow.Foods; int id = (int)ZooClient.GetProperty(animal, "FoodID"); dataGridFoods.SelectedItem = parentWindow.Foods.FirstOrDefault(food => (int)ZooClient.GetProperty(food, "ID") == id); } }
OvertimeView CreateOvertimeView(object overtime, object worker) { return(new OvertimeView() { ID = (int)ZooClient.GetProperty(overtime, "ID"), Date = (DateTime)ZooClient.GetProperty(overtime, "Date"), Hours = (int)ZooClient.GetProperty(overtime, "Hours"), PaymentPercentage = (int)ZooClient.GetProperty(overtime, "PaymentPercentage"), Employee = (string)ZooClient.GetProperty(worker, "Name") + " " + (string)ZooClient.GetProperty(worker, "Surname") }); }
void DataGridPlaces_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (dataGridPlaces.SelectedItem != null) { buttonModifyPlace.IsEnabled = true; buttonRemovePlace.IsEnabled = true; dataGridPlacesShouldClear = false; DataGridAttractions_SelectionChanged(sender, e); UpdateAttractions((int)ZooClient.GetProperty(dataGridPlaces.SelectedItem, "ID")); } }
public ModifyFoodWindow(MainWindow parent, object selectedFood) { InitializeComponent(); if (selectedFood == null) { Logger.LogWarning("Error selecting food to modify, process terminated.", GetType(), "ModifyFoodWindow(parent: MainWindow, selectedFood: null)"); Close(); } food = selectedFood; parentWindow = parent; textBoxName.Text = (string)ZooClient.GetProperty(food, "Name"); textBoxAmount.Text = ((double)ZooClient.GetProperty(food, "Amount")).ToString(); }
void UpdateAttractions(int?placeId = null) { new Thread(() => { IEnumerable <AttractionView> source; lock (attractions) { attractions = ZooConnection.GetModels(ModelType.Attraction); IEnumerable <object> filtered; if (placeId.HasValue) { filtered = attractions.Where(attraction => (int)ZooClient.GetProperty(attraction, "PlaceID") == placeId.Value); } else { filtered = attractions; } lock (Places) lock (workers) { source = filtered.Join(Places, attraction => ZooClient.GetProperty(attraction, "PlaceID"), place => ZooClient.GetProperty(place, "ID"), (attraction, place) => new { ID = (int)ZooClient.GetProperty(attraction, "ID"), Name = (string)ZooClient.GetProperty(attraction, "Name"), Description = (string)ZooClient.GetProperty(attraction, "Description"), AttractionManagerID = (int)ZooClient.GetProperty(attraction, "AttractionManagerID"), Place = (string)ZooClient.GetProperty(place, "Name") }).Join(workers, anon => ZooClient.GetProperty(anon, "AttractionManagerID"), worker => ZooClient.GetProperty(worker, "ID"), (anon, worker) => new AttractionView() { ID = anon.ID, Name = anon.Name, Description = anon.Description, AttractionManager = (string)ZooClient.GetProperty(worker, "Name") + " " + (string)ZooClient.GetProperty(worker, "Surname"), Place = anon.Place }); } dataGridAttractions.Dispatcher.Invoke(() => { buttonModifyAttraction.IsEnabled = false; buttonRemoveAttraction.IsEnabled = false; dataGridAttractions.ItemsSource = source; labelAttractionsCount.Content = source.Count(); }); } }).Start(); }
void DataGridAnimals_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (dataGridAnimals.SelectedItem != null) { buttonModifyAnimal.IsEnabled = true; buttonRemoveAnimal.IsEnabled = true; dataGridAnimalsShouldClear = false; DataGridFoods_SelectionChanged(sender, e); int id = (int)ZooClient.GetProperty(dataGridAnimals.SelectedItem, "ID"); int foodId = 0; lock (animals) foodId = (int)ZooClient.GetProperty(animals.FirstOrDefault(animal => (int)ZooClient.GetProperty(animal, "ID") == id), "FoodID"); UpdateFoods(foodId); } }
public ModifyPlaceWindow(MainWindow parent, object selectedPlace) { InitializeComponent(); if (selectedPlace == null) { Logger.LogWarning("Error selecting place to modify, process terminated.", GetType(), "ModifyPlaceWindow(parent: MainWindow, selectedPlace: null)"); Close(); } place = selectedPlace; parentWindow = parent; textBoxName.Text = (string)ZooClient.GetProperty(place, "Name"); timePickerOpen.Value = System.DateTime.Now.Date + ((System.TimeSpan)ZooClient.GetProperty(place, "OpenTime")); timePickerClose.Value = System.DateTime.Now.Date + ((System.TimeSpan)ZooClient.GetProperty(place, "CloseTime")); textBoxCost.Text = ((decimal)ZooClient.GetProperty(place, "MaintenanceCost")).ToString(); }
void ButtonModifyAttraction_Click(object sender, RoutedEventArgs e) { if (dataGridAttractions.SelectedItem != null) { object attraction = null; lock (attractions) attraction = attractions.SingleOrDefault(a => (int)ZooClient.GetProperty(a, "ID") == (int)ZooClient.GetProperty(dataGridAttractions.SelectedItem, "ID")); ModifyAttractionWindow modifyAttractionWindow = new ModifyAttractionWindow(this, attraction); bool?isModified = modifyAttractionWindow.ShowDialog(); if (isModified.HasValue && isModified.Value) { UpdateAttractions(); } } }
void ButtonModifyFoodCount_Click(object sender, RoutedEventArgs e) { if (dataGridFoods.SelectedItem != null) { object food = null; lock (Foods) food = Foods.SingleOrDefault(f => (int)ZooClient.GetProperty(f, "ID") == (int)ZooClient.GetProperty(dataGridFoods.SelectedItem, "ID")); ModifyFoodWindow modifyFoodWindow = new ModifyFoodWindow(this, food); bool? isModified = modifyFoodWindow.ShowDialog(); if (isModified.HasValue && isModified.Value) { UpdateFoods(); } } }
void ButtonModifyAnimal_Click(object sender, RoutedEventArgs e) { if (dataGridAnimals.SelectedItem != null) { object animal = null; lock (animals) animal = animals.SingleOrDefault(a => (int)ZooClient.GetProperty(a, "ID") == ((AnimalView)dataGridAnimals.SelectedItem).ID); ModifyAnimalWindow modifyAnimalWindow = new ModifyAnimalWindow(this, animal); bool?isModified = modifyAnimalWindow.ShowDialog(); if (isModified.HasValue && isModified.Value) { UpdateAnimals(); UpdateFoods(); } } }
void ButtonModifyWorker_Click(object sender, RoutedEventArgs e) { if (dataGridWorkers.SelectedItem != null) { object worker = null; lock (workers) worker = workers.SingleOrDefault(w => (int)ZooClient.GetProperty(w, "ID") == ((WorkerView)dataGridWorkers.SelectedItem).ID); ModifyWorkerWindow modifyWorkerWindow = new ModifyWorkerWindow(this, worker); bool?isModified = modifyWorkerWindow.ShowDialog(); if (isModified.HasValue && isModified.Value) { UpdateWorkers(); UpdateOvertimes(); } } }
void ButtonModifyPlace_Click(object sender, RoutedEventArgs e) { if (dataGridPlaces.SelectedItem != null) { object place = null; lock (Places) place = Places.SingleOrDefault(p => (int)ZooClient.GetProperty(p, "ID") == (int)ZooClient.GetProperty(dataGridPlaces.SelectedItem, "ID")); ModifyPlaceWindow modifyPlaceWindow = new ModifyPlaceWindow(this, place); bool?isModified = modifyPlaceWindow.ShowDialog(); if (isModified.HasValue && isModified.Value) { UpdatePlaces(); UpdateAttractions(); } } }
public IEnumerable <WorkerView> GetWorkerViews() { lock (Places) { return(workers.Join(Places, worker => ZooClient.GetProperty(worker, "PlaceID"), place => ZooClient.GetProperty(place, "ID"), (worker, place) => new WorkerView() { ID = (int)ZooClient.GetProperty(worker, "ID"), Surname = (string)ZooClient.GetProperty(worker, "Surname"), Name = (string)ZooClient.GetProperty(worker, "Name"), Age = (int)ZooClient.GetProperty(worker, "Age"), Salary = (decimal)ZooClient.GetProperty(worker, "Salary"), StartDate = (DateTime)ZooClient.GetProperty(worker, "StartDate"), Place = (string)ZooClient.GetProperty(place, "Name") })); } }
void UpdateAnimals() { new Thread(() => { IEnumerable <AnimalView> source; lock (animals) { animals = ZooConnection.GetModels(ModelType.Animal); lock (Places) lock (Foods) { source = animals.Join(Places, animal => ZooClient.GetProperty(animal, "PlaceID"), place => ZooClient.GetProperty(place, "ID"), (animal, place) => new { ID = (int)ZooClient.GetProperty(animal, "ID"), Name = (string)ZooClient.GetProperty(animal, "Name"), Count = (int)ZooClient.GetProperty(animal, "Count"), MaintenanceCost = (decimal)ZooClient.GetProperty(animal, "MaintenanceCost"), Place = (string)ZooClient.GetProperty(place, "Name"), FoodID = (int)ZooClient.GetProperty(animal, "FoodID") }).Join(Foods, anon => ZooClient.GetProperty(anon, "FoodID"), food => ZooClient.GetProperty(food, "ID"), (anon, food) => new AnimalView() { ID = anon.ID, Name = anon.Name, Count = anon.Count, MaintenanceCost = anon.MaintenanceCost, Place = anon.Place, Food = (string)ZooClient.GetProperty(food, "Name") }); } } dataGridAnimals.Dispatcher.Invoke(() => { buttonModifyAnimal.IsEnabled = false; buttonRemoveAnimal.IsEnabled = false; dataGridAnimals.ItemsSource = source; labelAnimalSpeciesCount.Content = source.Count().ToString(); labelAnimalsCount.Content = source.Sum(animal => animal.Count).ToString(); }); }).Start(); }
void Button_Click(object sender, RoutedEventArgs e) { if(IsDataInputValid()) { object operation = parentWindow.ZooConnection.CreateModel(ModelType.CashBalance); ZooClient.SetProperty(operation, "SubmitDate", datePickerSubmit.SelectedDate); ZooClient.SetProperty(operation, "Money", decimal.Parse(textBoxMoney.Text)); ZooClient.SetProperty(operation, "BalanceTypeID", ZooClient.GetProperty(dataGridTypes.SelectedItem, "ID")); if (string.IsNullOrWhiteSpace(textBoxDescription.Text)) ZooClient.SetProperty(operation, "DetailedDescription", textBoxDescription.Text); if (!parentWindow.ZooConnection.AddModel(operation)) { MessageBox.Show("[ERROR] Cannot add new finance operation to database, check log for detailed cause."); DialogResult = false; } else DialogResult = true; Close(); } }
public ModifyAttractionWindow(MainWindow parent, object selectedAttraction) { InitializeComponent(); if (selectedAttraction == null) { Logger.LogWarning("Error selecting attraction to modify, process terminated.", GetType(), "ModifyAttractionWindow(parent: MainWindow, selectedAttraction: null)"); Close(); } attraction = selectedAttraction; parentWindow = parent; dataGridPlaces.DataContext = parentWindow.ZooConnection.GetModelType(ModelType.Place); lock (parentWindow.Places) { dataGridPlaces.ItemsSource = parentWindow.Places; int id = (int)ZooClient.GetProperty(attraction, "PlaceID"); dataGridPlaces.SelectedItem = parentWindow.Places.FirstOrDefault(place => (int)ZooClient.GetProperty(place, "ID") == id); } textBoxName.Text = (string)ZooClient.GetProperty(attraction, "Name"); textBoxDescription.Text = (string)ZooClient.GetProperty(attraction, "Description"); }
void Button_Click(object sender, RoutedEventArgs e) { if (IsDataInputValid()) { ZooClient.SetProperty(animal, "Name", textBoxName.Text); ZooClient.SetProperty(animal, "Count", int.Parse(textBoxCount.Text)); ZooClient.SetProperty(animal, "MaintenanceCost", decimal.Parse(textBoxCost.Text)); ZooClient.SetProperty(animal, "PlaceID", ZooClient.GetProperty(dataGridPlaces.SelectedItem, "ID")); ZooClient.SetProperty(animal, "FoodID", ZooClient.GetProperty(dataGridFoods.SelectedItem, "ID")); if (!parentWindow.ZooConnection.ModifyModel(animal)) { MessageBox.Show("[ERROR] Cannot add new animal to database, check log for detailed cause."); DialogResult = false; } else { DialogResult = true; } Close(); } }
void Button_Click(object sender, RoutedEventArgs e) { if (IsDataInputValid()) { ZooClient.SetProperty(attraction, "Name", textBoxName.Text); if (!string.IsNullOrWhiteSpace(textBoxDescription.Text)) { ZooClient.SetProperty(attraction, "Description", textBoxDescription.Text); } ZooClient.SetProperty(attraction, "PlaceID", ZooClient.GetProperty(dataGridPlaces.SelectedItem, "ID")); if (!parentWindow.ZooConnection.ModifyModel(attraction)) { MessageBox.Show("[ERROR] Cannot add new worker to database, check log for detailed cause."); DialogResult = false; } else { DialogResult = true; } Close(); } }
void Button_Click(object sender, RoutedEventArgs e) { if (IsDataInputValid()) { ZooClient.SetProperty(worker, "Surname", textBoxSurname.Text); ZooClient.SetProperty(worker, "Name", textBoxName.Text); ZooClient.SetProperty(worker, "Age", int.Parse(textBoxAge.Text)); ZooClient.SetProperty(worker, "Salary", decimal.Parse(textBoxSalary.Text)); ZooClient.SetProperty(worker, "StartDate", datePickerStartDate.SelectedDate); ZooClient.SetProperty(worker, "PlaceID", ZooClient.GetProperty(dataGridPlaces.SelectedItem, "ID")); if (!parentWindow.ZooConnection.ModifyModel(worker)) { MessageBox.Show("[ERROR] Cannot modify worker, check log for detailed cause."); DialogResult = false; } else { DialogResult = true; } Close(); } }
public ModifyWorkerWindow(MainWindow parent, object selectedWorker) { InitializeComponent(); if (selectedWorker == null) { Logger.LogWarning("Error selecting worker to modify, process terminated.", GetType(), "ModifyWorkerWindow(parent: MainWindow, selectedWorker: null)"); Close(); } worker = selectedWorker; parentWindow = parent; dataGridPlaces.DataContext = parentWindow.ZooConnection.GetModelType(ModelType.Place); lock (parentWindow.Places) { dataGridPlaces.ItemsSource = parentWindow.Places; int id = (int)ZooClient.GetProperty(worker, "PlaceID"); dataGridPlaces.SelectedItem = parentWindow.Places.FirstOrDefault(place => (int)ZooClient.GetProperty(place, "ID") == id); } textBoxSurname.Text = (string)ZooClient.GetProperty(worker, "Surname"); textBoxName.Text = (string)ZooClient.GetProperty(worker, "Name"); textBoxAge.Text = ((int)ZooClient.GetProperty(worker, "Age")).ToString(); textBoxSalary.Text = ((decimal)ZooClient.GetProperty(worker, "Salary")).ToString(); datePickerStartDate.SelectedDate = (DateTime)ZooClient.GetProperty(worker, "StartDate"); }
void ButtonRemoveAttraction_Click(object sender, RoutedEventArgs e) { if (dataGridAttractions.SelectedItem != null) { int id = (int)ZooClient.GetProperty(dataGridAttractions.SelectedItem, "ID"); new Thread(() => { Tuple <bool, byte> status = ZooConnection.DeleteModel(ModelType.Attraction, id); if (status == null) { MessageBox.Show("[ERROR] Cannot remove attraction from Zoo, server connection error!"); } else if (!status.Item1) { MessageBox.Show(ZooClient.DecodeDeleteError(status.Item2)); } else { UpdatePlaces(); UpdateAttractions(); } }).Start(); } }