コード例 #1
0
        private void CompileCostEquations()
        {
            try
            {
                List <string> columnNames    = DBMgr.GetTableColumns("COSTS");
                string        queryEquations = "SELECT " + columnNames[0].ToString() + ", COST_ FROM COSTS";
                DataSet       equations      = DBMgr.ExecuteQuery(queryEquations);
                string        equation;
                string        id;

                // Compile each equation in the table.
                CalculateEvaluate.CalculateEvaluate calcEval;
                foreach (DataRow rowEquation in equations.Tables[0].Rows)
                {
                    equation = rowEquation["COST_"].ToString();
                    if (equation.Contains("COMPOUND_TREATMENT"))
                    {
                        continue;
                    }
                    id = rowEquation[0].ToString();

                    calcEval = new CalculateEvaluate.CalculateEvaluate();
                    calcEval.BuildClass(equation, true);
                    calcEval.CompileAssembly();
                    //UpdateCosts(id, calcEval);
                }
            }
            catch (Exception exc)
            {
                errors += "\n Error occured while getting and compiling equation in table COSTS. " + exc.Message;
            }
            return;
        }
コード例 #2
0
        private void CompileEquations(string tableName)
        {
            // Get the equation information out of the table
            try
            {
                List <string> columnNames    = DBMgr.GetTableColumns(tableName);
                string        queryEquations = "SELECT " + columnNames[0].ToString() + ", EQUATION FROM " + tableName;
                DataSet       equations      = DBMgr.ExecuteQuery(queryEquations);
                string        equation;
                string        id;

                // Compile each equation in the table.
                CalculateEvaluate.CalculateEvaluate calcEval;
                foreach (DataRow rowEquation in equations.Tables[0].Rows)
                {
                    equation = rowEquation["EQUATION"].ToString();
                    id       = rowEquation[0].ToString();

                    calcEval = new CalculateEvaluate.CalculateEvaluate();
                    calcEval.BuildClass(equation, true);
                    calcEval.CompileAssembly();
                    UpdateEquation(tableName, id, columnNames[0].ToString(), calcEval);
                }
            }
            catch (Exception exc)
            {
                errors += "\n Error occured while getting and compiling equation in table " + tableName + ". " + exc.Message;
            }
            return;
        }
コード例 #3
0
        private void CompileCriteria(string tableName)
        {
            // Get the criteria statement out of the database and in the correct format.
            try
            {
                List <string> columnNames   = DBMgr.GetTableColumns(tableName);
                string        queryCriteria = "SELECT " + columnNames[0].ToString() + ", CRITERIA FROM " + tableName;
                DataSet       criterium     = DBMgr.ExecuteQuery(queryCriteria);
                string        criteria;
                string        id;

                // Compile each criteria in the table.
                CalculateEvaluate.CalculateEvaluate calcEval;
                foreach (DataRow rowCriteria in criterium.Tables[0].Rows)
                {
                    if (rowCriteria["CRITERIA"] != null && rowCriteria["CRITERIA"].ToString() != "")
                    {
                        id       = rowCriteria[0].ToString();
                        criteria = rowCriteria["CRITERIA"].ToString().Replace("|", "'").ToUpper();

                        List <String> listAttribute = ParseAttribute(criteria);
                        foreach (String str in listAttribute)
                        {
                            String strType = m_attributeToType[str].ToString();
                            if (strType == "STRING")
                            {
                                String strOldValue = "[" + str + "]";
                                String strNewValue = "[@" + str + "]";
                                criteria = criteria.Replace(strOldValue, strNewValue);
                            }
                        }

                        calcEval = new CalculateEvaluate.CalculateEvaluate();
                        calcEval.BuildClass(criteria, false, tableName + "_BINARY_CRITERIA_" + id);
                        calcEval.CompileAssembly();
                        //UpdateCriteria(tableName, id, columnNames[0].ToString(), calcEval);
                    }
                }
            }
            catch (Exception exc)
            {
                errors += "\n Error occured while getting and compiling criteria in table " + tableName + ". " + exc.Message;
            }
            return;
        }
コード例 #4
0
ファイル: Costs.cs プロジェクト: jakedw7/iAM
        internal void SetFunction(string equation)
        {
            _costEquation = equation;

            // Get list of attributes
            _attributesEquation = SimulationMessaging.ParseAttribute(_costEquation);
            if (_attributesEquation == null)
            {
                return;
            }

            if (_calculate == null)
            {
                _calculate = new CalculateEvaluate.CalculateEvaluate();

                //Allow functions to utilize strings and dates.
                string        functionEquation = _costEquation;
                List <string> attributes       = SimulationMessaging.ParseAttribute(functionEquation);

                foreach (String attribute in attributes)
                {
                    String attributeType = SimulationMessaging.GetAttributeType(attribute);
                    if (attributeType == "STRING")
                    {
                        String oldValue = "[" + attribute + "]";
                        String newValue = "[@" + attribute + "]";
                        functionEquation = functionEquation.Replace(oldValue, newValue);
                    }
                    else if (attributeType == "DATETIME")
                    {
                        String oldValue = "[" + attribute + "]";
                        String newValue = "[$" + attribute + "]";
                        functionEquation = functionEquation.Replace(oldValue, newValue);
                    }
                }

                _calculate.BuildFunctionClass(functionEquation, "double", cgOMS.Prefix + "COSTS_BINARY_EQUATION_" + CostID);
                if (_calculate.m_cr == null)
                {
                    _compilerResultsEquation = _calculate.CompileAssembly();
                    SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + "COSTS", "BINARY_EQUATION", CostID, _calculate);
                }
            }
        }
コード例 #5
0
        private bool CheckLegalAreaEquations(String strArea)
        {
            if (strArea.Trim() == "")
            {
                Global.WriteOutput("Error: Definition for CALCULATION_AREA required");
                return(false);
            }
            List <String> m_listArea = new List <String>();

            string[] listAreaParameters = strArea.Split(']');
            for (int i = 0; i < listAreaParameters.Length; i++)
            {
                if (listAreaParameters[i].Contains("["))
                {
                    m_listArea.Add(listAreaParameters[i].Substring(listAreaParameters[i].IndexOf('[') + 1));
                }
            }
            Global.LoadAttributes();

            foreach (String str in m_listArea)
            {
                if (str != "LENGTH" && str != "AREA")
                {
                    if (!Global.Attributes.Contains(str))
                    {
                        Global.WriteOutput("Error: Only [LENGTH], [AREA] and Attributes may be used to define AREA.  Unrecognized attributes " + str);
                        return(false);
                    }
                }
            }

            CalculateEvaluate.CalculateEvaluate calculate = new CalculateEvaluate.CalculateEvaluate();
            calculate.BuildTemporaryClass(strArea, true);
            calculate.CompileAssembly();
            if (calculate.m_listError.Count > 0)
            {
                Global.WriteOutput("Error: Compiling area equations. " + calculate.m_listError[0].ToString());
                return(false);
            }
            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Sets the function version of consequences.
        /// </summary>
        /// <param name="equation"></param>
        public void SetFunction(string equation)
        {
            _consequenceEquation = equation;
            IsEquation           = true;
            _attributesEquation  = SimulationMessaging.ParseAttribute(_consequenceEquation);
            if (_calculate == null)
            {
                _calculate = new CalculateEvaluate.CalculateEvaluate();
                string functionEquation = _consequenceEquation;

                foreach (String attribute in _attributesEquation)
                {
                    String attributeType = SimulationMessaging.GetAttributeType(attribute);
                    if (attributeType == "STRING")
                    {
                        String oldValue = "[" + attribute + "]";
                        String newValue = "[@" + attribute + "]";
                        functionEquation = functionEquation.Replace(oldValue, newValue);
                    }
                    else if (attributeType == "DATETIME")
                    {
                        String oldValue = "[" + attribute + "]";
                        String newValue = "[$" + attribute + "]";
                        functionEquation = functionEquation.Replace(oldValue, newValue);
                    }
                }

                _calculate.BuildFunctionClass(_consequenceEquation, "double", cgOMS.Prefix + "CONSEQUENCES_BINARY_EQUATION_" + _id);

                if (_calculate.m_cr == null)
                {
                    _compilerResultsEquation = _calculate.CompileAssembly();
                    SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + "CONSEQUENCES", "BINARY_EQUATION", _id, _calculate);
                }
            }
        }
コード例 #7
0
ファイル: SimulationMessaging.cs プロジェクト: jakedw7/iAM
        public static void SaveSerializedCalculateEvaluate(string tableName, string binaryColumnName, string ID, CalculateEvaluate.CalculateEvaluate equationCritera)
        {
            byte[] assembly = RoadCareGlobalOperations.AssemblySerialize.SerializeObjectToByteArray(equationCritera);
            string path     = Path.GetTempPath() + "DecisionEngine";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path += "\\" + tableName + "_" + binaryColumnName + "_" + ID + ".bin";
            using (FileStream file = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
            {
                file.Write(assembly, 0, assembly.Length);
                file.Close();
            }
        }
コード例 #8
0
ファイル: FormEditEquation.cs プロジェクト: radtek/iAM-legacy
        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);
            }
        }
コード例 #9
0
ファイル: FormEditEquation.cs プロジェクト: radtek/iAM-legacy
        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);
            }
        }
コード例 #10
0
        internal void SetFunction(string equation)
        {
            _equation = equation;

            // Get list of attributes
            _attributesEquation = SimulationMessaging.ParseAttribute(_equation);
            if (_attributesEquation == null)
            {
                return;
            }

            if (_attributesEquation.Count == 1 && _attributesEquation[0].ToUpper() == "AGE")
            {
                _isAgeOnly = true;
            }

            if (_equation.Length >= 6 && _equation.Substring(0, 6) == "MODULE")
            {
                IsModule = true;
                //this will crash the program for equations with less than 10 characters
                //if (m_strEquation.Substring(0, 6) == "MODULE")
                if (_equation.Length >= 10 && _equation.Substring(7, 3) == "CRS")
                {
                    IsCRS = true;
                }
                else if (_equation.Length >= 10 && _equation.Substring(7, 3) == "OCI")
                {
                    IsOCI = true;
                }
                return;
            }
            else
            {
                if (_calculate == null)
                {
                    _calculate = new CalculateEvaluate.CalculateEvaluate();

                    //Allow functions to utilize strings and dates.
                    string        functionEquation = _equation;
                    List <string> attributes       = SimulationMessaging.ParseAttribute(functionEquation);

                    foreach (String attribute in attributes)
                    {
                        String attributeType = SimulationMessaging.GetAttributeType(attribute);
                        if (attributeType == "STRING")
                        {
                            String oldValue = "[" + attribute + "]";
                            String newValue = "[@" + attribute + "]";
                            functionEquation = functionEquation.Replace(oldValue, newValue);
                        }
                        else if (attributeType == "DATETIME")
                        {
                            String oldValue = "[" + attribute + "]";
                            String newValue = "[$" + attribute + "]";
                            functionEquation = functionEquation.Replace(oldValue, newValue);
                        }
                    }
                    _calculate.BuildFunctionClass(functionEquation, "double", cgOMS.Prefix + _table + "_BINARY_EQUATION_" + _performanceID);

                    if (_calculate.m_cr == null)
                    {
                        _compilerResultsEquation = _calculate.CompileAssembly();
                        if (_table != null)
                        {
                            SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + _table, "BINARY_EQUATION", _performanceID, _calculate);
                        }
                    }

                    if (_calculate.m_listError.Count > 0)
                    {
                        foreach (String str in _calculate.m_listError)
                        {
                            _errors.Add(str);
                        }
                    }
                }
                //If [AGE] is the only variable.  This only needs to be solved once so might
                //as well solve it right now.
                if (_isAgeOnly)
                {
                    Hashtable hash = new Hashtable();
                    hash.Add("AGE", "0");
                    this.Solve(hash);
                }
            }
        }
コード例 #11
0
 private void UpdateCosts(string ID, CalculateEvaluate.CalculateEvaluate calcEval)
 {
     //byte[] assembly = RoadCareGlobalOperations.AssemblySerialize.SerializeObjectToByteArray(calcEval);
     //GlobalDatabaseOperations.SaveBinaryObjectToDatabase(ID, "COSTID", "COSTS", "BINARY_COST", assembly);
 }
コード例 #12
0
 private void UpdateEquation(string tableName, string ID, string IDFieldName, CalculateEvaluate.CalculateEvaluate calcEval)
 {
     //byte[] assembly = RoadCareGlobalOperations.AssemblySerialize.SerializeObjectToByteArray(calcEval);
     //GlobalDatabaseOperations.SaveBinaryObjectToDatabase(ID, IDFieldName, tableName, "BINARY_EQUATION", assembly);
 }
コード例 #13
0
        /// <summary>
        /// Updates summary when necessary
        /// </summary>
        private void UpdateSummaryValues()
        {
            if (!m_bChange)
            {
                return;
            }
            labelError.Visible = false;
            String strTreatment = dgvSummary[1, 1].Value.ToString();


            if (strTreatment == m_strCurrentTreatment)
            {
                dgvSummary[1, 2].Value = m_strCurrentBudget;
                dgvSummary[1, 3].Value = m_strCurrentCost;
                dgvSummary[1, 4].Value = m_strCurrentAny;
                dgvSummary[1, 5].Value = m_strCurrentSame;

                dgvAttribute.Rows.Clear();
                foreach (String key in m_hashCurrentChange.Keys)
                {
                    int nRow = dgvAttribute.Rows.Add(key, m_hashCurrentChange[key]);
                }
            }
            else if (m_listFeasibleTreatment.Contains(strTreatment))
            {
                double dArea     = 0;
                String strSelect = "SELECT AREA FROM " + this.ReportTable + " WHERE SECTIONID ='" + this.SectionID + "' AND YEARS='" + this.Year + "'";
                try
                {
                    DataSet ds = DBMgr.ExecuteQuery(strSelect);
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        DataRow dr = ds.Tables[0].Rows[0];
                        dArea = double.Parse(dr["AREA"].ToString());
                    }
                }
                catch (Exception exception)
                {
                    labelError.Visible = true;
                    labelError.Text    = "Error retrieving AREA." + exception.Message;
                }


                strSelect = "SELECT BUDGET,YEARSANY,YEARSSAME,COST_,CHANGEHASH FROM " + this.BenefitCostTable + " WHERE SECTIONID ='" + this.SectionID + "' AND YEARS='" + this.Year + "' AND TREATMENT='" + strTreatment + "'";
                try
                {
                    DataSet ds = DBMgr.ExecuteQuery(strSelect);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        DataRow dr     = ds.Tables[0].Rows[0];
                        double  dCost  = double.Parse(dr["COST_"].ToString()) * dArea * inflationRate;
                        string  budget = dr["BUDGET"].ToString();
                        if (!budget.Contains("|"))
                        {
                            dgvSummary[1, 2].Value = budget;
                        }

                        dgvSummary[1, 3].Value = Math.Round(dCost, 2).ToString("c");
                        dgvSummary[1, 4].Value = dr["YEARSANY"].ToString();
                        dgvSummary[1, 5].Value = dr["YEARSSAME"].ToString();
                        String strChangeHash = dr["CHANGEHASH"].ToString();

                        dgvAttribute.Rows.Clear();
                        string[] pairs = strChangeHash.Split(new string[] { "\n" }, StringSplitOptions.None);
                        for (int i = 0; i < pairs.Length; i++)
                        {
                            if (pairs[i].Contains("\t"))
                            {
                                string[] attributechange = pairs[i].Split(new string[] { "\t" }, StringSplitOptions.None);
                                dgvAttribute.Rows.Add(attributechange[0], attributechange[1]);
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    labelError.Visible = true;
                    labelError.Text    = "Error: Retrieving default information from the BENEFIT_COST table." + exception.Message;
                }
            }
            else if (m_listTreatments.Contains(strTreatment))
            {
                //Fill with default from Treatment table
                String strSelect      = "SELECT BUDGET, BEFOREANY, BEFORESAME, TREATMENTID FROM TREATMENTS WHERE SIMULATIONID ='" + this.SimulationID + "' AND TREATMENT='" + strTreatment + "'";
                String strTreatmentID = "";
                try
                {
                    DataSet ds = DBMgr.ExecuteQuery(strSelect);
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        DataRow dr = ds.Tables[0].Rows[0];
                        dgvSummary[1, 2].Value = dr["BUDGET"].ToString();
                        dgvSummary[1, 4].Value = dr["BEFOREANY"].ToString();
                        dgvSummary[1, 5].Value = dr["BEFORESAME"].ToString();
                        strTreatmentID         = dr["TREATMENTID"].ToString();
                    }
                }
                catch (Exception exception)
                {
                    labelError.Visible = true;
                    labelError.Text    = "Error: Retrieving default information from the TREATMENTS table." + exception.Message;
                }

                //Get Cost information
                String strCost = "0";
                //strSelect = "SELECT COST_ FROM COSTS WHERE TREATMENTID='" + strTreatmentID + "' AND CRITERIA=''";
                //inserting '' in oracle inserts a null
                // TODO: Why not pull the criteria for each cost equation found, and calculate the cost for each and show them in a cost dropdown.
                strSelect = "SELECT COST_,CRITERIA FROM COSTS WHERE TREATMENTID='" + strTreatmentID + "'";
                try
                {
                    DataSet ds = DBMgr.ExecuteQuery(strSelect);
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        DataRow dr       = ds.Tables[0].Rows[0];
                        var     cost     = dr["COST_"];
                        var     criteria = dr["CRITERIA"];


                        if (criteria == DBNull.Value)
                        {
                            strCost = dr["COST_"].ToString();
                        }
                        else
                        {
                            var criteriaString = criteria.ToString();
                            if (String.IsNullOrWhiteSpace(criteriaString))
                            {
                                strCost = dr["COST_"].ToString();
                            }
                            else
                            {
                                var criteriaToEvaluate = new Criterias();
                                criteriaToEvaluate.Criteria = criteriaString;
                                if (criteriaToEvaluate.IsCriteriaMet(m_hashAttributeValue))
                                {
                                    strCost = dr["COST_"].ToString();
                                }
                            }
                        }
                        strCost = dr["COST_"].ToString();
                    }
                }
                catch (Exception exception)
                {
                    labelError.Visible = true;
                    labelError.Text    = "Error: Retrieving default COST information from the COSTS table." + exception.Message;
                }
                List <String> listError;
                List <String> listAttributesEquation          = Global.TryParseAttribute(strCost, out listError);  // See if listAttributeEquations is included in dgvDefault
                CalculateEvaluate.CalculateEvaluate calculate = new CalculateEvaluate.CalculateEvaluate();
                calculate.BuildTemporaryClass(strCost, true);
                CompilerResults m_crEquation = calculate.CompileAssembly();

                object[] input = new object[listAttributesEquation.Count];
                int      i     = 0;
                foreach (String attribute in listAttributesEquation)
                {
                    input[i] = m_hashAttributeValue[attribute];
                    i++;
                }
                try
                {
                    object result = calculate.RunMethod(input);
                    dgvSummary[1, 3].Value = result.ToString();
                }
                catch (Exception exc)
                {
                    Global.WriteOutput("Error running single section. " + exc.Message);
                }


                //strSelect = "SELECT ATTRIBUTE_,CHANGE_ FROM CONSEQUENCES WHERE TREATMENTID='" + strTreatmentID + "' AND CRITERIA=''";
                //inserting '' in oracle inserts a null
                strSelect = "SELECT ATTRIBUTE_,CHANGE_, CRITERIA FROM CONSEQUENCES WHERE TREATMENTID='" + strTreatmentID + "'";
                dgvAttribute.Rows.Clear();
                try
                {
                    DataSet ds = DBMgr.ExecuteQuery(strSelect);
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        var attribute = dr["ATTRIBUTE_"];
                        var change    = dr["CHANGE_"];
                        var criteria  = dr["CRITERIA"];

                        if (criteria == DBNull.Value)
                        {
                            dgvAttribute.Rows.Add(dr["ATTRIBUTE_"].ToString(), dr["CHANGE_"].ToString());
                        }
                        else
                        {
                            var criteriaString = criteria.ToString();
                            if (String.IsNullOrWhiteSpace(criteriaString))
                            {
                                dgvAttribute.Rows.Add(dr["ATTRIBUTE_"].ToString(), dr["CHANGE_"].ToString());
                            }
                            else
                            {
                                var criteriaToEvaluate = new Criterias();
                                criteriaToEvaluate.Criteria = criteriaString;
                                if (criteriaToEvaluate.IsCriteriaMet(m_hashAttributeValue))
                                {
                                    dgvAttribute.Rows.Add(dr["ATTRIBUTE_"].ToString(), dr["CHANGE_"].ToString());
                                }
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    labelError.Visible = true;
                    labelError.Text    = "Error: Loading Consequences for selected TREATMENT. " + exception.Message;
                }
            }
            else
            {
                //User defined treatment.  Leave existing as is.
            }
            dgvSummary.Update();
            dgvAttribute.Update();
        }
コード例 #14
0
        public CompoundTreatmentElement(string compoundTreatmentID, string compoundTreatmentName, string attributeFrom, string attributeTo, string costEquation, string extentEquation, string quantityCriteria, string criteriaString)
        {
            _compoundTreatmentID   = compoundTreatmentID;
            _compoundTreatmentName = compoundTreatmentName;

            // Begin building the relavent attribute list.  This list contains all attributes used in the various
            // criteria and equations.
            _attributeFrom = attributeFrom;
            if (!_relevantAttributes.Contains(_attributeFrom))
            {
                _relevantAttributes.Add(_attributeFrom);
            }

            _attributeTo = attributeTo;
            if (!_relevantAttributes.Contains(_attributeTo))
            {
                _relevantAttributes.Add(_attributeTo);
            }

            // Add cost attributes


            byte[] assembly = SimulationMessaging.GetSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "COST", compoundTreatmentID, null);
            if (assembly != null && assembly.Length > 0)
            {
                _cost = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assembly);
                if (SimulationMessaging.Area.OriginalInput != costEquation)
                {
                    _cost = null;
                }
            }
            if (_cost == null)
            {
                _cost = new CalculateEvaluate.CalculateEvaluate();
                _cost.BuildClass(costEquation, true, cgOMS.Prefix + "COMPOUNDTREATMENT_COST_" + compoundTreatmentID);
                _cost.CompileAssembly();
                SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "COST", compoundTreatmentID, _cost);
            }
            foreach (string parameter in _cost.m_listParameters)
            {
                if (!_relevantAttributes.Contains(parameter))
                {
                    _relevantAttributes.Add(parameter);
                }
            }


            assembly = null;
            assembly = SimulationMessaging.GetSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "EXTENT", compoundTreatmentID, null);
            if (assembly != null && assembly.Length > 0)
            {
                _extent = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assembly);
                if (SimulationMessaging.Area.OriginalInput != extentEquation)
                {
                    _extent = null;
                }
            }
            if (_extent == null)
            {
                // Add extent attributes
                _extent = new CalculateEvaluate.CalculateEvaluate();
                _extent.BuildClass(extentEquation, true, cgOMS.Prefix + "COMPOUNDTREATMENT_EXTENT_" + compoundTreatmentID);
                _extent.CompileAssembly();
                SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "EXTENT", compoundTreatmentID, _extent);
            }
            foreach (string parameter in _extent.m_listParameters)
            {
                if (!_relevantAttributes.Contains(parameter))
                {
                    _relevantAttributes.Add(parameter);
                }
            }



            assembly = null;
            assembly = SimulationMessaging.GetSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "QUANTITY", compoundTreatmentID, null);
            if (assembly != null && assembly.Length > 0)
            {
                _quantity = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assembly);
                if (SimulationMessaging.Area.OriginalInput != extentEquation)
                {
                    _quantity = null;
                }
            }
            if (_quantity == null)
            {
                // Add quantity attributes
                _quantity = new CalculateEvaluate.CalculateEvaluate();
                _quantity.BuildClass(quantityCriteria, true, cgOMS.Prefix + "COMPOUNDTREATMENT_QUANTITY_" + compoundTreatmentID);
                _quantity.CompileAssembly();
                SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "QUANTITY", compoundTreatmentID, _quantity);
            }
            foreach (string parameter in _quantity.m_listParameters)
            {
                if (!_relevantAttributes.Contains(parameter))
                {
                    _relevantAttributes.Add(parameter);
                }
            }

            // Add any criteria attributes
            _criteria = new Criterias();
            if (!string.IsNullOrEmpty(criteriaString))
            {
                _criteria.Criteria = criteriaString;
                foreach (string parameter in _criteria.CriteriaAttributes)
                {
                    if (!_relevantAttributes.Contains(parameter))
                    {
                        _relevantAttributes.Add(parameter);
                    }
                }
            }
        }