Пример #1
0
 private void btnOpen_Click(object sender, System.EventArgs e)
 {
     //lets see if this scenario is already open
     try
     {
         utils oUtils = new utils();
         oUtils.m_intLevel = -1;
         if (this.ScenarioType.Trim().ToUpper() == "OPTIMIZER")
         {
             if (oUtils.FindWindowLike(frmMain.g_oFrmMain.Handle, "Treatment Optimizer: Optimization Scenario (" + this.lstScenario.SelectedItem.ToString().Trim() + ")", "*", true, false) > 0)
             {
                 MessageBox.Show("!!Scenario Already Open!!", "Scenario Open", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 return;
             }
             ((frmOptimizerScenario)this.ParentForm).DialogResult = DialogResult.OK;
         }
         else
         {
             if (oUtils.FindWindowLike(frmMain.g_oFrmMain.Handle, "Processor: Scenario (" + this.lstScenario.SelectedItem.ToString().Trim() + ")", "*", true, false) > 0)
             {
                 MessageBox.Show("!!Scenario Already Open!!", "Scenario Open", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 return;
             }
             this.ReferenceProcessorScenarioForm.DialogResult = DialogResult.OK;
         }
     }
     catch (Exception err)
     {
         MessageBox.Show("!!Error!! \n" +
                         "Module - uc_scenario:btnOpen_Click  \n" +
                         "Err Msg - " + err.Message.ToString().Trim(),
                         "Open Scenario", System.Windows.Forms.MessageBoxButtons.OK,
                         System.Windows.Forms.MessageBoxIcon.Exclamation);
     }
 }
Пример #2
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;
        }
Пример #3
0
        private void btnHarvestCosts_Click(object sender, System.EventArgs e)
        {
            string strScenarioId = "";
            //string strScenarioMDB="";
            string strConn = "";
            string strSQL  = "";
            string strRandomPathAndFile  = "";
            string strHvstCostsTableName = "";
            string strCondTableName      = "";

            string[] strColumnsToEditArray;
            string   strColumnsToEditList = "";

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

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

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

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



            ado_data_access p_ado = new ado_data_access();

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

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

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

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

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

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

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


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

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

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

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

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


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

            FIA_Biosum_Manager.frmDialog frmTemp = new frmDialog();
            frmTemp.uc_select_list_item1.listBox1.Font = new System.Drawing.Font("Courier New", 8);
            frmTemp.Text = "Table Structure";

            frmTemp.uc_select_list_item1.lblMsg.Text    = "Table structure of " + this.m_table.TableName;
            frmTemp.uc_select_list_item1.lblMsg.Visible = true;

            frmTemp.uc_select_list_item1.Dock = System.Windows.Forms.DockStyle.Fill;

            frmTemp.uc_project1.Visible = false;
            frmTemp.uc_select_list_item1.listBox1.Items.Clear();
            //list the header information
            utils p_utils = new utils();

            //print header information
            //dataset name
            p_utils.LoadStringToCharArray("Structure For DataSet:", ref this.m_printheader.chrLabel, true, 0);
            p_utils.LoadStringToCharArray("  ", ref this.m_printheader.chrFiller, true, 0);
            p_utils.LoadStringToCharArray(this.m_table.TableName, ref this.m_printheader.chrDesc, true, 0);
            p_utils.LoadCharArrayToString(ref str, this.m_printheader.chrLabel, false);
            p_utils.LoadCharArrayToString(ref str, this.m_printheader.chrFiller, false);
            p_utils.LoadCharArrayToString(ref str, this.m_printheader.chrDesc, false);
            frmTemp.uc_select_list_item1.listBox1.Items.Add(str);
            strLargestString = str.Trim();

            //number of records
            str = "";
            p_utils.LoadStringToCharArray("Number Of Records:", ref this.m_printheader.chrLabel, true, 0);
            p_utils.LoadStringToCharArray("  ", ref this.m_printheader.chrFiller, true, 0);
            p_utils.LoadStringToCharArray(this.m_table.Rows.Count.ToString(), ref this.m_printheader.chrDesc, true, 0);
            p_utils.LoadCharArrayToString(ref str, this.m_printheader.chrLabel, true);
            p_utils.LoadCharArrayToString(ref str, this.m_printheader.chrFiller, false);
            p_utils.LoadCharArrayToString(ref str, this.m_printheader.chrDesc, false);
            frmTemp.uc_select_list_item1.listBox1.Items.Add(str);
            if (str.Trim().Length > strLargestString.Trim().Length)
            {
                strLargestString = str.Trim();
            }

            //field information column headers
            p_utils.LoadStringToCharArray("Field", ref this.m_printfield.chrFieldNumber, true, 0);
            p_utils.LoadStringToCharArray("   ", ref this.m_printfield.chrFiller, true, 0);
            p_utils.LoadStringToCharArray("Field Name", ref this.m_printfield.chrFieldName, true, 0);
            p_utils.LoadStringToCharArray("   ", ref this.m_printfield.chrFiller2, true, 0);
            p_utils.LoadStringToCharArray("Type", ref this.m_printfield.chrFieldType, true, 0);
            p_utils.LoadCharArrayToString(ref str, this.m_printfield.chrFieldNumber, true);
            p_utils.LoadCharArrayToString(ref str, this.m_printfield.chrFiller, false);
            p_utils.LoadCharArrayToString(ref str, this.m_printfield.chrFieldName, false);
            p_utils.LoadCharArrayToString(ref str, this.m_printfield.chrFiller2, false);
            p_utils.LoadCharArrayToString(ref str, this.m_printfield.chrFieldType, false);
            frmTemp.uc_select_list_item1.listBox1.Items.Add(str);
            if (str.Trim().Length > strLargestString.Trim().Length)
            {
                strLargestString = str;
            }

            //detail
            for (x = 0; x <= this.m_table.Columns.Count - 1; x++)
            {
                p_utils.LoadStringToCharArray(Convert.ToString(x + 1), ref this.m_printfield.chrFieldNumber, true, 0);
                p_utils.LoadStringToCharArray("   ", ref this.m_printfield.chrFiller, true, 0);
                p_utils.LoadStringToCharArray(this.m_table.Columns[x].ColumnName.ToString(), ref this.m_printfield.chrFieldName, true, 0);
                p_utils.LoadStringToCharArray("   ", ref this.m_printfield.chrFiller2, true, 0);
                p_utils.LoadStringToCharArray(this.m_table.Columns[x].DataType.ToString(), ref this.m_printfield.chrFieldType, true, 0);
                p_utils.LoadCharArrayToString(ref str, this.m_printfield.chrFieldNumber, true);
                p_utils.LoadCharArrayToString(ref str, this.m_printfield.chrFiller, false);
                p_utils.LoadCharArrayToString(ref str, this.m_printfield.chrFieldName, false);
                p_utils.LoadCharArrayToString(ref str, this.m_printfield.chrFiller2, false);
                p_utils.LoadCharArrayToString(ref str, this.m_printfield.chrFieldType, false);
                frmTemp.uc_select_list_item1.listBox1.Items.Add(str);
                if (str.Trim().Length > strLargestString.Trim().Length)
                {
                    strLargestString = str;
                }
            }


            frmTemp.uc_select_list_item1.Initialize_Width(strLargestString + "***********");
            frmTemp.uc_select_list_item1.Visible    = true;
            frmTemp.uc_select_list_item1.btnOK.Text = "Print";
            DialogResult result = frmTemp.ShowDialog();

            if (result == DialogResult.OK)
            {
                printing p_oPrint = new printing();
                p_oPrint.PrintListBoxContents("FIA Biosum Data Set Structure", frmTemp.uc_select_list_item1.listBox1);
                p_oPrint = null;
            }


            frmTemp.Close();
            frmTemp = null;
        }