private string[] loadScenarioArray(ado_data_access oAdo)
        {
            //
            //OPEN CONNECTION TO DB FILE CONTAINING PROCESSOR SCENARIO TABLE
            //
            //scenario mdb connection
            string strProcessorScenarioMDB =
                frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                "\\processor\\db\\scenario_processor_rule_definitions.mdb";

            //
            //get a list of all the scenarios
            //
            oAdo.OpenConnection(oAdo.getMDBConnString(strProcessorScenarioMDB, "", ""));
            string[] strScenarioArray =
                frmMain.g_oUtils.ConvertListToArray(
                    oAdo.CreateCommaDelimitedList(
                        oAdo.m_OleDbConnection,
                        "SELECT scenario_id " +
                        "FROM scenario " +
                        "WHERE scenario_id IS NOT NULL AND " +
                        "LEN(TRIM(scenario_id)) > 0", ""), ",");
            oAdo.CloseConnection(oAdo.m_OleDbConnection);
            return(strScenarioArray);
        }
示例#2
0
 private void InstantiateConnectionObject(ado_data_access p_oAdo)
 {
     if (_oConn == null)
     {
     }
     else
     {
         p_oAdo.CloseConnection(_oConn);
         _oConn.Dispose();
         _oConn = null;
     }
     _oConn = new System.Data.OleDb.OleDbConnection();
 }
示例#3
0
        private string getNextScenarioId()
        {
            System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection();
            string strProjDir     = frmMain.g_oFrmMain.getProjectDirectory();
            string strScenarioDir = strProjDir + "\\" + ScenarioType + "\\db";
            string strFile        = "scenario_" + ScenarioType + "_rule_definitions.mdb";

            System.Text.StringBuilder strFullPath = new System.Text.StringBuilder(strScenarioDir);
            strFullPath.Append("\\");
            strFullPath.Append(strFile);
            ado_data_access oAdo    = new ado_data_access();
            string          strConn = oAdo.getMDBConnString(strFullPath.ToString(), "admin", "");

            oAdo.OpenConnection(strConn);
            string strSQL = "SELECT scenario_id from " + Tables.Scenario.DefaultScenarioTableName;

            System.Collections.Generic.IList <string> lstExistingScenarios = new System.Collections.Generic.List <string>();

            oAdo.SqlQueryReader(oAdo.m_OleDbConnection, strSQL);
            if (oAdo.m_OleDbDataReader.HasRows)
            {
                // Load all of the existing scenarios into a list we can query
                while (oAdo.m_OleDbDataReader.Read())
                {
                    string strScenario = Convert.ToString(oAdo.m_OleDbDataReader["scenario_id"]).Trim();
                    if (!String.IsNullOrEmpty(strScenario))
                    {
                        lstExistingScenarios.Add(strScenario);
                    }
                }
            }
            oAdo.CloseConnection(oAdo.m_OleDbConnection);

            int    i = 1;
            string strTestName;

            // keep incrementing the scenario name until we find one that doesn't exist
            while (i < (lstExistingScenarios.Count + 1))
            {
                strTestName = "scenario" + Convert.ToString(i);
                if (!lstExistingScenarios.Contains(strTestName))
                {
                    break;
                }
                i++;
            }

            strTestName = "scenario" + Convert.ToString(i);
            return(strTestName);
        }
        private void Save()
        {
            string          strPath       = "";
            string          strDatasource = "";
            string          strTableType  = "";
            string          strScenario   = "";
            ado_data_access oAdo          = new ado_data_access();

            oAdo.OpenConnection(oAdo.getMDBConnString(m_strRandomPathAndFile, "", ""));

            for (int x = 0; x <= lvDatasources.Items.Count - 1; x++)
            {
                strDatasource = lvDatasources.Items[x].SubItems[COLUMN_DATASOURCE].Text.Trim();
                strTableType  = lvDatasources.Items[x].SubItems[COLUMN_TABLETYPE].Text.Trim();
                strPath       = lvDatasources.Items[x].SubItems[COLUMN_PATH].Text.Trim();
                strScenario   = lvDatasources.Items[x].SubItems[COLUMN_SCENARIO].Text.Trim();
                oAdo.m_strSQL = "";
                if (strDatasource == "Project")
                {
                    oAdo.m_strSQL = "UPDATE project_datasource SET path = '" + strPath + "' WHERE TRIM(Table_Type) = '" + strTableType + "'";
                }
                else if (strDatasource == "TreatmentOptimizer" && strTableType == "NA")
                {
                    oAdo.m_strSQL = "UPDATE optimizer_scenario SET path = '" + strPath + "' WHERE TRIM(scenario_id) = '" + strScenario + "'";
                }
                else if (strDatasource == "TreatmentOptimizer")
                {
                    oAdo.m_strSQL = "UPDATE optimizer_scenario_datasource SET path = '" + strPath + "' WHERE TRIM(scenario_id) = '" + strScenario + "' AND TRIM(Table_Type) = '" + strTableType + "'";
                }
                else if (strDatasource == "Processor" && strTableType == "NA")
                {
                    oAdo.m_strSQL = "UPDATE processor_scenario SET path = '" + strPath + "' WHERE TRIM(scenario_id) = '" + strScenario + "'";
                }
                else if (strDatasource == "Processor")
                {
                    oAdo.m_strSQL = "UPDATE processor_scenario_datasource SET path = '" + strPath + "' WHERE TRIM(scenario_id) = '" + strScenario + "' AND TRIM(Table_Type) = '" + strTableType + "'";
                }
                if (oAdo.m_strSQL.Trim().Length > 0)
                {
                    oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL);
                }
            }
            oAdo.CloseConnection(oAdo.m_OleDbConnection);
            MessageBox.Show("Done", "FIA Biosum");
            m_bSyncd = false;
        }
        public void savevalues()
        {
            ado_data_access oAdo           = new ado_data_access();
            string          strScenarioId  = this.ReferenceOptimizerScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower();
            string          strScenarioMDB =
                frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" +
                Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioTableDbFile;

            oAdo.OpenConnection(oAdo.getMDBConnString(strScenarioMDB, "", ""));
            oAdo.m_strSQL = "DELETE FROM " + Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioProcessorScenarioSelectTableName + " " +
                            "WHERE TRIM(UCASE(scenario_id)) = '" +
                            ReferenceOptimizerScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToUpper() + "';";
            oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL);
            if (lvProcessorScenario.CheckedItems.Count > 0)
            {
                string strColumnsList = "scenario_id,processor_scenario_id,FullDetailsYN";
                string strValuesList  = "";
                strValuesList = "'" + ReferenceOptimizerScenarioForm.uc_scenario1.txtScenarioId.Text.Trim() + "',";
                strValuesList = strValuesList + "'" + lvProcessorScenario.CheckedItems[0].SubItems[COL_SCENARIOID].Text.Trim() + "',";
                if (this.chkFullDetails.Checked)
                {
                    strValuesList = strValuesList + "'Y'";
                }
                else
                {
                    strValuesList = strValuesList + "'N'";
                }

                oAdo.m_strSQL = "INSERT INTO " + Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioProcessorScenarioSelectTableName + " " +
                                "(" + strColumnsList + ") " +
                                "VALUES " +
                                "(" + strValuesList + ")";

                oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL);
            }
            oAdo.CloseConnection(oAdo.m_OleDbConnection);
        }
        public void loadvalues(bool p_bScenarioCopy)
        {
            int x;
            ProcessorScenarioTools oTools = new ProcessorScenarioTools();

            //Reset m_oProcessorScenarioItem_Collection so we don't get duplicates when we loadAll down below
            m_oProcessorScenarioItem_Collection = new ProcessorScenarioItem_Collection();
            lvProcessorScenario.Items.Clear();
            System.Windows.Forms.ListViewItem entryListItem = null;
            this.m_oLvAlternateColors.InitializeRowCollection();
            this.m_oLvAlternateColors.ReferenceAlternateBackgroundColor   = frmMain.g_oGridViewAlternateRowBackgroundColor;
            this.m_oLvAlternateColors.ReferenceAlternateForegroundColor   = frmMain.g_oGridViewRowForegroundColor;
            this.m_oLvAlternateColors.ReferenceBackgroundColor            = frmMain.g_oGridViewRowBackgroundColor;
            this.m_oLvAlternateColors.ReferenceForegroundColor            = frmMain.g_oGridViewRowForegroundColor;
            this.m_oLvAlternateColors.ReferenceSelectedRowBackgroundColor = frmMain.g_oGridViewSelectedRowBackgroundColor;
            this.m_oLvAlternateColors.ReferenceListView   = this.lvProcessorScenario;
            this.m_oLvAlternateColors.CustomFullRowSelect = true;
            if (frmMain.g_oGridViewFont != null)
            {
                this.lvProcessorScenario.Font = frmMain.g_oGridViewFont;
            }

            ado_data_access oAdo = new ado_data_access();
            string          strProcessorScenario = "";
            string          strFullDetailsYN     = "N";

            if (p_bScenarioCopy == false)
            {
                string[] strScenarioArray = null;
                if (!ReferenceOptimizerScenarioForm.m_bProcessorUsingSqlite)
                {
                    strScenarioArray = loadScenarioArray(oAdo);
                }
                else
                {
                    strScenarioArray = loadScenarioArraySqlite();
                }
                if (strScenarioArray == null)
                {
                    return;
                }

                for (x = 0; x <= strScenarioArray.Length - 1; x++)
                {
                    //
                    //LOAD PROJECT DATATASOURCES INFO
                    //
                    m_oQueries.m_oFvs.LoadDatasource       = true;
                    m_oQueries.m_oFIAPlot.LoadDatasource   = true;
                    m_oQueries.m_oProcessor.LoadDatasource = true;
                    m_oQueries.m_oReference.LoadDatasource = true;
                    m_oQueries.LoadDatasources(true, ReferenceOptimizerScenarioForm.m_bProcessorUsingSqlite, "processor", strScenarioArray[x]);
                    if (!ReferenceOptimizerScenarioForm.m_bProcessorUsingSqlite)
                    {
                        m_oQueries.m_oDataSource.CreateScenarioRuleDefinitionTableLinks(
                            m_oQueries.m_strTempDbFile,
                            frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim(),
                            "P");
                        oTools.LoadAll(m_oQueries.m_strTempDbFile, m_oQueries, strScenarioArray[x], m_oProcessorScenarioItem_Collection);
                    }
                    else
                    {
                        oTools.LoadAllSqlite(m_oQueries, strScenarioArray[x], m_oProcessorScenarioItem_Collection);
                    }
                }
            }
            else
            {
                foreach (ProcessorScenarioItem psItem in ReferenceOptimizerScenarioForm.m_oOptimizerScenarioItem.m_oProcessorScenarioItem_Collection)
                {
                    m_oProcessorScenarioItem_Collection.Add(psItem);
                    if (psItem.Selected == true)
                    {
                        strProcessorScenario = psItem.ScenarioId;
                        strFullDetailsYN     = psItem.DisplayFullDetailsYN;
                    }
                }
            }
            for (x = 0; x <= m_oProcessorScenarioItem_Collection.Count - 1; x++)
            {
                entryListItem = lvProcessorScenario.Items.Add(" ");

                entryListItem.UseItemStyleForSubItems = false;
                this.m_oLvAlternateColors.AddRow();
                this.m_oLvAlternateColors.AddColumns(x, lvProcessorScenario.Columns.Count);


                entryListItem.SubItems.Add(m_oProcessorScenarioItem_Collection.Item(x).ScenarioId);
                entryListItem.SubItems.Add(m_oProcessorScenarioItem_Collection.Item(x).Description);
            }
            this.m_oLvAlternateColors.ListView();

            if (p_bScenarioCopy == false)
            {
                string strScenarioMDB =
                    frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" +
                    Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioTableDbFile;


                string strConn = oAdo.getMDBConnString(strScenarioMDB, "", "");
                oAdo.OpenConnection(strConn);

                if (oAdo.TableExist(oAdo.m_OleDbConnection, Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioProcessorScenarioSelectTableName))
                {
                    oAdo.m_strSQL = "SELECT * FROM " + Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioProcessorScenarioSelectTableName + " " +
                                    "WHERE TRIM(UCASE(scenario_id)) = '" +
                                    ReferenceOptimizerScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToUpper() + "';";
                    oAdo.SqlQueryReader(oAdo.m_OleDbConnection, oAdo.m_strSQL);

                    if (oAdo.m_OleDbDataReader.HasRows)
                    {
                        while (oAdo.m_OleDbDataReader.Read())
                        {
                            if (oAdo.m_OleDbDataReader["processor_scenario_id"] != System.DBNull.Value &&
                                oAdo.m_OleDbDataReader["processor_scenario_id"].ToString().Trim().Length > 0)
                            {
                                strProcessorScenario = oAdo.m_OleDbDataReader["processor_scenario_id"].ToString().Trim();
                            }
                            if (oAdo.m_OleDbDataReader["FullDetailsYN"] != System.DBNull.Value &&
                                oAdo.m_OleDbDataReader["FullDetailsYN"].ToString().Trim().Length > 0)
                            {
                                strFullDetailsYN = oAdo.m_OleDbDataReader["FullDetailsYN"].ToString().Trim();
                            }
                        }
                    }
                    oAdo.m_OleDbDataReader.Close();
                    oAdo.CloseConnection(oAdo.m_OleDbConnection);
                }
                else
                {
                    frmMain.g_oTables.m_oOptimizerScenarioRuleDef.CreateScenarioProcessorScenarioSelectTable(oAdo, oAdo.m_OleDbConnection, Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioProcessorScenarioSelectTableName);
                }
            }
            if (lvProcessorScenario.Items.Count > 0)
            {
                for (x = 0; x <= lvProcessorScenario.Items.Count - 1; x++)
                {
                    if (lvProcessorScenario.Items[x].SubItems[COL_SCENARIOID].Text.Trim().ToUpper() ==
                        strProcessorScenario.ToUpper())
                    {
                        lvProcessorScenario.Items[x].Checked = true;
                        for (int y = 0; y <= ReferenceOptimizerScenarioForm.uc_scenario_processor_scenario_select1.m_oProcessorScenarioItem_Collection.Count - 1; y++)
                        {
                            if (lvProcessorScenario.Items[x].SubItems[COL_SCENARIOID].Text.Trim().ToUpper() ==
                                ReferenceOptimizerScenarioForm.uc_scenario_processor_scenario_select1.m_oProcessorScenarioItem_Collection.Item(y).ScenarioId.Trim().ToUpper())
                            {
                                ReferenceOptimizerScenarioForm.uc_scenario_cond_filter1.strLowSlope =
                                    ReferenceOptimizerScenarioForm.uc_scenario_processor_scenario_select1.m_oProcessorScenarioItem_Collection.Item(y).m_oHarvestMethod.SteepSlopePercent;

                                ReferenceOptimizerScenarioForm.uc_scenario_cond_filter1.strSteepSlope =
                                    ReferenceOptimizerScenarioForm.uc_scenario_processor_scenario_select1.m_oProcessorScenarioItem_Collection.Item(y).m_oHarvestMethod.SteepSlopePercent;
                            }
                        }
                        break;
                    }
                }
                if (x <= lvProcessorScenario.Items.Count - 1)
                {
                    lvProcessorScenario.Items[0].Selected = true;
                }
            }

            if (strFullDetailsYN == "Y")
            {
                chkFullDetails.Checked = true;
            }
            else
            {
                chkFullDetails.Checked = false;
            }
        }
示例#7
0
        public void loadvalues()
        {
            int x;

            lvProcessorScenario.Items.Clear();
            System.Windows.Forms.ListViewItem entryListItem = null;
            this.m_oLvAlternateColors.InitializeRowCollection();
            this.m_oLvAlternateColors.ReferenceAlternateBackgroundColor   = frmMain.g_oGridViewAlternateRowBackgroundColor;
            this.m_oLvAlternateColors.ReferenceAlternateForegroundColor   = frmMain.g_oGridViewRowForegroundColor;
            this.m_oLvAlternateColors.ReferenceBackgroundColor            = frmMain.g_oGridViewRowBackgroundColor;
            this.m_oLvAlternateColors.ReferenceForegroundColor            = frmMain.g_oGridViewRowForegroundColor;
            this.m_oLvAlternateColors.ReferenceSelectedRowBackgroundColor = frmMain.g_oGridViewSelectedRowBackgroundColor;
            this.m_oLvAlternateColors.ReferenceListView   = this.lvProcessorScenario;
            this.m_oLvAlternateColors.CustomFullRowSelect = true;
            if (frmMain.g_oGridViewFont != null)
            {
                this.lvProcessorScenario.Font = frmMain.g_oGridViewFont;
            }
            //
            //OPEN CONNECTION TO DB FILE CONTAINING Processor Scenario TABLE
            //
            //scenario mdb connection
            string strProcessorScenarioMDB =
                frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                "\\processor\\db\\scenario_processor_rule_definitions.mdb";
            //
            //get a list of all the scenarios
            //
            ado_data_access oAdo = new ado_data_access();

            oAdo.OpenConnection(oAdo.getMDBConnString(strProcessorScenarioMDB, "", ""));
            oAdo.SqlQueryReader(oAdo.m_OleDbConnection,
                                "SELECT scenario_id,description " +
                                "FROM scenario " +
                                "WHERE scenario_id IS NOT NULL AND " +
                                "LEN(TRIM(scenario_id)) > 0");

            x = 0;
            if (oAdo.m_OleDbDataReader.HasRows)
            {
                while (oAdo.m_OleDbDataReader.Read())
                {
                    if (oAdo.m_OleDbDataReader["scenario_id"] != DBNull.Value &&
                        oAdo.m_OleDbDataReader["scenario_id"].ToString().Trim().Length > 0 &&
                        ReferenceCurrentScenarioItem.ScenarioId.Trim().ToUpper() !=
                        oAdo.m_OleDbDataReader["scenario_id"].ToString().Trim().ToUpper())
                    {
                        entryListItem = lvProcessorScenario.Items.Add(" ");

                        entryListItem.UseItemStyleForSubItems = false;
                        this.m_oLvAlternateColors.AddRow();
                        this.m_oLvAlternateColors.AddColumns(x, lvProcessorScenario.Columns.Count);


                        entryListItem.SubItems.Add(oAdo.m_OleDbDataReader["scenario_id"].ToString().Trim());

                        if (oAdo.m_OleDbDataReader["description"] != DBNull.Value &&
                            oAdo.m_OleDbDataReader["description"].ToString().Trim().Length > 0)
                        {
                            entryListItem.SubItems.Add(oAdo.m_OleDbDataReader["description"].ToString().Trim());
                        }
                        else
                        {
                            entryListItem.SubItems.Add(" ");
                        }
                        x = x + 1;
                    }
                }
                this.m_oLvAlternateColors.ListView();
            }
            else
            {
                MessageBox.Show("!!No Scenarios To Copy!!", "FIA Bisoum");
                btnCopy.Enabled = false;
            }
            oAdo.m_OleDbDataReader.Close();
            oAdo.CloseConnection(oAdo.m_OleDbConnection);
        }
        private void mnuEditBrowse_Click(object sender, System.EventArgs e)
        {
            //instantiate the datasource class
            //FIA_Biosum_Manager.Datasource p_datasource = new Datasource(((frmDialog)this.ParentForm).m_frmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim());
            FIA_Biosum_Manager.Datasource p_datasource = new Datasource();
            p_datasource.LoadTableColumnNamesAndDataTypes = false;
            p_datasource.LoadTableRecordCount             = false;
            p_datasource.m_strDataSourceMDBFile           = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\db\\project.mdb";
            p_datasource.m_strDataSourceTableName         = "datasource";
            p_datasource.m_strScenarioId = "";
            p_datasource.populate_datasource_array();


            int intPlot = p_datasource.getTableNameRow("PLOT");

            //see if datasource found the PLOT table type
            if (intPlot >= 0)
            {
                string strFile = p_datasource.m_strDataSource[intPlot, PATH].Trim() + "\\" +
                                 p_datasource.m_strDataSource[intPlot, MDBFILE].Trim();

                ado_data_access oAdo    = new ado_data_access();
                string          strConn = oAdo.getMDBConnString(strFile, "", "");
                oAdo.OpenConnection(strConn);
                if (oAdo.m_intError == 0)
                {
                    //see if the MDB file is found and the plot table is found
                    if (p_datasource.m_strDataSource[intPlot, FILESTATUS].Trim() == "F" &&
                        p_datasource.m_strDataSource[intPlot, TABLESTATUS].Trim() == "F")
                    {
                        //see if there are records in the plot table
                        if (Convert.ToInt32(oAdo.getRecordCount(oAdo.m_OleDbConnection, "SELECT COUNT(*) FROM " + p_datasource.m_strDataSource[intPlot, TABLE].Trim(), "temp")) > 0)
                        {
                            //string strConn="";


                            oAdo.CloseConnection(oAdo.m_OleDbConnection);

                            FIA_Biosum_Manager.frmGridView frmGV = new frmGridView();
                            frmGV.strProjectDirectory = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim();

                            //frmGV.MdiParent = (frmMain)this.ParentForm.ParentForm;
                            frmGV.Text = "Database: Browse And Delete Plot Records";
                            frmGV.LoadDataSetToDeleteOnly(strConn, "select * from " + p_datasource.m_strDataSource[intPlot, TABLE].Trim() + ";", p_datasource.m_strDataSource[intPlot, TABLE].Trim());
                            frmMain.g_oFrmMain.Enabled = false;
                            frmGV.MinimizeMainForm     = true;
                            frmGV.Show();
                            //frmGV.Show();
                            //frmGV.Focus();
                        }
                        else
                        {
                            oAdo.CloseConnection(oAdo.m_OleDbConnection);
                            MessageBox.Show("!!No Records In The PLOT table!!", "BROWSE AND DELETE PLOT RECORDS", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        oAdo.CloseConnection(oAdo.m_OleDbConnection);
                        MessageBox.Show("!!Could not find either the MDB File named \n" +
                                        p_datasource.m_strDataSource[intPlot, MDBFILE] + "\n" +
                                        " or the plot table named \n" +
                                        p_datasource.m_strDataSource[intPlot, TABLE].Trim() + "!!",
                                        "BROWSE AND DELETE PLOT RECORDS",
                                        System.Windows.Forms.MessageBoxButtons.OK,
                                        System.Windows.Forms.MessageBoxIcon.Exclamation);
                    }
                }
            }
            else
            {
                MessageBox.Show("!!Could not find the table type PLOT in the datasource table!!", "BROWSE AND DELETE PLOT RECORDS", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
            }
        }
        public void savevalues()
        {
            //
            //OPEN CONNECTION TO DB FILE CONTAINING PROCESSOR SCENARIO TABLES
            //
            //scenario mdb connection
            ado_data_access oAdo           = new ado_data_access();
            string          strScenarioMDB =
                frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                "\\processor\\db\\scenario_processor_rule_definitions.mdb";

            oAdo.OpenConnection(oAdo.getMDBConnString(strScenarioMDB, "", ""));
            if (oAdo.m_intError != 0)
            {
                m_intError = oAdo.m_intError;
                m_strError = oAdo.m_strError;
                oAdo       = null;
                return;
            }

            m_intError = 0;
            m_strError = "";
            string strFields = "scenario_id,yard_dist_threshold,assumed_harvest_area_ac," +
                               "move_in_time_multiplier," +
                               "move_in_hours_addend";
            string strValues = "";

            oAdo.m_strSQL = "DELETE FROM " + Tables.ProcessorScenarioRuleDefinitions.DefaultMoveInCostsTableName + " " +
                            "WHERE TRIM(UCASE(scenario_id)) = '" + ScenarioId.Trim().ToUpper() + "'";
            oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL);

            //
            //SCENARIOID
            //
            strValues = "'" + ScenarioId + "',";
            //
            //YARDING DISTANCE THRESHOLD
            //
            if (this.txtYardDistThreshold.Text.Trim().Length > 0)
            {
                strValues = strValues + this.txtYardDistThreshold.Text.Trim() + ",";
            }
            else
            {
                strValues = strValues + "null,";
            }
            //
            //ASSUMED HARVEST AREA
            //
            if (this.txtAssumedHarvestArea.Text.Trim().Length > 0)
            {
                strValues = strValues + this.txtAssumedHarvestArea.Text.Trim() + ",";
            }
            else
            {
                strValues = strValues + "null,";
            }
            //
            //MOVE IN TIME MULTIPLIER
            //
            if (this.txtMoveInTimeMultiplier.Text.Trim().Length > 0)
            {
                strValues = strValues + this.txtMoveInTimeMultiplier.Text.Trim() + ",";
            }
            else
            {
                strValues = strValues + "null,";
            }
            //
            //MOVE IN TIME ADDEND
            //
            if (this.txtMoveInAddend.Text.Trim().Length > 0)
            {
                strValues = strValues + this.txtMoveInAddend.Text.Trim();
            }
            else
            {
                strValues = strValues + "null";
            }
            //

            oAdo.m_strSQL = Queries.GetInsertSQL(strFields, strValues, Tables.ProcessorScenarioRuleDefinitions.DefaultMoveInCostsTableName);
            oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL);
            m_intError = oAdo.m_intError;

            oAdo.CloseConnection(oAdo.m_OleDbConnection);
            oAdo = null;
        }
        public void loadvalues()
        {
            int x;

            //
            //SCENARIO ID
            //
            ScenarioId = this.ReferenceProcessorScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower();

            if (!ReferenceProcessorScenarioForm.m_bUsingSqlite)
            {
                if (m_oAdo != null && m_oAdo.m_OleDbConnection != null)
                {
                    if (m_oAdo.m_OleDbConnection.State == System.Data.ConnectionState.Open)
                    {
                        m_oAdo.CloseConnection(m_oAdo.m_OleDbConnection);
                    }
                }

                //
                //SCENARIO MDB
                //
                string strScenarioMDB =
                    frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                    "\\processor\\db\\scenario_processor_rule_definitions.mdb";

                //
                //CREATE LINK IN TEMP MDB TO SCENARIO TREE SPECIES DIAM DOLLAR VALUES TABLE
                //
                dao_data_access oDao = new dao_data_access();
                //link to tree species groups table
                oDao.CreateTableLink(this.ReferenceProcessorScenarioForm.LoadedQueries.m_strTempDbFile,
                                     "scenario_tree_species_diam_dollar_values",
                                     strScenarioMDB, "scenario_tree_species_diam_dollar_values", true);
                oDao.m_DaoWorkspace.Close();
                oDao = null;
                //
                //OPEN CONNECTION TO TEMP DB FILE
                //
                m_oAdo = new ado_data_access();
                m_oAdo.OpenConnection(m_oAdo.getMDBConnString(this.ReferenceProcessorScenarioForm.LoadedQueries.m_strTempDbFile, "", ""));
                if (m_oAdo.m_intError == 0)
                {
                    ReferenceProcessorScenarioForm.m_oProcessorScenarioTools.LoadSpeciesAndDiameterGroupDollarValues
                        (m_oAdo, m_oAdo.m_OleDbConnection, ReferenceProcessorScenarioForm.m_oProcessorScenarioItem);
                }
            }
            else
            {
                //
                //SCENARIO MDB
                //
                string strScenarioMDB =
                    frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                    "\\processor\\" + Tables.ProcessorScenarioRuleDefinitions.DefaultSqliteDbFile;
                ReferenceProcessorScenarioForm.m_oProcessorScenarioTools.LoadSpeciesAndDiameterGroupDollarValuesSqlite(strScenarioMDB,
                                                                                                                       ReferenceProcessorScenarioForm.m_oProcessorScenarioItem);
            }


            //REMOVE OLD CONTROLS FROM FORM IF THEY EXIST
            string strName = "uc_processor_scenario_spc_dbh_group_value2";

            if (this.pnlMerchValues.Controls[strName] != null)
            {
                for (x = 2; x <= this.uc_processor_scenario_spc_dbh_group_value_collection1.Count; x++)
                {
                    strName = "uc_processor_scenario_spc_dbh_group_value" + x;
                    uc_processor_scenario_spc_dbh_group_value oItem = (uc_processor_scenario_spc_dbh_group_value)this.pnlMerchValues.Controls[strName];
                    if (oItem != null)
                    {
                        this.pnlMerchValues.Controls.Remove(oItem);
                    }
                }
            }

            //REMOVE OLD ITEMS FROM COLLECTION IF THEY EXIST
            if (this.uc_processor_scenario_spc_dbh_group_value_collection1.Count > 0)
            {
                this.uc_processor_scenario_spc_dbh_group_value_collection1.Clear();
            }

            for (x = 0; x <= ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Count - 1; x++)
            {
                if (this.uc_processor_scenario_spc_dbh_group_value_collection1.Count == 0)
                {
                    if (ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).SpeciesGroup.Trim().Length > 0)
                    {
                        //
                        //SPECIES GROUP
                        //
                        this.uc_processor_scenario_spc_dbh_group_value1.SpeciesGroup =
                            ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).SpeciesGroup.Trim();
                        //
                        //DBH GROUP
                        //
                        this.uc_processor_scenario_spc_dbh_group_value1.DbhGroup =
                            ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).DbhGroup.Trim();
                        //
                        //MERCH CUBIC FOOT VALUE
                        //
                        this.m_oValidate.ValidateDecimal(ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).MerchDollarPerCubicFootValue);
                        this.uc_processor_scenario_spc_dbh_group_value1.CubicFootDollarValue = this.m_oValidate.ReturnValue;
                        //
                        //USE AS ENERGY WOOD
                        //
                        this.uc_processor_scenario_spc_dbh_group_value1.EnergyWood =
                            ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).UseAsEnergyWood;

                        this.uc_processor_scenario_spc_dbh_group_value1.ReferenceProcessorScenarioForm = ReferenceProcessorScenarioForm;

                        this.uc_processor_scenario_spc_dbh_group_value_collection1.Add(this.uc_processor_scenario_spc_dbh_group_value1);
                        this.m_oValidate.ValidateDecimal(ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).ChipsDollarPerCubicFootValue);
                        this.txtChipValue.Text  = this.m_oValidate.ReturnValue;
                        this.m_strChipValueSave = this.txtChipValue.Text;
                    }
                }
                else
                {
                    if (ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).SpeciesGroup.Trim().Length > 0)
                    {
                        uc_processor_scenario_spc_dbh_group_value oItem = new uc_processor_scenario_spc_dbh_group_value();
                        //
                        //SPECIES GROUP
                        //
                        oItem.SpeciesGroup =
                            ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).SpeciesGroup.Trim();
                        //
                        //DBH GROUP
                        //
                        oItem.DbhGroup =
                            ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).DbhGroup.Trim();
                        //
                        //MERCH CUBIC FOOT VALUE
                        //
                        this.m_oValidate.ValidateDecimal(ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).MerchDollarPerCubicFootValue);
                        oItem.CubicFootDollarValue = this.m_oValidate.ReturnValue;
                        //
                        //USE AS ENERGY WOOD
                        oItem.EnergyWood =
                            ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).UseAsEnergyWood;
                        oItem.Name = "uc_processor_scenario_spc_dbh_group_value" + Convert.ToString(uc_processor_scenario_spc_dbh_group_value_collection1.Count + 1).Trim();
                        this.pnlMerchValues.Controls.Add(oItem);
                        oItem.Top = uc_processor_scenario_spc_dbh_group_value_collection1.Item(uc_processor_scenario_spc_dbh_group_value_collection1.Count - 1).Top +
                                    uc_processor_scenario_spc_dbh_group_value_collection1.Item(uc_processor_scenario_spc_dbh_group_value_collection1.Count - 1).Height;
                        oItem.Left = uc_processor_scenario_spc_dbh_group_value_collection1.Item(uc_processor_scenario_spc_dbh_group_value_collection1.Count - 1).Left;
                        oItem.ReferenceProcessorScenarioForm = ReferenceProcessorScenarioForm;
                        oItem.Visible = true;
                        this.uc_processor_scenario_spc_dbh_group_value_collection1.Add(oItem);
                    }
                }
            }
        }
        public void saveTreeGroupings_FromProperties()
        {
            if (!ReferenceProcessorScenarioForm.m_bUsingSqlite)
            {
                ado_data_access _objAdo   = new ado_data_access();
                string          strDbFile = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                                            "\\processor\\" + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeDiamGroupsDbFile;
                _objAdo.OpenConnection(_objAdo.getMDBConnString(strDbFile, "", ""));

                if (_objAdo.m_intError == 0)
                {
                    string strScenarioId = this.ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.ScenarioId;
                    //delete the current records
                    _objAdo.m_strSQL = "DELETE FROM " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeDiamGroupsTableName +
                                       " WHERE TRIM(UCASE(scenario_id)) = '" + strScenarioId.Trim() + "'";
                    _objAdo.SqlNonQuery(_objAdo.m_OleDbConnection, _objAdo.m_strSQL);

                    // saving tree diameter groups
                    if (_objAdo.m_intError == 0)
                    {
                        string strMin;
                        string strMax;
                        string strDef;
                        string strId;
                        for (int x = 0; x <= ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeDiamGroupsItem_Collection.Count - 1; x++)
                        {
                            FIA_Biosum_Manager.ProcessorScenarioItem.TreeDiamGroupsItem oItem =
                                ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeDiamGroupsItem_Collection.Item(x);
                            strId  = oItem.DiamGroup;
                            strMin = oItem.MinDiam;
                            strMax = oItem.MaxDiam;
                            strDef = oItem.DiamClass;

                            _objAdo.m_strSQL = "INSERT INTO " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeDiamGroupsTableName + " " +
                                               "(diam_group,diam_class,min_diam,max_diam,scenario_id) VALUES " +
                                               "(" + strId + ",'" + strDef.Trim() + "'," +
                                               strMin + "," + strMax + ",'" + strScenarioId.Trim() + "');";
                            _objAdo.SqlNonQuery(_objAdo.m_OleDbConnection, _objAdo.m_strSQL);
                            if (_objAdo.m_intError != 0)
                            {
                                break;
                            }
                        }
                    }
                    // saving tree species groups
                    if (_objAdo.m_intError == 0)
                    {
                        string strCommonName;
                        int    intSpCd;
                        int    intSpcGrp;
                        string strGrpLabel;
                        int    x;

                        //delete all records from the tree species group table
                        _objAdo.m_strSQL = "DELETE FROM " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeSpeciesGroupsTableName +
                                           " WHERE TRIM(UCASE(scenario_id))='" + strScenarioId.Trim().ToUpper() + " '";
                        _objAdo.SqlNonQuery(_objAdo.m_OleDbConnection, _objAdo.m_strSQL);
                        if (_objAdo.m_intError != 0)
                        {
                            return;
                        }

                        //delete all records from the tree species group list table
                        _objAdo.m_strSQL = "DELETE FROM " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeSpeciesGroupsListTableName +
                                           " WHERE TRIM(UCASE(scenario_id))='" + strScenarioId.Trim().ToUpper() + " '";
                        _objAdo.SqlNonQuery(_objAdo.m_OleDbConnection, _objAdo.m_strSQL);

                        if (_objAdo.m_intError == 0)
                        {
                            for (x = 0; x <= this.ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oSpcGroupItem_Collection.Count - 1; x++)
                            {
                                FIA_Biosum_Manager.ProcessorScenarioItem.SpcGroupItem oItem =
                                    ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oSpcGroupItem_Collection.Item(x);
                                intSpcGrp        = oItem.SpeciesGroup;
                                strGrpLabel      = oItem.SpeciesGroupLabel;
                                _objAdo.m_strSQL = "INSERT INTO " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeSpeciesGroupsTableName + " " +
                                                   "(SPECIES_GROUP,SPECIES_LABEL,SCENARIO_ID) VALUES " +
                                                   "(" + Convert.ToString(intSpcGrp).Trim() + ",'" + strGrpLabel.Trim() + "','" + strScenarioId.Trim() + "');";
                                _objAdo.SqlNonQuery(_objAdo.m_OleDbConnection, _objAdo.m_strSQL);
                            }
                        }
                        if (_objAdo.m_intError == 0)
                        {
                            for (x = 0; x <= this.ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oSpcGroupListItem_Collection.Count - 1; x++)
                            {
                                FIA_Biosum_Manager.ProcessorScenarioItem.SpcGroupListItem oItem =
                                    ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oSpcGroupListItem_Collection.Item(x);
                                intSpcGrp     = oItem.SpeciesGroup;
                                strCommonName = oItem.CommonName;
                                strCommonName = _objAdo.FixString(strCommonName.Trim(), "'", "''");
                                intSpCd       = oItem.SpeciesCode;

                                _objAdo.m_strSQL = "INSERT INTO " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeSpeciesGroupsListTableName + " " +
                                                   "(SPECIES_GROUP,common_name,SCENARIO_ID,SPCD) VALUES " +
                                                   "(" + Convert.ToString(intSpcGrp).Trim() + ",'" + strCommonName + "','" + strScenarioId.Trim() + "', " +
                                                   intSpCd + " );";
                                _objAdo.SqlNonQuery(_objAdo.m_OleDbConnection, _objAdo.m_strSQL);
                            }
                        }
                    }

                    ReferenceProcessorScenarioForm.m_bTreeGroupsCopied = false;
                }
                _objAdo.CloseConnection(_objAdo.m_OleDbConnection);
                _objAdo = null;
            }
            else
            {
                saveTreeGroupings_FromPropertiesSqlite();
            }
        }
        public void savevalues()
        {
            val_data();
            if (this.m_intError == 0)
            {
                //string strSQL;
                int    x;
                string strMin;
                string strMax;
                string strDef;
                string strId;

                if (!ReferenceProcessorScenarioForm.m_bUsingSqlite)
                {
                    //
                    //OPEN CONNECTION TO DB FILE CONTAINING PROCESSOR SCENARIO TABLES
                    //
                    //scenario mdb connection
                    string strScenarioMDB =
                        frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                        "\\processor\\db\\scenario_processor_rule_definitions.mdb";
                    ado_data_access oAdo = new ado_data_access();
                    oAdo.OpenConnection(oAdo.getMDBConnString(strScenarioMDB, "", ""));
                    if (oAdo.m_intError != 0)
                    {
                        m_intError = m_ado.m_intError;
                        m_strError = m_ado.m_strError;
                        oAdo       = null;
                        return;
                    }

                    if (this.m_intError == 0)
                    {
                        //delete the current records
                        oAdo.m_strSQL = "DELETE FROM " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeDiamGroupsTableName +
                                        " WHERE TRIM(UCASE(scenario_id)) = '" + ScenarioId.Trim().ToUpper() + "'";
                        oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL);

                        if (oAdo.m_intError == 0)
                        {
                            for (x = 0; x <= this.lstTreeDiam.Items.Count - 1; x++)
                            {
                                strId  = this.lstTreeDiam.Items[x].Text;
                                strMin = this.lstTreeDiam.Items[x].SubItems[1].Text;
                                strMax = this.lstTreeDiam.Items[x].SubItems[2].Text;
                                strDef = this.lstTreeDiam.Items[x].SubItems[3].Text;

                                oAdo.m_strSQL = "INSERT INTO " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeDiamGroupsTableName + " " +
                                                "(diam_group,diam_class,min_diam,max_diam,scenario_id) VALUES " +
                                                "(" + strId + ",'" + strDef.Trim() + "'," +
                                                strMin + "," + strMax + ",'" + ScenarioId + "');";
                                oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL);
                                if (oAdo.m_intError != 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    oAdo.CloseConnection(oAdo.m_OleDbConnection);
                    this.m_intError = oAdo.m_intError;
                    oAdo            = null;
                }
                else
                {
                    string strScenarioDB =
                        frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                        "\\processor\\" + Tables.ProcessorScenarioRuleDefinitions.DefaultSqliteDbFile;
                    SQLite.ADO.DataMgr oDataMgr = new SQLite.ADO.DataMgr();
                    using (System.Data.SQLite.SQLiteConnection conn =
                               new System.Data.SQLite.SQLiteConnection(oDataMgr.GetConnectionString(strScenarioDB)))
                    {
                        conn.Open();
                        if (oDataMgr.m_intError != 0)
                        {
                            m_intError = oDataMgr.m_intError;
                            m_strError = oDataMgr.m_strError;
                            oDataMgr   = null;
                            return;
                        }
                        if (this.m_intError == 0)
                        {
                            //delete the current records
                            oDataMgr.m_strSQL = "DELETE FROM " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeDiamGroupsTableName +
                                                " WHERE TRIM(UPPER(scenario_id)) = '" + ScenarioId.Trim().ToUpper() + "'";
                            oDataMgr.SqlNonQuery(conn, oDataMgr.m_strSQL);

                            if (oDataMgr.m_intError == 0)
                            {
                                for (x = 0; x <= this.lstTreeDiam.Items.Count - 1; x++)
                                {
                                    strId             = this.lstTreeDiam.Items[x].Text;
                                    strMin            = this.lstTreeDiam.Items[x].SubItems[1].Text;
                                    strMax            = this.lstTreeDiam.Items[x].SubItems[2].Text;
                                    strDef            = this.lstTreeDiam.Items[x].SubItems[3].Text;
                                    oDataMgr.m_strSQL = "INSERT INTO " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeDiamGroupsTableName + " " +
                                                        "(diam_group,diam_class,min_diam,max_diam,scenario_id) VALUES " +
                                                        "(" + strId + ",'" + strDef.Trim() + "'," +
                                                        strMin + "," + strMax + ",'" + ScenarioId + "');";
                                    oDataMgr.SqlNonQuery(conn, oDataMgr.m_strSQL);
                                    if (oDataMgr.m_intError != 0)
                                    {
                                        break;
                                    }
                                }
                                this.m_intError = oDataMgr.m_intError;
                                oDataMgr        = null;
                            }
                        }
                    }
                }
                if (this.m_intError == 0)
                {
                    this.btnSave.Enabled = false;
                }
            }
        }
        private void DeleteCondsFromBiosumProject_Process()
        {
            frmMain.g_oDelegate.CurrentThreadProcessStarted = true;
            this.m_intError = 0;
            try
            {
                this.m_ado = new ado_data_access();
                this.m_dao = new dao_data_access();

                //progress bar 1: single process
                this.SetThermValue(m_frmTherm.progressBar1, "Maximum", 100);
                this.SetThermValue(m_frmTherm.progressBar1, "Minimum", 0);
                this.SetThermValue(m_frmTherm.progressBar1, "Value", 0);
                this.SetLabelValue(m_frmTherm.lblMsg, "Text", "");
                frmMain.g_oDelegate.SetControlPropertyValue((System.Windows.Forms.Form)m_frmTherm, "Visible", true);
                //progress bar 2: overall progress
                this.SetThermValue(m_frmTherm.progressBar2, "Maximum", 100);
                this.SetThermValue(m_frmTherm.progressBar2, "Minimum", 0);
                this.SetThermValue(m_frmTherm.progressBar2, "Value", 0);
                this.SetLabelValue(m_frmTherm.lblMsg2, "Text", "Overall Progress");
                frmMain.g_oDelegate.SetControlPropertyValue((System.Windows.Forms.Form)m_frmTherm, "Visible", true);


                this.m_strTempMDBFile = m_oDatasource.CreateMDBAndTableDataSourceLinks();
                //get an ado connection string for the temp mdb file
                this.m_strTempMDBFileConn = this.m_ado.getMDBConnString(this.m_strTempMDBFile, "", "");
                //create a new connection to the temp MDB file
                this.m_connTempMDBFile = new System.Data.OleDb.OleDbConnection();
                //open the connection to the temp mdb file
                this.m_ado.OpenConnection(this.m_strTempMDBFileConn, ref this.m_connTempMDBFile);

                UpdateProgressBar2(10);
                SetConditionLookupAndIDStrings();

                //Need to access plot.fvs_variants before deleting records
                string[] strVariants = m_oDatasource.getVariants();

                //ProjectRoot\gis Section
                UpdateProgressBar2(20);
                ConnectToDatabasesInPathAndExecuteDeletes(Directory.GetFiles(m_strProjDir + "\\gis\\db\\", "*.mdb"));

                //ProjectRoot\processor Section
                UpdateProgressBar2(30);
                foreach (string subfolder in Directory.GetDirectories(m_strProjDir + "\\processor\\"))
                {
                    if (Path.GetFileName(subfolder) == "db")
                    {
                        ConnectToDatabasesInPathAndExecuteDeletes(Directory.GetFiles(subfolder, "*.mdb"));
                    }
                    else
                    if (Directory.Exists(subfolder + "\\db\\"))
                    {
                        ConnectToDatabasesInPathAndExecuteDeletes(Directory.GetFiles(subfolder + "\\db\\", "*.mdb"));
                    }
                }

                //FVS Section
                UpdateProgressBar2(40);
                if (strVariants != null && strVariants.Length > 0)
                {
                    string strFvsDataDir            = m_strProjDir + "\\fvs\\data\\";
                    int    num_variants_in_fvs_data = 0;
                    foreach (string variant in strVariants)
                    {
                        if (Directory.Exists(strFvsDataDir + "\\" + variant + "\\"))
                        {
                            num_variants_in_fvs_data++;
                        }
                    }
                    int progressbar2_value = 50;
                    foreach (string variant in strVariants)
                    {
                        //Collect pathfiles of databases to delete from in FVS Data directory
                        string strVariantPath = strFvsDataDir + variant + "\\";
                        if (Directory.Exists(strVariantPath))
                        {
                            progressbar2_value += (30 / (num_variants_in_fvs_data + 1));
                            UpdateProgressBar2(progressbar2_value);
                            ConnectToDatabasesInPathAndExecuteDeletes(
                                Directory.GetFiles(strVariantPath, "*.*", SearchOption.AllDirectories)
                                .Where(s => s.ToLower().EndsWith(".mdb") || s.ToLower().EndsWith(".accdb"))
                                .ToArray(),
                                strTableExceptions: new string[] { "FVS_GroupAddFilesAndKeywords" });
                        }
                    }
                }

                //PREPOST Databases
                UpdateProgressBar2(70);
                ConnectToDatabasesInPathAndExecuteDeletes(
                    Directory.GetFiles(m_strProjDir + "\\fvs\\db\\", "PREPOST*.accdb"),
                    strTableExceptions: new string[] { "FVS_TREE" });

                //OPTIMIZER weighted variables
                UpdateProgressBar2(80);
                ConnectToDatabasesInPathAndExecuteDeletes(
                    Directory.GetFiles(m_strProjDir + "\\optimizer\\db\\", "prepost*.accdb"));
                UpdateProgressBar2(100);

                //ProjectRoot\db Section
                UpdateProgressBar2(90);
                ConnectToDatabasesInPathAndExecuteDeletes(Directory
                                                          .GetFiles(m_strProjDir + "\\db\\", "*.*", SearchOption.AllDirectories)
                                                          .Where(s => s.ToLower().EndsWith(".mdb") || s.ToLower().EndsWith(".accdb")).ToArray());

                //Results
                if (Checked(chkCreateLog))
                {
                    CreateLogFile(frmMain.g_oFrmMain.getProjectDirectory() + "\\db\\biosum_deleted_records" +
                                  String.Format("{0:yyyyMMddhhmm}", DateTime.Now) + ".txt");
                }

                MessageBox.Show(
                    String.Format("Successfully deleted data associated with {0} Conditions!",
                                  ((HashSet <string>)m_dictIdentityColumnsToValues["biosum_cond_id"]).Count),
                    "Delete Conditions Results");

                //Cleanup section, assuming no exceptions were thrown
                this.m_connTempMDBFile.Close();
                while (m_connTempMDBFile.State != System.Data.ConnectionState.Closed)
                {
                    System.Threading.Thread.Sleep(1000);
                }
                if (m_ado != null)
                {
                    if (m_ado.m_DataSet != null)
                    {
                        this.m_ado.m_DataSet.Clear();
                        this.m_ado.m_DataSet.Dispose();
                    }
                    this.m_ado = null;
                }
                if (m_dao != null)
                {
                    this.m_dao.m_DaoWorkspace.Close();
                    this.m_dao.m_DaoWorkspace = null;
                    this.m_dao = null;
                }

                frmMain.g_oDelegate.SetControlPropertyValue((System.Windows.Forms.Form)ReferenceFormDialog, "Visible",
                                                            true);
                frmMain.g_oDelegate.SetControlPropertyValue((System.Windows.Forms.Form)ReferenceFormDialog, "Enabled",
                                                            true);

                DeleteCondsFromBiosumProject_Finish();
            }
            catch (System.Threading.ThreadInterruptedException err)
            {
                MessageBox.Show("Threading Interruption Error " + err.Message.ToString());
            }
            catch (System.Threading.ThreadAbortException err)
            {
                if (this.m_connTempMDBFile != null)
                {
                    if (m_connTempMDBFile.State != System.Data.ConnectionState.Closed)
                    {
                        m_ado.CloseConnection(m_connTempMDBFile);
                    }
                    m_connTempMDBFile = null;
                }
                if (m_ado != null)
                {
                    if (m_ado.m_DataSet != null)
                    {
                        this.m_ado.m_DataSet.Clear();
                        this.m_ado.m_DataSet.Dispose();
                    }
                    this.m_ado = null;
                }
                this.ThreadCleanUp();
                this.CleanupThread();
            }
            catch (Exception err)
            {
                MessageBox.Show("!!Error!! \n" +
                                "Module - uc_delete_conditions:DeleteCondsFromBiosumProject_Process  \n" +
                                "Err Msg - " + err.Message.ToString().Trim(),
                                "FVS Biosum", System.Windows.Forms.MessageBoxButtons.OK,
                                System.Windows.Forms.MessageBoxIcon.Exclamation);
                this.m_intError = -1;
            }
            finally
            {
            }

            if (this.m_connTempMDBFile != null)
            {
                if (m_connTempMDBFile.State != System.Data.ConnectionState.Closed)
                {
                    m_ado.CloseConnection(m_connTempMDBFile);
                }
                m_connTempMDBFile = null;
            }
            if (m_ado != null)
            {
                if (m_ado.m_DataSet != null)
                {
                    this.m_ado.m_DataSet.Clear();
                    this.m_ado.m_DataSet.Dispose();
                }
                this.m_ado = null;
            }
            frmMain.g_oDelegate.SetControlPropertyValue((System.Windows.Forms.Form)ReferenceFormDialog, "Enabled",
                                                        true);
            if (this.m_frmTherm != null)
            {
                frmMain.g_oDelegate.SetControlPropertyValue((System.Windows.Forms.Form)m_frmTherm, "Visible", false);
            }


            DeleteCondsFromBiosumProject_Finish();

            CleanupThread();

            frmMain.g_oDelegate.m_oEventThreadStopped.Set();
            this.Invoke(frmMain.g_oDelegate.m_oDelegateThreadFinished);
        }
        private void GetExistingColumns()
        {
            int    x;
            string strCol        = "";
            string strFieldsList = "";

            string[] strProcessorColumnsArray = null;

            System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection();
            oConn.ConnectionString = m_oAdo.getMDBConnString(frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\processor\\db\\scenario_processor_rule_definitions.mdb", "", "");
            m_oAdo.OpenConnection(oConn.ConnectionString, ref oConn);
            string strProcessorColumnsList = m_oAdo.CreateCommaDelimitedList(oConn, "SELECT DISTINCT ColumnName FROM scenario_harvest_cost_columns", ",");

            m_oAdo.CloseConnection(oConn);

            if (strProcessorColumnsList.Trim().Length > 0)
            {
                strFieldsList            = strProcessorColumnsList;
                strProcessorColumnsArray = frmMain.g_oUtils.ConvertListToArray(strProcessorColumnsList, ",");
            }



            string strTable = m_oQueries.m_oDataSource.getValidDataSourceTableName("TREATMENT PRESCRIPTIONS HARVEST COST COLUMNS").Trim();

            //string strTable = "scenario_harvest_cost_columns";
            m_oAdo.m_strSQL = "SELECT DISTINCT ColumnName FROM " + strTable;
            m_oAdo.SqlQueryReader(m_oAdo.m_OleDbConnection, m_oAdo.m_strSQL);
            if (m_oAdo.m_OleDbDataReader.HasRows)
            {
                while (m_oAdo.m_OleDbDataReader.Read())
                {
                    if (m_oAdo.m_OleDbDataReader["ColumnName"] != System.DBNull.Value &&
                        Convert.ToString(m_oAdo.m_OleDbDataReader["ColumnName"]).Trim().Length > 0)
                    {
                        strCol = Convert.ToString(m_oAdo.m_OleDbDataReader["ColumnName"]).Trim().ToUpper();
                        if (strProcessorColumnsArray != null)
                        {
                            for (x = 0; x <= strProcessorColumnsArray.Length - 1; x++)
                            {
                                if (strProcessorColumnsArray[x] != null)
                                {
                                    if (strProcessorColumnsArray[x].Trim().ToUpper() ==
                                        strCol)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (x > strProcessorColumnsArray.Length - 1)
                            {
                                strFieldsList = strFieldsList + Convert.ToString(m_oAdo.m_OleDbDataReader["ColumnName"]).Trim() + ",";
                            }
                        }
                        else
                        {
                            strFieldsList = strFieldsList + Convert.ToString(m_oAdo.m_OleDbDataReader["ColumnName"]).Trim() + ",";
                        }
                    }
                }
            }
            m_oAdo.m_OleDbDataReader.Close();

            if (strFieldsList.Trim().Length > 0)
            {
                strFieldsList = strFieldsList.Substring(0, strFieldsList.Length - 1);

                string[] strFieldsArray = frmMain.g_oUtils.ConvertListToArray(strFieldsList, ",");
            }

            m_strHarvestTableColumnNameList = strFieldsList;
        }
        public void loadvalues()
        {
            int    x, y;
            string strField;

            if (m_oAdo != null && m_oAdo.m_OleDbConnection != null)
            {
                if (m_oAdo.m_OleDbConnection.State == System.Data.ConnectionState.Open)
                {
                    m_oAdo.CloseConnection(m_oAdo.m_OleDbConnection);
                }
            }

            //
            //SCENARIO MDB
            //
            string strScenarioMDB =
                frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                "\\processor\\db\\scenario_processor_rule_definitions.mdb";

            //
            //SCENARIO ID
            //
            ScenarioId = this.ReferenceProcessorScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower();
            //
            //CREATE LINK IN TEMP MDB TO SCENARIO COST REVENUE ESCALATORS TABLE
            //
            dao_data_access oDao = new dao_data_access();

            //link to tree species groups table
            oDao.CreateTableLink(this.ReferenceProcessorScenarioForm.LoadedQueries.m_strTempDbFile,
                                 "scenario_cost_revenue_escalators",
                                 strScenarioMDB, "scenario_cost_revenue_escalators", true);
            oDao.m_DaoWorkspace.Close();
            oDao = null;
            //
            //OPEN CONNECTION TO TEMP DB FILE
            //
            m_oAdo = new ado_data_access();
            m_oAdo.OpenConnection(m_oAdo.getMDBConnString(this.ReferenceProcessorScenarioForm.LoadedQueries.m_strTempDbFile, "", ""));
            if (m_oAdo.m_intError == 0)
            {
                ReferenceProcessorScenarioForm.m_oProcessorScenarioTools.LoadEscalators(
                    m_oAdo, m_oAdo.m_OleDbConnection, ReferenceProcessorScenarioForm.LoadedQueries, ReferenceProcessorScenarioForm.m_oProcessorScenarioItem);
                ProcessorScenarioItem.Escalators oEscalators = ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oEscalators;
                //
                //UPDATE CYCLE ESCALATOR TEXT BOXES
                //
                //operating costs cycle 2,3,4
                //cycle2
                if (oEscalators.OperatingCostsCycle2.Trim().Length > 0)
                {
                    uc_processor_scenario_escalators_value1.Cycle1 =
                        oEscalators.OperatingCostsCycle2.Trim();
                }
                else
                {
                    uc_processor_scenario_escalators_value1.Cycle1 = "1.00";
                }
                //cycle3
                if (oEscalators.OperatingCostsCycle3.Trim().Length > 0)
                {
                    uc_processor_scenario_escalators_value1.Cycle2 =
                        oEscalators.OperatingCostsCycle3.Trim();
                }
                else
                {
                    uc_processor_scenario_escalators_value1.Cycle2 = "1.00";
                }
                if (oEscalators.OperatingCostsCycle4.Trim().Length > 0)
                {
                    uc_processor_scenario_escalators_value1.Cycle3 =
                        oEscalators.OperatingCostsCycle4.Trim();
                }
                else
                {
                    uc_processor_scenario_escalators_value1.Cycle3 = "1.00";
                }
                //merch wood revenue cycle 2,3,4
                //cycle2
                if (oEscalators.MerchWoodRevenueCycle2.Trim().Length > 0)
                {
                    uc_processor_scenario_escalators_value2.Cycle1 =
                        oEscalators.MerchWoodRevenueCycle2.Trim();
                }
                else
                {
                    uc_processor_scenario_escalators_value2.Cycle1 = "1.00";
                }
                //cycle3
                if (oEscalators.MerchWoodRevenueCycle3.Trim().Length > 0)
                {
                    uc_processor_scenario_escalators_value2.Cycle2 =
                        oEscalators.MerchWoodRevenueCycle3.Trim();
                }
                else
                {
                    uc_processor_scenario_escalators_value2.Cycle2 = "1.00";
                }
                if (oEscalators.MerchWoodRevenueCycle4.Trim().Length > 0)
                {
                    uc_processor_scenario_escalators_value2.Cycle3 =
                        oEscalators.MerchWoodRevenueCycle4.Trim();
                }
                else
                {
                    uc_processor_scenario_escalators_value2.Cycle3 = "1.00";
                }
                //Energy wood revenue cycle 2,3,4
                //cycle2
                if (oEscalators.EnergyWoodRevenueCycle2.Trim().Length > 0)
                {
                    uc_processor_scenario_escalators_value3.Cycle1 =
                        oEscalators.EnergyWoodRevenueCycle2.Trim();
                }
                else
                {
                    uc_processor_scenario_escalators_value3.Cycle1 = "1.00";
                }
                //cycle3
                if (oEscalators.EnergyWoodRevenueCycle3.Trim().Length > 0)
                {
                    uc_processor_scenario_escalators_value3.Cycle2 =
                        oEscalators.EnergyWoodRevenueCycle3.Trim();
                }
                else
                {
                    uc_processor_scenario_escalators_value3.Cycle2 = "1.00";
                }
                if (oEscalators.EnergyWoodRevenueCycle4.Trim().Length > 0)
                {
                    uc_processor_scenario_escalators_value3.Cycle3 =
                        oEscalators.EnergyWoodRevenueCycle4.Trim();
                }
                else
                {
                    uc_processor_scenario_escalators_value3.Cycle3 = "1.00";
                }
            }
            this.uc_processor_scenario_escalators_value1.ReferenceProcessorScenarioForm = ReferenceProcessorScenarioForm;
            this.uc_processor_scenario_escalators_value2.ReferenceProcessorScenarioForm = ReferenceProcessorScenarioForm;
            this.uc_processor_scenario_escalators_value3.ReferenceProcessorScenarioForm = ReferenceProcessorScenarioForm;
            lblCycleLength.Text = Convert.ToString(ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oEscalators.CycleLength);
        }