74 lines
1.4 KiB
C#
74 lines
1.4 KiB
C#
using DevExpress.Mvvm;
|
|
using DevExpress.Mvvm.POCO;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
|
|
namespace BeWo.ViewModel.View
|
|
{
|
|
public abstract class AcceptCancelDialogViewModel : DialogViewModel
|
|
{
|
|
public DelegateCommand SaveCommand { get; set; }
|
|
|
|
protected AcceptCancelDialogViewModel() : base()
|
|
{
|
|
SaveCommand = new DelegateCommand(Save, canSave, false);
|
|
}
|
|
|
|
protected virtual void Save()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
protected virtual bool canSave()
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public class AcceptCancelDialogViewModel<DCType, VMType> : AcceptCancelDialogViewModel where VMType : AbstractDCMapperVM<DCType> where DCType : new()
|
|
{
|
|
public event EventHandler<DCType> DataSaved;
|
|
|
|
public VMType ViewModel { get; set; }
|
|
|
|
public string AcceptButtonText => ViewModel.IsNew ? "Hinzufügen" : "Speichern";
|
|
|
|
public AcceptCancelDialogViewModel(VMType viewModel) : base()
|
|
{
|
|
ViewModel = viewModel;
|
|
|
|
ViewModel.PropertyChanged += (s, e) =>
|
|
{
|
|
SaveCommand.RaiseCanExecuteChanged();
|
|
};
|
|
}
|
|
|
|
protected void DataSave(DCType dCType)
|
|
{
|
|
DataSaved?.Invoke(this, dCType);
|
|
|
|
Close();
|
|
}
|
|
|
|
protected override void Close()
|
|
{
|
|
base.Close();
|
|
}
|
|
|
|
protected override bool canSave()
|
|
{
|
|
return ViewModel.IsNew || ViewModel.IsDirty;
|
|
}
|
|
|
|
protected virtual bool isDirty()
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|