using System; using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; namespace Haftmittel { public class Skladnik : INotifyPropertyChanged, IDataErrorInfo { private int _id = 0; private decimal _procent = 0; private decimal _procentDo = 0; public int Id { get => _id; set { _id = value; if (_id == 0) { Procent = 0; OnPropertyChanged(nameof(Procent)); } OnPropertyChanged(); } } public decimal Procent { get => _procent; set { _procent = value; OnPropertyChanged(); OnPropertyChanged(nameof(ProcentDo)); } } public decimal ProcentDo { get => _procentDo; set { _procentDo = value; OnPropertyChanged(); OnPropertyChanged(nameof(Procent)); } } /// /// Historia zmian wartości /// public List Historia { get; set; } /// /// Historia zmian typu /// public List Historia_Id { get; set; } /// /// Historia zmian wartości ProcentDo /// public List Historia_Do { get; set; } #region Obsługa INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string name = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); #endregion #region Obsługa IDataErrorInfo public string Error => throw new NotImplementedException(); public string this[string columnName] { get { string result = null; #region Procent if (columnName == "Procent") { if (Procent < 0 || Procent > 100) result = "tylko wartości od 0 do 100"; } #endregion #region ProcentDo if (columnName == "ProcentDo") { if (ProcentDo < 0 || ProcentDo > 100) result = "tylko wartości od 0 do 100"; } #endregion #region Procent if (columnName == "Procent" || columnName == "ProcentDo") { if (Procent > ProcentDo) result = "niewłaściwe wartości"; } #endregion return result; } } #endregion } }