} // Creates a copy of the previous form(month display) and sets it to the same location as this form, with the same information as this form has. private void buttonSave_Click(object sender, EventArgs e) { Month saveMonth = locations[location].GetYear(year).GetMonth(month); saveMonth.handleIdentity = Convert.ToInt32(textBoxIndex.Text); saveMonth.handleMaximumTemperature = Convert.ToSingle(textBoxMaxTemp.Text); saveMonth.handleMinimumTemperature = Convert.ToSingle(textBoxMinTemp.Text); saveMonth.handleDaysOfAirFrost = Convert.ToSingle(textBoxAirFrost.Text); saveMonth.handleMillimitersOfRainfall = Convert.ToSingle(textBoxRainfall.Text); saveMonth.handleHoursOfSunshine = Convert.ToSingle(textBoxSunshine.Text); locations[location].handleYears[year].handleMonths[month] = saveMonth; Filehandler.SaveFile(locations); } // Sets the attributes of the currently selected month in the man data structure to be equal to the values currently in the form, then calls the SaveFile function.
} // Brings up a file selection dialogue, then copies the selected file into the relevant box on the form. private void buttonLaunch_Click(object sender, EventArgs e) { Location[] data = Filehandler.ReadFile(fileOpenBox.Text); if (data.Length != 0) { var formLocationDisplay = new FormLocationDisplay(data); formLocationDisplay.Location = this.Location; formLocationDisplay.StartPosition = FormStartPosition.Manual; this.Hide(); formLocationDisplay.Show(); } else { Console.WriteLine("Invalid file selection"); fileOpenBox.Text = "Invalid file was selected."; } } // Reads the selected file from the text box and atempts to ReadFile using the file handler. If the filehandler errors (indicated by an array length 0) outputs an error.
} // Creates a copy of the previous form (year display) and sets it to the same location as this form, with the same information as this form has. private void ButtonSave_Click(object sender, EventArgs e) { try { Year savedYear = new Year(); savedYear.handleDescription = textBoxDescription.Text; savedYear.handleDate = int.Parse(textBoxDate.Text); Month[] savedMonths = new Month[12]; #region reading months TextBox[] january = new TextBox[5] { textBoxJMX, textBoxJMI, textBoxJAF, textBoxJRF, textBoxJS }; savedMonths[0] = ReadTextBoxesToMonth(january, 1); TextBox[] february = new TextBox[5] { textBoxFMX, textBoxFMI, textBoxFAF, textBoxFRF, textBoxFS }; savedMonths[1] = ReadTextBoxesToMonth(february, 2); TextBox[] march = new TextBox[5] { textBoxMMX, textBoxMMI, textBoxMAF, textBoxMRF, textBoxMS }; savedMonths[2] = ReadTextBoxesToMonth(march, 3); TextBox[] april = new TextBox[5] { textBoxAMX, textBoxAMI, textBoxAAF, textBoxARF, textBoxAS }; savedMonths[3] = ReadTextBoxesToMonth(april, 4); TextBox[] may = new TextBox[5] { textBoxMAMX, textBoxMAMI, textBoxMAAF, textBoxMARF, textBoxMAS }; savedMonths[4] = ReadTextBoxesToMonth(may, 5); TextBox[] june = new TextBox[5] { textBoxJUNMX, textBoxJUNMI, textBoxJUNAF, textBoxJUNRF, textBoxJUNS }; savedMonths[5] = ReadTextBoxesToMonth(june, 6); TextBox[] july = new TextBox[5] { textBoxJULMX, textBoxJULMI, textBoxJULAF, textBoxJULRF, textBoxJULS }; savedMonths[6] = ReadTextBoxesToMonth(july, 7); TextBox[] august = new TextBox[5] { textBoxAUMX, textBoxAUMI, textBoxAUAF, textBoxAURF, textBoxAUS }; savedMonths[7] = ReadTextBoxesToMonth(august, 8); TextBox[] september = new TextBox[5] { textBoxSMX, textBoxSMI, textBoxSAF, textBoxSRF, textBoxSS }; savedMonths[8] = ReadTextBoxesToMonth(september, 9); TextBox[] october = new TextBox[5] { textBoxOMI, textBoxOMI, textBoxOAF, textBoxORF, textBoxOS }; savedMonths[9] = ReadTextBoxesToMonth(october, 10); TextBox[] november = new TextBox[5] { textBoxNMX, textBoxNMI, textBoxNAF, textBoxNRF, textBoxNS }; savedMonths[10] = ReadTextBoxesToMonth(november, 11); TextBox[] december = new TextBox[5] { textBoxDMX, textBoxDMI, textBoxDAF, textBoxDRF, textBoxDS }; savedMonths[11] = ReadTextBoxesToMonth(december, 12); #endregion // I'm not 100% happy with this; I'd have prefered to declare the textboxes in an array rather than put them in one here. However, to do that I'd have to touch autogenerated code. // Visual studio won't let me do that; it overwrites my changes at the slightest provocation. So, since I'm not using a gridView for the sake of UX, I think this is my best option. savedYear.handleMonths = savedMonths; locations[location].AddYear(savedYear); Filehandler.SaveFile(locations); string message = "The year has been saved."; string title = "Success!"; MessageBox.Show(message, title); } catch (Exception badInputError) { Console.WriteLine("An error ocurred while rading the form: {0}", badInputError.Message); Console.WriteLine("Additional details: \n {0}", badInputError); Console.WriteLine("It's probably because you entered something wrong, user."); string message = "The year has not been saved due to an invalid input."; string title = "Error."; MessageBox.Show(message, title); } } // Saves the data entered into this form into a new year, using the Location class's AddYear function.