Esempio n. 1
0
        public bool MyCircle(int row, int column)  //!!!
        {
            DataCell      cell    = Data.GetData(row, column);
            List <string> depList = new List <string>();

            depList.Add(cell.name_get());
            string searchableCell = cell.name_get();
            string currentCell    = searchableCell;
            bool   withoutCircle  = true;

            CircleRecursivHelper(cell);
            DataCell tempCell;

            void CircleRecursivHelper(DataCell cell1)
            {
                if (!withoutCircle)
                {
                    return;
                }

                tempCell = Data.GetData(LetterNumberConverter.NameToRaw(currentCell), LetterNumberConverter.NameToColumn(currentCell));
                while (tempCell.related.Count != 0)
                {
                    if (!withoutCircle)
                    {
                        return;
                    }
                    foreach (var depend in tempCell.related)
                    {
                        currentCell = depend;

                        if (currentCell == searchableCell)
                        {
                            withoutCircle = false;
                            //MessageBox.Show("Circle");
                            return;
                        }
                        depList.Add(currentCell);
                        if (withoutCircle == false)
                        {
                            return;
                        }
                        CircleRecursivHelper(Data.GetData(LetterNumberConverter.NameToRaw(currentCell), LetterNumberConverter.NameToColumn(currentCell)));
                        if (withoutCircle == false)
                        {
                            return;
                        }
                        depList.Remove(currentCell);
                    }
                    if (withoutCircle == false)
                    {
                        return;
                    }
                }
            }

            if (!withoutCircle)
            {
                Data.GetData(LetterNumberConverter.NameToRaw(searchableCell), LetterNumberConverter.NameToColumn(searchableCell)).value_set("Error");
                // dataGridView1.Rows[int.Parse(searchableCell[1].ToString())].Cells[int.Parse((searchableCell[0] - 65).ToString())].Value = "#CIRCLE";
                for (int i = 0; i < depList.Count; i++)
                {
                    Data.GetData(LetterNumberConverter.NameToRaw(depList[i]), LetterNumberConverter.NameToColumn(depList[i])).value_set("Error");
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        public bool IsCycled()
        {
            try
            {
                List <string> temp = new List <string>();
                temp.Add(name);

                int  i    = 0;
                bool flag = false;
                if (related.Count == 1)
                {
                    if (name == related[0])
                    {
                        value = "Error"; return(true);
                    }
                }
                while (true)
                {
                    int m = temp.Count;
                    if (i == (m))
                    {
                        break;
                    }

                    DataCell tempr = Data.GetData(LetterNumberConverter.NameToRaw(temp[i]), LetterNumberConverter.NameToColumn(temp[i]));
                    for (int j = 0; j < tempr.related.Count; j++)
                    {
                        temp.Add(tempr.related[j]);
                    }



                    for (int j = 0; j < temp.Count; j++)
                    {
                        for (int h = j + 1; h < temp.Count; h++)
                        {
                            if (temp[j] == temp[h])
                            {
                                flag = true; break;
                            }
                        }
                        if (flag == true)
                        {
                            break;
                        }
                    }
                    if (flag == true)
                    {
                        break;
                    }
                    i++;
                }


                string k = "";
                for (int j = 0; j < temp.Count; j++)
                {
                    k += temp[j];  //.ToString() + " ";
                }
                Console.WriteLine(k);



                if (flag == false)
                {
                    return(false);
                }

                for (int j = 0; j < temp.Count; j++)
                {
                    DataCell tempr = Data.GetData(LetterNumberConverter.NameToRaw(temp[j]), LetterNumberConverter.NameToColumn(temp[j]));
                    tempr.value_set("Error");
                }
                return(true);
            }
            catch (Exception) { return(true); }
        }
Esempio n. 3
0
        private string Preparing(string expression, int column, int row)
        {
            try
            {
                DataCell temp_      = Data.GetData(row, column);
                string   alphabet   = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                string   operations = "+*/^incdecmoddiv-()";
                // string numbers = "0123456789";

                expression = NoSpaces(expression);
                List <string> temp3       = new List <string>();
                string        expression2 = "+" + expression + "+";
                for (int i = 0; i < expression2.Length; i++)
                {
                    if (alphabet.Contains(expression2[i]))
                    {
                        string temp = "";
                        for (; ((!operations.Contains(expression2[i]))); i++)
                        {
                            temp += expression2[i];
                        }
                        if (!temp3.Contains(temp))
                        {
                            temp3.Add(temp);
                        }
                    }
                }


                temp_.related = temp3;


                //  if (MyCircle(row, column)) return "Error"; V2
                if (temp_.IsCycled())
                {
                    return("Error");
                }

                for (int i = 0; i < temp_.related.Count; i++)
                {
                    if ((Data.GetData(LetterNumberConverter.NameToRaw(temp_.related[i]), LetterNumberConverter.NameToColumn(temp_.related[i]))) == null)
                    {
                        return("Error");
                    }
                    string m;
                    if (Data.GetData(LetterNumberConverter.NameToRaw(temp_.related[i]), LetterNumberConverter.NameToColumn(temp_.related[i])).value_get() == null)
                    {
                        m = "0";
                    }
                    else if (Data.GetData(LetterNumberConverter.NameToRaw(temp_.related[i]), LetterNumberConverter.NameToColumn(temp_.related[i])).value_get() == "Error")
                    {
                        return("Error");
                    }
                    else
                    {
                        m = Data.GetData(LetterNumberConverter.NameToRaw(temp_.related[i]), LetterNumberConverter.NameToColumn(temp_.related[i])).value_get();
                    }

                    expression = expression.Replace(temp_.related[i], m);
                }

                return(expression);
            }
            catch (Exception) { return("Error"); }
        }