Inspections added
This commit is contained in:
+22
-1
@@ -1,4 +1,8 @@
|
||||
namespace GazpromApp.Enums;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Avalonia.Data.Converters;
|
||||
|
||||
namespace GazpromApp.Enums;
|
||||
|
||||
public enum PeriodType
|
||||
{
|
||||
@@ -36,3 +40,20 @@ public static class PeriodTypeExtensions
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class PeriodConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is PeriodType periodType)
|
||||
return periodType.ToDescription();
|
||||
return false;
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string periodType)
|
||||
return periodType.ToPeriodType();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ public class Inspection
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public DateTime InspectionDate { get; set; }
|
||||
public DateTimeOffset InspectionDate { get; set; }
|
||||
[Required]
|
||||
public string PeriodType { get; set; } = string.Empty;
|
||||
[Required]
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using GazpromApp.Enums;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.ViewModels;
|
||||
|
||||
namespace GazpromApp.Utils;
|
||||
|
||||
public static class DateCalculator
|
||||
{
|
||||
public static DateTime[] GetNearestDates(this InspectionViewModel inspection)
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
|
||||
var firstFutureDate = AddPeriod(inspection.InspectionDate.DateTime, inspection.PeriodType, inspection.PeriodValue);
|
||||
|
||||
if (firstFutureDate > today)
|
||||
{
|
||||
return [inspection.InspectionDate.DateTime, firstFutureDate];
|
||||
}
|
||||
|
||||
DateTime futureDate = Enumerable.Range(1, int.MaxValue)
|
||||
.Select(i => AddPeriod(inspection.InspectionDate.DateTime, inspection.PeriodType, inspection.PeriodValue * i))
|
||||
.First(d => d > today);
|
||||
|
||||
DateTime pastDate = SubtractPeriod(futureDate, inspection.PeriodType, inspection.PeriodValue);
|
||||
|
||||
return [pastDate, futureDate];
|
||||
}
|
||||
|
||||
private static DateTime AddPeriod(DateTime date, PeriodType periodType, float value)
|
||||
{
|
||||
return periodType switch
|
||||
{
|
||||
PeriodType.Day => date.AddDays(value),
|
||||
PeriodType.Week => date.AddDays(value * 7),
|
||||
PeriodType.Month => date.AddDays(value * 30.436875), // Avg days/month
|
||||
PeriodType.Year => date.AddDays(value * 365.2425), // Avg days/year (incl. leap years)
|
||||
_ => throw new ArgumentException("Invalid period type")
|
||||
};
|
||||
}
|
||||
|
||||
private static DateTime SubtractPeriod(DateTime date, PeriodType periodType, float value)
|
||||
{
|
||||
return AddPeriod(date, periodType, -value);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Avalonia.Media.Imaging;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.Utils;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
@@ -33,7 +33,7 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
Image = null;
|
||||
Properties = [];
|
||||
Inspections = [];
|
||||
NearestInspection = DateTime.Now.ToLongDateString();
|
||||
NearestInspection = "Нету инспекций";
|
||||
}
|
||||
|
||||
public EquipmentViewModel(Equipment equipment)
|
||||
@@ -42,8 +42,22 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
Description = equipment.Description;
|
||||
Image = new ImageViewModel(equipment.Image ?? new Image());
|
||||
Properties = new ObservableCollection<PropertyViewModel>(equipment.Properties.Select(e => new PropertyViewModel(e)));
|
||||
Inspections = new ObservableCollection<InspectionViewModel>(equipment.Inspections.Select(e => new InspectionViewModel(e)));
|
||||
NearestInspection = DateTime.Now.ToLongDateString();
|
||||
|
||||
List<DateTime[]> times = (equipment.Inspections.Select(e => new InspectionViewModel(e)))
|
||||
.Select(e => e.GetNearestDates())
|
||||
.ToList();
|
||||
|
||||
Inspections = new ObservableCollection<InspectionViewModel>(equipment.Inspections
|
||||
.Select((e, i) => new InspectionViewModel(e) { InspectionDate = times[i][0] }));
|
||||
|
||||
NearestInspection = times
|
||||
.Where(e => e[1] > DateTime.Now)
|
||||
.Select(e => e[1])
|
||||
.OrderBy(e => e)
|
||||
.FirstOrDefault()
|
||||
.ToLongDateString();
|
||||
|
||||
if (Inspections.Count == 0) NearestInspection = "Нету инспекций";
|
||||
}
|
||||
|
||||
public Equipment GetEquipment()
|
||||
@@ -53,6 +67,7 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Image = Image?.GetImage(),
|
||||
Inspections = Inspections.Select(e => e.GetInspection()).ToList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,50 @@
|
||||
using GazpromApp.Models;
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GazpromApp.Enums;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class InspectionViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string _name;
|
||||
[ObservableProperty]
|
||||
private DateTimeOffset _inspectionDate;
|
||||
[ObservableProperty]
|
||||
private PeriodType _periodType;
|
||||
[ObservableProperty]
|
||||
private float _periodValue;
|
||||
|
||||
// Visual properties
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isEditing = false;
|
||||
|
||||
public InspectionViewModel()
|
||||
{
|
||||
|
||||
Name = string.Empty;
|
||||
InspectionDate = DateTimeOffset.Now;
|
||||
PeriodType = 0;
|
||||
PeriodValue = 1;
|
||||
}
|
||||
|
||||
public InspectionViewModel(Inspection inspection)
|
||||
{
|
||||
Name = inspection.Name;
|
||||
InspectionDate = inspection.InspectionDate;
|
||||
PeriodType = inspection.PeriodType.ToPeriodType();
|
||||
PeriodValue = inspection.PeriodValue;
|
||||
}
|
||||
|
||||
public Inspection GetInspection()
|
||||
{
|
||||
return new Inspection()
|
||||
{
|
||||
Name = Name,
|
||||
InspectionDate = InspectionDate,
|
||||
PeriodType = PeriodType.ToDescription(),
|
||||
PeriodValue = PeriodValue
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Avalonia.Controls;
|
||||
@@ -33,6 +35,8 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private ImageViewModel? _image;
|
||||
|
||||
public ObservableCollection<InspectionViewModel> Inspections { get; set; }
|
||||
|
||||
[RelayCommand]
|
||||
private void EditName()
|
||||
{
|
||||
@@ -91,6 +95,27 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
IsImageSelected = false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void AddInspection()
|
||||
{
|
||||
Inspections.Add(new InspectionViewModel { Name = "Название инспекции", InspectionDate = DateTimeOffset.Now, PeriodValue = 1, PeriodType = PeriodType.Day });
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void EditInspection(InspectionViewModel inspection)
|
||||
{
|
||||
foreach (var item in Inspections)
|
||||
if (item != inspection)
|
||||
item.IsEditing = false;
|
||||
inspection.IsEditing = !inspection.IsEditing;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void DeleteInspection(InspectionViewModel inspection)
|
||||
{
|
||||
Inspections.Remove(inspection);
|
||||
}
|
||||
|
||||
private bool CanCompleteEdit() => !string.IsNullOrWhiteSpace(Name);
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanCompleteEdit))]
|
||||
@@ -102,6 +127,7 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Image = Image?.GetImage(),
|
||||
Inspections = Inspections.Select(e => e.GetInspection()).ToList(),
|
||||
Properties = [],
|
||||
};
|
||||
WeakReferenceMessenger.Default.Send(new EditEquipmentDone(new EquipmentViewModel(equipment)));
|
||||
@@ -124,15 +150,20 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
|
||||
private readonly EquipmentViewModel _equipment;
|
||||
|
||||
public PeriodType[] AllPeriods => Enum.GetValues<PeriodType>()
|
||||
.Where(p => p != PeriodType.Unknown)
|
||||
.ToArray();
|
||||
|
||||
public EditEquipmentDialogViewModel()
|
||||
{
|
||||
Name = "";
|
||||
Description = "";
|
||||
Name = "Testing";
|
||||
Description = "Testing";
|
||||
Image = null;
|
||||
Inspections = [];
|
||||
|
||||
IsImageSelected = false;
|
||||
|
||||
_equipment = new EquipmentViewModel(new Equipment());
|
||||
_equipment = new EquipmentViewModel();
|
||||
}
|
||||
|
||||
public EditEquipmentDialogViewModel(EquipmentViewModel equipment)
|
||||
@@ -140,6 +171,7 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
Name = equipment.Name;
|
||||
Description = equipment.Description;
|
||||
Image = equipment.Image;
|
||||
Inspections = new ObservableCollection<InspectionViewModel>(equipment.Inspections.Select(e => e));
|
||||
|
||||
IsImageSelected = equipment.Image is { Bytes.Length: > 0 };
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:GazpromApp.ViewModels"
|
||||
xmlns:enums="using:GazpromApp.Enums"
|
||||
x:Name="Window"
|
||||
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="600"
|
||||
Width="1000" Height="600"
|
||||
@@ -16,6 +17,21 @@
|
||||
<Design.DataContext>
|
||||
<vm:EditEquipmentDialogViewModel/>
|
||||
</Design.DataContext>
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.ThemeDictionaries>
|
||||
<ResourceDictionary x:Key="Light">
|
||||
<SolidColorBrush x:Key="BackgroundBrush" Color="#f0f0f0"/>
|
||||
<SolidColorBrush x:Key="BorderBrush" Color="#d3d3d3"/>
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary x:Key="Dark">
|
||||
<SolidColorBrush x:Key="BackgroundBrush" Color="#101010"/>
|
||||
<SolidColorBrush x:Key="BorderBrush" Color="#303030"/>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.ThemeDictionaries>
|
||||
</ResourceDictionary>
|
||||
<enums:PeriodConverter x:Key="PeriodConverter"/>
|
||||
</Window.Resources>
|
||||
<Grid RowDefinitions="70,150,*,Auto" ColumnDefinitions="*,100,220" x:Name="Root">
|
||||
<TextBlock Grid.Column="0" Grid.Row="0" FontSize="28" Margin="20,4,0,4"
|
||||
Text="{Binding Name}"
|
||||
@@ -64,7 +80,61 @@
|
||||
|
||||
<TabControl Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="2">
|
||||
<TabItem Header="Тех. осмотры">
|
||||
<ScrollViewer>
|
||||
<StackPanel>
|
||||
<ItemsRepeater HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding Inspections}">
|
||||
<ItemsRepeater.Layout>
|
||||
<StackLayout Orientation="Vertical" Spacing="8"/>
|
||||
</ItemsRepeater.Layout>
|
||||
<ItemsRepeater.ItemTemplate>
|
||||
<DataTemplate DataType="vm:InspectionViewModel">
|
||||
<Border CornerRadius="4" BorderThickness="1"
|
||||
Background="{DynamicResource BackgroundBrush}"
|
||||
BorderBrush="{DynamicResource BorderBrush}">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Panel>
|
||||
<TextBlock Margin="12,6,6,6" VerticalAlignment="Center"
|
||||
IsVisible="{Binding !IsEditing}"
|
||||
Text="{Binding Name}" FontSize="22"/>
|
||||
<TextBox Height="35" Margin="12,14,84,6" FontSize="18"
|
||||
IsVisible="{Binding IsEditing}"
|
||||
Text="{Binding Name}"/>
|
||||
<Button HorizontalAlignment="Right" Margin="0,8,20,0"
|
||||
Command="{Binding #Root.((vm:EditEquipmentDialogViewModel)DataContext).EditInspectionCommand}"
|
||||
CommandParameter="{Binding .}">
|
||||
<Image Width="24" Source="avares://GazpromApp/Assets/ic_fluent_edit_24_filled (Custom).png"/>
|
||||
</Button>
|
||||
</Panel>
|
||||
<Grid ColumnDefinitions="Auto, Auto, Auto, Auto, Auto, *" Margin="8">
|
||||
<TextBlock Margin="10,0,0,0" Text="Дата проведения: " FontSize="18" VerticalAlignment="Center"/>
|
||||
<DatePicker Grid.Column="1" VerticalAlignment="Center"
|
||||
SelectedDate="{Binding InspectionDate}"/>
|
||||
|
||||
<TextBlock Grid.Column="2" Margin="16,0,0,0" Text="Период: " FontSize="18" VerticalAlignment="Center"/>
|
||||
<NumericUpDown Grid.Column="3" AllowSpin="True" Width="120" VerticalAlignment="Center"
|
||||
Value="{Binding PeriodValue}"/>
|
||||
<ComboBox Grid.Column="4" Width="100" VerticalAlignment="Center" Margin="4,0,0,0"
|
||||
ItemsSource="{Binding #Root.((vm:EditEquipmentDialogViewModel)DataContext).AllPeriods}"
|
||||
SelectedItem="{Binding PeriodType, Mode=TwoWay}"
|
||||
DisplayMemberBinding="{Binding ., Converter={StaticResource PeriodConverter}}"/>
|
||||
<Button Grid.Column="5" Margin="0,0,12,0" HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Command="{Binding #Root.((vm:EditEquipmentDialogViewModel)DataContext).DeleteInspectionCommand}"
|
||||
CommandParameter="{Binding .}">
|
||||
<Image Width="24" Source="avares://GazpromApp/Assets/ic_fluent_delete_24_filled (Custom).png"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsRepeater.ItemTemplate>
|
||||
</ItemsRepeater>
|
||||
<Button HorizontalAlignment="Center" Margin="10"
|
||||
Command="{Binding AddInspectionCommand}">
|
||||
<Image Width="24" Source="avares://GazpromApp/Assets/ic_fluent_add_24_filled (Custom).png"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
<TabItem Header="Свойства">
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
004891c51b7c26ff54260c1cbfcff302500ddbafa20549c101da76cc7da60e8a
|
||||
3656b818a608cac55f3434fefe51f65e8b2346fa99aecf23bebe97e8e8aa269e
|
||||
|
||||
Binary file not shown.
@@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("GazpromApp")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5816f21e6cc989b7059d5a18a1f56939b27bf40d")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+725b6dc53998e3fe82d1e7e83d0312933ae96983")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("GazpromApp")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("GazpromApp")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
22f6a7bf36b71d326c8840f0501afa961a7d4f13e9163340a4acf3e167738c72
|
||||
327dd27f22ee4d496be5fbf4fc27c7f9dfbad856b482d896a83e82e336f0e4fd
|
||||
|
||||
@@ -1 +1 @@
|
||||
17514599119483488
|
||||
17518675823308854
|
||||
@@ -1 +1 @@
|
||||
17514599119483488
|
||||
17518675823308854
|
||||
Reference in New Issue
Block a user