using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Shlukova_Analyza_BP
{
    public partial class ucOblasti : UserControl
    {
        private static ucOblasti instance;
        public static ucOblasti Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new ucOblasti();
                }
                return instance;
            }
        }
        public ucOblasti()
        {
            InitializeComponent();
            comboBoxOblasti.SelectedIndex = 0;
            textBoxOblasti.Enabled = false;
        }
        private void comboBoxOblasti_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxOblasti.SelectedIndex == 0)
            {
                textBoxOblasti.Enabled = false;
            }
            else
            {
                textBoxOblasti.Enabled = true;
            }
        }
        public int[] Oblasti
        {
            get
            {
                string str = textBoxOblasti.Text;
                List<int> cisla = new List<int>();
                string cislo = "";
                for (int i = 0; i < str.Length; i++)
                {
                    if (char.IsDigit(str[i]))
                    {
                        cislo += str[i];
                        if (i == str.Length - 1)
                        {
                            cisla.Add(Convert.ToInt32(cislo));
                        }
                    }
                    else if (i > 0 && char.IsDigit(str[i - 1]))
                    {
                        cisla.Add(Convert.ToInt32(cislo));
                        cislo = "";
                    }
                }
                int[] oblasti = new int[cisla.Count];
                for (int i = 0; i < cisla.Count; i++)
                {
                    oblasti[i] = cisla[i];
                }
                return oblasti;
            }
        }
        public int TypOblasti
        {
            get { return comboBoxOblasti.SelectedIndex; }
        }
    }
}
