public static string Commit(string sessionID, List <int> rowNumbers) { SessionStore session = OMS.Sessions.Find(delegate(SessionStore s) { return(s.SessionID == sessionID); }); if (session == null) { return("INVALID_SESSION"); } List <CommittedStore> comitted = SelectScenario.GetCommittedForCopy(session.SimulationID); List <ActivityResultStore> activities = SelectScenario.GetRecommendedActivities(session.SimulationID); try { using (SqlConnection connection = new SqlConnection(DB.ConnectionString)) { connection.Open(); string insert = "INSERT INTO " + DB.TablePrefix + "COMMITTED_ (SIMULATIONID,SECTIONID,YEARS,TREATMENTNAME,OMS_IS_NOT_ALLOWED) VALUES(@simulationID,@sectionID,@years,@treatmentName,0)"; SqlCommand cmdCommit = new SqlCommand(insert, connection); cmdCommit.Parameters.Add(new SqlParameter("simulationID", SqlDbType.Int, 0)); cmdCommit.Parameters.Add(new SqlParameter("sectionID", SqlDbType.Int, 0)); cmdCommit.Parameters.Add(new SqlParameter("years", SqlDbType.Int, 0)); cmdCommit.Parameters.Add(new SqlParameter("treatmentName", SqlDbType.VarChar, 50)); cmdCommit.Prepare(); //Update the report table to show that they are committed. string update = "UPDATE " + DB.TablePrefix + "REPORT_1_" + session.SimulationID.ToString() + " SET RESULT_TYPE=1 WHERE SECTIONID=@sectionID AND TREATMENT<>'No Treatment' AND RESULT_TYPE=0"; SqlCommand cmdUpdate = new SqlCommand(update, connection); cmdUpdate.Parameters.Add(new SqlParameter("sectionID", SqlDbType.Int, 0)); cmdUpdate.Prepare(); foreach (int rowNumber in rowNumbers) { string sectionID = session.OIDs[rowNumber]; List <ActivityResultStore> rowActivities = activities.FindAll(delegate(ActivityResultStore a) { return(a.OID == sectionID); }); if (rowActivities != null) { foreach (ActivityResultStore activity in rowActivities) { //Add each to the committed table. cmdCommit.Parameters[0].Value = Convert.ToInt32(session.SimulationID); cmdCommit.Parameters[1].Value = Convert.ToInt32(activity.OID); cmdCommit.Parameters[2].Value = Convert.ToInt32(activity.Year); cmdCommit.Parameters[3].Value = activity.ActivityName; cmdCommit.ExecuteNonQuery(); //Update the report table to show that they are committed. cmdUpdate.Parameters[0].Value = sectionID; cmdUpdate.ExecuteNonQuery(); } } } } } catch (Exception ex) { Utility.ExceptionHandling.DataAccessExceptionHandler.HandleException(ex, false); } return("SUCCESS"); }
private static void UpdateYearlyTargetNumberYears(int numberYears, string simulationID) { List <TargetStore> targets = SelectScenario.GetEditSimulationTargets(simulationID); if (numberYears == 0) { return; } int startYear = int.Parse(targets[0].Year); if (numberYears > targets.Count) { int currentLastYear = int.Parse(targets[targets.Count - 1].Year) + 1; while (currentLastYear < startYear + numberYears) { CreateScenario.InsertSimulationOCITargets(simulationID, currentLastYear.ToString()); currentLastYear++; } } else if (numberYears < targets.Count) { for (int i = numberYears; i < targets.Count; i++) { if (i >= numberYears) { DeleteScenario.DeleteTarget(targets[i].ID); } } } }
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) { } } } }
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 { } } }
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; }
// ======================================== // constructor // ======================================== public MemoTableCellEditorHandle() { _facade = MemopadApplication.Instance; _selectScenario = new SelectScenario(this, false); _isScenarioHandled = false; _startRowIndex = -1; _startColIndex = -1; _endRowIndex = -1; _endColIndex = -1; }
private static void CopyTargets(string simulationID, string newSimulationID) { List <TargetStore> targets = SelectScenario.GetTargetsForCopy(simulationID); foreach (TargetStore target in targets) { string criteria = null; string year = null; if (target.Criteria == null) { criteria = "NULL"; } else { criteria = "'" + target.Criteria + "'"; } if (target.Year == null) { year = "NULL"; } else { year = "'" + target.Year + "'"; } if (target.IsOMSPriority == null) { target.IsOMSPriority = "0"; } using (SqlConnection connection = new SqlConnection(DB.ConnectionString)) { try { connection.Open(); string insert = "INSERT INTO " + DB.TablePrefix + "TARGETS (SIMULATIONID,ATTRIBUTE_,YEARS,TARGETMEAN,TARGETNAME,CRITERIA,IS_OMS_PRIORITY) VALUES" + "('" + newSimulationID + "','OverallConditionIndex'," + year + ",'" + target.TargetOCI + "','" + target.Name + "'," + criteria + ",'" + target.IsOMSPriority + "')"; SqlCommand cmd = new SqlCommand(insert, connection); cmd.ExecuteNonQuery(); } catch { } } } }
public static string ConvertDisplayCostToOMS(string activityID, string criteria) { string simulationID = GetSimulationIDFromActivityID(activityID); string assetName = SelectScenario.GetAssetType(simulationID); string displayAttribute = SimulationComponents.FindAttribute(criteria, 0); if (displayAttribute != null) { List <AttributeStore> attributes = OMS.GetAssetAttributes(assetName); AttributeStore attribute = attributes.Find(delegate(AttributeStore a) { return(a.OmsHierarchy == displayAttribute); }); criteria = criteria.Replace("[" + displayAttribute + "]", "[" + attribute.OmsObjectUserIDHierarchy + "]"); } return(criteria); }
private static void UpdateYearlyTargetStartYear(int startYear, string simulationID) { List <TargetStore> targets = SelectScenario.GetEditSimulationTargets(simulationID); int numberYears = targets.Count; if (numberYears == 0) { return; } // If startYear earlier than current, add new years with 0 amounts, delete excess years. if (startYear < int.Parse(targets[0].Year)) { for (int i = 0; i < numberYears; i++) { int year = startYear + i; TargetStore target = targets.Find(delegate(TargetStore ts) { return(ts.Year == year.ToString()); }); if (target == null) { CreateScenario.InsertSimulationOCITargets(simulationID, year.ToString()); } } for (int index = 0; index < targets.Count; index++) { if (int.Parse(targets[index].Year) > startYear + numberYears) { DeleteScenario.DeleteTarget(targets[index].ID); } } } else if (startYear > int.Parse(targets[0].Year)) // If startYear later than current, delete earlier. Add later. { for (int index = 0; index < targets.Count; index++) { if (int.Parse(targets[index].Year) < startYear) { DeleteScenario.DeleteTarget(targets[index].ID); } } for (int i = 0; i < numberYears; i++) { int year = i + startYear; TargetStore target = targets.Find(delegate(TargetStore ts) { return(ts.Year == year.ToString()); }); if (target == null) { CreateScenario.InsertSimulationOCITargets(simulationID, year.ToString()); } } } }
// ======================================== // constructor // ======================================== public MemoTableRuledLineHandle(Func <TableFigure> tableFigureProvider) { _tableFigureProvider = tableFigureProvider; _figure = new Lazy <MemoTableRuledLineHandleFigure>( () => new MemoTableRuledLineHandleFigure(tableFigureProvider) ); _changeRowHeightRequest = new ChangeRowHeightRequest(); _changeColumnWidthRequest = new ChangeColumnWidthRequest(); _dragStartPoint = Point.Empty; _lineIndex = 0; _isVertical = false; _selectScenario = new SelectScenario(this); }
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. }
public static string UpdateResultActivity(string sessionID, int rowIndex, string action, string treatment, int fromYear, string value) { SessionStore session = OMS.Sessions.Find(delegate(SessionStore s) { return(s.SessionID == sessionID); }); string sectionID = session.OIDs[rowIndex]; if (session == null) { return("Error: Expired sessionID=" + sessionID); } string encoded = null; Simulation.SimulationMessaging.ClearProgressList(session.SimulationID); Simulation.Simulation simulation = new Simulation.Simulation(session.SimulationID, sectionID, action, treatment, fromYear, value, DB.ConnectionString); simulation.UpdateSimulation(); encoded = SelectScenario.GetActivityResults(session.SessionID, sectionID); return(encoded); }
/// <summary> /// Convert SimulationStore into necessary tables entries for RoadCare /// </summary> /// <param name="simulationID"></param> public static void Simulation(string simulationID) { SimulationStore simulation = SelectScenario.GetSimulationStore(simulationID); OMSAssetConditionIndexStore oci = OMS.GetAssetConditionIndex(simulation.Asset); PrepareAnalysis.Priorities(simulation); //PrepareAnalysis.TargetAndDeficients(simulation); PrepareAnalysis.ConditionCategoryWeights(simulation); //PrepareAnalysis.Performance(simulation); //PrepareAnalysis.RepeatedActivities(simulation); //PrepareAnalysis.ActivityFeasibilityCostConsequences(simulation); List <AttributeStore> attributes = PrepareAnalysis.Attributes(simulation); AssetRequestOMSDataStore assetRequest = new AssetRequestOMSDataStore(DateTime.Now, attributes, oci); Dictionary <string, AssetReplyOMSLookupTable> assetLookups = OMS.GetAssetLookupData(assetRequest); List <AssetReplyOMSDataStore> assets = OMS.GetAssetData(assetRequest); List <AssetReplyOMSDataStore> assetsWithCondition = assets.FindAll(delegate(AssetReplyOMSDataStore arods) { return(arods.ConditionIndices != null); }); PrepareAnalysis.Assets(simulation, assetsWithCondition, attributes, assetRequest, assetLookups); }
public static bool UpdateActivityConditionIndex(string activityID, string conditionIndex, string property, string value) { string simulationID = GetSimulationIDFromActivityID(activityID); string assetType = SelectScenario.GetAssetType(simulationID); bool isSuccessful = true; if (property == "Impact") { UpdateImpact(assetType, activityID, conditionIndex, value); } //WE NEED TO HAVE INTERFACE RETURN ENTIRE CRITERIA. //else if (property == "MinimumIndex") //{ // string existingCriteria = SelectScenario.GetActivityFeasibility(activityID); //} //else if (property == "MaximumIndex") //{ //} return(isSuccessful); }
/// <summary> /// Creates a new Decision Engine Simulation and initializes it. /// </summary> /// <param name="username">Login username who created simulation.</param> /// <param name="asset">Asset for which scenario is being created</param> /// <returns>Returns the SimulationStore created so user interface can be populated.</returns> public static SimulationStore CreateNewSimulationStore(string username, string asset) { SimulationStore simulation = null; if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(asset)) { try { using (SqlConnection connection = new SqlConnection(DB.ConnectionString)) { connection.Open(); string insert = "INSERT INTO " + DB.TablePrefix + "SIMULATIONS " + "(SIMULATION,NETWORKID,DATECREATED,USERNAME,BENEFIT_VARIABLE,BENEFIT_LIMIT,ANALYSIS, BUDGET_CONSTRAINT,ASSET_TYPE,RUN_TIME,USE_TARGET,TARGET_OCI,SIMULATION_AREA)" + "VALUES('New Simulation',1,'" + DateTime.Now.ToString() + "',@username,'OCI',0,'Benefit/Cost','Budget Target',@asset,'0','false','" + DB.DefaultTargetOCI.ToString() + "','1')"; SqlCommand cmd = new SqlCommand(insert, connection); cmd.Parameters.Add(new SqlParameter("username", username)); cmd.Parameters.Add(new SqlParameter("asset", asset)); cmd.ExecuteNonQuery(); string table = DB.TablePrefix + "SIMULATIONS"; string selectIdentity = "SELECT IDENT_CURRENT ('" + table + "') FROM " + table; cmd = new SqlCommand(selectIdentity, connection); int identity = Convert.ToInt32(cmd.ExecuteScalar()); InsertNewInvestment(identity.ToString(), asset); simulation = SelectScenario.GetSimulationStore(identity.ToString()); InsertOMSActivities(simulation); InsertSimulationOCITargets(simulation); LoadPerformanceCurvesToDecisionEngine(identity, asset); } } catch (Exception ex) { Utility.ExceptionHandling.DataAccessExceptionHandler.HandleException(ex, false); } } return(simulation); }
private static void CopyCommitted(string simulationID, string newSimulationID) { List <CommittedStore> committeds = SelectScenario.GetCommittedForCopy(simulationID); String myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); myDocumentsFolder += "\\RoadCare Projects\\Temp"; Directory.CreateDirectory(myDocumentsFolder); string fileOut = myDocumentsFolder + "\\oms_committed_copy_" + newSimulationID + ".txt"; TextWriter tw = new StreamWriter(fileOut); string lineOut = null; foreach (CommittedStore committed in committeds) { try { lineOut = "\t" + newSimulationID + "," + committed.SectionID.ToString() + "," + committed.Years.ToString() + "," + committed.YearsSame.ToString() + "," + committed.YearsAny.ToString() + "," + committed.Budget.ToString() + "," + committed.Cost.ToString() + ","; if (committed.OMSIsRepeat) { lineOut += "1,"; } else { lineOut += "0,"; } if (committed.OMSIsExclusive) { lineOut += "1,"; } else { lineOut += "0,"; } if (committed.OMSIsNotAllowed) { lineOut += "1"; } else { lineOut += "0"; } tw.WriteLine(lineOut); } catch (Exception ex) { int test = ex.Message.Length; } } tw.Close(); using (SqlConnection connection = new SqlConnection(DB.ConnectionString)) { string password = ParsePassword(DB.ConnectionString); string username = ParseUserName(DB.ConnectionString); string datasource = connection.DataSource; string database = connection.Database; char delimiter = ','; string bcp = "\"" + database + ".dbo." + DB.TablePrefix + "COMMITTED_" + "\" IN \"" + fileOut + "\" /S " + datasource + " -t\"" + delimiter + "\" -c -q -U " + username + " -P " + password;; System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = "bcp"; proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; proc.StartInfo.Arguments = bcp; proc.Start(); proc.WaitForExit(); } }
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; }
public SelectEditorHandle() { _scenario = new SelectScenario(this); _scenario.Apply(); }
/// <summary> /// Updates TREATMENTS table from changes to the interface. /// </summary> /// <param name="activityID">Treatment ID</param> /// <param name="property">The JSON property to change</param> /// <param name="value">The new value</param> /// <returns>True if successful</returns> public static bool UpdateActivity(string activityID, string property, string value) { bool isSuccessful = true; string budgets = ""; using (SqlConnection connection = new SqlConnection(DB.ConnectionString)) { string update = null; switch (property) { case "IsSelected": update = "UPDATE " + DB.TablePrefix + "TREATMENTS SET OMS_IS_SELECTED=@value WHERE TREATMENTID=@activityID"; break; case "IsRepeatActivity": update = "UPDATE " + DB.TablePrefix + "TREATMENTS SET OMS_IS_REPEAT=@value WHERE TREATMENTID=@activityID"; break; case "StartYear": update = "UPDATE " + DB.TablePrefix + "TREATMENTS SET OMS_REPEAT_START=@value WHERE TREATMENTID=@activityID"; break; case "RepeatYear": update = "UPDATE " + DB.TablePrefix + "TREATMENTS SET OMS_REPEAT_INTERVAL=@value WHERE TREATMENTID=@activityID"; break; case "IsExclusive": update = "UPDATE " + DB.TablePrefix + "TREATMENTS SET OMS_IS_EXCLUSIVE=@value WHERE TREATMENTID=@activityID"; break; case "Criteria": if (value == "null") { update = "UPDATE " + DB.TablePrefix + "FEASIBILITY SET CRITERIA=NULL WHERE TREATMENTID=@activityID"; } else { update = "UPDATE " + DB.TablePrefix + "FEASIBILITY SET CRITERIA=@value WHERE TREATMENTID=@activityID"; } break; case "YearSame": update = "UPDATE " + DB.TablePrefix + "TREATMENTS SET BEFORESAME=@value WHERE TREATMENTID=@activityID"; break; case "Cost": value = ConvertDisplayCostToOMS(activityID, value); update = "UPDATE " + DB.TablePrefix + "COSTS SET COST_=@value WHERE TREATMENTID=@activityID"; break; case "DeleteBudget": List <string> removeBudgets = SelectScenario.GetBudgetsForActivity(activityID); removeBudgets.Remove(value); foreach (string budget in removeBudgets) { if (budgets.Length != 0) { budgets += "|"; } budgets += budget; } value = budgets; update = "UPDATE " + DB.TablePrefix + "TREATMENTS SET BUDGET=@value WHERE TREATMENTID=@activityID"; break; case "AddBudget": List <string> addBudgets = SelectScenario.GetBudgetsForActivity(activityID); if (!addBudgets.Contains(value)) { addBudgets.Add(value); foreach (string budget in addBudgets) { if (budgets.Length != 0) { budgets += "|"; } budgets += budget; } value = budgets; update = "UPDATE " + DB.TablePrefix + "TREATMENTS SET BUDGET=@value WHERE TREATMENTID=@activityID"; } break; } if (update != null) { try { connection.Open(); SqlCommand cmd = new SqlCommand(update, connection); cmd.Parameters.Add(new SqlParameter("activityID", activityID)); cmd.Parameters.Add(new SqlParameter("value", value)); cmd.ExecuteNonQuery(); } catch (Exception e) { Utility.ExceptionHandling.DataAccessExceptionHandler.HandleException(e, false); isSuccessful = false; } } } return(isSuccessful); }