Преглед изворни кода

Настройка отображения и редактирование коэффициентов ЗП

Данилов Денис пре 1 година
родитељ
комит
e4487f3327

+ 52 - 0
esoft/Class/CoefficientFill.cs

@@ -0,0 +1,52 @@
+using esoft.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+
+namespace esoft.Class
+{
+    /// <summary>
+    /// Класс для заполнения коэффицентов
+    /// </summary>
+    public class CoefficientFill : Manager
+    {
+        public static CoefficientFill CoefficientFills(int managerId)
+        {
+            try
+            {
+                ActualContext actualContext = new ActualContext();
+                var manager = esoftEntities.GetContext().Manager
+                    .FirstOrDefault(m => m.ID == managerId);
+
+                if (manager != null)
+                {
+                    return new CoefficientFill
+                    {
+                        ID = manager.ID,
+                        JuniorMinimum = manager.JuniorMinimum,
+                        MiddleMinimum = manager.MiddleMinimum,
+                        SeniorMinimum = manager.SeniorMinimum,
+                        AnalysisCoefficient = manager.AnalysisCoefficient,
+                        InstallationCoefficient = manager.InstallationCoefficient,
+                        SupportCoefficient = manager.SupportCoefficient,
+                        TimeCoefficient = manager.TimeCoefficient,
+                        DifficultyCoefficient = manager.DifficultyCoefficient,
+                        ToMoneyCoefficient = manager.ToMoneyCoefficient,
+                        // Добавьте остальные свойства, если необходимо
+                    };
+                }
+            }
+            catch
+            {
+                MessageBox.Show("Ошибка при заполнении коэффициентов",
+                    "Ошибка",
+                    MessageBoxButton.OK,
+                    MessageBoxImage.Error);
+            }
+
+            return null;
+        }
+    }
+}

+ 0 - 1
esoft/Class/ExecuterFill.cs

@@ -39,7 +39,6 @@ namespace esoft.Class
             get { return fioUser; }
             set { fioUser = value; }
         }
-
         public string FioManager
         {
             get { return fioManager; }

+ 1 - 1
esoft/Class/GetCurrentUser.cs

@@ -11,4 +11,4 @@ namespace esoft.Class
     {
         public static User CurrentUser { get; set; }
     }
-}
+}

+ 1 - 1
esoft/Entities/Manager.cs

@@ -35,4 +35,4 @@ namespace esoft.Entities
         public virtual ICollection<Executor> Executor { get; set; }
         public virtual User User { get; set; }
     }
-}
+}

+ 0 - 1
esoft/Pages/AddEditServicePage.xaml.cs

@@ -12,7 +12,6 @@ namespace esoft.Pages
     public partial class AddEditServicePage : Page
     {
         ActualContext actualContext = new ActualContext();
-        TaskFill tasks = new TaskFill();
         List<TaskFill> taskContext = new List<TaskFill>();
         private TaskFill selectedTask;
         private bool isEditing = false;

+ 0 - 4
esoft/Pages/AddExecutorPage.xaml.cs

@@ -24,10 +24,6 @@ namespace esoft.Pages
     /// </summary>
     public partial class AddExecutorPage : Page
     {
-        ActualContext actualContext = new ActualContext();
-        ExecuterFill executor = new ExecuterFill();
-        List<ExecuterFill> executorContext = new List<ExecuterFill>();
-        List<TaskFill> taskFill;
         List<TaskFill> taskContext = new List<TaskFill>();
         private ExecuterFill selectedExecutor;
         private bool isEditing = false;

+ 9 - 9
esoft/Pages/EditPriceCoefficient.xaml

@@ -53,42 +53,42 @@
                         <Separator Width="50" Background="{x:Null}"/>
                         <TextBlock Style="{StaticResource BlockCommon}" Text="Коэффициент анализа:" FontSize="40"/>
                         <Separator Width="79" Background="{x:Null}"/>
-                        <xctk:IntegerUpDown x:Name="IUDAnalysisCoefficient" Width="375" Height="40" FontSize="29"/>
+                        <TextBox x:Name="TBoxAnalysisCoefficient" Width="375" Height="40" FontSize="29"/>
                     </StackPanel>
                     <Separator Height="10" Background="{x:Null}" />
                     <StackPanel Orientation="Horizontal" Width="1000" HorizontalAlignment = "Left">
                         <Separator Width="50" Background="{x:Null}"/>
                         <TextBlock Style="{StaticResource BlockCommon}" Text="Коэффициент установки:" FontSize="40"/>
                         <Separator Width="41" Background="{x:Null}"/>
-                        <xctk:IntegerUpDown x:Name="IUDInstallationCoefficient" Width="375" Height="40" FontSize="29"/>
+                        <TextBox x:Name="TBoxInstallationCoefficient" Width="375" Height="40" FontSize="29"/>
                     </StackPanel>
                     <Separator Height="10" Background="{x:Null}" />
                     <StackPanel Orientation="Horizontal" Width="1000" HorizontalAlignment = "Left">
                         <Separator Width="50" Background="{x:Null}"/>
                         <TextBlock Style="{StaticResource BlockCommon}" Text="Коэффициент поддержки:" FontSize="40"/>
                         <Separator Width="19" Background="{x:Null}"/>
-                        <xctk:IntegerUpDown x:Name="IUDSupportCoefficient" Width="375" Height="40" FontSize="29"/>
+                        <TextBox x:Name="TBoxSupportCoefficient" Width="375" Height="40" FontSize="29"/>
                     </StackPanel>
                     <Separator Height="10" Background="{x:Null}" />
                     <StackPanel Orientation="Horizontal" Width="1000" HorizontalAlignment = "Left">
                         <Separator Width="50" Background="{x:Null}"/>
                         <TextBlock Style="{StaticResource BlockCommon}" Text="Временной коэффициент:" FontSize="40"/>
                         <Separator Width="21" Background="{x:Null}"/>
-                        <xctk:IntegerUpDown x:Name="IUDTimeCoefficient" Width="375" Height="40" FontSize="29"/>
+                        <TextBox x:Name="TBoxTimeCoefficient" Width="375" Height="40" FontSize="29"/>
                     </StackPanel>
                     <Separator Height="10" Background="{x:Null}" />
                     <StackPanel Orientation="Horizontal" Width="1000" HorizontalAlignment = "Left">
                         <Separator Width="50" Background="{x:Null}"/>
                         <TextBlock Style="{StaticResource BlockCommon}" Text="Коэфициент сложности:" FontSize="40"/>
                         <Separator Width="57" Background="{x:Null}"/>
-                        <xctk:IntegerUpDown x:Name="IUDDifficultyCoefficient" Width="375" Height="40" FontSize="29"/>
+                        <TextBox x:Name="TBoxDifficultyCoefficient" Width="375" Height="40" FontSize="29"/>
                     </StackPanel>
                     <Separator Height="10" Background="{x:Null}"/>
                     <StackPanel Orientation="Horizontal" Width="1000" HorizontalAlignment = "Left">
                         <Separator Width="50" Background="{x:Null}"/>
                         <TextBlock Style="{StaticResource BlockCommon}" Text="Денежный коэффициент:" FontSize="40"/>
                         <Separator Width="33" Background="{x:Null}"/>
-                        <xctk:IntegerUpDown x:Name="IUDToMoneyCoefficient" Width="375" Height="40" FontSize="29"/>
+                        <TextBox x:Name="TBoxToMoneyCoefficient" Width="375" Height="40" FontSize="29"/>
                     </StackPanel>
                 </StackPanel>
 
@@ -106,9 +106,9 @@
                         </Button.Style>
                     </Button>
                     <Separator Width="70" Background="{x:Null}"/>
-                    <TextBlock Style="{StaticResource BlockCommon}" Text="Итого заработная плата составляет:" FontSize="40" FontWeight="Bold" TextWrapping="Wrap" Width="360"/>
-                    <Separator Width="40" Background="{x:Null}"/>
-                    <TextBlock x:Name="TBlockTotalSalary" Style="{DynamicResource Header}" Text="{Binding TotalSalary}" Width="475"/>
+                    <TextBlock Style="{StaticResource BlockCommon}" Text="Итого заработная плата составляет:" FontSize="35" FontWeight="Bold" TextWrapping="Wrap" Width="650"/>
+                    <TextBlock x:Name="TBlockTotalSalary" Style="{DynamicResource Header}" Width="150" TextWrapping="Wrap" FontSize="40"/>
+                    <TextBlock Style="{StaticResource BlockCommon}" Text="₽" FontWeight="Bold" TextWrapping="Wrap" Width="650" FontSize="40"/>
                 </StackPanel>
             </StackPanel>
         </StackPanel>

+ 87 - 50
esoft/Pages/EditPriceCoefficient.xaml.cs

@@ -25,80 +25,117 @@ namespace esoft.Pages
     public partial class EditPriceCoefficient : Page
     {
         ActualContext actualContext = new ActualContext();
+        List<CoefficientFill> coefficientContext = new List<CoefficientFill>();
+        private CoefficientFill selectedCoefficient;
+        private ExecuterFill selectedExecuter;
+        private bool isEditing = false;
 
-        public EditPriceCoefficient()
+        public EditPriceCoefficient(ExecuterFill executer)
         {
             InitializeComponent();
+            selectedExecuter = executer;
+            if (selectedExecuter.ManagerID != 0)  // Используйте 0, если ID имеет тип int
+            {
+                isEditing = true;
+            }
             FillForm();
         }
 
         private void FillForm()
         {
-            List<User> usersManager = actualContext.Users.Where(user => actualContext.Manager.Any(manager => manager.ID == user.ID)).ToList(); // Получение списка менеджеров
-            cbManager.ItemsSource = UserInFIO.GroupUser(usersManager);
-        }
+            selectedCoefficient = CoefficientFill.CoefficientFills(selectedExecuter.ManagerID);
 
-        private void BtnSaveSalaryCoeff_Click(object sender, RoutedEventArgs e)
-        {
-            try
+            if (isEditing && selectedCoefficient != null)
             {
-                // Получаем значения из элементов интерфейса
-                int managerId = (int)(cbManager.SelectedItem as ComboBoxItem)?.Tag;
-                int juniorMin = (int)IUDJuniorMin.Value;
-                int middleMin = (int)IUDMiddleMin.Value;
-                int seniorMin = (int)IUDSeniorMin.Value;
-                double analysisCoeff = (double)IUDAnalysisCoefficient.Value;
-                double installationCoeff = (double)IUDInstallationCoefficient.Value;
-                double supportCoeff = (double)IUDSupportCoefficient.Value;
-                double timeCoeff = (double)IUDTimeCoefficient.Value;
-                double difficultyCoeff = (double)IUDDifficultyCoefficient.Value;
-                double toMoneyCoeff = (double)IUDToMoneyCoefficient.Value;
+                try
+                {
+                    // Получаем всех пользователей, которых связывает ID
+                    var usersManager = actualContext.Users.Where(user => actualContext.Manager
+                        .Any(manager => selectedCoefficient.ID == user.ID)).ToList();
+                    cbManager.ItemsSource = UserInFIO.GroupUser(usersManager);
+                    cbManager.SelectedItem = UserInFIO.SoloUser(usersManager
+                        .FirstOrDefault(u => u.ID == selectedCoefficient.ID));
 
-                // Обновляем коэффициенты менеджера
-                UpdateManagerCoefficients(managerId, juniorMin, middleMin, seniorMin, analysisCoeff, installationCoeff, supportCoeff, timeCoeff, difficultyCoeff, toMoneyCoeff);
-                MessageBox.Show("Коэффициенты сохранены успешно!");
-            }
-            catch (Exception ex)
-            {
-                MessageBox.Show($"Ошибка при сохранении коэффициентов: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+
+                    // Заполняем остальные поля формы
+                    IUDJuniorMin.Value = selectedCoefficient.JuniorMinimum;
+                    IUDMiddleMin.Value = selectedCoefficient.MiddleMinimum;
+                    IUDSeniorMin.Value = selectedCoefficient.SeniorMinimum;
+                    TBoxAnalysisCoefficient.Text = selectedCoefficient.AnalysisCoefficient.ToString();
+                    TBoxInstallationCoefficient.Text = selectedCoefficient.InstallationCoefficient.ToString();
+                    TBoxSupportCoefficient.Text = selectedCoefficient.SupportCoefficient.ToString();
+                    TBoxTimeCoefficient.Text = selectedCoefficient.TimeCoefficient.ToString();
+                    TBoxDifficultyCoefficient.Text = selectedCoefficient.DifficultyCoefficient.ToString();
+                    TBoxToMoneyCoefficient.Text = selectedCoefficient.ToMoneyCoefficient.ToString();
+
+                    if (selectedExecuter.Grade == "junior")
+                    {
+                        TBlockTotalSalary.Text = selectedCoefficient.JuniorMinimum.ToString();
+                    }
+                    else if (selectedExecuter.Grade == "middle")
+                    {
+                        TBlockTotalSalary.Text = selectedCoefficient.MiddleMinimum.ToString();
+                    }
+                    else if (selectedExecuter.Grade == "senior")
+                    {
+                        TBlockTotalSalary.Text = selectedCoefficient.SeniorMinimum.ToString();
+                    }
+                }
+                catch (Exception ex)
+                {
+                    MessageBox.Show($"Ошибка при заполнении формы: {ex.Message}",
+                                    "Ошибка",
+                                    MessageBoxButton.OK,
+                                    MessageBoxImage.Error);
+                }
             }
         }
 
-        public void UpdateManagerCoefficients(int managerId, int juniorMin, int middleMin, int seniorMin, double analysisCoeff, double installationCoeff, double supportCoeff, double timeCoeff, double difficultyCoeff, double toMoneyCoeff)
+        private void BtnSaveSalaryCoeff_Click(object sender, RoutedEventArgs e)
         {
             try
             {
-                // Получаем контекст базы данных и находим менеджера по ID
+                // Создаем экземпляр контекста данных
+                ActualContext actualContext = new ActualContext();
                 var context = esoftEntities.GetContext();
-                {
-                    Manager targetManager = context.Manager.FirstOrDefault(m => m.ID == managerId);
 
-                    if (targetManager != null)
-                    {
-                        // Обновляем значения коэффициентов менеджера
-                        targetManager.JuniorMinimum = juniorMin;
-                        targetManager.MiddleMinimum = middleMin;
-                        targetManager.SeniorMinimum = seniorMin;
-                        targetManager.AnalysisCoefficient = analysisCoeff;
-                        targetManager.InstallationCoefficient = installationCoeff;
-                        targetManager.SupportCoefficient = supportCoeff;
-                        targetManager.TimeCoefficient = timeCoeff;
-                        targetManager.DifficultyCoefficient = difficultyCoeff;
-                        targetManager.ToMoneyCoefficient = toMoneyCoeff;
+                // Получаем значения из элементов управления
+                int juniorMinimum = (int)IUDJuniorMin.Value;
+                int middleMinimum = (int)IUDMiddleMin.Value;
+                int seniorMinimum = (int)IUDSeniorMin.Value;
+                double analysisCoefficient = double.Parse(TBoxAnalysisCoefficient.Text);
+                double installationCoefficient = double.Parse(TBoxInstallationCoefficient.Text);
+                double supportCoefficient = double.Parse(TBoxSupportCoefficient.Text);
+                double timeCoefficient = double.Parse(TBoxTimeCoefficient.Text);
+                double difficultyCoefficient = double.Parse(TBoxDifficultyCoefficient.Text);
+                double toMoneyCoefficient = double.Parse(TBoxToMoneyCoefficient.Text);
 
-                        // Сохраняем изменения в базе данных
-                        context.SaveChanges();
-                    }
-                    else
-                    {
-                        MessageBox.Show("Менеджер не найден!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
-                    }
+                var existingCoefficient = context.Manager.FirstOrDefault(t => t.ID == selectedCoefficient.ID);
+
+                // Присваиваем свойствам объекта значения из элементов управления
+                existingCoefficient.JuniorMinimum = juniorMinimum;
+                existingCoefficient.MiddleMinimum = middleMinimum;
+                existingCoefficient.SeniorMinimum = seniorMinimum;
+                existingCoefficient.AnalysisCoefficient = analysisCoefficient;
+                existingCoefficient.InstallationCoefficient = installationCoefficient;
+                existingCoefficient.SupportCoefficient = supportCoefficient;
+                existingCoefficient.TimeCoefficient = timeCoefficient;
+                existingCoefficient.DifficultyCoefficient = difficultyCoefficient;
+                existingCoefficient.ToMoneyCoefficient = toMoneyCoefficient;
+
+                context.SaveChanges();
+
+                MessageBoxResult result = MessageBox.Show("Коэффициенты успешно изменены!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
+                if (result == MessageBoxResult.OK)
+                {
+                    NavigationService.GoBack();
                 }
             }
             catch (Exception ex)
             {
-                MessageBox.Show($"Ошибка обновления коэффициентов: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                MessageBox.Show($"Ошибка при сохранении данных: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
+
     }
-}
+}

+ 15 - 2
esoft/Pages/ExecutorsListPage.xaml.cs

@@ -179,8 +179,21 @@ namespace esoft.Pages
 
         private void BtnPriceCoefficient_Click(object sender, RoutedEventArgs e)
         {
-            // Перенаправление пользователя на страницу с коэфициентом
-            NavigationService.Navigate(new Pages.EditPriceCoefficient());
+            if (LViewExecutors.SelectedItem != null)
+            {
+                if (LViewExecutors.SelectedItem is ExecuterFill selectedExecuter)
+                {
+                    // Передаем выбранного исполнителя на страницу редактирования коэффициентов
+                    EditPriceCoefficient editPricePage = new EditPriceCoefficient(selectedExecuter);
+
+                    // Открываем страницу редактирования коэффициентов
+                    NavigationService.Navigate(editPricePage);
+                }
+                else
+                {
+                    MessageBox.Show("Выберите исполнителя для редактирования коэффициентов.", "Внимание", MessageBoxButton.OK, MessageBoxImage.Information);
+                }
+            }
         }
     }
 }

+ 1 - 0
esoft/esoft.csproj

@@ -95,6 +95,7 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="Class\ActualContext.cs" />
+    <Compile Include="Class\CoefficientFill.cs" />
     <Compile Include="Class\ExecuterFill.cs" />
     <Compile Include="Class\GetCurrentUser.cs" />
     <Compile Include="Class\GetGrade.cs" />