// *********************** protected members **************************************** /// <summary> /// Read the next available cell from the datasource. If the datasource has not /// been connected, an InvalidOperationException exception is raised. /// </summary> /// <param name="Cells"> /// A cCellData object into which the data is written. If Cells is null, an /// ArgumentNullException exception is raised. /// </param> /// <returns>False if there are no more cell records to read, True otherwise.</returns> protected override bool GetNextCellRecord(cCellData Cells) { if (!mvarConnected) { ThrowConnectionException(); } if (Cells == null) { throw new ArgumentNullException("Cells", "Cells cannot be null."); } // return false if we have reached the end of the record set if (ReadPosition == mvarDataSet.Tables[TName["AllCellData"]].Rows.Count) { return(false); } // get the data DataTable dt = mvarDataSet.Tables[TName["AllCellData"]]; // get the datarow at the current read position DataRow dr = dt.Rows[ReadPosition]; // read the data at the next position Cells.ID = Convert.ToString(dr[FName["HEXID"]]); Cells.SuperCellID = Convert.ToString(dr[FName["supercell"]]); Cells.K = Convert.ToDouble(dr[FName["K"]]); Cells.XLoc = Convert.ToDouble(dr[FName["easting"]]); Cells.YLoc = Convert.ToDouble(dr[FName["northing"]]); Cells.Neighbours[0] = Convert.ToString(dr[FName["n"]]); Cells.Neighbours[1] = Convert.ToString(dr[FName["ne"]]); Cells.Neighbours[2] = Convert.ToString(dr[FName["se"]]); Cells.Neighbours[3] = Convert.ToString(dr[FName["s"]]); Cells.Neighbours[4] = Convert.ToString(dr[FName["sw"]]); Cells.Neighbours[5] = Convert.ToString(dr[FName["nw"]]); ReadPosition++; return(true); }
/// <summary> /// Read the next available cell from the datasource. If the datasource has not /// been connected, an InvalidOperationException exception is raised. /// </summary> /// <param name="Cells"> /// A cCellData object into which the data is written. If Cells is null, an /// ArgumentNullException exception is raised. /// </param> /// <returns>False if there are no more cell records to read, True otherwise.</returns> protected override bool GetNextCellRecord(cCellData Cells) { if (mvarReader == null) { ThrowConnectionException(); } if (Cells == null) { throw new ArgumentNullException("Cells", "Cells cannot be null."); } // make sure reader is of the correct type if (ReaderType == "SC") { this.Reset(); } // read the data if (!mvarReader.Read()) { return(false); } else { Cells.ID = Convert.ToString(mvarReader["HEXID"]); Cells.SuperCellID = Convert.ToString(mvarReader["supercell"]); Cells.K = Convert.ToDouble(mvarReader["K"]); Cells.XLoc = Convert.ToDouble(mvarReader["easting"]); Cells.YLoc = Convert.ToDouble(mvarReader["northing"]); Cells.Neighbours[0] = Convert.ToString(mvarReader["n"]); Cells.Neighbours[1] = Convert.ToString(mvarReader["ne"]); Cells.Neighbours[2] = Convert.ToString(mvarReader["se"]); Cells.Neighbours[3] = Convert.ToString(mvarReader["s"]); Cells.Neighbours[4] = Convert.ToString(mvarReader["sw"]); Cells.Neighbours[5] = Convert.ToString(mvarReader["nw"]); return(true); } }
public void btn_LoadSettingsFile_Click(object sender, EventArgs e) { //System.Diagnostics.Debug.WriteLine(""); //System.Diagnostics.Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click()"); DataSet returnSettingsData = null; string filePath = string.Empty; string fileExt = string.Empty; settingsFile = null; OpenFileDialog file = new OpenFileDialog(); //open dialog to choose file if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK) //if there is a file choosen by the user { filePath = file.FileName; //get the path and name of the file settingsFile = filePath; /*Debug.WriteLine("settingsFile = " + settingsFile); * Debug.WriteLine("filePath = " + filePath);*/ fileExt = Path.GetExtension(filePath); //get the file extension if (fileExt.CompareTo(".xls") == 0 || fileExt.CompareTo(".xlsx") == 0) { try { //Code to put Excel worksheets in datatables and then 1 dataset alphabetically //Make excel settings file into dataset object returnSettingsData = cCSVSettingsTemplate.Parse(filePath); //Retrieve setttings values in the dataset: Table(worksheet), row and column String parameterSetName = returnSettingsData.Tables[4].Rows[0][1].ToString(); //YM //String parameterSetName = returnSettingsData.Tables[6].Rows[0][1].ToString(); //YM textBoxParameterSet.Text = parameterSetName; outputFolder = returnSettingsData.Tables[4].Rows[2][1].ToString();//YM //outputFolder = returnSettingsData.Tables[6].Rows[2][1].ToString(); //YM textBoxOutputFolder.Text = outputFolder; String landscapeFile = returnSettingsData.Tables[4].Rows[3][1].ToString();//YM //String landscapeFile = returnSettingsData.Tables[6].Rows[3][1].ToString();//YM Char[] delimiters = { '\\', '/' }; String[] landscapeFileItems = landscapeFile.Split(delimiters); String landscapeFileItemsLast = landscapeFileItems.Last(); textBoxLandscapeFile.Text = landscapeFileItemsLast; String growPop = returnSettingsData.Tables[4].Rows[4][1].ToString();//YM //String growPop = returnSettingsData.Tables[6].Rows[4][1].ToString();//YM //Debug.WriteLine("growPop = " + growPop); if (growPop == "TRUE") { textBoxPopulationFile.Text = "No file provided. A population is being grown."; } else { String populationFile = returnSettingsData.Tables[4].Rows[7][1].ToString();//YM //String populationFile = returnSettingsData.Tables[6].Rows[7][1].ToString();//YM //Debug.WriteLine("populationFile = " + populationFile); //Char delimiter = '\\'; String[] populationFileItems = populationFile.Split(delimiters); String populationFileItemsLast = populationFileItems.Last(); //Debug.WriteLine("populationFileItemsLast = " + populationFileItemsLast); textBoxPopulationFile.Text = populationFileItemsLast; } String numbIterations = returnSettingsData.Tables[4].Rows[12][1].ToString();//YM //String numbIterations = returnSettingsData.Tables[6].Rows[12][1].ToString();//YM textBoxNumbIterations.Text = numbIterations; String numbYears = returnSettingsData.Tables[4].Rows[8][1].ToString();//YM //String numbYears = returnSettingsData.Tables[6].Rows[8][1].ToString();//YM textBoxNumbYears.Text = numbYears; //Connect to landscape XML file to get supercell and K information cXMLCellDataSource landscapeXMLFile = new cXMLCellDataSource(true); int totalPathLength = landscapeFile.Length; int landNameLength = landscapeFileItemsLast.Length; string landPath = landscapeFile.Substring(0, totalPathLength - landNameLength); //Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click(): landPath = " + landPath); //Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click(): landscapeFileItemsLast = " + landscapeFileItemsLast); landscapeXMLFile.DataSourcePath = landPath; landscapeXMLFile.DataSourceName = landscapeFileItemsLast; landscapeXMLFile.Connect(); //Getting set up to get supercell values cSuperCellList listSuperCells = new cSuperCellList(); landscapeXMLFile.GetSuperCellData(listSuperCells); int numbSupCells = listSuperCells.Count; //Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click(): numbSupCells = " + numbSupCells); string superCellFormEntry; superCellFormEntry = null; //Getting set up to get K values cUniformRandom rand = new cUniformRandom(); cCellList listCells = new cCellList(rand); landscapeXMLFile.GetCellData(listCells, listSuperCells); cCellData CellData = new cCellData(); int numbCells = listCells.Count; //Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click(): numbCells = " + numbCells); double mvarK; // Get the supercell and K combinations var superK = new ListWithDuplicates(); for (int i = 0; i < numbCells; i++) { //landscapeKValues[i] = listCells.ToString() //values = listCells.ToString(); mvarK = listCells[i].K; superCellFormEntry = listCells[i].SuperCell.ID; //Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click(): i = " + i + " mvarK = " + mvarK + "; supercell = " + superCellFormEntry); superK.Add(superCellFormEntry, mvarK); } // Disconnect from the landscape XML file landscapeXMLFile.Disconnect(); //With the data loaded in, activate the run button btnRun.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } else { MessageBox.Show("Please choose .xls or .xlsx file only.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); //custom messageBox to show error } } }
//*************************************************************************************************************************************** //mothode : Load Files ** for ORM console ** public void LoadSettingsFile(string[] args) { //System.Diagnostics.Debug.WriteLine(""); //System.Diagnostics.Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click()"); pathArg[0] = "."; Debug.WriteLine("settingsFile =++++++++++++++++++++++++++++++++++++++++++++++++++++++++ " + pathArg[0]); DataSet returnSettingsData = null; string filePath = string.Empty; string fileExt = string.Empty; settingsFile = null; //filePath = pathArg[0]; //get the path and name of the file settingsFile = pathArg[0]; /*Debug.WriteLine("settingsFile = " + settingsFile); * Debug.WriteLine("filePath = " + filePath);*/ //fileExt = pathArg[0]; //get the file extension if (pathArg[0] != "") { try { //Code to put Excel worksheets in datatables and then 1 dataset alphabetically //Make excel settings file into dataset object returnSettingsData = cCSVSettingsTemplate.Parse(pathArg[0]); //Retrieve setttings values in the dataset: Table(worksheet), row and column String parameterSetName = returnSettingsData.Tables[4].Rows[0][1].ToString(); // textBoxParameterSet.Text = parameterSetName; outputFolder = returnSettingsData.Tables[4].Rows[2][1].ToString(); // textBoxOutputFolder.Text = outputFolder; Debug.WriteLine(" outputFolder =++++++++++++++++++++++++++++++++++++++++++++++++++++++++ " + outputFolder); String landscapeFile = returnSettingsData.Tables[4].Rows[3][1].ToString(); Char[] delimiters = { '\\', '/' }; String[] landscapeFileItems = landscapeFile.Split(delimiters); String landscapeFileItemsLast = landscapeFileItems.Last(); // textBoxLandscapeFile.Text = landscapeFileItemsLast; String growPop = returnSettingsData.Tables[4].Rows[4][1].ToString(); //Debug.WriteLine("growPop = " + growPop); if (growPop == "TRUE") { // textBoxPopulationFile.Text = "No file provided. A population is being grown."; } else { String populationFile = returnSettingsData.Tables[4].Rows[7][1].ToString(); //Debug.WriteLine("populationFile = " + populationFile); //Char delimiter = '\\'; String[] populationFileItems = populationFile.Split(delimiters); String populationFileItemsLast = populationFileItems.Last(); //Debug.WriteLine("populationFileItemsLast = " + populationFileItemsLast); // textBoxPopulationFile.Text = populationFileItemsLast; } String numbIterations = returnSettingsData.Tables[4].Rows[12][1].ToString(); // textBoxNumbIterations.Text = numbIterations; String numbYears = returnSettingsData.Tables[4].Rows[8][1].ToString(); // textBoxNumbYears.Text = numbYears; //Connect to landscape XML file to get supercell and K information cXMLCellDataSource landscapeXMLFile = new cXMLCellDataSource(true); int totalPathLength = landscapeFile.Length; int landNameLength = landscapeFileItemsLast.Length; string landPath = landscapeFile.Substring(0, totalPathLength - landNameLength); //Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click(): landPath = " + landPath); //Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click(): landscapeFileItemsLast = " + landscapeFileItemsLast); landscapeXMLFile.DataSourcePath = landPath; landscapeXMLFile.DataSourceName = landscapeFileItemsLast; landscapeXMLFile.Connect(); //Getting set up to get supercell values cSuperCellList listSuperCells = new cSuperCellList(); landscapeXMLFile.GetSuperCellData(listSuperCells); int numbSupCells = listSuperCells.Count; //Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click(): numbSupCells = " + numbSupCells); string superCellFormEntry; superCellFormEntry = null; //Getting set up to get K values cUniformRandom rand = new cUniformRandom(); cCellList listCells = new cCellList(rand); landscapeXMLFile.GetCellData(listCells, listSuperCells); cCellData CellData = new cCellData(); int numbCells = listCells.Count; //Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click(): numbCells = " + numbCells); double mvarK; // Get the supercell and K combinations var superK = new ListWithDuplicates(); for (int i = 0; i < numbCells; i++) { //landscapeKValues[i] = listCells.ToString() //values = listCells.ToString(); mvarK = listCells[i].K; superCellFormEntry = listCells[i].SuperCell.ID; //Debug.WriteLine("Form1.cs: btn_LoadSettingsFile_Click(): i = " + i + " mvarK = " + mvarK + "; supercell = " + superCellFormEntry); superK.Add(superCellFormEntry, mvarK); } // Disconnect from the landscape XML file landscapeXMLFile.Disconnect(); //With the data loaded in, activate the run button // btnRun.Enabled = true; } catch (Exception ex) { Console.Error.WriteLine(ex.Message.ToString()); } } else { Console.Error.WriteLine("Please choose .xls or .xlsx file only."); } }