Example #1
0
        private Hashtable ApplyCommittedConsequences(Hashtable hashInput, Committed commit)
        {
            var hashOutput = new Hashtable();


            var hashConsequences      = new Hashtable();
            var committedConsequences = CommittedConsequences[commit.ConsequenceID];

            foreach (AttributeChange attributeChange in committedConsequences)
            {
                if (SimulationMessaging.AttributeMinimum.Contains(attributeChange.Attribute))
                {
                    attributeChange.Minimum =
                        SimulationMessaging.AttributeMinimum[attributeChange.Attribute].ToString();
                }
                if (SimulationMessaging.AttributeMaximum.Contains(attributeChange.Attribute))
                {
                    attributeChange.Maximum =
                        SimulationMessaging.AttributeMaximum[attributeChange.Attribute].ToString();
                }
                hashConsequences.Add(attributeChange.Attribute, attributeChange);
            }

            // Get all of this years deteriorated values.
            foreach (String key in hashInput.Keys)
            {
                object sValue = hashInput[key];

                if (hashConsequences.Contains(key))
                {
                    AttributeChange change = (AttributeChange)hashConsequences[key];
                    if (change != null && CommittedEquations.ContainsKey(change.Change))
                    {
                        CommittedEquation ce = CommittedEquations[change.Change];
                        if (!ce.HasErrors)
                        {
                            sValue = ce.GetConsequence(hashInput);
                        }
                    }
                    else
                    {
                        if (change != null)
                        {
                            sValue = change.ApplyChange(sValue);
                        }
                    }
                }

                hashOutput.Add(key, sValue);
            }

            return(hashOutput);
        }
        private bool CheckInput()
        {
            //Modified by adding simulationID so can run multiple runs for Cartegeraph.
            SimulationMessaging.LoadAttributes(m_strSimulationID);
            m_singleSection = new Simulation.Committed();

            labelError.Visible = false;
            //Check for Treatment Name
            m_strSingleTreatment = dgvSummary[1, 1].Value.ToString();
            if (m_strSingleTreatment.Trim().Length == 0)
            {
                labelError.Visible = true;
                labelError.Text    = "Error:Non-blank treatment name must be entered.";
                return(false);
            }
            m_singleSection.Treatment = m_strSingleTreatment;

            //Check for budget
            m_strSingleBudget = dgvSummary[1, 2].Value.ToString();
            if (m_strSingleTreatment != "No Treatment")
            {
                if (!m_listBudgets.Contains(m_strSingleBudget))
                {
                    labelError.Visible = true;
                    labelError.Text    = "Error: Budget category must be selected";
                    return(false);
                }
                m_singleSection.Budget = m_strSingleBudget;
            }
            //Check for Cost (is positive number)

            m_strSingleCost = dgvSummary[1, 3].Value.ToString().Replace("$", "");
            try
            {
                double dCost = double.Parse(m_strSingleCost);
                if (dCost < 0)
                {
                    labelError.Visible = true;
                    labelError.Text    = "Error: Cost must be greater than or equal to 0.";
                    return(false);
                }
            }
            catch
            {
                labelError.Visible = true;
                labelError.Text    = "Error: Cost must be a number.";
                return(false);
            }
            m_singleSection.Cost = float.Parse(m_strSingleCost);

            //Check for YearsAny (is positive number)
            m_strSingleAny = dgvSummary[1, 4].Value.ToString();
            try
            {
                int nAny = int.Parse(m_strSingleAny);
                if (nAny < 0)
                {
                    labelError.Visible = true;
                    labelError.Text    = "Error: Year any must be an integer must be greater than or equal to 0.";
                    return(false);
                }
            }
            catch
            {
                labelError.Visible = true;
                labelError.Text    = "Error: Year Any must be a positive integer.";
                return(false);
            }
            m_singleSection.Any = int.Parse(m_strSingleAny);

            //Check for Years Same (is positive number)
            m_strSingleSame = dgvSummary[1, 5].Value.ToString();
            try
            {
                int nSame = int.Parse(m_strSingleSame);
                if (nSame < 0)
                {
                    labelError.Visible = true;
                    labelError.Text    = "Error: Year same must be an integer must be greater than or equal to 0.";
                    return(false);
                }
            }
            catch
            {
                labelError.Visible = true;
                labelError.Text    = "Error: Year Same must be a positive integer.";
                return(false);
            }
            m_singleSection.Same = int.Parse(m_strSingleSame);

            //Check to make sure there are not repeats of attributes.
            List <String> listConsequence = new List <String>();

            Simulation.Consequences consequence = new Simulation.Consequences();
            foreach (DataGridViewRow row in dgvAttribute.Rows)
            {
                if (row.Cells[0].Value == null)
                {
                    continue;
                }
                if (listConsequence.Contains(row.Cells[0].Value.ToString()))
                {
                    labelError.Visible = true;
                    labelError.Text    = "Error: Multiple consequences for the same attribute not allowed.";
                    return(false);
                }
                listConsequence.Add(row.Cells[0].Value.ToString());
                consequence.LoadAttributeChange(row.Cells[0].Value.ToString(), row.Cells[1].Value.ToString());
            }
            m_singleSection.Consequence = consequence;

            return(true);
        }