AddRegistration.xaml.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.Shapes;
  14. namespace Learn
  15. {
  16. /// <summary>
  17. /// Логика взаимодействия для AddRegistration.xaml
  18. /// </summary>
  19. public partial class AddRegistration : Window
  20. {
  21. Entities DB = new Entities();
  22. ClientService cs = new ClientService();
  23. int ServId = 0;
  24. public AddRegistration()
  25. {
  26. InitializeComponent();
  27. }
  28. public AddRegistration(int id)
  29. {
  30. InitializeComponent();
  31. ServId = id;
  32. ServName.Text = DB.Service.Where(x => x.ID == id).Select(x => x.Title).First();
  33. Duration.Text = (DB.Service.Where(x => x.ID == id).Select(x => x.DurationInSeconds).First() / 60).ToString();
  34. List<string> clients = new List<string>();
  35. foreach (Client c in DB.Client)
  36. {
  37. clients.Add($"{c.LastName} {c.FirstName} {c.Patronymic}");
  38. }
  39. Client.ItemsSource = clients;
  40. }
  41. private void MakeReg(object sender, RoutedEventArgs e)
  42. {
  43. cs.ClientID = Client.SelectedIndex + 1;
  44. cs.ServiceID = ServId;
  45. DateTime tm = Convert.ToDateTime(TimeServ.Text);
  46. DateTime DateReg = new DateTime(DateServ.SelectedDate.Value.Year, DateServ.SelectedDate.Value.Month, DateServ.SelectedDate.Value.Day, tm.Hour, tm.Minute, tm.Second);
  47. cs.StartTime = DateReg;
  48. DB.ClientService.Add(cs);
  49. DB.SaveChanges();
  50. MessageBox.Show("Запись сделана");
  51. this.Close();
  52. }
  53. }
  54. }