public void savevalues()
        {
            ado_data_access oAdo           = new ado_data_access();
            string          strScenarioId  = this.ReferenceOptimizerScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower();
            string          strScenarioMDB =
                frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" +
                Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioTableDbFile;

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

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

                oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL);
            }
            oAdo.CloseConnection(oAdo.m_OleDbConnection);
        }
Ejemplo n.º 2
0
        // We do not currently save the list of selected packages. It is reloaded
        // each time a scenario is loaded.
        public int savevalues()
        {
            string strScenarioId;
            int    x = -1;

            ado_data_access p_ado = new ado_data_access();

            strScenarioId = this.ReferenceOptimizerScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower();
            string strScenarioMDB =
                frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" +
                Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioTableDbFile;

            string strConn = p_ado.getMDBConnString(strScenarioMDB, "admin", "");

            p_ado.OpenConnection(strConn);
            if (p_ado.m_intError != 0)
            {
                x     = p_ado.m_intError;
                p_ado = null;
                return(x);
            }

            return(x);
        }
Ejemplo n.º 3
0
        public void SaveScenarioProperties()
        {
            string strTemp1;
            string strTemp2;
            string strSQL  = "";
            bool   bCore   = false;
            string strDesc = "";

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

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

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



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


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


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

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

                                case "CONDITION":
                                    bCore = true;
                                    break;

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

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

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

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

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

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

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

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

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

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


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

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

                System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection();
                string strProjDir     = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectDirectory;
                string strScenarioDir = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectDirectory + "\\" + ScenarioType + "\\db";
                string strFile        = "scenario_" + ScenarioType + "_rule_definitions.mdb";
                if (ScenarioType.Trim().ToUpper() == "OPTIMIZER")
                {
                    ((frmOptimizerScenario)ParentForm).uc_datasource1.strScenarioId        = this.txtScenarioId.Text.Trim();
                    ((frmOptimizerScenario)ParentForm).uc_datasource1.strDataSourceMDBFile = strScenarioDir + "\\scenario_" + ScenarioType + "_rule_definitions.mdb";
                    ((frmOptimizerScenario)ParentForm).uc_datasource1.strDataSourceTable   = "scenario_datasource";
                    ((frmOptimizerScenario)ParentForm).uc_datasource1.strProjectDirectory  = strProjDir;
                }
                else
                {
                    this.ReferenceProcessorScenarioForm.uc_datasource1.strScenarioId        = this.txtScenarioId.Text.Trim();
                    this.ReferenceProcessorScenarioForm.uc_datasource1.strDataSourceMDBFile = strScenarioDir + "\\scenario_" + ScenarioType + "_rule_definitions.mdb";
                    this.ReferenceProcessorScenarioForm.uc_datasource1.strDataSourceTable   = "scenario_datasource";
                    this.ReferenceProcessorScenarioForm.uc_datasource1.strProjectDirectory  = strProjDir;
                }
                StringBuilder strFullPath = new StringBuilder(strScenarioDir);
                strFullPath.Append("\\");
                strFullPath.Append(strFile);
                if (this.txtDescription.Text.Trim().Length > 0)
                {
                    strDesc = p_ado.FixString(this.txtDescription.Text.Trim(), "'", "''");
                }
                string strConn = p_ado.getMDBConnString(strFullPath.ToString(), "admin", "");
                //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFullPath.ToString() + ";User Id=admin;Password=;";
                strSQL = "UPDATE scenario SET description = '" +
                         strDesc +
                         "' WHERE scenario_id = '" + this.txtScenarioId.Text.ToLower() + "';";
                p_ado.SqlNonQuery(strConn, strSQL);
                p_ado = null;
            }
            if (ScenarioType.Trim().ToUpper() == "OPTIMIZER")
            {
                if (((frmOptimizerScenario)this.ParentForm).m_bScenarioOpen == false)
                {
                    ((frmOptimizerScenario)this.ParentForm).Text = "Core Analysis: Optimization Scenario (" + this.txtScenarioId.Text.Trim() + ")";
                    ((frmOptimizerScenario)this.ParentForm).SetMenu("scenario");
                    ((frmOptimizerScenario)this.ParentForm).m_bScenarioOpen = true;
                    this.lblTitle.Text = "";
                    this.Visible       = false;
                }
            }
            else
            {
                if (this.ReferenceProcessorScenarioForm.m_bScenarioOpen == false)
                {
                    this.ReferenceProcessorScenarioForm.Text            = "Processor: Scenario (" + this.txtScenarioId.Text.Trim() + ")";
                    this.ReferenceProcessorScenarioForm.m_bScenarioOpen = true;
                    this.lblTitle.Text = "";
                    this.Visible       = false;
                }
            }
        }
        public void saveTreeGroupings_FromProperties()
        {
            if (!ReferenceProcessorScenarioForm.m_bUsingSqlite)
            {
                ado_data_access _objAdo   = new ado_data_access();
                string          strDbFile = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                                            "\\processor\\" + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeDiamGroupsDbFile;
                _objAdo.OpenConnection(_objAdo.getMDBConnString(strDbFile, "", ""));

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

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

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

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

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

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

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

                    ReferenceProcessorScenarioForm.m_bTreeGroupsCopied = false;
                }
                _objAdo.CloseConnection(_objAdo.m_OleDbConnection);
                _objAdo = null;
            }
            else
            {
                saveTreeGroupings_FromPropertiesSqlite();
            }
        }
        public void 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);
            }
        }
Ejemplo n.º 6
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);
        }
        public void create_travel_times()
        {
            int    intRandomNumber;
            string strRandomNumber;
            string strRandomSave;
            string strMDBFile;
            string strConn;
            string strSQL;
            //string strPsiteRailTravel_YN="N";
            int x;
            int y;

            System.Data.OleDb.OleDbConnection p_conn;
            p_conn = new System.Data.OleDb.OleDbConnection();

            ado_data_access p_ado = new ado_data_access();

            utils p_utils = new utils();

            strMDBFile = this.m_frmMain.frmProject.uc_project1.txtRootDirectory.Text + "\\gis\\db\\gis_travel_times.mdb";
            strConn    = p_ado.getMDBConnString(strMDBFile, "admin", "");
            p_ado.OpenConnection(strConn, ref p_conn);
            p_ado.SqlNonQuery(p_conn, "delete from travel_time");
            if (p_ado.m_intError == 0)
            {
                p_ado.CreateDataSet(p_conn, "select * from plot", "plot");
                if (p_ado.m_intError == 0)
                {
                    p_ado.AddSQLQueryToDataSet(p_conn, ref p_ado.m_OleDbDataAdapter, ref p_ado.m_DataSet, "select * from processing_site where ucase(name) like 'TEST%'", "processing_site");
                    if (p_ado.m_intError == 0)
                    {
                        this.m_frmTherm = new frmTherm();
                        this.m_frmTherm.AbortProcess         = false;
                        this.m_frmTherm.progressBar1.Minimum = 1;
                        this.m_frmTherm.progressBar1.Maximum =
                            p_ado.m_DataSet.Tables["plot"].Rows.Count;
                        m_frmTherm.btnCancel.Visible = true;
                        m_frmTherm.Show();
                        m_frmTherm.Focus();
                        m_frmTherm.Text = "Generating Random Travel Times";
                        m_frmTherm.Refresh();
                        this.m_frmTherm.btnCancel.Click += new System.EventHandler(this.ThermCancel);
                        for (x = 0; x <= p_ado.m_DataSet.Tables["plot"].Rows.Count - 1; x++)
                        {
                            this.m_frmTherm.Increment(x + 1);
                            strRandomSave = "";
                            for (y = 0; y <= p_ado.m_DataSet.Tables["processing_site"].Rows.Count - 1; y++)
                            {
                                for (;;)
                                {
                                    intRandomNumber  = p_utils.RandomNumber(1, 18);
                                    strRandomNumber  = Convert.ToString(intRandomNumber);
                                    intRandomNumber  = p_utils.RandomNumber(0, 9);
                                    strRandomNumber += "." + Convert.ToString(intRandomNumber);
                                    intRandomNumber  = p_utils.RandomNumber(0, 9);
                                    strRandomNumber += Convert.ToString(intRandomNumber);
                                    if (strRandomNumber != strRandomSave)
                                    {
                                        strRandomSave = strRandomNumber;
                                        break;
                                    }
                                }
                                strSQL  = "insert into travel_time (psite_id,biosum_plot_id,travel_mode,travel_time) VALUES ";
                                strSQL += "(" + p_ado.m_DataSet.Tables["processing_site"].Rows[y]["psite_id"].ToString()
                                          + ",'" + p_ado.m_DataSet.Tables["plot"].Rows[x]["biosum_plot_id"].ToString()
                                          + "',1" +
                                          "," + strRandomNumber + ");";
                                p_ado.SqlNonQuery(p_conn, strSQL);
                            }
                            System.Windows.Forms.Application.DoEvents();
                            if (this.m_frmTherm.AbortProcess == true)
                            {
                                break;
                            }
                        }
                        int intStart = 1;
                        this.m_frmTherm.progressBar1.Maximum =
                            p_ado.m_DataSet.Tables["processing_site"].Rows.Count;
                        strRandomSave = "";
                        for (x = 0; x <= p_ado.m_DataSet.Tables["processing_site"].Rows.Count - 1; x++)
                        {
                            this.m_frmTherm.Increment(x + 1);
                            for (y = intStart; y <= p_ado.m_DataSet.Tables["processing_site"].Rows.Count - 1; y++)
                            {
                                strSQL = "";
                                if (p_ado.m_DataSet.Tables["processing_site"].Rows[y]["trancd"].ToString().Trim() == "2")
                                {
                                    strSQL = "insert into travel_time (psite_id,railhead_id,travel_mode,travel_time) values ";
                                }
                                else if (p_ado.m_DataSet.Tables["processing_site"].Rows[y]["trancd"].ToString().Trim() == "3")
                                {
                                    strSQL = "insert into travel_time (psite_id,collector_id,travel_mode,travel_time) values ";
                                }
                                if (strSQL.Trim().Length > 0)
                                {
                                    for (;;)
                                    {
                                        intRandomNumber  = p_utils.RandomNumber(1, 18);
                                        strRandomNumber  = Convert.ToString(intRandomNumber);
                                        intRandomNumber  = p_utils.RandomNumber(0, 9);
                                        strRandomNumber += "." + Convert.ToString(intRandomNumber);
                                        intRandomNumber  = p_utils.RandomNumber(0, 9);
                                        strRandomNumber += Convert.ToString(intRandomNumber);
                                        if (strRandomNumber != strRandomSave)
                                        {
                                            strRandomSave = strRandomNumber;
                                            break;
                                        }
                                    }
                                    strSQL += "(" + p_ado.m_DataSet.Tables["processing_site"].Rows[x]["psite_id"].ToString()
                                              + "," + p_ado.m_DataSet.Tables["processing_site"].Rows[y]["psite_id"].ToString()
                                              + ",2" +
                                              "," + strRandomNumber + ");";
                                    p_ado.SqlNonQuery(p_conn, strSQL);
                                    if (p_ado.m_intError != 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (p_ado.m_intError != 0)
                            {
                                break;
                            }
                            intStart++;
                            System.Windows.Forms.Application.DoEvents();
                            if (this.m_frmTherm.AbortProcess == true)
                            {
                                break;
                            }
                        }
                        if (p_ado.m_intError != 0)
                        {
                        }
                        else
                        {
                            MessageBox.Show("Finished Generating Travel Times");
                        }
                        this.m_frmTherm.Close();
                        this.m_frmTherm = null;
                    }
                    p_ado.m_DataSet.Clear();
                    p_ado.m_DataSet = null;
                    p_ado.m_OleDbDataAdapter.Dispose();
                    p_ado.m_OleDbDataAdapter = null;
                    p_conn.Close();

                    p_ado.m_OleDbConnection = null;
                }
            }
            p_conn  = null;
            p_ado   = null;
            p_utils = null;
        }
        public void DeleteRecords()
        {
            int             row     = 0;
            int             col     = 0;
            bool            lprompt = false;
            DialogResult    result  = DialogResult.None;
            ado_data_access p_ado;


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

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

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

                        if (lprompt == true)
                        {
                            p_ado.SqlNonQuery(p_ado.m_OleDbConnection, sb.ToString());
                        }
                        sb = null;
                    }
                }
            }
            if (lprompt == true)
            {
                p_ado.m_OleDbConnection.Close();
                p_ado.m_OleDbConnection = null;
            }
            p_ado = null;
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
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.º 11
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();
        }
        public void loadvalues()
        {
            int    x, y;
            string strField;

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

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

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

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

            m_oQueries.m_oFvs.LoadDatasource       = true;
            m_oQueries.m_oReference.LoadDatasource = true;
            m_oQueries.LoadDatasources(true);
            m_oAdo = new ado_data_access();
            m_oAdo.OpenConnection(m_oAdo.getMDBConnString(m_oQueries.m_strTempDbFile, "", ""));

            this.lvRxHarvestCostColumns.Clear();

            this.m_oLvAlternateRowColors.InitializeRowCollection();
            this.lvRxHarvestCostColumns.Columns.Add("", 2, HorizontalAlignment.Left);
            this.lvRxHarvestCostColumns.Columns.Add("RxPackage", 80, HorizontalAlignment.Left);
            this.lvRxHarvestCostColumns.Columns.Add("Rx", 80, HorizontalAlignment.Left);
            this.lvRxHarvestCostColumns.Columns.Add("SimCycle", 80, HorizontalAlignment.Left);
            this.lvRxHarvestCostColumns.Columns.Add("Harvest Cost Column", 200, HorizontalAlignment.Left);
            this.lvRxHarvestCostColumns.Columns.Add("Description", 300, HorizontalAlignment.Left);

            this.m_intError = 0;
            this.m_strError = "";

            for (x = 0; x <= this.ReferenceFormRxPackageItem.ReferenceRxItemCollection.Count - 1; x++)
            {
                //
                //1st simulation
                //
                if (ReferenceFormRxPackageItem.ReferenceRxPackageItem.SimulationYear1Rx.Trim() ==
                    ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).RxId.Trim())
                {
                    if (ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection != null)
                    {
                        for (y = 0;
                             y <= ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection.Count - 1;
                             y++)
                        {
                            AddItemToList(1,
                                          ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection.Item(y));
                        }
                    }
                }
                //
                //2nd simulation
                //
                if (ReferenceFormRxPackageItem.ReferenceRxPackageItem.SimulationYear2Rx.Trim() ==
                    ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).RxId.Trim())
                {
                    if (ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection != null)
                    {
                        for (y = 0;
                             y <= ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection.Count - 1;
                             y++)
                        {
                            AddItemToList(2,
                                          ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection.Item(y));
                        }
                    }
                }
                //
                //3rd simulation
                //
                if (ReferenceFormRxPackageItem.ReferenceRxPackageItem.SimulationYear3Rx.Trim() ==
                    ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).RxId.Trim())
                {
                    if (ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection != null)
                    {
                        for (y = 0;
                             y <= ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection.Count - 1;
                             y++)
                        {
                            AddItemToList(3,
                                          ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection.Item(y));
                        }
                    }
                }
                //
                //4th simulation
                //
                if (ReferenceFormRxPackageItem.ReferenceRxPackageItem.SimulationYear4Rx.Trim() ==
                    ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).RxId.Trim())
                {
                    if (ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection != null)
                    {
                        for (y = 0;
                             y <= ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection.Count - 1;
                             y++)
                        {
                            AddItemToList(4,
                                          ReferenceFormRxPackageItem.ReferenceRxItemCollection.Item(x).ReferenceHarvestCostColumnCollection.Item(y));
                        }
                    }
                }
            }


            this.m_oLvAlternateRowColors.ListView();

            this.ReOrderList();
        }
        public void loadvalues()
        {
            int x;

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

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

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

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


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

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

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

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

                        this.uc_processor_scenario_spc_dbh_group_value1.ReferenceProcessorScenarioForm = ReferenceProcessorScenarioForm;

                        this.uc_processor_scenario_spc_dbh_group_value_collection1.Add(this.uc_processor_scenario_spc_dbh_group_value1);
                        this.m_oValidate.ValidateDecimal(ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).ChipsDollarPerCubicFootValue);
                        this.txtChipValue.Text  = this.m_oValidate.ReturnValue;
                        this.m_strChipValueSave = this.txtChipValue.Text;
                    }
                }
                else
                {
                    if (ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).SpeciesGroup.Trim().Length > 0)
                    {
                        uc_processor_scenario_spc_dbh_group_value oItem = new uc_processor_scenario_spc_dbh_group_value();
                        //
                        //SPECIES GROUP
                        //
                        oItem.SpeciesGroup =
                            ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).SpeciesGroup.Trim();
                        //
                        //DBH GROUP
                        //
                        oItem.DbhGroup =
                            ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).DbhGroup.Trim();
                        //
                        //MERCH CUBIC FOOT VALUE
                        //
                        this.m_oValidate.ValidateDecimal(ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).MerchDollarPerCubicFootValue);
                        oItem.CubicFootDollarValue = this.m_oValidate.ReturnValue;
                        //
                        //USE AS ENERGY WOOD
                        oItem.EnergyWood =
                            ReferenceProcessorScenarioForm.m_oProcessorScenarioItem.m_oTreeSpeciesAndDbhDollarValuesItem_Collection.Item(x).UseAsEnergyWood;
                        oItem.Name = "uc_processor_scenario_spc_dbh_group_value" + Convert.ToString(uc_processor_scenario_spc_dbh_group_value_collection1.Count + 1).Trim();
                        this.pnlMerchValues.Controls.Add(oItem);
                        oItem.Top = uc_processor_scenario_spc_dbh_group_value_collection1.Item(uc_processor_scenario_spc_dbh_group_value_collection1.Count - 1).Top +
                                    uc_processor_scenario_spc_dbh_group_value_collection1.Item(uc_processor_scenario_spc_dbh_group_value_collection1.Count - 1).Height;
                        oItem.Left = uc_processor_scenario_spc_dbh_group_value_collection1.Item(uc_processor_scenario_spc_dbh_group_value_collection1.Count - 1).Left;
                        oItem.ReferenceProcessorScenarioForm = ReferenceProcessorScenarioForm;
                        oItem.Visible = true;
                        this.uc_processor_scenario_spc_dbh_group_value_collection1.Add(oItem);
                    }
                }
            }
        }
        private void GetExistingColumns()
        {
            int    x;
            string strCol        = "";
            string strFieldsList = "";

            string[] strProcessorColumnsArray = null;

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

            m_oAdo.CloseConnection(oConn);

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



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

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

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

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

            m_strHarvestTableColumnNameList = strFieldsList;
        }
        public void savevalues()
        {
            //
            //OPEN CONNECTION TO DB FILE CONTAINING PROCESSOR SCENARIO TABLES
            //
            //scenario mdb connection
            ado_data_access oAdo           = new ado_data_access();
            string          strScenarioMDB =
                frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() +
                "\\processor\\db\\scenario_processor_rule_definitions.mdb";

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

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

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

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

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

            oAdo.CloseConnection(oAdo.m_OleDbConnection);
            oAdo = null;
        }
Ejemplo n.º 17
0
        public int savevalues()
        {
            int x = 0;

            //string str="";
            string strSQL            = "";
            string strConn           = "";
            string strRevPerGreenTon = "";

            string strHaulCost;
            string strRailHaulCost;
            string strRailBioTransferCost;
            string strRailMerchTransferCost;


            //ldp strRevPerGreenTon = this.txtRevPerGreenTon_subclass.Text.Replace("$","");
            //ldp strRevPerGreenTon = strRevPerGreenTon.Replace(",","");
            //ldp if (strRevPerGreenTon.Trim().Length == 1) strRevPerGreenTon = "0.00";



            //strHaulCost = this.txtHaulCost_subclass.Text.Replace("$","");
            strHaulCost = RoadHaulCostDollarsPerGreenTonPerHour.Replace("$", "");


            strHaulCost = strHaulCost.Replace(",", "");
            if (strHaulCost.Trim().Length == 1)
            {
                strHaulCost = "0.00";
            }

            //ldp strRailHaulCost = this.txtRailHaulCost_subclass.Text.Replace("$","");
            strRailHaulCost = RailHaulCostDollarsPerGreenTonPerMile.Replace("$", "");
            strRailHaulCost = strRailHaulCost.Replace(",", "");
            if (strRailHaulCost.Trim().Length == 1)
            {
                strRailHaulCost = "0.00";
            }

            //ldp strRailBioTransferCost = this.txtRailChipTransfer_subclass.Text.Replace("$","");
            strRailBioTransferCost = RailChipTransferCostDollarsPerGreenTonPerHour.Replace("$", "");
            strRailBioTransferCost = strRailBioTransferCost.Replace(",", "");
            if (strRailBioTransferCost.Trim().Length == 1)
            {
                strRailBioTransferCost = "0.00";
            }

            //ldp strRailMerchTransferCost = this.txtRailMerchTransfer_subclass.Text.Replace("$","");
            strRailMerchTransferCost = RailMerchTransferCostDollarsPerGreenTonPerHour.Replace("$", "");
            strRailMerchTransferCost = strRailMerchTransferCost.Replace(",", "");
            if (strRailMerchTransferCost.Trim().Length == 1)
            {
                strRailMerchTransferCost = "0.00";
            }



            ado_data_access p_ado          = new ado_data_access();
            string          strScenarioId  = this.ReferenceOptimizerScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower();
            string          strScenarioMDB =
                frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" +
                Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioTableDbFile;

            this.m_OleDbConnectionScenario = new System.Data.OleDb.OleDbConnection();
            strConn = p_ado.getMDBConnString(strScenarioMDB, "admin", "");
            //strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strScenarioMDB + ";User Id=admin;Password=;";
            p_ado.OpenConnection(strConn, ref this.m_OleDbConnectionScenario);
            if (p_ado.m_intError != 0)
            {
                x     = p_ado.m_intError;
                p_ado = null;
                return(x);
            }

            //delete all records from the scenario wind speed class table
            strSQL = "DELETE FROM scenario_costs WHERE " +
                     " scenario_id = '" + strScenarioId + "';";

            p_ado.SqlNonQuery(this.m_OleDbConnectionScenario, strSQL);
            if (p_ado.m_intError < 0)
            {
                this.m_OleDbConnectionScenario.Close();
                x     = p_ado.m_intError;
                p_ado = null;
                return(x);
            }


            strSQL = "INSERT INTO scenario_costs (scenario_id,road_haul_cost_pgt_per_hour,rail_haul_cost_pgt_per_mile,rail_chip_transfer_pgt_per_hour,rail_merch_transfer_pgt_per_hour)" +
                     " VALUES ('" + strScenarioId + "'," +
                     strHaulCost + "," + strRailHaulCost + "," + strRailBioTransferCost + "," + strRailMerchTransferCost + ");";
            p_ado.SqlNonQuery(this.m_OleDbConnectionScenario, strSQL);
            this.m_OleDbConnectionScenario.Close();
            p_ado = null;
            return(0);
        }
Ejemplo n.º 18
0
        private void mnuEditBrowse_Click(object sender, System.EventArgs e)
        {
            //instantiate the datasource class
            //FIA_Biosum_Manager.Datasource p_datasource = new Datasource(((frmDialog)this.ParentForm).m_frmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim());
            FIA_Biosum_Manager.Datasource p_datasource = new Datasource();
            p_datasource.LoadTableColumnNamesAndDataTypes = false;
            p_datasource.LoadTableRecordCount             = false;
            p_datasource.m_strDataSourceMDBFile           = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\db\\project.mdb";
            p_datasource.m_strDataSourceTableName         = "datasource";
            p_datasource.m_strScenarioId = "";
            p_datasource.populate_datasource_array();


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

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

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


                            oAdo.CloseConnection(oAdo.m_OleDbConnection);

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

                            //frmGV.MdiParent = (frmMain)this.ParentForm.ParentForm;
                            frmGV.Text = "Database: Browse And Delete Plot Records";
                            frmGV.LoadDataSetToDeleteOnly(strConn, "select * from " + p_datasource.m_strDataSource[intPlot, TABLE].Trim() + ";", p_datasource.m_strDataSource[intPlot, TABLE].Trim());
                            frmMain.g_oFrmMain.Enabled = false;
                            frmGV.MinimizeMainForm     = true;
                            frmGV.Show();
                            //frmGV.Show();
                            //frmGV.Focus();
                        }
                        else
                        {
                            oAdo.CloseConnection(oAdo.m_OleDbConnection);
                            MessageBox.Show("!!No Records In The PLOT table!!", "BROWSE AND DELETE PLOT RECORDS", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        oAdo.CloseConnection(oAdo.m_OleDbConnection);
                        MessageBox.Show("!!Could not find either the MDB File named \n" +
                                        p_datasource.m_strDataSource[intPlot, MDBFILE] + "\n" +
                                        " or the plot table named \n" +
                                        p_datasource.m_strDataSource[intPlot, TABLE].Trim() + "!!",
                                        "BROWSE AND DELETE PLOT RECORDS",
                                        System.Windows.Forms.MessageBoxButtons.OK,
                                        System.Windows.Forms.MessageBoxIcon.Exclamation);
                    }
                }
            }
            else
            {
                MessageBox.Show("!!Could not find the table type PLOT in the datasource table!!", "BROWSE AND DELETE PLOT RECORDS", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
            }
        }
        public void 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.º 20
0
 public void OpenConnection(ado_data_access p_oAdo)
 {
     InstantiateConnectionObject(p_oAdo);
     p_oAdo.OpenConnection(p_oAdo.getMDBConnString(FullPath, "", ""), ref _oConn);
 }
        public int savevalues()
        {
            int x = 0;

            //const int LANDOWNER_FORESTSERVICE = 10;
            //const int LANDOWNER_OTHERFEDERAL = 20;
            //const int LANDOWNER_STATELOCAL = 30;
            //const int LANDOWNER_PRIVATE = 40;

            //string str="";
            string strSQL  = "";
            string strConn = "";


            ado_data_access p_ado          = new ado_data_access();
            string          strScenarioId  = ((frmOptimizerScenario)this.ParentForm).uc_scenario1.txtScenarioId.Text.Trim().ToLower();
            string          strScenarioMDB =
                ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectDirectory + "\\" +
                Tables.OptimizerScenarioRuleDefinitions.DefaultScenarioTableDbFile;

            this.m_OleDbConnectionScenario = new System.Data.OleDb.OleDbConnection();
            strConn = p_ado.getMDBConnString(strScenarioMDB, "admin", "");
            //strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strScenarioMDB + ";User Id=admin;Password=;";
            p_ado.OpenConnection(strConn, ref this.m_OleDbConnectionScenario);
            if (p_ado.m_intError != 0)
            {
                x     = p_ado.m_intError;
                p_ado = null;
                return(x);
            }

            //delete all records from the scenario wind speed class table
            strSQL = "DELETE FROM scenario_land_owner_groups WHERE " +
                     " scenario_id = '" + strScenarioId + "';";

            p_ado.SqlNonQuery(this.m_OleDbConnectionScenario, strSQL);
            if (p_ado.m_intError < 0)
            {
                this.m_OleDbConnectionScenario.Close();
                x     = p_ado.m_intError;
                p_ado = null;
                return(x);
            }

            if (this.chkOwnGrp10.Checked == true)
            {
                strSQL = "INSERT INTO scenario_land_owner_groups (scenario_id,owngrpcd)" +
                         " VALUES ('" + strScenarioId + "',10);";
                p_ado.SqlNonQuery(this.m_OleDbConnectionScenario, strSQL);
            }

            if (this.chkOwnGrp20.Checked == true)
            {
                strSQL = "INSERT INTO scenario_land_owner_groups (scenario_id,owngrpcd)" +
                         " VALUES ('" + strScenarioId + "',20);";
                p_ado.SqlNonQuery(this.m_OleDbConnectionScenario, strSQL);
            }

            if (this.chkOwnGrp30.Checked == true)
            {
                strSQL = "INSERT INTO scenario_land_owner_groups (scenario_id,owngrpcd)" +
                         " VALUES ('" + strScenarioId + "',30);";
                p_ado.SqlNonQuery(this.m_OleDbConnectionScenario, strSQL);
            }
            if (this.chkOwnGrp40.Checked == true)
            {
                strSQL = "INSERT INTO scenario_land_owner_groups (scenario_id,owngrpcd)" +
                         " VALUES ('" + strScenarioId + "',40);";
                p_ado.SqlNonQuery(this.m_OleDbConnectionScenario, strSQL);
            }

            this.m_OleDbConnectionScenario.Close();
            p_ado = null;
            return(0);
        }
Ejemplo n.º 22
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;
        }
        public void savevalues()
        {
            val_data();
            if (this.m_intError == 0)
            {
                //string strSQL;
                int    x;
                string strMin;
                string strMax;
                string strDef;
                string strId;

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

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

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

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

                            if (oDataMgr.m_intError == 0)
                            {
                                for (x = 0; x <= this.lstTreeDiam.Items.Count - 1; x++)
                                {
                                    strId             = this.lstTreeDiam.Items[x].Text;
                                    strMin            = this.lstTreeDiam.Items[x].SubItems[1].Text;
                                    strMax            = this.lstTreeDiam.Items[x].SubItems[2].Text;
                                    strDef            = this.lstTreeDiam.Items[x].SubItems[3].Text;
                                    oDataMgr.m_strSQL = "INSERT INTO " + Tables.ProcessorScenarioRuleDefinitions.DefaultTreeDiamGroupsTableName + " " +
                                                        "(diam_group,diam_class,min_diam,max_diam,scenario_id) VALUES " +
                                                        "(" + strId + ",'" + strDef.Trim() + "'," +
                                                        strMin + "," + strMax + ",'" + ScenarioId + "');";
                                    oDataMgr.SqlNonQuery(conn, oDataMgr.m_strSQL);
                                    if (oDataMgr.m_intError != 0)
                                    {
                                        break;
                                    }
                                }
                                this.m_intError = oDataMgr.m_intError;
                                oDataMgr        = null;
                            }
                        }
                    }
                }
                if (this.m_intError == 0)
                {
                    this.btnSave.Enabled = false;
                }
            }
        }
        public void 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.º 25
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;
            }
        }