Files
GotecHaftmittel/.svn/pristine/80/80df2f45356f21a7f3473c705102e8714fe35843.svn-base
2025-10-31 12:50:24 +01:00

111 lines
2.9 KiB
Plaintext

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));
}
}
/// <summary>
/// Historia zmian wartości
/// </summary>
public List<Historia> Historia { get; set; }
/// <summary>
/// Historia zmian typu
/// </summary>
public List<Historia> Historia_Id { get; set; }
/// <summary>
/// Historia zmian wartości ProcentDo
/// </summary>
public List<Historia> 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
}
}