/* EQUATION HEADER AND TEXTBOX FUNCTIONS */ private void Txt_Equation_TextChanged(object sender, EventArgs e) { if (ControlFlow.ConditionRawInput(Txt_Equation.Text, false) != "") { Btn_ExtractVars.Enabled = true; } else { Btn_ExtractVars.Enabled = false; } return; }
/* CALCULATE BUTTON FUNCTION */ private void Btn_Calculate_Click(object sender, EventArgs e) { string equation = ControlFlow.ConditionRawInput(Txt_Equation.Text, false); string variables = ""; List <string> varNames = new List <string>(); string[] delimiters = ControlFlow.GetDelimiters(); Grid_Vars.AllowUserToAddRows = false; foreach (DataGridViewRow var in Grid_Vars.Rows) { if (var.Cells[0].Value != null && var.Cells[1].Value != null && var.Cells[2].Value != null) { if (var.Cells[0].Value.ToString() != "" && var.Cells[1].Value.ToString() != "" && var.Cells[2].Value.ToString() != "") { if (!varNames.Contains(Regex.Replace(var.Cells[0].Value.ToString(), @"\s+", ""))) { variables += var.Cells[0].Value.ToString() + delimiters[1] + var.Cells[1].Value.ToString() + delimiters[1] + var.Cells[2].Value.ToString() + delimiters[0]; varNames.Add(Regex.Replace(var.Cells[0].Value.ToString(), @"\s+", "")); } else { UpdateLog("Warning: Found duplicate variable name (" + Regex.Replace(var.Cells[0].Value.ToString(), @"\s+", "") + "). Removing from the list." + Environment.NewLine); Grid_Vars.Rows.Remove(var); } } } else { Grid_Vars.Rows.Remove(var); } } Grid_Vars.AllowUserToAddRows = true; HandleResults(equation, variables); Txt_Log.AppendText(logMessages); ClearLog(); return; }
/* VARIABLE EXTRACTION FUNCTION */ private void Btn_ExtractVars_Click(object sender, EventArgs e) { string eq = ControlFlow.ConditionRawInput(Txt_Equation.Text, false); string[] variables; string[] varTableRow; bool contains = false; if (eq != "") { variables = ControlFlow.ExtractVariables(eq); if (variables != null) { Txt_Equation.BackColor = System.Drawing.SystemColors.Window; if (variables.Length > 0) { varTableRow = new string[] { "", "", "" }; foreach (string varName in variables) { foreach (DataGridViewRow row in Grid_Vars.Rows) { if (!(row.Cells[0].Value == null)) { if (row.Cells[0].Value.ToString().Contains(varName)) { contains = true; } } } if (!contains) { varTableRow[0] = varName; Grid_Vars.Rows.Add(varTableRow); } contains = false; } Btn_ExtractVars.Enabled = false; } else { Btn_Calculate.Enabled = true; } } else { Txt_Equation.BackColor = System.Drawing.Color.Red; } } else { UpdateLog("Error: Equation field is empty. Please enter an equation into the Equation field to proceed." + Environment.NewLine); Txt_Equation.BackColor = System.Drawing.Color.Red; } Txt_Log.AppendText(logMessages); ClearLog(); return; }