Code clean up
This commit is contained in:
+3
-4
@@ -1,15 +1,14 @@
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Data.Core;
|
||||
using Avalonia.Data.Core.Plugins;
|
||||
using System.Linq;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using GazpromApp.ViewModels;
|
||||
using GazpromApp.Views;
|
||||
|
||||
namespace GazpromApp;
|
||||
|
||||
public partial class App : Application
|
||||
public class App : Application
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -25,7 +24,7 @@ public partial class App : Application
|
||||
DisableAvaloniaDataAnnotationValidation();
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
DataContext = new MainWindowViewModel(),
|
||||
DataContext = new MainWindowViewModel()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using GazpromApp.ViewModels;
|
||||
using CommunityToolkit.Mvvm.Messaging.Messages;
|
||||
using CommunityToolkit.Mvvm.Messaging.Messages;
|
||||
using GazpromApp.ViewModels;
|
||||
|
||||
namespace GazpromApp.Messages;
|
||||
|
||||
public class NewPointMessage : AsyncRequestMessage<PointViewModel?>;
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GazpromApp.Models;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Equipment
|
||||
|
||||
// EF stuff
|
||||
public Image? Image { get; set; }
|
||||
public Models.Point? Point { get; set; }
|
||||
public Point? Point { get; set; }
|
||||
public List<Property> Properties { get; set; } = [];
|
||||
public List<Inspection> Inspections { get; set; } = [];
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using GazpromApp.Enums;
|
||||
using GazpromApp.ViewModels;
|
||||
|
||||
namespace GazpromApp.Models;
|
||||
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@ public class Inspection
|
||||
public string PeriodType { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public float PeriodValue { get; set; }
|
||||
|
||||
public int EquipmentId { get; set; }
|
||||
|
||||
// EF stuff
|
||||
public Equipment? Equipment { get; set; }
|
||||
public Equipment? Equipment { get; } = new();
|
||||
}
|
||||
+2
-2
@@ -14,9 +14,9 @@ public class Point
|
||||
[Required]
|
||||
public string? Description { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Latitude { get; set; } = 0;
|
||||
public double Latitude { get; set; }
|
||||
[Required]
|
||||
public double Longitude { get; set; } = 0;
|
||||
public double Longitude { get; set; }
|
||||
// EF stuff
|
||||
public List<Image> Images { get; set; } = [];
|
||||
public List<Equipment> Equipment { get; set; } = [];
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace GazpromApp.Models;
|
||||
|
||||
public class Property
|
||||
@@ -15,6 +16,6 @@ public class Property
|
||||
// EF stuff
|
||||
public Property? Parent { get; set; }
|
||||
public List<Property> Properties{ get; set; } = [];
|
||||
public List<Models.Point> Points { get; set; } = [];
|
||||
public List<Point> Points { get; set; } = [];
|
||||
public List<Equipment> Equipment { get; } = [];
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
using Avalonia;
|
||||
using System;
|
||||
using System;
|
||||
using Avalonia;
|
||||
|
||||
namespace GazpromApp;
|
||||
|
||||
@@ -7,7 +7,7 @@ sealed class Program
|
||||
{
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||
// yet and stuff might break.
|
||||
// yet, and stuff might break.
|
||||
[STAThread]
|
||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GazpromApp.Utils;
|
||||
|
||||
public class AppDbContext : DbContext
|
||||
{
|
||||
public DbSet<Models.Image> Image { get; set; }
|
||||
public DbSet<Image> Image { get; set; }
|
||||
public DbSet<Equipment> Equipment { get; set; }
|
||||
public DbSet<Models.Point> Point { get; set; }
|
||||
public DbSet<Point> Point { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
@@ -20,7 +20,7 @@ public class AppDbContext : DbContext
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
// Images
|
||||
modelBuilder.Entity<Models.Point>()
|
||||
modelBuilder.Entity<Point>()
|
||||
.HasMany(e => e.Images)
|
||||
.WithMany(e => e.Points);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class AppDbContext : DbContext
|
||||
.HasForeignKey(e => e.ImageId);
|
||||
|
||||
// Properties
|
||||
modelBuilder.Entity<Models.Point>()
|
||||
modelBuilder.Entity<Point>()
|
||||
.HasMany(e => e.Properties)
|
||||
.WithMany(e => e.Points);
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using GazpromApp.Enums;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.ViewModels;
|
||||
|
||||
namespace GazpromApp.Utils;
|
||||
@@ -19,11 +18,11 @@ public static class DateCalculator
|
||||
return [inspection.InspectionDate.DateTime, firstFutureDate];
|
||||
}
|
||||
|
||||
DateTime futureDate = Enumerable.Range(1, int.MaxValue)
|
||||
var 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);
|
||||
var pastDate = SubtractPeriod(futureDate, inspection.PeriodType, inspection.PeriodValue);
|
||||
|
||||
return [pastDate, futureDate];
|
||||
}
|
||||
@@ -36,6 +35,7 @@ public static class DateCalculator
|
||||
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)
|
||||
PeriodType.Unknown => throw new ArgumentException("Invalid period type"),
|
||||
_ => throw new ArgumentException("Invalid period type")
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
@@ -43,7 +42,7 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
Image = new ImageViewModel(equipment.Image ?? new Image());
|
||||
Properties = new ObservableCollection<PropertyViewModel>(equipment.Properties.Select(e => new PropertyViewModel(e)));
|
||||
|
||||
List<DateTime[]> times = (equipment.Inspections.Select(e => new InspectionViewModel(e)))
|
||||
var times = equipment.Inspections.Select(e => new InspectionViewModel(e))
|
||||
.Select(e => e.GetNearestDates())
|
||||
.ToList();
|
||||
|
||||
@@ -62,12 +61,12 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
|
||||
public Equipment GetEquipment()
|
||||
{
|
||||
return new Equipment()
|
||||
return new Equipment
|
||||
{
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Image = Image?.GetImage(),
|
||||
Inspections = Inspections.Select(e => e.GetInspection()).ToList(),
|
||||
Inspections = Inspections.Select(e => e.GetInspection()).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public partial class ErrorViewModel : ViewModelBase
|
||||
w.Close();
|
||||
}
|
||||
|
||||
private ErrorSeverity severity;
|
||||
private readonly ErrorSeverity _severity;
|
||||
|
||||
// Visual and other properties
|
||||
[ObservableProperty] private bool _isErrorVisible;
|
||||
@@ -38,7 +38,7 @@ public partial class ErrorViewModel : ViewModelBase
|
||||
{
|
||||
Title = error.Title;
|
||||
Message = error.Message;
|
||||
severity = error.Severity;
|
||||
_severity = error.Severity;
|
||||
switch (error.Severity)
|
||||
{
|
||||
case ErrorSeverity.Error:
|
||||
@@ -48,21 +48,20 @@ public partial class ErrorViewModel : ViewModelBase
|
||||
IsWarnVisible = true;
|
||||
break;
|
||||
case ErrorSeverity.Message:
|
||||
IsInfoVisible = true;
|
||||
break;
|
||||
default:
|
||||
IsInfoVisible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public Error GetError()
|
||||
{
|
||||
Error error = new Error()
|
||||
var error = new Error
|
||||
{
|
||||
Title = Title,
|
||||
Message = Message,
|
||||
Severity = severity,
|
||||
Severity = _severity
|
||||
};
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@ public partial class ImageViewModel : ViewModelBase
|
||||
|
||||
public Image GetImage()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
var ms = new MemoryStream();
|
||||
FileName?.Save(ms);
|
||||
return new Image()
|
||||
return new Image
|
||||
{
|
||||
Bytes = ms.ToArray(),
|
||||
Equipment = Equipment ?? [],
|
||||
Points = Points ?? [],
|
||||
Points = Points ?? []
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public partial class InspectionViewModel : ViewModelBase
|
||||
// Visual properties
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isEditing = false;
|
||||
private bool _isEditing;
|
||||
|
||||
public InspectionViewModel()
|
||||
{
|
||||
@@ -39,7 +39,7 @@ public partial class InspectionViewModel : ViewModelBase
|
||||
|
||||
public Inspection GetInspection()
|
||||
{
|
||||
return new Inspection()
|
||||
return new Inspection
|
||||
{
|
||||
Name = Name,
|
||||
InspectionDate = InspectionDate,
|
||||
|
||||
@@ -26,7 +26,7 @@ public partial class PointViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private List<Property>? _properties;
|
||||
|
||||
public PointViewModel(Models.Point point)
|
||||
public PointViewModel(Point point)
|
||||
{
|
||||
Name = point.Name;
|
||||
Description = point.Description;
|
||||
@@ -37,14 +37,15 @@ public partial class PointViewModel : ViewModelBase
|
||||
Properties = point.Properties;
|
||||
}
|
||||
|
||||
public Models.Point GetPoint()
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public Point GetPoint()
|
||||
{
|
||||
return new Models.Point()
|
||||
return new Point
|
||||
{
|
||||
Name = this.Name,
|
||||
Description = this.Description,
|
||||
Equipment = this.Equipment ?? [],
|
||||
Properties = this.Properties ?? [],
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Equipment = Equipment ?? [],
|
||||
Properties = Properties ?? []
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
@@ -26,7 +25,7 @@ public partial class PropertyViewModel : ViewModelBase
|
||||
|
||||
public Property GetProperty(Property? parent = null)
|
||||
{
|
||||
Property p = new Property
|
||||
var p = new Property
|
||||
{
|
||||
Name = Name,
|
||||
Value = Value,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -13,6 +12,7 @@ using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Enums;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
using Image = GazpromApp.Models.Image;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
@@ -54,26 +54,26 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async Task AddImage(Window w)
|
||||
{
|
||||
IReadOnlyList<IStorageFile> files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
|
||||
var files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
AllowMultiple = false,
|
||||
Title = "Выберите картинку",
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll],
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll]
|
||||
});
|
||||
|
||||
IsImageSelected = files.Count > 0;
|
||||
|
||||
try
|
||||
{
|
||||
Image = IsImageSelected ? new ImageViewModel(new Models.Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(files[0].Path.AbsolutePath)) } : null;
|
||||
Image = IsImageSelected ? new ImageViewModel(new Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(files[0].Path.AbsolutePath)) } : null;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
Error error = new Error()
|
||||
var error = new Error
|
||||
{
|
||||
Title = "Ошибка обработки картинки",
|
||||
Message = "Картинка не была добавлена",
|
||||
Severity = ErrorSeverity.Error,
|
||||
Severity = ErrorSeverity.Error
|
||||
};
|
||||
_ = await WeakReferenceMessenger.Default.Send(new ErrorMessage(new ErrorViewModel(error)));
|
||||
|
||||
@@ -142,13 +142,13 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
|
||||
private void CompleteEdit()
|
||||
{
|
||||
IsClosed = true;
|
||||
Equipment equipment = new Equipment
|
||||
var equipment = new Equipment
|
||||
{
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Image = Image?.GetImage(),
|
||||
Inspections = Inspections.Select(e => e.GetInspection()).ToList(),
|
||||
Properties = Properties.Select(e => e.GetProperty()).ToList(),
|
||||
Properties = Properties.Select(e => e.GetProperty()).ToList()
|
||||
};
|
||||
WeakReferenceMessenger.Default.Send(new EditEquipmentDone(new EquipmentViewModel(equipment)));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
@@ -14,7 +12,6 @@ using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Enums;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.Views;
|
||||
using Image = GazpromApp.Models.Image;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
@@ -54,11 +51,11 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async Task AddImage(Window w)
|
||||
{
|
||||
IReadOnlyList<IStorageFile> files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
|
||||
var files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
AllowMultiple = true,
|
||||
Title = "Выберите одну или несколько картинок",
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll],
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll]
|
||||
});
|
||||
foreach (var file in files)
|
||||
{
|
||||
@@ -68,11 +65,11 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
Error error = new Error()
|
||||
var error = new Error
|
||||
{
|
||||
Title = "Ошибка обработки картинки",
|
||||
Message = $"Картинка не была добавлена: \"{HttpUtility.UrlDecode(file.Name)}\"",
|
||||
Severity = ErrorSeverity.Error,
|
||||
Severity = ErrorSeverity.Error
|
||||
};
|
||||
_ = await WeakReferenceMessenger.Default.Send(new ErrorMessage(new ErrorViewModel(error)));
|
||||
}
|
||||
@@ -96,7 +93,7 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async Task AddEquipment()
|
||||
{
|
||||
EquipmentViewModel? equipment = await WeakReferenceMessenger.Default.Send(new NewEquipmentMessage());
|
||||
var equipment = await WeakReferenceMessenger.Default.Send(new NewEquipmentMessage());
|
||||
|
||||
if (equipment != null)
|
||||
Equipment.Add(equipment);
|
||||
@@ -107,7 +104,7 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async Task EditEquipment(EquipmentViewModel equipment)
|
||||
{
|
||||
EquipmentViewModel e = await WeakReferenceMessenger.Default.Send(new EditEquipmentMessage(equipment)) ?? equipment;
|
||||
var e = await WeakReferenceMessenger.Default.Send(new EditEquipmentMessage(equipment)) ?? equipment;
|
||||
Equipment[Equipment.IndexOf(equipment)] = e;
|
||||
}
|
||||
|
||||
@@ -145,13 +142,13 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
private void CompleteEdit()
|
||||
{
|
||||
IsClosed = true;
|
||||
Point point = new Point()
|
||||
var point = new Point
|
||||
{
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Images = Images.Select(e => e.GetImage()).ToList(),
|
||||
Equipment = Equipment.Select(e => e.GetEquipment()).ToList(),
|
||||
Properties = Properties.Select(e => e.GetProperty()).ToList(),
|
||||
Properties = Properties.Select(e => e.GetProperty()).ToList()
|
||||
};
|
||||
WeakReferenceMessenger.Default.Send(new EditPointDone(new PointViewModel(point)));
|
||||
}
|
||||
@@ -234,8 +231,8 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
Value = "Property Value",
|
||||
Properties = [],
|
||||
Parent = null
|
||||
},
|
||||
],
|
||||
}
|
||||
],
|
||||
Parent = null
|
||||
},
|
||||
new PropertyViewModel
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GazpromApp.Messages;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
@@ -16,7 +16,7 @@ public partial class MainWindowViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async Task AddPoint()
|
||||
{
|
||||
PointViewModel? point = await WeakReferenceMessenger.Default.Send(new NewPointMessage());
|
||||
var point = await WeakReferenceMessenger.Default.Send(new NewPointMessage());
|
||||
|
||||
if (point != null)
|
||||
Points.Add(point);
|
||||
@@ -27,7 +27,7 @@ public partial class MainWindowViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async Task EditPoint(PointViewModel point)
|
||||
{
|
||||
PointViewModel p = await WeakReferenceMessenger.Default.Send(new EditPointMessage(point)) ?? point;
|
||||
var p = await WeakReferenceMessenger.Default.Send(new EditPointMessage(point)) ?? point;
|
||||
Points[Points.IndexOf(point)] = p;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Avalonia.Controls;
|
||||
@@ -11,6 +10,7 @@ using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Enums;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
using Image = GazpromApp.Models.Image;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
@@ -30,26 +30,26 @@ public partial class NewEquipmentDialogViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async Task AddImage(Window w)
|
||||
{
|
||||
IReadOnlyList<IStorageFile> files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
|
||||
var files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
AllowMultiple = false,
|
||||
Title = "Выберите картинку",
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll],
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll]
|
||||
});
|
||||
|
||||
IsImageSelected = files.Count > 0;
|
||||
|
||||
try
|
||||
{
|
||||
Image = IsImageSelected ? new ImageViewModel(new Models.Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(files[0].Path.AbsolutePath)) } : null;
|
||||
Image = IsImageSelected ? new ImageViewModel(new Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(files[0].Path.AbsolutePath)) } : null;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
Error error = new Error()
|
||||
var error = new Error
|
||||
{
|
||||
Title = "Ошибка обработки картинки",
|
||||
Message = "Картинка не была добавлена",
|
||||
Severity = ErrorSeverity.Error,
|
||||
Severity = ErrorSeverity.Error
|
||||
};
|
||||
_ = await WeakReferenceMessenger.Default.Send(new ErrorMessage(new ErrorViewModel(error)));
|
||||
|
||||
@@ -69,7 +69,7 @@ public partial class NewEquipmentDialogViewModel : ViewModelBase
|
||||
[RelayCommand (CanExecute = nameof(CanEnterEquipment))]
|
||||
private void EnterEquipment()
|
||||
{
|
||||
Equipment equipment = new Equipment()
|
||||
var equipment = new Equipment
|
||||
{
|
||||
Name = Name,
|
||||
Description = Description ?? string.Empty,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
@@ -34,11 +32,11 @@ public partial class NewPointDialogViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async Task AddImage(Window w)
|
||||
{
|
||||
IReadOnlyList<IStorageFile> files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
|
||||
var files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
AllowMultiple = true,
|
||||
Title = "Выберите одну или несколько картинок",
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll],
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll]
|
||||
});
|
||||
foreach (var file in files)
|
||||
{
|
||||
@@ -48,11 +46,11 @@ public partial class NewPointDialogViewModel : ViewModelBase
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
Error error = new Error()
|
||||
var error = new Error
|
||||
{
|
||||
Title = "Ошибка обработки картинки",
|
||||
Message = $"Картинка не была добавлена: \"{HttpUtility.UrlDecode(file.Name)}\"",
|
||||
Severity = ErrorSeverity.Error,
|
||||
Severity = ErrorSeverity.Error
|
||||
};
|
||||
_ = await WeakReferenceMessenger.Default.Send(new ErrorMessage(new ErrorViewModel(error)));
|
||||
}
|
||||
@@ -73,7 +71,7 @@ public partial class NewPointDialogViewModel : ViewModelBase
|
||||
[RelayCommand (CanExecute = nameof(CanEnterPoint))]
|
||||
private void EnterPoint()
|
||||
{
|
||||
Point point = new Point()
|
||||
var point = new Point
|
||||
{
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
|
||||
@@ -2,6 +2,4 @@
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public class ViewModelBase : ObservableObject
|
||||
{
|
||||
}
|
||||
public class ViewModelBase : ObservableObject;
|
||||
@@ -18,7 +18,7 @@
|
||||
<vm:EditEquipmentDialogViewModel/>
|
||||
</Design.DataContext>
|
||||
<Window.Resources>
|
||||
<!-- ReSharper disable once Xaml.RedundantResource -->
|
||||
<!-- ReSharper disable Xaml.RedundantResource -->
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.ThemeDictionaries>
|
||||
<ResourceDictionary x:Key="Light">
|
||||
@@ -31,6 +31,7 @@
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.ThemeDictionaries>
|
||||
</ResourceDictionary>
|
||||
<!-- ReSharper restore Xaml.RedundantResource -->
|
||||
<enums:PeriodConverter x:Key="PeriodConverter"/>
|
||||
</Window.Resources>
|
||||
<Grid RowDefinitions="70,150,*,Auto" ColumnDefinitions="*,100,220" x:Name="Root">
|
||||
@@ -116,7 +117,7 @@
|
||||
<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}"
|
||||
ItemsSource="{Binding (vm:EditEquipmentDialogViewModel).AllPeriods}"
|
||||
SelectedItem="{Binding PeriodType, Mode=TwoWay}"
|
||||
DisplayMemberBinding="{Binding ., Converter={StaticResource PeriodConverter}}"/>
|
||||
<Button Grid.Column="5" Margin="0,0,12,0" HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.ViewModels;
|
||||
|
||||
namespace GazpromApp.Views;
|
||||
|
||||
public partial class EditEquipmentDialog : Window
|
||||
{
|
||||
public Equipment? Equipment;
|
||||
|
||||
public EditEquipmentDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -23,7 +18,7 @@ public partial class EditEquipmentDialog : Window
|
||||
// view image
|
||||
WeakReferenceMessenger.Default.Register<EditEquipmentDialog, ViewImageMessage>(this, static (w, m) =>
|
||||
{
|
||||
ImageView dialog = new ImageView()
|
||||
var dialog = new ImageView
|
||||
{
|
||||
DataContext = m.Image
|
||||
};
|
||||
@@ -33,7 +28,7 @@ public partial class EditEquipmentDialog : Window
|
||||
// error handling
|
||||
WeakReferenceMessenger.Default.Register<EditEquipmentDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
var dialog = new ErrorView
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
<SolidColorBrush x:Key="BorderBrush" Color="#d3d3d3"/>
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary x:Key="Dark">
|
||||
<!-- ReSharper disable once Xaml.RedundantResource -->
|
||||
<SolidColorBrush x:Key="BackgroundBrush" Color="#101010"/>
|
||||
<!-- ReSharper disable once Xaml.RedundantResource -->
|
||||
<SolidColorBrush x:Key="BorderBrush" Color="#303030"/>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.ThemeDictionaries>
|
||||
|
||||
@@ -2,15 +2,12 @@
|
||||
using Avalonia.Controls;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.ViewModels;
|
||||
|
||||
namespace GazpromApp.Views;
|
||||
|
||||
public partial class EditPointDialog : Window
|
||||
{
|
||||
public Point? Point;
|
||||
|
||||
public EditPointDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -21,7 +18,7 @@ public partial class EditPointDialog : Window
|
||||
// view image
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, ViewImageMessage>(this, static (w, m) =>
|
||||
{
|
||||
ImageView dialog = new ImageView()
|
||||
var dialog = new ImageView
|
||||
{
|
||||
DataContext = m.Image
|
||||
};
|
||||
@@ -31,7 +28,7 @@ public partial class EditPointDialog : Window
|
||||
// error
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
var dialog = new ErrorView
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
@@ -42,7 +39,7 @@ public partial class EditPointDialog : Window
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, NewEquipmentMessage>(this, (w, m) =>
|
||||
{
|
||||
WeakReferenceMessenger.Default.Unregister<ErrorMessage>(this);
|
||||
NewEquipmentDialog dialog = new NewEquipmentDialog()
|
||||
var dialog = new NewEquipmentDialog
|
||||
{
|
||||
DataContext = new NewEquipmentDialogViewModel()
|
||||
};
|
||||
@@ -54,7 +51,7 @@ public partial class EditPointDialog : Window
|
||||
{
|
||||
WeakReferenceMessenger.Default.Unregister<ViewImageMessage>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<ErrorMessage>(this);
|
||||
EditEquipmentDialog dialog = new EditEquipmentDialog()
|
||||
var dialog = new EditEquipmentDialog
|
||||
{
|
||||
DataContext = new EditEquipmentDialogViewModel(m.Equipment)
|
||||
};
|
||||
@@ -66,7 +63,7 @@ public partial class EditPointDialog : Window
|
||||
{
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
var dialog = new ErrorView
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
@@ -79,7 +76,7 @@ public partial class EditPointDialog : Window
|
||||
{
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, ViewImageMessage>(this, static (w, m) =>
|
||||
{
|
||||
ImageView dialog = new ImageView()
|
||||
var dialog = new ImageView
|
||||
{
|
||||
DataContext = m.Image
|
||||
};
|
||||
@@ -88,7 +85,7 @@ public partial class EditPointDialog : Window
|
||||
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
var dialog = new ErrorView
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace GazpromApp.Views;
|
||||
|
||||
@@ -11,8 +9,8 @@ public partial class ErrorView : Window
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
if (Design.IsDesignMode)
|
||||
return;
|
||||
// if (Design.IsDesignMode)
|
||||
// return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace GazpromApp.Views;
|
||||
|
||||
@@ -13,6 +11,6 @@ public partial class ImageView : Window
|
||||
if (Design.IsDesignMode)
|
||||
return;
|
||||
|
||||
this.ExtendClientAreaToDecorationsHint = true;
|
||||
ExtendClientAreaToDecorationsHint = true;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,9 @@
|
||||
<SolidColorBrush x:Key="BorderBrush" Color="#d3d3d3"/>
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary x:Key="Dark">
|
||||
<!-- ReSharper disable once Xaml.RedundantResource -->
|
||||
<SolidColorBrush x:Key="BackgroundBrush" Color="#101010"/>
|
||||
<!-- ReSharper disable once Xaml.RedundantResource -->
|
||||
<SolidColorBrush x:Key="BorderBrush" Color="#303030"/>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.ThemeDictionaries>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Avalonia.Controls;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.ViewModels;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
|
||||
namespace GazpromApp.Views;
|
||||
|
||||
@@ -16,7 +16,7 @@ public partial class MainWindow : Window
|
||||
|
||||
WeakReferenceMessenger.Default.Register<MainWindow, NewPointMessage>(this, static (w, m) =>
|
||||
{
|
||||
NewPointDialog dialog = new NewPointDialog()
|
||||
var dialog = new NewPointDialog
|
||||
{
|
||||
DataContext = new NewPointDialogViewModel()
|
||||
};
|
||||
@@ -25,10 +25,9 @@ public partial class MainWindow : Window
|
||||
|
||||
WeakReferenceMessenger.Default.Register<MainWindow, EditPointMessage>(this, static (w, m) =>
|
||||
{
|
||||
EditPointDialog dialog = new EditPointDialog()
|
||||
var dialog = new EditPointDialog
|
||||
{
|
||||
DataContext = new EditPointDialogViewModel(m.Point),
|
||||
Point = m.Point.GetPoint()
|
||||
DataContext = new EditPointDialogViewModel(m.Point)
|
||||
};
|
||||
m.Reply(dialog.ShowDialog<PointViewModel?>(w));
|
||||
});
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class NewEquipmentDialog : Window
|
||||
// register to work with errors
|
||||
WeakReferenceMessenger.Default.Register<NewEquipmentDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
var dialog = new ErrorView
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class NewPointDialog : Window
|
||||
// register to work with errors
|
||||
WeakReferenceMessenger.Default.Register<NewPointDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
var dialog = new ErrorView
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
|
||||
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+72dc9b68743bc32f202a106f6161f2a4c5401a0c")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2a8f8d2714fbf16f8b576c0df1cc1439e63924d0")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("GazpromApp")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("GazpromApp")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
15ad954b97553ac87ab7a0c39a3000dca500a7ad2febeb4c503529c5bb6ac55b
|
||||
e3eb625a6811d3ba189fee7ab939040462cf2260b099c0651fd6ad4eaff5612d
|
||||
|
||||
Reference in New Issue
Block a user