Files
BeWoPlaner/BeWo/View/Detail/ModalViewWindow.xaml.cs

147 lines
5.3 KiB
C#
Raw Normal View History

2018-02-19 10:52:48 +01:00
using System;
using System.Diagnostics;
2018-02-19 10:52:48 +01:00
using System.Linq;
2016-06-27 01:45:38 +02:00
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using BeWo.Controls;
using BeWo.Core;
using Style = System.Windows.Style;
namespace BeWo.View.Detail
{
public partial class ModalViewWindow
{
2018-02-19 10:52:48 +01:00
private readonly bool _AllowSaveIfParentDirty;
2017-03-24 10:30:18 +01:00
public Action ModalEditViewUpdateCallback;
2016-06-27 01:45:38 +02:00
public BeWoView DetailView { get; set; }
public BeWoView ParentView { get; set; }
2018-02-19 10:52:48 +01:00
public Grid RootGrid => rootGrid;
2016-06-27 01:45:38 +02:00
2017-03-24 10:30:18 +01:00
public ModalViewWindow(BeWoView detailView, BeWoView parentView, bool allowSaveIfParentDirty)
2016-06-27 01:45:38 +02:00
{
InitializeComponent();
DetailView = detailView;
ParentView = parentView;
2018-02-19 10:52:48 +01:00
_AllowSaveIfParentDirty = allowSaveIfParentDirty;
2016-06-27 01:45:38 +02:00
rootGrid.Children.Add(DetailView);
InitCommandBindings();
2018-02-19 10:52:48 +01:00
if (BeWoApp.MainControl.ModalPopupBackGround == null)
{
2016-06-27 01:45:38 +02:00
BeWoApp.MainControl.ShowModalBackground();
2018-02-19 10:52:48 +01:00
}
2016-06-27 01:45:38 +02:00
MinWidth = detailView.MinWidth + 16;
MinHeight = 555;
Owner = parentView == null ? BeWoApp.CurrentBeWo.MainWindow : GetWindow(parentView);
Loaded += OnLoad;
Closing += delegate
{
2018-02-19 10:52:48 +01:00
if(BeWoApp.MainControl.OpenedModalViewWindows.Count > 0 && BeWoApp.MainControl.OpenedModalViewWindows.First().Equals(this))
{
2016-06-27 01:45:38 +02:00
BeWoApp.MainControl.CloseCurrentPopUp();
2018-02-19 10:52:48 +01:00
}
2016-06-27 01:45:38 +02:00
};
2018-02-19 10:52:48 +01:00
Closed += delegate
{
BeWoUtils.RemoveModalViewWindow();
};
((GroupBox) ((ShadowChrome) ((Grid) detailView.Content).Children[0]).Child).Style = BeWoApp.CurrentBeWo.Resources["MainContentGroupBoxWithoutMaximizeBtnStyle"] as Style;
2016-06-27 01:45:38 +02:00
}
private void OnLoad(object sender, RoutedEventArgs e)
{
if (BeWoApp.MainControl.OpenedModalViewWindows.Count > 1)
{
2018-02-19 10:52:48 +01:00
Left = BeWoApp.MainControl.ActualWidth/2 - ActualWidth/2 + 10*(BeWoApp.MainControl.OpenedModalViewWindows.Count - 1);
Top = BeWoApp.MainControl.ActualHeight/2 - ActualHeight/2 + 50*(BeWoApp.MainControl.OpenedModalViewWindows.Count - 1);
2016-06-27 01:45:38 +02:00
}
else
{
2018-02-19 10:52:48 +01:00
Left = BeWoApp.MainControl.ActualWidth / 2 - ActualWidth / 2;
Top = BeWoApp.MainControl.ActualHeight / 2 - ActualHeight / 2;
2016-06-27 01:45:38 +02:00
}
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
base.OnClosing(e);
2018-02-19 10:52:48 +01:00
if (!e.Cancel)
2016-06-27 01:45:38 +02:00
{
2018-02-19 10:52:48 +01:00
Owner?.Focus();
2016-06-27 01:45:38 +02:00
}
}
private void InitCommandBindings()
{
CommandBindings.Add(
new CommandBinding(
ApplicationCommands.Save,
(s, e) =>
{
if (ParentView != null)
2018-02-19 10:52:48 +01:00
{
if (!_AllowSaveIfParentDirty && ParentView.IsDirty)
2016-06-27 01:45:38 +02:00
{
MessageBox.Show("Bevor Sie an diesem Objekt eine Änderung durchführen können, müssen Sie das vorherige Objekt erst speichern!", "Speichern", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
2018-02-19 10:52:48 +01:00
}
2016-06-27 01:45:38 +02:00
if (!DetailView.SaveData())
2018-02-19 10:52:48 +01:00
{
2016-06-27 01:45:38 +02:00
return;
2018-02-19 10:52:48 +01:00
}
2016-06-27 01:45:38 +02:00
Close();
},
(s, e) => e.CanExecute = DetailView != null && DetailView.IsDirty));
CommandBindings.Add(new CommandBinding(BeWoCommands.Excel, (s, e) => DetailView.ExportToExcel(e.Parameter as string), (s, e) => e.CanExecute = DetailView != null && DetailView.CanExcelExport));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, (s, e) => DetailView.Delete(), (s, e) => e.CanExecute = DetailView != null && DetailView.CanDelete));
CommandBindings.Add(new CommandBinding(BeWoCommands.Word, (s, e) => DetailView.ExportToWord(e.Parameter as string), (s, e) => e.CanExecute = DetailView != null && DetailView.CanWordExport));
CommandBindings.Add(
new CommandBinding(
ApplicationCommands.Close,
(s, e) =>
{
if(ParentView != null)
2018-02-19 10:52:48 +01:00
{
2016-06-27 01:45:38 +02:00
if (ParentView.IsDirty)
{
Close();
return;
}
2018-02-19 10:52:48 +01:00
}
2016-06-27 01:45:38 +02:00
2018-02-19 10:52:48 +01:00
if (!DoSaveCheck())
{
2016-06-27 01:45:38 +02:00
return;
2018-02-19 10:52:48 +01:00
}
2016-06-27 01:45:38 +02:00
Close();
}, (s, e) => e.CanExecute = DetailView != null));
}
private bool DoSaveCheck()
{
return DetailView == null || DetailView.DoSaveCheck();
}
}
}