using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Xml; namespace UAS_MES_Tools { internal static class FormMethods { public static bool IsCheckSNRules(string Rule,string SN,string RuleLeng) { if (SN.Length != Convert.ToInt32(RuleLeng)) return true; int RuleIndex = 0; int SNIndex = 0; while (RuleIndex < Rule.Length && SNIndex < SN.Length) { char RuleChar = Rule[RuleIndex]; if (RuleChar == '{') { int endBraceIndex = Rule.IndexOf('}', RuleIndex); if (endBraceIndex == -1) { return true; } string content = Rule.Substring(RuleIndex + 1, endBraceIndex - RuleIndex - 1); if (content.Contains(",")) { string[] allowedChars = content.Split(','); if (Array.IndexOf(allowedChars, SN[SNIndex].ToString()) == -1) { return true; } } else if (content == "YY") { if (SNIndex + 1 >= SN.Length) return true; string yearPart = SN.Substring(SNIndex, 2); if (!Regex.IsMatch(yearPart, @"^\d{2}$")) { return true; } SNIndex++; } else if (content == "MM") { if (SNIndex + 1 >= SN.Length) return true; string monthPart = SN.Substring(SNIndex, 2); if (!Regex.IsMatch(monthPart, @"^(0[1-9]|1[0-2])$")) { return true; } SNIndex++; } else if (content == "DD") { if (SNIndex + 1 >= SN.Length) return true; string dayPart = SN.Substring(SNIndex, 2); if (!Regex.IsMatch(dayPart, @"^(0[1-9]|[12]\d|3[01])$")) { return true; } SNIndex++; } else { return true; } RuleIndex = endBraceIndex + 1; SNIndex++; } else if (RuleChar == '*') { RuleIndex++; SNIndex++; } else { if (RuleChar != SN[SNIndex]) { return true; } RuleIndex++; SNIndex++; } } if (RuleIndex != Rule.Length || SNIndex != SN.Length) { return true; } return false; } } }