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 Button_Click(object sender, RoutedEventArgs e) { if (IsDataInputValid()) { object worker = parentWindow.ZooConnection.CreateModel(ModelType.Worker); 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.AddModel(worker)) { 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()) { object attraction = parentWindow.ZooConnection.CreateModel(ModelType.Attraction); 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.AddModel(attraction)) { MessageBox.Show("[ERROR] Cannot add new worker to database, check log for detailed cause."); DialogResult = false; } else { DialogResult = true; } Close(); } }
void ButtonRemoveAnimal_Click(object sender, RoutedEventArgs e) { if (dataGridAnimals.SelectedItem != null) { int id = ((AnimalView)dataGridAnimals.SelectedItem).ID; new Thread(() => { Tuple <bool, byte> status = ZooConnection.DeleteModel(ModelType.Animal, id); if (status == null) { MessageBox.Show("[ERROR] Cannot remove animal from Zoo, server connection error!"); } else if (!status.Item1) { MessageBox.Show(ZooClient.DecodeDeleteError(status.Item2)); } else { UpdateAnimals(); UpdateFoods(); } }).Start(); } }
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(); } }
void ButtonRemoveWorker_Click(object sender, RoutedEventArgs e) { if (dataGridWorkers.SelectedItem != null) { int id = ((WorkerView)dataGridWorkers.SelectedItem).ID; new Thread(() => { Tuple <bool, byte> status = ZooConnection.DeleteModel(ModelType.Worker, id); if (status == null) { MessageBox.Show("[ERROR] Cannot delete worker, server connection error!"); } else if (!status.Item1) { MessageBox.Show(ZooClient.DecodeDeleteError(status.Item2)); } else { UpdateOvertimes(); UpdateWorkers(); } }).Start(); } }
/// <summary> /// 从ZooKeeper获取字节数组数据 /// </summary> /// <param name="path"></param> /// <returns></returns> public byte[] GetBytesData(string path) { byte[] bytes = ZooClient.getDataAsync(path).Result.Data; return(bytes); }
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 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 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(); } } }
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 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 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); } }
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 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); } }
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 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 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 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(); }