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); } }
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; }