public double GetQuantity(Hashtable hashAttributeValue) { int i = 0; object[] input = new object[_quantity.m_listParameters.Count]; foreach (String str in _quantity.m_listParameters) { if (str == "AREA") { input[i] = double.Parse(hashAttributeValue[str].ToString()); } else if (str == "LENGTH") { input[i] = double.Parse(hashAttributeValue[str].ToString()); } else { if (SimulationMessaging.GetAttributeType(str) == "STRING") { input[i] = hashAttributeValue[str].ToString(); } else { input[i] = double.Parse(hashAttributeValue[str].ToString()); } } i++; } try { object result = _quantity.RunMethod(input); return((double)result); } catch (Exception exc) { SimulationMessaging.AddMessage(new SimulationMessage("Error in RunMethod. " + exc.Message)); return(0); } }
private bool CheckEquation() { bool isFunction = checkBoxAsFunction.Checked; textBoxCompile.Text = ""; m_strEquation = richTextBoxEquation.Text; m_strEquation = m_strEquation.Trim(); List <string> listError; List <String> listAttributesEquation = Global.TryParseAttribute(m_strEquation, out listError); // See if listAttributeEquations is included in dgvDefault if (listError.Count > 0) { foreach (string str in listError) { textBoxCompile.Text = textBoxCompile.Text + str + "\r\n"; } return(false); } FillDefault(); if (m_strEquation.Length > 6) { if (m_strEquation.Substring(0, 6) == "MODULE") { return(CheckModule()); } else if (m_strEquation.Contains("COMPOUND_TREATMENT")) { return(true); } } if (m_strEquation.Trim().Length == 0) { textBoxCompile.Text = "Equation must be entered before selecting Check or OK."; System.Media.SystemSounds.Exclamation.Play(); return(false); } calculateCheck = new CalculateEvaluate.CalculateEvaluate(); if (isFunction) //Change to allow function equation to accept strings as properties. { string equation = m_strEquation; foreach (String attribute in listAttributesEquation) { String attributeType = SimulationMessaging.GetAttributeType(attribute); if (attributeType == "STRING") { String oldValue = "[" + attribute + "]"; String newValue = "[@" + attribute + "]"; equation = equation.Replace(oldValue, newValue); } else if (attributeType == "DATETIME") { String oldValue = "[" + attribute + "]"; String newValue = "[$" + attribute + "]"; equation = equation.Replace(oldValue, newValue); } } calculateCheck.BuildFunctionClass(equation, "double", null); } else { calculateCheck.BuildTemporaryClass(m_strEquation, true); } try { CompilerResults m_crEquation = calculateCheck.CompileAssembly(); if (calculateCheck.m_listError.Count > 0) { foreach (String str in calculate.m_listError) { textBoxCompile.Text = textBoxCompile.Text + str + "\r\n"; } } if (textBoxCompile.Text.Length == 0) { textBoxCompile.Text = "Compilation successful. Results that appear in right grid calculated using default values."; } else { System.Media.SystemSounds.Exclamation.Play(); return(false); } //If [AGE] is the only variable. This only needs to be solved once so might //as well solve it right now. //Equations that are based only on age can only have 100 distinct values. Fill the solution matrix and look up by age. Hashtable hash = GetDefaultValues(); if (!Solve(hash, listAttributesEquation)) { return(false); } return(true); } catch (Exception ex) { textBoxCompile.Text = "ERROR: unable to compile equation: " + ex.Message; return(false); } }
private bool CheckAreaEquation() { textBoxCompile.Text = ""; m_strEquation = richTextBoxEquation.Text; m_strEquation = m_strEquation.Trim(); List <string> listError; List <String> listAttributesEquation = Global.TryParseAttribute(m_strEquation, out listError); // See if listAttributeEquations is included in dgvDefault if (listError.Count > 0) { foreach (string str in listError) { textBoxCompile.Text = textBoxCompile.Text + str + "\r\n"; } return(false); } FillDefault(); if (m_strEquation.Trim().Length == 0) { textBoxCompile.Text = "Equation must be entered before selecting Check or OK."; System.Media.SystemSounds.Exclamation.Play(); return(false); } // Get list of attributes calculate = new CalculateEvaluate.CalculateEvaluate(); bool isFunction = checkBoxAsFunction.Checked; if (isFunction) //Change to allow function equation to accept strings as properties. { string equation = m_strEquation; foreach (String attribute in listAttributesEquation) { String attributeType = SimulationMessaging.GetAttributeType(attribute); if (attributeType == "STRING") { String oldValue = "[" + attribute + "]"; String newValue = "[@" + attribute + "]"; equation = equation.Replace(oldValue, newValue); } else if (attributeType == "DATETIME") { String oldValue = "[" + attribute + "]"; String newValue = "[$" + attribute + "]"; equation = equation.Replace(oldValue, newValue); } } calculate.BuildFunctionClass(equation, "double", null); } else { calculate.BuildTemporaryClass(m_strEquation, true); } try { CompilerResults m_crEquation = calculate.CompileAssembly(); if (calculate.m_listError.Count > 0) { foreach (String str in calculate.m_listError) { textBoxCompile.Text = textBoxCompile.Text + str + "\r\n"; } } if (textBoxCompile.Text.Length == 0) { textBoxCompile.Text = "Compilation sucessful. Results that appear in right grid calculated using default values."; } else { System.Media.SystemSounds.Exclamation.Play(); return(false); } //If [AGE] is the only variable. This only needs to be solved once so might //as well solve it right now. dgvPerformance.Rows.Clear(); object[] input = new object[dgvDefault.Rows.Count]; int i = 0; foreach (DataGridViewRow row in dgvDefault.Rows) { string attribute = row.Cells[0].Value.ToString(); if (Global.GetAttributeType(attribute) == "STRING") { input[i] = row.Cells[1].Value; } else { double value = 0; Double.TryParse(row.Cells[1].Value.ToString(), out value); input[i] = value; } i++; } object result = calculate.RunMethod(input); calculate.m_assemblyInstance = null; calculate.methodInfo = null; dgvPerformance.ColumnCount = 1; if (this.CalculatedField) { dgvPerformance.Columns[0].HeaderText = "CALCULATED"; } else { dgvPerformance.Columns[0].HeaderText = "COST"; } dgvPerformance.Rows.Add(result); return(true); } catch (Exception ex) { Global.WriteOutput("ERROR: could not compile equation:" + ex.Message); return(false); } }