147 lines
5.3 KiB
C#
147 lines
5.3 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
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
|
|
{
|
|
private readonly bool _AllowSaveIfParentDirty;
|
|
|
|
public Action ModalEditViewUpdateCallback;
|
|
|
|
public BeWoView DetailView { get; set; }
|
|
public BeWoView ParentView { get; set; }
|
|
public Grid RootGrid => rootGrid;
|
|
|
|
public ModalViewWindow(BeWoView detailView, BeWoView parentView, bool allowSaveIfParentDirty)
|
|
{
|
|
InitializeComponent();
|
|
DetailView = detailView;
|
|
ParentView = parentView;
|
|
_AllowSaveIfParentDirty = allowSaveIfParentDirty;
|
|
|
|
rootGrid.Children.Add(DetailView);
|
|
InitCommandBindings();
|
|
|
|
if (BeWoApp.MainControl.ModalPopupBackGround == null)
|
|
{
|
|
BeWoApp.MainControl.ShowModalBackground();
|
|
}
|
|
|
|
MinWidth = detailView.MinWidth + 16;
|
|
MinHeight = 555;
|
|
|
|
Owner = parentView == null ? BeWoApp.CurrentBeWo.MainWindow : GetWindow(parentView);
|
|
|
|
Loaded += OnLoad;
|
|
|
|
Closing += delegate
|
|
{
|
|
if(BeWoApp.MainControl.OpenedModalViewWindows.Count > 0 && BeWoApp.MainControl.OpenedModalViewWindows.First().Equals(this))
|
|
{
|
|
BeWoApp.MainControl.CloseCurrentPopUp();
|
|
}
|
|
};
|
|
|
|
Closed += delegate
|
|
{
|
|
BeWoUtils.RemoveModalViewWindow();
|
|
};
|
|
|
|
((GroupBox) ((ShadowChrome) ((Grid) detailView.Content).Children[0]).Child).Style = BeWoApp.CurrentBeWo.Resources["MainContentGroupBoxWithoutMaximizeBtnStyle"] as Style;
|
|
}
|
|
|
|
private void OnLoad(object sender, RoutedEventArgs e)
|
|
{
|
|
if (BeWoApp.MainControl.OpenedModalViewWindows.Count > 1)
|
|
{
|
|
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);
|
|
}
|
|
else
|
|
{
|
|
Left = BeWoApp.MainControl.ActualWidth / 2 - ActualWidth / 2;
|
|
Top = BeWoApp.MainControl.ActualHeight / 2 - ActualHeight / 2;
|
|
}
|
|
}
|
|
|
|
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
base.OnClosing(e);
|
|
|
|
if (!e.Cancel)
|
|
{
|
|
Owner?.Focus();
|
|
}
|
|
}
|
|
|
|
private void InitCommandBindings()
|
|
{
|
|
CommandBindings.Add(
|
|
new CommandBinding(
|
|
ApplicationCommands.Save,
|
|
(s, e) =>
|
|
{
|
|
if (ParentView != null)
|
|
{
|
|
if (!_AllowSaveIfParentDirty && ParentView.IsDirty)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
|
|
if (!DetailView.SaveData())
|
|
{
|
|
return;
|
|
}
|
|
|
|
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)
|
|
{
|
|
if (ParentView.IsDirty)
|
|
{
|
|
Close();
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!DoSaveCheck())
|
|
{
|
|
return;
|
|
}
|
|
|
|
Close();
|
|
|
|
}, (s, e) => e.CanExecute = DetailView != null));
|
|
}
|
|
|
|
private bool DoSaveCheck()
|
|
{
|
|
return DetailView == null || DetailView.DoSaveCheck();
|
|
}
|
|
}
|
|
}
|