Error handling system added
This commit is contained in:
@@ -30,6 +30,16 @@ public partial class EditEquipmentDialog : Window
|
||||
m.Reply(dialog.ShowDialog<ImageViewModel?>(w));
|
||||
});
|
||||
|
||||
// error handling
|
||||
WeakReferenceMessenger.Default.Register<EditEquipmentDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
m.Reply(dialog.ShowDialog<ErrorViewModel?>(w));
|
||||
});
|
||||
|
||||
// new property dialog
|
||||
|
||||
// edit property dialog
|
||||
@@ -50,6 +60,7 @@ public partial class EditEquipmentDialog : Window
|
||||
private void Window_OnClosed(object? sender, EventArgs e)
|
||||
{
|
||||
WeakReferenceMessenger.Default.Unregister<ViewImageMessage>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<ErrorMessage>(this);
|
||||
//
|
||||
//
|
||||
WeakReferenceMessenger.Default.Unregister<EditEquipmentDone>(this);
|
||||
|
||||
@@ -28,9 +28,20 @@ public partial class EditPointDialog : Window
|
||||
m.Reply(dialog.ShowDialog<ImageViewModel?>(w));
|
||||
});
|
||||
|
||||
// new equipment
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, NewEquipmentMessage>(this, static (w, m) =>
|
||||
// error
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
m.Reply(dialog.ShowDialog<ErrorViewModel?>(w));
|
||||
});
|
||||
|
||||
// new equipment
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, NewEquipmentMessage>(this, (w, m) =>
|
||||
{
|
||||
WeakReferenceMessenger.Default.Unregister<ErrorMessage>(this);
|
||||
NewEquipmentDialog dialog = new NewEquipmentDialog()
|
||||
{
|
||||
DataContext = new NewEquipmentDialogViewModel()
|
||||
@@ -42,6 +53,7 @@ public partial class EditPointDialog : Window
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, EditEquipmentMessage>(this, (w, m) =>
|
||||
{
|
||||
WeakReferenceMessenger.Default.Unregister<ViewImageMessage>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<ErrorMessage>(this);
|
||||
EditEquipmentDialog dialog = new EditEquipmentDialog()
|
||||
{
|
||||
DataContext = new EditEquipmentDialogViewModel(m.Equipment)
|
||||
@@ -49,8 +61,21 @@ public partial class EditPointDialog : Window
|
||||
m.Reply(dialog.ShowDialog<EquipmentViewModel?>(w));
|
||||
});
|
||||
|
||||
// re registering view image
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, EditEquipmentDone>(this, (w, m) =>
|
||||
// re registering error when new equipment done
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, NewEquipmentDone>(this, (_, _) =>
|
||||
{
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
m.Reply(dialog.ShowDialog<ErrorViewModel?>(w));
|
||||
});
|
||||
});
|
||||
|
||||
// re registering view image and error view
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, EditEquipmentDone>(this, (_, _) =>
|
||||
{
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, ViewImageMessage>(this, static (w, m) =>
|
||||
{
|
||||
@@ -60,6 +85,15 @@ public partial class EditPointDialog : Window
|
||||
};
|
||||
m.Reply(dialog.ShowDialog<ImageViewModel?>(w));
|
||||
});
|
||||
|
||||
WeakReferenceMessenger.Default.Register<EditPointDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
m.Reply(dialog.ShowDialog<ErrorViewModel?>(w));
|
||||
});
|
||||
});
|
||||
|
||||
// new property
|
||||
@@ -82,6 +116,7 @@ public partial class EditPointDialog : Window
|
||||
private void Window_OnClosed(object? sender, EventArgs e)
|
||||
{
|
||||
WeakReferenceMessenger.Default.Unregister<ViewImageMessage>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<ErrorMessage>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<NewEquipmentMessage>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<EditEquipmentMessage>(this);
|
||||
// new prop
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:GazpromApp.ViewModels"
|
||||
x:Name="Window"
|
||||
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="180"
|
||||
Width="400" Height="180"
|
||||
x:Class="GazpromApp.Views.ErrorView"
|
||||
x:DataType="vm:ErrorViewModel"
|
||||
Title="{Binding Title}"
|
||||
Icon="/Assets/ic_fluent_error_circle_24_filled (1) (Custom).png"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
Closing="Window_OnClosing"
|
||||
Closed="Window_OnClosed">
|
||||
<Design.DataContext>
|
||||
<vm:ErrorViewModel/>
|
||||
</Design.DataContext>
|
||||
<Grid x:Name="Root" Margin="16"
|
||||
ColumnDefinitions="50, *" RowDefinitions="50, *, Auto">
|
||||
<Image Grid.Row="0" Grid.Column="0"
|
||||
IsVisible="{Binding IsErrorVisible}"
|
||||
Source="avares://GazpromApp/Assets/ic_fluent_error_circle_24_filled (Custom).png"/>
|
||||
<Image Grid.Row="0" Grid.Column="0"
|
||||
IsVisible="{Binding IsWarnVisible}"
|
||||
Source="avares://GazpromApp/Assets/ic_fluent_warning_24_filled (Custom).png"/>
|
||||
<Image Grid.Row="0" Grid.Column="0"
|
||||
IsVisible="{Binding IsInfoVisible}"
|
||||
Source="avares://GazpromApp/Assets/ic_fluent_info_24_filled (Custom).png"/>
|
||||
<Panel Grid.Row="0" Grid.Column="1" Grid.RowSpan="2">
|
||||
<StackPanel Margin="8">
|
||||
<TextBlock Text="{Binding Title}" FontSize="20" MaxLines="2" TextWrapping="Wrap"/>
|
||||
<TextBlock Text="{Binding Message}" MaxLines="3" TextWrapping="Wrap"/>
|
||||
</StackPanel>
|
||||
</Panel>
|
||||
<Panel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Content="ОК"
|
||||
Command="{Binding OkCommand}"
|
||||
CommandParameter="{Binding #Window}"/>
|
||||
</StackPanel>
|
||||
</Panel>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace GazpromApp.Views;
|
||||
|
||||
public partial class ErrorView : Window
|
||||
{
|
||||
public ErrorView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
if (Design.IsDesignMode)
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Window_OnClosing(object? sender, WindowClosingEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void Window_OnClosed(object? sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Avalonia.Controls;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.ViewModels;
|
||||
|
||||
namespace GazpromApp.Views;
|
||||
|
||||
@@ -11,14 +12,26 @@ public partial class NewEquipmentDialog : Window
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// done entering new equipment
|
||||
WeakReferenceMessenger.Default.Register<NewEquipmentDialog, NewEquipmentDone>(this, static (w, m) =>
|
||||
{
|
||||
w.Close(m.Equipment);
|
||||
});
|
||||
|
||||
// register to work with errors
|
||||
WeakReferenceMessenger.Default.Register<NewEquipmentDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
m.Reply(dialog.ShowDialog<ErrorViewModel?>(w));
|
||||
});
|
||||
}
|
||||
|
||||
private void Window_OnClosed(object? sender, EventArgs e)
|
||||
{
|
||||
WeakReferenceMessenger.Default.Unregister<NewEquipmentDone>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<ErrorMessage>(this);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,8 @@
|
||||
x:DataType="vm:NewPointDialogViewModel"
|
||||
Title="Создание нового объекта"
|
||||
Icon="/Assets/ic_fluent_home_add_24_filled (Custom).png"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
WindowStartupLocation="CenterOwner"
|
||||
Closed="Window_OnClosed">
|
||||
<Design.DataContext>
|
||||
<vm:NewPointDialogViewModel/>
|
||||
</Design.DataContext>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Avalonia.Controls;
|
||||
using System;
|
||||
using Avalonia.Controls;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.ViewModels;
|
||||
|
||||
namespace GazpromApp.Views;
|
||||
|
||||
@@ -10,9 +12,25 @@ public partial class NewPointDialog : Window
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// done entering new point
|
||||
WeakReferenceMessenger.Default.Register<NewPointDialog, NewPointDone>(this, static (w, m) =>
|
||||
{
|
||||
w.Close(m.Point);
|
||||
});
|
||||
|
||||
// register to work with errors
|
||||
WeakReferenceMessenger.Default.Register<NewPointDialog, ErrorMessage>(this, static (w, m) =>
|
||||
{
|
||||
ErrorView dialog = new ErrorView()
|
||||
{
|
||||
DataContext = m.Error
|
||||
};
|
||||
m.Reply(dialog.ShowDialog<ErrorViewModel?>(w));
|
||||
});
|
||||
}
|
||||
|
||||
private void Window_OnClosed(object? sender, EventArgs e)
|
||||
{
|
||||
WeakReferenceMessenger.Default.Unregister<ErrorMessage>(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user