//-------------------------------------------------------------------------------------- public void RunAllyearsDB() { if (WSDB_Open) { TablenameDialog tableDialog = new TablenameDialog(); string runtablename = ""; DataTable DT = new DataTable(); // get the table name if (tableDialog.ShowDialog(WSim.DbConnection, false, false) == System.Windows.Forms.DialogResult.OK) { runtablename = tableDialog.Tablename; if (tableDialog.isNewTablename) { WSim.CreateNewDataTable(runtablename); } } if (runtablename != "") { StatusLabel1.Text = "Running DB Simulation"; // Ok fill the data table with all teh relvant fields // initialize a db simulation, turn control over to WaterSim_DB WSim.Simulation_Initialize(runtablename, ScenarioNameTextBox.Text); // Fetch all the Input fields SetAllModelValues(WS_InputPanel.GetAllValues()); // run each year of simulation db foreach (int year in WSim.simulationYears()) { WSim.Simulation_NextYear(); } // stop the simulation (which adds all data to data table WSim.Simulation_Stop(); // OK I now have control, update the database OleDbDataAdapter NewRawTableAdapter = new OleDbDataAdapter("Select * from " + '[' + runtablename + ']', WSim.DbConnection); NewRawTableAdapter.Fill(DT); dbTableGridView.DataSource = DT; StatusLabel1.Text = "Done"; FetchTablenames(); } } else { MessageBox.Show("A Database must first be opened"); OpenDB(); } }
//-------------------------------------------------------------------------------------- void LoadScenario() { bool iserror = false; string ErrMessage = ""; if (WSDB_Open) { TablenameDialog tableDialog = new TablenameDialog(); string tablename = ""; DataTable DT = new DataTable(); // get the table name if (tableDialog.ShowDialog(WSim.DbConnection, false, true) == System.Windows.Forms.DialogResult.OK) { tablename = tableDialog.Tablename; if (tablename != "") { try { DT = dbTool.LoadTable(WSim.DbConnection, "Select * from " + dbTool.BracketIt(WSim.DbConnection.SQLServerType, tablename) + ";", ref iserror, ref ErrMessage); //OleDbDataAdapter TableAdapter = new OleDbDataAdapter("Select * from " + '[' + tablename + ']', WSim.DbConnection); //TableAdapter.Fill(DT); //TableAdapter.Dispose(); if (!iserror) { SimulationInputs SI = WSim.ParamManager.GetSimulationInputs(); if (WSim.LoadScenario_DB("", 0, DT, ref SI)) { if (WSim.ParamManager.SetSimulationInputs(SI)) { WS_InputPanel.Refresh_Inputs(); } } } else { throw new Exception(ErrMessage); } } catch (Exception e) { MessageBox.Show("Whoops " + e.Message); } } } } else { } }
//-------------------------------------------------------------------------------------- void LoadScenario() { if (WSDB_Open) { TablenameDialog tableDialog = new TablenameDialog(); string tablename = ""; DataTable DT = new DataTable(); // get the table name if (tableDialog.ShowDialog(WSim.DbConnection, false, true) == System.Windows.Forms.DialogResult.OK) { tablename = tableDialog.Tablename; if (tablename != "") { try { OleDbDataAdapter TableAdapter = new OleDbDataAdapter("Select * from " + '[' + tablename + ']', WSim.DbConnection); TableAdapter.Fill(DT); TableAdapter.Dispose(); SimulationInputs SI = WSim.ParamManager.GetSimulationInputs(); if (WSim.LoadScenario_DB("", 0, DT, ref SI)) { if (WSim.ParamManager.SetSimulationInputs(SI)) { WS_InputPanel.Refresh_Inputs(); } } } catch (Exception e) { MessageBox.Show("Whoops " + e.Message); } } } } else { } }
//------------------------------------------------------------------------------------------------------- private void Refresh_Inputs() { WS_InputPanel.Refresh_Inputs(); }
//------------------------------------------------------------------------------------------------------- private void RunOneYear() { // Block Rentry if (!_inRunOneYear) { _inRunOneYear = true; int ProviderSize = ProviderClass.NumberOfProviders; ReportHeader lineout = new ReportHeader(); string ReportString = ""; string[] AllStrings = new string[ProviderSize]; string ScName = ScenarioNameTextBox.Text; int _runYear = 0; //---------------------------- if (_OneYearNotStarted) { // Resett the simulation WSim.Simulation_Initialize(); OutputListBox.Items.Clear(); OutputListBox.Items.Add(ReportTitle()); lineout = ReportClass.FullHeader(WSim, 20, false, true); OutputListBox.Items.Add(lineout[0]); OutputListBox.Items.Add(lineout[1]); SetAllModelValues(WS_InputPanel.GetAllValues()); _OneYearStart = WSim.Simulation_Start_Year; _OneYearStop = WSim.Simulation_End_Year; if (OutputReportCheckBox.Checked) { if (ContinuousCheckBox.Checked) { ReportString = ReportTextBox.Text; } else { ReportString = ""; } ReportString += ReportTitle() + System.Environment.NewLine + ReportClass.FullHeader(WSim, 0, true, false)[0] + System.Environment.NewLine; ReportTextBox.Text = ReportString; } _OneYearNotStarted = false; } // _oneYearNotSTarted true // Set New Year // Clear this just to be safe ReportString = ""; // Run One year of model SetAllModelValues(WS_InputPanel.GetAllValues()); // Lock the model WSim.LockSimulation(); _runYear = WSim.Simulation_NextYear(); AllStrings = ReportClass.AnnualFullData(WSim, ScName, _runYear, 20, false); for (int i = 0; i < ProviderSize; i++) { OutputListBox.Items.Add(AllStrings[i]); } if (OutputReportCheckBox.Checked) { ReportString = ReportTextBox.Text; AllStrings = ReportClass.AnnualFullData(WSim, ScName, _runYear, 20, true); for (int i = 0; i < ProviderSize; i++) { ReportString += AllStrings[i]; } ReportTextBox.Text = ReportString; } if (_runYear == _OneYearStop) { WSim.Simulation_Stop(); MessageBox.Show("Simulation has ended, next run will restart simulation!"); _OneYearNotStarted = true; } _inRunOneYear = false; } }
internal void RunModel() { if (!_InRunModel) { _InRunModel = true; string ScName = ScenarioNameTextBox.Text; //string lineout = ""; string ReportString = ""; int ProviderSize = ProviderClass.NumberOfProviders; string[] AllStrings = new string[ProviderSize]; // Resett the simulation WSim.Simulation_Initialize(); // Fetch all the Input fields SimulationInputs SimInputs = WS_InputPanel.GetAllValues(); SetAllModelValues(SimInputs); //SetStatusBar StatusLabel1.Text = "Running Simulation " + ScenarioNameTextBox.Text; StatusProgressBar.Maximum = WSim.Simulation_End_Year - WSim.Simulation_Start_Year; StatusProgressBar.Value = 1; StatusProgressBar.Visible = true; // Lock the model WSim.LockSimulation(); // Reset Memory Status ShowMemory(); // Add a Title and Header OutputListBox.Items.Clear(); OutputListBox.Items.Add(ReportTitle()); //string[] header = new string[2]; ReportHeader header = new ReportHeader(); header = ReportClass.FullHeader(WSim, 20, false, true); OutputListBox.Items.Add(header[2]); OutputListBox.Items.Add(header[0]); OutputListBox.Items.Add(header[1]); if (OutputReportCheckBox.Checked) { if (ContinuousCheckBox.Checked) { ReportString = ReportTextBox.Text; } else { ReportString = ""; } ReportString += ReportTitle() + System.Environment.NewLine + ReportClass.FullHeader(WSim, 0, true, false)[0] + System.Environment.NewLine; } // OK run the model int runyear = 0; int cnt = 0; foreach (int year in WSim.simulationYears()) { runyear = WSim.Simulation_NextYear(); AllStrings = ReportClass.AnnualFullData(WSim, ScName, runyear, 20, false); for (int i = 0; i < ProviderSize; i++) { OutputListBox.Items.Add(AllStrings[i]); } if (OutputReportCheckBox.Checked) { AllStrings = ReportClass.AnnualFullData(WSim, ScName, runyear, 20, true); for (int i = 0; i < ProviderSize; i++) { ReportString += AllStrings[i]; } } StatusProgressBar.Value = cnt; cnt++; } // Stop Model WSim.Simulation_Stop(); StatusProgressBar.Visible = false; // output report if (OutputReportCheckBox.Checked) { ReportTextBox.Text = ReportString + System.Environment.NewLine; } // Set output to default StatusLabel1.Text = ""; ModelControlsTabControl.SelectedTab = OutputTabPage; OutputTabPage.Select(); // Allow entry _InRunModel = false; } }