Esempio n. 1
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary> Sets a tablename. </summary>
        ///

        /// <param name="tablename">  The tablename. </param>
        /// <param name="errMessage"> [in,out] Message describing the error. </param>
        ///
        /// <returns> true if it succeeds, false if it fails. </returns>
        ///-------------------------------------------------------------------------------------------------

        public bool SetTablename(string tablename, ref string errMessage)
        {
            bool   iserror   = true;
            string errString = "";

            // Fetch the Parameters and Names for this table
            DataTable SelectedTable;

            SelectedTable = UniDB.Tools.LoadTable(FDbConnection, tablename, 1, ref iserror, ref errString);

            parameterTreeView1.ParameterManager = FPM;
            parameterTreeView1.Clear();
            if (!iserror)
            {
                //parameterTreeView1.Items.Clear();

                // get all the different paramters in order
                List <string> parmlist = WaterSimManager_DB.ParameterFieldsInTable(SelectedTable, FPM, false, false, false, modelParamtype.mptUnknown);
                parameterTreeView1.SetFieldsActive(parmlist);

                //    parmlist = WaterSimManager_DB.ParameterFieldsInTable(SelectedTable, FPM, true, false, true, modelParamtype.mptOutputProvider);
                //    foreach (string str in parmlist)
                //    {
                //        //parameterTreeView1.Items.Add(str);
                //    }
                //    parmlist = WaterSimManager_DB.ParamtersInTable(SelectedTable, FPM, true, false, true, modelParamtype.mptInputBase);
                //    foreach (string str in parmlist)
                //    {
                //        //parameterTreeView1.Items.Add(str);
                //    }
                //    parmlist = WaterSimManager_DB.ParamtersInTable(SelectedTable, FPM, true, false, true, modelParamtype.mptInputProvider);
                //    foreach (string str in parmlist)
                //    {
                //        //parameterTreeView1.Items.Add(str);
                //    }
                //    parmlist = WaterSimManager_DB.ParamtersInTable(SelectedTable, FPM, false, true, false, 0);
                //    foreach (string str in parmlist)
                //    {
                //        //parameterTreeView1.Items.Add(str);
                //    }
            }

            char stringquote = Tools.SQLStringQuote(FDbConnection.SQLServerType);
            // get the year
            string ScnName       = SelectedTable.Rows[0][WaterSimManager_DB.rdbfScenarioName].ToString();
            string firstyear     = SelectedTable.Rows[0][WaterSimManager_DB.rdbfSimYear].ToString();            // ok get the provider codes in the table
            string JustFirstYear = WaterSimManager_DB.rdbfSimYear + " = " + firstyear + " AND " + WaterSimManager_DB.rdbfScenarioName + " = " + stringquote + ScnName + stringquote;

            SelectedTable = UniDB.Tools.LoadTable(FDbConnection, tablename, JustFirstYear, ref iserror, ref errString);
            if (!iserror)
            {
                List <string> ProvList = WaterSimManager_DB.ProvidersInTable(SelectedTable);
                ProvidernamesComboBox.Items.Clear();
                foreach (string str in ProvList)
                {
                    ProvidernamesComboBox.Items.Add(str);
                }
            }

            // get the scenarios. load table with just the required fields which all is need to fethc scenario names
            List <string> GetTheseFields = WaterSimManager_DB.RequiredFieldsList();

            SelectedTable = UniDB.Tools.LoadTable(FDbConnection, tablename, GetTheseFields, ref iserror, ref errString);
            // Get the scenario names, if they are there
            if (!iserror)
            {
                List <string> ScnList = WaterSimManager_DB.ScenarioNamesInTable(SelectedTable);
                ScenarioNamesComboBox.Items.Clear();
                if (ScnList.Count > 0)
                {
                    ScenarioNamesComboBox.Items.Add(FIRSTSCENARIO);
                    foreach (string str in ScnList)
                    {
                        ScenarioNamesComboBox.Items.Add(str);
                    }
                }
                else
                {
                    ScenarioNamesComboBox.Items.Add(NOSCENARIOS);
                }
            }

            // OK, if no error so far, then load the whole table
            if (!iserror)
            {
                FDataTable = UniDB.Tools.LoadTable(FDbConnection, tablename, ref iserror, ref errString);
            }
            return(!iserror);
        }
        private bool SetTablename(string tablename, ref string errString)
        {
            char stringquote = Tools.SQLStringQuote(FDbConnection.SQLServerType);
            bool iserror     = true;
            // Fetch the Parameters and Names for this table
            DataTable SelectedTable;

            SelectedTable = UniDB.Tools.LoadTable(FDbConnection, tablename, ref iserror, ref errString);

            if (!iserror)
            {
                ParmComboBox.Items.Clear();

                // get all the different paramters in order
                List <string> parmlist = WaterSimManager_DB.ParamtersInTable(SelectedTable, FPM, true, false, true, modelParamtype.mptOutputBase);
                foreach (string str in parmlist)
                {
                    ParmComboBox.Items.Add(str);
                }

                parmlist = WaterSimManager_DB.ParamtersInTable(SelectedTable, FPM, true, false, true, modelParamtype.mptOutputProvider);
                foreach (string str in parmlist)
                {
                    ParmComboBox.Items.Add(str);
                }
                parmlist = WaterSimManager_DB.ParamtersInTable(SelectedTable, FPM, true, false, true, modelParamtype.mptInputBase);
                foreach (string str in parmlist)
                {
                    ParmComboBox.Items.Add(str);
                }
                parmlist = WaterSimManager_DB.ParamtersInTable(SelectedTable, FPM, true, false, true, modelParamtype.mptInputProvider);
                foreach (string str in parmlist)
                {
                    ParmComboBox.Items.Add(str);
                }
                parmlist = WaterSimManager_DB.ParamtersInTable(SelectedTable, FPM, false, true, false, 0);
                foreach (string str in parmlist)
                {
                    ParmComboBox.Items.Add(str);
                }

                List <string> Scnlist = WaterSimManager_DB.ScenarioNamesInTable(SelectedTable);

                string ScnName       = SelectedTable.Rows[0][WaterSimManager_DB.rdbfScenarioName].ToString();
                string firstyear     = SelectedTable.Rows[0][WaterSimManager_DB.rdbfSimYear].ToString();            // ok get the provider codes in the table
                string JustFirstYear = WaterSimManager_DB.rdbfSimYear + " = " + firstyear + " AND " + WaterSimManager_DB.rdbfScenarioName + " = " + stringquote + ScnName + stringquote;
                SelectedTable = UniDB.Tools.LoadTable(FDbConnection, tablename, JustFirstYear, ref iserror, ref errString);
                if (!iserror)
                {               // ok get the provider codes in the table
                    ProviderCheckedListBox.Items.Clear();
                    List <string> Provlist = WaterSimManager_DB.ProvidersInTable(SelectedTable);
                    foreach (string str in Provlist)
                    {
                        ProviderCheckedListBox.Items.Add(str);
                    }


                    // Get the scenario names, if they are there
                    ScenarioNamesComboBox.Items.Clear();
                    if (Scnlist.Count > 0)
                    {
                        ScenarioNamesComboBox.Enabled = true;
                        ScenarioNamesComboBox.Items.Add(FIRSTSCENARIO);
                        foreach (string str in Scnlist)
                        {
                            ScenarioNamesComboBox.Items.Add(str);
                        }
                    }
                    else
                    {
                        ScenarioNamesComboBox.Items.Add(NOSCENARIOS);
                        ScenarioNamesComboBox.Text    = NOSCENARIOS;
                        ScenarioNamesComboBox.Enabled = false;
                    }
                }
                else
                {
                    errString = "Error Finding Providers in Datatable";
                }
            }
            else
            {
                errString = "Error Finding WaterSim Parameters in DataTable";
            }

            if (!iserror)
            {
                FTablename = tablename;
                FDataTable = UniDB.Tools.LoadTable(FDbConnection, tablename, ref iserror, ref errString);
            }
            return(!iserror);
        }