private void btnAdd_Click(object sender, RoutedEventArgs e) { try { MyDbContext context = new MyDbContext(); ProvidersController providersController = new ProvidersController(); Provider provider = new Provider(NameProvider.Text, Telephone.Text); if (providersController.AddProvider(provider)) { MessageBox.Show("Поставщик успешно добавлен."); ProviderDataGrid.ClearValue(ItemsControl.ItemsSourceProperty); List <Provider> providers = context.Providers.ToList(); ProviderDataGrid.ItemsSource = providers; } else { MessageBox.Show("Этот поставщик уже был добавлен или введенные данные имеют неверный формат."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void BtnPdfProvider_Click(object sender, RoutedEventArgs e) { var document = ProviderDataGrid.ExportToPdf(new PdfExportingOptions() { AutoColumnWidth = true, AutoRowHeight = true, ExcludeColumns = new List <string>() { "Id", "Password" } }); GeneratePDF(document); }
private void AccesoriesDataGrid_RowValidating(object sender, RowValidatingEventArgs args) { if (ProviderDataGrid.IsAddNewIndex(args.RowIndex)) { var accesory = args.RowData as Accessory; var error = getManager.Accessory.Validate(accesory); if (error.Count > 0) { args.IsValid = false; foreach (var item in error) { args.ErrorMessages.Add(item.Key, item.Value); } } } }
private void btnUpdate_Click(object sender, RoutedEventArgs e) { if (Telephone.Text.Length < 13) { try { context.SaveChanges(); ProviderDataGrid.ClearValue(ItemsControl.ItemsSourceProperty); List <Provider> providers = context.Providers.ToList(); ProviderDataGrid.ItemsSource = providers; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Превышен диапазон"); } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { try { MyDbContext context = new MyDbContext(); ProvidersController providersController = new ProvidersController(); Provider provider = ProviderDataGrid.SelectedItem as Provider; if (ProviderDataGrid.SelectedItem != null) { context.Providers.Attach(provider); providersController.RemoveProvider(provider); MessageBox.Show("Поставшик успешно удален."); } ProviderDataGrid.ClearValue(ItemsControl.ItemsSourceProperty); List <Provider> providers = context.Providers.ToList(); ProviderDataGrid.ItemsSource = providers; } catch (Exception ex) { MessageBox.Show(ex.Message); } }