/// <summary> /// Multiply function /// </summary> /// <param name="values"></param> /// <param name="loop"></param> /// <returns></returns> public string Multiply(ExpressionValues values, int loop) { if (loop == 1) { return(values.value[0]); } //recursive process to do the multiply function values.value[loop - 2] = (Convert.ToDouble(values.value[loop - 1]) * Convert.ToDouble(values.value[loop - 2])).ToString(); return(Multiply(values, loop - 1)); }
/// <summary> /// Devide function /// </summary> /// <param name="values"></param> /// <param name="loop"></param> /// <returns></returns> public string Devide(ExpressionValues values, int loop) { if (loop == 1) { return(values.value[0]); } //recursive process to do the devide function values.value[loop - 2] = (Convert.ToDouble(values.value[loop - 2]) / Convert.ToDouble(values.value[loop - 1])).ToString(); return(Devide(values, loop - 1)); }
public ExpressionValues Operation(Func <PossibleValueSet, PossibleValueSet> operation) { var result = new ExpressionValues(operation(Values)); foreach (string memberExpression in MemberExpressions) { result.MemberExpressionValuesIfEmptyOuterJoined.Add(memberExpression, operation(GetValues(memberExpression))); } return(result); }
/// <summary> /// Subtract function /// </summary> /// <param name="values"></param> /// <param name="loop"></param> /// <returns></returns> public string Subtract(ExpressionValues values, int loop) { if (loop == 1) { return(values.value[0]); } //recursive process to do the subtract function int test = Convert.ToInt32(values.value[loop - 2]) - Convert.ToInt32(values.value[loop - 1]); values.value[loop - 2] = (Convert.ToDouble(values.value[loop - 2]) - Convert.ToDouble(values.value[loop - 1])).ToString(); return(Subtract(values, loop - 1)); }
public string Subtract2(ExpressionValues values, int loop) { if (loop == 1) { return(values.value[0]); } //int check = Math.Sign(Convert.ToInt32("-1")); int test = Convert.ToInt32(values.value[loop - 2]) - Convert.ToInt32(values.value[loop - 1]); values.value[loop - 2] = (Convert.ToDouble(values.value[loop - 2]) - Convert.ToDouble(values.value[loop - 1])).ToString(); return(Subtract2(values, loop - 1)); }
public ExpressionValues Operation(ExpressionValues mergeWith, Func <PossibleValueSet, PossibleValueSet, PossibleValueSet> operation) { var result = new ExpressionValues(operation(Values, mergeWith.Values)); foreach (string memberExpression in MemberExpressions.Union(mergeWith.MemberExpressions)) { var left = GetValues(memberExpression); var right = mergeWith.GetValues(memberExpression); result.MemberExpressionValuesIfEmptyOuterJoined.Add(memberExpression, operation(left, right)); } return(result); }
// We would usually get NULL if one of our inner member expressions was null. // However, it's possible a method call will convert the null value from the failed join into a non-null value. // This could be optimized by actually checking what the method does. For example StartsWith("s") would leave null as null and would still allow us to inner join. //protected override Expression VisitMethodCall(MethodCallExpression expression) //{ // Expression result = base.VisitMethodCall(expression); // return result; //} protected override Expression VisitMember(MemberExpression expression) { // The member expression we're visiting might be on the end of a variety of things, such as: // a.B // a.B.C // (a.B ?? a.C).D // I'm not sure what processing re-linq does to strange member expressions. // TODO: I suspect this code doesn't add the right joins for the last case. // A static member expression such as DateTime.Now has a null Expression. if (expression.Expression == null) { // A static member call is never a join, and it is not an instance member access either: leave // the current value on stack, untouched. return(base.VisitMember(expression)); } var isIdentifier = _isEntityDecider.IsIdentifier( expression.Expression.Type, expression.Member.Name); if (!isIdentifier) { _memberExpressionDepth++; } var result = base.VisitMember(expression); if (!isIdentifier) { _memberExpressionDepth--; } ExpressionValues values = _values.Pop().Operation(pvs => pvs.MemberAccess(expression.Type)); if (_isEntityDecider.IsEntity(expression.Type)) { // Don't add joins for things like a.B == a.C where B and C are entities. // We only need to join B when there's something like a.B.D. var key = ExpressionKeyVisitor.Visit(expression, null); if (_memberExpressionDepth > 0 && _joiner.CanAddJoin(expression)) { result = _joiner.AddJoin(result, key); } values.MemberExpressionValuesIfEmptyOuterJoined[key] = PossibleValueSet.CreateNull(expression.Type); } SetResultValues(values); return(result); }
public string Add2(ExpressionValues values, int loop) { if (loop == 1) { return(values.value[0]); } // int valuescheck = Convert.ToInt32(values.value[loop-1]) + Convert.ToInt32(values.value[loop - 2]); // values.value[loop - 2] = valuescheck.ToString(); values.value[loop - 2] = (Convert.ToDouble(values.value[loop - 1]) + Convert.ToDouble(values.value[loop - 2])).ToString(); return(Add2(values, loop - 1)); //return null; }
internal static void Find(Expression expression, NameGenerator nameGenerator, IIsEntityDecider isEntityDecider, Dictionary <string, NhJoinClause> joins, Dictionary <MemberExpression, QuerySourceReferenceExpression> expressionMap) { WhereJoinDetector f = new WhereJoinDetector(nameGenerator, isEntityDecider, joins, expressionMap); f.VisitExpression(expression); ExpressionValues values = f._values.Pop(); foreach (var memberExpression in values.MemberExpressions) { // If outer join can never produce true, we can safely inner join. if (!values.GetValues(memberExpression).Contains(true)) { f.MakeInnerIfJoined(memberExpression); } } }
private void SetResultValues(ExpressionValues values) { _handled.Pop(); _handled.Push(true); _values.Push(values); }
public PrimaryExpression(ExpressionValues values) : base(values) { }
protected TertiaryExpression(ExpressionValues values) { Values = values; }
protected SecondaryExpression(ExpressionValues values) : base(values) { }
/// <summary> /// Check what values are passed and manupilate as needed by the math expression given /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { Mathematics math = new Mathematics(); MathExpression mathExpression = new MathExpression(); ExpressionValues expresionValue = new ExpressionValues(); GridProperty gridProperty = new GridProperty(); try { if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) { string cell = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); //Define the Mathematical expressions needed and check the value that wi determine the calculation // mathExpression = math.MathExpression(cell, dataGridView.ColumnCount); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = math.MathExpression(cell, dataGridView.ColumnCount); //Check if a calculation needs to happen //if (mathExpression.mathExpressionSymbol != -1) //{ // gridProperty.column = new int[dataGridView.ColumnCount]; // gridProperty.row = new int[dataGridView.RowCount]; // expresionValue.value = new string[dataGridView.ColumnCount]; // Alphabet.AlphabetEnum rowIndex = (Alphabet.AlphabetEnum)e.RowIndex; // string[] names = Enum.GetNames(rowIndex.GetType()); // //Check if a cell value is used with the enum provided // for (int i = 0; i < names.Length; i++) // { // if (names[i] == cell.Substring(mathExpression.mathExpressionSymbol + 1, mathExpression.mathExpressionSymbol + 1)) // { // gridProperty.column[0] = i; // break; // } // else // { // gridProperty.column[0] = -1; // } // } // // gridProperty.column = Alphabet.AlphabetLetter(mathExpression, cell,e.RowIndex,0); // //Check if a cell value is used or if it is a fixed numerical value // if (gridProperty.column[0] != -1) // { // //If a cell value is used use the cell value // if(mathExpression.mathSymbol[4] != 0) // { // gridProperty.row[0] = Convert.ToInt32(cell.Substring(mathExpression.mathExpressionSymbol + 2, mathExpression.mathSymbol[4] - (mathExpression.mathExpressionSymbol + 2))); // if (dataGridView.Rows[gridProperty.row[0] - 1].Cells[gridProperty.column[0]].Value != null) // { // expresionValue.value[0] = dataGridView.Rows[gridProperty.row[0] - 1].Cells[gridProperty.column[0]].Value.ToString(); // } // } // else // { // gridProperty.row[0] = Convert.ToInt32(cell.Substring(mathExpression.mathExpressionSymbol + 2)); // //gridProperty.column[0] = dataGridView.Rows[gridProperty.row[0] - 1].Cells[gridProperty.column[0]].Value.ToString() // dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = dataGridView.Rows[gridProperty.row[0]-1].Cells[gridProperty.column[0]].Value.ToString(); // } // } // else // { // gridProperty.row[0] = Convert.ToInt32(cell.Substring(mathExpression.mathExpressionSymbol + 1, mathExpression.mathSymbol[4] - 1)); // expresionValue.value[0] = gridProperty.row[0].ToString(); // } // // Check the length of the cell text to make sure it is cell values or some cell values // if (cell.Length > 3) // { // for (int j = 0; j < names.Length; j++) // { // if (names[j] == cell.Substring(mathExpression.mathSymbol[4] + 1, 1)) // { // gridProperty.column[1] = j; // break; // } // else // { // gridProperty.column[1] = -1; // } // } // //gridProperty.column = Alphabet.AlphabetLetter(mathExpression, cell, e.RowIndex, 1); // //Check if a cell value is used or if it is a fixed numerical value // if (gridProperty.column[1] != -1) // { // //If a cell value is used use the cell value // gridProperty.row[1] = Convert.ToInt32(cell.Substring(mathExpression.mathSymbol[4] + 2)); // if (dataGridView.Rows[gridProperty.row[1] - 1].Cells[gridProperty.column[1]].Value != null) // { // expresionValue.value[1] = dataGridView.Rows[gridProperty.row[1] - 1].Cells[gridProperty.column[1]].Value.ToString(); // } // } // else // { // gridProperty.row[1] = Convert.ToInt32(cell.Substring(mathExpression.mathSymbol[4] + 1)); // expresionValue.value[1] = gridProperty.row[1].ToString(); // } // } // else // { // mathExpression.mathCalculationSymbol = "default"; // } // //Switch to call the right Mathermatical Expression // switch (mathExpression.mathCalculationSymbol) // { // case "+": // dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = math.Add(expresionValue); // break; // case "-": // dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = math.Subtract(expresionValue); // break; // case "*": // dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = math.Multiply(expresionValue); // break; // case "/": // dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = math.Devide(expresionValue); // break; // default: // // dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = expresionValue.value[0]; // break; // } //} } } catch (Exception ex) { // exception written to active cell MessageBox.Show("An Error occured on the cell: " + ex); } }
/// <summary> /// Initial mathematical call and manupilation of string value /// </summary> /// <param name="text"></param> /// <param name="cells"></param> /// <returns></returns> public string MathExpression(string text, int cells) { try { //Define the Mathematical expressions needed and check the value that wi determine the calculation MathExpression mathExpressionLocal = new MathExpression(); ExpressionValues ExpressionLocal = new ExpressionValues(); ExpressionLocal.value = new string[100]; int count = -1; string answer = null; //split the string given to validate what mathematical functions to call and calculations to do count = text.Split('*').Length - 1; if (count == 0) { count = text.Split('/').Length - 1; if (count == 0) { count = text.Split('+').Length - 1; if (count == 0) { count = text.Split('-').Length - 1; answer = Calcultation(text.Substring(1), ExpressionLocal, count); } else { answer = Calcultation(text.Substring(1), ExpressionLocal, count); } } else { count = text.Split('+').Length - 1; if (count == 0) { count = text.Split('-').Length - 1; if (count == 0) { answer = Calcultation(text.Substring(1), ExpressionLocal, cells); } else { answer = Calcultation(text.Substring(1), ExpressionLocal, count); } } else { answer = Calcultation(text.Substring(1), ExpressionLocal, count); } } } else { count = text.Split('/').Length - 1; if (count == 0) { count = text.Split('+').Length - 1; if (count == 0) { count = text.Split('-').Length - 1; if (count == 0) { answer = Calcultation(text.Substring(1), ExpressionLocal, cells); } else { answer = Calcultation(text.Substring(1), ExpressionLocal, cells); } } else { answer = Calcultation(text.Substring(1), ExpressionLocal, count); } } else { answer = Calcultation(text.Substring(1), ExpressionLocal, count); } } return(answer); } catch (Exception ex) { //MessageBox.Show("An Error occured on the Math: " + ex); return(null); } }
public string Devide(ExpressionValues values) { return((Convert.ToInt32(values.value[0]) / Convert.ToInt32(values.value[1])).ToString()); }
/// <summary> /// Recursive calculation method for all calculations needed /// </summary> /// <param name="text"></param> /// <param name="ExpressionLocal"></param> /// <param name="length"></param> /// <returns></returns> public string Calcultation(string text, ExpressionValues ExpressionLocal, int length) { //do the calculations with 2 values at a time for the whole string string[] expression = text.Substring(0).Split('+'); string answer = null; string value = null; for (int i = 0; i < expression.Length; i++) { // check which mathematical expressions where passed bool matchMinus = expression[i].Contains("-"); bool matchMultiply = expression[i].Contains("*"); bool matchDivide = expression[i].Contains("/"); bool matchPlus = expression[i].Contains("+"); if (!string.IsNullOrEmpty(expression[i])) { if (matchMinus == true) { if (expression[i].Substring(0, 1) != "-") { string[] subExpression = expression[i].Substring(0).Split('-'); //do the calculations for each expression for (int g = 0; g < subExpression.Length; g++) { if (matchPlus == true || matchDivide == true || matchMultiply == true) { subExpression[g] = Calcultation(subExpression[g], ExpressionLocal, 1); } } ExpressionLocal.value = subExpression; value = Subtract(ExpressionLocal, ExpressionLocal.value.Length); expression[i] = value; } } if (matchMultiply == true) { if (expression[i].Substring(0, 1) != "-") { string[] subExpression = expression[i].Substring(0).Split('*'); //do the calculations for each expression for (int g = 0; g < subExpression.Length; g++) { if (matchMinus == true || matchDivide == true || matchPlus == true) { subExpression[g] = Calcultation(subExpression[g], ExpressionLocal, 1); } } ExpressionLocal.value = subExpression; value = Multiply(ExpressionLocal, ExpressionLocal.value.Length); expression[i] = value; } } if (matchDivide == true) { if (expression[i].Substring(0, 1) != "-") { string[] subExpression = expression[i].Substring(0).Split('/'); //do the calculations for each expression for (int g = 0; g < subExpression.Length; g++) { if (matchMinus == true || matchMultiply == true || matchPlus == true) { subExpression[g] = Calcultation(subExpression[g], ExpressionLocal, 1); } } ExpressionLocal.value = subExpression; value = Devide(ExpressionLocal, ExpressionLocal.value.Length); expression[i] = value; } } if (matchPlus == true) { if (expression[i].Substring(0, 1) != "-") { string[] subExpression = expression[i].Substring(0).Split('+'); //do the calculations for each expression for (int g = 0; g < subExpression.Length; g++) { if (matchMinus == true || matchDivide == true || matchMultiply == true) { subExpression[g] = Calcultation(subExpression[g], ExpressionLocal, 1); } } ExpressionLocal.value = subExpression; value = Add(ExpressionLocal, ExpressionLocal.value.Length); expression[i] = value; } } } if (i == (expression.Length - 1)) { ExpressionLocal.value = expression; answer = Add(ExpressionLocal, ExpressionLocal.value.Length); } } if (length == 1) { return(answer); } return(Calcultation(text, ExpressionLocal, length - 1)); }
public string Subtract(ExpressionValues values) { return((Convert.ToInt32(values.value[0]) - Convert.ToInt32(values.value[1])).ToString()); }
public string Calcultation(string text, ExpressionValues ExpressionLocal, int length) { //int count = text.Split('+').Length - 1; string[] test = text.Substring(0).Split('+'); // mathExpressionLocal.mathPlusSymbol = test; // int value = 0; string answer = null; string value = null; //int pos = Array.IndexOf(test, match); for (int i = 0; i < test.Length; i++) { bool matchMinus = test[i].Contains("-"); bool matchMultiply = test[i].Contains("*"); bool matchDivide = test[i].Contains("/"); //string match = Array.Find(test, n => n.Contains("-")); //if (!string.IsNullOrEmpty(match)) if (!string.IsNullOrEmpty(test[i])) { if (matchMinus == true) { // if (match.Substring(0, 1) != "-") if (test[i].Substring(0, 1) != "-") { string[] test2 = test[i].Substring(0).Split('-'); for (int g = 0; g < test2.Length; g++) { test2[g] = Calcultation(test2[g], ExpressionLocal, 1); } ExpressionLocal.value = test2; // value = Convert.ToInt32(test2[0]) - Convert.ToInt32(test2[1]); value = Subtract2(ExpressionLocal, ExpressionLocal.value.Length); test[i] = value; } } if (matchMultiply == true) { // if (match.Substring(0, 1) != "-") if (test[i].Substring(0, 1) != "-") { string[] test2 = test[i].Substring(0).Split('*'); for (int g = 0; g < test2.Length; g++) { test2[g] = Calcultation(test2[g], ExpressionLocal, 1); } ExpressionLocal.value = test2; // value = Convert.ToInt32(test2[0]) - Convert.ToInt32(test2[1]); value = Multiply2(ExpressionLocal, ExpressionLocal.value.Length); test[i] = value; } } if (matchDivide == true) { // if (match.Substring(0, 1) != "-") if (test[i].Substring(0, 1) != "-") { string[] test2 = test[i].Substring(0).Split('/'); ExpressionLocal.value = test2; // value = Convert.ToInt32(test2[0]) - Convert.ToInt32(test2[1]); value = Devide2(ExpressionLocal, ExpressionLocal.value.Length); test[i] = value; } } } if (i == (test.Length - 1)) { ExpressionLocal.value = test; answer = Add2(ExpressionLocal, ExpressionLocal.value.Length); } } if (length == 1) { return(answer); } // int valuescheck = Convert.ToInt32(values.value[loop-1]) + Convert.ToInt32(values.value[loop - 2]); // values.value[loop - 2] = valuescheck.ToString(); return(Calcultation(text, ExpressionLocal, length - 1)); // return answer; }
public ExpressionValues Operation(ExpressionValues mergeWith, Func<PossibleValueSet, PossibleValueSet, PossibleValueSet> operation) { var result = new ExpressionValues(operation(Values, mergeWith.Values)); foreach (string memberExpression in MemberExpressions.Union(mergeWith.MemberExpressions)) { var left = GetValues(memberExpression); var right = mergeWith.GetValues(memberExpression); result.MemberExpressionValuesIfEmptyOuterJoined.Add(memberExpression, operation(left, right)); } return result; }
public string Multiply(ExpressionValues values) { return((Convert.ToInt32(values.value[0]) * Convert.ToInt32(values.value[1])).ToString()); }
public ExpressionValues Operation(Func<PossibleValueSet, PossibleValueSet> operation) { var result = new ExpressionValues(operation(Values)); foreach (string memberExpression in MemberExpressions) { result.MemberExpressionValuesIfEmptyOuterJoined.Add(memberExpression, operation(GetValues(memberExpression))); } return result; }
//public MathExpression MathExpression(string text, int cells) public string MathExpression(string text, int cells) { try { //Define the Mathematical expressions needed and check the value that wi determine the calculation MathExpression mathExpressionLocal = new MathExpression(); ExpressionValues ExpressionLocal = new ExpressionValues(); ExpressionLocal.value = new string[5]; int count = -1; string answer = null; count = text.Split('*').Length - 1; if (count == 0) { count = text.Split('/').Length - 1; if (count == 0) { count = text.Split('+').Length - 1; if (count == 0) { count = text.Split('-').Length - 1; //if } else { answer = Calcultation(text.Substring(1), ExpressionLocal, count); } } else { count = text.Split('+').Length - 1; if (count == 0) { count = text.Split('-').Length - 1; } else { answer = Calcultation(text.Substring(1), ExpressionLocal, count); } } } else { count = text.Split('/').Length - 1; if (count == 0) { count = text.Split('+').Length - 1; if (count == 0) { count = text.Split('-').Length - 1; } else { answer = Calcultation(text.Substring(1), ExpressionLocal, count); } } else { answer = Calcultation(text.Substring(1), ExpressionLocal, count); } } return(answer); //mathExpressionLocal.mathSymbol = new int[cells]; //mathExpressionLocal.mathSymbol[0] = text.IndexOf('+'); //mathExpressionLocal.mathSymbol[1] = text.IndexOf('-'); //mathExpressionLocal.mathSymbol[2] = text.IndexOf('*'); //mathExpressionLocal.mathSymbol[3] = text.IndexOf('/'); //mathExpressionLocal.mathExpressionSymbol = text.IndexOf('='); ////Check which mathematical expression is used //for (int check = 0; check < mathExpressionLocal.mathSymbol.Length; check++) //{ // if (mathExpressionLocal.mathSymbol[check] != -1) // { // mathExpressionLocal.mathSymbol[4] = mathExpressionLocal.mathSymbol[check]; // mathExpressionLocal.mathCalculationSymbol = text.Substring(mathExpressionLocal.mathSymbol[check], 1); // } //} //return mathExpressionLocal; } catch (Exception ex) { //MessageBox.Show("An Error occured on the Math: " + ex); return(null); } }
/// <summary> /// Check what values are passed and manupilate as needed by the math expression given /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { Mathematics math = new Mathematics(); MathExpression mathExpression = new MathExpression(); ExpressionValues expresionValue = new ExpressionValues(); GridProperty gridProperty = new GridProperty(); gridProperty.column = new int[dataGridView.ColumnCount]; gridProperty.row = new int[dataGridView.RowCount]; try { if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) { //get info from cell to string for manupilation string cell = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); //check if the string is null or empty if (!string.IsNullOrEmpty(cell)) { //Check if single value needs to be written or calculation needs to follow if (cell.Substring(0, 1) == "=") { var letterNumberLocation = Regex.Matches(cell, @"[a-zA-Z]{0,1}\d{0,3}"); //check if a value needs to be copied or if calculation needs to happen if (letterNumberLocation.Count < 4) { cell = cell.Substring(1); Alphabet.AlphabetEnum rowIndex = (Alphabet.AlphabetEnum)e.RowIndex; string[] names = Enum.GetNames(rowIndex.GetType()); // Check if a cell value is used with the enum provided for (int i = 0; i < names.Length; i++) { if (names[i] == cell.Substring(0, 1)) { //copy the value found to the new column gridProperty.column[i] = i; gridProperty.row[i] = Convert.ToInt32(cell.Substring(1)); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = dataGridView.Rows[gridProperty.row[gridProperty.row[i]]].Cells[gridProperty.column[gridProperty.column[i]]].Value.ToString(); break; } } } else { int count = 0; expresionValue.value = new string[dataGridView.ColumnCount]; //Define the Mathematical expressions needed and check the value that wi determine the calculation cell = cell.Substring(1); string newCell = null; //Regex ecpressions to get the row and column values for string munipilation bool errorCounter = Regex.IsMatch(cell, @"[a-zA-Z]"); var letterLocation = Regex.Matches(cell, @"[a-zA-Z]{0,1}"); //var letterNumberLocation = Regex.Matches(cell, @"[a-zA-Z]{0,1}\d{0,3}"); var numberLocation = Regex.Matches(cell, @"\d{0,3}"); int numberCount = Regex.Matches(cell, @"\d{1,3}").Count; //check if Alpabetical symbols are available if (false != errorCounter) { for (int g = 0; g < numberLocation.Count; g++) { if (!string.IsNullOrEmpty(numberLocation[g].ToString())) { Alphabet.AlphabetEnum rowIndex = (Alphabet.AlphabetEnum)e.RowIndex; string[] names = Enum.GetNames(rowIndex.GetType()); // Check if a cell value is used with the enum provided for (int i = 0; i < names.Length; i++) { if (g == 0) { //Check the first value that comes in if (names[i] == letterLocation[g].ToString()) { //use the alphabet value to determine the numerical value on where to find the value gridProperty.column[count] = i; gridProperty.row[count] = Convert.ToInt32(cell.Substring(numberLocation[g].Index, numberLocation[g].Length)); expresionValue.value[count] = dataGridView.Rows[gridProperty.row[g] - 1].Cells[gridProperty.column[g]].Value.ToString(); break; } else { //if it does not have a aphabetical value wright it straigt into the array expresionValue.value[count] = numberLocation[g].ToString(); } } else { // calculate and manipulate the rest of the values from 1 up if (names[i] == letterLocation[g - 1].ToString()) { gridProperty.column[count] = i; gridProperty.row[count] = Convert.ToInt32(cell.Substring(numberLocation[g].Index, numberLocation[g].Length)); expresionValue.value[count] = dataGridView.Rows[gridProperty.row[count] - 1].Cells[gridProperty.column[count]].Value.ToString(); break; } else { expresionValue.value[count] = numberLocation[g].ToString(); } } } //create the new string from the values collected from the cell to do the calculations if (count == 0) { newCell = expresionValue.value[count] + cell.Substring(numberLocation[g].Index + numberLocation[g].Length, 1); } else { if (numberCount - 1 == count) { newCell = newCell + expresionValue.value[count]; } else { newCell = newCell + expresionValue.value[count] + cell.Substring(numberLocation[g].Index + numberLocation[g].Length, 1); } } count++; } } } else { newCell = cell; } //pass the new string with the values to the calculation method dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = math.MathExpression("=" + newCell, 1); } } } } } catch (Exception ex) { // exception Given in pop up box MessageBox.Show("An Error occured on the cell: " + ex); } }
public SubExpression[] GetSubExpressions() { if (string.IsNullOrWhiteSpace(ExpressionString)) { return(null); } if (!ExpressionString.Contains('(') && !ExpressionString.Contains(')')) { return(GetSubs()); } var subs = 0; var currentExpression = string.Empty; var result = new List <SubExpression>(); for (var i = 0; i < ExpressionString.Length; i++) { var c = ExpressionString[i]; if (c == '(') { subs++; if (subs == 1) { if (!string.IsNullOrWhiteSpace(currentExpression)) { result.Add(new SubExpression(currentExpression, this)); } currentExpression = string.Empty; } else { currentExpression += c; } } else if (c == ')') { subs--; if (subs == 0) { if (!string.IsNullOrWhiteSpace(currentExpression)) { result.Add(new SubExpression(currentExpression, this)); } currentExpression = string.Empty; } else { currentExpression += c; } } else if (ExpressionValues.IsMathSymbol(c) && subs == 0) { if (!string.IsNullOrWhiteSpace(currentExpression)) { result.Add(new SubExpression(currentExpression, this)); } currentExpression = string.Empty; result.Add(new SubExpression(c.ToString(), this)); } else { currentExpression += c; } } if (!string.IsNullOrWhiteSpace(currentExpression)) { result.Add(new SubExpression(currentExpression, this)); } if (result.Count == 1 && result[0].ExpressionString == ExpressionString) { return(null); } return(result.ToArray()); }