EditPriceCoefficient.xaml.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using esoft.Class;
  2. using esoft.Entities;
  3. using System;
  4. using System.CodeDom.Compiler;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Net.NetworkInformation;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace esoft.Pages
  20. {
  21. /// <summary>
  22. /// Логика взаимодействия для EditPriceCoefficient.xaml
  23. /// </summary>
  24. public partial class EditPriceCoefficient : Page
  25. {
  26. ActualContext actualContext = new ActualContext();
  27. public EditPriceCoefficient()
  28. {
  29. InitializeComponent();
  30. FillForm();
  31. }
  32. private void FillForm()
  33. {
  34. List<User> usersManager = actualContext.Users.Where(user => actualContext.Manager.Any(manager => manager.ID == user.ID)).ToList(); // Получение списка менеджеров
  35. cbManager.ItemsSource = UserInFIO.GroupUser(usersManager);
  36. }
  37. private void BtnSaveSalaryCoeff_Click(object sender, RoutedEventArgs e)
  38. {
  39. try
  40. {
  41. // Получаем значения из элементов интерфейса
  42. int managerId = (int)(cbManager.SelectedItem as ComboBoxItem)?.Tag;
  43. int juniorMin = (int)IUDJuniorMin.Value;
  44. int middleMin = (int)IUDMiddleMin.Value;
  45. int seniorMin = (int)IUDSeniorMin.Value;
  46. double analysisCoeff = (double)IUDAnalysisCoefficient.Value;
  47. double installationCoeff = (double)IUDInstallationCoefficient.Value;
  48. double supportCoeff = (double)IUDSupportCoefficient.Value;
  49. double timeCoeff = (double)IUDTimeCoefficient.Value;
  50. double difficultyCoeff = (double)IUDDifficultyCoefficient.Value;
  51. double toMoneyCoeff = (double)IUDToMoneyCoefficient.Value;
  52. // Обновляем коэффициенты менеджера
  53. UpdateManagerCoefficients(managerId, juniorMin, middleMin, seniorMin, analysisCoeff, installationCoeff, supportCoeff, timeCoeff, difficultyCoeff, toMoneyCoeff);
  54. MessageBox.Show("Коэффициенты сохранены успешно!");
  55. }
  56. catch (Exception ex)
  57. {
  58. MessageBox.Show($"Ошибка при сохранении коэффициентов: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
  59. }
  60. }
  61. public void UpdateManagerCoefficients(int managerId, int juniorMin, int middleMin, int seniorMin, double analysisCoeff, double installationCoeff, double supportCoeff, double timeCoeff, double difficultyCoeff, double toMoneyCoeff)
  62. {
  63. try
  64. {
  65. // Получаем контекст базы данных и находим менеджера по ID
  66. var context = esoftEntities.GetContext();
  67. {
  68. Manager targetManager = context.Manager.FirstOrDefault(m => m.ID == managerId);
  69. if (targetManager != null)
  70. {
  71. // Обновляем значения коэффициентов менеджера
  72. targetManager.JuniorMinimum = juniorMin;
  73. targetManager.MiddleMinimum = middleMin;
  74. targetManager.SeniorMinimum = seniorMin;
  75. targetManager.AnalysisCoefficient = analysisCoeff;
  76. targetManager.InstallationCoefficient = installationCoeff;
  77. targetManager.SupportCoefficient = supportCoeff;
  78. targetManager.TimeCoefficient = timeCoeff;
  79. targetManager.DifficultyCoefficient = difficultyCoeff;
  80. targetManager.ToMoneyCoefficient = toMoneyCoeff;
  81. // Сохраняем изменения в базе данных
  82. context.SaveChanges();
  83. }
  84. else
  85. {
  86. MessageBox.Show("Менеджер не найден!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
  87. }
  88. }
  89. }
  90. catch (Exception ex)
  91. {
  92. MessageBox.Show($"Ошибка обновления коэффициентов: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
  93. }
  94. }
  95. }
  96. }