Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- namespace SimpleWpfAppEDM
- {
- public partial class MainWindow : Window
- {
- ObservableCollection<Card> cards;
- public MainWindow()
- {
- InitializeComponent();
- //загрузка данных
- using (var context = new AutoLotEntities())
- {
- var query = from card in context.Card
- select card;
- if (query.Count() != 0)
- {
- cards = new ObservableCollection<Card>();
- foreach (var c in query)
- cards.Add(c);
- lvCard.ItemsSource = cards;
- }
- }
- }
- //кнопка загрузки
- private void BtLoad_Click(object sender, RoutedEventArgs e)
- { }
- //кнопка добавить
- private void BTAdd_Click(object sender, RoutedEventArgs e)
- {
- Card newCard = new Card();
- EditCardView editCard = new EditCardView();
- editCard.Title = "Добавление данных карты";
- editCard.DataContext = newCard;
- editCard.ShowDialog();
- if (editCard.DialogResult == true)
- {
- using (var context = new AutoLotEntities())
- {
- try
- {
- context.Card.Add(newCard);
- context.SaveChanges();
- cards.Add(newCard);
- }
- catch (Exception ex)
- {
- MessageBox.Show("\nОшибка добавления данных!\n" + ex.Message,
- "Предупреждение");
- }
- }
- }
- }
- //кнопка редактировать
- private void BtEdit_Click(object sender, RoutedEventArgs e)
- {
- Card editCard = (Card)lvCard.SelectedItem;
- EditCardView editCardView = new EditCardView();
- editCardView.Title = "Редактироание данных карты";
- editCardView.DataContext = editCard;
- editCardView.ShowDialog();
- if (editCardView.DialogResult == true)
- {
- using (var context = new AutoLotEntities())
- {
- try
- {
- Card card = context.Card.Find(editCard.Id);
- if (card.Make != editCard.Make)
- card.Make = editCard.Make.Trim();
- if (card.GB != editCard.GB)
- card.GB = editCard.GB.Trim();
- context.SaveChanges();
- }
- catch (Exception ex)
- {
- MessageBox.Show("\nОшибка редактирования данных!\n" + ex.Message,
- "Предупреждение");
- }
- }
- }
- }
- //кнопка удалить
- private void BtDelete_Click(object sender, RoutedEventArgs e)
- {
- Card delCard = (Card)lvCard.SelectedItem;
- using (var context = new AutoLotEntities())
- {
- try {
- Card delcard = context.Card.Find(delCard.Id);
- if (delcard != null)
- {
- MessageBoxResult result = MessageBox.Show("Удалить карту: \nПроизводитель: " + delCard.Make + "\nGB: " + delCard.GB, "Предупреждение", MessageBoxButton.OKCancel);
- if (result == MessageBoxResult.OK)
- {
- context.Card.Remove(delcard);
- context.SaveChanges();
- cards.Remove(delCard);
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("\nОшибка удаления данных!\n" + ex.Message, "Предупреждение");
- }
- }
- }
- private void lvCard_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- }
- }
- }
- System.Windows.Data Error: 40 : BindingExpression path error: 'Color' property not found on 'object' ''Card' (HashCode=17513507)'. BindingExpression:Path=Color; DataItem='Card' (HashCode=17513507); target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
- System.Windows.Data Error: 40 : BindingExpression path error: 'Color' property not found on 'object' ''Card' (HashCode=17513507)'. BindingExpression:Path=Color; DataItem='Card' (HashCode=17513507); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
- The program '[7828] SimpleWpfAppEDM.exe' has exited with code 0 (0x0).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement