From f451c63926f1b87fa923f7e4bd49c0717dfd1a38 Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Mon, 26 Aug 2024 14:13:21 +0200 Subject: [PATCH] IsDirty bei ObservColl ImageDC --- .../WohneinheitGrundrissControl.xaml | 63 +++++++++++-------- .../WohneinheitGrundrissControl.xaml.cs | 24 +++---- BeWo/ViewModel/WohneinheitVM.cs | 18 +++++- Shared/DataContracts/ImageDC.cs | 1 + 4 files changed, 69 insertions(+), 37 deletions(-) diff --git a/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml b/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml index 02a72c86e..1156cfaec 100644 --- a/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml +++ b/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml @@ -8,10 +8,18 @@ mc:Ignorable="d"> + - + @@ -22,38 +30,43 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml.cs b/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml.cs index b7f6bfc67..8d3df2276 100644 --- a/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml.cs +++ b/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml.cs @@ -32,7 +32,7 @@ namespace BeWo.View.Detail.Wohneinheit this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) => { - BeWoApp.MainControl.CloseCurrentPopUp(); + BeWoApp.MainControl.CloseCurrentPopUp(); })); Images = images; @@ -49,19 +49,21 @@ namespace BeWo.View.Detail.Wohneinheit // Show open file dialog box bool? result = dialog.ShowDialog(); - // Process open file dialog box results - if (result == true) - { - // Open document - string filename = dialog.FileName; + if (result != true) + return; - var dc = new ImageDC(); + var info = new FileInfo(dialog.FileName); - dc.Filename = filename; - dc.ImageData = File.ReadAllBytes(filename); + if (!info.Exists) + return; - Images.Add(dc); - } + var dc = new ImageDC(); + + dc.Filename = info.Name; + dc.Fullname = info.FullName; + dc.ImageData = File.ReadAllBytes(info.FullName); + + Images.Add(dc); } private void MenuItem_Del_Click(object sender, RoutedEventArgs e) diff --git a/BeWo/ViewModel/WohneinheitVM.cs b/BeWo/ViewModel/WohneinheitVM.cs index 21316679b..8602e678d 100644 --- a/BeWo/ViewModel/WohneinheitVM.cs +++ b/BeWo/ViewModel/WohneinheitVM.cs @@ -32,6 +32,7 @@ namespace BeWo.ViewModel private string _Zusatznotiz; private string _Stock; private ObservableCollection _Grundrisse; + private bool _GrundrisseIsDirty; public WohneinheitVM() { @@ -248,14 +249,29 @@ namespace BeWo.ViewModel } public ObservableCollection Grundrisse { - get => _Grundrisse ?? (_Grundrisse = new ObservableCollection()); + get => _Grundrisse ?? (Grundrisse = new ObservableCollection()); set { + if (_Grundrisse is object) + _Grundrisse.CollectionChanged -= GrundrisseCollectionChanged; + _Grundrisse = value; + + if (_Grundrisse is object) + _Grundrisse.CollectionChanged += GrundrisseCollectionChanged; + FirePropertyChanged(nameof(Grundrisse)); } } + public void GrundrisseCollectionChanged(object sender, EventArgs e) + { + _GrundrisseIsDirty = true; + FirePropertyChanged(nameof(IsDirty)); + } + + public override bool IsDirty => base.IsDirty || _GrundrisseIsDirty; + public bool IsEinzelwohnung => string.IsNullOrEmpty(Zimmername); public string Caption => IsEinzelwohnung ? Wohnname : Zimmername ; diff --git a/Shared/DataContracts/ImageDC.cs b/Shared/DataContracts/ImageDC.cs index 5a86b5d2b..fcfb8422b 100644 --- a/Shared/DataContracts/ImageDC.cs +++ b/Shared/DataContracts/ImageDC.cs @@ -16,6 +16,7 @@ namespace BS.Shared.DataContracts //[DataMember] public long OwnerOid { get; set; } [DataMember] public string Filename { get; set; } + [DataMember] public string Fullname { get; set; } [DataMember] public byte[] ImageData { get; set; } public BitmapImage BitmapImage