private void btnBrowse_Click(object sender, System.EventArgs e) { if (this.lstFields.Items.Count > 0) { if (this.lstFields.CheckedItems.Count == 0) { MessageBox.Show("!!Select The Columns To Browse!!", "FIA Biosum", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); return; } this.m_strCurConn = this.m_ado.getMDBConnString(this.m_strCurMDBFile, "", ""); this.m_ado.m_strSQL = ""; for (int x = 0; x <= this.lstFields.CheckedItems.Count - 1; x++) { if (this.m_ado.m_strSQL.Trim().Length == 0) { this.m_ado.m_strSQL = this.lstFields.CheckedItems[x].ToString(); } else { this.m_ado.m_strSQL += "," + this.lstFields.CheckedItems[x].ToString(); } } this.m_ado.m_strSQL = "SELECT " + this.m_ado.m_strSQL + " FROM " + this.m_strCurTable; this.m_frmGridView = new frmGridView(); this.m_frmGridView.Text = "Database: Browse (" + this.m_strCurTable.Trim() + ")"; this.m_frmGridView.LoadDataSet(this.m_strCurConn, this.m_ado.m_strSQL, this.m_strCurTable); this.m_frmGridView.Show(); this.m_frmGridView.Focus(); } }
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; }