using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; namespace Haftmittel { public class Skladnik : INotifyPropertyChanged, IDataErrorInfo { private Int32 _id = 0; private decimal _procent = 0; private decimal _procentDo = 0; private List _Historia; public Int32 Id { get { return _id; } set { _id = value; if (_id == 0) { Procent = 0; OnPropertyChanged("Procent"); } OnPropertyChanged("Id"); } } public decimal Procent { get { return _procent; } set { _procent = value; OnPropertyChanged("Procent"); OnPropertyChanged("ProcentDo"); } } public decimal ProcentDo { get { return _procentDo; } set { _procentDo = value; OnPropertyChanged("ProcentDo"); OnPropertyChanged("Procent"); } } /// /// Historia zmian wartości /// public List Historia { get { return _Historia; } set { _Historia = value; } } /// /// 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(string name) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(name)); } } #endregion #region Obsługa IDataErrorInfo public string Error { get { 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 } }