예제 #1
0
 private void SearchEl_Click(object sender, EventArgs e)
 {
     if (data.ElementExist(input.Text))
     {
         output.Text = data.FindElement(input.Text).ToString();
     }
 }
예제 #2
0
        public string Draw(string compound)
        {
            if (!CountUppervLower(compound))
            {
                compound = SearchByName();
            }
            List <Element> elements = new List <Element>();
            List <string>  elToFind = new List <string>();
            string         curr     = compound.Substring(0, 1);

            for (int i = 1; i < compound.Length; i++)
            {
                if (int.TryParse(compound.Substring(i, 1), out int res))
                {
                    for (int j = 0; j < res; j++)
                    {
                        elToFind.Add(curr);
                    }
                    curr = "";
                }
                else if (compound.Substring(i, 1) == compound.Substring(i, 1).ToUpper()) //new element
                {
                    if (curr != "")
                    {
                        elToFind.Add(curr);
                    }
                    curr = compound.Substring(i, 1);
                }
                else
                {
                    curr += compound.Substring(i, 1);
                }
            }
            if (curr != "")
            {
                elToFind.Add(curr);
            }
            for (int i = 0; i < elToFind.Count; i++)
            {
                Element el = data.FindElement(elToFind[i]);
                if (el == null)
                {
                    return("This is not a valid compound");
                }
                elements.Add(el);
            }

            //create adj matrix
            List <int> valenceEl = new List <int>();

            for (int i = 0; i < elements.Count; i++)
            {
                valenceEl.Add(data.FindProbableAmtValenceEl(elements[i]) - elements[i].AtomicNumber);
            }

            //search for connection
            string        toReturn = "";
            List <string> result   = Solve(elements, valenceEl);

            if (result == null)
            {
                return("Error, cannot solve");
            }
            for (int i = 0; i < result.Count; i++)
            {
                toReturn += result[i];
            }
            return(toReturn);
        }