commit
25281888c4
10
README.md
Normal file
10
README.md
Normal file
@ -0,0 +1,10 @@
|
||||
# anbsoftware_componentspack
|
||||
some classes that extend the capabilities of the C # language
|
||||
|
||||
# Welcome to ANB Software Components Pack!
|
||||
|
||||
You are on the component set «ANB» page. Thanks for your interest in the project
|
||||
|
||||
# License
|
||||
|
||||
MIIT
|
34
anbs_cp/CountFormatter.cs
Normal file
34
anbs_cp/CountFormatter.cs
Normal file
@ -0,0 +1,34 @@
|
||||
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>
|
||||
public string[] ValueNames { get => CountNames; set => CountNames = value; }
|
||||
/// <summary>
|
||||
/// Реализация интерфейса
|
||||
/// </summary>
|
||||
public long[] MaxSizes { get => Delimeters; set => Delimeters = value; }
|
||||
#endregion
|
||||
}
|
||||
}
|
56
anbs_cp/FileSizeFormatter.cs
Normal file
56
anbs_cp/FileSizeFormatter.cs
Normal file
@ -0,0 +1,56 @@
|
||||
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>
|
||||
public string[] ValueNames { get => SizeNames; set => SizeNames = value; }
|
||||
/// <summary>
|
||||
/// Реализация интерфейса
|
||||
/// </summary>
|
||||
public long[] MaxSizes
|
||||
{
|
||||
get => new long[] { ByteMax, KByteMax, MByteMax, GByteMax };
|
||||
set
|
||||
{
|
||||
ByteMax = value[0];
|
||||
KByteMax = value[1];
|
||||
MByteMax = value[2];
|
||||
GByteMax = value[3];
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
82
anbs_cp/IValueFormatter.cs
Normal file
82
anbs_cp/IValueFormatter.cs
Normal file
@ -0,0 +1,82 @@
|
||||
namespace anbs_cp
|
||||
{
|
||||
/// <summary>
|
||||
/// Форматирует размерности в понятную строку
|
||||
/// </summary>
|
||||
public interface IValueFormatter
|
||||
{
|
||||
|
||||
#region Определения интерфейса
|
||||
/// <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)
|
||||
{
|
||||
//Левая граница
|
||||
long leftnum;
|
||||
//Правая граница
|
||||
long rightnum;
|
||||
|
||||
for (int i = 0; i <= MaxSizes.Length; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
leftnum = 0;
|
||||
else
|
||||
leftnum = MaxSizes[i - 1];
|
||||
|
||||
if (i == MaxSizes.Length)
|
||||
rightnum = long.MaxValue;
|
||||
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;
|
||||
|
||||
for (int i = 0; i <= DecimalPlaces; i++)
|
||||
{
|
||||
delim *= 10;
|
||||
}
|
||||
|
||||
decimal value = Math.Round((decimal)(dividend * delim / divider)) / delim;
|
||||
|
||||
return $"{value}";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,23 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using System.Collections.Generic;
|
||||
namespace anbs_cp
|
||||
{
|
||||
public class LikeDelphi
|
||||
/// <summary>
|
||||
/// Класс, добавляющий реализацию некоторых методов Delphi, которые упрощают работу в C#.
|
||||
/// </summary>
|
||||
public static class LikeDelphi
|
||||
{
|
||||
/*
|
||||
* Аналог функции "IncludeTrailingBackslash
|
||||
*/
|
||||
public static string IncludeTrailingBackslash(string Path)
|
||||
/// <summary>
|
||||
/// Аналог функции IncludeTrailingBackslash
|
||||
/// </summary>
|
||||
/// <param name="path">Путь, к которому нужно добавить slash</param>
|
||||
/// <returns>Путь со slash в конце</returns>
|
||||
public static string IncludeTrailingBackslash(string path)
|
||||
{
|
||||
string result = Path;
|
||||
int Index = Path.Length - 1;
|
||||
if (Path[Index] != '\\')
|
||||
string result = path;
|
||||
int Index = path.Length - 1;
|
||||
if (path[Index] != '\\')
|
||||
{
|
||||
result = $"{Path}\\";
|
||||
result = $"{path}\\";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Парсер строки в множество строк
|
||||
/// </summary>
|
||||
/// <param name="astring">Строка, которую нужно разбить</param>
|
||||
/// <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
|
||||
{
|
||||
from++;
|
||||
to = astring.IndexOf(delim, from);
|
||||
if (to <= 0)
|
||||
to = astring.Length;
|
||||
if (from != to)
|
||||
result.Add(astring[from..(to-from)]);
|
||||
from = to;
|
||||
} while (to != astring.Length);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace anbs_componentspack
|
||||
{
|
||||
public enum TStringListType
|
||||
{
|
||||
sltStringsOnly, //Только строки -- сортировка по строкам включена, имеющиеся объекты удалит
|
||||
sltObjectsOnly, //Только объекты -- сортировка по объектам включена
|
||||
sltBoth //И строки, и объекты -- сортировка отключена
|
||||
}
|
||||
public class TStringList
|
||||
{
|
||||
private List<string> FLines;
|
||||
private List<object> FObjects;
|
||||
private TStringListType type = TStringListType.sltBoth;
|
||||
public TStringListType Type { get => type; set => type = value; }
|
||||
public int Count => FLines.Count;
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is TStringList list &&
|
||||
Count == list.Count;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Count);
|
||||
}
|
||||
public void Add(string AString)
|
||||
{
|
||||
if (!(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
FLines.Add(AString);
|
||||
if (!(type == TStringListType.sltStringsOnly))
|
||||
{
|
||||
FObjects.Add(AString);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Add(object AObject)
|
||||
{
|
||||
if (!(type == TStringListType.sltStringsOnly))
|
||||
{
|
||||
if (!(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
FLines.Add(AObject.ToString());
|
||||
|
||||
}
|
||||
FObjects.Add(AObject);
|
||||
}
|
||||
}
|
||||
public void Add(string AString, object AObject)
|
||||
{
|
||||
if (!(type == TStringListType.sltStringsOnly) && !(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
FLines.Add(AString);
|
||||
FObjects.Add(AObject);
|
||||
}
|
||||
}
|
||||
public (string, object) Get(int Index) => (FLines[Index], FObjects[Index]);
|
||||
public string GetString(int Index)
|
||||
{
|
||||
string result = "";
|
||||
if (!(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
result = FLines[Index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public object GetObject(int Index)
|
||||
{
|
||||
object result = null;
|
||||
if (!(type == TStringListType.sltStringsOnly))
|
||||
{
|
||||
result = FObjects[Index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void Delete(int Index)
|
||||
{
|
||||
if (!(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
FLines.RemoveAt(Index);
|
||||
}
|
||||
if (!(type == TStringListType.sltStringsOnly))
|
||||
{
|
||||
FObjects.RemoveAt(Index);
|
||||
}
|
||||
}
|
||||
public int IndexOf(string AString) => FLines.IndexOf(AString);
|
||||
public int IndexOf(object AObject) => FObjects.IndexOf(AObject);
|
||||
public void Sort()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case TStringListType.sltStringsOnly:
|
||||
FLines.Sort();
|
||||
break;
|
||||
case TStringListType.sltObjectsOnly:
|
||||
FObjects.Sort();
|
||||
break;
|
||||
case TStringListType.sltBoth:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
FLines.Clear();
|
||||
FObjects.Clear();
|
||||
}
|
||||
public void Assign(List<string> ALines)
|
||||
{
|
||||
if (!(type == TStringListType.sltStringsOnly))
|
||||
{
|
||||
throw new ArgumentException("Assign method works in TStringList only for the sltStringsOnly type. Your changes are not applied!");
|
||||
}
|
||||
Clear();
|
||||
FLines.AddRange(ALines);
|
||||
}
|
||||
public string DelimetedText(char Delimeter)
|
||||
{
|
||||
string result = "";
|
||||
if (!(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
for (int i = 0; i < FLines.Count; i++)
|
||||
{
|
||||
result = $"{result}{Delimeter}{FLines[i]}";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public string Text()
|
||||
{
|
||||
char Delim = '\n';
|
||||
return DelimetedText(Delim);
|
||||
}
|
||||
public void LoadFromFile(string FileName)
|
||||
{
|
||||
if (!File.Exists(FileName))
|
||||
{
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
StreamReader sr = new StreamReader(FileName);
|
||||
string line = sr.ReadLine();
|
||||
while (line != null)
|
||||
{
|
||||
FLines.Add(line);
|
||||
line = sr.ReadLine();
|
||||
}
|
||||
sr.Close();
|
||||
}
|
||||
public void SaveToFile(string FileName)
|
||||
{
|
||||
StreamWriter sw = new StreamWriter(FileName);
|
||||
for (int i = 0; i < FLines.Count; i++)
|
||||
{
|
||||
sw.WriteLine(FLines[i]);
|
||||
}
|
||||
sw.Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +1,114 @@
|
||||
using System;
|
||||
|
||||
namespace anbs_componentspack
|
||||
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();
|
||||
public static int StrToInt(string AStr)
|
||||
/// <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))
|
||||
{
|
||||
result = 0;
|
||||
result = ADefault;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static long StrToInt64(string AStr)
|
||||
/// <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 = 0;
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<Version>0.1.0</Version>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Version>1.20211111.0</Version>
|
||||
<Authors>Alexander Babaev</Authors>
|
||||
<Product>delphi2c#</Product>
|
||||
<Description>Library to import some useful functions from Delphi language to C# language.</Description>
|
||||
<Copyright />
|
||||
<Product>ANB Software Components Pack</Product>
|
||||
<Description>Library of some useful functions in C# language.</Description>
|
||||
<Copyright>Alexander Babaev</Copyright>
|
||||
<AssemblyName>anbs_cp</AssemblyName>
|
||||
<RootNamespace>anbs_cp</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<SignAssembly>False</SignAssembly>
|
||||
<PackageProjectUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</RepositoryUrl>
|
||||
<AssemblyVersion>1.2021.1111</AssemblyVersion>
|
||||
<FileVersion>1.2021.1111</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<WarningLevel>2</WarningLevel>
|
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<WarningLevel>2</WarningLevel>
|
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop" Version="17.0.31902.203" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,10 +1,15 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31424.327
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "anbs_cp", "anbs_cp\anbs_cp.csproj", "{442A56CC-1061-4EB5-8B67-3E3D997976D7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "demo", "demo\demo.csproj", "{3BB0778D-3C34-4DD8-A54E-CB476BEF2F7B}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{442A56CC-1061-4EB5-8B67-3E3D997976D7} = {442A56CC-1061-4EB5-8B67-3E3D997976D7}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -15,6 +20,9 @@ Global
|
||||
{442A56CC-1061-4EB5-8B67-3E3D997976D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{442A56CC-1061-4EB5-8B67-3E3D997976D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{442A56CC-1061-4EB5-8B67-3E3D997976D7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3BB0778D-3C34-4DD8-A54E-CB476BEF2F7B}.Debug|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3BB0778D-3C34-4DD8-A54E-CB476BEF2F7B}.Debug|Any CPU.Build.0 = Release|Any CPU
|
||||
{3BB0778D-3C34-4DD8-A54E-CB476BEF2F7B}.Release|Any CPU.ActiveCfg = Debug.CNF|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
134
demo/CountValueTest.Designer.cs
generated
Normal file
134
demo/CountValueTest.Designer.cs
generated
Normal file
@ -0,0 +1,134 @@
|
||||
namespace demo
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.InsertDataLabel = new System.Windows.Forms.Label();
|
||||
this.InsertDataBox = new System.Windows.Forms.TextBox();
|
||||
this.ResultLabel = new System.Windows.Forms.Label();
|
||||
this.CalculateButton = new System.Windows.Forms.Button();
|
||||
this.SelectFormatterLabel = new System.Windows.Forms.Label();
|
||||
this.SelectFormatterBox = new System.Windows.Forms.ComboBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// InsertDataLabel
|
||||
//
|
||||
this.InsertDataLabel.AutoSize = true;
|
||||
this.InsertDataLabel.Location = new System.Drawing.Point(12, 66);
|
||||
this.InsertDataLabel.Name = "InsertDataLabel";
|
||||
this.InsertDataLabel.Size = new System.Drawing.Size(197, 17);
|
||||
this.InsertDataLabel.TabIndex = 0;
|
||||
this.InsertDataLabel.Text = "&Insert any int value:";
|
||||
//
|
||||
// InsertDataBox
|
||||
//
|
||||
this.InsertDataBox.Location = new System.Drawing.Point(12, 86);
|
||||
this.InsertDataBox.Name = "InsertDataBox";
|
||||
this.InsertDataBox.Size = new System.Drawing.Size(246, 24);
|
||||
this.InsertDataBox.TabIndex = 1;
|
||||
//
|
||||
// ResultLabel
|
||||
//
|
||||
this.ResultLabel.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.ResultLabel.Location = new System.Drawing.Point(0, 143);
|
||||
this.ResultLabel.Margin = new System.Windows.Forms.Padding(5);
|
||||
this.ResultLabel.Name = "ResultLabel";
|
||||
this.ResultLabel.Padding = new System.Windows.Forms.Padding(5);
|
||||
this.ResultLabel.Size = new System.Drawing.Size(270, 79);
|
||||
this.ResultLabel.TabIndex = 2;
|
||||
this.ResultLabel.Text = "&Insert any int value to insert box above and press \"Calculate\" button to see res" +
|
||||
"ult...";
|
||||
this.ResultLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// CalculateButton
|
||||
//
|
||||
this.CalculateButton.Location = new System.Drawing.Point(81, 116);
|
||||
this.CalculateButton.Name = "CalculateButton";
|
||||
this.CalculateButton.Size = new System.Drawing.Size(103, 23);
|
||||
this.CalculateButton.TabIndex = 3;
|
||||
this.CalculateButton.Text = "Calc&ulate";
|
||||
this.CalculateButton.UseVisualStyleBackColor = true;
|
||||
this.CalculateButton.Click += new System.EventHandler(this.CalculateButton_Click);
|
||||
//
|
||||
// SelectFormatterLabel
|
||||
//
|
||||
this.SelectFormatterLabel.AutoSize = true;
|
||||
this.SelectFormatterLabel.Location = new System.Drawing.Point(12, 9);
|
||||
this.SelectFormatterLabel.Name = "SelectFormatterLabel";
|
||||
this.SelectFormatterLabel.Size = new System.Drawing.Size(161, 17);
|
||||
this.SelectFormatterLabel.TabIndex = 4;
|
||||
this.SelectFormatterLabel.Text = "&Select formatter:";
|
||||
//
|
||||
// SelectFormatterBox
|
||||
//
|
||||
this.SelectFormatterBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.SelectFormatterBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
||||
this.SelectFormatterBox.FormattingEnabled = true;
|
||||
this.SelectFormatterBox.Items.AddRange(new object[] {
|
||||
"CountFormatter",
|
||||
"FileSizeFormatter"});
|
||||
this.SelectFormatterBox.Location = new System.Drawing.Point(12, 29);
|
||||
this.SelectFormatterBox.Name = "SelectFormatterBox";
|
||||
this.SelectFormatterBox.Size = new System.Drawing.Size(246, 25);
|
||||
this.SelectFormatterBox.TabIndex = 5;
|
||||
//
|
||||
// CountValueTest
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 17F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(270, 222);
|
||||
this.Controls.Add(this.SelectFormatterBox);
|
||||
this.Controls.Add(this.SelectFormatterLabel);
|
||||
this.Controls.Add(this.CalculateButton);
|
||||
this.Controls.Add(this.ResultLabel);
|
||||
this.Controls.Add(this.InsertDataBox);
|
||||
this.Controls.Add(this.InsertDataLabel);
|
||||
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.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "CountValueTest";
|
||||
this.ShowIcon = false;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Formatter Test Unit";
|
||||
this.Load += new System.EventHandler(this.CountValueTest_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label InsertDataLabel;
|
||||
private TextBox InsertDataBox;
|
||||
private Label ResultLabel;
|
||||
private Button CalculateButton;
|
||||
private Label SelectFormatterLabel;
|
||||
private ComboBox SelectFormatterBox;
|
||||
}
|
||||
}
|
42
demo/CountValueTest.cs
Normal file
42
demo/CountValueTest.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using anbs_cp;
|
||||
namespace demo
|
||||
{
|
||||
public partial class CountValueTest : Form
|
||||
{
|
||||
public CountValueTest()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void CalculateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
60
demo/CountValueTest.resx
Normal file
60
demo/CountValueTest.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
15
demo/Program.cs
Normal file
15
demo/Program.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace demo
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new CountValueTest());
|
||||
}
|
||||
}
|
||||
}
|
16
demo/demo.csproj
Normal file
16
demo/demo.csproj
Normal file
@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Configurations>Release;Debug.CNF</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\anbs_cp\anbs_cp.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user