using System; using System.Collections.Generic; using System.Linq; using BeWo.Core; using BeWo.Validation; using BeWo.ViewModel.ListViewModel; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.Extensions; using System.Windows.Forms; using BS.Shared.DataContracts.Compact; namespace BeWo.ViewModel { public class WohnheimVM : AbstractDCMapperVM { #region Property Names public static string PropertyName_WohnheimEmployeeRelations = "WohnheimEmployeeRelations"; public static string PropertyName_WohnheimCustomerRelations = "WohnheimCustomerRelations"; public static string PropertyName_WohnheimTeamRelations = "WohnheimTeamRelations"; public static string PropertyName_IsArchived = "IsArchived"; //##################### Erstellte Variablen ####################### public static string PropertyName_WohnheimName = "WohnheimName"; public static string PropertyName_PLZ = "PLZ"; public static string PropertyName_Ort = "Ort"; public static string PropertyName_Bemerkung = "Bemerkung"; public static string PropertyName_Street = "Strasse"; public static string PropertyName_PflichtbesetzungStart = "PflichtbesetzungStart"; public static string PropertyName_PflichtbesetzungEnde = "PflichtbesetzungEnde"; public static string PropertyName_PflichtbesetzungEinblenden = "PflichtbesetzungEinblenden"; public static string PropertyName_StandardZeilenanzahl = "StandardZeilenanzahl"; public static string PropertyName_Sortierungsart = "Sortierungsart"; public static string PropertyName_AbsteigendeSortierung = "AbsteigendeSortierung"; //################################################################## #endregion //##################### Erstellte Variablen ####################### private string _WohnheimName; private string _Strasse; private string _PLZ; private string _Ort; private string _Bemerkung; private string _PflichtbesetzungStart; private string _PflichtbesetzungEnde; private int _PflichtbesetzungEinblenden; private int _StandardZeilenanzahl; private int _Sortierungsart; private int _AbsteigendeSortierung; private bool _IsArchived; //################################################################## private WohnheimEmployeeRelationListVM _WohnheimEmployeeRelations; private WohnheimCustomerRelationListVM _WohnheimCustomerRelations; private CompactTeamDC _WohnheimTeamRelations; public WohnheimVM(WohnheimDC pWohnheimDC) : base(pWohnheimDC, pWohnheimDC.WohnheimOid == null) { } public override bool IsDirty { get { return base.IsDirty || WohnheimEmployeeRelations.IsDirty || WohnheimCustomerRelations.IsDirty; } } public bool IsArchived { get { return _IsArchived; } set { if (AreDifferent(_IsArchived, value)) { _IsArchived = value; StoreDirtyInformation( (value && DataContract.ActivationType == ActivationTypeId.Active) || (!value && DataContract.ActivationType == ActivationTypeId.Archived), PropertyName_IsArchived); FirePropertyChanged(PropertyName_IsArchived); } } } //Setter und Getter public String WohnheimName { get { return _WohnheimName; } set { _WohnheimName = value; StoreDirtyInformation(AreDifferent(DataContract.WohnheimName, value), PropertyName_WohnheimName); FirePropertyChanged(PropertyName_WohnheimName); } } public String Strasse { get { return _Strasse; } set { _Strasse = value; StoreDirtyInformation(AreDifferent(DataContract.Strasse, value), PropertyName_Street); FirePropertyChanged(PropertyName_Street); } } public String PLZ { get { return _PLZ; } set { _PLZ = value; StoreDirtyInformation(AreDifferent(DataContract.PLZ, value), PropertyName_PLZ); FirePropertyChanged(PropertyName_PLZ); } } public String Ort { get { return _Ort; } set { _Ort = value; StoreDirtyInformation(AreDifferent(DataContract.Ort, value), PropertyName_Ort); FirePropertyChanged(PropertyName_Ort); } } public String Bemerkung { get { return _Bemerkung; } set { _Bemerkung = value; StoreDirtyInformation(AreDifferent(DataContract.Bemerkung, value), PropertyName_Bemerkung); FirePropertyChanged(PropertyName_Bemerkung); } } public String PflichtbesetzungStart { get { return _PflichtbesetzungStart; } set { _PflichtbesetzungStart = value; StoreDirtyInformation(AreDifferent(DataContract.PflichtbesetzungStart, value), PropertyName_PflichtbesetzungStart); FirePropertyChanged(PropertyName_PflichtbesetzungStart); } } public String PflichtbesetzungEnde { get { return _PflichtbesetzungEnde; } set { _PflichtbesetzungEnde = value; StoreDirtyInformation(AreDifferent(DataContract.PflichtbesetzungEnde, value), PropertyName_PflichtbesetzungEnde); FirePropertyChanged(PropertyName_PflichtbesetzungEnde); } } public int PflichtbesetzungEinblenden { get { return _PflichtbesetzungEinblenden; } set { _PflichtbesetzungEinblenden = value; StoreDirtyInformation(AreDifferent(DataContract.PflichtbesetzungEinblenden, value), PropertyName_PflichtbesetzungEinblenden); FirePropertyChanged(PropertyName_PflichtbesetzungEinblenden); } } public int StandardZeilenanzahl { get { return _StandardZeilenanzahl; } set { _StandardZeilenanzahl = value; StoreDirtyInformation(AreDifferent(DataContract.StandardZeilenanzahl, value), PropertyName_StandardZeilenanzahl); FirePropertyChanged(PropertyName_StandardZeilenanzahl); } } public int Sortierungsart { get { return _Sortierungsart; } set { _Sortierungsart = value; StoreDirtyInformation(AreDifferent(DataContract.Sortierungsart, value), PropertyName_Sortierungsart); FirePropertyChanged(PropertyName_Sortierungsart); } } public int AbsteigendeSortierung { get { return _AbsteigendeSortierung; } set { _AbsteigendeSortierung = value; StoreDirtyInformation(AreDifferent(DataContract.AbsteigendeSortierung, value), PropertyName_AbsteigendeSortierung); FirePropertyChanged(PropertyName_AbsteigendeSortierung); } } public WohnheimEmployeeRelationListVM WohnheimEmployeeRelations { get { return _WohnheimEmployeeRelations; } set { _WohnheimEmployeeRelations = value; FirePropertyChanged(PropertyName_WohnheimEmployeeRelations); } } public WohnheimCustomerRelationListVM WohnheimCustomerRelations { get { return _WohnheimCustomerRelations; } set { _WohnheimCustomerRelations = value; FirePropertyChanged(PropertyName_WohnheimCustomerRelations); } } public CompactTeamDC WohnheimTeamRelations { get { return _WohnheimTeamRelations; } set { _WohnheimTeamRelations = value; FirePropertyChanged(PropertyName_WohnheimTeamRelations); } } // HACK: Bug bei den RadioButtons, geben false nicht weiter // TODO nochmal angucken wenn mehr als zwei Optionen, dann in listbox und an selected item binden // http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2146568&SiteID=1 protected override void InitByDataContract(WohnheimDC pDataContract) { _WohnheimName = pDataContract.WohnheimName; _Strasse = pDataContract.Strasse; _PLZ = pDataContract.PLZ; _Ort = pDataContract.Ort; _Bemerkung = pDataContract.Bemerkung; _PflichtbesetzungStart = pDataContract.PflichtbesetzungStart; _PflichtbesetzungEnde = pDataContract.PflichtbesetzungEnde; _PflichtbesetzungEinblenden = pDataContract.PflichtbesetzungEinblenden; _StandardZeilenanzahl = pDataContract.StandardZeilenanzahl; _Sortierungsart = pDataContract.Sortierungsart; _AbsteigendeSortierung = pDataContract.AbsteigendeSortierung; _IsArchived = pDataContract.ActivationType == ActivationTypeId.Archived; WohnheimEmployeeRelations = VMFactory.CreateWohnheimEmployeeRelationListVM(pDataContract.RelatedEmployees ?? (pDataContract.RelatedEmployees = new List())); WohnheimCustomerRelations = VMFactory.CreateWohnheimCustomerRelationListVM(pDataContract.RelatedCustomers ?? (pDataContract.RelatedCustomers = new List())); } protected override WohnheimDC MapToDataContract(WohnheimDC pDataContract, bool doCommit) { pDataContract.WohnheimName = _WohnheimName; pDataContract.Strasse = _Strasse; pDataContract.PLZ = _PLZ; pDataContract.Ort = _Ort; pDataContract.Bemerkung = _Bemerkung; pDataContract.PflichtbesetzungStart = _PflichtbesetzungStart; pDataContract.PflichtbesetzungEnde = _PflichtbesetzungEnde; pDataContract.PflichtbesetzungEinblenden = _PflichtbesetzungEinblenden; pDataContract.StandardZeilenanzahl = _StandardZeilenanzahl; pDataContract.Sortierungsart = _Sortierungsart; pDataContract.AbsteigendeSortierung = _AbsteigendeSortierung; pDataContract.ActivationType = _IsArchived ? ActivationTypeId.Archived : ActivationTypeId.Active; pDataContract.RelatedEmployees = _WohnheimEmployeeRelations.CopyToDCList(doCommit); pDataContract.RelatedCustomers = _WohnheimCustomerRelations.CopyToDCList(doCommit); return pDataContract; } } }