Example #1
0
 void EntryIP2(System.Object sender, System.EventArgs e)
 {
     if (IP_adress_2.Text.Length > 0)
     {
         if (IP_adress_2.Text.EndsWith("."))
         {
             IP_adress_3.CursorPosition = 1;
             char[] MyChar = { '.' };
             IP_adress_2.Text = IP_adress_2.Text.TrimEnd(MyChar);
         }
         if (!EntNumCheck.EntryNumCheck(IP_adress_2.Text) && !IP_adress_2.Text.EndsWith("."))
         {
             IP_adress_2.Text           = "";
             IP_adress_2.CursorPosition = 1;
         }
     }
     try
     {
         if (IP_adress_2.Text.Length > 2)
         {
             IP_adress_3.CursorPosition = 1;
             if (Int32.Parse(IP_adress_2.Text) > 255)
             {
                 IP_adress_2.Text           = "";
                 IP_adress_2.CursorPosition = 1;
             }
         }
     }
     catch
     {
     }
 }
        void InputPortsTextChanged(System.Object sender, System.EventArgs e)
        {
            // Проверка, если ввод больше 3-х чисел

            Regex regnum3 = new Regex(@"([0-9]{3}\Z)");

            if (regnum3.IsMatch(InputPorts.Text))
            {
                InputPorts.Text = InputPorts.Text.Remove(InputPorts.Text.Length - 1);
            }
            ;


            // Проверка, если пустой ввод

            if (InputPorts.Text.Length == 0)
            {
                Array.Resize(ref numbers, 0);
            }
            ;

            // Проверка если ввод больше 48

            Regex regnum48 = new Regex(@"([0-9]{2}\Z)");

            if (regnum48.IsMatch(InputPorts.Text))
            {
                int PortNo = Int32.Parse(InputPorts.Text.Substring(InputPorts.Text.Length - 2, 2));
                if (PortNo > 48)
                {
                    InputPorts.Text = InputPorts.Text.Remove(InputPorts.Text.Length - 2);
                }
            }

            // Проверка  на ноль

            Regex regzero = new Regex(@"(\A01?)");

            if (regzero.IsMatch(InputPorts.Text) || InputPorts.Text.EndsWith(",0"))
            {
                InputPorts.Text = InputPorts.Text.Remove(InputPorts.Text.Length - 1);
            }

            // Проверка - первые символы должны быть числа

            if (InputPorts.Text.Length == 1)
            {
                if (!EntNumCheck.EntryNumCheck(InputPorts.Text))
                {
                    InputPorts.Text = InputPorts.Text.Remove(InputPorts.Text.Length - 1);
                }
                numbers = InputPorts.Text.Split(new Char[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            }

            // Проверка - символы больше 2-х должны быть числа, запятые и тире

            else if (InputPorts.Text.Length >= 2)
            {
                if (!EntNumCheck.EntryNumCheck(InputPorts.Text) && (!(InputPorts.Text.EndsWith(",") || InputPorts.Text.EndsWith("-"))))
                {
                    InputPorts.Text = InputPorts.Text.Remove(InputPorts.Text.Length - 1);
                }

                // Проверка на случайные повторения типа ",," ",-" "-," "--"

                if (InputPorts.Text.EndsWith(",,") || InputPorts.Text.EndsWith(",-") || InputPorts.Text.EndsWith("-,") || InputPorts.Text.EndsWith("--"))
                {
                    InputPorts.Text = InputPorts.Text.Remove(InputPorts.Text.Length - 1);
                }

                // Проверка на двойное тире, типа "x-x-", где х - число

                Regex regdoubleminus = new Regex(@"([0-9]+-[0-9]+-\Z)");

                if (regdoubleminus.IsMatch(InputPorts.Text))
                {
                    InputPorts.Text = InputPorts.Text.Remove(InputPorts.Text.Length - 1);
                }

                // Расчет диапазона портов

                Regex regrange = new Regex(@"([0-9]+-[0-9]+,\Z)");
                if (regrange.IsMatch(InputPorts.Text))
                {
                    string[] rports      = InputPorts.Text.Split(new Char[] { ',', '-' }, StringSplitOptions.RemoveEmptyEntries);
                    int      startrport  = Int32.Parse((rports[rports.Length - 2]));
                    int      finishrport = Int32.Parse((rports[rports.Length - 1]));
                    string   str         = "";
                    for (int i = startrport; i <= finishrport; i++)
                    {
                        str += i + ",";
                    }
                    InputPorts.Text = InputPorts.Text.Remove(InputPorts.Text.Length - (Convert.ToString(startrport).Length + Convert.ToString(finishrport).Length + 2)) + str;
                }

                numbers = InputPorts.Text.Split(new Char[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            }
        }