private async void Delete_Click(object sender, RoutedEventArgs e) { if (workersList.SelectedItem != null) { ContentDialog deleteFileDialog = new ContentDialog() { Title = "Подтверждение действия", Content = "Вы действительно хотите удалить работника?", PrimaryButtonText = "ОК", SecondaryButtonText = "Отмена" }; ContentDialogResult result = await deleteFileDialog.ShowAsync(); if (result == ContentDialogResult.Primary) { if (workersList.SelectedItem != null) { Worker worker = workersList.SelectedItem as Worker; if (worker != null) { using (MobileContext db = new MobileContext()) { db.Workers.Remove(worker); db.SaveChanges(); workersList.ItemsSource = db.Workers.ToList(); } } } } else if (result == ContentDialogResult.Secondary) { } } }
private async void Save_Click(object sender, RoutedEventArgs e) { try { using (MobileContext db = new MobileContext()) { if (worker != null) { if (worker.hours > 144) { worker.name = nameBox.Text; worker.family = familyBox.Text; worker.hours = Convert.ToDouble(hoursBox.Text); worker.Tariff = Convert.ToDouble(tarifBox.Text); zpp = worker.hours - 144; worker.salary = (144 * worker.Tariff) + (zpp * (worker.Tariff) * 2); worker.salaryw = worker.salary * 0.87; db.Workers.Update(worker); var itsok = new MessageDialog("Информация изменена!"); await itsok.ShowAsync(); } else { worker.name = nameBox.Text; worker.family = familyBox.Text; worker.hours = Convert.ToDouble(hoursBox.Text); worker.Tariff = Convert.ToDouble(tarifBox.Text); worker.salary = worker.hours * worker.Tariff; worker.salaryw = worker.salary * 0.87; db.Workers.Update(worker); var itsok = new MessageDialog("Информация изменена!"); await itsok.ShowAsync(); } } else { double tar = Convert.ToDouble(tarifBox.Text); double or = Convert.ToDouble(hoursBox.Text); if (or > 144) { zpp = or - 144; double salary = (144 * tar) + ((zpp * tar) * 2); double salaryw = salary * 0.87; double lol = salaryw; db.Workers.Add(new Worker { name = nameBox.Text, family = familyBox.Text, hours = Convert.ToDouble(hoursBox.Text), Tariff = Convert.ToDouble(tarifBox.Text), salary = salary, salaryw = lol }); var itsok = new MessageDialog("Информация сохранена!"); await itsok.ShowAsync(); } else { double z = Convert.ToDouble(hoursBox.Text); double p = Convert.ToDouble(tarifBox.Text); double zp0 = z * p; double zp = (z * p) * 0.87; db.Workers.Add(new Worker { name = nameBox.Text, family = familyBox.Text, hours = Convert.ToDouble(hoursBox.Text), Tariff = Convert.ToDouble(tarifBox.Text), salary = zp0, salaryw = zp }); var itsok = new MessageDialog("Информация сохранена!"); await itsok.ShowAsync(); } } db.SaveChanges(); } GoToMainPage(); } catch (FormatException) { var dialog = new MessageDialog("Неверные данные"); await dialog.ShowAsync(); } }