Esempio n. 1
0
        //--------------------------------------------------------------------------------------
        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
            {
            }
        }
Esempio n. 2
0
        //--------------------------------------------------------------------------------------
        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
            {
            }
        }
Esempio n. 3
0
 //----------------------------------------------------------
 public void SetAllModelValues(SimulationInputs si)
 {
     WSim.ParamManager.SetSimulationInputs(si);
 }
Esempio n. 4
0
        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;
            }
        }