public double Cost(Hashtable hashAttributeValue) { //return this.UnitCost * GetQuantity(hashAttributeValue); double cost = 0.0; try { cost = double.Parse(_cost.m_strResult); } catch (Exception exc) { SimulationMessaging.AddMessage(new SimulationMessage("Could not parse cost to a double. Cost set to zero." + exc.Message)); } return(cost); }
/// <summary> /// Saves any changes made to the currently selected compound treatment, including its associated elements to the database. /// </summary> private void SaveCurrentCompoundTreatmentChanges() { // Navigation off of a blank row will produce a null value for _compoundTreatment. No changes are necessary in the database in this case. if (_compoundTreatment != null) { // Statements for database changes. List <string> changeStatements = new List <string>(); // Delete from the compound treatment table our current compound treatment. This should cascade and remove its elements from teh element table as well. string delete = "DELETE FROM COMPOUND_TREATMENTS WHERE COMPOUND_TREATMENT_ID = '" + _compoundTreatment.CompoundTreatmentID + "'"; changeStatements.Add(delete); // Now insert the current compound treatment string insert = "INSERT INTO COMPOUND_TREATMENTS (COMPOUND_TREATMENT_NAME, AFFECTED_ATTRIBUTE, COMPOUND_TREATMENT_ID) VALUES ('" + _compoundTreatment.CompoundTreatmentName + "', '" + _compoundTreatment.AffectedAttribute + "', '" + _compoundTreatment.CompoundTreatmentID + "')"; changeStatements.Add(insert); foreach (DataGridViewRow elementRow in dataGridViewCompoundTreatmentElements.Rows) { CompoundTreatmentElement toInsert = (CompoundTreatmentElement)elementRow.Cells["colCompoundTreatmentElement"].Value; if (toInsert != null) { // Insert the data. insert = "INSERT INTO COMPOUND_TREATMENT_ELEMENTS (ATTRIBUTE_FROM, ATTRIBUTE_TO, EXTENT_, QUANTITY_, CRITERIA_, COST_, COMPOUND_TREATMENT_ID) VALUES ('" + toInsert.AttributeFrom + "', '" + toInsert.AttributeTo + "', '" + toInsert.ExtentEquation.m_expression + "', '" + toInsert.Quantity.m_expression + "', '" + toInsert.CriteriaEquation.Criteria + "', '" + toInsert.CostEquation.m_expression + "', '" + toInsert.CompoundTreatmentID + "')"; changeStatements.Add(insert); } } try { DBMgr.ExecuteBatchNonQuery(changeStatements); } catch (Exception exc) { SimulationMessaging.AddMessage(new SimulationMessage("Error updating database with new compound treatment values. Transaction aborted. " + exc.Message)); } } }
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); } }