private void showMonthData(int rows, int cols) { //get the months for the correct location and year Yearly[] theYearData = Data.WeatherStationData[locationSelected].getYears(); Monthly[] theMonths = theYearData[yearSelected].getMonths(); //loop through each row saving the value from the month year selected for (int i = 0; i < rows; i++) { Monthly month = theMonths[i]; dgdMonths[0, i].Value = month.getId(); dgdMonths[1, i].Value = month.getMaxTemp(); dgdMonths[2, i].Value = month.getMinTemp(); dgdMonths[3, i].Value = month.getNumDaysAirFrost(); dgdMonths[4, i].Value = month.getMmRainfall(); dgdMonths[5, i].Value = month.getHoursSunshine(); } }
private void btnEditMonth_Click(object sender, EventArgs e) { const int rows = 12; Yearly[] theYearData = Data.WeatherStationData[locationSelected].getYears(); Monthly[] theMonths = theYearData[yearSelected].getMonths(); //loop through all the grid to save all the changes for (int i = 0; i < rows; i++) { Monthly month = theMonths[i]; month.setId(dgdMonths[0, i].Value.ToString()); month.setMaxTemp(Convert.ToDouble(dgdMonths[1, i].Value)); month.setMinTemp(Convert.ToDouble(dgdMonths[2, i].Value)); month.setNumDaysAirFrost(Convert.ToDouble(dgdMonths[3, i].Value)); month.setMmRainfall(Convert.ToDouble(dgdMonths[4, i].Value)); month.setHoursSunshine(Convert.ToDouble(dgdMonths[5, i].Value)); } }
private void getMonths(StreamReader theData, ref Monthly[] theMonths) { const int amountOfMonths = 12; //loop for months for 12 times for (int i = 0; i < amountOfMonths; i++) { string id; double maxTemp, minTemp, airFrost, rainfall, sunshine; //read in id = theData.ReadLine(); maxTemp = Convert.ToDouble(theData.ReadLine()); minTemp = Convert.ToDouble(theData.ReadLine()); airFrost = Convert.ToDouble(theData.ReadLine()); rainfall = Convert.ToDouble(theData.ReadLine()); sunshine = Convert.ToDouble(theData.ReadLine()); // due to the data file has a yearid repeating i am removing it when reading in if (i < 11) { string bin = theData.ReadLine(); } //create object Monthly tempMonth = new Monthly(id, maxTemp, minTemp, airFrost, rainfall, sunshine); //resize the array int size; if (theMonths == null) { size = 0; } else { size = theMonths.Length; } Array.Resize(ref theMonths, size + 1); theMonths[size] = tempMonth; } }
private void btnAddNewYear_Click(object sender, EventArgs e)//adds a new year and creates the monthly data but is all blank { Yearly[] theYearData = Data.WeatherStationData[locationSelected].getYears(); int theYear; string Description; theYear = Convert.ToInt32(txtSetNewYear.Text); Description = txtSetYearDescription.Text; //set a blank monthly datagrid CreateBlankGrid(); //set up loop to store all the blank months in an array Monthly[] tempBlankMonths = null; const int amountOfMonths = 12; for (int i = 0; i < amountOfMonths; i++) { string id; double maxTemp, minTemp, airFrost, rainfall, sunshine; //assign varaibles to 0 to create blank data id = ((i + 1).ToString()); maxTemp = 0; minTemp = 0; airFrost = 0; rainfall = 0; sunshine = 0; //create object Monthly tempBlankMonth = new Monthly(id, maxTemp, minTemp, airFrost, rainfall, sunshine); //size the array int sizeofMonth; if (tempBlankMonths == null) { sizeofMonth = 0; } else { sizeofMonth = tempBlankMonths.Length; } Array.Resize(ref tempBlankMonths, sizeofMonth + 1); tempBlankMonths[sizeofMonth] = tempBlankMonth; } //create object Yearly tempYear = new Yearly(theYear, Description, tempBlankMonths); Yearly [] tempLocation = Data.WeatherStationData[locationSelected].getYears(); //resize the array int size; if (tempLocation == null) { size = 0; } else { size = tempLocation.Length; } Array.Resize(ref tempLocation, size + 1); tempLocation[size] = tempYear; Data.WeatherStationData[locationSelected].setYears(tempLocation); //to refresh the list so the changes that are made show up showYears(); }