JSON export added
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace GazpromApp.Models;
|
namespace GazpromApp.Models;
|
||||||
|
|
||||||
@@ -8,18 +9,24 @@ public class Equipment
|
|||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
[JsonIgnore]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string? Name { get; set; } = string.Empty;
|
public string? Name { get; set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
public string? Description { get; set; } = string.Empty;
|
public string? Description { get; set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public int PointId { get; set; }
|
public int PointId { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
public int ImageId { get; set; }
|
public int ImageId { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
public List<int> InspectionIds { get; set; } = [];
|
public List<int> InspectionIds { get; set; } = [];
|
||||||
|
|
||||||
// EF stuff
|
// EF stuff
|
||||||
public Image? Image { get; set; }
|
public Image? Image { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
public Point? Point { get; set; }
|
public Point? Point { get; set; }
|
||||||
public List<Property> Properties { get; set; } = [];
|
public List<Property> Properties { get; set; } = [];
|
||||||
public List<Inspection> Inspections { get; set; } = [];
|
public List<Inspection> Inspections { get; set; } = [];
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace GazpromApp.Models;
|
namespace GazpromApp.Models;
|
||||||
public class Image
|
public class Image
|
||||||
@@ -8,10 +9,13 @@ public class Image
|
|||||||
|
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
[JsonIgnore]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public byte[] Bytes { get; set; } = [];
|
public byte[] Bytes { get; set; } = [];
|
||||||
// EF stuff
|
// EF stuff
|
||||||
|
[JsonIgnore]
|
||||||
public List<Point> Points { get; set; } = [];
|
public List<Point> Points { get; set; } = [];
|
||||||
|
[JsonIgnore]
|
||||||
public List<Equipment> Equipment { get; set; } = [];
|
public List<Equipment> Equipment { get; set; } = [];
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace GazpromApp.Models;
|
namespace GazpromApp.Models;
|
||||||
|
|
||||||
@@ -8,6 +9,7 @@ public class Inspection
|
|||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
[JsonIgnore]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
@@ -18,8 +20,10 @@ public class Inspection
|
|||||||
[Required]
|
[Required]
|
||||||
public float PeriodValue { get; set; }
|
public float PeriodValue { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public int EquipmentId { get; set; }
|
public int EquipmentId { get; set; }
|
||||||
|
|
||||||
// EF stuff
|
// EF stuff
|
||||||
|
[JsonIgnore]
|
||||||
public Equipment? Equipment { get; } = new();
|
public Equipment? Equipment { get; } = new();
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace GazpromApp.Models;
|
namespace GazpromApp.Models;
|
||||||
|
|
||||||
@@ -8,6 +9,7 @@ public class Point
|
|||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
[JsonIgnore]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string? Name { get; set; } = string.Empty;
|
public string? Name { get; set; } = string.Empty;
|
||||||
|
|||||||
+8
-1
@@ -1,6 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace GazpromApp.Models;
|
namespace GazpromApp.Models;
|
||||||
|
|
||||||
@@ -8,14 +10,19 @@ public class Property
|
|||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
[JsonIgnore]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
public int ParentId { get; set; }
|
public int ParentId { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
public string Value { get; set; } = string.Empty;
|
public string Value { get; set; } = string.Empty;
|
||||||
// EF stuff
|
// EF stuff
|
||||||
|
[JsonIgnore]
|
||||||
public Property? Parent { get; set; }
|
public Property? Parent { get; set; }
|
||||||
public List<Property> Properties{ get; set; } = [];
|
public List<Property> Properties{ get; set; } = [];
|
||||||
|
[JsonIgnore]
|
||||||
public List<Point> Points { get; set; } = [];
|
public List<Point> Points { get; set; } = [];
|
||||||
|
[JsonIgnore]
|
||||||
public List<Equipment> Equipment { get; } = [];
|
public List<Equipment> Equipment { get; } = [];
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text.Json;
|
||||||
|
using GazpromApp.Models;
|
||||||
|
|
||||||
|
namespace GazpromApp.Utils;
|
||||||
|
|
||||||
|
public static class DataSerialization
|
||||||
|
{
|
||||||
|
private static void SaveData(string path, string data)
|
||||||
|
{
|
||||||
|
System.IO.File.WriteAllText(path, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string LoadData(string path)
|
||||||
|
{
|
||||||
|
return System.IO.File.ReadAllText(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SavePoint(Point point, string path)
|
||||||
|
{
|
||||||
|
SaveData(path, point.Serialize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Point? LoadPoint(string path)
|
||||||
|
{
|
||||||
|
return Deserialization.Deserialize(LoadData(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Serialization
|
||||||
|
{
|
||||||
|
public static string Serialize(this Point point)
|
||||||
|
{
|
||||||
|
return JsonSerializer.Serialize(point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Deserialization
|
||||||
|
{
|
||||||
|
public static Point? Deserialize(string point)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return string.IsNullOrEmpty(point) ? JsonSerializer.Deserialize<Point>(point) : null;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Ошибка расшивроки json файла");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,7 +37,6 @@ public partial class PointViewModel : ViewModelBase
|
|||||||
Properties = point.Properties;
|
Properties = point.Properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once UnusedMember.Global
|
|
||||||
public Point GetPoint()
|
public Point GetPoint()
|
||||||
{
|
{
|
||||||
return new Point
|
return new Point
|
||||||
@@ -45,6 +44,7 @@ public partial class PointViewModel : ViewModelBase
|
|||||||
Name = Name,
|
Name = Name,
|
||||||
Description = Description,
|
Description = Description,
|
||||||
Equipment = Equipment ?? [],
|
Equipment = Equipment ?? [],
|
||||||
|
Images = Images ?? [],
|
||||||
Properties = Properties ?? []
|
Properties = Properties ?? []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Web;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using CommunityToolkit.Mvvm.Messaging;
|
using CommunityToolkit.Mvvm.Messaging;
|
||||||
using GazpromApp.Messages;
|
using GazpromApp.Messages;
|
||||||
using GazpromApp.Models;
|
using GazpromApp.Models;
|
||||||
|
using GazpromApp.Utils;
|
||||||
|
|
||||||
namespace GazpromApp.ViewModels;
|
namespace GazpromApp.ViewModels;
|
||||||
|
|
||||||
public partial class MainWindowViewModel : ViewModelBase
|
public partial class MainWindowViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
public ObservableCollection<PointViewModel> Points { get; } = [];
|
public ObservableCollection<PointViewModel> Points { get; }
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private async Task AddPoint()
|
private async Task AddPoint()
|
||||||
@@ -38,6 +43,28 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
IsLineVisible = Points.Count > 0;
|
IsLineVisible = Points.Count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private void ImportPoint(Window w)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task ExportPoint(Window w)
|
||||||
|
{
|
||||||
|
var folder = await w.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions()
|
||||||
|
{
|
||||||
|
AllowMultiple = false,
|
||||||
|
SuggestedStartLocation =
|
||||||
|
await w.StorageProvider.TryGetFolderFromPathAsync(
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
|
||||||
|
});
|
||||||
|
foreach (var point in Points)
|
||||||
|
{
|
||||||
|
DataSerialization.SavePoint(point.GetPoint(), Path.Combine(HttpUtility.HtmlDecode(folder[0].Path.AbsolutePath), point.Name + ".json") );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Visual properties
|
// Visual properties
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@
|
|||||||
<NumericUpDown Grid.Column="3" AllowSpin="True" Width="120" VerticalAlignment="Center"
|
<NumericUpDown Grid.Column="3" AllowSpin="True" Width="120" VerticalAlignment="Center"
|
||||||
Value="{Binding PeriodValue}"/>
|
Value="{Binding PeriodValue}"/>
|
||||||
<ComboBox Grid.Column="4" Width="100" VerticalAlignment="Center" Margin="4,0,0,0"
|
<ComboBox Grid.Column="4" Width="100" VerticalAlignment="Center" Margin="4,0,0,0"
|
||||||
ItemsSource="{Binding (vm:EditEquipmentDialogViewModel).AllPeriods}"
|
ItemsSource="{Binding #Root.((vm:EditEquipmentDialogViewModel)DataContext).AllPeriods}"
|
||||||
SelectedItem="{Binding PeriodType, Mode=TwoWay}"
|
SelectedItem="{Binding PeriodType, Mode=TwoWay}"
|
||||||
DisplayMemberBinding="{Binding ., Converter={StaticResource PeriodConverter}}"/>
|
DisplayMemberBinding="{Binding ., Converter={StaticResource PeriodConverter}}"/>
|
||||||
<Button Grid.Column="5" Margin="0,0,12,0" HorizontalAlignment="Right" VerticalAlignment="Center"
|
<Button Grid.Column="5" Margin="0,0,12,0" HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
Width="1436" Height="720"
|
Width="1436" Height="720"
|
||||||
x:Class="GazpromApp.Views.MainWindow"
|
x:Class="GazpromApp.Views.MainWindow"
|
||||||
x:DataType="vm:MainWindowViewModel"
|
x:DataType="vm:MainWindowViewModel"
|
||||||
|
x:Name="Window"
|
||||||
Icon="/Assets/gazpromapp.ico"
|
Icon="/Assets/gazpromapp.ico"
|
||||||
Title="GazpromApp"
|
Title="GazpromApp"
|
||||||
WindowStartupLocation="CenterScreen">
|
WindowStartupLocation="CenterScreen">
|
||||||
@@ -42,7 +43,8 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</MenuItem.Header>
|
</MenuItem.Header>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem>
|
<MenuItem Command="{Binding ExportPointCommand}"
|
||||||
|
CommandParameter="{Binding #Window}">
|
||||||
<MenuItem.Header>
|
<MenuItem.Header>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Image Width="24" Height="24" Source="avares://GazpromApp/Assets/ic_fluent_arrow_export_ltr_24_filled (Custom).png"/>
|
<Image Width="24" Height="24" Source="avares://GazpromApp/Assets/ic_fluent_arrow_export_ltr_24_filled (Custom).png"/>
|
||||||
|
|||||||
Binary file not shown.
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("GazpromApp")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("GazpromApp")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2a8f8d2714fbf16f8b576c0df1cc1439e63924d0")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+915c7a7c5ec49dae4fabb6a5def0aa05d90783a6")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("GazpromApp")]
|
[assembly: System.Reflection.AssemblyProductAttribute("GazpromApp")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("GazpromApp")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("GazpromApp")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
e3eb625a6811d3ba189fee7ab939040462cf2260b099c0651fd6ad4eaff5612d
|
21fc2377da7e1819564fca788d76eb9386fb849b5d97c9fa58834904b0020d89
|
||||||
|
|||||||
Reference in New Issue
Block a user