//Reads in the data from the file public void ReadInData() { int numOfYears, numOfLocations; Location tempLocation; Year[] tempYears = null; MonthlyObservations[] tempMonthlyObservations = null; StreamReader readInputs = new StreamReader("inputExtended.txt"); //read the number of locations in the file numOfLocations = Convert.ToInt32(readInputs.ReadLine()); //Read the locations data and set it in a temporary object for (int l = 0; l < numOfLocations; l++) { tempLocation = new Location(); tempLocation.SetLocationName(readInputs.ReadLine()); tempLocation.SetStreetNumberAndName(readInputs.ReadLine()); tempLocation.SetCounty(readInputs.ReadLine()); tempLocation.SetPostcode(readInputs.ReadLine()); tempLocation.SetLatitude(Convert.ToDouble(readInputs.ReadLine())); tempLocation.SetLongitude(Convert.ToDouble(readInputs.ReadLine())); numOfYears = Convert.ToInt32(readInputs.ReadLine()); //Read the years for the locations and set it in a temporary object tempYears = new Year[numOfYears]; for (int y = 0; y < numOfYears; y++) { tempYears[y] = new Year(); tempYears[y].SetYearDescription(readInputs.ReadLine()); //Read the monthly observations for the years and set it in a temporary object tempMonthlyObservations = new MonthlyObservations[12]; for (int m = 0; m < 12; m++) { tempYears[y].SetYear(Convert.ToInt32(readInputs.ReadLine())); tempMonthlyObservations[m] = new MonthlyObservations(); tempMonthlyObservations[m].SetMonthIdNumber(Convert.ToInt32(readInputs.ReadLine())); tempMonthlyObservations[m].SetMaxTemp(Convert.ToDouble(readInputs.ReadLine())); tempMonthlyObservations[m].SetMinTemp(Convert.ToDouble(readInputs.ReadLine())); tempMonthlyObservations[m].SetNumOfAirFrostDays(Convert.ToInt32(readInputs.ReadLine())); tempMonthlyObservations[m].SetMillimetresRainfall(Convert.ToDouble(readInputs.ReadLine())); tempMonthlyObservations[m].SetHoursOfSunshine(Convert.ToDouble(readInputs.ReadLine())); } //stores the monthly observations in the temp years object tempYears[y].SetMonthlyObservations(tempMonthlyObservations); } //stores stores the years in the temp locations object tempLocation.SetYears(tempYears); //store all of the information in the array Array.Resize(ref Data.Locations, l + 1); Data.Locations[l] = tempLocation; } //closes the stream reader readInputs.Close(); }
public frmEditMonthlyObservation(int inLocationRef, int inYearRef, int inMonthRef) { InitializeComponent(); //stores the references to the selected indexs in the main form locationRef = inLocationRef; yearRef = inYearRef; monthRef = inMonthRef; //stores the relevant month in a temporary array selectedMonth = Data.Locations[locationRef].GetYears()[yearRef].GetMonthlyObservations()[monthRef]; //goes to a method that inputs the data to the text boxes LoadInData(); }
public void LoadObseravations() { //adds all of the info to the observations list box lstObservations.Items.Clear(); MonthlyObservations tempMonth = Data.Locations[lstLocationNames.SelectedIndex].GetYears()[lstYears.SelectedIndex].GetMonthlyObservations()[lstMonths.SelectedIndex]; lstObservations.Items.Add("MonthID; " + tempMonth.GetMonthId().ToString()); lstObservations.Items.Add("MaxTemp: " + tempMonth.GetMaxTemp().ToString()); lstObservations.Items.Add("MinTemp: " + tempMonth.GetMinTemp().ToString()); lstObservations.Items.Add("Number Of Days Of Air Frost: " + tempMonth.GetNumAirFrostDays().ToString()); lstObservations.Items.Add("Millimetres Of Rainfall: " + tempMonth.GetMmsOfRainfall().ToString()); lstObservations.Items.Add("Hours Of Sunshine: " + tempMonth.GetHoursOfSunshine().ToString()); }
//saves all of the data input into the form public void SaveNewYear() { //creates a place to store data temporarily Year tempYear = new Year(); MonthlyObservations[] tempMonthlyObservations = new MonthlyObservations[12]; //loops through all of the 12 rows storing the data in the temporary objects for (int month = 0; month < 12; month++) { tempMonthlyObservations[month] = new MonthlyObservations(); try { tempYear.SetYear(Convert.ToInt32(txtYear.Text)); tempMonthlyObservations[month].SetMonthIdNumber(Convert.ToInt32(dgdMonthlyObservations.Rows[month].Cells[0].Value)); tempMonthlyObservations[month].SetMaxTemp(Convert.ToDouble(dgdMonthlyObservations.Rows[month].Cells[1].Value)); tempMonthlyObservations[month].SetMinTemp(Convert.ToDouble(dgdMonthlyObservations.Rows[month].Cells[2].Value)); tempMonthlyObservations[month].SetNumOfAirFrostDays(Convert.ToInt32(dgdMonthlyObservations.Rows[month].Cells[3].Value)); tempMonthlyObservations[month].SetMillimetresRainfall(Convert.ToDouble(dgdMonthlyObservations.Rows[month].Cells[4].Value)); tempMonthlyObservations[month].SetHoursOfSunshine(Convert.ToDouble(dgdMonthlyObservations.Rows[month].Cells[5].Value)); } catch (Exception e) { MessageBox.Show(string.Format("Error: {0} \nPlease make sure the inputs are valid.", e.Message)); return; } } //if nothing is stored in the year desc then it will store a message of no desc available if (txtYearDesc.Text != "") { tempYear.SetYearDescription(txtYearDesc.Text); } else { tempYear.SetYearDescription("no description available"); } //store the temp monthly observations in the temp year tempYear.SetMonthlyObservations(tempMonthlyObservations); //stores the data in the locations object Data.Locations[locationRef].AddNewYear(locationRef, tempYear); MessageBox.Show("New year saved"); //resets the page dgdMonthlyObservations.Rows.Clear(); txtYear.Clear(); txtYearDesc.Clear(); SetUpMonthlyObservations(); }