Esempio n. 1
0
        private void getYear(StreamReader theData, ref Yearly[] allYears)
        {
            Monthly[] theMonths = null; // temp monthly array storage
            //readin
            string desciption;
            int    yearID;

            //read description and yearID
            desciption = theData.ReadLine();
            yearID     = Convert.ToInt32(theData.ReadLine());
            //call the getMonths procedure with theData and a reference to theMonths temp storage
            getMonths(theData, ref theMonths);
            //create object
            Yearly tempYears = new Yearly(yearID, desciption, theMonths);
            //resize array
            int size;

            if (allYears == null)
            {
                size = 0;
            }
            else
            {
                size = allYears.Length;
            }
            Array.Resize(ref allYears, size + 1);
            allYears[size] = tempYears;
        }
Esempio n. 2
0
        private void showYearData()
        {
            //show the year data into text boxes
            Yearly[] theYearData = Data.WeatherStationData[locationSelected].getYears();
            Yearly   yearData    = theYearData[yearSelected];

            txtYear.Text        = yearData.getYear().ToString();
            txtDescription.Text = yearData.getDescription();
        }
Esempio n. 3
0
        private void btnEditYear_Click(object sender, EventArgs e)
        {
            //change the desciption id dependant on the user input
            Yearly[] theYearData = Data.WeatherStationData[locationSelected].getYears();
            Yearly   yearData    = theYearData[yearSelected];

            yearData.setDescription(txtDescription.Text);
            // to refresh the list so the changes that are made show up
            lstYears.Items.Clear();
            showYears();
        }
Esempio n. 4
0
 private void saveMonths(StreamWriter theData, Yearly yearData)
 {
     //loop through each month in the year
     foreach (Monthly monthData in yearData.getMonths())
     {
         theData.WriteLine(yearData.getYear()); // save the year id as it repeats in every month
         // write all of the month data to the file
         theData.WriteLine(monthData.getId());
         theData.WriteLine(monthData.getMaxTemp());
         theData.WriteLine(monthData.getMinTemp());
         theData.WriteLine(monthData.getMmRainfall());
         theData.WriteLine(monthData.getNumDaysAirFrost());
         theData.WriteLine(monthData.getHoursSunshine());
     }
 }
Esempio n. 5
0
        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();
        }