59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using Avalonia.Data.Converters;
|
|
|
|
namespace GazpromApp.Enums;
|
|
|
|
public enum PeriodType
|
|
{
|
|
Unknown = -1,
|
|
Day = 0,
|
|
Week = 1,
|
|
Month = 2,
|
|
Year = 3
|
|
}
|
|
|
|
public static class PeriodTypeExtensions
|
|
{
|
|
public static string ToDescription(this PeriodType periodType)
|
|
{
|
|
return periodType switch
|
|
{
|
|
PeriodType.Day => "День",
|
|
PeriodType.Week => "Неделя",
|
|
PeriodType.Month => "Месяц",
|
|
PeriodType.Year => "Год",
|
|
PeriodType.Unknown => "Неизв.",
|
|
_ => string.Empty
|
|
};
|
|
}
|
|
|
|
public static PeriodType ToPeriodType(this string periodType)
|
|
{
|
|
return periodType switch
|
|
{
|
|
"День" => PeriodType.Day,
|
|
"Неделя" => PeriodType.Week,
|
|
"Месяц" => PeriodType.Month,
|
|
"Год" => PeriodType.Year,
|
|
_ => PeriodType.Unknown
|
|
};
|
|
}
|
|
}
|
|
|
|
public class PeriodConverter : IValueConverter
|
|
{
|
|
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is PeriodType periodType)
|
|
return periodType.ToDescription();
|
|
return false;
|
|
}
|
|
|
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is string periodType)
|
|
return periodType.ToPeriodType();
|
|
return false;
|
|
}
|
|
} |