105040 Update 增加数据丢失提示

This commit is contained in:
lihanbo 2025-01-24 08:46:21 +08:00
parent 860ce040ed
commit ea476590da
3 changed files with 33 additions and 17 deletions

View File

@ -21,6 +21,7 @@ using static Sinvo.EplanHpD.Plugin.WPFUI.Utils.LectotypeManager;
using System.Linq; using System.Linq;
using EPLAN.Harness.ProjectCore.Occurrences; using EPLAN.Harness.ProjectCore.Occurrences;
using Sinvo.EplanHpD.Plugin.WPFUI.Extension; using Sinvo.EplanHpD.Plugin.WPFUI.Extension;
using Sinvo.EplanHpD.Plugin.Service.Model;
namespace Sinvo.EplanHpD.Plugin.WPFUI.View namespace Sinvo.EplanHpD.Plugin.WPFUI.View
{ {
@ -95,11 +96,12 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
//var motor = Motor as MotorModel; //var motor = Motor as MotorModel;
if(Motor is CableLectotypeViewModel motor) if(Motor is CableLectotypeViewModel motor)
{ {
WeakReferenceMessenger.Default.Send<LectotypeMessage>(new LectotypeMessage WeakReferenceMessenger.Default.Send<LectotypeMessage,string>(new LectotypeMessage
(new System.Collections.Generic.Dictionary<string, string> (new System.Collections.Generic.Dictionary<string, string>
{ {
{motor.Motor.MotorModelStr,motor.Motor.AxisNo} {motor.Motor.MotorModelStr,motor.Motor.AxisNo}
})); }), "Lectotype"
);
} }
} }
@ -131,6 +133,15 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
{ {
if (ViewModel.SaveToDb()) if (ViewModel.SaveToDb())
{ {
if (Motor is CableLectotypeViewModel motor)
{
WeakReferenceMessenger.Default.Send(new LectotypeMessage
(new System.Collections.Generic.Dictionary<string, string>
{
{motor.Motor.MotorModelStr,motor.Motor.AxisNo}
}), "LectotypeSaved"
);
}
Growl.Success("保存成功", "CableLectotypeMessage"); Growl.Success("保存成功", "CableLectotypeMessage");
} }
else else

View File

@ -43,11 +43,13 @@
<Button <Button
Width="100" Width="100"
Click="btnOK_Click" Click="btnOK_Click"
Content="是" /> Content="是"
Style="{StaticResource ButtonDanger}" />
<Button <Button
Width="100" Width="100"
Click="btnCancel_Click" Click="btnCancel_Click"
Content="否" /> Content="否"
Style="{StaticResource ButtonInfo}" />
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</Grid> </Grid>

View File

@ -45,6 +45,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
this.DataContext = ViewModel = new LectotypeViewModel(docId); this.DataContext = ViewModel = new LectotypeViewModel(docId);
Application.Current.SetMainWindow(this); Application.Current.SetMainWindow(this);
RegisterEvent();
}
public void RegisterEvent()
{
WeakReferenceMessenger.Default.Register<CommonMessage>("RowDetailsVisibility", (sender, message) => WeakReferenceMessenger.Default.Register<CommonMessage>("RowDetailsVisibility", (sender, message) =>
{ {
if (System.Enum.IsDefined(typeof(DataGridRowDetailsVisibilityMode), message.Value)) if (System.Enum.IsDefined(typeof(DataGridRowDetailsVisibilityMode), message.Value))
@ -60,23 +64,29 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
DrawPDFDrawer.IsOpen = true; DrawPDFDrawer.IsOpen = true;
} }
}); });
WeakReferenceMessenger.Default.Register<LectotypeMessage>("Lectotype", (sender, message) => WeakReferenceMessenger.Default.Register<LectotypeMessage,string>("Lectotype", "Lectotype", (sender, message) =>
{ {
if (message.Value != null) if (message.Value != null)
{ {
ViewModel.AddNotSavedLectotype(message.Value); ViewModel.AddNotSavedLectotype(message.Value);
} }
}); });
WeakReferenceMessenger.Default.Register<LectotypeMessage>("LectotypeSaved", (sender, message) => WeakReferenceMessenger.Default.Register<LectotypeMessage,string>("LectotypeSaved", "LectotypeSaved", (sender, message) =>
{ {
if(message.Value != null) if (message.Value != null)
{ {
ViewModel.RemoveNotSavedLectotype(message.Value); ViewModel.RemoveNotSavedLectotype(message.Value);
} }
}); });
Growl.Register("CableLectotypeMessage", GrowlParent); Growl.Register("CableLectotypeMessage", GrowlParent);
} }
public void UnRegisterEvent()
{
WeakReferenceMessenger.Default.Unregister<CommonMessage>("RowDetailsVisibility");
WeakReferenceMessenger.Default.Unregister<OpenDrawMessage>("OpenDraw");
WeakReferenceMessenger.Default.Unregister<LectotypeMessage>("Lectotype");
WeakReferenceMessenger.Default.Unregister<LectotypeMessage>("LectotypeSaved");
}
private void Window_Loaded(object sender, RoutedEventArgs e) private void Window_Loaded(object sender, RoutedEventArgs e)
{ {
try try
@ -197,16 +207,9 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
private void Window_Closed(object sender, System.EventArgs e) private void Window_Closed(object sender, System.EventArgs e)
{ {
//DrawPDFHelper.ClearCache(); //DrawPDFHelper.ClearCache();
UnRegisterEvent();
WeakReferenceMessenger.Default.Unregister<CommonMessage>("RowDetailsVisibility");
WeakReferenceMessenger.Default.Unregister<OpenDrawMessage>("OpenDraw");
WeakReferenceMessenger.Default.Unregister<LectotypeMessage>("Lectotype");
WeakReferenceMessenger.Default.Unregister<LectotypeMessage>("LectotypeSaved");
MotorExcelHelper.Instance.CloseStream(); MotorExcelHelper.Instance.CloseStream();
} }
private void ViewDrawingButton_Click(object sender, RoutedEventArgs e) private void ViewDrawingButton_Click(object sender, RoutedEventArgs e)
{ {
if (sender is Button btn && btn.Tag != null) if (sender is Button btn && btn.Tag != null)