Пример #1
0
        private void btnAddNewYear_Click(object sender, EventArgs e)
        {
            //creates an instance of the add year form
            frmAddNewYear tempAddYear = new frmAddNewYear(lstLocationNames.SelectedIndex);

            tempAddYear.ShowDialog();
            //saves the data to the file
            SaveToFile();
            //updates the list boxes
            FillYears();
        }
Пример #2
0
        public void AddLocation()
        {
            Location tempLocation = new Location();

            //saves the new values into the array
            tempLocation.SetLocationName(txtLocationName.Text);
            tempLocation.SetStreetNumberAndName(txtStreet.Text);
            tempLocation.SetCounty(txtCounty.Text);
            tempLocation.SetPostcode(txtPostcode.Text);
            //catch any incorrect inputs from the user when they try to input a string rather than a number
            try
            {
                tempLocation.SetLatitude(Convert.ToDouble(txtLatitude.Text));
            }
            catch (Exception E)
            {
                MessageBox.Show(string.Format("Error: {0} \nPlease enter a valid number for latitude.", E.Message));
                return;
            }
            try
            {
                tempLocation.SetLongitude(Convert.ToDouble(txtLongitude.Text));
            }
            catch (Exception E)
            {
                MessageBox.Show(string.Format("Error: {0} \nPlease enter a valid number for longitude.", E.Message));
                return;
            }
            MessageBox.Show("New locations added.");

            //resizes the array so a location can be added
            Array.Resize(ref Data.Locations, Data.Locations.Length + 1);
            Data.Locations[Data.Locations.Length - 1] = new Location();
            //set the temp to the main array
            Data.Locations[Data.Locations.Length - 1] = tempLocation;

            //creates a new instance of the form add year as there should be at least one year in a location
            frmAddNewYear tempFrmAddNewYear = new frmAddNewYear(Data.Locations.Length - 1);

            tempFrmAddNewYear.ShowDialog();

            //resets the text boxes
            txtLocationName.Clear();
            txtStreet.Clear();
            txtCounty.Clear();
            txtPostcode.Clear();
            txtLatitude.Clear();
            txtLongitude.Clear();
        }