Пример #1
0
        public void UpdateDescription()
        {
            string strDesc = "";

            FIA_Biosum_Manager.ado_data_access oAdo = new ado_data_access();
            string        strScenarioDBDir          = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" + ScenarioType + "\\db";
            string        strScenarioFile           = "scenario_" + ScenarioType + "_rule_definitions.mdb";
            StringBuilder strScenarioFullPath       = new StringBuilder(strScenarioDBDir);

            strScenarioFullPath.Append("\\");
            strScenarioFullPath.Append(strScenarioFile);
            string strScenarioConn = oAdo.getMDBConnString(strScenarioFullPath.ToString(), "admin", "");

            oAdo.OpenConnection(strScenarioConn);
            if (this.txtDescription.Text.Trim().Length > 0)
            {
                strDesc = oAdo.FixString(this.txtDescription.Text.Trim(), "'", "''");
            }
            oAdo.m_strSQL = "UPDATE scenario SET description='" + strDesc.Trim() + "' WHERE TRIM(scenario_id)='" + this.txtScenarioId.Text.Trim() + "'";
            oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL);
            oAdo.m_OleDbConnection.Close();
            while (oAdo.m_OleDbConnection.State != System.Data.ConnectionState.Closed)
            {
                oAdo.m_OleDbConnection.Close();
                System.Threading.Thread.Sleep(1000);
            }
            oAdo = null;
        }
Пример #2
0
        public void SaveScenarioNotes()
        {
            ado_data_access p_ado = new ado_data_access();

            System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection();
            string        strProjDir     = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim();
            string        strScenarioDir = strProjDir + "\\" + ScenarioType + "\\db";
            string        strFile        = "scenario_" + ScenarioType + "_rule_definitions.mdb"; //((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectFile;
            StringBuilder strFullPath    = new StringBuilder(strScenarioDir);

            strFullPath.Append("\\");
            strFullPath.Append(strFile);
            string strNotes = this.txtNotes.Text;
            string strSQL   = "";

            strNotes = p_ado.FixString(strNotes, "'", "''");
            string strConn = p_ado.getMDBConnString(strFullPath.ToString(), "admin", "");

            //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFullPath.ToString() + ";User Id=admin;Password=;";
            if (ScenarioType.Trim().ToUpper() == "OPTIMIZER")
            {
                strSQL = "UPDATE scenario SET notes = '" +
                         strNotes +
                         "' WHERE trim(lcase(scenario_id)) = '" + ((frmOptimizerScenario)this.ParentForm).uc_scenario1.txtScenarioId.Text.Trim().ToLower() + "';";
            }
            else
            {
                strSQL = "UPDATE scenario SET notes = '" +
                         strNotes +
                         "' WHERE trim(lcase(scenario_id)) = '" + this.ReferenceProcessorScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower() + "';";
            }
            p_ado.SqlNonQuery(strConn, strSQL);
            p_ado = null;
        }
Пример #3
0
        private void saveprivate()
        {
            ado_data_access p_ado   = new ado_data_access();
            string          strMDB  = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.txtPersonal.Text.Trim() + "\\personal_project_links_and_notes.mdb";
            string          strConn = p_ado.getMDBConnString(strMDB, "admin", "");
            //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strMDB + ";User Id=admin;Password=;";
            string strSQL = "";

            p_ado.OpenConnection(strConn);
            if (p_ado.m_intError == 0)
            {
                try
                {
                    string strNotes = this.txtNotesPersonal.Text;
                    strNotes = p_ado.FixString(strNotes, "'", "''");
                    if ((int)p_ado.getRecordCount(p_ado.m_OleDbConnection, "SELECT COUNT(*) FROM NOTES", "NOTES") > 0)
                    {
                        strSQL = "UPDATE NOTES SET NOTES = '" + strNotes + "'";
                        p_ado.SqlNonQuery(p_ado.m_OleDbConnection, strSQL);
                    }
                    else
                    {
                        strSQL = "INSERT INTO NOTES (NOTES) VALUES ('" + strNotes + "')";
                        p_ado.SqlNonQuery(p_ado.m_OleDbConnection, strSQL);
                    }
                }
                catch
                {
                }
            }
            p_ado = null;
        }
        public void SaveScenarioNotes()
        {
            ado_data_access p_ado = null;

            SQLite.ADO.DataMgr oDataMgr       = null;
            string             strNotes       = this.txtNotes.Text;
            string             strProjDir     = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim();
            string             strScenarioDir = strProjDir + "\\" + ScenarioType + "\\db";

            if ((ReferenceProcessorScenarioForm != null && !ReferenceProcessorScenarioForm.m_bUsingSqlite) ||
                ScenarioType.Trim().ToUpper() == "OPTIMIZER")
            {
                p_ado    = new ado_data_access();
                strNotes = p_ado.FixString(strNotes, "'", "''");
                string strSQL = "";
                if (ScenarioType.Trim().ToUpper() == "OPTIMIZER")
                {
                    strSQL = "UPDATE scenario SET notes = '" +
                             strNotes +
                             "' WHERE trim(lcase(scenario_id)) = '" + ((frmOptimizerScenario)this.ParentForm).uc_scenario1.txtScenarioId.Text.Trim().ToLower() + "';";
                }
                else
                {
                    strSQL = "UPDATE scenario SET notes = '" +
                             strNotes +
                             "' WHERE trim(lcase(scenario_id)) = '" + this.ReferenceProcessorScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower() + "';";
                }
                System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection();
                string        strFile     = "scenario_" + ScenarioType + "_rule_definitions.mdb";
                StringBuilder strFullPath = new StringBuilder(strScenarioDir);
                strFullPath.Append("\\");
                strFullPath.Append(strFile);
                string strConn = p_ado.getMDBConnString(strFullPath.ToString(), "admin", "");
                p_ado.SqlNonQuery(strConn, strSQL);
                p_ado = null;
            }
            else
            {
                oDataMgr = new SQLite.ADO.DataMgr();
                strNotes = oDataMgr.FixString(strNotes, "'", "''");
                //@ToDo: Only support Processor at this time
                string strSQL = "UPDATE scenario SET notes = '" +
                                strNotes +
                                "' WHERE trim(lower(scenario_id)) = '" + this.ReferenceProcessorScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower() + "';";
                string        strFile     = "scenario_" + ScenarioType + "_rule_definitions.db";
                StringBuilder strFullPath = new StringBuilder(strScenarioDir);
                strFullPath.Append("\\");
                strFullPath.Append(strFile);
                string strConn = oDataMgr.GetConnectionString(strFullPath.ToString());
                using (System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection(strConn))
                {
                    conn.Open();
                    oDataMgr.SqlNonQuery(conn, strSQL);
                }
                oDataMgr = null;
            }
        }
Пример #5
0
        public void SaveScenarioProperties()
        {
            bool   bOptimizer;
            string strDesc = "";
            string strSQL  = "";

            System.Text.StringBuilder strFullPath;
            m_intError = 0;
            //validate the input
            //
            //Optimization id
            //
            if (this.txtScenarioId.Text.Length == 0)
            {
                MessageBox.Show("Enter A Unique Optimization scenario Id");
                this.txtScenarioId.Focus();
                m_intError = -1;
                return;
            }
            //
            //check for duplicate scenario id
            //
            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";

            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.SqlQueryReader(strConn, "select scenario_id from scenario");
            if (oAdo.m_OleDbDataReader.HasRows)
            {
                while (oAdo.m_OleDbDataReader.Read())
                {
                    if (oAdo.m_OleDbDataReader["scenario_id"] != System.DBNull.Value)
                    {
                        if (this.txtScenarioId.Text.Trim().ToUpper() ==
                            Convert.ToString(oAdo.m_OleDbDataReader["scenario_id"]).Trim().ToUpper())
                        {
                            this.m_intError = -1;
                            MessageBox.Show("Cannot have a duplicate Optimization scenario id");
                            oAdo.m_OleDbDataReader.Close();
                            oAdo.m_OleDbDataReader = null;
                            oAdo = null;
                            this.txtScenarioId.Focus();
                            return;
                        }
                    }
                }
            }
            else
            {
            }
            oAdo.m_OleDbDataReader.Close();
            oAdo.m_OleDbDataReader = null;
            //
            //create the scenario path if it does not exist and
            //copy the scenario_results.mdb to it
            //
            try
            {
                if (!System.IO.Directory.Exists(this.txtScenarioPath.Text))
                {
                    System.IO.Directory.CreateDirectory(this.txtScenarioPath.Text);
                    System.IO.Directory.CreateDirectory(this.txtScenarioPath.Text.ToString() + "\\db");

                    //copy default processor scenario_results database to the new project directory
                    if (this.ScenarioType == "processor")
                    {
                        dao_data_access oDao        = new dao_data_access();
                        string          strDestFile = this.txtScenarioPath.Text + "\\" + Tables.ProcessorScenarioRun.DefaultHarvestCostsTableDbFile;
                        oDao.CreateMDB(strDestFile);
                        oDao.m_DaoWorkspace.Close();
                        oDao = null;
                        string strScenarioResultsConn = oAdo.getMDBConnString(strDestFile, "", "");
                        System.Data.OleDb.OleDbConnection OleDbScenarioResultsConn = new System.Data.OleDb.OleDbConnection();
                        oAdo.OpenConnection(strScenarioResultsConn, ref OleDbScenarioResultsConn);
                        frmMain.g_oTables.m_oProcessor.CreateHarvestCostsTable(
                            oAdo,
                            OleDbScenarioResultsConn,
                            Tables.ProcessorScenarioRun.DefaultHarvestCostsTableName);

                        frmMain.g_oTables.m_oProcessor.CreateTreeVolValSpeciesDiamGroupsTable(
                            oAdo,
                            OleDbScenarioResultsConn,
                            Tables.ProcessorScenarioRun.DefaultTreeVolValSpeciesDiamGroupsTableName);

                        OleDbScenarioResultsConn.Close();
                        OleDbScenarioResultsConn.Dispose();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error Creating Folder");
                m_intError = -1;
                return;
            }
            //
            //copy the project data source values to the scenario data source
            //
            string        strProjDBDir    = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\db";
            string        strProjFile     = "project.mdb";
            StringBuilder strProjFullPath = new StringBuilder(strProjDBDir);

            strProjFullPath.Append("\\");
            strProjFullPath.Append(strProjFile);
            string strProjConn = oAdo.getMDBConnString(strProjFullPath.ToString(), "admin", "");

            System.Data.OleDb.OleDbConnection p_OleDbProjConn = new System.Data.OleDb.OleDbConnection();
            oAdo.OpenConnection(strProjConn, ref p_OleDbProjConn);

            string        strScenarioDBDir    = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" + ScenarioType + "\\db";
            string        strScenarioFile     = "scenario_" + ScenarioType + "_rule_definitions.mdb";
            StringBuilder strScenarioFullPath = new StringBuilder(strScenarioDBDir);

            strScenarioFullPath.Append("\\");
            strScenarioFullPath.Append(strScenarioFile);
            string strScenarioConn = oAdo.getMDBConnString(strScenarioFullPath.ToString(), "admin", "");

            oAdo.OpenConnection(strScenarioConn);


            if (oAdo.m_intError == 0)
            {
                if (this.txtDescription.Text.Trim().Length > 0)
                {
                    strDesc = oAdo.FixString(this.txtDescription.Text.Trim(), "'", "''");
                }
                strSQL = "INSERT INTO scenario (scenario_id,description,Path,File) VALUES " + "('" + this.txtScenarioId.Text.Trim() + "'," +
                         "'" + strDesc + "'," +
                         "'" + this.txtScenarioPath.Text.Trim() + "','scenario_" + ScenarioType + "_rule_definitions.mdb');";
                oAdo.SqlNonQuery(oAdo.m_OleDbConnection, strSQL);

                oAdo.SqlQueryReader(p_OleDbProjConn, "select * from datasource");
                if (oAdo.m_intError == 0)
                {
                    try
                    {
                        while (oAdo.m_OleDbDataReader.Read())
                        {
                            bOptimizer = false;
                            switch (oAdo.m_OleDbDataReader["table_type"].ToString().Trim().ToUpper())
                            {
                            case "PLOT":
                                bOptimizer = true;
                                break;

                            case "CONDITION":
                                bOptimizer = true;
                                break;

                            //case "FIRE AND FUEL EFFECTS":
                            //	bCore = true;
                            //	break;
                            //case "HARVEST COSTS":
                            //	bCore = true;
                            //	break;
                            case "ADDITIONAL HARVEST COSTS":
                                bOptimizer = true;
                                break;

                            case "TREATMENT PRESCRIPTIONS":
                                bOptimizer = true;
                                break;

                            //case "TREE VOLUMES AND VALUES BY SPECIES AND DIAMETER GROUPS":
                            //	bCore = true;
                            //	break;
                            case "TRAVEL TIMES":
                                bOptimizer = true;
                                break;

                            case "PROCESSING SITES":
                                bOptimizer = true;
                                break;

                            //case "TREE SPECIES AND DIAMETER GROUPS DOLLAR VALUES":
                            //	bCore = true;
                            //	break;
                            case "PLOT AND CONDITION RECORD AUDIT":
                                if (ScenarioType == "optimizer")
                                {
                                    bOptimizer = true;
                                }
                                break;

                            case "PLOT, CONDITION AND TREATMENT RECORD AUDIT":
                                if (ScenarioType == "optimizer")
                                {
                                    bOptimizer = true;
                                }
                                break;

                            case "TREE":
                                if (ScenarioType == "processor")
                                {
                                    bOptimizer = true;
                                }
                                break;

                            case "HARVEST METHODS":
                                if (ScenarioType == "processor")
                                {
                                    bOptimizer = true;
                                }
                                break;

                            case "TREATMENT PACKAGES":
                                bOptimizer = true;
                                break;

                            //case "FVS TREE LIST FOR PROCESSOR":
                            //	if (ScenarioType=="processor") bCore=true;
                            //	break;
                            case "TREE SPECIES":
                                if (ScenarioType == "processor")
                                {
                                    bOptimizer = true;
                                }
                                break;

                            case "TREATMENT PRESCRIPTIONS HARVEST COST COLUMNS":
                                if (ScenarioType == "processor")
                                {
                                    bOptimizer = true;
                                }
                                break;

                            case "FIA TREE SPECIES REFERENCE":
                                if (ScenarioType == "processor")
                                {
                                    bOptimizer = true;
                                }
                                break;

                            default:
                                break;
                            }
                            if (bOptimizer == true)
                            {
                                strSQL = "INSERT INTO scenario_datasource (scenario_id,table_type,Path,file,table_name) VALUES " + "('" + this.txtScenarioId.Text.Trim() + "'," +
                                         "'" + oAdo.m_OleDbDataReader["table_type"].ToString().Trim() + "'," +
                                         "'" + oAdo.m_OleDbDataReader["path"].ToString().Trim() + "'," +
                                         "'" + oAdo.m_OleDbDataReader["file"].ToString().Trim() + "'," +
                                         "'" + oAdo.m_OleDbDataReader["table_name"].ToString().Trim() + "');";
                                oAdo.SqlNonQuery(oAdo.m_OleDbConnection, strSQL);
                            }
                        }
                    }
                    catch (Exception caught)
                    {
                        m_intError = -1;
                        m_strError = caught.Message;
                        MessageBox.Show(strError);
                    }
                    oAdo.m_OleDbDataReader.Close();
                    oAdo.m_OleDbDataReader = null;
                    oAdo.m_OleDbCommand    = null;
                    p_OleDbProjConn.Close();
                    p_OleDbProjConn = null;
                }
                if (ScenarioType.Trim().ToUpper() == "OPTIMIZER")
                {
                    string strTemp = oAdo.FixString("SELECT @@PlotTable@@.* FROM @@PlotTable@@ WHERE @@PlotTable@@.plot_accessible_yn='Y'", "'", "''");
                    strSQL = "INSERT INTO scenario_plot_filter (scenario_id,sql_command,current_yn) VALUES " + "('" + this.txtScenarioId.Text.Trim() + "'," +
                             "'" + strTemp + "'," +
                             "'Y');";
                    oAdo.SqlNonQuery(oAdo.m_OleDbConnection, strSQL);

                    strTemp = oAdo.FixString("SELECT @@CondTable@@.* FROM @@CondTable@@", "'", "''");
                    strSQL  = "INSERT INTO scenario_cond_filter (scenario_id,sql_command,current_yn) VALUES " + "('" + this.txtScenarioId.Text.Trim() + "'," +
                              "'" + strTemp + "'," +
                              "'Y');";
                    oAdo.SqlNonQuery(oAdo.m_OleDbConnection, strSQL);
                }
            }
            oAdo.m_OleDbConnection.Close();
            oAdo.m_OleDbConnection = null;
            oAdo = null;
        }
Пример #6
0
        public void SaveScenarioProperties()
        {
            string strTemp1;
            string strTemp2;
            string strSQL  = "";
            bool   bCore   = false;
            string strDesc = "";

            if (this.lstScenario.Visible == true)             //new scenario
            {
                //validate the input
                //Optimization id
                if (this.txtScenarioId.Text.Length == 0)
                {
                    MessageBox.Show("Enter A Unique Optimization scenario Id");
                    this.txtScenarioId.Focus();
                    return;
                }

                //check for duplicate scenario id
                if (this.lstScenario.Items.Count > 0)
                {
                    strTemp2 = this.txtScenarioId.Text.Trim();
                    for (int x = 0; x <= this.lstScenario.Items.Count - 1; x++)
                    {
                        strTemp1 = this.lstScenario.Items[x].ToString().Trim();
                        if (strTemp1.ToUpper() == strTemp2.ToUpper())
                        {
                            MessageBox.Show("Cannot have a duplicate Optimization scenario id");
                            this.txtScenarioId.Focus();
                            return;
                        }
                    }
                }

                //make sure user entered scenario path
                if (this.txtScenarioPath.Text.Length > 0)
                {
                    //create the scenario path if it does not exist and
                    //copy the scenario_results.mdb to it
                    try
                    {
                        if (!System.IO.Directory.Exists(this.txtScenarioPath.Text))
                        {
                            System.IO.Directory.CreateDirectory(this.txtScenarioPath.Text);
                            System.IO.Directory.CreateDirectory(this.txtScenarioPath.Text.ToString() + "\\db");
                            //copy default scenario_results database to the new project directory
                            string strSourceFile = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectDirectory + "\\" + ScenarioType + "\\db\\scenario_results.mdb";
                            string strDestFile   = this.txtScenarioPath.Text + "\\db\\scenario_results.mdb";
                            System.IO.File.Copy(strSourceFile, strDestFile, true);
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Error Creating Folder");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Enter A Directory Location To Save Optimization scenario Files");
                    this.txtScenarioPath.Focus();
                    return;
                }



                //copy the project data source values to the scenario data source
                ado_data_access p_ado           = new ado_data_access();
                string          strProjDBDir    = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectDirectory + "\\db";
                string          strProjFile     = "project.mdb";
                StringBuilder   strProjFullPath = new StringBuilder(strProjDBDir);
                strProjFullPath.Append("\\");
                strProjFullPath.Append(strProjFile);
                string strProjConn = p_ado.getMDBConnString(strProjFullPath.ToString(), "admin", "");
                System.Data.OleDb.OleDbConnection p_OleDbProjConn = new System.Data.OleDb.OleDbConnection();
                p_ado.OpenConnection(strProjConn, ref p_OleDbProjConn);


                string        strScenarioDBDir    = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectDirectory + "\\" + ScenarioType + "\\db";
                string        strScenarioFile     = "scenario_" + ScenarioType + "_rule_definitions.mdb";
                StringBuilder strScenarioFullPath = new StringBuilder(strScenarioDBDir);
                strScenarioFullPath.Append("\\");
                strScenarioFullPath.Append(strScenarioFile);
                string strScenarioConn = p_ado.getMDBConnString(strScenarioFullPath.ToString(), "admin", "");
                p_ado.OpenConnection(strScenarioConn);


                if (p_ado.m_intError == 0)
                {
                    if (this.txtDescription.Text.Trim().Length > 0)
                    {
                        strDesc = p_ado.FixString(this.txtDescription.Text.Trim(), "'", "''");
                    }
                    strSQL = "INSERT INTO scenario (scenario_id,description,Path,File) VALUES " + "('" + this.txtScenarioId.Text.Trim() + "'," +
                             "'" + strDesc + "'," +
                             "'" + this.txtScenarioPath.Text.Trim() + "','scenario_" + ScenarioType + "_rule_definitions.mdb');";
                    //"'" + this.txtScenarioMDBFile.Text.Trim() + "');";
                    p_ado.SqlNonQuery(p_ado.m_OleDbConnection, strSQL);

                    p_ado.SqlQueryReader(p_OleDbProjConn, "select * from datasource");
                    if (p_ado.m_intError == 0)
                    {
                        try
                        {
                            while (p_ado.m_OleDbDataReader.Read())
                            {
                                bCore = false;
                                switch (p_ado.m_OleDbDataReader["table_type"].ToString().Trim().ToUpper())
                                {
                                case "PLOT":
                                    bCore = true;
                                    break;

                                case "CONDITION":
                                    bCore = true;
                                    break;

                                //case "FIRE AND FUEL EFFECTS":
                                //	bCore = true;
                                //	break;
                                case "HARVEST COSTS":
                                    bCore = true;
                                    break;

                                case "TREATMENT PRESCRIPTIONS":
                                    bCore = true;
                                    break;

                                case "TREE VOLUMES AND VALUES BY SPECIES AND DIAMETER GROUPS":
                                    bCore = true;
                                    break;

                                case "TRAVEL TIMES":
                                    bCore = true;
                                    break;

                                case "PROCESSING SITES":
                                    bCore = true;
                                    break;

                                case "TREE SPECIES AND DIAMETER GROUPS DOLLAR VALUES":
                                    bCore = true;
                                    break;

                                case "PLOT AND CONDITION RECORD AUDIT":
                                    bCore = true;
                                    break;

                                case "PLOT, CONDITION AND TREATMENT RECORD AUDIT":
                                    bCore = true;
                                    break;

                                default:
                                    break;
                                }
                                if (bCore == true)
                                {
                                    strSQL = "INSERT INTO scenario_datasource (scenario_id,table_type,Path,file,table_name) VALUES " + "('" + this.txtScenarioId.Text.Trim() + "'," +
                                             "'" + p_ado.m_OleDbDataReader["table_type"].ToString().Trim() + "'," +
                                             "'" + p_ado.m_OleDbDataReader["path"].ToString().Trim() + "'," +
                                             "'" + p_ado.m_OleDbDataReader["file"].ToString().Trim() + "'," +
                                             "'" + p_ado.m_OleDbDataReader["table_name"].ToString().Trim() + "');";
                                    p_ado.SqlNonQuery(p_ado.m_OleDbConnection, strSQL);
                                }
                            }
                        }
                        catch (Exception caught)
                        {
                            intError = -1;
                            strError = caught.Message;
                            MessageBox.Show(strError);
                        }
                        if (p_ado.m_intError == 0)
                        {
                            if (ScenarioType.Trim().ToUpper() == "OPTIMIZER")
                            {
                                ((frmOptimizerScenario)ParentForm).uc_datasource1.strScenarioId        = this.txtScenarioId.Text.Trim();
                                ((frmOptimizerScenario)ParentForm).uc_datasource1.strDataSourceMDBFile = ((frmMain)ParentForm.ParentForm).frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" + ScenarioType + "\\db\\scenario_" + ScenarioType + "_rule_definitions.mdb";
                                ((frmOptimizerScenario)ParentForm).uc_datasource1.strDataSourceTable   = "scenario_datasource";
                                ((frmOptimizerScenario)ParentForm).uc_datasource1.strProjectDirectory  = ((frmMain)ParentForm.ParentForm).frmProject.uc_project1.txtRootDirectory.Text.Trim();
                            }
                            else
                            {
                                this.ReferenceProcessorScenarioForm.uc_datasource1.strScenarioId        = this.txtScenarioId.Text.Trim();
                                this.ReferenceProcessorScenarioForm.uc_datasource1.strDataSourceMDBFile = ((frmMain)ParentForm.ParentForm).frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" + ScenarioType + "\\db\\scenario_" + ScenarioType + "_rule_definitions.mdb";
                                this.ReferenceProcessorScenarioForm.uc_datasource1.strDataSourceTable   = "scenario_datasource";
                                this.ReferenceProcessorScenarioForm.uc_datasource1.strProjectDirectory  = ((frmMain)ParentForm.ParentForm).frmProject.uc_project1.txtRootDirectory.Text.Trim();
                            }
                        }
                        p_ado.m_OleDbDataReader.Close();
                        p_ado.m_OleDbDataReader = null;
                        p_ado.m_OleDbCommand    = null;
                        p_OleDbProjConn.Close();
                        p_OleDbProjConn = null;
                    }
                    if (ScenarioType.Trim().ToUpper() == "OPTIMIZER")
                    {
                        string strTemp = p_ado.FixString("SELECT @@PlotTable@@.* FROM @@PlotTable@@ WHERE @@PlotTable@@.plot_accessible_yn='Y'", "'", "''");
                        strSQL = "INSERT INTO scenario_plot_filter (scenario_id,sql_command,current_yn) VALUES " + "('" + this.txtScenarioId.Text.Trim() + "'," +
                                 "'" + strTemp + "'," +
                                 "'Y');";
                        p_ado.SqlNonQuery(p_ado.m_OleDbConnection, strSQL);

                        strTemp = p_ado.FixString("SELECT @@CondTable@@.* FROM @@CondTable@@", "'", "''");
                        strSQL  = "INSERT INTO scenario_cond_filter (scenario_id,sql_command,current_yn) VALUES " + "('" + this.txtScenarioId.Text.Trim() + "'," +
                                  "'" + strTemp + "'," +
                                  "'Y');";
                        p_ado.SqlNonQuery(p_ado.m_OleDbConnection, strSQL);
                    }
                }
                p_ado.m_OleDbConnection.Close();
                p_ado.m_OleDbConnection = null;
                p_ado = null;


                this.btnCancel.Enabled = false;
                this.btnOpen.Enabled   = true;

                this.lstScenario.Enabled     = true;
                this.txtScenarioId.Visible   = false;
                this.lblNewScenario.Visible  = false;
                this.txtScenarioPath.Enabled = false;
                this.lstScenario.Items.Add(this.txtScenarioId.Text);
                this.lstScenario.SelectedIndex = this.lstScenario.Items.Count - 1;
            }
            else
            {
                ado_data_access p_ado = new ado_data_access();

                System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection();
                string strProjDir     = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectDirectory;
                string strScenarioDir = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectDirectory + "\\" + ScenarioType + "\\db";
                string strFile        = "scenario_" + ScenarioType + "_rule_definitions.mdb";
                if (ScenarioType.Trim().ToUpper() == "OPTIMIZER")
                {
                    ((frmOptimizerScenario)ParentForm).uc_datasource1.strScenarioId        = this.txtScenarioId.Text.Trim();
                    ((frmOptimizerScenario)ParentForm).uc_datasource1.strDataSourceMDBFile = strScenarioDir + "\\scenario_" + ScenarioType + "_rule_definitions.mdb";
                    ((frmOptimizerScenario)ParentForm).uc_datasource1.strDataSourceTable   = "scenario_datasource";
                    ((frmOptimizerScenario)ParentForm).uc_datasource1.strProjectDirectory  = strProjDir;
                }
                else
                {
                    this.ReferenceProcessorScenarioForm.uc_datasource1.strScenarioId        = this.txtScenarioId.Text.Trim();
                    this.ReferenceProcessorScenarioForm.uc_datasource1.strDataSourceMDBFile = strScenarioDir + "\\scenario_" + ScenarioType + "_rule_definitions.mdb";
                    this.ReferenceProcessorScenarioForm.uc_datasource1.strDataSourceTable   = "scenario_datasource";
                    this.ReferenceProcessorScenarioForm.uc_datasource1.strProjectDirectory  = strProjDir;
                }
                StringBuilder strFullPath = new StringBuilder(strScenarioDir);
                strFullPath.Append("\\");
                strFullPath.Append(strFile);
                if (this.txtDescription.Text.Trim().Length > 0)
                {
                    strDesc = p_ado.FixString(this.txtDescription.Text.Trim(), "'", "''");
                }
                string strConn = p_ado.getMDBConnString(strFullPath.ToString(), "admin", "");
                //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFullPath.ToString() + ";User Id=admin;Password=;";
                strSQL = "UPDATE scenario SET description = '" +
                         strDesc +
                         "' WHERE scenario_id = '" + this.txtScenarioId.Text.ToLower() + "';";
                p_ado.SqlNonQuery(strConn, strSQL);
                p_ado = null;
            }
            if (ScenarioType.Trim().ToUpper() == "OPTIMIZER")
            {
                if (((frmOptimizerScenario)this.ParentForm).m_bScenarioOpen == false)
                {
                    ((frmOptimizerScenario)this.ParentForm).Text = "Core Analysis: Optimization Scenario (" + this.txtScenarioId.Text.Trim() + ")";
                    ((frmOptimizerScenario)this.ParentForm).SetMenu("scenario");
                    ((frmOptimizerScenario)this.ParentForm).m_bScenarioOpen = true;
                    this.lblTitle.Text = "";
                    this.Visible       = false;
                }
            }
            else
            {
                if (this.ReferenceProcessorScenarioForm.m_bScenarioOpen == false)
                {
                    this.ReferenceProcessorScenarioForm.Text            = "Processor: Scenario (" + this.txtScenarioId.Text.Trim() + ")";
                    this.ReferenceProcessorScenarioForm.m_bScenarioOpen = true;
                    this.lblTitle.Text = "";
                    this.Visible       = false;
                }
            }
        }
        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 DeleteRecords()
        {
            int             row     = 0;
            int             col     = 0;
            bool            lprompt = false;
            DialogResult    result  = DialogResult.None;
            ado_data_access p_ado;


            p_ado = new ado_data_access();
            //check to see if there are any records to delete
            for (row = 0; row <= this.listView1.Items.Count - 1; row++)
            {
                if (this.listView1.Items[row].Text == "*")
                {
                    if (lprompt == false)
                    {
                        result = MessageBox.Show("Permenently delete those items marked for deletion? Y/N", "SQL Expressions", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    }
                    if (result == DialogResult.Yes || lprompt == true)
                    {
                        if (lprompt == false)
                        {
                            p_ado.OpenConnection(this.m_strCurrentConnection);
                            if (p_ado.m_intError != 0)
                            {
                                p_ado = null;
                                return;
                            }
                            lprompt = true;
                        }
                        System.Text.StringBuilder sb = new System.Text.StringBuilder();

                        string strSQL = "DELETE * FROM " + this.m_strTable +
                                        " WHERE ";

                        sb.Append(strSQL);
                        for (col = 1; col <= this.listView1.Columns.Count - 1; col++)
                        {
                            if (this.m_strFieldTypeAString_YN[col - 1] == "Y")
                            {
                                if (this.listView1.Items[row].SubItems[col].Text.Trim().Length == 0)
                                {
                                    strSQL = "(" + this.listView1.Columns[col].Text.Trim() + " IS NULL OR LEN(TRIM(" + this.listView1.Columns[col].Text.Trim() + ")) = 0)";
                                    //if (strSQL.IndexOf("'",0) > 0) strSQL=p_ado.FixString(strSQL);
                                    sb.Append(strSQL);
                                }
                                else
                                {
                                    strSQL = "TRIM(UCASE(" + this.listView1.Columns[col].Text.Trim() + "))=";
                                    sb.Append(strSQL);
                                    sb.Append("'");
                                    if (this.listView1.Items[row].SubItems[col].Text.IndexOf("'", 0) > 0)
                                    {
                                        strSQL = p_ado.FixString(this.listView1.Items[row].SubItems[col].Text, "'", "''");
                                        sb.Append(strSQL);
                                    }
                                    else
                                    {
                                        strSQL = this.listView1.Items[row].SubItems[col].Text.Trim().ToUpper();
                                        sb.Append(strSQL);
                                    }
                                    sb.Append("'");
                                }
                            }
                            else
                            {
                                if (this.listView1.Items[row].SubItems[col].Text.Trim().Length == 0)
                                {
                                    strSQL = this.listView1.Columns[col].Text.Trim() + " IS NULL";
                                    sb.Append(strSQL);
                                }
                                else
                                {
                                    strSQL = this.listView1.Columns[col].Text.Trim() + "=";
                                    sb.Append(strSQL);
                                    strSQL = this.listView1.Items[row].SubItems[col].Text.Trim();
                                    sb.Append(strSQL);
                                }
                            }
                            if (col < this.listView1.Columns.Count - 1)
                            {
                                strSQL = " AND ";
                                sb.Append(strSQL);
                            }
                            else
                            {
                                strSQL = ";";
                                sb.Append(strSQL);
                            }
                        }

                        if (lprompt == true)
                        {
                            p_ado.SqlNonQuery(p_ado.m_OleDbConnection, sb.ToString());
                        }
                        sb = null;
                    }
                }
            }
            if (lprompt == true)
            {
                p_ado.m_OleDbConnection.Close();
                p_ado.m_OleDbConnection = null;
            }
            p_ado = null;
        }