MainWindow.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace WPF_Entity_Examole
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для MainWindow.xaml
  19. /// </summary>
  20. public partial class MainWindow : Window
  21. {
  22. gr671_mkyuEntities db;
  23. public MainWindow()
  24. {
  25. InitializeComponent();
  26. }
  27. private void InsertClick_Click(object sender, RoutedEventArgs e)
  28. {
  29. Call call = new Call();
  30. call.DateCall = Convert.ToDateTime(txtFirst.Text);
  31. call.LongCall = Convert.ToInt32(txtLast.Text);
  32. call.IdUser = Convert.ToInt32(txtUser.Text);
  33. call.IdLead = Convert.ToInt32(txtLead.Text);
  34. db.Call.Add(call);
  35. db.SaveChanges();
  36. dgogrenci.ItemsSource = db.Call.ToList();
  37. }
  38. private void DeleteClick_Click(object sender, RoutedEventArgs e)
  39. {
  40. int num = (dgogrenci.SelectedItem as Call).IdCall;
  41. var dRow = db.Call.Where(w => w.IdCall == num).FirstOrDefault();
  42. db.Call.Remove(dRow);
  43. db.SaveChanges();
  44. dgogrenci.ItemsSource = db.Call.ToList();
  45. }
  46. private void UpdateClick_Click(object sender, RoutedEventArgs e)
  47. {
  48. int num = (dgogrenci.SelectedItem as Call).IdCall;
  49. var uRow = db.Call.Where(w => w.IdCall == num).FirstOrDefault();
  50. // uRow.Firstname = txtFist.Text;
  51. // uRow.LastName = txtLast.Text;
  52. db.SaveChanges();
  53. dgogrenci.ItemsSource = db.Call.ToList();
  54. }
  55. private void Dgogrenci_Loaded(object sender, RoutedEventArgs e)
  56. {
  57. db = new gr671_mkyuEntities();
  58. dgogrenci.ItemsSource = db.Call.ToList();
  59. }
  60. }
  61. }