20211113 C#10 Update
This commit is contained in:
parent
438c123876
commit
869dc25fb4
@ -1,34 +1,33 @@
|
|||||||
namespace anbs_cp
|
namespace anbs_cp;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Форматирует число элементов в понятную строку
|
|
||||||
/// </summary>
|
|
||||||
public class CountFormatter : IValueFormatter
|
|
||||||
{
|
|
||||||
#region Cвойства класса
|
|
||||||
/// <summary>
|
|
||||||
/// Имена чисел (тысяч, миллионов, миллиардов и т.п.)
|
|
||||||
/// </summary>
|
|
||||||
public string[] CountNames { get; set; } = { "", "тыс.", "млн.", "млрд." };
|
|
||||||
/// <summary>
|
|
||||||
/// Знаков после запятой
|
|
||||||
/// </summary>
|
|
||||||
public byte DecimalPlaces { get; set; } = 1;
|
|
||||||
/// <summary>
|
|
||||||
/// Делители чисел
|
|
||||||
/// </summary>
|
|
||||||
public long[] Delimeters { get; set; } = { 1000, 1000000, 1000000000 };
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Реализация интерфейса
|
/// <summary>
|
||||||
/// <summary>
|
/// Форматирует число элементов в понятную строку
|
||||||
/// Реализация интерфейса
|
/// </summary>
|
||||||
/// </summary>
|
public class CountFormatter: IValueFormatter
|
||||||
public string[] ValueNames { get => CountNames; set => CountNames = value; }
|
{
|
||||||
/// <summary>
|
#region Cвойства класса
|
||||||
/// Реализация интерфейса
|
/// <summary>
|
||||||
/// </summary>
|
/// Имена чисел (тысяч, миллионов, миллиардов и т.п.)
|
||||||
public long[] MaxSizes { get => Delimeters; set => Delimeters = value; }
|
/// </summary>
|
||||||
#endregion
|
public string[] CountNames { get; set; } = { "", "тыс.", "млн.", "млрд." };
|
||||||
}
|
/// <summary>
|
||||||
|
/// Знаков после запятой
|
||||||
|
/// </summary>
|
||||||
|
public byte DecimalPlaces { get; set; } = 1;
|
||||||
|
/// <summary>
|
||||||
|
/// Делители чисел
|
||||||
|
/// </summary>
|
||||||
|
public long[] Delimeters { get; set; } = { 1000, 1000000, 1000000000 };
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Реализация интерфейса
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация интерфейса
|
||||||
|
/// </summary>
|
||||||
|
public string[] ValueNames { get => CountNames; set => CountNames = value; }
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация интерфейса
|
||||||
|
/// </summary>
|
||||||
|
public long[] MaxSizes { get => Delimeters; set => Delimeters = value; }
|
||||||
|
#endregion
|
||||||
}
|
}
|
@ -1,56 +1,55 @@
|
|||||||
namespace anbs_cp
|
namespace anbs_cp;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Форматирует размер файла/папки в понятную строку
|
|
||||||
/// </summary>
|
|
||||||
public class FileSizeFormatter : IValueFormatter
|
|
||||||
{
|
|
||||||
#region Cвойства класса
|
|
||||||
/// <summary>
|
|
||||||
/// Имена размеров (байт, килобайт, мегабайт, гигабайт и террабайт)
|
|
||||||
/// </summary>
|
|
||||||
public string[] SizeNames { get; set; } = { "Байт", "Кб", "Мб", "Гб", "Тб" };
|
|
||||||
/// <summary>
|
|
||||||
/// Знаков после запятой
|
|
||||||
/// </summary>
|
|
||||||
public byte DecimalPlaces { get; set; } = 2;
|
|
||||||
/// <summary>
|
|
||||||
/// Максимально байт (далее идут Кбайты)
|
|
||||||
/// </summary>
|
|
||||||
public long ByteMax { get; set; } = 1024;
|
|
||||||
/// <summary>
|
|
||||||
/// Максимально Кбайт (далее идут Мбайты)
|
|
||||||
/// </summary>
|
|
||||||
public long KByteMax { get; set; } = 1048576;
|
|
||||||
/// <summary>
|
|
||||||
/// Максимально Мбайт (далее идут Гбайты)
|
|
||||||
/// </summary>
|
|
||||||
public long MByteMax { get; set; } = 1073741824;
|
|
||||||
/// <summary>
|
|
||||||
/// Максимально Гбайт (далее идут Тбайты)
|
|
||||||
/// </summary>
|
|
||||||
public long GByteMax { get; set; } = 1099511627776;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Реализация интерфейса
|
/// <summary>
|
||||||
/// <summary>
|
/// Форматирует размер файла/папки в понятную строку
|
||||||
/// Реализация интерфейса
|
/// </summary>
|
||||||
/// </summary>
|
public class FileSizeFormatter: IValueFormatter
|
||||||
public string[] ValueNames { get => SizeNames; set => SizeNames = value; }
|
{
|
||||||
/// <summary>
|
#region Cвойства класса
|
||||||
/// Реализация интерфейса
|
/// <summary>
|
||||||
/// </summary>
|
/// Имена размеров (байт, килобайт, мегабайт, гигабайт и террабайт)
|
||||||
public long[] MaxSizes
|
/// </summary>
|
||||||
|
public string[] SizeNames { get; set; } = { "Байт", "Кб", "Мб", "Гб", "Тб" };
|
||||||
|
/// <summary>
|
||||||
|
/// Знаков после запятой
|
||||||
|
/// </summary>
|
||||||
|
public byte DecimalPlaces { get; set; } = 2;
|
||||||
|
/// <summary>
|
||||||
|
/// Максимально байт (далее идут Кбайты)
|
||||||
|
/// </summary>
|
||||||
|
public long ByteMax { get; set; } = 1024;
|
||||||
|
/// <summary>
|
||||||
|
/// Максимально Кбайт (далее идут Мбайты)
|
||||||
|
/// </summary>
|
||||||
|
public long KByteMax { get; set; } = 1048576;
|
||||||
|
/// <summary>
|
||||||
|
/// Максимально Мбайт (далее идут Гбайты)
|
||||||
|
/// </summary>
|
||||||
|
public long MByteMax { get; set; } = 1073741824;
|
||||||
|
/// <summary>
|
||||||
|
/// Максимально Гбайт (далее идут Тбайты)
|
||||||
|
/// </summary>
|
||||||
|
public long GByteMax { get; set; } = 1099511627776;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Реализация интерфейса
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация интерфейса
|
||||||
|
/// </summary>
|
||||||
|
public string[] ValueNames { get => SizeNames; set => SizeNames = value; }
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация интерфейса
|
||||||
|
/// </summary>
|
||||||
|
public long[] MaxSizes
|
||||||
|
{
|
||||||
|
get => new long[] { ByteMax, KByteMax, MByteMax, GByteMax };
|
||||||
|
set
|
||||||
{
|
{
|
||||||
get => new long[] { ByteMax, KByteMax, MByteMax, GByteMax };
|
ByteMax = value[0];
|
||||||
set
|
KByteMax = value[1];
|
||||||
{
|
MByteMax = value[2];
|
||||||
ByteMax = value[0];
|
GByteMax = value[3];
|
||||||
KByteMax = value[1];
|
|
||||||
MByteMax = value[2];
|
|
||||||
GByteMax = value[3];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
@ -1,82 +1,75 @@
|
|||||||
namespace anbs_cp
|
namespace anbs_cp;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Форматирует размерности в понятную строку
|
||||||
|
/// </summary>
|
||||||
|
public interface IValueFormatter
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#region Определения интерфейса
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Форматирует размерности в понятную строку
|
/// Имена размерностей
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IValueFormatter
|
public string[] ValueNames { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Знаков после запятой
|
||||||
|
/// </summary>
|
||||||
|
public byte DecimalPlaces { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Максимальные размеры (массив ulong[4])
|
||||||
|
/// </summary>
|
||||||
|
public long[] MaxSizes { get; set; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Методы интерфейса
|
||||||
|
/// <summary>
|
||||||
|
/// Форматирование размерности
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">Размерность, требующая форматирования</param>
|
||||||
|
/// <returns>Форматированная размерность (например, 20 Мб)</returns>
|
||||||
|
public string Format (long value)
|
||||||
{
|
{
|
||||||
|
//Левая граница
|
||||||
|
long leftnum;
|
||||||
|
//Правая граница
|
||||||
|
long rightnum;
|
||||||
|
|
||||||
#region Определения интерфейса
|
for (int i = 0; i <= MaxSizes.Length; i++)
|
||||||
/// <summary>
|
|
||||||
/// Имена размерностей
|
|
||||||
/// </summary>
|
|
||||||
public string[] ValueNames { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Знаков после запятой
|
|
||||||
/// </summary>
|
|
||||||
public byte DecimalPlaces { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Максимальные размеры (массив ulong[4])
|
|
||||||
/// </summary>
|
|
||||||
public long[] MaxSizes { get; set; }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Методы интерфейса
|
|
||||||
/// <summary>
|
|
||||||
/// Форматирование размерности
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value">Размерность, требующая форматирования</param>
|
|
||||||
/// <returns>Форматированная размерность (например, 20 Мб)</returns>
|
|
||||||
public string Format(long value)
|
|
||||||
{
|
{
|
||||||
//Левая граница
|
leftnum = i == 0 ? 0 : MaxSizes[i - 1];
|
||||||
long leftnum;
|
|
||||||
//Правая граница
|
|
||||||
long rightnum;
|
|
||||||
|
|
||||||
for (int i = 0; i <= MaxSizes.Length; i++)
|
rightnum = i == MaxSizes.Length ? long.MaxValue : MaxSizes[i];
|
||||||
{
|
|
||||||
if (i == 0)
|
|
||||||
leftnum = 0;
|
|
||||||
else
|
|
||||||
leftnum = MaxSizes[i - 1];
|
|
||||||
|
|
||||||
if (i == MaxSizes.Length)
|
if ((value >= leftnum) && (value < rightnum))
|
||||||
rightnum = long.MaxValue;
|
return $"{FormatValue(value, leftnum)} {ValueNames[i]}";
|
||||||
else
|
|
||||||
rightnum = MaxSizes[i];
|
|
||||||
|
|
||||||
if ((value >= leftnum) && (value < rightnum))
|
|
||||||
return $"{FormatValue(value, leftnum)} {ValueNames[i]}";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return value.ToString();
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Деление числа на число с DecimalPlaces знаками после запятой
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dividend">Делимое число</param>
|
|
||||||
/// <param name="divider">Число-делитель</param>
|
|
||||||
/// <returns>Частное (с DecimalPlaces знаками после запятой)</returns>
|
|
||||||
private string FormatValue(long dividend, long divider)
|
|
||||||
{
|
|
||||||
if (divider == 0)
|
|
||||||
{
|
|
||||||
return $"{dividend}";
|
|
||||||
}
|
|
||||||
|
|
||||||
long delim = 1;
|
return value.ToString();
|
||||||
|
|
||||||
for (int i = 0; i <= DecimalPlaces; i++)
|
|
||||||
{
|
|
||||||
delim *= 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
decimal value = Math.Round((decimal)(dividend * delim / divider)) / delim;
|
|
||||||
|
|
||||||
return $"{value}";
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Деление числа на число с DecimalPlaces знаками после запятой
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dividend">Делимое число</param>
|
||||||
|
/// <param name="divider">Число-делитель</param>
|
||||||
|
/// <returns>Частное (с DecimalPlaces знаками после запятой)</returns>
|
||||||
|
private string FormatValue (long dividend, long divider)
|
||||||
|
{
|
||||||
|
if (divider == 0)
|
||||||
|
{
|
||||||
|
return $"{dividend}";
|
||||||
|
}
|
||||||
|
|
||||||
|
long delim = 1;
|
||||||
|
|
||||||
|
for (int i = 0; i <= DecimalPlaces; i++)
|
||||||
|
{
|
||||||
|
delim *= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
decimal value = Math.Round((decimal)(dividend * delim / divider)) / delim;
|
||||||
|
|
||||||
|
return $"{value}";
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
@ -1,48 +1,46 @@
|
|||||||
using System.Collections.Generic;
|
namespace anbs_cp;
|
||||||
namespace anbs_cp
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, добавляющий реализацию некоторых методов Delphi, которые упрощают работу в C#.
|
||||||
|
/// </summary>
|
||||||
|
public static class LikeDelphi
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс, добавляющий реализацию некоторых методов Delphi, которые упрощают работу в C#.
|
/// Аналог функции IncludeTrailingBackslash
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class LikeDelphi
|
/// <param name="path">Путь, к которому нужно добавить slash</param>
|
||||||
|
/// <returns>Путь со slash в конце</returns>
|
||||||
|
public static string IncludeTrailingBackslash (string path)
|
||||||
{
|
{
|
||||||
/// <summary>
|
string result = path;
|
||||||
/// Аналог функции IncludeTrailingBackslash
|
int Index = path.Length - 1;
|
||||||
/// </summary>
|
if (path[Index] != '\\')
|
||||||
/// <param name="path">Путь, к которому нужно добавить slash</param>
|
|
||||||
/// <returns>Путь со slash в конце</returns>
|
|
||||||
public static string IncludeTrailingBackslash(string path)
|
|
||||||
{
|
{
|
||||||
string result = path;
|
result = $"{path}\\";
|
||||||
int Index = path.Length - 1;
|
|
||||||
if (path[Index] != '\\')
|
|
||||||
{
|
|
||||||
result = $"{path}\\";
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
return result;
|
||||||
/// Парсер строки в множество строк
|
}
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="astring">Строка, которую нужно разбить</param>
|
/// Парсер строки в множество строк
|
||||||
/// <param name="delim">Символ-делитель строки</param>
|
/// </summary>
|
||||||
/// <returns>Массив строк</returns>
|
/// <param name="astring">Строка, которую нужно разбить</param>
|
||||||
public static List<string> ParseString(string astring, char delim)
|
/// <param name="delim">Символ-делитель строки</param>
|
||||||
|
/// <returns>Массив строк</returns>
|
||||||
|
public static List<string> ParseString (string astring, char delim)
|
||||||
|
{
|
||||||
|
int from = -1;
|
||||||
|
int to;
|
||||||
|
List<string> result = new();
|
||||||
|
do
|
||||||
{
|
{
|
||||||
int from = -1;
|
from++;
|
||||||
int to;
|
to = astring.IndexOf(delim, from);
|
||||||
List<string> result = new();
|
if (to <= 0)
|
||||||
do
|
to = astring.Length;
|
||||||
{
|
if (from != to)
|
||||||
from++;
|
result.Add(astring[from..(to - from)]);
|
||||||
to = astring.IndexOf(delim, from);
|
from = to;
|
||||||
if (to <= 0)
|
} while (to != astring.Length);
|
||||||
to = astring.Length;
|
return result;
|
||||||
if (from != to)
|
|
||||||
result.Add(astring[from..(to-from)]);
|
|
||||||
from = to;
|
|
||||||
} while (to != astring.Length);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,114 +1,113 @@
|
|||||||
namespace anbs_cp
|
namespace anbs_cp;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Конвертер типов на манер Delphi
|
|
||||||
/// </summary>
|
|
||||||
public static class TypeConverter
|
|
||||||
{
|
|
||||||
#region Конвертация числа в строку
|
|
||||||
/// <summary>
|
|
||||||
/// Преобразование int в string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="AInt">Число</param>
|
|
||||||
/// <returns>Строка</returns>
|
|
||||||
public static string IntToStr(int AInt) => AInt.ToString();
|
|
||||||
/// <summary>
|
|
||||||
/// Преобразование uint в string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="AInt">Число</param>
|
|
||||||
/// <returns>Строка</returns>
|
|
||||||
public static string IntToStr(uint AInt) => AInt.ToString();
|
|
||||||
/// <summary>
|
|
||||||
/// Преобразование long в string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="AInt">Число</param>
|
|
||||||
/// <returns>Строка</returns>
|
|
||||||
public static string IntToStr(long AInt) => AInt.ToString();
|
|
||||||
/// <summary>
|
|
||||||
/// Преобразование ulong в string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="AInt">Число</param>
|
|
||||||
/// <returns>Строка</returns>
|
|
||||||
public static string IntToStr(ulong AInt) => AInt.ToString();
|
|
||||||
/// <summary>
|
|
||||||
/// Преобразование byte в string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="AInt">Число</param>
|
|
||||||
/// <returns>Строка</returns>
|
|
||||||
public static string IntToStr(byte AInt) => AInt.ToString();
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Конвертация строки в число
|
/// <summary>
|
||||||
/// <summary>
|
/// Конвертер типов на манер Delphi
|
||||||
/// Преобразование строки в число
|
/// </summary>
|
||||||
/// </summary>
|
public static class TypeConverter
|
||||||
/// <param name="AStr">Строка</param>
|
{
|
||||||
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
#region Конвертация числа в строку
|
||||||
/// <returns>Число</returns>
|
/// <summary>
|
||||||
public static int StrToInt(string AStr, int ADefault = 0)
|
/// Преобразование int в string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="AInt">Число</param>
|
||||||
|
/// <returns>Строка</returns>
|
||||||
|
public static string IntToStr (int AInt) => AInt.ToString();
|
||||||
|
/// <summary>
|
||||||
|
/// Преобразование uint в string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="AInt">Число</param>
|
||||||
|
/// <returns>Строка</returns>
|
||||||
|
public static string IntToStr (uint AInt) => AInt.ToString();
|
||||||
|
/// <summary>
|
||||||
|
/// Преобразование long в string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="AInt">Число</param>
|
||||||
|
/// <returns>Строка</returns>
|
||||||
|
public static string IntToStr (long AInt) => AInt.ToString();
|
||||||
|
/// <summary>
|
||||||
|
/// Преобразование ulong в string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="AInt">Число</param>
|
||||||
|
/// <returns>Строка</returns>
|
||||||
|
public static string IntToStr (ulong AInt) => AInt.ToString();
|
||||||
|
/// <summary>
|
||||||
|
/// Преобразование byte в string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="AInt">Число</param>
|
||||||
|
/// <returns>Строка</returns>
|
||||||
|
public static string IntToStr (byte AInt) => AInt.ToString();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Конвертация строки в число
|
||||||
|
/// <summary>
|
||||||
|
/// Преобразование строки в число
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="AStr">Строка</param>
|
||||||
|
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
||||||
|
/// <returns>Число</returns>
|
||||||
|
public static int StrToInt (string AStr, int ADefault = 0)
|
||||||
|
{
|
||||||
|
if (!int.TryParse(AStr, out int result))
|
||||||
{
|
{
|
||||||
if (!int.TryParse(AStr, out int result))
|
result = ADefault;
|
||||||
{
|
|
||||||
result = ADefault;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
return result;
|
||||||
/// Преобразование строки в число
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="AStr">Строка</param>
|
|
||||||
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
|
||||||
/// <returns>Число</returns>
|
|
||||||
public static uint StrToUInt(string AStr, uint ADefault = 0)
|
|
||||||
{
|
|
||||||
if (!uint.TryParse(AStr, out uint result))
|
|
||||||
{
|
|
||||||
result = ADefault;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Преобразование строки в число
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="AStr">Строка</param>
|
|
||||||
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
|
||||||
/// <returns>Число</returns>
|
|
||||||
public static long StrToInt64(string AStr, long ADefault = 0)
|
|
||||||
{
|
|
||||||
if (!long.TryParse(AStr, out long result))
|
|
||||||
{
|
|
||||||
result = ADefault;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Преобразование строки в число
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="AStr">Строка</param>
|
|
||||||
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
|
||||||
/// <returns>Число</returns>
|
|
||||||
public static ulong StrToUInt64(string AStr, ulong ADefault = 0)
|
|
||||||
{
|
|
||||||
if (!ulong.TryParse(AStr, out ulong result))
|
|
||||||
{
|
|
||||||
result = ADefault;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Преобразование строки в число
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="AStr">Строка</param>
|
|
||||||
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
|
||||||
/// <returns>Число</returns>
|
|
||||||
public static byte StrToByte(string AStr, byte ADefault = 0)
|
|
||||||
{
|
|
||||||
if (!byte.TryParse(AStr, out byte result))
|
|
||||||
{
|
|
||||||
result = ADefault;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Преобразование строки в число
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="AStr">Строка</param>
|
||||||
|
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
||||||
|
/// <returns>Число</returns>
|
||||||
|
public static uint StrToUInt (string AStr, uint ADefault = 0)
|
||||||
|
{
|
||||||
|
if (!uint.TryParse(AStr, out uint result))
|
||||||
|
{
|
||||||
|
result = ADefault;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Преобразование строки в число
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="AStr">Строка</param>
|
||||||
|
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
||||||
|
/// <returns>Число</returns>
|
||||||
|
public static long StrToInt64 (string AStr, long ADefault = 0)
|
||||||
|
{
|
||||||
|
if (!long.TryParse(AStr, out long result))
|
||||||
|
{
|
||||||
|
result = ADefault;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Преобразование строки в число
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="AStr">Строка</param>
|
||||||
|
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
||||||
|
/// <returns>Число</returns>
|
||||||
|
public static ulong StrToUInt64 (string AStr, ulong ADefault = 0)
|
||||||
|
{
|
||||||
|
if (!ulong.TryParse(AStr, out ulong result))
|
||||||
|
{
|
||||||
|
result = ADefault;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Преобразование строки в число
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="AStr">Строка</param>
|
||||||
|
/// <param name="ADefault">Значение по умолчанию (по умолчанию, 0)</param>
|
||||||
|
/// <returns>Число</returns>
|
||||||
|
public static byte StrToByte (string AStr, byte ADefault = 0)
|
||||||
|
{
|
||||||
|
if (!byte.TryParse(AStr, out byte result))
|
||||||
|
{
|
||||||
|
result = ADefault;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Version>1.20211111.0</Version>
|
<Version>1.2021.1113</Version>
|
||||||
<Authors>Alexander Babaev</Authors>
|
<Authors>Alexander Babaev</Authors>
|
||||||
<Product>ANB Software Components Pack</Product>
|
<Product>ANB Software Components Pack</Product>
|
||||||
<Description>Library of some useful functions in C# language.</Description>
|
<Description>Library of some useful functions in C# language.</Description>
|
||||||
@ -15,8 +15,8 @@
|
|||||||
<SignAssembly>False</SignAssembly>
|
<SignAssembly>False</SignAssembly>
|
||||||
<PackageProjectUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</RepositoryUrl>
|
<RepositoryUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</RepositoryUrl>
|
||||||
<AssemblyVersion>1.2021.1111</AssemblyVersion>
|
<AssemblyVersion>1.2021.1113</AssemblyVersion>
|
||||||
<FileVersion>1.2021.1111</FileVersion>
|
<FileVersion>1.2021.1113</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
245
demo/CountValueTest.Designer.cs
generated
245
demo/CountValueTest.Designer.cs
generated
@ -1,134 +1,133 @@
|
|||||||
namespace demo
|
namespace demo;
|
||||||
|
|
||||||
|
partial class CountValueTest
|
||||||
{
|
{
|
||||||
partial class CountValueTest
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose (bool disposing)
|
||||||
{
|
{
|
||||||
/// <summary>
|
if (disposing && (components != null))
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
{
|
||||||
if (disposing && (components != null))
|
components.Dispose();
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent ()
|
||||||
{
|
{
|
||||||
this.InsertDataLabel = new System.Windows.Forms.Label();
|
this.InsertDataLabel = new System.Windows.Forms.Label();
|
||||||
this.InsertDataBox = new System.Windows.Forms.TextBox();
|
this.InsertDataBox = new System.Windows.Forms.TextBox();
|
||||||
this.ResultLabel = new System.Windows.Forms.Label();
|
this.ResultLabel = new System.Windows.Forms.Label();
|
||||||
this.CalculateButton = new System.Windows.Forms.Button();
|
this.CalculateButton = new System.Windows.Forms.Button();
|
||||||
this.SelectFormatterLabel = new System.Windows.Forms.Label();
|
this.SelectFormatterLabel = new System.Windows.Forms.Label();
|
||||||
this.SelectFormatterBox = new System.Windows.Forms.ComboBox();
|
this.SelectFormatterBox = new System.Windows.Forms.ComboBox();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// InsertDataLabel
|
// InsertDataLabel
|
||||||
//
|
//
|
||||||
this.InsertDataLabel.AutoSize = true;
|
this.InsertDataLabel.AutoSize = true;
|
||||||
this.InsertDataLabel.Location = new System.Drawing.Point(12, 66);
|
this.InsertDataLabel.Location = new System.Drawing.Point(12, 66);
|
||||||
this.InsertDataLabel.Name = "InsertDataLabel";
|
this.InsertDataLabel.Name = "InsertDataLabel";
|
||||||
this.InsertDataLabel.Size = new System.Drawing.Size(197, 17);
|
this.InsertDataLabel.Size = new System.Drawing.Size(197, 17);
|
||||||
this.InsertDataLabel.TabIndex = 0;
|
this.InsertDataLabel.TabIndex = 0;
|
||||||
this.InsertDataLabel.Text = "&Insert any int value:";
|
this.InsertDataLabel.Text = "&Insert any int value:";
|
||||||
//
|
//
|
||||||
// InsertDataBox
|
// InsertDataBox
|
||||||
//
|
//
|
||||||
this.InsertDataBox.Location = new System.Drawing.Point(12, 86);
|
this.InsertDataBox.Location = new System.Drawing.Point(12, 86);
|
||||||
this.InsertDataBox.Name = "InsertDataBox";
|
this.InsertDataBox.Name = "InsertDataBox";
|
||||||
this.InsertDataBox.Size = new System.Drawing.Size(246, 24);
|
this.InsertDataBox.Size = new System.Drawing.Size(246, 24);
|
||||||
this.InsertDataBox.TabIndex = 1;
|
this.InsertDataBox.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// ResultLabel
|
// ResultLabel
|
||||||
//
|
//
|
||||||
this.ResultLabel.Dock = System.Windows.Forms.DockStyle.Bottom;
|
this.ResultLabel.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||||
this.ResultLabel.Location = new System.Drawing.Point(0, 143);
|
this.ResultLabel.Location = new System.Drawing.Point(0, 143);
|
||||||
this.ResultLabel.Margin = new System.Windows.Forms.Padding(5);
|
this.ResultLabel.Margin = new System.Windows.Forms.Padding(5);
|
||||||
this.ResultLabel.Name = "ResultLabel";
|
this.ResultLabel.Name = "ResultLabel";
|
||||||
this.ResultLabel.Padding = new System.Windows.Forms.Padding(5);
|
this.ResultLabel.Padding = new System.Windows.Forms.Padding(5);
|
||||||
this.ResultLabel.Size = new System.Drawing.Size(270, 79);
|
this.ResultLabel.Size = new System.Drawing.Size(270, 79);
|
||||||
this.ResultLabel.TabIndex = 2;
|
this.ResultLabel.TabIndex = 2;
|
||||||
this.ResultLabel.Text = "&Insert any int value to insert box above and press \"Calculate\" button to see res" +
|
this.ResultLabel.Text = "&Insert any int value to insert box above and press \"Calculate\" button to see res" +
|
||||||
"ult...";
|
"ult...";
|
||||||
this.ResultLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
this.ResultLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
//
|
//
|
||||||
// CalculateButton
|
// CalculateButton
|
||||||
//
|
//
|
||||||
this.CalculateButton.Location = new System.Drawing.Point(81, 116);
|
this.CalculateButton.Location = new System.Drawing.Point(81, 116);
|
||||||
this.CalculateButton.Name = "CalculateButton";
|
this.CalculateButton.Name = "CalculateButton";
|
||||||
this.CalculateButton.Size = new System.Drawing.Size(103, 23);
|
this.CalculateButton.Size = new System.Drawing.Size(103, 23);
|
||||||
this.CalculateButton.TabIndex = 3;
|
this.CalculateButton.TabIndex = 3;
|
||||||
this.CalculateButton.Text = "Calc&ulate";
|
this.CalculateButton.Text = "Calc&ulate";
|
||||||
this.CalculateButton.UseVisualStyleBackColor = true;
|
this.CalculateButton.UseVisualStyleBackColor = true;
|
||||||
this.CalculateButton.Click += new System.EventHandler(this.CalculateButton_Click);
|
this.CalculateButton.Click += new System.EventHandler(this.CalculateButton_Click);
|
||||||
//
|
//
|
||||||
// SelectFormatterLabel
|
// SelectFormatterLabel
|
||||||
//
|
//
|
||||||
this.SelectFormatterLabel.AutoSize = true;
|
this.SelectFormatterLabel.AutoSize = true;
|
||||||
this.SelectFormatterLabel.Location = new System.Drawing.Point(12, 9);
|
this.SelectFormatterLabel.Location = new System.Drawing.Point(12, 9);
|
||||||
this.SelectFormatterLabel.Name = "SelectFormatterLabel";
|
this.SelectFormatterLabel.Name = "SelectFormatterLabel";
|
||||||
this.SelectFormatterLabel.Size = new System.Drawing.Size(161, 17);
|
this.SelectFormatterLabel.Size = new System.Drawing.Size(161, 17);
|
||||||
this.SelectFormatterLabel.TabIndex = 4;
|
this.SelectFormatterLabel.TabIndex = 4;
|
||||||
this.SelectFormatterLabel.Text = "&Select formatter:";
|
this.SelectFormatterLabel.Text = "&Select formatter:";
|
||||||
//
|
//
|
||||||
// SelectFormatterBox
|
// SelectFormatterBox
|
||||||
//
|
//
|
||||||
this.SelectFormatterBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
this.SelectFormatterBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
this.SelectFormatterBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
this.SelectFormatterBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
||||||
this.SelectFormatterBox.FormattingEnabled = true;
|
this.SelectFormatterBox.FormattingEnabled = true;
|
||||||
this.SelectFormatterBox.Items.AddRange(new object[] {
|
this.SelectFormatterBox.Items.AddRange(new object[] {
|
||||||
"CountFormatter",
|
"CountFormatter",
|
||||||
"FileSizeFormatter"});
|
"FileSizeFormatter"});
|
||||||
this.SelectFormatterBox.Location = new System.Drawing.Point(12, 29);
|
this.SelectFormatterBox.Location = new System.Drawing.Point(12, 29);
|
||||||
this.SelectFormatterBox.Name = "SelectFormatterBox";
|
this.SelectFormatterBox.Name = "SelectFormatterBox";
|
||||||
this.SelectFormatterBox.Size = new System.Drawing.Size(246, 25);
|
this.SelectFormatterBox.Size = new System.Drawing.Size(246, 25);
|
||||||
this.SelectFormatterBox.TabIndex = 5;
|
this.SelectFormatterBox.TabIndex = 5;
|
||||||
//
|
//
|
||||||
// CountValueTest
|
// CountValueTest
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 17F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 17F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(270, 222);
|
this.ClientSize = new System.Drawing.Size(270, 222);
|
||||||
this.Controls.Add(this.SelectFormatterBox);
|
this.Controls.Add(this.SelectFormatterBox);
|
||||||
this.Controls.Add(this.SelectFormatterLabel);
|
this.Controls.Add(this.SelectFormatterLabel);
|
||||||
this.Controls.Add(this.CalculateButton);
|
this.Controls.Add(this.CalculateButton);
|
||||||
this.Controls.Add(this.ResultLabel);
|
this.Controls.Add(this.ResultLabel);
|
||||||
this.Controls.Add(this.InsertDataBox);
|
this.Controls.Add(this.InsertDataBox);
|
||||||
this.Controls.Add(this.InsertDataLabel);
|
this.Controls.Add(this.InsertDataLabel);
|
||||||
this.Font = new System.Drawing.Font("Courier New", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
this.Font = new System.Drawing.Font("Courier New", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
this.MinimizeBox = false;
|
this.MinimizeBox = false;
|
||||||
this.Name = "CountValueTest";
|
this.Name = "CountValueTest";
|
||||||
this.ShowIcon = false;
|
this.ShowIcon = false;
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "Formatter Test Unit";
|
this.Text = "Formatter Test Unit";
|
||||||
this.Load += new System.EventHandler(this.CountValueTest_Load);
|
this.Load += new System.EventHandler(this.CountValueTest_Load);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private Label InsertDataLabel;
|
|
||||||
private TextBox InsertDataBox;
|
|
||||||
private Label ResultLabel;
|
|
||||||
private Button CalculateButton;
|
|
||||||
private Label SelectFormatterLabel;
|
|
||||||
private ComboBox SelectFormatterBox;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label InsertDataLabel;
|
||||||
|
private TextBox InsertDataBox;
|
||||||
|
private Label ResultLabel;
|
||||||
|
private Button CalculateButton;
|
||||||
|
private Label SelectFormatterLabel;
|
||||||
|
private ComboBox SelectFormatterBox;
|
||||||
}
|
}
|
@ -1,42 +1,32 @@
|
|||||||
using anbs_cp;
|
using anbs_cp;
|
||||||
namespace demo
|
|
||||||
|
namespace demo;
|
||||||
|
|
||||||
|
public partial class CountValueTest: Form
|
||||||
{
|
{
|
||||||
public partial class CountValueTest : Form
|
public CountValueTest ()
|
||||||
{
|
{
|
||||||
public CountValueTest()
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CalculateButton_Click (object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(InsertDataBox.Text))
|
||||||
|
return;
|
||||||
|
|
||||||
|
long value = TypeConverter.StrToInt64(InsertDataBox.Text);
|
||||||
|
IValueFormatter formatter = SelectFormatterBox.SelectedIndex switch
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
0 => new CountFormatter(),
|
||||||
}
|
1 => new FileSizeFormatter(),
|
||||||
|
_ => new CountFormatter(),
|
||||||
|
};
|
||||||
|
ResultLabel.Text = formatter.Format(value);
|
||||||
|
}
|
||||||
|
|
||||||
private void CalculateButton_Click(object sender, EventArgs e)
|
private void CountValueTest_Load (object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
SelectFormatterBox.SelectedIndex = 0;
|
||||||
if (string.IsNullOrEmpty(InsertDataBox.Text))
|
|
||||||
return;
|
|
||||||
|
|
||||||
IValueFormatter formatter;
|
|
||||||
|
|
||||||
long value = TypeConverter.StrToInt64(InsertDataBox.Text);
|
|
||||||
|
|
||||||
switch (SelectFormatterBox.SelectedIndex)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
formatter = new CountFormatter();
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
formatter = new FileSizeFormatter();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
formatter = new CountFormatter();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultLabel.Text = formatter.Format(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CountValueTest_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
SelectFormatterBox.SelectedIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,15 +1,14 @@
|
|||||||
namespace demo
|
namespace demo;
|
||||||
|
|
||||||
|
internal static class Program
|
||||||
{
|
{
|
||||||
internal static class Program
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main ()
|
||||||
{
|
{
|
||||||
/// <summary>
|
ApplicationConfiguration.Initialize();
|
||||||
/// The main entry point for the application.
|
Application.Run(new CountValueTest());
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
|
||||||
static void Main()
|
|
||||||
{
|
|
||||||
ApplicationConfiguration.Initialize();
|
|
||||||
Application.Run(new CountValueTest());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user