AddServiseWin.xaml.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace ServiceDEMO.Win
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для AddServiseWin.xaml
  20. /// </summary>
  21. public partial class AddServiseWin : Window
  22. {
  23. Goiman_A_AEntities1 db = new Goiman_A_AEntities1 ();
  24. public AddServiseWin()
  25. {
  26. InitializeComponent();
  27. }
  28. public string path = "";
  29. public List<string> pathList = new List<string>();
  30. private void AddImageB_Click(object sender, RoutedEventArgs e)
  31. {
  32. OpenFileDialog ofd = new OpenFileDialog();
  33. ofd.Multiselect = true;
  34. if (ofd.ShowDialog() == true)
  35. {
  36. for (int i = 0; i <ofd.FileName.Count(); i++)
  37. {
  38. pathList.Add("\\Услуги школы\\" + ofd.SafeFileNames[i]);
  39. File.Copy(ofd.FileNames[i], Environment.CurrentDirectory + "\\Услуги школы\\Дополнительные фото\\" + ofd.SafeFileNames[i], true);
  40. }
  41. }
  42. }
  43. private void AddServiseB_Click(object sender, RoutedEventArgs e)
  44. {
  45. if (Decimal.TryParse(tb_Cost.Text, out decimal cost) && int.TryParse(tb_Duration.Text, out int duration)
  46. && Double.TryParse(tb_Discount.Text, out double discount))
  47. {
  48. Service entity = new Service
  49. {
  50. Title = tb_Name.Text,
  51. Cost = cost,
  52. DurationInSeconds = duration,
  53. Description = tb_Discription.Text,
  54. Discount = discount,
  55. MainImagePath = path
  56. };
  57. db.Service.Add(entity);
  58. db.SaveChanges();
  59. MessageBox.Show("Alert");
  60. }
  61. else
  62. {
  63. MessageBox.Show("Mega Alert");
  64. }
  65. }
  66. }
  67. }