DB integration added, multiple images for equipment

This commit is contained in:
retr0volkov
2025-07-15 11:14:28 +03:00 Unverified
parent 7a34fc2dbb
commit 8ddce4005f
38 changed files with 627 additions and 297 deletions
+15 -15
View File
@@ -9,18 +9,19 @@ namespace GazpromApp.ViewModels;
public partial class EquipmentViewModel : ViewModelBase
{
private Equipment Equipment { get; }
[ObservableProperty]
private string? _name;
[ObservableProperty]
private string? _description;
[ObservableProperty]
private ImageViewModel? _image;
public ObservableCollection<PropertyViewModel> Properties { get; set; }
public ObservableCollection<InspectionViewModel> Inspections { get; set; }
public ObservableCollection<ImageViewModel> Images { get; init; } = [];
public ObservableCollection<PropertyViewModel> Properties { get; }
public ObservableCollection<InspectionViewModel> Inspections { get; }
[ObservableProperty]
private string _nearestInspection;
@@ -29,17 +30,17 @@ public partial class EquipmentViewModel : ViewModelBase
{
Name = string.Empty;
Description = string.Empty;
Image = null;
Properties = [];
Inspections = [];
NearestInspection = "Нету инспекций";
Equipment = new Equipment();
}
public EquipmentViewModel(Equipment equipment)
{
Name = equipment.Name;
Description = equipment.Description;
Image = new ImageViewModel(equipment.Image ?? new Image());
Images = new ObservableCollection<ImageViewModel>(equipment.Images.Select(i => new ImageViewModel(i)));
Properties = new ObservableCollection<PropertyViewModel>(equipment.Properties.Select(e => new PropertyViewModel(e)));
var times = equipment.Inspections.Select(e => new InspectionViewModel(e))
@@ -57,16 +58,15 @@ public partial class EquipmentViewModel : ViewModelBase
.ToLongDateString();
if (Inspections.Count == 0) NearestInspection = "Нету инспекций";
Equipment = equipment;
}
public Equipment GetEquipment()
{
return new Equipment
{
Name = Name,
Description = Description,
Image = Image?.GetImage(),
Inspections = Inspections.Select(e => e.GetInspection()).ToList()
};
Equipment.Name = Name;
Equipment.Description = Description;
Equipment.Images = Images.Select(e => e.GetImage()).ToList();
Equipment.Inspections = Inspections.Select(e => e.GetInspection()).ToList();
return Equipment;
}
}
+17 -12
View File
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.IO;
using Avalonia.Media.Imaging;
using CommunityToolkit.Mvvm.ComponentModel;
using GazpromApp.Models;
@@ -8,13 +7,19 @@ namespace GazpromApp.ViewModels;
public partial class ImageViewModel : ViewModelBase
{
private Image Image { get; }
[ObservableProperty]
private byte[]? _bytes;
// EF stuff
[ObservableProperty]
private List<Point>? _points;
private Point? _point;
[ObservableProperty]
private List<Equipment>? _equipment;
private Equipment? _equipment;
[ObservableProperty]
private Bitmap? _fileName;
@@ -22,26 +27,26 @@ public partial class ImageViewModel : ViewModelBase
{
Bytes = image.Bytes;
Equipment = image.Equipment;
Points = image.Points;
Point = image.Point;
FileName = image.Bytes is { Length: > 0 } ? new Bitmap(new MemoryStream(image.Bytes)) : null;
Image = image;
}
public ImageViewModel()
{
Bytes = null;
Equipment = null;
Points = null;
Point = null;
Image = new Image();
}
public Image GetImage()
{
var ms = new MemoryStream();
FileName?.Save(ms);
return new Image
{
Bytes = ms.ToArray(),
Equipment = Equipment ?? [],
Points = Points ?? []
};
Image.Bytes = ms.ToArray();
Image.Equipment = Equipment;
Image.Point = Point;
return Image;
}
}
+8 -7
View File
@@ -7,6 +7,7 @@ namespace GazpromApp.ViewModels;
public partial class InspectionViewModel : ViewModelBase
{
private Inspection Inspection { get; }
[ObservableProperty]
private string _name;
[ObservableProperty]
@@ -27,6 +28,7 @@ public partial class InspectionViewModel : ViewModelBase
InspectionDate = DateTimeOffset.Now;
PeriodType = 0;
PeriodValue = 1;
Inspection = new Inspection();
}
public InspectionViewModel(Inspection inspection)
@@ -35,16 +37,15 @@ public partial class InspectionViewModel : ViewModelBase
InspectionDate = inspection.InspectionDate;
PeriodType = inspection.PeriodType.ToPeriodType();
PeriodValue = inspection.PeriodValue;
Inspection = inspection;
}
public Inspection GetInspection()
{
return new Inspection
{
Name = Name,
InspectionDate = InspectionDate,
PeriodType = PeriodType.ToDescription(),
PeriodValue = PeriodValue
};
Inspection.Name = Name;
Inspection.InspectionDate = InspectionDate;
Inspection.PeriodType = PeriodType.ToDescription();
Inspection.PeriodValue = PeriodValue;
return Inspection;
}
}
+12 -11
View File
@@ -6,6 +6,8 @@ namespace GazpromApp.ViewModels;
public partial class PointViewModel : ViewModelBase
{
private Point Point { get; }
[ObservableProperty]
private string? _name;
@@ -20,14 +22,15 @@ public partial class PointViewModel : ViewModelBase
// EF stuff
[ObservableProperty]
private List<Image>? _images;
private List<Image> _images;
[ObservableProperty]
private List<Equipment>? _equipment;
private List<Equipment> _equipment;
[ObservableProperty]
private List<Property>? _properties;
private List<Property> _properties;
public PointViewModel(Point point)
{
Point = point;
Name = point.Name;
Description = point.Description;
Latitude = point.Latitude;
@@ -39,13 +42,11 @@ public partial class PointViewModel : ViewModelBase
public Point GetPoint()
{
return new Point
{
Name = Name,
Description = Description,
Equipment = Equipment ?? [],
Images = Images ?? [],
Properties = Properties ?? []
};
Point.Name = Name;
Point.Description = Description;
Point.Equipment = Equipment;
Point.Images = Images;
Point.Properties = Properties;
return Point;
}
}
+11 -10
View File
@@ -8,6 +8,8 @@ namespace GazpromApp.ViewModels;
public partial class PropertyViewModel : ViewModelBase
{
private Property Property { get; }
[ObservableProperty]
private string _name;
@@ -18,22 +20,18 @@ public partial class PropertyViewModel : ViewModelBase
// Visual and other properties
public PropertyViewModel? Parent { get; set; }
public PropertyViewModel? Parent { get; init; }
[ObservableProperty]
private bool _isEditing;
public Property GetProperty(Property? parent = null)
{
var p = new Property
{
Name = Name,
Value = Value,
Properties = [],
Parent = parent
};
p.Properties = Properties.Select(e => e.GetProperty(p)).ToList();
return p;
Property.Name = Name;
Property.Value = Value;
Property.Parent = parent;
Property.Properties = Properties.Select(e => e.GetProperty(Property)).ToList();
return Property;
}
public PropertyViewModel()
@@ -42,6 +40,7 @@ public partial class PropertyViewModel : ViewModelBase
Value = "Значение свойства";
Properties = [];
Parent = null;
Property = new Property();
}
public PropertyViewModel(Property property, PropertyViewModel? parent = null)
@@ -51,6 +50,7 @@ public partial class PropertyViewModel : ViewModelBase
Properties = new ObservableCollection<PropertyViewModel>(
property.Properties.Select(e => new PropertyViewModel(e, this)));
Parent = property.Parent is null ? null : parent;
Property = property;
}
public PropertyViewModel(PropertyViewModel property)
@@ -59,5 +59,6 @@ public partial class PropertyViewModel : ViewModelBase
Value = "Значение свойства";
Properties = [];
Parent = property;
Property = new Property();
}
}