public void LoadValuesSqlite()
        {
            string strNotes = "";

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

            strScenarioFullPath.Append("\\");
            strScenarioFullPath.Append(strScenarioFile);
            string strScenarioConn = dataMgr.GetConnectionString(strScenarioFullPath.ToString());

            using (System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(strScenarioConn))
            {
                con.Open();
                if (ScenarioType.Trim().ToUpper() == "OPTIMIZER")
                {
                    dataMgr.m_strSQL = "SELECT notes FROM scenario WHERE TRIM(scenario_id)='" + this.ReferenceOptimizerScenarioForm.uc_scenario1.strScenarioId.Trim() + "'";
                }
                else
                {
                    dataMgr.m_strSQL = "SELECT notes FROM scenario WHERE TRIM(scenario_id)='" + this.ReferenceProcessorScenarioForm.uc_scenario1.strScenarioId.Trim() + "'";
                }
                strNotes = dataMgr.getSingleStringValueFromSQLQuery(con, dataMgr.m_strSQL, "scenario");
            }
            this.txtNotes.Text = strNotes;
        }
        private string[] loadScenarioArraySqlite()
        {
            //
            //OPEN CONNECTION TO DB FILE CONTAINING PROCESSOR SCENARIO TABLE
            //
            //scenario mdb connection
            string strProcessorScenarioDB =
                frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                "\\processor\\" + Tables.ProcessorScenarioRuleDefinitions.DefaultSqliteDbFile;

            //
            //get a list of all the scenarios
            //
            SQLite.ADO.DataMgr dataMgr          = new SQLite.ADO.DataMgr();
            string             strConn          = dataMgr.GetConnectionString(strProcessorScenarioDB);
            IList <string>     lstScenarioArray = null;

            using (System.Data.SQLite.SQLiteConnection oConn = new System.Data.SQLite.SQLiteConnection(strConn))
            {
                oConn.Open();
                lstScenarioArray = dataMgr.getStringList(oConn,
                                                         "SELECT scenario_id " +
                                                         "FROM scenario " +
                                                         "WHERE scenario_id IS NOT NULL AND " +
                                                         "LENGTH(TRIM(scenario_id)) > 0");
            }
            return(lstScenarioArray.ToArray());
        }
        private void RefreshFormSqlite()
        {
            SQLite.ADO.DataMgr dataMgr        = new SQLite.ADO.DataMgr();
            string             strScenarioDir = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" + ScenarioType + "\\" +
                                                Tables.ProcessorScenarioRuleDefinitions.DefaultSqliteDbFile;
            string strConn = dataMgr.GetConnectionString(strScenarioDir);

            try
            {
                using (System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(strConn))
                {
                    con.Open();
                    string strSQL = "select * from scenario where scenario_id = '" + this.lstScenario.SelectedItem.ToString() + "';";
                    dataMgr.SqlQueryReader(con, strSQL);
                    if (dataMgr.m_DataReader.HasRows)
                    {
                        while (dataMgr.m_DataReader.Read())
                        {
                            txtScenarioId.Text   = dataMgr.m_DataReader["scenario_id"].ToString();
                            txtDescription.Text  = dataMgr.m_DataReader["description"].ToString();
                            txtScenarioPath.Text = dataMgr.m_DataReader["path"].ToString();
                            break;
                        }
                    }
                    dataMgr.m_DataReader.Close();
                }
            }
            catch (Exception caught)
            {
                intError = -1;
                strError = caught.Message;
                MessageBox.Show(strError, "FIA Biosum");
            }
        }
        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;
            }
        }
        public void populate_scenario_listbox_sqlite()
        {
            string strScenarioId   = "";
            string strDescription  = "";
            string strScenarioPath = "";

            SQLite.ADO.DataMgr dataMgr = new SQLite.ADO.DataMgr();

            string strScenarioDir = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" + ScenarioType + "\\" +
                                    Tables.ProcessorScenarioRuleDefinitions.DefaultSqliteDbFile;

            string strConn = dataMgr.GetConnectionString(strScenarioDir);

            try
            {
                lstScenario.Items.Clear();
                using (System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(strConn))
                {
                    con.Open();
                    dataMgr.SqlQueryReader(con, "select * from scenario");
                    if (dataMgr.m_DataReader.HasRows)
                    {
                        while (dataMgr.m_DataReader.Read())
                        {
                            strScenarioId   = dataMgr.m_DataReader["scenario_id"].ToString();
                            strDescription  = dataMgr.m_DataReader["description"].ToString();
                            strScenarioPath = dataMgr.m_DataReader["path"].ToString();
                            this.lstScenario.Items.Add(strScenarioId);
                        }
                    }
                }
                this.lstScenario.SelectedIndex = this.lstScenario.Items.Count - 1;
                this.txtScenarioPath.Text      = strScenarioPath;
                this.txtDescription.Text       = strDescription;
            }
            catch (Exception caught)
            {
                intError = -1;
                strError = caught.Message;
                MessageBox.Show(strError, "FIA Biosum");
            }
        }
        public void savevalues()
        {
            int    x;
            string strSpcGrp     = "";
            string strDbhGrp     = "";
            string strMerchValue = "";
            string strChipValue  = "";
            string strWoodBin    = "";
            string strSql        = "";

            SQLite.ADO.DataMgr oDataMgr = null;
            if (!ReferenceProcessorScenarioForm.m_bUsingSqlite)
            {
                //
                //DELETE THE CURRENT SCENARIO RECORDS
                //
                m_oAdo.m_strSQL = "DELETE FROM scenario_tree_species_diam_dollar_values " +
                                  "WHERE TRIM(scenario_id)='" + this.ScenarioId.Trim() + "'";
                m_oAdo.SqlNonQuery(m_oAdo.m_OleDbConnection, m_oAdo.m_strSQL);
                //
                //DELETE THE WORK TABLE
                //
                if (m_oAdo.TableExist(m_oAdo.m_OleDbConnection, "spcgrp_dbhgrp"))
                {
                    m_oAdo.SqlNonQuery(m_oAdo.m_OleDbConnection, "DROP TABLE spcgrp_dbhgrp");
                }
                //
                //CREATE AND POPULATE WORK TABLE
                //
                m_oAdo.m_strSQL = "CREATE TABLE spcgrp_dbhgrp (" +
                                  "species_group INTEGER," +
                                  "species_label CHAR(50)," +
                                  "diam_group INTEGER," +
                                  "diam_class CHAR(15))";
                m_oAdo.SqlNonQuery(m_oAdo.m_OleDbConnection, m_oAdo.m_strSQL);

                foreach (ProcessorScenarioItem.SpcGroupItem objSpcGroup in ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oSpcGroupItem_Collection)
                {
                    foreach (ProcessorScenarioItem.TreeDiamGroupsItem objDiamGroup in ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeDiamGroupsItem_Collection)
                    {
                        // INITIALIZE RECORDS IN WORK TABLE
                        m_oAdo.m_strSQL = "INSERT INTO spcgrp_dbhgrp (species_group,species_label, diam_group, diam_class) " +
                                          "VALUES (" + objSpcGroup.SpeciesGroup + ",'" + objSpcGroup.SpeciesGroupLabel + "'," +
                                          objDiamGroup.DiamGroup + ",'" + objDiamGroup.DiamClass + "')";
                        m_oAdo.SqlNonQuery(m_oAdo.m_OleDbConnection, m_oAdo.m_strSQL);
                        //
                        //INSERT SCENARIO RECORDS
                        //
                        m_oAdo.m_strSQL = "INSERT INTO scenario_tree_species_diam_dollar_values (scenario_id,species_group,diam_group) " +
                                          "VALUES ('" + ScenarioId.Trim() + "'," + objSpcGroup.SpeciesGroup + "," +
                                          objDiamGroup.DiamGroup + ")";
                        m_oAdo.SqlNonQuery(m_oAdo.m_OleDbConnection, m_oAdo.m_strSQL);
                    }
                }
            }
            else
            {
                oDataMgr = new SQLite.ADO.DataMgr();
                string strScenarioDB =
                    frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                    "\\processor\\" + Tables.ProcessorScenarioRuleDefinitions.DefaultSqliteDbFile;
                oDataMgr.OpenConnection(oDataMgr.GetConnectionString(strScenarioDB));
                if (oDataMgr.m_intError != 0)
                {
                    m_intError = oDataMgr.m_intError;
                    m_strError = oDataMgr.m_strError;
                    oDataMgr   = null;
                    return;
                }
                m_intError = 0;
                m_strError = "";
                //
                //DELETE THE CURRENT SCENARIO RECORDS
                //
                oDataMgr.m_strSQL = "DELETE FROM scenario_tree_species_diam_dollar_values " +
                                    "WHERE TRIM(scenario_id)='" + this.ScenarioId.Trim() + "'";
                oDataMgr.SqlNonQuery(oDataMgr.m_Connection, oDataMgr.m_strSQL);
                //
                //DELETE THE WORK TABLE
                //
                if (oDataMgr.TableExist(oDataMgr.m_Connection, "spcgrp_dbhgrp"))
                {
                    oDataMgr.SqlNonQuery(oDataMgr.m_Connection, "DROP TABLE spcgrp_dbhgrp");
                }
                //
                //CREATE AND POPULATE WORK TABLE
                //
                oDataMgr.m_strSQL = "CREATE TABLE spcgrp_dbhgrp (" +
                                    "species_group INTEGER," +
                                    "species_label TEXT," +
                                    "diam_group INTEGER," +
                                    "diam_class TEXT)";
                oDataMgr.SqlNonQuery(oDataMgr.m_Connection, oDataMgr.m_strSQL);

                foreach (ProcessorScenarioItem.SpcGroupItem objSpcGroup in ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oSpcGroupItem_Collection)
                {
                    foreach (ProcessorScenarioItem.TreeDiamGroupsItem objDiamGroup in ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeDiamGroupsItem_Collection)
                    {
                        // INITIALIZE RECORDS IN WORK TABLE
                        oDataMgr.m_strSQL = "INSERT INTO spcgrp_dbhgrp (species_group,species_label, diam_group, diam_class) " +
                                            "VALUES (" + objSpcGroup.SpeciesGroup + ",'" + objSpcGroup.SpeciesGroupLabel + "'," +
                                            objDiamGroup.DiamGroup + ",'" + objDiamGroup.DiamClass + "')";
                        oDataMgr.SqlNonQuery(oDataMgr.m_Connection, oDataMgr.m_strSQL);
                        //
                        //INSERT SCENARIO RECORDS
                        //
                        oDataMgr.m_strSQL = "INSERT INTO scenario_tree_species_diam_dollar_values (scenario_id,species_group,diam_group) " +
                                            "VALUES ('" + ScenarioId.Trim() + "'," + objSpcGroup.SpeciesGroup + "," +
                                            objDiamGroup.DiamGroup + ")";
                        oDataMgr.SqlNonQuery(oDataMgr.m_Connection, oDataMgr.m_strSQL);
                    }
                }
            }


            //
            //UPDATE SCENARIO RECORDS WITH MERCH AND CHIP VALUES
            //
            for (x = 0; x <= this.uc_processor_scenario_spc_dbh_group_value_collection1.Count - 1; x++)
            {
                strSpcGrp     = uc_processor_scenario_spc_dbh_group_value_collection1.Item(x).SpeciesGroup.Trim();
                strDbhGrp     = uc_processor_scenario_spc_dbh_group_value_collection1.Item(x).DbhGroup.Trim();
                strWoodBin    = uc_processor_scenario_spc_dbh_group_value_collection1.Item(x).GetWoodBin();
                strMerchValue = uc_processor_scenario_spc_dbh_group_value_collection1.Item(x).CubicFootDollarValue.Trim();
                strMerchValue = strMerchValue.Replace("$", "");
                strChipValue  = this.txtChipValue.Text.Trim();
                strChipValue  = strChipValue.Replace("$", "");

                if (!ReferenceProcessorScenarioForm.m_bUsingSqlite)
                {
                    strSql = "UPDATE scenario_tree_species_diam_dollar_values a " +
                             "INNER JOIN spcgrp_dbhgrp b " +
                             "ON  a.species_group=b.species_group AND " +
                             "a.diam_group=b.diam_group " +
                             "SET a.merch_value=" + strMerchValue + "," +
                             "a.chip_value=" + strChipValue + ", " +
                             "a.wood_bin='" + strWoodBin.Trim() + "' " +
                             "WHERE TRIM(a.scenario_id)='" + ScenarioId.Trim() + "' AND " +
                             "TRIM(b.species_label)='" + strSpcGrp + "' AND " +
                             "TRIM(b.diam_class)='" + strDbhGrp + "'";
                    m_oAdo.SqlNonQuery(m_oAdo.m_OleDbConnection, strSql);
                }
                else
                {
                    strSql = "UPDATE scenario_tree_species_diam_dollar_values " +
                             "SET merch_value = " + strMerchValue + "," +
                             "chip_value = " + strChipValue + "," +
                             "wood_bin = '" + strWoodBin.Trim() + "' WHERE EXISTS (" +
                             "SELECT * FROM spcgrp_dbhgrp " +
                             "WHERE scenario_tree_species_diam_dollar_values.species_group = spcgrp_dbhgrp.species_group " +
                             "AND scenario_tree_species_diam_dollar_values.diam_group = spcgrp_dbhgrp.diam_group " +
                             "AND TRIM(scenario_tree_species_diam_dollar_values.scenario_id) = '" + ScenarioId.Trim() + "' " +
                             "AND TRIM(spcgrp_dbhgrp.species_label) = '" + strSpcGrp + "' " +
                             "AND TRIM(spcgrp_dbhgrp.diam_class) = '" + strDbhGrp + "')";

                    oDataMgr.SqlNonQuery(oDataMgr.m_Connection, strSql);
                }

                uc_processor_scenario_spc_dbh_group_value_collection1.Item(x).SaveValues();
            }
            this.m_strChipValueSave = this.txtChipValue.Text;
            if (ReferenceProcessorScenarioForm.m_bUsingSqlite)
            {
                //
                //DELETE THE WORK TABLE AND CLOSE CONNECTION
                //
                if (oDataMgr.TableExist(oDataMgr.m_Connection, "spcgrp_dbhgrp"))
                {
                    oDataMgr.SqlNonQuery(oDataMgr.m_Connection, "DROP TABLE spcgrp_dbhgrp");
                }
                m_intError = oDataMgr.m_intError;

                oDataMgr.CloseConnection(oDataMgr.m_Connection);
                oDataMgr = null;
            }
        }
        public void saveTreeGroupings_FromPropertiesSqlite()
        {
            SQLite.ADO.DataMgr oDataMgr  = new SQLite.ADO.DataMgr();
            string             strDbFile = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                                           "\\processor\\" + Tables.ProcessorScenarioRuleDefinitions.DefaultSqliteDbFile;

            using (System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection(oDataMgr.GetConnectionString(strDbFile)))
            {
                conn.Open();
                if (oDataMgr.m_intError == 0)
                {
                    string strScenarioId = this.ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.ScenarioId;
                    //delete the current records
                    oDataMgr.m_strSQL = "DELETE FROM " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeDiamGroupsTableName +
                                        " WHERE TRIM(UPPER(scenario_id)) = '" + strScenarioId.ToUpper().Trim() + "'";
                    oDataMgr.SqlNonQuery(conn, oDataMgr.m_strSQL);

                    // saving tree diameter groups
                    if (oDataMgr.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++)
                        {
                            ProcessorScenarioItem.TreeDiamGroupsItem oItem =
                                ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeDiamGroupsItem_Collection.Item(x);
                            strId  = oItem.DiamGroup;
                            strMin = oItem.MinDiam;
                            strMax = oItem.MaxDiam;
                            strDef = oItem.DiamClass;

                            oDataMgr.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() + "');";
                            oDataMgr.SqlNonQuery(conn, oDataMgr.m_strSQL);
                            if (oDataMgr.m_intError != 0)
                            {
                                break;
                            }
                        }
                    }
                    // saving tree species groups
                    if (oDataMgr.m_intError == 0)
                    {
                        string strCommonName;
                        int    intSpCd;
                        int    intSpcGrp;
                        string strGrpLabel;
                        int    x;

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

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

                        if (oDataMgr.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;
                                oDataMgr.m_strSQL = "INSERT INTO " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeSpeciesGroupsTableName + " " +
                                                    "(SPECIES_GROUP,SPECIES_LABEL,SCENARIO_ID) VALUES " +
                                                    "(" + Convert.ToString(intSpcGrp).Trim() + ",'" + strGrpLabel.Trim() + "','" + strScenarioId.Trim() + "');";
                                oDataMgr.SqlNonQuery(conn, oDataMgr.m_strSQL);
                            }
                        }
                        if (oDataMgr.m_intError == 0)
                        {
                            for (x = 0; x <= this.ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oSpcGroupListItem_Collection.Count - 1; x++)
                            {
                                ProcessorScenarioItem.SpcGroupListItem oItem =
                                    ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oSpcGroupListItem_Collection.Item(x);
                                intSpcGrp     = oItem.SpeciesGroup;
                                strCommonName = oItem.CommonName;
                                strCommonName = oDataMgr.FixString(strCommonName.Trim(), "'", "''");
                                intSpCd       = oItem.SpeciesCode;

                                oDataMgr.m_strSQL = "INSERT INTO " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeSpeciesGroupsListTableName + " " +
                                                    "(SPECIES_GROUP,common_name,SCENARIO_ID,SPCD) VALUES " +
                                                    "(" + Convert.ToString(intSpcGrp).Trim() + ",'" + strCommonName + "','" + strScenarioId.Trim() + "', " +
                                                    intSpCd + " );";
                                oDataMgr.SqlNonQuery(conn, oDataMgr.m_strSQL);
                            }
                        }
                    }
                    ReferenceProcessorScenarioForm.m_bTreeGroupsCopied = false;
                }
            }
            oDataMgr = null;
        }
        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;
                }
            }
        }
        public void savevalues()
        {
            string strFields = "scenario_id,yard_dist_threshold,assumed_harvest_area_ac," +
                               "move_in_time_multiplier," +
                               "move_in_hours_addend";
            string strValues = "";

            //
            //OPEN CONNECTION TO DB FILE CONTAINING PROCESSOR SCENARIO TABLES
            //
            //scenario mdb connection
            ado_data_access oAdo = null;

            SQLite.ADO.DataMgr oDataMgr = null;
            if (!ReferenceProcessorScenarioForm.m_bUsingSqlite)
            {
                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 = "";

                oAdo.m_strSQL = "DELETE FROM " + Tables.ProcessorScenarioRuleDefinitions.DefaultMoveInCostsTableName + " " +
                                "WHERE TRIM(UCASE(scenario_id)) = '" + ScenarioId.Trim().ToUpper() + "'";
                oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL);
            }
            else
            {
                oDataMgr = new SQLite.ADO.DataMgr();
                string strScenarioDB =
                    frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                    "\\processor\\" + Tables.ProcessorScenarioRuleDefinitions.DefaultSqliteDbFile;
                oDataMgr.OpenConnection(oDataMgr.GetConnectionString(strScenarioDB));
                if (oDataMgr.m_intError != 0)
                {
                    m_intError = oDataMgr.m_intError;
                    m_strError = oDataMgr.m_strError;
                    oDataMgr   = null;
                    return;
                }
                m_intError = 0;
                m_strError = "";

                oDataMgr.m_strSQL = "DELETE FROM " + Tables.ProcessorScenarioRuleDefinitions.DefaultMoveInCostsTableName + " " +
                                    "WHERE TRIM(UPPER(scenario_id)) = '" + ScenarioId.Trim().ToUpper() + "'";
                oDataMgr.SqlNonQuery(oDataMgr.m_Connection, oDataMgr.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";
            }
            //

            if (!ReferenceProcessorScenarioForm.m_bUsingSqlite)
            {
                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;
            }
            else
            {
                oDataMgr.m_strSQL = Queries.GetInsertSQL(strFields, strValues, Tables.ProcessorScenarioRuleDefinitions.DefaultMoveInCostsTableName);
                oDataMgr.SqlNonQuery(oDataMgr.m_Connection, oDataMgr.m_strSQL);
                m_intError = oDataMgr.m_intError;

                oDataMgr.CloseConnection(oDataMgr.m_Connection);
                oDataMgr = null;
            }
        }
Пример #10
0
        public void savevalues()
        {
            m_intError = 0;
            m_strError = "";

            string strValues = "";
            string strFields = "scenario_id," +
                               "EscalatorOperatingCosts_Cycle2," +
                               "EscalatorOperatingCosts_Cycle3," +
                               "EscalatorOperatingCosts_Cycle4," +
                               "EscalatorMerchWoodRevenue_Cycle2," +
                               "EscalatorMerchWoodRevenue_Cycle3," +
                               "EscalatorMerchWoodRevenue_Cycle4," +
                               "EscalatorEnergyWoodRevenue_Cycle2," +
                               "EscalatorEnergyWoodRevenue_Cycle3," +
                               "EscalatorEnergyWoodRevenue_Cycle4";


            try
            {
                SQLite.ADO.DataMgr oDataMgr = null;
                //
                //DELETE THE CURRENT SCENARIO RECORDS
                //
                if (!ReferenceProcessorScenarioForm.m_bUsingSqlite)
                {
                    m_oAdo.m_strSQL = "DELETE FROM scenario_cost_revenue_escalators " +
                                      "WHERE TRIM(scenario_id)='" + this.ScenarioId.Trim() + "'";
                    m_oAdo.SqlNonQuery(m_oAdo.m_OleDbConnection, m_oAdo.m_strSQL);
                }
                else
                {
                    oDataMgr = new SQLite.ADO.DataMgr();
                    string strScenarioDB =
                        frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                        "\\processor\\" + Tables.ProcessorScenarioRuleDefinitions.DefaultSqliteDbFile;
                    oDataMgr.OpenConnection(oDataMgr.GetConnectionString(strScenarioDB));
                    if (oDataMgr.m_intError != 0)
                    {
                        m_intError = oDataMgr.m_intError;
                        m_strError = oDataMgr.m_strError;
                        oDataMgr   = null;
                        return;
                    }
                    oDataMgr.m_strSQL = "DELETE FROM scenario_cost_revenue_escalators " +
                                        "WHERE TRIM(scenario_id)='" + this.ScenarioId.Trim() + "'";
                    oDataMgr.SqlNonQuery(oDataMgr.m_Connection, oDataMgr.m_strSQL);
                }

                //
                //scenario id
                //
                strValues = "'" + ScenarioId.Trim() + "',";
                //
                //Operating Cost Cycle1
                //
                strValues = strValues + this.uc_processor_scenario_escalators_value1.Cycle1.Trim() + ",";
                //
                //Operating Cost Cycle2
                //
                strValues = strValues + this.uc_processor_scenario_escalators_value1.Cycle2.Trim() + ",";
                //
                //Operating Cost Cycle3
                //
                strValues = strValues + this.uc_processor_scenario_escalators_value1.Cycle3.Trim() + ",";
                //
                //Merch Wood Revenue Cycle1
                //
                strValues = strValues + this.uc_processor_scenario_escalators_value2.Cycle1.Trim() + ",";
                //
                //Merch Wood Revenue Cycle2
                //
                strValues = strValues + this.uc_processor_scenario_escalators_value2.Cycle2.Trim() + ",";
                //
                //Merch Wood Revenue Cycle3
                //
                strValues = strValues + this.uc_processor_scenario_escalators_value2.Cycle3.Trim() + ",";
                //
                //Energy Wood Revenue Cycle1
                //
                strValues = strValues + this.uc_processor_scenario_escalators_value3.Cycle1.Trim() + ",";
                //
                //Energy Wood Revenue Cycle2
                //
                strValues = strValues + this.uc_processor_scenario_escalators_value3.Cycle2.Trim() + ",";
                //
                //Energy Wood Revenue Cycle3
                //
                strValues = strValues + this.uc_processor_scenario_escalators_value3.Cycle3.Trim();

                if (!ReferenceProcessorScenarioForm.m_bUsingSqlite)
                {
                    m_oAdo.m_strSQL = Queries.GetInsertSQL(strFields, strValues, "scenario_cost_revenue_escalators");
                    m_oAdo.SqlNonQuery(m_oAdo.m_OleDbConnection, m_oAdo.m_strSQL);
                }
                else
                {
                    oDataMgr.m_strSQL = Queries.GetInsertSQL(strFields, strValues, "scenario_cost_revenue_escalators");
                    oDataMgr.SqlNonQuery(oDataMgr.m_Connection, oDataMgr.m_strSQL);
                    m_intError = oDataMgr.m_intError;

                    oDataMgr.CloseConnection(oDataMgr.m_Connection);
                    oDataMgr = null;
                }

                this.uc_processor_scenario_escalators_value1.SaveValues();
                this.uc_processor_scenario_escalators_value2.SaveValues();
                this.uc_processor_scenario_escalators_value3.SaveValues();
            }
            catch (Exception e)
            {
                m_intError = -1;
                m_strError = e.Message;
            }
        }
Пример #11
0
        private void loadgridSqlite()
        {
            //
            //OPEN CONNECTION TO DB FILE CONTAINING Processor Scenario TABLE
            //
            //scenario mdb connection
            string strProcessorScenarioDB =
                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(strProcessorScenarioDB)))
            {
                conn.Open();
                //
                //get a list of all the scenarios
                //
                oDataMgr.SqlQueryReader(conn,
                                        "SELECT scenario_id,description " +
                                        "FROM scenario " +
                                        "WHERE scenario_id IS NOT NULL AND " +
                                        "LENGTH(TRIM(scenario_id)) > 0");
                int          x             = 0;
                ListViewItem entryListItem = null;
                if (oDataMgr.m_DataReader.HasRows)
                {
                    while (oDataMgr.m_DataReader.Read())

                    {
                        if (oDataMgr.m_DataReader["scenario_id"] != DBNull.Value &&
                            oDataMgr.m_DataReader["scenario_id"].ToString().Trim().Length > 0 &&
                            ReferenceCurrentScenarioItem.ScenarioId.Trim().ToUpper() !=
                            oDataMgr.m_DataReader["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(oDataMgr.m_DataReader["scenario_id"].ToString().Trim());

                            if (oDataMgr.m_DataReader["description"] != DBNull.Value &&
                                oDataMgr.m_DataReader["description"].ToString().Trim().Length > 0)
                            {
                                entryListItem.SubItems.Add(oDataMgr.m_DataReader["description"].ToString().Trim());
                            }
                            else
                            {
                                entryListItem.SubItems.Add(" ");
                            }
                            x = x + 1;
                        }
                    }
                    oDataMgr.m_DataReader.Close();
                    this.m_oLvAlternateColors.ListView();
                }
                else
                {
                    MessageBox.Show("!!No Scenarios To Copy!!", "FIA Bisoum");
                    btnCopy.Enabled = false;
                }
            }
        }