Ejemplo n.º 1
0
        public EditSimulationStore(SimulationStore simulation)
        {
            _simulationID      = simulation.SimulationID;
            _simulationName    = simulation.SimulationName;
            _numberAssets      = simulation.TotalAssets;
            _numberYears       = simulation.Years;
            _estimatedRunTime  = simulation.EstimatedRunTime;
            _assetType         = simulation.Asset;
            _scopeFilter       = simulation.Jurisdiction;
            _scopeName         = simulation.ScopeDescription;
            _startDate         = simulation.StartDate.ToShortDateString();
            _budgetName        = simulation.BudgetName;
            _yearBudgetAmounts = SelectScenario.GetBudgetsByYear(simulation.SimulationID);
            _assetTypeOID      = simulation.AssetTypeOID;
            _totalBudget       = 0;
            _budgetOrder       = simulation.BudgetOrder;
            _inflationRate     = simulation.InflationRate;

            foreach (YearBudgetAmountStore yba in _yearBudgetAmounts)
            {
                _totalBudget += (int)yba.Amount;
            }
            _activities = SelectScenario.GetActivities(simulation.SimulationID, false);
            _targets    = SelectScenario.GetEditSimulationTargets(simulation.SimulationID);

            //Analysis type is a combination of AnalysisType and Budget Contraint
            // Budget Target = As Budget Permits
            // OCI Target
            // Until OCI or Budget Met
            // Unlimited
            _optimizationType = simulation.BudgetConstraint;
        }
Ejemplo n.º 2
0
        private static void CopyTreatments(string simulationID, string newSimulationID)
        {
            List <ActivityStore> activities = SelectScenario.GetActivities(simulationID, true);

            foreach (ActivityStore activity in activities)
            {
                using (SqlConnection connection = new SqlConnection(DB.ConnectionString))
                {
                    try
                    {
                        connection.Open();

                        string insert = "INSERT INTO " + DB.TablePrefix + "TREATMENTS (SIMULATIONID,TREATMENT,BEFOREANY,BEFORESAME,BUDGET,DESCRIPTION,OMS_IS_REPEAT,OMS_REPEAT_START,OMS_REPEAT_INTERVAL,OMS_OID,OMS_IS_SELECTED, OMS_IS_EXCLUSIVE) VALUES " +
                                        "(@simulationID,@treatment,@beforeAny,@beforeSame,@budget,@description,@omsIsRepeat,@omsRepeatStart,@omsRepeatInterval,@omsOID,@omsIsSelected,@omsIsExclusive)";

                        SqlCommand cmd = new SqlCommand(insert, connection);
                        cmd.Parameters.Add(new SqlParameter("simulationID", newSimulationID));
                        cmd.Parameters.Add(new SqlParameter("treatment", activity.Activity));
                        cmd.Parameters.Add(new SqlParameter("beforeAny", 1));
                        cmd.Parameters.Add(new SqlParameter("beforeSame", activity.YearSame));
                        string concatenatedbudget = "";
                        if (activity.Budgets != null)
                        {
                            foreach (string budget in activity.Budgets)
                            {
                                if (concatenatedbudget.Length > 0)
                                {
                                    concatenatedbudget += "|";
                                }
                                concatenatedbudget += budget;
                            }
                            if (concatenatedbudget.Length > 0)
                            {
                                cmd.Parameters.Add(new SqlParameter("budget", concatenatedbudget));
                            }
                        }
                        else
                        {
                            cmd.Parameters.Add(new SqlParameter("budget", DBNull.Value));
                        }

                        cmd.Parameters.Add(new SqlParameter("description", DBNull.Value));
                        cmd.Parameters.Add(new SqlParameter("omsIsRepeat", activity.IsRepeatActivity));
                        cmd.Parameters.Add(new SqlParameter("omsRepeatStart", activity.RepeatStart));
                        cmd.Parameters.Add(new SqlParameter("omsRepeatInterval", activity.RepeatInterval));
                        cmd.Parameters.Add(new SqlParameter("omsOID", activity.OmsOID));
                        cmd.Parameters.Add(new SqlParameter("omsIsSelected", activity.IsSelected));
                        cmd.Parameters.Add(new SqlParameter("omsIsExclusive", activity.IsExclusive));
                        cmd.ExecuteNonQuery();
                        string selectIdentity = "SELECT IDENT_CURRENT ('" + DB.TablePrefix + "TREATMENTS') FROM " + DB.TablePrefix + "TREATMENTS";
                        cmd = new SqlCommand(selectIdentity, connection);
                        int newTreatmentID = Convert.ToInt32(cmd.ExecuteScalar());
                        InsertFeasibilityCostConsequence(newTreatmentID, activity);
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
        }