Esempio n. 1
0
        //--------------------------------------------------------------------------------------

        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();
            }
        }
Esempio n. 2
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. 3
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
            {
            }
        }