Ejemplo n.º 1
0
 private void InitializeVariantLocationDictionary()
 {
     m_ado = new ado_data_access();
     dictVariantLocations = new Dictionary <string, List <string> >();
     using (var conn = new OleDbConnection(m_ado.getMDBConnString(
                                               frmMain.g_oEnv.strApplicationDataDirectory.Trim() + frmMain.g_strBiosumDataDir + "\\" +
                                               Tables.Reference.DefaultBiosumReferenceDbFile, "", "")))
     {
         conn.Open();
         m_ado.SqlQueryReader(conn, "SELECT DISTINCT fvs_variant, fvsloccode FROM fiadb_fvs_variant;");
         if (this.m_ado.m_intError == 0)
         {
             if (this.m_ado.m_OleDbDataReader.HasRows)
             {
                 string variant  = "";
                 string location = "";
                 while (this.m_ado.m_OleDbDataReader.Read())
                 {
                     variant = m_ado.m_OleDbDataReader["fvs_variant"].ToString().Trim();
                     if (!dictVariantLocations.ContainsKey(variant))
                     {
                         dictVariantLocations.Add(variant, new List <string>());
                     }
                     location = m_ado.m_OleDbDataReader["fvsloccode"].ToString().Trim();
                     dictVariantLocations[variant].Add(location);
                 }
             }
         }
         m_ado.m_OleDbDataReader.Dispose();
     }
     m_ado = null;
 }
Ejemplo n.º 2
0
        private void populate_state_combo()
        {
            this.cmbState.Items.Clear();
            ado_data_access p_ado   = new ado_data_access();
            env             p_env   = new env();
            string          strConn = p_ado.getMDBConnString(p_env.strAppDir.Trim() + "\\db\\utils.mdb", "", "");

            try
            {
                p_ado.SqlQueryReader(strConn, "select * from states order by stabv");
                if (p_ado.m_OleDbDataReader.HasRows == true)
                {
                    while (p_ado.m_OleDbDataReader.Read())
                    {
                        string strState = p_ado.m_OleDbDataReader["stabv"].ToString().Trim() + " - " +
                                          p_ado.m_OleDbDataReader["state_name"].ToString();
                        this.cmbState.Items.Add(strState);
                    }
                }
                p_ado.m_OleDbDataReader.Close();
                p_ado.m_OleDbConnection.Close();
                p_ado.m_OleDbConnection.Dispose();
            }
            catch
            {
            }
            p_ado = null;
            p_env = null;
        }
Ejemplo n.º 3
0
        public void populate_scenario_listbox()
        {
            string strScenarioId  = "";
            string strDescription = "";
            //string strScenarioMDBFile="";
            string strScenarioPath = "";

            System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection();
            string strProjDir = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim();

            string        strScenarioDir = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" + ScenarioType + "\\db";
            string        strFile        = "scenario_" + ScenarioType + "_rule_definitions.mdb";
            StringBuilder strFullPath    = new StringBuilder(strScenarioDir);

            strFullPath.Append("\\");
            strFullPath.Append(strFile);
            ado_data_access p_ado   = new ado_data_access();
            string          strConn = p_ado.getMDBConnString(strFullPath.ToString(), "admin", "");

            p_ado.SqlQueryReader(strConn, "select * from scenario");
            if (p_ado.m_intError == 0)
            {
                try
                {
                    this.lstScenario.Items.Clear();
                    while (p_ado.m_OleDbDataReader.Read())
                    {
                        strScenarioId = p_ado.m_OleDbDataReader["scenario_id"].ToString();
                        //strScenarioMDBFile = p_ado.m_OleDbDataReader["file"].ToString();
                        strDescription  = p_ado.m_OleDbDataReader["description"].ToString();
                        strScenarioPath = p_ado.m_OleDbDataReader["path"].ToString();
                        this.lstScenario.Items.Add(p_ado.m_OleDbDataReader["scenario_id"].ToString());
                    }
                    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);
                }
                p_ado.m_OleDbDataReader.Close();
                p_ado.m_OleDbDataReader = null;
                p_ado.m_OleDbCommand    = null;
                p_ado.m_OleDbConnection.Close();
                p_ado.m_OleDbConnection = null;
            }
            p_ado = null;
        }
Ejemplo n.º 4
0
        private string getNextScenarioId()
        {
            System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection();
            string strProjDir     = frmMain.g_oFrmMain.getProjectDirectory();
            string strScenarioDir = strProjDir + "\\" + ScenarioType + "\\db";
            string strFile        = "scenario_" + ScenarioType + "_rule_definitions.mdb";

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

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

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

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

            int    i = 1;
            string strTestName;

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

            strTestName = "scenario" + Convert.ToString(i);
            return(strTestName);
        }
Ejemplo n.º 5
0
        private void cmbVariant_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (this.cmbVariant.Text.Trim().Length > 0)
            {
                this.m_strVariant = this.cmbVariant.Text.Trim().Substring(0, 2).ToString();

                if (m_strVariant.Trim().Length > 0)
                {
                    this.cmbFvsSpCd.Items.Clear();
                    // cache convertToSpcd
                    int intMyConvertToSpcd = -1;
                    if (m_intConvertToSpCd > 0)
                    {
                        intMyConvertToSpcd = m_intConvertToSpCd;
                    }
                    this.m_dictFvsCommonName.Clear();
                    m_ado.m_strSQL = "SELECT  spcd,fvs_species,common_name,fvs_common_name " +
                                     "FROM " + m_strFvsTreeSpcTable + " " +
                                     "WHERE LEN(TRIM(fvs_species)) > 0 AND " +
                                     "LEN(TRIM(common_name)) > 0 AND " +
                                     "TRIM(fvs_variant) = '" + m_strVariant.Trim() + "' order by spcd;";

                    m_ado.SqlQueryReader(m_ado.m_OleDbConnection, m_ado.m_OleDbTransaction, m_ado.m_strSQL);
                    if (m_ado.m_OleDbDataReader.HasRows)
                    {
                        while (m_ado.m_OleDbDataReader.Read())
                        {
                            string strMySpCd = Convert.ToString(m_ado.m_OleDbDataReader["spcd"]);
                            this.cmbFvsSpCd.Items.Add(strMySpCd + " - " + Convert.ToString(m_ado.m_OleDbDataReader["common_name"]) + " - " + m_ado.m_OleDbDataReader["fvs_species"]);
                            if (!m_dictFvsCommonName.ContainsKey(strMySpCd))
                            {
                                m_dictFvsCommonName.Add(strMySpCd, Convert.ToString(m_ado.m_OleDbDataReader["fvs_common_name"]));
                            }
                        }

                        if (intMyConvertToSpcd > 0)
                        {
                            this.intConvertToSpCd = intMyConvertToSpcd;
                        }
                    }
                    m_ado.m_OleDbDataReader.Close();
                }
            }
        }
Ejemplo n.º 6
0
        public int getNumberOfOptimizerTables(string strScenarioMDB, string strScenarioId)
        {
            int intCount = 0;

            System.Data.OleDb.OleDbConnection p_conn;

            ado_data_access p_ado = new ado_data_access();

            p_conn = new System.Data.OleDb.OleDbConnection();
            string strConn = p_ado.getMDBConnString(strScenarioMDB, "admin", "");

            p_ado.OpenConnection(strConn, ref p_conn);
            if (p_ado.m_intError != 0)
            {
                p_ado = null;
                return(intCount);
            }
            string strSQL = "SELECT table_name FROM scenario_datasource WHERE " +
                            " scenario_id = '" + strScenarioId + "';";

            p_ado.SqlQueryReader(p_conn, strSQL);
            if (p_ado.m_intError == 0)
            {
                while (p_ado.m_OleDbDataReader.Read())
                {
                    if (p_ado.m_OleDbDataReader["table_name"] != System.DBNull.Value)
                    {
                        if (p_ado.m_OleDbDataReader["table_name"].ToString().Trim().Length > 0)
                        {
                            intCount++;
                        }
                    }
                }
            }
            p_ado.m_OleDbDataReader.Close();
            p_ado.m_OleDbDataReader = null;
            p_conn.Close();
            p_conn = null;
            p_ado  = null;
            return(intCount);
        }
Ejemplo n.º 7
0
        //Get rx listing from project and make sure all FSOUT_rx* is present, TODO: otherwise?
        private ArrayList DbRxVerify()
        {
            ArrayList       aryL  = new ArrayList();
            ado_data_access p_ado = new ado_data_access();

            string strSQL = @"SELECT * FROM RX;";

            try
            {
                p_ado.SqlQueryReader(string.Format(this.strDbConx, this.strPathMasterDbFile), strSQL);
                if (p_ado.m_intError == 0)
                {
                    if (p_ado.m_OleDbDataReader.HasRows == true)
                    {
                        while (p_ado.m_OleDbDataReader.Read())
                        {
                            aryL.Add(p_ado.m_OleDbDataReader["RX"].ToString().Trim());
                        }
                    }
                    else
                    {
                        //TODO: Log to file
                    }
                }
            }
            catch (OLE.OleDbException ode)
            {
                p_ado.m_OleDbDataReader.Close();
                p_ado.m_OleDbConnection.Close();
                throw ode;
            }
            finally
            {
                p_ado.m_OleDbDataReader.Close();
                p_ado.m_OleDbConnection.Close();
                p_ado.m_OleDbDataReader = null;
                p_ado.m_OleDbConnection = null;
                p_ado = null;
            }
            return(aryL);
        }
Ejemplo n.º 8
0
        private void RefreshForm()
        {
            string        strScenarioDir = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" + ScenarioType + "\\db";
            string        strFile        = "scenario_" + ScenarioType + "_rule_definitions.mdb";
            StringBuilder strFullPath    = new StringBuilder(strScenarioDir);

            strFullPath.Append("\\");
            strFullPath.Append(strFile);
            ado_data_access p_ado   = new ado_data_access();
            string          strConn = p_ado.getMDBConnString(strFullPath.ToString(), "admin", "");
            //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFullPath.ToString() + ";User Id=admin;Password=;";
            string strSQL = "select * from scenario where scenario_id = '" + this.lstScenario.SelectedItem.ToString() + "';";

            p_ado.SqlQueryReader(strConn, strSQL);
            if (p_ado.m_intError == 0)
            {
                try
                {
                    while (p_ado.m_OleDbDataReader.Read())
                    {
                        this.txtDescription.Text  = p_ado.m_OleDbDataReader["description"].ToString();
                        this.txtScenarioPath.Text = p_ado.m_OleDbDataReader["path"].ToString();
                        this.txtScenarioId.Text   = p_ado.m_OleDbDataReader["scenario_id"].ToString();
                        //((frmScenario)this.ParentForm).uc_scenario_notes1.txtNotes.Text = p_ado.m_OleDbDataReader["notes"].ToString();
                        break;
                    }
                    p_ado.m_OleDbDataReader.Close();
                }
                catch (Exception caught)
                {
                    this.strError = caught.Message;
                    this.intError = -1;
                    MessageBox.Show(this.strError);
                }
                p_ado.m_OleDbDataReader = null;
                p_ado.m_OleDbCommand    = null;
                p_ado.m_OleDbConnection.Close();
                p_ado.m_OleDbConnection = null;
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Populate listbox with the strColumn values
 /// </summary>
 /// <param name="p_oAdo"></param>
 /// <param name="p_oConn"></param>
 /// <param name="strSQL"></param>
 /// <param name="strColumn"></param>
 public void loadvalues(ado_data_access p_oAdo,
                        System.Data.OleDb.OleDbConnection p_oConn,
                        string strSQL, string strColumn)
 {
     listBox1.Items.Clear();
     p_oAdo.SqlQueryReader(p_oConn, strSQL);
     if (p_oAdo.m_OleDbDataReader.HasRows)
     {
         while (p_oAdo.m_OleDbDataReader.Read())
         {
             if (p_oAdo.m_OleDbDataReader[strColumn] != System.DBNull.Value &&
                 p_oAdo.m_OleDbDataReader[strColumn].ToString().Trim().Length > 0)
             {
                 listBox1.Items.Add(p_oAdo.m_OleDbDataReader[strColumn].ToString().Trim());
             }
         }
     }
     else
     {
         MessageBox.Show("No items to add to menu list", "FIA Bisoum");
     }
 }
Ejemplo n.º 10
0
        private void LoadCategoryListBox()
        {
            string str = "";

            this.lstMajor.Items.Clear();
            this.m_oAdo.m_strSQL = "SELECT * FROM " + this.m_oQueries.m_oFvs.m_strFvsCatTable;

            m_oAdo.SqlQueryReader(m_oAdo.m_OleDbConnection, m_oAdo.m_strSQL);

            if (m_oAdo.m_OleDbDataReader.HasRows)
            {
                while (m_oAdo.m_OleDbDataReader.Read())
                {
                    if (m_oAdo.m_OleDbDataReader["desc"] != System.DBNull.Value)
                    {
                        str = Convert.ToString(m_oAdo.m_OleDbDataReader["desc"]) + " " +
                              Convert.ToString(m_oAdo.m_OleDbDataReader["min"]).Trim().PadLeft(3, '0') + "-" +
                              Convert.ToString(m_oAdo.m_OleDbDataReader["max"]).Trim().PadLeft(3, '0');
                        this.lstMajor.Items.Add(str);
                    }
                }
            }
            m_oAdo.m_OleDbDataReader.Close();
        }
Ejemplo n.º 11
0
        public uc_biosum_id(string strBiosumId)
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();
            this.m_biosumid = new Biosum_Id();

            this.m_biosumid.strInvId        = strBiosumId.ToString().Substring(0, 1);
            this.m_biosumid.strSecInvId     = strBiosumId.ToString().Substring(1, 4);
            this.m_biosumid.strStateCd      = strBiosumId.ToString().Substring(5, 2);
            this.m_biosumid.strNimsCycle    = strBiosumId.ToString().Substring(7, 2);
            this.m_biosumid.strNimsSubCycle = strBiosumId.ToString().Substring(9, 2);
            this.m_biosumid.strCountyCd     = strBiosumId.ToString().Substring(11, 3);
            this.m_biosumid.strPlot         = strBiosumId.ToString().Substring(14, 7);
            this.m_biosumid.strPnwIdbForestOrBlmDistrict = strBiosumId.ToString().Substring(21, 3);
            if (strBiosumId.Trim().Length == BIOSUM_COND_ID_LENGTH)
            {
                this.m_biosumid.strCondId = strBiosumId.ToString().Substring(24, 1);
                this.lblCondId.Text       = this.m_biosumid.strCondId;
            }
            else
            {
                this.m_biosumid.strCondId = "NA";
                this.lblCondId.Text       = "NA";
            }

            switch (this.m_biosumid.strInvId)
            {
            case "1":
                this.lblInvSource.Text = "FIADB";
                this.lblCycle.Text     = this.m_biosumid.strNimsCycle;
                this.lblSubcycle.Text  = this.m_biosumid.strNimsSubCycle;
                this.lblPNWOrBLM.Text  = "NA";
                break;

            case "2":
                this.lblInvSource.Text = "PNW IDB";
                this.lblCycle.Text     = "NA";
                this.lblSubcycle.Text  = "NA";
                this.lblPNWOrBLM.Text  = this.m_biosumid.strPnwIdbForestOrBlmDistrict;
                break;

            case "3":
                this.lblInvSource.Text = "NIMS";
                this.lblCycle.Text     = this.m_biosumid.strNimsCycle;
                this.lblSubcycle.Text  = this.m_biosumid.strNimsSubCycle;
                this.lblPNWOrBLM.Text  = "NA";
                break;

            default:
                this.lblInvSource.Text = "Unknown";
                this.lblCycle.Text     = "NA";
                this.lblSubcycle.Text  = "NA";
                this.lblPNWOrBLM.Text  = "NA";

                break;
            }

            env             p_oEnv  = new env();
            ado_data_access p_ado   = new ado_data_access();
            string          strFile = p_oEnv.strAppDir + "\\db\\ref_master.mdb";
            string          strConn = "";

            strConn = p_ado.getMDBConnString(strFile, "admin", "");
            string strSQL = "select inv_id_def from inventories where trim(ucase(inv_id)) = '" + this.m_biosumid.strSecInvId.Trim().ToUpper() + "';";

            p_ado.SqlQueryReader(strConn, strSQL);
            if (p_ado.m_intError == 0)
            {
                if (p_ado.m_OleDbDataReader.HasRows == true)
                {
                    p_ado.m_OleDbDataReader.Read();
                    this.lblYearMeasured.Text = p_ado.m_OleDbDataReader["inv_id_def"].ToString().Trim();
                }
                else
                {
                    this.lblYearMeasured.Text = this.m_biosumid.strSecInvId.Trim();
                }
                p_ado.m_OleDbDataReader.Close();
                p_ado.m_OleDbConnection.Close();
            }
            p_ado.m_OleDbDataReader = null;
            p_ado.m_OleDbConnection = null;
            p_ado = null;

            this.lblState.Text  = this.ConvertStateCd(this.m_biosumid.strStateCd);
            this.lblCounty.Text = this.m_biosumid.strCountyCd;
            this.lblPlot.Text   = this.m_biosumid.strPlot;

            // TODO: Add any initialization after the InitializeComponent call
        }
        public void loadgrid(bool p_bScenarioCopy)
        {
            string[] strDeleteSQL = new string[25];
            string   strSQL       = "";
            int      intArrayCount;
            int      x       = 0;
            string   strConn = "";

            string strScenarioMDB = "";

            ado_data_access p_ado = new ado_data_access();

            this.strScenarioId = ReferenceOptimizerScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower();

            /***************************************************
            **scenario mdb connection
            ***************************************************/
            if (p_ado.m_intError != 0)
            {
                return;
            }
            p_ado.getScenarioConnStringAndMDBFile(ref strScenarioMDB,
                                                  ref strConn,
                                                  frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim());

            this.m_OleDbConnectionScenario = new System.Data.OleDb.OleDbConnection();
            p_ado.OpenConnection(strConn, ref this.m_OleDbConnectionScenario);

            /*************************************************************************
            **get the treatment prescription mdb file,table, and connection strings
            *************************************************************************/
            p_ado.getScenarioDataSourceConnStringAndTable(ref this.strRxMDBFile,
                                                          ref this.strRxPackageTableName, ref this.strRxConn,
                                                          "Treatment Packages",
                                                          this.strScenarioId,
                                                          this.m_OleDbConnectionScenario);


            this.m_OleDbRxConn = new System.Data.OleDb.OleDbConnection();
            p_ado.OpenConnection(this.strRxConn, ref this.m_OleDbRxConn);
            if (p_ado.m_intError != 0)
            {
                this.m_OleDbConnectionScenario.Close();
                this.m_OleDbConnectionScenario = null;
                this.m_OleDbRxConn             = null;
                return;
            }
            strSQL = "select * from " + this.strRxPackageTableName;
            p_ado.SqlQueryReader(this.m_OleDbRxConn, strSQL);

            /********************************************************************************
            **insert records into the scenario_last_tiebreak_rank table from the master rxpackage table
            ********************************************************************************/
            if (p_ado.m_intError == 0)
            {
                this.m_DataSet          = new System.Data.DataSet();
                this.m_OleDbDataAdapter = new System.Data.OleDb.OleDbDataAdapter();
                while (p_ado.m_OleDbDataReader.Read())
                {
                    strSQL = "select * from scenario_last_tiebreak_rank " +
                             " where scenario_id = '" + this.strScenarioId + "' and " +
                             "rxpackage = '" + p_ado.m_OleDbDataReader["rxpackage"].ToString() + "';";
                    this.m_OleDbCommand                   = this.m_OleDbConnectionScenario.CreateCommand();
                    this.m_OleDbCommand.CommandText       = strSQL;
                    this.m_OleDbDataAdapter.SelectCommand = this.m_OleDbCommand;
                    this.m_OleDbDataAdapter.Fill(this.m_DataSet, "scenario_last_tiebreak_rank");

                    /*******************************************************************************
                    **if the master treatment record is not found in the scenario db than insert it
                    *******************************************************************************/
                    if (this.m_DataSet.Tables["scenario_last_tiebreak_rank"].Rows.Count == 0)
                    {
                        strSQL = "INSERT INTO scenario_last_tiebreak_rank (scenario_id," +
                                 "rxpackage, last_tiebreak_rank) VALUES " +
                                 "('" + this.strScenarioId + "'," +
                                 "'" + p_ado.m_OleDbDataReader["rxpackage"].ToString() + "'," +
                                 "0);";

                        p_ado.SqlNonQuery(this.m_OleDbConnectionScenario, strSQL);
                    }
                    this.m_DataSet.Tables.Clear();
                }
                p_ado.m_OleDbDataReader.Close();
                this.m_DataSet.Dispose();
                this.m_OleDbDataAdapter.Dispose();


                intArrayCount = 0;

                /****************************************************************************************************
                **delete any prescriptions from the scenario db that do not exist in the master
                ****************************************************************************************************/
                strSQL = "select * from scenario_last_tiebreak_rank where scenario_id = '" + this.strScenarioId + "';";
                p_ado.SqlQueryReader(this.m_OleDbConnectionScenario, strSQL);


                if (p_ado.m_intError == 0)
                {
                    this.m_DataSet          = new System.Data.DataSet();
                    this.m_OleDbDataAdapter = new System.Data.OleDb.OleDbDataAdapter();
                    while (p_ado.m_OleDbDataReader.Read())
                    {
                        /************************************************************************
                        **query the scenario treatment in the master db. If it is not found
                        **in the master db then delete the scenario treatment record
                        ************************************************************************/
                        strSQL = "select * from " + this.strRxPackageTableName +
                                 " where rxpackage = '" + p_ado.m_OleDbDataReader["rxpackage"].ToString() + "';";
                        this.m_OleDbCommand                   = this.m_OleDbRxConn.CreateCommand();
                        this.m_OleDbCommand.CommandText       = strSQL;
                        this.m_OleDbDataAdapter.SelectCommand = this.m_OleDbCommand;
                        this.m_OleDbDataAdapter.Fill(this.m_DataSet, this.strRxPackageTableName);
                        if (this.m_DataSet.Tables[this.strRxPackageTableName].Rows.Count == 0)
                        {
                            strDeleteSQL[intArrayCount] = "DELETE FROM scenario_last_tiebreak_rank" +
                                                          " WHERE scenario_id = '" + this.strScenarioId + "'" +
                                                          " AND rxpackage = '" + p_ado.m_OleDbDataReader["rxpackage"] + "';";
                            intArrayCount++;
                        }
                        this.m_DataSet.Tables.Clear();
                    }

                    p_ado.m_OleDbDataReader.Close();
                    this.m_DataSet.Dispose();
                    this.m_OleDbDataAdapter.Dispose();

                    /**********************************************************************************
                    **if there were any treatments that were loaded into sql delete
                    **arrays then perform the sql to delete the treatments out of the table
                    **********************************************************************************/
                    if (intArrayCount > 0)
                    {
                        for (x = 0; x <= intArrayCount - 1; x++)
                        {
                            p_ado.SqlNonQuery(this.m_OleDbConnectionScenario, strDeleteSQL[x].ToString());
                        }
                    }
                }

                /***************************************************************************************
                **okay, now that the table has been validated and updated lets load the grid to
                **display the treatments to the user
                ***************************************************************************************/
                this.m_DataSet                        = new System.Data.DataSet();
                this.m_OleDbDataAdapter               = new System.Data.OleDb.OleDbDataAdapter();
                this.m_OleDbCommand                   = this.m_OleDbRxConn.CreateCommand();
                this.m_OleDbCommand.CommandText       = "select * from " + this.strRxPackageTableName;
                this.m_OleDbDataAdapter.SelectCommand = this.m_OleDbCommand;
                this.m_OleDbDataAdapter.Fill(this.m_DataSet, this.strRxPackageTableName);

                this.m_OleDbCommand = this.m_OleDbConnectionScenario.CreateCommand();
                strSQL = "";
                for (x = 0; x <= this.m_DataSet.Tables[this.strRxPackageTableName].Rows.Count - 1; x++)
                {
                    if (this.m_DataSet.Tables[this.strRxPackageTableName].Rows[x]["rxpackage"].ToString().Length > 0)
                    {
                        strSQL = "select scenario_id,rxpackage,last_tiebreak_rank from scenario_last_tiebreak_rank where scenario_id = '" + this.strScenarioId + "';";
                        break;
                    }
                }

                /************************************************************
                **if no records in the master prescription table then return
                ************************************************************/
                if (strSQL.Length == 0)
                {
                    this.m_DataSet.Clear();
                    this.m_DataSet.Dispose();
                    this.m_OleDbDataAdapter.Dispose();
                    this.m_OleDbCommand.Dispose();
                    this.m_OleDbConnectionScenario.Close();
                    this.m_OleDbConnectionScenario = null;
                    this.m_OleDbRxConn.Close();
                    this.m_OleDbRxConn = null;
                    return;
                }

                /*******************************
                **create the data sets
                *******************************/
                this.m_OleDbCommand                   = this.m_OleDbConnectionScenario.CreateCommand();
                this.m_OleDbCommand.CommandText       = "select scenario_id,rxpackage,last_tiebreak_rank from scenario_last_tiebreak_rank where scenario_id = '" + this.strScenarioId + "';";
                this.m_OleDbDataAdapter.SelectCommand = this.m_OleDbCommand;
                this.m_OleDbDataAdapter.Fill(this.m_DataSet, "scenario_last_tiebreak_rank");

                /*****************************************************************************
                **add the description column to the scenario last tiebreak rank dataset
                *****************************************************************************/
                this.m_DataSet.Tables["scenario_last_tiebreak_rank"].Columns.Add("Description");

                /********************************************************************************
                **add the treatment description value to the scenrario rx last tiebreak rank data set.
                **the description is only in the master rx table and is added to the
                **scenario last tiebreak rank data set for information purposes.
                ********************************************************************************/

                /***********************************************************************************
                **for loop through the master db rx dataset adding the description field to the
                **scenenario db scenario_last_tiebreak_rank dataset
                ***********************************************************************************/
                for (x = 0; x <= this.m_DataSet.Tables[this.strRxPackageTableName].Rows.Count - 1; x++)
                {
                    if (this.m_DataSet.Tables[this.strRxPackageTableName].Rows[x]["rxpackage"].ToString().Length > 0)
                    {
                        /***************************************************************************************
                        **build the expression to filter only the scenario row that meets the expression
                        ***************************************************************************************/
                        strSQL = "rxpackage = '" + this.m_DataSet.Tables[this.strRxPackageTableName].Rows[x]["rxpackage"] + "'";

                        /***************************************************************************************
                        **create a datarow that will hold the results from the query expression
                        ***************************************************************************************/
                        System.Data.DataRow[] dr1;
                        dr1 = this.m_DataSet.Tables["scenario_last_tiebreak_rank"].Select(strSQL);

                        /***************************************************************************************
                        **check to see if it found the master rx treatment in the sceanrio last tiebreak rank dataset
                        ***************************************************************************************/
                        if (dr1.Length != 0)
                        {
                            /***************************************************************************************
                            **it found it, loop through the dataset and find the row that matches the row
                            **returned from the search expression
                            ***************************************************************************************/
                            for (int y = 0; y <= this.m_DataSet.Tables["scenario_last_tiebreak_rank"].Rows.Count - 1; y++)
                            {
                                if (dr1[0]["rxpackage"] ==
                                    this.m_DataSet.Tables["scenario_last_tiebreak_rank"].Rows[y]["rxpackage"])
                                {
                                    /**********************************************************************************
                                    **update the description row/column with the master db rx table description value
                                    **********************************************************************************/
                                    this.m_DataSet.Tables["scenario_last_tiebreak_rank"].Rows[y]["description"] =
                                        this.m_DataSet.Tables[this.strRxPackageTableName].Rows[x]["description"];
                                    break;
                                }
                            }
                            this.m_DataSet.Tables["scenario_last_tiebreak_rank"].AcceptChanges();
                        }
                    }
                }


                /**************************************************************************************************
                **place the dataset table into a view class so as to not allow new records to be appended
                **************************************************************************************************/
                DataView firstView = new DataView(this.m_DataSet.Tables["scenario_last_tiebreak_rank"]);
                firstView.AllowNew    = false;                    //cannot append new records
                firstView.AllowDelete = false;                    //cannot delete records

                /***************************************************************
                **custom define the grid style
                ***************************************************************/
                DataGridTableStyle tableStyle = new DataGridTableStyle();

                /***********************************************************************
                **map the data grid table style to the last tiebreak rank dataset
                ***********************************************************************/
                tableStyle.MappingName          = "scenario_last_tiebreak_rank";
                tableStyle.AlternatingBackColor = frmMain.g_oGridViewAlternateRowBackgroundColor;
                tableStyle.BackColor            = frmMain.g_oGridViewRowBackgroundColor;
                tableStyle.ForeColor            = frmMain.g_oGridViewRowForegroundColor;
                tableStyle.SelectionBackColor   = frmMain.g_oGridViewSelectedRowBackgroundColor;

                /******************************************************************************
                **since the dataset has things like field name and number of columns,
                **we will use those to create new columnstyles for the columns in our grid
                ******************************************************************************/
                //get the number of columns from the scenario_last_tiebreak_rank data set
                int numCols = this.m_DataSet.Tables["scenario_last_tiebreak_rank"].Columns.Count;

                /***********************************************************************************
                **assign the aColumnTextColumn as type DataGridColoredTextBoxColumn object class
                ***********************************************************************************/
                DataGridColoredTextBoxColumn aColumnTextColumn;

                //loop through all the columns in the dataset
                for (int i = 0; i < numCols; ++i)
                {
                    //create a new instance of the DataGridColoredTextBoxColumn class
                    aColumnTextColumn            = new DataGridColoredTextBoxColumn();
                    aColumnTextColumn.HeaderText = this.m_DataSet.Tables["scenario_last_tiebreak_rank"].Columns[i].ColumnName;
                    //all columns are read-only except the last_tiebreak_rank column
                    if (aColumnTextColumn.HeaderText != "last_tiebreak_rank")
                    {
                        aColumnTextColumn.ReadOnly = true;
                    }
                    //assign the mappingname property the data sets column name
                    aColumnTextColumn.MappingName = this.m_DataSet.Tables["scenario_last_tiebreak_rank"].Columns[i].ColumnName;
                    //add the datagridcoloredtextboxcolumn object to the data grid table style object
                    tableStyle.GridColumnStyles.Add(aColumnTextColumn);
                    //set wider width for some columns
                    switch (aColumnTextColumn.HeaderText)
                    {
                    case "scenario_id":
                        aColumnTextColumn.Width = 150;
                        break;

                    case "Description":
                        aColumnTextColumn.Width = 475;
                        break;
                    }
                }
                dataGrid1.BackgroundColor = frmMain.g_oGridViewBackgroundColor;
                dataGrid1.BackColor       = frmMain.g_oGridViewRowBackgroundColor;
                if (frmMain.g_oGridViewFont != null)
                {
                    dataGrid1.Font = frmMain.g_oGridViewFont;
                }

                // make the dataGrid use our new tablestyle and bind it to our table
                this.dataGrid1.TableStyles.Clear();
                this.dataGrid1.TableStyles.Add(tableStyle);

                // If this is a copied scenario, we will have a reference form to get the values
                if (p_bScenarioCopy == true)
                {
                    if (ReferenceOptimizerScenarioForm.m_oOptimizerScenarioItem_Collection.Item(0).m_oLastTieBreakRankItem_Collection != null)
                    {
                        OptimizerScenarioItem.LastTieBreakRankItem_Collection oLastTieBreakRankItem_Collection = ReferenceOptimizerScenarioForm.m_oOptimizerScenarioItem_Collection.Item(0).m_oLastTieBreakRankItem_Collection;
                        for (int i = 0; i < firstView.Count - 1; ++i)
                        {
                            for (x = 0; x <= oLastTieBreakRankItem_Collection.Count - 1; x++)
                            {
                                if (oLastTieBreakRankItem_Collection.Item(x).RxPackage.Equals(firstView[i]["rxpackage"]))
                                {
                                    firstView[i]["last_tiebreak_rank"] = oLastTieBreakRankItem_Collection.Item(x).LastTieBreakRank;
                                }
                            }
                        }
                    }
                }
                this.dataGrid1.DataSource = firstView;
                this.dataGrid1.Expand(-1);
            }
        }
        public void loadvalues(bool p_bScenarioCopy)
        {
            int x;
            ProcessorScenarioTools oTools = new ProcessorScenarioTools();

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

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

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

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

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


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

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


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

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

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

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

            if (strFullDetailsYN == "Y")
            {
                chkFullDetails.Checked = true;
            }
            else
            {
                chkFullDetails.Checked = false;
            }
        }
Ejemplo n.º 14
0
        public void LoadDataSourceTablesFromListBox(string strScenarioMDB, string strScenarioId,
                                                    System.Windows.Forms.ListBox listBox1, string strDestinationLinkMDB)
        {
            string strSQL         = "";
            string strFullPathMDB = "";
            string strConn        = "";

            int  x       = 0;
            int  y       = 0;
            bool lLoaded = false;

            this.m_intError = 0;

            this.m_intNumberOfOptimizerTables = this.getNumberOfOptimizerTables(strScenarioMDB, strScenarioId);

            //ado specific routines class
            ado_data_access p_ado = new ado_data_access();



            //connect to mdb file containing data sources
            this.m_OleDbConnectionScenario = new System.Data.OleDb.OleDbConnection();
            strConn = p_ado.getMDBConnString(strScenarioMDB, "admin", "");

            p_ado.OpenConnection(strConn, ref this.m_OleDbConnectionScenario);
            if (p_ado.m_intError != 0)
            {
                this.m_intError = p_ado.m_intError;
                p_ado           = null;
                return;
            }

            //go through each of the items in the listbox
            for (y = 0; y <= listBox1.Items.Count - 1; y++)
            {
                lLoaded = false;
                //see if the listbox item is already loaded into a dataset table and the linked mdb table
                if (this.m_intNumberOfOptimizerTablesLoaded != 0)
                {
                    for (x = 0; x <= this.m_intNumberOfOptimizerTables - 1; x++)
                    {
                        if (this.m_strOptimizerTables[x].Trim().Length > 0)
                        {
                            if (listBox1.Items[y].ToString().Trim().ToLower() ==
                                this.m_strOptimizerTables[x].Trim().ToLower())
                            {
                                lLoaded = true;
                                break;
                            }
                        }
                    }
                }
                if (lLoaded == false)
                {
                    //query the MDB datasource table for Optimizer table names
                    strSQL = "SELECT path, file,table_name FROM scenario_datasource WHERE " +
                             " scenario_id = '" + strScenarioId + "' AND " +
                             " table_name = '" + listBox1.Items[y] + "';";
                    p_ado.SqlQueryReader(this.m_OleDbConnectionScenario, strSQL);
                    if (p_ado.m_intError == 0)
                    {
                        //read the record
                        while (p_ado.m_OleDbDataReader.Read())
                        {
                            //look to make sure we have the correct record
                            if (listBox1.Items[y].ToString().Trim().ToUpper()
                                ==
                                p_ado.m_OleDbDataReader["table_name"].ToString().Trim().ToUpper())
                            {
                                strFullPathMDB = p_ado.m_OleDbDataReader["path"].ToString().Trim() + "\\" +
                                                 p_ado.m_OleDbDataReader["file"].ToString().Trim();
                                if (System.IO.File.Exists(strFullPathMDB) == true)
                                {
                                    //used to create a link to the table
                                    dao_data_access p_dao = new dao_data_access();

                                    //create a link to the table in an mdb file
                                    p_dao.CreateTableLink(strDestinationLinkMDB, listBox1.Items[y].ToString().Trim(),
                                                          strFullPathMDB, listBox1.Items[y].ToString().Trim());
                                    p_dao = null;

                                    //connect to mdb file that will be used as the master table link file
                                    this.m_connMasterLink = new System.Data.OleDb.OleDbConnection();
                                    strConn = p_ado.getMDBConnString(strDestinationLinkMDB, "admin", "");

                                    p_ado.OpenConnection(strConn, ref this.m_connMasterLink);
                                    strSQL = "SELECT * FROM " + p_ado.m_OleDbDataReader["table_name"];
                                    this.m_OleDbDataAdapter.SelectCommand = new System.Data.OleDb.OleDbCommand(strSQL, this.m_connMasterLink);
                                    try
                                    {
                                        this.m_OleDbDataAdapter.Fill(this.m_dsOptimizerTables, p_ado.m_OleDbDataReader["table_name"].ToString().Trim());
                                    }
                                    catch (Exception e)
                                    {
                                        MessageBox.Show(e.Message, "Table", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                        this.m_intError = -1;
                                    }
                                    this.m_strOptimizerTables[this.m_intNumberOfOptimizerTablesLoaded] = p_ado.m_OleDbDataReader["table_name"].ToString().Trim();
                                    this.m_intNumberOfOptimizerTablesLoaded++;

                                    this.m_connMasterLink.Close();
                                    this.m_connMasterLink = null;
                                }
                                else
                                {
                                    MessageBox.Show(strFullPathMDB + " does not exist", "Scenario Data Source");
                                    this.m_intError = -1;
                                    p_ado.m_OleDbDataReader.Close();
                                    this.m_OleDbConnection.Close();
                                    p_ado.m_OleDbCommand    = null;
                                    p_ado.m_OleDbDataReader = null;
                                    p_ado = null;
                                    this.m_dsOptimizerTables.Clear();
                                    this.m_dsOptimizerTables = null;
                                    this.m_OleDbDataAdapter.Dispose();
                                    this.m_OleDbDataAdapter = null;
                                    return;
                                }
                            }
                        }
                        p_ado.m_OleDbDataReader.Close();
                    }
                }
            }
            p_ado.m_OleDbDataReader = null;
            p_ado.m_OleDbCommand    = null;

            p_ado = null;
            this.m_OleDbConnectionScenario.Close();
        }
Ejemplo n.º 15
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;
        }
Ejemplo n.º 16
0
        public void loadvalues(ProcessorScenarioItem oProcItem)
        {
            this.lstRxPackages.Clear();
            this.m_oLvRowColors.InitializeRowCollection();

            this.lstRxPackages.Columns.Add("", 2, HorizontalAlignment.Left);
            this.lstRxPackages.Columns.Add("Variant", 75, HorizontalAlignment.Left);
            this.lstRxPackages.Columns.Add("Package", 300, HorizontalAlignment.Left);

            this.lstRxPackages.Columns[COLUMN_CHECKBOX].Width = -2;

            // Create an instance of a ListView column sorter and assign it
            // to the ListView control.
            lvwColumnSorter = new ListViewColumnSorter();
            this.lstRxPackages.ListViewItemSorter = lvwColumnSorter;

            m_oEnv = new env();
            ado_data_access oAdo = new ado_data_access();

            if (String.IsNullOrEmpty(oProcItem.ScenarioId))
            {
                return;
            }

            string[] arr1             = new string[] { "PLOT" };
            string   strPlotTableName = "";
            object   oValue           = frmMain.g_oDelegate.GetValueExecuteControlMethodWithParam(ReferenceOptimizerScenarioForm.uc_datasource1,
                                                                                                  "getDataSourceTableName", arr1, true);

            if (oValue != null)
            {
                string strValue = Convert.ToString(oValue);
                if (strValue != "false")
                {
                    strPlotTableName = strValue;
                }
            }
            string strHarvestCostsPathAndFile = oProcItem.DbPath + "\\" + Tables.ProcessorScenarioRun.DefaultHarvestCostsTableDbFile;

            arr1 = new string[] { "CONDITION" };
            string strCondTableName = "";

            oValue = frmMain.g_oDelegate.GetValueExecuteControlMethodWithParam(ReferenceOptimizerScenarioForm.uc_datasource1,
                                                                               "getDataSourceTableName", arr1, true);
            if (oValue != null)
            {
                string strValue = Convert.ToString(oValue);
                if (strValue != "false")
                {
                    strCondTableName = strValue;
                }
            }

            /**************************************************************
            **create a temporary MDB File that will contain table links
            **to the cond, plot, and harvest_costs tables
            **************************************************************/
            dao_data_access p_dao = new dao_data_access();

            if (System.IO.File.Exists(strHarvestCostsPathAndFile) && p_dao.TableExists(strHarvestCostsPathAndFile,
                                                                                       Tables.ProcessorScenarioRun.DefaultHarvestCostsTableName))
            {
                this.m_strTempMDBFile = this.ReferenceOptimizerScenarioForm.uc_datasource1.CreateMDBAndScenarioTableDataSourceLinks(m_oEnv.strTempDir);

                p_dao.CreateTableLink(this.m_strTempMDBFile,
                                      Tables.ProcessorScenarioRun.DefaultHarvestCostsTableName,
                                      strHarvestCostsPathAndFile, Tables.ProcessorScenarioRun.DefaultHarvestCostsTableName);
                p_dao = null;

                string strTempConn = oAdo.getMDBConnString(this.m_strTempMDBFile, "", "");
                using (var oConn = new OleDbConnection(strTempConn))
                {
                    oConn.Open();
                    oAdo.m_strSQL = "SELECT DISTINCT plot.fvs_variant, harvest_costs.rxpackage, Count(*) AS [Count]" +
                                    " FROM (" + strCondTableName + " INNER JOIN " + strPlotTableName +
                                    " ON " + strCondTableName + ".biosum_plot_id = " + strPlotTableName + ".biosum_plot_id) " +
                                    " INNER JOIN " + Tables.ProcessorScenarioRun.DefaultHarvestCostsTableName +
                                    " ON " + strCondTableName + ".biosum_cond_id = " + Tables.ProcessorScenarioRun.DefaultHarvestCostsTableName + ".biosum_cond_id" +
                                    " GROUP BY FVS_VARIANT, RXPACKAGE";

                    oAdo.SqlQueryReader(oConn, oAdo.m_strSQL);
                    if (oAdo.m_OleDbDataReader.HasRows == true)
                    {
                        while (oAdo.m_OleDbDataReader.Read())
                        {
                            if (oAdo.m_OleDbDataReader["fvs_variant"] != System.DBNull.Value)
                            {
                                //null column
                                this.lstRxPackages.Items.Add(" ");
                                this.lstRxPackages.Items[lstRxPackages.Items.Count - 1].UseItemStyleForSubItems = false;
                                this.lstRxPackages.Items[lstRxPackages.Items.Count - 1].Checked = true;
                                this.m_oLvRowColors.AddRow();
                                this.m_oLvRowColors.AddColumns(lstRxPackages.Items.Count - 1, lstRxPackages.Columns.Count);

                                //fvs_variant
                                this.lstRxPackages.Items[lstRxPackages.Items.Count - 1].SubItems.Add(Convert.ToString(oAdo.m_OleDbDataReader["fvs_variant"]));
                                this.m_oLvRowColors.ListViewSubItem(lstRxPackages.Items.Count - 1,
                                                                    COLUMN_FVS_VARIANT,
                                                                    lstRxPackages.Items[lstRxPackages.Items.Count - 1].SubItems[COLUMN_FVS_VARIANT], false);

                                // rxPackage
                                if (oAdo.m_OleDbDataReader["rxpackage"] != System.DBNull.Value)
                                {
                                    this.lstRxPackages.Items[this.lstRxPackages.Items.Count - 1].SubItems.Add(oAdo.m_OleDbDataReader["rxpackage"].ToString());
                                }
                                else
                                {
                                    this.lstRxPackages.Items[this.lstRxPackages.Items.Count - 1].SubItems.Add(" ");
                                }
                                this.m_oLvRowColors.ListViewSubItem(lstRxPackages.Items.Count - 1,
                                                                    COLUMN_RXPACKAGE,
                                                                    lstRxPackages.Items[lstRxPackages.Items.Count - 1].SubItems[COLUMN_RXPACKAGE], false);
                            }
                        }
                    }
                    oAdo.m_OleDbDataReader.Close();
                }
            }
        }
Ejemplo n.º 17
0
        public void loadvalues()
        {
            int x;

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

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

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

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


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

                        if (oAdo.m_OleDbDataReader["description"] != DBNull.Value &&
                            oAdo.m_OleDbDataReader["description"].ToString().Trim().Length > 0)
                        {
                            entryListItem.SubItems.Add(oAdo.m_OleDbDataReader["description"].ToString().Trim());
                        }
                        else
                        {
                            entryListItem.SubItems.Add(" ");
                        }
                        x = x + 1;
                    }
                }
                this.m_oLvAlternateColors.ListView();
            }
            else
            {
                MessageBox.Show("!!No Scenarios To Copy!!", "FIA Bisoum");
                btnCopy.Enabled = false;
            }
            oAdo.m_OleDbDataReader.Close();
            oAdo.CloseConnection(oAdo.m_OleDbConnection);
        }
Ejemplo n.º 18
0
        public void LoadDataSourceTables(string strScenarioMDB, string strScenarioId)
        {
            string strSQL         = "";
            string strFullPathMDB = "";
            string strConn        = "";


            ado_data_access p_ado = new ado_data_access();



            this.m_OleDbConnectionScenario = new System.Data.OleDb.OleDbConnection();


            strConn = p_ado.getMDBConnString(strScenarioMDB, "admin", "");
            p_ado.OpenConnection(strConn, ref this.m_OleDbConnectionScenario);
            if (p_ado.m_intError != 0)
            {
                p_ado = null;
                return;
            }
            strSQL = "SELECT table_name FROM scenario_datasource WHERE " +
                     " scenario_id = '" + strScenarioId + "';";
            p_ado.SqlQueryReader(this.m_OleDbConnectionScenario, strSQL);



            if (p_ado.m_intError == 0)
            {
                this.m_OleDbDataAdapter              = new System.Data.OleDb.OleDbDataAdapter();
                this.m_dsOptimizerTables             = new DataSet();
                this.m_OleDbCommand                  = new System.Data.OleDb.OleDbCommand();
                this.m_dsOptimizerTables.DataSetName = "LoadAllRecordsFromScenarioDataSource";
                while (p_ado.m_OleDbDataReader.Read())
                {
                    if (p_ado.m_OleDbDataReader["table_name"] != System.DBNull.Value)
                    {
                        if (p_ado.m_OleDbDataReader["table_name"].ToString().Trim().Length > 0)
                        {
                            if (p_ado.m_OleDbDataReader["table_name"].ToString().Trim().ToUpper() == "PLOT" ||
                                p_ado.m_OleDbDataReader["table_name"].ToString().Trim().ToUpper() == "COND")
                            {
                                strFullPathMDB = p_ado.m_OleDbDataReader["path"].ToString().Trim() + "\\" +
                                                 p_ado.m_OleDbDataReader["file"].ToString().Trim();
                                if (System.IO.File.Exists(strFullPathMDB) == true)
                                {
                                    strConn = p_ado.getMDBConnString(strFullPathMDB, "admin", "");
                                    p_ado.OpenConnection(strConn);
                                    if (p_ado.m_intError == 0)
                                    {
                                        this.m_OleDbDataAdapter.SelectCommand.CommandText = "select * from " +
                                                                                            p_ado.m_OleDbDataReader["table_name"].ToString().Trim();
                                        this.m_OleDbDataAdapter.Fill(this.m_dsOptimizerTables, p_ado.m_OleDbDataReader["table_name"].ToString().Trim());
                                    }
                                    else
                                    {
                                        this.m_intError = -1;
                                        p_ado.m_OleDbDataReader.Close();
                                        this.m_OleDbConnection.Close();
                                        p_ado.m_OleDbCommand    = null;
                                        p_ado.m_OleDbDataReader = null;
                                        p_ado = null;
                                        this.m_dsOptimizerTables.Clear();
                                        this.m_dsOptimizerTables = null;
                                        this.m_OleDbDataAdapter.Dispose();
                                        this.m_OleDbDataAdapter = null;
                                        return;
                                    }
                                }
                                else
                                {
                                    //MessageBox.Show(strFullPathMDB + " does not exist","Scenario Data Source", MessageBoxIcon.Error, MessageBoxButtons.OK);
                                    MessageBox.Show(strFullPathMDB + " does not exist", "Scenario Data Source");
                                    this.m_intError = -1;
                                    p_ado.m_OleDbDataReader.Close();
                                    this.m_OleDbConnection.Close();
                                    p_ado.m_OleDbCommand    = null;
                                    p_ado.m_OleDbDataReader = null;
                                    p_ado = null;

                                    this.m_dsOptimizerTables.Clear();
                                    this.m_dsOptimizerTables = null;
                                    this.m_OleDbDataAdapter.Dispose();
                                    this.m_OleDbDataAdapter = null;
                                    return;
                                }
                            }
                        }
                    }
                }

                p_ado.m_OleDbDataReader.Close();
            }
            p_ado.m_OleDbDataReader = null;
            p_ado.m_OleDbCommand    = null;

            p_ado = null;
            this.m_OleDbConnectionScenario.Close();
        }
Ejemplo n.º 19
0
        public void CreateMDBAndCreateOptimizerTableDataSourceLinks(string strScenarioMDB, string strScenarioId, string strDestinationLinkDir)
        {
            string strSQL         = "";
            string strFullPathMDB = "";
            string strConn        = "";

            //ado specific routines class
            ado_data_access p_ado = new ado_data_access();

            //connect to mdb file containing data sources
            this.m_OleDbConnectionScenario = new System.Data.OleDb.OleDbConnection();
            strConn = p_ado.getMDBConnString(strScenarioMDB, "admin", "");

            p_ado.OpenConnection(strConn, ref this.m_OleDbConnectionScenario);
            if (p_ado.m_intError != 0)
            {
                this.m_intError = p_ado.m_intError;
                p_ado           = null;
                return;
            }

            //used to get the temporary random file name
            utils p_utils = new utils();


            //get temporary mdb file
            this.m_strRandomFileName =
                p_utils.getRandomFile(strDestinationLinkDir, "accdb");
            p_utils = null;

            //used to create a link to the table
            dao_data_access p_dao = new dao_data_access();

            //create a temporary mdb that will contain all
            //the links to the Optimizer tables
            p_dao.CreateMDB(this.m_strRandomFileName);


            //query the MDB datasource table for Optimizer table names and location of the table

            strSQL = "SELECT path, file,table_name FROM scenario_datasource WHERE " +
                     " scenario_id = '" + strScenarioId + "';";
            p_ado.SqlQueryReader(this.m_OleDbConnectionScenario, strSQL);
            if (p_ado.m_intError == 0)
            {
                //read the record
                while (p_ado.m_OleDbDataReader.Read())
                {
                    //look to make sure we have the correct record
                    strFullPathMDB = p_ado.m_OleDbDataReader["path"].ToString().Trim() + "\\" +
                                     p_ado.m_OleDbDataReader["file"].ToString().Trim();
                    if (System.IO.File.Exists(strFullPathMDB) == true)
                    {
                        if (p_ado.m_OleDbDataReader["table_name"].ToString().Trim().ToUpper() == "PLOT" ||
                            p_ado.m_OleDbDataReader["table_name"].ToString().Trim().ToUpper() == "COND" ||
                            p_ado.m_OleDbDataReader["table_name"].ToString().Trim().ToUpper() == "FFE")

                        {
                            //create a link to the table in an mdb file
                            p_dao.CreateTableLink(this.m_strRandomFileName, p_ado.m_OleDbDataReader["table_name"].ToString().Trim(),
                                                  strFullPathMDB, p_ado.m_OleDbDataReader["table_name"].ToString().Trim());
                        }
                    }
                }
                p_ado.m_OleDbDataReader.Close();
                p_ado.m_OleDbDataReader = null;
            }
            this.m_OleDbConnectionScenario.Close();
            this.m_OleDbConnectionScenario = null;
            p_ado = null;
            p_dao = null;
        }
        public void loadvalues(ado_data_access p_oAdo, System.Data.OleDb.OleDbConnection p_oConn, string p_strSelectSQL, string p_strDisplayColumn, string p_strSelectColumn, string p_strTable)
        {
            ((frmDialog)this.ParentForm).DialogResult = System.Windows.Forms.DialogResult.OK; p_oAdo.SqlQueryReader(p_oAdo.m_OleDbConnection, p_strSelectSQL);

            if (p_oAdo.m_intError != 0)
            {
                return;
            }
            if (p_oAdo.m_OleDbDataReader.HasRows)
            {
                this.listView1.Clear();
                this.listView1.Columns.Add(" ", 10, HorizontalAlignment.Center);
                this.m_strFieldTypeAString_YN = new string[p_oAdo.m_OleDbDataReader.FieldCount];
                for (int x = 0; x <= p_oAdo.m_OleDbDataReader.FieldCount - 1; x++)
                {
                    this.m_strFieldTypeAString_YN[x] = p_oAdo.getIsTheFieldAStringDataType(p_oAdo.m_OleDbDataReader.GetFieldType(x).FullName.ToString());
                    this.listView1.Columns.Add(p_oAdo.m_OleDbDataReader.GetName(x).ToString(), 100, HorizontalAlignment.Left);
                    if (p_oAdo.m_OleDbDataReader.GetName(x).ToString().Trim().ToUpper() ==
                        p_strDisplayColumn.Trim().ToUpper())
                    {
                        this.m_intDisplayColumn = x;
                    }
                    if (p_oAdo.m_OleDbDataReader.GetName(x).ToString().Trim().ToUpper() ==
                        p_strSelectColumn.Trim().ToUpper())
                    {
                        this.m_intSelectColumn = x;
                    }
                }

                while (p_oAdo.m_OleDbDataReader.Read())
                {
                    if (p_oAdo.m_OleDbDataReader[0] != System.DBNull.Value)
                    {
                        if (p_oAdo.m_OleDbDataReader[0].ToString().Trim().Length > 0)
                        {
                            System.Windows.Forms.ListViewItem entryListItem =
                                listView1.Items.Add("", 0);
                            this.m_oLvAlternateColors.AddRow();
                            this.m_oLvAlternateColors.AddColumns(entryListItem.Index, listView1.Columns.Count);
                            entryListItem.UseItemStyleForSubItems = false;
                            this.m_oLvAlternateColors.ListViewSubItem(entryListItem.Index, 0, entryListItem.SubItems[entryListItem.SubItems.Count - 1], false);
                            for (int x = 0; x <= p_oAdo.m_OleDbDataReader.FieldCount - 1; x++)
                            {
                                this.listView1.Items[entryListItem.Index].SubItems.Add(p_oAdo.m_OleDbDataReader[x].ToString().Trim());
                                this.m_oLvAlternateColors.ListViewSubItem(entryListItem.Index, x + 1, entryListItem.SubItems[entryListItem.SubItems.Count - 1], false);
                            }
                            this.listView1.Items[0].Selected = true;
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("No previous data to choose from", "FIA Biosum", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                ((frmDialog)this.ParentForm).DialogResult = System.Windows.Forms.DialogResult.Cancel;
            }
        }
Ejemplo n.º 21
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;
                }
            }
        }
Ejemplo n.º 22
0
        public uc_processor_tree_spc_edit(ado_data_access p_ado, string p_strTreeSpcTable, string p_strFvsTreeSpcTable, string p_strVariant)
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            m_ado = p_ado;
            // Populate reference dictionary of spcd and fvs_common_name from fvs_tree_species
            m_dictFvsCommonName = new System.Collections.Generic.Dictionary <String, String>();
            m_strTreeSpcTable   = p_strTreeSpcTable;

            if (p_strVariant.Trim().Length > 0)
            {
                p_ado.m_strSQL = "SELECT  spcd,fvs_species,common_name,fvs_common_name " +
                                 "FROM " + p_strFvsTreeSpcTable + " " +
                                 "WHERE LEN(TRIM(fvs_species)) > 0 AND " +
                                 "LEN(TRIM(common_name)) > 0 AND " +
                                 "TRIM(fvs_variant) = '" + p_strVariant.Trim() + "' order by spcd;";

                p_ado.SqlQueryReader(p_ado.m_OleDbConnection, p_ado.m_OleDbTransaction, p_ado.m_strSQL);
                if (p_ado.m_OleDbDataReader.HasRows)
                {
                    while (p_ado.m_OleDbDataReader.Read())
                    {
                        string strMySpCd = Convert.ToString(p_ado.m_OleDbDataReader["spcd"]);
                        this.cmbFvsSpCd.Items.Add(strMySpCd + " - " + Convert.ToString(p_ado.m_OleDbDataReader["common_name"]) + " - " + p_ado.m_OleDbDataReader["fvs_species"]);

                        if (!m_dictFvsCommonName.ContainsKey(strMySpCd))
                        {
                            m_dictFvsCommonName.Add(strMySpCd, Convert.ToString(p_ado.m_OleDbDataReader["fvs_common_name"]));
                        }
                    }
                }

                // Only show fvs variants on the form that exist in the fvs_tree_species table
                p_ado.m_strSQL = "SELECT distinct fvs_variant " +
                                 "FROM " + p_strFvsTreeSpcTable + " ";
                p_ado.SqlQueryReader(p_ado.m_OleDbConnection, p_ado.m_OleDbTransaction, p_ado.m_strSQL);
                if (p_ado.m_OleDbDataReader.HasRows)
                {
                    // Copy all the combo box items into dictionary with variant as key
                    System.Collections.Generic.IDictionary <String, String> dictVariantItems =
                        new System.Collections.Generic.Dictionary <String, String>();
                    for (int i = 0; i < this.cmbVariant.Items.Count; i++)
                    {
                        string strKey = this.cmbVariant.GetItemText(this.cmbVariant.Items[i]).Substring(0, 2);
                        if (!dictVariantItems.ContainsKey(strKey))
                        {
                            dictVariantItems.Add(strKey, this.cmbVariant.GetItemText(this.cmbVariant.Items[i]));
                        }
                    }
                    // Clear combo box items
                    this.cmbVariant.Items.Clear();
                    while (p_ado.m_OleDbDataReader.Read())
                    {
                        string strNextVariant = Convert.ToString(p_ado.m_OleDbDataReader["fvs_variant"]).Trim();
                        // Only add combo box items back that are in the fvs_species table
                        if (dictVariantItems.ContainsKey(strNextVariant))
                        {
                            this.cmbVariant.Items.Add(dictVariantItems[strNextVariant]);
                        }
                    }
                }

                p_ado.m_OleDbDataReader.Close();
            }
            this.m_strFvsTreeSpcTable = p_strFvsTreeSpcTable;
            this.m_strVariant         = p_strVariant;



            // TODO: Add any initialization after the InitializeComponent call
        }
Ejemplo n.º 23
0
        public void loadnotes()
        {
            //set the buttons and menu options
            if (((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.txtShared.Text.Trim().Length > 0 &&
                ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.txtPersonal.Text.Trim().Length > 0)
            {
                this.tbrProjectNotes.Buttons[0].Enabled = true;
                this.tbrProjectNotes.Buttons[1].Enabled = true;
                this.tbrProjectNotes.Buttons[2].Enabled = true;
                this.menuItem1.Enabled = true;
                this.menuItem2.Enabled = true;
                this.menuItem3.Enabled = true;
            }
            else if (((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.txtShared.Text.Trim().Length > 0)
            {
                this.tbrProjectNotes.Buttons[0].Enabled = true;
                this.tbrProjectNotes.Buttons[1].Enabled = false;
                this.tbrProjectNotes.Buttons[2].Enabled = false;
                this.menuItem1.Enabled = true;
                this.menuItem2.Enabled = false;
                this.menuItem3.Enabled = false;
                this.tbrProjectNotes.Buttons[0].Pushed = true;
                this.tbrProjectNotes.Buttons[1].Pushed = false;
                this.tbrProjectNotes.Buttons[2].Pushed = false;
            }
            else if (((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.txtPersonal.Text.Trim().Length > 0)
            {
                this.tbrProjectNotes.Buttons[0].Enabled = false;
                this.tbrProjectNotes.Buttons[1].Enabled = true;
                this.tbrProjectNotes.Buttons[2].Enabled = false;
                this.menuItem1.Enabled = false;
                this.menuItem2.Enabled = true;
                this.menuItem3.Enabled = false;
                this.tbrProjectNotes.Buttons[0].Pushed = false;
                this.tbrProjectNotes.Buttons[1].Pushed = true;
                this.tbrProjectNotes.Buttons[2].Pushed = false;
            }
            else
            {
                this.tbrProjectNotes.Buttons[0].Enabled = false;
                this.tbrProjectNotes.Buttons[1].Enabled = false;
                this.tbrProjectNotes.Buttons[2].Enabled = false;
                this.menuItem1.Enabled = false;
                this.menuItem2.Enabled = false;
                this.menuItem3.Enabled = false;
            }

            if (this.m_bLoadNotes == true)
            {
                string strSQL  = "";
                string strConn = "";
                //string str="";
                ado_data_access p_ado  = new ado_data_access();
                string          strMDB = "";

                if (((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.txtPersonal.Text.Trim().Length > 0)
                {
                    strMDB  = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.txtPersonal.Text.Trim() + "\\personal_project_links_and_notes.mdb";
                    strConn = p_ado.getMDBConnString(strMDB, "admin", "");
                    //strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strMDB + ";User Id=admin;Password=;";
                    p_ado.OpenConnection(strConn);
                    if (p_ado.m_intError == 0)
                    {
                        strSQL = "SELECT TOP 1 * FROM notes;";
                        p_ado.SqlQueryReader(p_ado.m_OleDbConnection, strSQL);

                        if (p_ado.m_intError != 0)
                        {
                            p_ado.m_OleDbConnection.Close();
                        }
                    }
                    if (p_ado.m_intError == 0)
                    {
                        while (p_ado.m_OleDbDataReader.Read())
                        {
                            if (p_ado.m_OleDbDataReader["notes"] != System.DBNull.Value)
                            {
                                if (p_ado.m_OleDbDataReader["notes"].ToString().Trim().Length > 0)
                                {
                                    this.txtNotesPersonal.Text = p_ado.m_OleDbDataReader["notes"].ToString();
                                }
                            }
                        }
                        p_ado.m_OleDbDataReader.Close();
                        p_ado.m_OleDbConnection.Close();
                    }
                }

                if (((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.txtShared.Text.Trim().Length > 0)
                {
                    strMDB  = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.txtShared.Text.Trim() + "\\shared_project_links_and_notes.mdb";
                    strConn = p_ado.getMDBConnString(strMDB, "admin", "");
                    //strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strMDB + ";User Id=admin;Password=;";
                    p_ado.OpenConnection(strConn);
                    if (p_ado.m_intError == 0)
                    {
                        strSQL = "SELECT TOP 1 * FROM notes;";
                        p_ado.SqlQueryReader(p_ado.m_OleDbConnection, strSQL);

                        if (p_ado.m_intError != 0)
                        {
                            p_ado.m_OleDbConnection.Close();
                        }
                    }
                    if (p_ado.m_intError == 0)
                    {
                        while (p_ado.m_OleDbDataReader.Read())
                        {
                            if (p_ado.m_OleDbDataReader["notes"] != System.DBNull.Value)
                            {
                                if (p_ado.m_OleDbDataReader["notes"].ToString().Trim().Length > 0)
                                {
                                    this.txtNotesShared.Text = p_ado.m_OleDbDataReader["notes"].ToString();
                                }
                            }
                        }
                        p_ado.m_OleDbDataReader.Close();
                        p_ado.m_OleDbConnection.Close();
                    }
                }
                this.m_bLoadNotes = false;
                p_ado             = null;
            }
        }
        public void loadvalues()
        {
            m_bSyncd = false;
            ado_data_access oAdo = new ado_data_access();

            int x         = 0;
            int intPathNF = 0;
            int intRootNF = 0;


            this.lvDatasources.Clear();

            ado_data_access p_ado = new ado_data_access();

            this.lvDatasources.Columns.Add(" ", 2, HorizontalAlignment.Left);
            this.lvDatasources.Columns.Add("DataSource", 100, HorizontalAlignment.Left);
            this.lvDatasources.Columns.Add("Scenario", 100, HorizontalAlignment.Left);
            this.lvDatasources.Columns.Add("TableType", 50, HorizontalAlignment.Left);
            this.lvDatasources.Columns.Add("Path", 100, HorizontalAlignment.Left);
            this.lvDatasources.Columns.Add("PathFound", 100, HorizontalAlignment.Left);
            this.lvDatasources.Columns.Add("Synchronized", 100, HorizontalAlignment.Left);

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



            oAdo.m_strSQL =
                "SELECT 'Project' AS DataSource, 'NA' AS Scenario,table_type AS TableType,path FROM project_datasource ";

            if (oAdo.TableExist(oAdo.m_OleDbConnection, "optimizer_scenario"))
            {
                oAdo.m_strSQL = oAdo.m_strSQL +
                                "UNION " +
                                "SELECT 'TreatmentOptimizer' AS DataSource, Scenario_Id AS Scenario,'NA' AS TableType,path FROM optimizer_scenario ";
            }
            if (oAdo.TableExist(oAdo.m_OleDbConnection, "optimizer_scenario_datasource"))
            {
                oAdo.m_strSQL = oAdo.m_strSQL +
                                "UNION " +
                                "SELECT 'TreatmentOptimizer' AS DataSource, Scenario_Id AS Scenario,table_type AS TableType, path FROM optimizer_scenario_datasource ";
            }
            if (oAdo.TableExist(oAdo.m_OleDbConnection, "processor_scenario"))
            {
                oAdo.m_strSQL = oAdo.m_strSQL +
                                "UNION " +
                                "SELECT 'Processor' AS DataSource, Scenario_Id AS Scenario,'NA' AS TableType,path FROM processor_scenario ";
            }
            if (oAdo.TableExist(oAdo.m_OleDbConnection, "processor_scenario_datasource"))
            {
                oAdo.m_strSQL = oAdo.m_strSQL +
                                "UNION " +
                                "SELECT 'Processor' AS DataSource, Scenario_Id AS Scenario,table_type AS TableType, path FROM processor_scenario_datasource ";
            }

            oAdo.SqlQueryReader(oAdo.m_OleDbConnection, oAdo.m_strSQL);

            if (oAdo.m_OleDbDataReader.HasRows)
            {
                while (oAdo.m_OleDbDataReader.Read())
                {
                    // Don't add appData data sources to the grid
                    if (oAdo.m_OleDbDataReader["Path"].ToString().IndexOf("@@appdata@@") == -1)
                    {
                        System.Windows.Forms.ListViewItem entryListItem =
                            this.lvDatasources.Items.Add(" ");
                        entryListItem.UseItemStyleForSubItems = false;
                        this.lvDatasources.Items[x].SubItems.Add(oAdo.m_OleDbDataReader["DataSource"].ToString());
                        this.lvDatasources.Items[x].SubItems.Add(oAdo.m_OleDbDataReader["Scenario"].ToString());
                        this.lvDatasources.Items[x].SubItems.Add(oAdo.m_OleDbDataReader["TableType"].ToString());
                        this.lvDatasources.Items[x].SubItems.Add(oAdo.m_OleDbDataReader["Path"].ToString());
                        if (System.IO.Directory.Exists(oAdo.m_OleDbDataReader["Path"].ToString().Trim()))
                        {
                            ListViewItem.ListViewSubItem FileStatusSubItem =
                                entryListItem.SubItems.Add("Yes");
                            FileStatusSubItem.ForeColor = System.Drawing.Color.White;
                            FileStatusSubItem.BackColor = System.Drawing.Color.Green;
                        }
                        else
                        {
                            ListViewItem.ListViewSubItem FileStatusSubItem =
                                entryListItem.SubItems.Add("No");
                            FileStatusSubItem.ForeColor = System.Drawing.Color.White;
                            FileStatusSubItem.BackColor = System.Drawing.Color.Red;
                            intPathNF++;
                        }
                        if (oAdo.m_OleDbDataReader["Path"].ToString().ToUpper().Contains(lblCurrentProjectRootFolder.Text.Trim().ToUpper()))
                        {
                            ListViewItem.ListViewSubItem SyncStatusSubItem =
                                entryListItem.SubItems.Add("Yes");
                            SyncStatusSubItem.ForeColor = System.Drawing.Color.White;
                            SyncStatusSubItem.BackColor = System.Drawing.Color.Green;
                        }
                        else
                        {
                            ListViewItem.ListViewSubItem SyncStatusSubItem =
                                entryListItem.SubItems.Add("No");
                            SyncStatusSubItem.ForeColor = System.Drawing.Color.White;
                            SyncStatusSubItem.BackColor = System.Drawing.Color.Red;
                            intRootNF++;
                        }
                        x++;
                    }
                }
                lblFolderPaths.Text = intPathNF.ToString().Trim();
                lblProjectRootFolderNotFound.Text = intRootNF.ToString().Trim();
                oAdo.m_OleDbDataReader.Close();
            }
            if (intRootNF > 0)
            {
                btnAnalyze.Enabled = true;
            }
            else
            {
                btnAnalyze.Enabled = false;
            }
            oAdo.m_OleDbConnection.Close();
            oAdo = null;
        }
Ejemplo n.º 25
0
        private void btnHarvestCosts_Click(object sender, System.EventArgs e)
        {
            string strScenarioId = "";
            //string strScenarioMDB="";
            string strConn = "";
            string strSQL  = "";
            string strRandomPathAndFile  = "";
            string strHvstCostsTableName = "";
            string strCondTableName      = "";

            string[] strColumnsToEditArray;
            string   strColumnsToEditList = "";

            string[] strAllColumnsArray;
            string   strAllColumnsList = "";
            string   strScenarioConn = "";
            int      x, y;

            strScenarioId = this.ReferenceOptimizerScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower();

            /*****************************************************************
            **lets see if this harvest costs edit form is already open
            *****************************************************************/
            utils p_oUtils = new utils();

            p_oUtils.m_intLevel = 1;
            if (p_oUtils.FindWindowLike(frmMain.g_oFrmMain.Handle, "Treatment Optimizer: Edit Harvest Costs " + " (" + strScenarioId + ")", "*", true, false) > 0)
            {
                MessageBox.Show("!!Harvest Costs Edit Form Is  Already Open!!", "Harvest Costs Edit Form", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                if (this.m_frmHarvestCosts.WindowState == System.Windows.Forms.FormWindowState.Minimized)
                {
                    this.m_frmHarvestCosts.WindowState = System.Windows.Forms.FormWindowState.Normal;
                }
                this.m_frmHarvestCosts.Focus();
                return;
            }



            ado_data_access p_ado = new ado_data_access();

            strRandomPathAndFile =
                this.ReferenceOptimizerScenarioForm.uc_datasource1.CreateMDBAndScenarioTableDataSourceLinks(this.m_oEnv.strTempDir);
            if (strRandomPathAndFile.Trim().Length > 0)
            {
                strConn = p_ado.getMDBConnString(strRandomPathAndFile, "admin", "");

                strHvstCostsTableName =
                    this.ReferenceOptimizerScenarioForm.uc_datasource1.getDataSourceTableName("Harvest Costs");
                if (strHvstCostsTableName.Trim().Length > 0)
                {
                    strCondTableName =
                        this.ReferenceOptimizerScenarioForm.uc_datasource1.getDataSourceTableName("Condition");
                    if (strCondTableName.Trim().Length > 0)
                    {
                        strColumnsToEditArray = new string[1];
                        strColumnsToEditList  = "";

                        string strScenarioMDB =
                            frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text + "\\" +
                            Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioTableDbFile;

                        strScenarioConn = p_ado.getMDBConnString(strScenarioMDB, "admin", "");

                        strSQL = "SELECT * FROM scenario_harvest_cost_columns WHERE " +
                                 " TRIM(scenario_id) = '" + strScenarioId.Trim() + "';";
                        p_ado.SqlQueryReader(strScenarioConn, strSQL);
                        if (p_ado.m_OleDbDataReader.HasRows)
                        {
                            while (p_ado.m_OleDbDataReader.Read())
                            {
                                if (p_ado.m_OleDbDataReader["ColumnName"] != System.DBNull.Value)
                                {
                                    strColumnsToEditList = strColumnsToEditList + p_ado.m_OleDbDataReader["ColumnName"].ToString().Trim() + ",";
                                }
                            }
                        }
                        p_ado.m_OleDbDataReader.Close();
                        p_ado.m_OleDbDataReader = null;

                        if (strColumnsToEditList.Trim().Length > 0)
                        {
                            strColumnsToEditList  = strColumnsToEditList.Substring(0, strColumnsToEditList.Trim().Length - 1);
                            strColumnsToEditArray = p_oUtils.ConvertListToArray(strColumnsToEditList, ",");
                        }
                        else
                        {
                            //strColumnsToEditArray = new string[2];
                            //strColumnsToEditArray[0] = "water_barring_roads_cpa";
                            //strColumnsToEditArray[1] = "brush_cutting_cpa";
                        }

                        strAllColumnsList  = p_ado.getFieldNames(strConn, "select * from " + strHvstCostsTableName);
                        strAllColumnsArray = p_oUtils.ConvertListToArray(strAllColumnsList, ",");


                        strSQL = "";
                        for (x = 0; x <= strAllColumnsArray.Length - 1; x++)
                        {
                            if (strAllColumnsArray[x].Trim().ToUpper() == "BIOSUM_COND_ID")
                            {
                                strSQL = "biosum_cond_id,";
                                strSQL = strSQL + "mid(biosum_cond_id,6,2) as statecd,mid(biosum_cond_id,12,3) as countycd,mid(biosum_cond_id,15,7) as plot,mid(biosum_cond_id,25,1) as condid,";
                            }

                            else
                            {
                                for (y = 0; y <= strColumnsToEditArray.Length - 1; y++)
                                {
                                    if (strAllColumnsArray[x].Trim().ToUpper() == strColumnsToEditArray[y].Trim().ToUpper())
                                    {
                                        strSQL = strSQL + strColumnsToEditArray[y].Trim() + ",";
                                    }
                                }
                            }
                        }
                        strSQL = strSQL.Substring(0, strSQL.Trim().Length - 1);

                        strSQL = "SELECT DISTINCT " + strSQL + " FROM " + strHvstCostsTableName;

                        this.m_strColumnsToEdit      = strColumnsToEditArray;
                        this.m_intColumnsToEditCount = m_strColumnsToEdit.Length;

                        string[] strRecordKeyField = new string[1];
                        strRecordKeyField[0] = "biosum_cond_id";


                        this.m_frmHarvestCosts = new frmGridView();
                        this.m_frmHarvestCosts.HarvestCostColumns             = true;
                        this.m_frmHarvestCosts.ReferenceOptimizerScenarioForm = this.ReferenceOptimizerScenarioForm;
                        this.m_frmHarvestCosts.LoadDataSetToEdit(strConn, strSQL, strHvstCostsTableName, this.m_strColumnsToEdit, this.m_intColumnsToEditCount, strRecordKeyField);
                        if (this.m_frmHarvestCosts.Visible == false)
                        {
                            this.m_frmHarvestCosts.MdiParent = this.ParentForm.ParentForm;
                            this.m_frmHarvestCosts.Text      = "Treatment Optimizer Analysis: Edit Harvest Costs " + " (" + strScenarioId + ")";
                            this.m_frmHarvestCosts.Show();
                        }
                        this.m_frmHarvestCosts.Focus();
                    }
                }
            }
            p_oUtils = null;
        }
        private void GetExistingColumns()
        {
            int    x;
            string strCol        = "";
            string strFieldsList = "";

            string[] strProcessorColumnsArray = null;

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

            m_oAdo.CloseConnection(oConn);

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



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

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

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

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

            m_strHarvestTableColumnNameList = strFieldsList;
        }