Files
BeWoPlaner/BeWo/ViewModel/View/AcceptCancelDialogViewModel.cs

74 lines
1.4 KiB
C#
Raw Permalink Normal View History

2025-12-30 12:35:43 +01:00
using DevExpress.Mvvm;
using DevExpress.Mvvm.POCO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2026-06-05 14:56:49 +02:00
using System.Windows;
2025-12-30 12:35:43 +01:00
using System.Windows.Input;
namespace BeWo.ViewModel.View
{
2026-06-05 14:56:49 +02:00
public abstract class AcceptCancelDialogViewModel : DialogViewModel
2025-12-30 12:35:43 +01:00
{
2026-06-05 14:56:49 +02:00
public DelegateCommand SaveCommand { get; set; }
2025-12-30 12:35:43 +01:00
2026-06-05 14:56:49 +02:00
protected AcceptCancelDialogViewModel() : base()
2025-12-30 12:35:43 +01:00
{
2026-06-05 14:56:49 +02:00
SaveCommand = new DelegateCommand(Save, canSave, false);
2025-12-30 12:35:43 +01:00
}
2026-06-05 14:56:49 +02:00
protected virtual void Save()
{
throw new NotImplementedException();
}
2025-12-30 12:35:43 +01:00
2026-06-05 14:56:49 +02:00
protected virtual bool canSave()
2025-12-30 12:35:43 +01:00
{
2026-06-05 14:56:49 +02:00
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();
};
2025-12-30 12:35:43 +01:00
}
2026-06-05 14:56:49 +02:00
protected void DataSave(DCType dCType)
2025-12-30 12:35:43 +01:00
{
2026-06-05 14:56:49 +02:00
DataSaved?.Invoke(this, dCType);
2025-12-30 12:35:43 +01:00
Close();
}
2026-06-05 14:56:49 +02:00
protected override void Close()
{
base.Close();
}
protected override bool canSave()
2025-12-30 12:35:43 +01:00
{
2026-06-05 14:56:49 +02:00
return ViewModel.IsNew || ViewModel.IsDirty;
2025-12-30 12:35:43 +01:00
}
2026-06-05 14:56:49 +02:00
protected virtual bool isDirty()
2025-12-30 12:35:43 +01:00
{
2026-06-05 14:56:49 +02:00
return false;
2025-12-30 12:35:43 +01:00
}
}
}