using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace Dll { public class Class1 { public static List regions = new List { 102, 103, 111, 113, 116, 118, 121, 122, 123, 124, 125, 126, 130, 134, 136, 138, 142, 147, 150, 152, 154, 155, 156, 158, 159, 161, 163, 164, 172, 173, 174, 177, 178, 180, 181, 186, 190, 193, 196, 197, 198, 199, 252, 277, 299, 702, 716, 725, 750, 754, 761, 763, 774, 777, 790, 797, 799, 977 }; public static List letters = new List { 'A', 'B', 'E', 'K', 'M', 'H', 'O', 'P', 'C', 'T', 'Y', 'X' }; public static bool CheckMark(string mark) { if (string.IsNullOrEmpty(mark) || mark.Length != 9) { throw new ArgumentException("Строка не соответствует формату"); } Regex regex = new Regex(@"^[ABEKMHOPCTYX]{1}\d{3}[ABEKMHOPCTYX]{2}\d{2}(\d{1}|[0-9]{2}|[0-7][0-9]|[8][0-8])$"); if (regex.IsMatch(mark)) { string regionCode = mark.Substring(6, 3).ToUpper(); int regionCodeInt = Convert.ToInt32(regionCode); if (regions.Contains(regionCodeInt) || (regionCodeInt >= 1 && regionCodeInt <= 99)) { return true; } } return false; } public static string GetNextMarkAfter(string mark) { if (string.IsNullOrEmpty(mark) || mark.Length != 9) { throw new ArgumentException("Строка не соответствует формату"); } string newMark = mark; int number = Convert.ToInt32(mark.Substring(1, 3)); if(number != 999) { number++; newMark = newMark.Remove(1, 3); newMark = newMark.Insert(1,Convert.ToString(number)); } else { if (newMark[5] != 'X') { int index = letters.IndexOf(newMark[5]); newMark = newMark.Remove(5, 1); newMark = newMark.Insert(5, Convert.ToString(letters[index + 1])); } else if(newMark[4]!= 'X') { int index = letters.IndexOf(newMark[4]); newMark = newMark.Remove(4, 1); newMark = newMark.Insert(4, Convert.ToString(letters[index + 1])); } else if(newMark[0] != 'X') { int index = letters.IndexOf(newMark[0]); newMark = newMark.Remove(0, 1); newMark = newMark.Insert(0, Convert.ToString(letters[index + 1])); } else { return "Это конец..."; } } return newMark; } public static string GetNextMarkAfterInRange(string prevMark, string rangeStart, string rangeEnd) { if (string.IsNullOrEmpty(prevMark) || string.IsNullOrEmpty(rangeStart) || string.IsNullOrEmpty(rangeEnd)) { throw new ArgumentException("Строка не соответствует формату"); } string newMark = prevMark; int number = Convert.ToInt32(prevMark.Substring(1, 3)); int startNumber = Convert.ToInt32(rangeStart.Substring(1, 3)); int endNumber = Convert.ToInt32(rangeEnd.Substring(1, 3)); if (number < endNumber && number >= startNumber) { number++; newMark = newMark.Remove(1, 3); newMark = newMark.Insert(1, Convert.ToString(number)); return newMark; } else { return "out of stock"; } } public static int GetCombinationsCountInRange(string mark1, string mark2) { if (string.IsNullOrEmpty(mark1) || string.IsNullOrEmpty(mark2)) { throw new ArgumentException("Строка не соответствует формату"); } int startNumber = Convert.ToInt32(mark1.Substring(1, 3)); int endNumber = Convert.ToInt32(mark2.Substring(1, 3)); int count = 0; while (startNumber <= endNumber) { count++; startNumber++; } return count; } } }