From d0756fad5661c6c6e4f373f4621a49cc0df0f649 Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Tue, 27 Aug 2024 14:17:14 +0200 Subject: [PATCH] Bereits existierendes Images weiter ausbauen - Verweis auf Wohneinheiten --- .../WohneinheitGrundrissControl.xaml | 2 +- .../WohneinheitGrundrissControl.xaml.cs | 2 +- BeWo/ViewModel/ImageVM.cs | 44 ++++-------- Data/Data.csproj | 1 - Data/Entities/Image.cs | 7 +- Data/Entities/ImageSimple.cs | 70 ------------------- Data/Entities/Wohneinheit.cs | 18 ++++- Data/Mappings/Image.hbm.xml | 8 ++- Data/Mappings/Wohneinheit.hbm.xml | 4 ++ ...nges_2024_08_27 Wohneinheit Grundrisse.txt | 25 +++++++ Service/DCEntityMapper/ImageDC_Image.cs | 48 +++++++++++++ Service/DCEntityMapper/ImageDC_ImageSimple.cs | 56 --------------- Service/DCEntityMapper/MapperFactory.cs | 6 +- Service/DCEntityMapper/PersonDC_Person.cs | 1 - .../WohneinheitDC_Wohneinheit.cs | 8 +++ Service/Service.csproj | 2 +- Shared/Core/Utils.cs | 21 ++++++ Shared/DataContracts/ImageDC.cs | 5 +- 18 files changed, 153 insertions(+), 175 deletions(-) delete mode 100644 Data/Entities/ImageSimple.cs create mode 100644 Model/Changes_2024_08_27 Wohneinheit Grundrisse.txt create mode 100644 Service/DCEntityMapper/ImageDC_Image.cs delete mode 100644 Service/DCEntityMapper/ImageDC_ImageSimple.cs diff --git a/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml b/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml index b9116e3f3..3fc314656 100644 --- a/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml +++ b/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml @@ -56,7 +56,7 @@ - + diff --git a/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml.cs b/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml.cs index 8cfec28c1..df8c5945f 100644 --- a/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml.cs +++ b/BeWo/View/Detail/Wohneinheit/WohneinheitGrundrissControl.xaml.cs @@ -64,7 +64,7 @@ namespace BeWo.View.Detail.Wohneinheit vm.Filename = info.Name; vm.Fullname = info.FullName; - vm.ImageData = File.ReadAllBytes(info.FullName); + vm.Original = File.ReadAllBytes(info.FullName); Images.VMList.Add(vm); } diff --git a/BeWo/ViewModel/ImageVM.cs b/BeWo/ViewModel/ImageVM.cs index b6654976b..21c7d3e3c 100644 --- a/BeWo/ViewModel/ImageVM.cs +++ b/BeWo/ViewModel/ImageVM.cs @@ -1,6 +1,7 @@ using System; using System.Windows.Media.Imaging; using BS.Shared; +using BS.Shared.Core; using BS.Shared.DataContracts; namespace BeWo.ViewModel @@ -9,7 +10,9 @@ namespace BeWo.ViewModel { private string _Filename; private string _Fullname; - private byte[] _ImageData; + private byte[] _Original; + private byte[] _MediumThumbnail; + private byte[] _SmallThumbnail; public ImageVM() : this(new ImageDC()) { @@ -33,7 +36,6 @@ namespace BeWo.ViewModel FirePropertyChanged(nameof(Filename)); } } - public string Fullname { get { return _Fullname; } @@ -47,55 +49,35 @@ namespace BeWo.ViewModel FirePropertyChanged(nameof(Fullname)); } } - - public byte[] ImageData + public byte[] Original { - get { return _ImageData; } + get { return _Original; } set { - if (!AreDifferent(_ImageData, value)) + if (!AreDifferent(_Original, value)) return; - _ImageData = value; - StoreDirtyInformation(AreDifferent(DataContract.ImageData, value), nameof(ImageData)); - FirePropertyChanged(nameof(ImageData)); + _Original = value; + StoreDirtyInformation(AreDifferent(DataContract.Original, value), nameof(Original)); + FirePropertyChanged(nameof(Original)); FirePropertyChanged(nameof(BitmapImage)); } } - public BitmapImage BitmapImage - { - get - { - if (ImageData != null) - { - using (var ms = new System.IO.MemoryStream(ImageData)) - { - var image = new BitmapImage(); - image.BeginInit(); - image.CacheOption = BitmapCacheOption.OnLoad; // here - image.StreamSource = ms; - image.EndInit(); - return image; - } - } - - return null; - } - } + public BitmapImage BitmapImage => Utils.CreateBitmapImageFromByteArray(Original); protected override void InitByDataContract(ImageDC pDataContract) { _Filename = pDataContract.Filename; _Fullname = pDataContract.Fullname; - _ImageData = pDataContract.ImageData; + _Original = pDataContract.Original; } protected override ImageDC MapToDataContract(ImageDC pDataContract, bool doCommit) { pDataContract.Filename = _Filename; pDataContract.Fullname = _Fullname; - pDataContract.ImageData = _ImageData; + pDataContract.Original = _Original; return pDataContract; } diff --git a/Data/Data.csproj b/Data/Data.csproj index d8923a623..78ca41230 100644 --- a/Data/Data.csproj +++ b/Data/Data.csproj @@ -220,7 +220,6 @@ - diff --git a/Data/Entities/Image.cs b/Data/Entities/Image.cs index 085d52709..2eaf8047d 100644 --- a/Data/Entities/Image.cs +++ b/Data/Entities/Image.cs @@ -13,11 +13,10 @@ namespace BeWo.Data.Entities _Tid = TableID.Image; } - public virtual byte[] Original { get; set; } - + public virtual string Filename { get; set; } + public virtual string Fullname { get; set; } + public virtual byte[] Original { get; set; } public virtual byte[] MediumThumbnail { get; set; } - public virtual byte[] SmallThumbnail { get; set; } - } } \ No newline at end of file diff --git a/Data/Entities/ImageSimple.cs b/Data/Entities/ImageSimple.cs deleted file mode 100644 index dbc1277c7..000000000 --- a/Data/Entities/ImageSimple.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; - -using BS.Shared; -using BS.Shared.Core; - -namespace BeWo.Data.Entities -{ - public class ImageSimple : BeWoEntityBase - { - private BeWoEntityBase _Parent; - - private string _Filename; - private string _Fullname; - private byte[] _ImageData; - - public ImageSimple() - { - _Tid = TableID.ImageSimple; - } - - public virtual BeWoEntityBase Parent - { - get { return _Parent; } - set - { - if (!AreDifferent(_Parent, value)) - return; - - _Parent = value; - } - } - - public virtual string Filename - { - get { return _Filename; } - set - { - if (!AreDifferent(_Filename, value)) - return; - - _Filename = value; - } - } - - public virtual string Fullname - { - get { return _Fullname; } - set - { - if (!AreDifferent(_Fullname, value)) - return; - - _Fullname = value; - } - } - - public virtual byte[] ImageData - { - get { return _ImageData; } - set - { - if (!AreDifferent(_ImageData, value)) - return; - - _ImageData = value; - } - } - } -} diff --git a/Data/Entities/Wohneinheit.cs b/Data/Entities/Wohneinheit.cs index 70bd12196..b53a93c03 100644 --- a/Data/Entities/Wohneinheit.cs +++ b/Data/Entities/Wohneinheit.cs @@ -41,6 +41,7 @@ namespace BeWo.Data.Entities private string _Zusatznotiz; private string _Stock; private IList _Belegungen; + private IList _Grundrisse; public Wohneinheit() { @@ -286,6 +287,21 @@ namespace BeWo.Data.Entities this._Belegungen = value; } } - } + } + public virtual IList Grundrisse + { + get + { + return _Grundrisse; + } + + set + { + if (AreDifferent(_Grundrisse, value)) + { + _Grundrisse = value; + } + } + } } } diff --git a/Data/Mappings/Image.hbm.xml b/Data/Mappings/Image.hbm.xml index 51e45b7cc..f20a6fcce 100644 --- a/Data/Mappings/Image.hbm.xml +++ b/Data/Mappings/Image.hbm.xml @@ -13,8 +13,10 @@ - - - + + + + + \ No newline at end of file diff --git a/Data/Mappings/Wohneinheit.hbm.xml b/Data/Mappings/Wohneinheit.hbm.xml index 9fecffd9c..e473b0045 100644 --- a/Data/Mappings/Wohneinheit.hbm.xml +++ b/Data/Mappings/Wohneinheit.hbm.xml @@ -32,5 +32,9 @@ + + + + \ No newline at end of file diff --git a/Model/Changes_2024_08_27 Wohneinheit Grundrisse.txt b/Model/Changes_2024_08_27 Wohneinheit Grundrisse.txt new file mode 100644 index 000000000..02d1763ca --- /dev/null +++ b/Model/Changes_2024_08_27 Wohneinheit Grundrisse.txt @@ -0,0 +1,25 @@ +ALTER TABLE `image` +DROP FOREIGN KEY `FK_EMPLOYEE`, +DROP FOREIGN KEY `FK_CUSTOMER`; +ALTER TABLE `image` +DROP COLUMN `EmployeeOid`, +DROP COLUMN `CustomerOid`, +ADD COLUMN `WohneinheitOid` BIGINT NULL DEFAULT NULL AFTER `PersonOid`, +DROP INDEX `KEY_EMPLOYEE` , +DROP INDEX `KEY_CUSTOMER` ; +; +ALTER TABLE `image` +ADD CONSTRAINT `FK_IMAGE_PERSON` + FOREIGN KEY (`Oid`) + REFERENCES `person` (`Oid`) + ON DELETE CASCADE + ON UPDATE CASCADE, +ADD CONSTRAINT `FK_IMAGE_WOHNEINHEIT` + FOREIGN KEY (`Oid`) + REFERENCES `wohneinheit` (`Oid`) + ON DELETE CASCADE + ON UPDATE CASCADE; +; +ALTER TABLE `image` +ADD COLUMN `Filename` VARCHAR(1024) NULL DEFAULT NULL AFTER `SystemEntryID`, +ADD COLUMN `Fullname` VARCHAR(1024) NULL DEFAULT NULL AFTER `Filename`; diff --git a/Service/DCEntityMapper/ImageDC_Image.cs b/Service/DCEntityMapper/ImageDC_Image.cs new file mode 100644 index 000000000..d0d66985a --- /dev/null +++ b/Service/DCEntityMapper/ImageDC_Image.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.Linq; + +using BeWo.Data.Access; +using BeWo.Data.Entities; + +using BS.Shared; +using BS.Shared.Core; +using BS.Shared.DataContracts; +using BS.Shared.DataContracts.Wohnhilfe; + +namespace BeWo.Service.DCEntityMapper +{ + public class ImageDC_Image : AbstractIDCEntityMapper + { + public override ImageDC MergeWithDC(Image pEntity, ImageDC pDataContract) + { + pDataContract.Filename = pEntity.Filename; + pDataContract.Fullname = pEntity.Fullname; + pDataContract.Original = pEntity.Original; + pDataContract.SmallThumbnail = pEntity.SmallThumbnail; + pDataContract.MediumThumbnail = pEntity.MediumThumbnail; + + return pDataContract; + } + + public override Image MergeWithEntity(ImageDC pDataContract, Image pEntity) + { + pEntity.Filename = pDataContract.Filename; + pEntity.Fullname = pDataContract.Fullname; + pEntity.Original = pDataContract.Original; + pEntity.SmallThumbnail = pDataContract.SmallThumbnail; + pEntity.MediumThumbnail = pDataContract.MediumThumbnail; + + return pEntity; + } + + protected override bool AreDCAndEntityEqual(ImageDC pDC, Image pEntity) + { + if (pDC.Oid == null) + { + return false; + } + + return pDC.Oid == pEntity.Oid; + } + } +} diff --git a/Service/DCEntityMapper/ImageDC_ImageSimple.cs b/Service/DCEntityMapper/ImageDC_ImageSimple.cs deleted file mode 100644 index a48eac4e4..000000000 --- a/Service/DCEntityMapper/ImageDC_ImageSimple.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -using BeWo.Data.Access; -using BeWo.Data.Entities; - -using BS.Shared; -using BS.Shared.Core; -using BS.Shared.DataContracts; -using BS.Shared.DataContracts.Wohnhilfe; - -namespace BeWo.Service.DCEntityMapper -{ - public class ImageDC_ImageSimple : AbstractIDCEntityMapper - { - public ImageDC MergeWithDC(ImageSimple pEntity, ImageDC pDataContract, WohneinheitDC wohneinheit) - { - pDataContract.Filename = pEntity.Filename; - pDataContract.Fullname = pEntity.Fullname; - pDataContract.ImageData = pEntity.ImageData; - - if (wohneinheit.Grundrisse is null) - wohneinheit.Grundrisse = new List(); - - wohneinheit.Grundrisse.Add(pDataContract); - - return pDataContract; - } - - public ImageSimple MergeWithEntity(ImageDC pDataContract, ImageSimple pEntity, Wohneinheit wohneinheit) - { - pEntity.Filename = pDataContract.Filename; - pEntity.Fullname = pDataContract.Fullname; - pEntity.ImageData = pDataContract.ImageData; - - pEntity.Parent = wohneinheit; - - return pEntity; - } - - public override ImageDC MergeWithDC(ImageSimple pEntity, ImageDC pDataContract) - { - throw new System.NotImplementedException(); - } - - public override ImageSimple MergeWithEntity(ImageDC pDataContract, ImageSimple pEntity) - { - throw new System.NotImplementedException(); - } - - protected override bool AreDCAndEntityEqual(ImageDC pDC, ImageSimple pEntity) - { - throw new System.NotImplementedException(); - } - } -} diff --git a/Service/DCEntityMapper/MapperFactory.cs b/Service/DCEntityMapper/MapperFactory.cs index 382c71006..c8855638e 100644 --- a/Service/DCEntityMapper/MapperFactory.cs +++ b/Service/DCEntityMapper/MapperFactory.cs @@ -304,7 +304,7 @@ namespace BeWo.Service.DCEntityMapper private static FalldatenDC_CustomerFalldaten _FalldatenDC_CustomerFalldaten; - private static ImageDC_ImageSimple _ImageDC_ImageSimple; + private static ImageDC_Image _ImageDC_Image; public static MedRecordDC_MedRecord MedRecordDC_MedRecord => _MedRecordDC_MedRecord ?? (_MedRecordDC_MedRecord = new MedRecordDC_MedRecord()); @@ -766,7 +766,7 @@ namespace BeWo.Service.DCEntityMapper public static FalldatenDC_CustomerFalldaten FalldatenDC_CustomerFalldaten => _FalldatenDC_CustomerFalldaten ?? (_FalldatenDC_CustomerFalldaten = new FalldatenDC_CustomerFalldaten()); - public static ImageDC_ImageSimple ImageDC_ImageSimple => - _ImageDC_ImageSimple ?? (_ImageDC_ImageSimple = new ImageDC_ImageSimple()); + public static ImageDC_Image ImageDC_Image => + _ImageDC_Image ?? (_ImageDC_Image = new ImageDC_Image()); } } \ No newline at end of file diff --git a/Service/DCEntityMapper/PersonDC_Person.cs b/Service/DCEntityMapper/PersonDC_Person.cs index 215c22ece..1fd111a60 100644 --- a/Service/DCEntityMapper/PersonDC_Person.cs +++ b/Service/DCEntityMapper/PersonDC_Person.cs @@ -245,7 +245,6 @@ namespace BeWo.Service.DCEntityMapper pEntity.Images.Add(image); } - } MapperFactory.ContactDC_Contact.MergeWithEntitys(pDataContract.ContactInformations, pEntity.Contacts); diff --git a/Service/DCEntityMapper/WohneinheitDC_Wohneinheit.cs b/Service/DCEntityMapper/WohneinheitDC_Wohneinheit.cs index aa0148b42..e7d136e33 100644 --- a/Service/DCEntityMapper/WohneinheitDC_Wohneinheit.cs +++ b/Service/DCEntityMapper/WohneinheitDC_Wohneinheit.cs @@ -47,6 +47,9 @@ namespace BeWo.Service.DCEntityMapper if (pEntity.Belegungen is object && pEntity.Belegungen.Any()) pDataContract.Belegungen = MapperFactory.WohneinheitBelegungDC_WohneinheitBelegung.MapToNewDCs(pEntity.Belegungen); + if (pEntity.Grundrisse is object && pEntity.Grundrisse.Any()) + pDataContract.Grundrisse = MapperFactory.ImageDC_Image.MapToNewDCs(pEntity.Grundrisse); + return pDataContract; } @@ -75,6 +78,11 @@ namespace BeWo.Service.DCEntityMapper MapperFactory.WohneinheitBelegungDC_WohneinheitBelegung.MergeWithEntitys(pDataContract.Belegungen, pEntity.Belegungen, pEntity); + if (pEntity.Grundrisse is null) + pEntity.Grundrisse = new List(); + + MapperFactory.ImageDC_Image.MergeWithEntitys(pDataContract.Grundrisse, pEntity.Grundrisse); + return pEntity; } diff --git a/Service/Service.csproj b/Service/Service.csproj index bd6e3df84..b46c210cc 100644 --- a/Service/Service.csproj +++ b/Service/Service.csproj @@ -227,7 +227,7 @@ - + diff --git a/Shared/Core/Utils.cs b/Shared/Core/Utils.cs index 180df3945..0fb92cbc0 100644 --- a/Shared/Core/Utils.cs +++ b/Shared/Core/Utils.cs @@ -9,6 +9,7 @@ using System.IO.Compression; using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Windows.Media.Imaging; using System.Xml.Serialization; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; @@ -496,6 +497,26 @@ namespace BS.Shared.Core } } + public static BitmapImage CreateBitmapImageFromByteArray(byte[] array) + { + try + { + using (var ms = new MemoryStream(array)) + { + var image = new BitmapImage(); + image.BeginInit(); + image.CacheOption = BitmapCacheOption.OnLoad; // here + image.StreamSource = ms; + image.EndInit(); + return image; + } + } + catch (Exception) + { + return null; + } + } + public static Image ResizeImage(Image original, Size size) { var newSize = CalcSize(original.Width, original.Height, size.Width, size.Height); diff --git a/Shared/DataContracts/ImageDC.cs b/Shared/DataContracts/ImageDC.cs index 4e52c270d..b418a0eba 100644 --- a/Shared/DataContracts/ImageDC.cs +++ b/Shared/DataContracts/ImageDC.cs @@ -8,7 +8,6 @@ using System.Windows.Media.Imaging; namespace BS.Shared.DataContracts { - [DataContract] public class ImageDC : BeWoDataContract { // Server DC_Entity_Mapping bis Datenbank wichtig @@ -17,6 +16,8 @@ namespace BS.Shared.DataContracts [DataMember] public string Filename { get; set; } [DataMember] public string Fullname { get; set; } - [DataMember] public byte[] ImageData { get; set; } + [DataMember] public byte[] Original { get; set; } + [DataMember] public byte[] MediumThumbnail { get; set; } + [DataMember] public byte[] SmallThumbnail { get; set; } } }