Example #1
0
        private static void CopyInvestments(string simulationID, string newSimulationID)
        {
            DateTime        dateStart  = DateTime.Now;
            InvestmentStore investment = SelectScenario.GetInvestment(simulationID);

            using (SqlConnection connection = new SqlConnection(DB.ConnectionString))
            {
                try
                {
                    connection.Open();
                    string insert = "INSERT INTO " + DB.TablePrefix + "INVESTMENTS (SIMULATIONID,FIRSTYEAR,NUMBERYEARS,INFLATIONRATE,DISCOUNTRATE,BUDGETORDER,SIMULATION_START_DATE) VALUES"
                                    + "('" + newSimulationID + "','" + investment.FirstYear.ToString() + "','" + investment.NumberYear + "','" + investment.InflationRate.ToString() + "','" + investment.DiscountRate.ToString() + "','" + investment.BudgetOrder + "','" + investment.StartDate + "')";
                    SqlCommand cmd = new SqlCommand(insert, connection);
                    cmd.ExecuteNonQuery();

                    List <YearBudgetAmountStore> yearBudgets = SelectScenario.GetBudgetsByYear(simulationID);

                    foreach (YearBudgetAmountStore yearBudget in yearBudgets)
                    {
                        insert = "INSERT INTO " + DB.TablePrefix + "YEARLYINVESTMENT (SIMULATIONID,YEAR_,BUDGETNAME,AMOUNT) VALUES ('" + newSimulationID + "','" + yearBudget.Year.ToString() + "','" + yearBudget.Budget + "','" + yearBudget.Amount + "')";
                        cmd    = new SqlCommand(insert, connection);
                        cmd.ExecuteNonQuery();
                    }
                }
                catch
                {
                }
            }
        }
Example #2
0
        public static void UpdateBudgetCategory(string simulationID, string oldBudget, string newBudget)
        {
            InvestmentStore investment  = SelectScenario.GetInvestment(simulationID);
            string          budgetOrder = "";

            foreach (string budget in investment.Budgets)
            {
                if (budgetOrder.Length > 0)
                {
                    budgetOrder += "|";
                }
                if (budget == oldBudget)
                {
                    budgetOrder += newBudget;
                }
                else
                {
                    budgetOrder += budget;
                }
            }
            // Update budget order
            using (SqlConnection connection = new SqlConnection(DB.ConnectionString))
            {
                string update = "UPDATE " + DB.TablePrefix + "INVESTMENTS SET BUDGETORDER=@budgetOrder WHERE SIMULATIONID=@simulationID";
                connection.Open();
                SqlCommand cmd = new SqlCommand(update, connection);
                cmd.Parameters.Add(new SqlParameter("simulationID", simulationID));
                cmd.Parameters.Add(new SqlParameter("budgetOrder", budgetOrder));
                cmd.ExecuteNonQuery();
            }


            //Updating yearly budget.
            using (SqlConnection connection = new SqlConnection(DB.ConnectionString))
            {
                string update = "UPDATE " + DB.TablePrefix + "YEARLYINVESTMENT SET BUDGETNAME=@newBudget WHERE SIMULATIONID=@simulationID AND BUDGETNAME=@oldBudget";
                connection.Open();
                SqlCommand cmd = new SqlCommand(update, connection);
                cmd.Parameters.Add(new SqlParameter("simulationID", simulationID));
                cmd.Parameters.Add(new SqlParameter("newBudget", newBudget));
                cmd.Parameters.Add(new SqlParameter("oldBudget", oldBudget));
                cmd.ExecuteNonQuery();
            }


            //Need to change all committed projects.
        }
Example #3
0
        public static void UpdateEditScenario(string simulationID, string property, string value)
        {
            if (property == "BudgetCategories")
            {
                //               UpdateBudgetCategories(simulationID, value);
            }
            else
            {
                using (SqlConnection connection = new SqlConnection(DB.ConnectionString))
                {
                    string update = null;
                    switch (property)
                    {
                    case "Asset":
                        update = "UPDATE " + DB.TablePrefix + "SIMULATIONS SET ASSET_TYPE=@value WHERE SIMULATIONID=@simulationID";
                        break;

                    case "SimulationName":
                        update = "UPDATE " + DB.TablePrefix + "SIMULATIONS SET SIMULATION=@value WHERE SIMULATIONID=@simulationID";
                        break;

                    case "ScopeName":
                        update = "UPDATE " + DB.TablePrefix + "SIMULATIONS SET COMMENTS=@value WHERE SIMULATIONID=@simulationID";
                        break;

                    case "ScopeFilter":
                        value = value.Replace("_cgDEDate", "#");
                        if (value == "null")
                        {
                            update = "UPDATE " + DB.TablePrefix + "SIMULATIONS SET JURISDICTION=NULL WHERE SIMULATIONID=@simulationID";
                        }
                        else
                        {
                            update = "UPDATE " + DB.TablePrefix + "SIMULATIONS SET JURISDICTION=@value WHERE SIMULATIONID=@simulationID";
                        }
                        break;

                    case "AnalysisType":
                        update = "UPDATE " + DB.TablePrefix + "SIMULATIONS SET ANALYSIS=@value WHERE SIMULATIONID=@simulationID";
                        break;

                    case "NumberYears":
                        update = "UPDATE " + DB.TablePrefix + "INVESTMENTS SET NUMBERYEARS=@value WHERE SIMULATIONID=@simulationID";
                        UpdateYearlyTargetNumberYears(int.Parse(value), simulationID);
                        UpdateYearlyInvestmentNumberYears(int.Parse(value), simulationID);
                        break;

                    case "BudgetName":
                        update = "UPDATE " + DB.TablePrefix + "INVESTMENTS SET BUDGET_NAME=@value WHERE SIMULATIONID=@simulationID";
                        break;

                    case "InflationRate":
                        update = "UPDATE " + DB.TablePrefix + "INVESTMENTS SET INFLATIONRATE=@value WHERE SIMULATIONID=@simulationID";
                        break;

                    case "StartDate":
                        UpdateEditScenario(simulationID, "FirstYear", Convert.ToDateTime(value).Year.ToString());
                        update = "UPDATE " + DB.TablePrefix + "INVESTMENTS SET SIMULATION_START_DATE=@value WHERE SIMULATIONID=@simulationID";
                        break;

                    case "FirstYear":
                        update = "UPDATE " + DB.TablePrefix + "INVESTMENTS SET FIRSTYEAR=@value WHERE SIMULATIONID=@simulationID";
                        UpdateYearlyInvestmentStartYear(int.Parse(value), simulationID);
                        UpdateYearlyTargetStartYear(int.Parse(value), simulationID);
                        break;

                    case "AddBudget":
                        InvestmentStore investment  = SelectScenario.GetInvestment(simulationID);
                        string          budgetOrder = "";
                        foreach (string budget in investment.Budgets)
                        {
                            if (budgetOrder.Length > 0)
                            {
                                budgetOrder += "|";
                            }
                            budgetOrder += budget;
                        }
                        if (budgetOrder.Length > 0)
                        {
                            budgetOrder += "|";
                        }
                        budgetOrder += value;
                        value        = budgetOrder;
                        update       = "UPDATE " + DB.TablePrefix + "INVESTMENTS SET BUDGETORDER=@value WHERE SIMULATIONID=@simulationID";
                        UpdateYearlyInvestmentBudgetOrder(budgetOrder, simulationID);
                        break;

                    case "DeleteBudget":
                        InvestmentStore investmentDelete  = SelectScenario.GetInvestment(simulationID);
                        string          budgetOrderDelete = "";
                        foreach (string budget in investmentDelete.Budgets)
                        {
                            if (budget != value)
                            {
                                if (budgetOrderDelete.Length > 0)
                                {
                                    budgetOrderDelete += "|";
                                }
                                budgetOrderDelete += budget;
                            }
                        }

                        value  = budgetOrderDelete;
                        update = "UPDATE " + DB.TablePrefix + "INVESTMENTS SET BUDGETORDER=@value WHERE SIMULATIONID=@simulationID";
                        UpdateYearlyInvestmentBudgetOrder(budgetOrderDelete, simulationID);
                        break;

                    case "Optimization":
                        update = "UPDATE " + DB.TablePrefix + "SIMULATIONS SET BUDGET_CONSTRAINT=@value WHERE SIMULATIONID=@simulationID";
                        break;
                    }

                    if (update != null)
                    {
                        try
                        {
                            connection.Open();
                            SqlCommand cmd = new SqlCommand(update, connection);
                            cmd.Parameters.Add(new SqlParameter("simulationID", simulationID));
                            cmd.Parameters.Add(new SqlParameter("value", value));
                            cmd.ExecuteNonQuery();
                        }
                        catch (Exception e)
                        {
                            Utility.ExceptionHandling.DataAccessExceptionHandler.HandleException(e, false);
                        }
                    }
                }
            }
            return;
        }