Prechádzať zdrojové kódy

немного и много изменений

Nanech 4 mesiacov pred
rodič
commit
faa8f4a72b

+ 17 - 13
SocialEducatorAvalonia/SocialEducatorAvalonia.csproj

@@ -18,27 +18,27 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="Avalonia" Version="11.0.10" />
-    <PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
-    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
-    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.10" />
+    <PackageReference Include="Avalonia" Version="11.0.11" />
+    <PackageReference Include="Avalonia.Desktop" Version="11.0.11" />
+    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.11" />
+    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.11" />
     <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
-    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
+    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.11" />
     <PackageReference Condition="'$(Configuration)' == 'Release'" Include="Avalonia.Controls.DataGrid" Version="11.0.10" />
     <PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.0.10.9" />
     <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
-    <PackageReference Include="ExcelDataReader" Version="3.6.0" />
-    <PackageReference Include="ExcelDataReader.DataSet" Version="3.6.0" />
+    <PackageReference Include="ExcelDataReader" Version="3.7.0" />
+    <PackageReference Include="ExcelDataReader.DataSet" Version="3.7.0" />
     <PackageReference Include="MessageBox.Avalonia" Version="3.1.5.1" />
     <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" />
-    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
-    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
+    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
-    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.4" />
-    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
-    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.6" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
@@ -76,5 +76,9 @@
   <ItemGroup>
     <UpToDateCheckInput Remove="Views\AddDataToDbView.axaml" />
   </ItemGroup>
-  
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.CodeAnalysis.Scripting.Common" Version="4.5.0" />
+  </ItemGroup>
+
 </Project>

+ 3 - 5
SocialEducatorAvalonia/ViewModels/AddPaymentsViewModel.cs

@@ -49,7 +49,7 @@ namespace SocialEducatorAvalonia.ViewModels
         // TODO: немного доработать с выделением и проверкой дичи всякой
 
         [RelayCommand]
-        void ApllyFilters()
+        void ApplyFilters()
         {
             if (SelectedPayment is not "Не выбрано")
             {
@@ -126,7 +126,7 @@ namespace SocialEducatorAvalonia.ViewModels
                         {
                             int monthsApart = ((payment.EndRangeDate.Value.Year - payment.CurrentPaymentDate.Year) * 12) + payment.EndRangeDate.Value.Month - payment.CurrentPaymentDate.Month;
 
-                            DateTime original = new DateTime(payment.CurrentPaymentDate.Year, payment.CurrentPaymentDate.Month, 1, 0, 0, 0);
+                            DateTime original = new(payment.CurrentPaymentDate.Year, payment.CurrentPaymentDate.Month, 1, 0, 0, 0);
 
                             monthsApart++;
 
@@ -150,9 +150,7 @@ namespace SocialEducatorAvalonia.ViewModels
                     }
                     else
                     {
-                        var currentPayment = new StudentsAndPayment();
-
-                        currentPayment = new StudentsAndPayment()
+                        StudentsAndPayment currentPayment = new()
                         {
                             StudentId = payment.StudentId,
                             AmountPayment = payment.Payment,

+ 10 - 9
SocialEducatorAvalonia/ViewModels/PaymentsViewModel.cs

@@ -9,6 +9,7 @@ using System.Collections.Immutable;
 using System.Collections.ObjectModel;
 using System.Linq;
 using Microsoft.EntityFrameworkCore;
+using System.Diagnostics;
 
 namespace SocialEducatorAvalonia.ViewModels
 {
@@ -54,7 +55,7 @@ namespace SocialEducatorAvalonia.ViewModels
         readonly Dictionary<string, int> PaymentDict = [];
 
         /// <summary>
-        /// перечисление студентов в кеше
+        /// перечисление студентов в кэше
         /// </summary>
         List<Student> _studentsStorage = [];
 
@@ -75,7 +76,7 @@ namespace SocialEducatorAvalonia.ViewModels
         /// <returns>True - могу менять, False - не могу менять</returns>
         bool CheckAllFields()
         {
-            string functionName = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod().Name;
+            string functionName = new StackTrace().GetFrame(1)?.GetMethod()?.Name ?? "Unknown";
 
             switch (functionName)
             {
@@ -115,7 +116,7 @@ namespace SocialEducatorAvalonia.ViewModels
 
         void TakeCorrectData()
         {
-            string functionName = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod().Name;
+            string functionName = new StackTrace().GetFrame(1)?.GetMethod()?.Name ?? "Unknown";
 
             switch (functionName)
             {
@@ -211,7 +212,7 @@ namespace SocialEducatorAvalonia.ViewModels
 
             ObservableCollection<Student> students = new();
 
-            if (DataEditorUtilities.ValueNullOrBlank(ref value))
+            if (!string.IsNullOrEmpty(value))
             {
                 if (CheckAllFields())
                     students = new(DbContext.Students.FromSql($"select * from search_students_by_fio({value})").Include(x => x.StudentsAndPayments).ToList());
@@ -362,9 +363,9 @@ namespace SocialEducatorAvalonia.ViewModels
                         else // error
                             collection = new(StudentsList.Where(x => x.StudentsAndPayments.All(y => y.DataOfPayment.CompareTo(StartedDate) >= 0)).ToList());
                     }
-                    else
+                    else if (SelectedEndDate.HasValue)
                     {
-                        DateOnly EndDate = DateOnly.FromDateTime((DateTime)SelectedEndDate);
+                        DateOnly EndDate = SelectedEndDate.HasValue ? DateOnly.FromDateTime(SelectedEndDate.Value) : default;
 
                         if (CheckAllFields())
                             collection = new([.. DbContext.Students.FromSql($"select * from find_students_by_payment_end_date({EndDate})").Include(x => x.StudentsAndPayments)]);
@@ -387,9 +388,9 @@ namespace SocialEducatorAvalonia.ViewModels
         /// <param name="value"></param>
         partial void OnStudentsListChanged(ObservableCollection<Student> value)
         {
-            _studentsList = value;
+            StudentsList = value;
 
-            var itemNotInList = _studentsList.FirstOrDefault(x => x.IsChecked == false);
+            var itemNotInList = StudentsList.FirstOrDefault(x => x.IsChecked == false);
 
             if (itemNotInList is not null)
                 SelectedComboBox = false;
@@ -541,7 +542,7 @@ namespace SocialEducatorAvalonia.ViewModels
             else
                 _personsToPayment.Add(student);
 
-            var changeComboBox = _studentsList.FirstOrDefault(x => x.IsChecked == false);
+            var changeComboBox = StudentsList.FirstOrDefault(x => x.IsChecked == false);
 
             if (changeComboBox is not null)
                 SelectedComboBox = false;

+ 41 - 5
SocialEducatorAvalonia/ViewModels/PersonalStudentPaymentViewModel.cs

@@ -8,6 +8,7 @@ using System.Collections.Immutable;
 using System.Collections.ObjectModel;
 using System.Linq;
 using System.Threading.Tasks;
+using System.Diagnostics;
 
 namespace SocialEducatorAvalonia.ViewModels
 {
@@ -88,7 +89,8 @@ namespace SocialEducatorAvalonia.ViewModels
             {
                 List<StudentsAndPayment> payments = [];
 
-                string functionName = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod().Name;
+                string functionName = new StackTrace().GetFrame(1)?.GetMethod()?.Name ?? "Unknown";
+
                 switch (functionName)
                 {
                     case "FindByDate":
@@ -105,10 +107,7 @@ namespace SocialEducatorAvalonia.ViewModels
                             if (existWithPayment.Count > 0)
                                 payments = existWithPayment;
                             else
-                            {
-                                var box = MessageBoxManager.GetMessageBoxStandard("Сообщение для вас", "В данном диапазоне нету данных с этим типом выплат", ButtonEnum.Ok, Icon.Database);
-                                box.ShowAsync();
-                            }
+                                MessageBoxManager.GetMessageBoxStandard("Сообщение для вас", "В данном диапазоне нету данных с этим типом выплат", ButtonEnum.Ok, Icon.Database).ShowAsync();
                         }
 
                         break;
@@ -119,7 +118,11 @@ namespace SocialEducatorAvalonia.ViewModels
 
                         if (curList is not null)
                             payments.AddRange(curList);
+                        break;
+
 
+                    case "Unknown":
+                        MessageBoxManager.GetMessageBoxStandard("Сообщение для вас", "Возникла ошибка", ButtonEnum.Ok, Icon.Error).ShowAsync();
                         break;
                 }
 
@@ -192,6 +195,39 @@ namespace SocialEducatorAvalonia.ViewModels
             }
         }
 
+        [RelayCommand]
+        async Task DeleteListAsync()
+        {
+            var list = PaymentList.Where(x => x.IsChecked == true).ToList();
+
+            if (PaymentList.Count() > 1)
+            {
+                ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Сообщение для вас", "Вы уверены что хотите удалить записи", ButtonEnum.YesNo, Icon.Warning).ShowAsync();
+
+                if (result == ButtonResult.Yes)
+                {
+                    DbContext.StudentsAndPayments.RemoveRange(list);
+                    await DbContext.SaveChangesAsync();
+
+                    _paymentStorage.RemoveAll(item => list.Contains(item));
+
+                    if (PaymentList.Count == 1)
+                        PaymentList.Clear();
+                    else
+                    {
+                        foreach (var item in list)
+                        {
+                            PaymentList.Remove(item);
+                        }
+                    }
+                }
+            }
+            else
+                await MessageBoxManager.GetMessageBoxStandard("Сообщение для вас", "Записи или не выбраны или выбран один элемент", ButtonEnum.Ok, Icon.Warning).ShowAsync();
+
+            list.Clear();
+        }
+
         [RelayCommand]
         void GoBack()
         {

+ 18 - 5
SocialEducatorAvalonia/ViewModels/StudentsViewModel.cs

@@ -7,6 +7,9 @@ using System.Linq;
 using System.Reactive.Linq;
 using SocialEducatorAvalonia.Utilities;
 using System.Collections.Immutable;
+using System.Data.Common;
+using SocialEducatorAvalonia.DTOs;
+using System;
 
 namespace SocialEducatorAvalonia.ViewModels
 {
@@ -190,12 +193,22 @@ namespace SocialEducatorAvalonia.ViewModels
             // Берем все элементы кроме "Обучающийся", т.к. часто встречается
             _statusList = StatusDict.Keys.Where((v, i) => v != "Обучается").ToImmutableArray();
 
-            //_studentsStorage = [.. DbContext.StudentsActiveAndGraduations.Take(200)
-            //    .Select(x => new Student 
-            //    { Fio = x.Fio, AdmissionDate = x.AdmissionDate, StudentGroupId = x.StudentGroupId,
-            //      Studen = x.StudentStatusId   }  )    ];
 
-            _studentsStorage = [.. DbContext.Students.Take(200)];
+            _studentsStorage = DbContext.StudentsActiveAndGraduations.Take(200).AsEnumerable()
+                .Select(x =>
+                {
+                    string[] spilledFio = x.Fio.Split(' ');                    
+                    return new Student
+                    {
+                        Fio = x.Fio,
+                        Surname = spilledFio.Length > 0 ? spilledFio[0] : string.Empty,
+                        Name = spilledFio.Length > 1 ? spilledFio[1] : string.Empty,
+                        Patronymic = spilledFio.Length > 2 ? spilledFio[2] : string.Empty,
+                        AdmissionDate = x.AdmissionDate,
+                        StudentGroupId = x.StudentGroupId,
+                        StudentStatusId = x.StudentStatusId,                        
+                    };
+                }).ToList();
 
             StudentsList = new ObservableCollection<Student>(_studentsStorage.Take(25));
 

+ 2 - 10
SocialEducatorAvalonia/Views/AddPaymentsView.axaml

@@ -25,7 +25,7 @@
 				<Button Content="Сохранить в БД" Command="{Binding SaveListToDataBaseCommand}"/>
 
 				<Button Content="Очистить" Command="{Binding ClearAllFieldsCommand}"/>
-
+        
 				<!--<Button Content="Добавить из файла" Command=""/>-->
 
 			</StackPanel>
@@ -37,17 +37,13 @@
 
 				<TextBox Width="100" Watermark="Деньга" Text="{Binding Payment}"/>
 
-				<Button Content="Применить фильтры" Command="{Binding ApllyFiltersCommand }" />
+				<Button Content="Применить фильтры" Command="{Binding ApplyFiltersCommand }" />
 				
 				<CheckBox Content="Выделить все" IsChecked="{Binding SelectedComboBox, Mode=TwoWay}"
                   Command="{Binding CheckBoxClickedCommand}"/>
 
-				
-				<!--<Button Content="Очистить" Command="{Binding ClearAllFieldsCommand}"/>-->
-
 			</StackPanel>
 
-
 		</StackPanel>
 
 		<DataGrid Classes="def" Grid.Row="1" ItemsSource="{Binding PersonsPaymentList, Mode=TwoWay}" BorderBrush="White" GridLinesVisibility="All">
@@ -94,9 +90,6 @@
 					</DataGridTemplateColumn.CellTemplate>
 				</DataGridTemplateColumn>
 
-				<!--Command="{Binding #root((vm:PaymentsViewModel)DataContext).AddToListCommand, Mode=OneWay}"
-        CommandParameter="{Binding}"-->
-
 				<DataGridTemplateColumn Width="*" Header="Удалить из списка">
 					<DataGridTemplateColumn.CellTemplate>
 						<DataTemplate>
@@ -106,7 +99,6 @@
 					</DataGridTemplateColumn.CellTemplate>
 				</DataGridTemplateColumn>
 
-
 			</DataGrid.Columns>
 
 		</DataGrid>

+ 1 - 2
SocialEducatorAvalonia/Views/AddStudentView.axaml

@@ -34,8 +34,7 @@
         <DataGridTemplateColumn Header="Группа" Width="120">
           <DataGridTemplateColumn.CellTemplate>
             <DataTemplate>
-              <AutoCompleteBox ItemsSource="{Binding #root.((vm:AddStudentViewModel)DataContext).GroupList}" SelectedItem="{Binding Group}"/>
-              <!--<ComboBox ItemsSource="{Binding #root.((vm:AddStudentViewModel)DataContext).GroupList}" SelectedItem="{Binding Group}"/>-->
+              <AutoCompleteBox ItemsSource="{Binding #root.((vm:AddStudentViewModel)DataContext).GroupList}" SelectedItem="{Binding Group}"/>              
             </DataTemplate>
           </DataGridTemplateColumn.CellTemplate>
         </DataGridTemplateColumn>

+ 10 - 0
SocialEducatorAvalonia/Views/PersonalStudentPaymentView.axaml

@@ -36,6 +36,8 @@
 
         <Button Content="Найти по датам" Command="{Binding FindByDateCommand}"/>
 
+        <Button Content="Удалить список" Command="{Binding DeleteListCommand}"/>
+
       </StackPanel>
 
     </StackPanel>
@@ -58,6 +60,14 @@
           </DataGridTemplateColumn.CellTemplate>
         </DataGridTemplateColumn>
 
+        <DataGridTemplateColumn Header="В списке" Width="100">
+          <DataGridTemplateColumn.CellTemplate>
+            <DataTemplate>
+              <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding  Path=IsChecked, Mode=TwoWay}"/>
+            </DataTemplate>
+          </DataGridTemplateColumn.CellTemplate>
+        </DataGridTemplateColumn>
+
       </DataGrid.Columns>
     </DataGrid>