public void DeleteScenario() { string strSQL = "Delete Scenario '" + this.txtScenarioId.Text + "' (Y/N)?"; DialogResult result = MessageBox.Show(strSQL, "Delete Scenario", MessageBoxButtons.YesNo, MessageBoxIcon.Question); switch (result) { case DialogResult.Yes: break; case DialogResult.No: return; } string strScenarioPath = this.txtScenarioPath.Text; string strScenarioFile = "scenario_" + ScenarioType + "_rule_definitions.mdb"; string strScenarioDir = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectDirectory + "\\" + ScenarioType + "\\db"; string strFile = "scenario_" + ScenarioType + "_rule_definitions.mdb"; //((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectFile; StringBuilder strFullPath = new StringBuilder(strScenarioDir); strFullPath.Append("\\"); strFullPath.Append(strFile); System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection(); ado_data_access p_ado = new ado_data_access(); string strConn = p_ado.getMDBConnString(strFullPath.ToString(), "admin", ""); //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFullPath.ToString() + ";User Id=admin;Password=;"; strSQL = "DELETE * FROM scenario WHERE scenario_id = " + "'" + this.txtScenarioId.Text.Trim() + "'"; p_ado.SqlNonQuery(strConn, strSQL); if (p_ado.m_intError == 0) { strSQL = "DELETE * FROM scenario_datasource WHERE scenario_id = " + "'" + this.txtScenarioId.Text.Trim() + "'"; p_ado.SqlNonQuery(strConn, strSQL); } if (p_ado.m_intError == 0) { strSQL = this.txtScenarioId.Text + " was successfully deleted from the scenario tables. Do you wish to delete the scenario file and directory (Y/N)?"; result = MessageBox.Show(strSQL, "Delete Scenario", MessageBoxButtons.YesNo, MessageBoxIcon.Question); switch (result) { case DialogResult.Yes: strSQL = strScenarioPath + "\\" + strScenarioFile; try { System.IO.Directory.Delete(strScenarioPath, true); } catch { } break; case DialogResult.No: break; } } p_ado = null; this.ParentForm.Close(); }
public void LoadValues() { string strNotes = ""; FIA_Biosum_Manager.ado_data_access oAdo = new ado_data_access(); 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 (ScenarioType.Trim().ToUpper() == "OPTIMIZER") { oAdo.m_strSQL = "SELECT notes FROM scenario WHERE TRIM(scenario_id)='" + this.ReferenceOptimizerScenarioForm.uc_scenario1.strScenarioId.Trim() + "'"; } else { oAdo.m_strSQL = "SELECT notes FROM scenario WHERE TRIM(scenario_id)='" + this.ReferenceProcessorScenarioForm.uc_scenario1.strScenarioId.Trim() + "'"; } strNotes = oAdo.getSingleStringValueFromSQLQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL, "scenario"); oAdo.m_OleDbConnection.Close(); while (oAdo.m_OleDbConnection.State != System.Data.ConnectionState.Closed) { oAdo.m_OleDbConnection.Close(); System.Threading.Thread.Sleep(1000); } oAdo = null; this.txtNotes.Text = strNotes; }
public void loadvalues() { this.m_oQueries.m_oFvs.LoadDatasource = true; this.m_oQueries.LoadDatasources(true); this.m_oAdo.OpenConnection(m_oAdo.getMDBConnString(this.m_oQueries.m_strTempDbFile, "", "")); // //populate category list box // this.LoadRxComboBox(); if (this.ReferenceFormRxPackageItem.m_strAction == "new") { LoadAvailablePackageIdComboBox(); } else { this.cmbRxPackageId.Text = this.ReferenceFormRxPackageItem.m_oRxPackageItem.RxPackageId; this.txtPackageDesc.Text = this.ReferenceFormRxPackageItem.m_oRxPackageItem.Description; this.txtKcpFile.Text = this.ReferenceFormRxPackageItem.m_oRxPackageItem.KcpFile; if (ReferenceFormRxPackageItem.m_oRxPackageItem.RxCycleLength == 10) { this.rdo10YearCycle.Checked = true; } else { this.rdo5YearCycle.Checked = true; } this.cmbRxPackageId.Enabled = false; LoadSimYearGrid(); } }
private void populate_state_combo() { this.cmbState.Items.Clear(); ado_data_access p_ado = new ado_data_access(); env p_env = new env(); string strConn = p_ado.getMDBConnString(p_env.strAppDir.Trim() + "\\db\\utils.mdb", "", ""); try { p_ado.SqlQueryReader(strConn, "select * from states order by stabv"); if (p_ado.m_OleDbDataReader.HasRows == true) { while (p_ado.m_OleDbDataReader.Read()) { string strState = p_ado.m_OleDbDataReader["stabv"].ToString().Trim() + " - " + p_ado.m_OleDbDataReader["state_name"].ToString(); this.cmbState.Items.Add(strState); } } p_ado.m_OleDbDataReader.Close(); p_ado.m_OleDbConnection.Close(); p_ado.m_OleDbConnection.Dispose(); } catch { } p_ado = null; p_env = null; }
public void UpdateDescription() { string strDesc = ""; FIA_Biosum_Manager.ado_data_access oAdo = new ado_data_access(); 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 (this.txtDescription.Text.Trim().Length > 0) { strDesc = oAdo.FixString(this.txtDescription.Text.Trim(), "'", "''"); } oAdo.m_strSQL = "UPDATE scenario SET description='" + strDesc.Trim() + "' WHERE TRIM(scenario_id)='" + this.txtScenarioId.Text.Trim() + "'"; oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL); oAdo.m_OleDbConnection.Close(); while (oAdo.m_OleDbConnection.State != System.Data.ConnectionState.Closed) { oAdo.m_OleDbConnection.Close(); System.Threading.Thread.Sleep(1000); } oAdo = null; }
private string[] loadScenarioArray(ado_data_access oAdo) { // //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 // oAdo.OpenConnection(oAdo.getMDBConnString(strProcessorScenarioMDB, "", "")); string[] strScenarioArray = frmMain.g_oUtils.ConvertListToArray( oAdo.CreateCommaDelimitedList( oAdo.m_OleDbConnection, "SELECT scenario_id " + "FROM scenario " + "WHERE scenario_id IS NOT NULL AND " + "LEN(TRIM(scenario_id)) > 0", ""), ","); oAdo.CloseConnection(oAdo.m_OleDbConnection); return(strScenarioArray); }
public void loadvalues() { int x, y, z; m_oQueries.m_oFvs.LoadDatasource = true; m_oQueries.m_oReference.LoadDatasource = true; m_oQueries.m_oProcessor.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("Rx", 80, HorizontalAlignment.Left); this.lvRxHarvestCostColumns.Columns.Add("Harvest Cost Component", 200, HorizontalAlignment.Left); this.lvRxHarvestCostColumns.Columns.Add("Description", 300, HorizontalAlignment.Left); this.m_intError = 0; this.m_strError = ""; if (this.ReferenceFormRxItem.m_oRxItem.ReferenceHarvestCostColumnCollection != null) { this.lvRxHarvestCostColumns.BeginUpdate(); for (x = 0; x <= this.ReferenceFormRxItem.m_oRxItem.ReferenceHarvestCostColumnCollection.Count - 1; x++) { if (ReferenceFormRxItem.m_oRxItem.ReferenceHarvestCostColumnCollection.Item(x).Delete == false) { FIA_Biosum_Manager.RxItemHarvestCostColumnItem oItem = ReferenceFormRxItem.m_oRxItem.ReferenceHarvestCostColumnCollection.Item(x); this.lvRxHarvestCostColumns.Items.Add(""); this.lvRxHarvestCostColumns.Items[lvRxHarvestCostColumns.Items.Count - 1].UseItemStyleForSubItems = false; for (z = 1; z <= this.lvRxHarvestCostColumns.Columns.Count - 1; z++) { this.lvRxHarvestCostColumns.Items[lvRxHarvestCostColumns.Items.Count - 1].SubItems.Add(" "); } this.lvRxHarvestCostColumns.Items[lvRxHarvestCostColumns.Items.Count - 1].SubItems[COLUMN_RX].Text = oItem.RxId; this.lvRxHarvestCostColumns.Items[lvRxHarvestCostColumns.Items.Count - 1].SubItems[COLUMN_FIELD].Text = oItem.HarvestCostColumn; this.lvRxHarvestCostColumns.Items[lvRxHarvestCostColumns.Items.Count - 1].SubItems[COLUMN_DESC].Text = oItem.Description; this.m_oLvAlternateRowColors.AddRow(); this.m_oLvAlternateRowColors.AddColumns(lvRxHarvestCostColumns.Items.Count - 1, this.lvRxHarvestCostColumns.Columns.Count); } } this.lvRxHarvestCostColumns.EndUpdate(); } this.m_oLvAlternateRowColors.ListView(); if (this.lvRxHarvestCostColumns.Items.Count > 0) { this.lvRxHarvestCostColumns.Items[0].Selected = true; ReferenceFormRxItem.m_bToolBarButtonEnabled[frmRxItem.UC_HARVESTCOST, frmRxItem.BUTTON_CLEARALL] = true; ReferenceFormRxItem.m_bToolBarButtonEnabled[frmRxItem.UC_HARVESTCOST, frmRxItem.BUTTON_DELETE] = true; ReferenceFormRxItem.m_bToolBarButtonEnabled[frmRxItem.UC_HARVESTCOST, frmRxItem.BUTTON_EDIT] = true; } }
public void SaveScenarioNotes() { ado_data_access p_ado = new ado_data_access(); System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection(); string strProjDir = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim(); string strScenarioDir = strProjDir + "\\" + ScenarioType + "\\db"; string strFile = "scenario_" + ScenarioType + "_rule_definitions.mdb"; //((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.m_strProjectFile; StringBuilder strFullPath = new StringBuilder(strScenarioDir); strFullPath.Append("\\"); strFullPath.Append(strFile); string strNotes = this.txtNotes.Text; string strSQL = ""; strNotes = p_ado.FixString(strNotes, "'", "''"); string strConn = p_ado.getMDBConnString(strFullPath.ToString(), "admin", ""); //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFullPath.ToString() + ";User Id=admin;Password=;"; if (ScenarioType.Trim().ToUpper() == "OPTIMIZER") { strSQL = "UPDATE scenario SET notes = '" + strNotes + "' WHERE trim(lcase(scenario_id)) = '" + ((frmOptimizerScenario)this.ParentForm).uc_scenario1.txtScenarioId.Text.Trim().ToLower() + "';"; } else { strSQL = "UPDATE scenario SET notes = '" + strNotes + "' WHERE trim(lcase(scenario_id)) = '" + this.ReferenceProcessorScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower() + "';"; } p_ado.SqlNonQuery(strConn, strSQL); p_ado = null; }
private void InitializeVariantLocationDictionary() { m_ado = new ado_data_access(); dictVariantLocations = new Dictionary <string, List <string> >(); using (var conn = new OleDbConnection(m_ado.getMDBConnString( frmMain.g_oEnv.strApplicationDataDirectory.Trim() + frmMain.g_strBiosumDataDir + "\\" + Tables.Reference.DefaultBiosumReferenceDbFile, "", ""))) { conn.Open(); m_ado.SqlQueryReader(conn, "SELECT DISTINCT fvs_variant, fvsloccode FROM fiadb_fvs_variant;"); if (this.m_ado.m_intError == 0) { if (this.m_ado.m_OleDbDataReader.HasRows) { string variant = ""; string location = ""; while (this.m_ado.m_OleDbDataReader.Read()) { variant = m_ado.m_OleDbDataReader["fvs_variant"].ToString().Trim(); if (!dictVariantLocations.ContainsKey(variant)) { dictVariantLocations.Add(variant, new List <string>()); } location = m_ado.m_OleDbDataReader["fvsloccode"].ToString().Trim(); dictVariantLocations[variant].Add(location); } } } m_ado.m_OleDbDataReader.Dispose(); } m_ado = null; }
private void saveprivate() { ado_data_access p_ado = new ado_data_access(); string strMDB = ((frmMain)this.ParentForm.ParentForm).frmProject.uc_project1.txtPersonal.Text.Trim() + "\\personal_project_links_and_notes.mdb"; string strConn = p_ado.getMDBConnString(strMDB, "admin", ""); //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strMDB + ";User Id=admin;Password=;"; string strSQL = ""; p_ado.OpenConnection(strConn); if (p_ado.m_intError == 0) { try { string strNotes = this.txtNotesPersonal.Text; strNotes = p_ado.FixString(strNotes, "'", "''"); if ((int)p_ado.getRecordCount(p_ado.m_OleDbConnection, "SELECT COUNT(*) FROM NOTES", "NOTES") > 0) { strSQL = "UPDATE NOTES SET NOTES = '" + strNotes + "'"; p_ado.SqlNonQuery(p_ado.m_OleDbConnection, strSQL); } else { strSQL = "INSERT INTO NOTES (NOTES) VALUES ('" + strNotes + "')"; p_ado.SqlNonQuery(p_ado.m_OleDbConnection, strSQL); } } catch { } } p_ado = null; }
private void ExecuteDeleteOnTables(string strDbPathFile, string[] tables = null, string[] exceptions = null) { using (var conn = new OleDbConnection(m_ado.getMDBConnString(strDbPathFile, "", ""))) { conn.Open(); string[] strTables = tables; if (tables == null || tables.Length == 0) { strTables = m_ado.getTableNamesOfSpecificTypes(conn); //In case none of the tables are valid if (strTables.Length == 1 && strTables[0] == "") { return; } } string column; foreach (string table in strTables) { if (exceptions != null && exceptions.Contains(table)) { continue; } column = null; foreach (string col in m_dictIdentityColumnsToValues.Keys) { if (m_ado.ColumnExist(conn, table, col)) { column = col; break; } } if (!String.IsNullOrEmpty(column) && m_dictIdentityColumnsToValues[column].Count > 0) { m_ado.AddIndex(conn, table, column + "_delete_idx", column); if (frmMain.g_bDebug) { // var message = Checked(chkDeletesDisabled) // ? "\r\nCounting records to delete from " + strDbPathFile + " " + table + " using " + column + "\r\n" // : "\r\nDeleting from " + strDbPathFile + " " + table + " using " + column + "\r\n"; frmMain.g_oUtils.WriteText(m_strDebugFile, Checked(chkDeletesDisabled) ? "\r\nCounting records to delete from " + strDbPathFile + " " + table + " using " + column + "\r\n" : "\r\nDeleting from " + strDbPathFile + " " + table + " using " + column + "\r\n"); } int deletedRecords = BuildAndExecuteDeleteSQLStmts(conn, table, column); AddDeletedCountToDictionary(strDbPathFile, table, deletedRecords); m_ado.SqlNonQuery(conn, String.Format("DROP INDEX {0} ON {1}", column + "_delete_idx", table)); } } } if (Checked(chkCompactMDB)) { m_dao.CompactMDB(strDbPathFile); } }
public void SaveScenarioNotes() { ado_data_access p_ado = null; SQLite.ADO.DataMgr oDataMgr = null; string strNotes = this.txtNotes.Text; string strProjDir = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim(); string strScenarioDir = strProjDir + "\\" + ScenarioType + "\\db"; if ((ReferenceProcessorScenarioForm != null && !ReferenceProcessorScenarioForm.m_bUsingSqlite) || ScenarioType.Trim().ToUpper() == "OPTIMIZER") { p_ado = new ado_data_access(); strNotes = p_ado.FixString(strNotes, "'", "''"); string strSQL = ""; if (ScenarioType.Trim().ToUpper() == "OPTIMIZER") { strSQL = "UPDATE scenario SET notes = '" + strNotes + "' WHERE trim(lcase(scenario_id)) = '" + ((frmOptimizerScenario)this.ParentForm).uc_scenario1.txtScenarioId.Text.Trim().ToLower() + "';"; } else { strSQL = "UPDATE scenario SET notes = '" + strNotes + "' WHERE trim(lcase(scenario_id)) = '" + this.ReferenceProcessorScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower() + "';"; } System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection(); string strFile = "scenario_" + ScenarioType + "_rule_definitions.mdb"; StringBuilder strFullPath = new StringBuilder(strScenarioDir); strFullPath.Append("\\"); strFullPath.Append(strFile); string strConn = p_ado.getMDBConnString(strFullPath.ToString(), "admin", ""); p_ado.SqlNonQuery(strConn, strSQL); p_ado = null; } else { oDataMgr = new SQLite.ADO.DataMgr(); strNotes = oDataMgr.FixString(strNotes, "'", "''"); //@ToDo: Only support Processor at this time string strSQL = "UPDATE scenario SET notes = '" + strNotes + "' WHERE trim(lower(scenario_id)) = '" + this.ReferenceProcessorScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower() + "';"; string strFile = "scenario_" + ScenarioType + "_rule_definitions.db"; StringBuilder strFullPath = new StringBuilder(strScenarioDir); strFullPath.Append("\\"); strFullPath.Append(strFile); string strConn = oDataMgr.GetConnectionString(strFullPath.ToString()); using (System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection(strConn)) { conn.Open(); oDataMgr.SqlNonQuery(conn, strSQL); } oDataMgr = null; } }
public void loadvalues() { if (this.ReferenceFormRxItem.m_strAction == "edit") { this.lblMajor.Hide(); this.lblMinor.Hide(); this.lblId.Hide(); this.lstMajor.Hide(); this.lstMinor.Hide(); this.lstId.Hide(); this.lblRxId.Top = this.lblMajor.Top; this.txtRxId.Top = this.lblRxId.Top; this.txtRxId.Left = 104; this.lblCategory.Top = this.lblRxId.Top + this.lblRxId.Height + 10; this.txtCategory.Top = this.lblCategory.Top; this.txtCategory.Left = 104; this.lblSubCategory.Top = this.lblCategory.Top + this.lblCategory.Height + 10; this.txtSubCategory.Top = this.lblSubCategory.Top; this.txtSubCategory.Left = 104; this.lblDesc.Top = this.lblSubCategory.Top + this.lblSubCategory.Height + 10; this.lblPackageMember.Top = this.lblDesc.Top; this.txtDesc.Top = this.lblDesc.Top + this.lblDesc.Height + 5; this.txtDesc.Height = this.ClientSize.Height - this.txtDesc.Top - 5; this.lstPackageMember.Top = this.txtDesc.Top; this.lstPackageMember.Height = this.txtDesc.Height; this.btnSelectRxId.Hide(); this.lblId.Hide(); this.txtRxId.Text = this.ReferenceFormRxItem.m_oRxItem.RxId; this.txtDesc.Text = this.ReferenceFormRxItem.m_oRxItem.Description; this.txtCategory.Text = this.ReferenceFormRxItem.m_oRxItem.Category; this.txtSubCategory.Text = this.ReferenceFormRxItem.m_oRxItem.SubCategory; this.txtRxId.Enabled = false; this.txtCategory.Enabled = false; this.txtSubCategory.Enabled = false; if (this.ReferenceFormRxItem.m_oRxItem.RxPackageMemberList.Trim().Length > 0) { string[] strArray = frmMain.g_oUtils.ConvertListToArray(ReferenceFormRxItem.m_oRxItem.RxPackageMemberList, ","); for (int x = 0; x <= strArray.Length - 1; x++) { this.lstPackageMember.Items.Add(strArray[x]); } } } else { this.m_oQueries.m_oFvs.LoadDatasource = true; this.m_oQueries.LoadDatasources(true); this.m_oAdo.OpenConnection(m_oAdo.getMDBConnString(this.m_oQueries.m_strTempDbFile, "", "")); // //populate category list box // this.LoadCategoryListBox(); } }
public void populate_scenario_listbox() { string strScenarioId = ""; string strDescription = ""; //string strScenarioMDBFile=""; string strScenarioPath = ""; System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection(); string strProjDir = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim(); string strScenarioDir = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" + ScenarioType + "\\db"; string strFile = "scenario_" + ScenarioType + "_rule_definitions.mdb"; StringBuilder strFullPath = new StringBuilder(strScenarioDir); strFullPath.Append("\\"); strFullPath.Append(strFile); ado_data_access p_ado = new ado_data_access(); string strConn = p_ado.getMDBConnString(strFullPath.ToString(), "admin", ""); p_ado.SqlQueryReader(strConn, "select * from scenario"); if (p_ado.m_intError == 0) { try { this.lstScenario.Items.Clear(); while (p_ado.m_OleDbDataReader.Read()) { strScenarioId = p_ado.m_OleDbDataReader["scenario_id"].ToString(); //strScenarioMDBFile = p_ado.m_OleDbDataReader["file"].ToString(); strDescription = p_ado.m_OleDbDataReader["description"].ToString(); strScenarioPath = p_ado.m_OleDbDataReader["path"].ToString(); this.lstScenario.Items.Add(p_ado.m_OleDbDataReader["scenario_id"].ToString()); } this.lstScenario.SelectedIndex = this.lstScenario.Items.Count - 1; this.txtScenarioPath.Text = strScenarioPath; this.txtDescription.Text = strDescription; } catch (Exception caught) { intError = -1; strError = caught.Message; MessageBox.Show(strError); } p_ado.m_OleDbDataReader.Close(); p_ado.m_OleDbDataReader = null; p_ado.m_OleDbCommand = null; p_ado.m_OleDbConnection.Close(); p_ado.m_OleDbConnection = null; } p_ado = null; }
private string getNextScenarioId() { System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection(); string strProjDir = frmMain.g_oFrmMain.getProjectDirectory(); string strScenarioDir = strProjDir + "\\" + ScenarioType + "\\db"; string strFile = "scenario_" + ScenarioType + "_rule_definitions.mdb"; System.Text.StringBuilder strFullPath = new System.Text.StringBuilder(strScenarioDir); strFullPath.Append("\\"); strFullPath.Append(strFile); ado_data_access oAdo = new ado_data_access(); string strConn = oAdo.getMDBConnString(strFullPath.ToString(), "admin", ""); oAdo.OpenConnection(strConn); string strSQL = "SELECT scenario_id from " + Tables.Scenario.DefaultScenarioTableName; System.Collections.Generic.IList <string> lstExistingScenarios = new System.Collections.Generic.List <string>(); oAdo.SqlQueryReader(oAdo.m_OleDbConnection, strSQL); if (oAdo.m_OleDbDataReader.HasRows) { // Load all of the existing scenarios into a list we can query while (oAdo.m_OleDbDataReader.Read()) { string strScenario = Convert.ToString(oAdo.m_OleDbDataReader["scenario_id"]).Trim(); if (!String.IsNullOrEmpty(strScenario)) { lstExistingScenarios.Add(strScenario); } } } oAdo.CloseConnection(oAdo.m_OleDbConnection); int i = 1; string strTestName; // keep incrementing the scenario name until we find one that doesn't exist while (i < (lstExistingScenarios.Count + 1)) { strTestName = "scenario" + Convert.ToString(i); if (!lstExistingScenarios.Contains(strTestName)) { break; } i++; } strTestName = "scenario" + Convert.ToString(i); return(strTestName); }
private void Save() { string strPath = ""; string strDatasource = ""; string strTableType = ""; string strScenario = ""; ado_data_access oAdo = new ado_data_access(); oAdo.OpenConnection(oAdo.getMDBConnString(m_strRandomPathAndFile, "", "")); for (int x = 0; x <= lvDatasources.Items.Count - 1; x++) { strDatasource = lvDatasources.Items[x].SubItems[COLUMN_DATASOURCE].Text.Trim(); strTableType = lvDatasources.Items[x].SubItems[COLUMN_TABLETYPE].Text.Trim(); strPath = lvDatasources.Items[x].SubItems[COLUMN_PATH].Text.Trim(); strScenario = lvDatasources.Items[x].SubItems[COLUMN_SCENARIO].Text.Trim(); oAdo.m_strSQL = ""; if (strDatasource == "Project") { oAdo.m_strSQL = "UPDATE project_datasource SET path = '" + strPath + "' WHERE TRIM(Table_Type) = '" + strTableType + "'"; } else if (strDatasource == "TreatmentOptimizer" && strTableType == "NA") { oAdo.m_strSQL = "UPDATE optimizer_scenario SET path = '" + strPath + "' WHERE TRIM(scenario_id) = '" + strScenario + "'"; } else if (strDatasource == "TreatmentOptimizer") { oAdo.m_strSQL = "UPDATE optimizer_scenario_datasource SET path = '" + strPath + "' WHERE TRIM(scenario_id) = '" + strScenario + "' AND TRIM(Table_Type) = '" + strTableType + "'"; } else if (strDatasource == "Processor" && strTableType == "NA") { oAdo.m_strSQL = "UPDATE processor_scenario SET path = '" + strPath + "' WHERE TRIM(scenario_id) = '" + strScenario + "'"; } else if (strDatasource == "Processor") { oAdo.m_strSQL = "UPDATE processor_scenario_datasource SET path = '" + strPath + "' WHERE TRIM(scenario_id) = '" + strScenario + "' AND TRIM(Table_Type) = '" + strTableType + "'"; } if (oAdo.m_strSQL.Trim().Length > 0) { oAdo.SqlNonQuery(oAdo.m_OleDbConnection, oAdo.m_strSQL); } } oAdo.CloseConnection(oAdo.m_OleDbConnection); MessageBox.Show("Done", "FIA Biosum"); m_bSyncd = false; }
public void loadvalues() { ScenarioId = this.ReferenceProcessorScenarioForm.uc_scenario1.txtScenarioId.Text.Trim().ToLower(); m_oAdo = new ado_data_access(); m_oAdo.OpenConnection(m_oAdo.getMDBConnString(this.ReferenceProcessorScenarioForm.LoadedQueries.m_strTempDbFile, "", "")); ReferenceProcessorScenarioForm.m_oProcessorScenarioTools.LoadMoveInCosts (frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\processor\\db\\scenario_processor_rule_definitions.mdb", ReferenceProcessorScenarioForm.m_oProcessorScenarioItem); FIA_Biosum_Manager.ProcessorScenarioItem oItem = ReferenceProcessorScenarioForm.m_oProcessorScenarioItem; if (ReferenceProcessorScenarioForm.m_oProcessorScenarioTools.m_intError == 0) { this.txtYardDistThreshold.Text = oItem.m_oMoveInCosts.YardDistThreshold; this.txtAssumedHarvestArea.Text = oItem.m_oMoveInCosts.AssumedHarvestAreaAc; this.txtMoveInTimeMultiplier.Text = oItem.m_oMoveInCosts.MoveInTimeMultiplier; this.txtMoveInAddend.Text = oItem.m_oMoveInCosts.MoveInHoursAddend; } }
public void loadvalues() { int x; this.txtDesc.Text = ""; this.txtRxDesc.Text = ""; this.txtSteepSlopeDesc.Text = ""; 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, "", "")); if (m_oAdo.m_intError == 0) { this.m_oRxTools.LoadRxHarvestMethods(m_oAdo, m_oAdo.m_OleDbConnection, m_oQueries, cmbMethod, cmbSteepSlopeMethod); for (x = 0; x <= this.cmbMethod.Items.Count - 1; x++) { if (ReferenceFormRxItem.m_oRxItem.HarvestMethodLowSlope.Trim().ToUpper() == cmbMethod.Items[x].ToString().Trim().ToUpper()) { cmbMethod.Text = cmbMethod.Items[x].ToString().Trim(); } } for (x = 0; x <= this.cmbSteepSlopeMethod.Items.Count - 1; x++) { if (ReferenceFormRxItem.m_oRxItem.HarvestMethodSteepSlope.Trim().ToUpper() == cmbSteepSlopeMethod.Items[x].ToString().Trim().ToUpper()) { cmbSteepSlopeMethod.Text = cmbSteepSlopeMethod.Items[x].ToString().Trim(); } } //if (ReferenceFormRxItem != null) //{ // if (this.cmbMethod.Text.Trim().Length > 0) this.getDesc(); // if (this.cmbSteepSlopeMethod.Text.Trim().Length > 0) this.getDescSteepSlope(); // this.txtRxDesc.Text = ReferenceFormRxItem.m_oRxItem.Description; //} } this.txtRxDesc.Text = this.ReferenceFormRxItem.m_oRxItem.Description; }
public int getNumberOfOptimizerTables(string strScenarioMDB, string strScenarioId) { int intCount = 0; System.Data.OleDb.OleDbConnection p_conn; ado_data_access p_ado = new ado_data_access(); p_conn = new System.Data.OleDb.OleDbConnection(); string strConn = p_ado.getMDBConnString(strScenarioMDB, "admin", ""); p_ado.OpenConnection(strConn, ref p_conn); if (p_ado.m_intError != 0) { p_ado = null; return(intCount); } string strSQL = "SELECT table_name FROM scenario_datasource WHERE " + " scenario_id = '" + strScenarioId + "';"; p_ado.SqlQueryReader(p_conn, strSQL); if (p_ado.m_intError == 0) { while (p_ado.m_OleDbDataReader.Read()) { if (p_ado.m_OleDbDataReader["table_name"] != System.DBNull.Value) { if (p_ado.m_OleDbDataReader["table_name"].ToString().Trim().Length > 0) { intCount++; } } } } p_ado.m_OleDbDataReader.Close(); p_ado.m_OleDbDataReader = null; p_conn.Close(); p_conn = null; p_ado = null; return(intCount); }
private void RefreshForm() { string strScenarioDir = frmMain.g_oFrmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim() + "\\" + ScenarioType + "\\db"; string strFile = "scenario_" + ScenarioType + "_rule_definitions.mdb"; StringBuilder strFullPath = new StringBuilder(strScenarioDir); strFullPath.Append("\\"); strFullPath.Append(strFile); ado_data_access p_ado = new ado_data_access(); string strConn = p_ado.getMDBConnString(strFullPath.ToString(), "admin", ""); //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFullPath.ToString() + ";User Id=admin;Password=;"; string strSQL = "select * from scenario where scenario_id = '" + this.lstScenario.SelectedItem.ToString() + "';"; p_ado.SqlQueryReader(strConn, strSQL); if (p_ado.m_intError == 0) { try { while (p_ado.m_OleDbDataReader.Read()) { this.txtDescription.Text = p_ado.m_OleDbDataReader["description"].ToString(); this.txtScenarioPath.Text = p_ado.m_OleDbDataReader["path"].ToString(); this.txtScenarioId.Text = p_ado.m_OleDbDataReader["scenario_id"].ToString(); //((frmScenario)this.ParentForm).uc_scenario_notes1.txtNotes.Text = p_ado.m_OleDbDataReader["notes"].ToString(); break; } p_ado.m_OleDbDataReader.Close(); } catch (Exception caught) { this.strError = caught.Message; this.intError = -1; MessageBox.Show(this.strError); } p_ado.m_OleDbDataReader = null; p_ado.m_OleDbCommand = null; p_ado.m_OleDbConnection.Close(); p_ado.m_OleDbConnection = null; } }
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); }
// 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); }
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 loadvalues(ProcessorScenarioItem oProcItem) { this.lstRxPackages.Clear(); this.m_oLvRowColors.InitializeRowCollection(); this.lstRxPackages.Columns.Add("", 2, HorizontalAlignment.Left); this.lstRxPackages.Columns.Add("Variant", 75, HorizontalAlignment.Left); this.lstRxPackages.Columns.Add("Package", 300, HorizontalAlignment.Left); this.lstRxPackages.Columns[COLUMN_CHECKBOX].Width = -2; // Create an instance of a ListView column sorter and assign it // to the ListView control. lvwColumnSorter = new ListViewColumnSorter(); this.lstRxPackages.ListViewItemSorter = lvwColumnSorter; m_oEnv = new env(); ado_data_access oAdo = new ado_data_access(); if (String.IsNullOrEmpty(oProcItem.ScenarioId)) { return; } string[] arr1 = new string[] { "PLOT" }; string strPlotTableName = ""; object oValue = frmMain.g_oDelegate.GetValueExecuteControlMethodWithParam(ReferenceOptimizerScenarioForm.uc_datasource1, "getDataSourceTableName", arr1, true); if (oValue != null) { string strValue = Convert.ToString(oValue); if (strValue != "false") { strPlotTableName = strValue; } } string strHarvestCostsPathAndFile = oProcItem.DbPath + "\\" + Tables.ProcessorScenarioRun.DefaultHarvestCostsTableDbFile; arr1 = new string[] { "CONDITION" }; string strCondTableName = ""; oValue = frmMain.g_oDelegate.GetValueExecuteControlMethodWithParam(ReferenceOptimizerScenarioForm.uc_datasource1, "getDataSourceTableName", arr1, true); if (oValue != null) { string strValue = Convert.ToString(oValue); if (strValue != "false") { strCondTableName = strValue; } } /************************************************************** **create a temporary MDB File that will contain table links **to the cond, plot, and harvest_costs tables **************************************************************/ dao_data_access p_dao = new dao_data_access(); if (System.IO.File.Exists(strHarvestCostsPathAndFile) && p_dao.TableExists(strHarvestCostsPathAndFile, Tables.ProcessorScenarioRun.DefaultHarvestCostsTableName)) { this.m_strTempMDBFile = this.ReferenceOptimizerScenarioForm.uc_datasource1.CreateMDBAndScenarioTableDataSourceLinks(m_oEnv.strTempDir); p_dao.CreateTableLink(this.m_strTempMDBFile, Tables.ProcessorScenarioRun.DefaultHarvestCostsTableName, strHarvestCostsPathAndFile, Tables.ProcessorScenarioRun.DefaultHarvestCostsTableName); p_dao = null; string strTempConn = oAdo.getMDBConnString(this.m_strTempMDBFile, "", ""); using (var oConn = new OleDbConnection(strTempConn)) { oConn.Open(); oAdo.m_strSQL = "SELECT DISTINCT plot.fvs_variant, harvest_costs.rxpackage, Count(*) AS [Count]" + " FROM (" + strCondTableName + " INNER JOIN " + strPlotTableName + " ON " + strCondTableName + ".biosum_plot_id = " + strPlotTableName + ".biosum_plot_id) " + " INNER JOIN " + Tables.ProcessorScenarioRun.DefaultHarvestCostsTableName + " ON " + strCondTableName + ".biosum_cond_id = " + Tables.ProcessorScenarioRun.DefaultHarvestCostsTableName + ".biosum_cond_id" + " GROUP BY FVS_VARIANT, RXPACKAGE"; oAdo.SqlQueryReader(oConn, oAdo.m_strSQL); if (oAdo.m_OleDbDataReader.HasRows == true) { while (oAdo.m_OleDbDataReader.Read()) { if (oAdo.m_OleDbDataReader["fvs_variant"] != System.DBNull.Value) { //null column this.lstRxPackages.Items.Add(" "); this.lstRxPackages.Items[lstRxPackages.Items.Count - 1].UseItemStyleForSubItems = false; this.lstRxPackages.Items[lstRxPackages.Items.Count - 1].Checked = true; this.m_oLvRowColors.AddRow(); this.m_oLvRowColors.AddColumns(lstRxPackages.Items.Count - 1, lstRxPackages.Columns.Count); //fvs_variant this.lstRxPackages.Items[lstRxPackages.Items.Count - 1].SubItems.Add(Convert.ToString(oAdo.m_OleDbDataReader["fvs_variant"])); this.m_oLvRowColors.ListViewSubItem(lstRxPackages.Items.Count - 1, COLUMN_FVS_VARIANT, lstRxPackages.Items[lstRxPackages.Items.Count - 1].SubItems[COLUMN_FVS_VARIANT], false); // rxPackage if (oAdo.m_OleDbDataReader["rxpackage"] != System.DBNull.Value) { this.lstRxPackages.Items[this.lstRxPackages.Items.Count - 1].SubItems.Add(oAdo.m_OleDbDataReader["rxpackage"].ToString()); } else { this.lstRxPackages.Items[this.lstRxPackages.Items.Count - 1].SubItems.Add(" "); } this.m_oLvRowColors.ListViewSubItem(lstRxPackages.Items.Count - 1, COLUMN_RXPACKAGE, lstRxPackages.Items[lstRxPackages.Items.Count - 1].SubItems[COLUMN_RXPACKAGE], false); } } } oAdo.m_OleDbDataReader.Close(); } } }
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; } }
/// <summary> /// Delete all plot records and the plot's tree and condition records /// </summary> private void DeleteAllPlotRecords() { string strMsg = "All condition and tree records for the plots deleted will also be deleted. \n Are you sure you want to remove all plot data from the project?"; DialogResult result = MessageBox.Show(strMsg, "Delete All Plot Data", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (result) { case DialogResult.Yes: break; case DialogResult.No: return; case DialogResult.Cancel: return; } frmMain.g_oFrmMain.ActivateStandByAnimation(frmMain.g_oFrmMain.WindowState, this.Left, this.Height, this.Width, this.Top); //instantiate the ado data access class FIA_Biosum_Manager.ado_data_access p_ado = new ado_data_access(); //instantiate the datasource class FIA_Biosum_Manager.Datasource p_datasource = new Datasource(((frmDialog)this.ParentForm).m_frmMain.frmProject.uc_project1.txtRootDirectory.Text.Trim()); string strSQL = ""; /******************************************************************** **have the data source class create an mdb file in the user's temp **directory, create links to the plot,tree, and cond table and **return the name of the mdb path and file ********************************************************************/ string strMDBFile = p_datasource.CreateMDBAndTableDataSourceLinks(); //have the ado data access class return the connection string string strConn = p_ado.getMDBConnString(strMDBFile, "", ""); //get the location in the array for each of the table type information int intTree = p_datasource.getValidTableNameRow("TREE"); int intPlot = p_datasource.getValidTableNameRow("PLOT"); int intCond = p_datasource.getValidTableNameRow("CONDITION"); int intPpsa = p_datasource.getValidTableNameRow("POPULATION PLOT STRATUM ASSIGNMENT"); int intTreeRegionalBiomass = p_datasource.getValidTableNameRow("TREE REGIONAL BIOMASS"); int intPopEval = p_datasource.getValidTableNameRow("POPULATION EVALUATION"); int intPopStratum = p_datasource.getValidTableNameRow("POPULATION STRATUM"); int intPopEstUnit = p_datasource.getValidTableNameRow("POPULATION ESTIMATION UNIT"); int intSiteTree = p_datasource.getValidTableNameRow("SITE TREE"); //check to see if we found all the table information if (intTree >= 0 && intPlot >= 0 && intCond >= 0) { //check if we have tree regional biomass records if (p_datasource.m_strDataSource[intTreeRegionalBiomass, RECORDCOUNT].Trim() != "0") { //delete the tree regional records that are related to a plot strSQL = "DELETE FROM " + p_datasource.m_strDataSource[intTreeRegionalBiomass, TABLE]; // + " tr " + // "WHERE EXISTS (SELECT * FROM " + p_datasource.m_strDataSource[intCond,TABLE] + " c, " + // p_datasource.m_strDataSource[intPlot,TABLE] + " p, " + // p_datasource.m_strDataSource[intTree,TABLE] + " t " + // "WHERE c.biosum_plot_id=p.biosum_plot_id AND " + // "t.biosum_cond_id=c.biosum_cond_id AND " + // "tr.tre_cn = t.cn);"; p_ado.SqlNonQuery(strConn, strSQL); } //check if we have site tree records if (p_datasource.m_strDataSource[intSiteTree, RECORDCOUNT].Trim() != "0") { strSQL = "DELETE FROM " + p_datasource.m_strDataSource[intSiteTree, TABLE]; p_ado.SqlNonQuery(strConn, strSQL); } //check if we have tree records if (p_datasource.m_strDataSource[intTree, RECORDCOUNT].Trim() != "0") { //delete the tree records that are related to a plot strSQL = "DELETE FROM " + p_datasource.m_strDataSource[intTree, TABLE]; // + " t " + // "WHERE EXISTS (SELECT * FROM " + p_datasource.m_strDataSource[intCond,TABLE] + " c " + // " INNER JOIN " + p_datasource.m_strDataSource[intPlot,TABLE] + " p " + // "ON c.biosum_plot_id = p.biosum_plot_id " + // " WHERE t.biosum_cond_id = c.biosum_cond_id);"; p_ado.SqlNonQuery(strConn, strSQL); } //check if we have ppsa records if (p_ado.m_intError == 0 && p_datasource.m_strDataSource[intPpsa, RECORDCOUNT].Trim() != "0") { //delete the ppsa records strSQL = "DELETE FROM " + p_datasource.m_strDataSource[intPpsa, TABLE]; p_ado.SqlNonQuery(strConn, strSQL); } //check if we have cond records if (p_ado.m_intError == 0 && p_datasource.m_strDataSource[intCond, RECORDCOUNT].Trim() != "0") { //delete the cond records that are related to a plot strSQL = "DELETE FROM " + p_datasource.m_strDataSource[intCond, TABLE]; // + " c " + // "WHERE EXISTS (SELECT * FROM " + p_datasource.m_strDataSource[intPlot,TABLE] + " p " + // " WHERE c.biosum_plot_id = p.biosum_plot_id);"; p_ado.SqlNonQuery(strConn, strSQL); } //check if we have ploteval records if (p_ado.m_intError == 0 && p_datasource.m_strDataSource[intPopEval, RECORDCOUNT].Trim() != "0") { //delete all the ploteval records strSQL = "DELETE FROM " + p_datasource.m_strDataSource[intPopEval, TABLE]; p_ado.SqlNonQuery(strConn, strSQL); } //check if we have pop est unit records if (p_ado.m_intError == 0 && p_datasource.m_strDataSource[intPopEstUnit, RECORDCOUNT].Trim() != "0") { //delete all the ploteval records strSQL = "DELETE FROM " + p_datasource.m_strDataSource[intPopEstUnit, TABLE]; p_ado.SqlNonQuery(strConn, strSQL); } //check if we have pop est unit records if (p_ado.m_intError == 0 && p_datasource.m_strDataSource[intPopStratum, RECORDCOUNT].Trim() != "0") { //delete all the ploteval records strSQL = "DELETE FROM " + p_datasource.m_strDataSource[intPopStratum, TABLE]; p_ado.SqlNonQuery(strConn, strSQL); } //check if we have plot records if (p_ado.m_intError == 0 && p_datasource.m_strDataSource[intPlot, RECORDCOUNT].Trim() != "0") { //delete all the plot records strSQL = "DELETE FROM " + p_datasource.m_strDataSource[intPlot, TABLE]; p_ado.SqlNonQuery(strConn, strSQL); } frmMain.g_oFrmMain.DeactivateStandByAnimation(); MessageBox.Show("Done", "DELETE ALL PLOT DATA", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); } else { frmMain.g_oFrmMain.DeactivateStandByAnimation(); strSQL = "Delete Failed - Could not locate these designated tables:\n"; if (intPlot == -1) { strSQL += "Plot table\n"; } if (intCond == -1) { strSQL += "Cond table\n"; } if (intTree == -1) { strSQL += "Tree table\n"; } MessageBox.Show(strSQL, "DELETE ALL PLOT DATA", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); } }
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 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 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 OpenConnection(ado_data_access p_oAdo) { InstantiateConnectionObject(p_oAdo); p_oAdo.OpenConnection(p_oAdo.getMDBConnString(FullPath, "", ""), ref _oConn); }