Exemplo n.º 1
0
        public void SaveCalendar(Year curr, User user)
        {
            string year     = curr.getYear().ToString();
            string userName = user.getUserName();


            string path = "Files/" + year + "_" + "Events_" + userName + ".txt";

            using (StreamWriter sw = new StreamWriter(path))
            {
                for (int i = 0; i < curr.getMonthRange(); i++)
                {
                    for (int j = 0; j < curr.getMonth(i).getDayRange(); j++)
                    {
                        for (int k = 0; k < curr.getMonth(i).getDay(j).getEventRange(); k++)
                        {
                            sw.WriteLine((i + 1).ToString());
                            sw.WriteLine((j + 1).ToString());
                            sw.WriteLine(curr.getMonth(i).getDay(j).getEvent(k).getName());
                            sw.WriteLine(curr.getMonth(i).getDay(j).getEvent(k).getStart().ToString());
                            sw.WriteLine(curr.getMonth(i).getDay(j).getEvent(k).getEnd().ToString());
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        // reads a text file with all the stored events and loads them into the calendar
        public int loadEvents(Year curr, User user)
        {
            int    month = 0;
            int    day   = 0;
            double start = 0;
            double end   = 0;
            string name  = "";
            string line;

            string year     = curr.getYear().ToString();
            string userName = user.getUserName();


            string path = "Files/" + year + "_" + "Events_" + userName + ".txt";

            if (!File.Exists(path))
            {
                return(-1);
            }

            System.IO.StreamReader file = new System.IO.StreamReader(path);
            while ((line = file.ReadLine()) != null)
            {
                month = Int32.Parse(line);                    // get month number
                line  = file.ReadLine();
                day   = Int32.Parse(line);                    // get day number
                line  = file.ReadLine();
                name  = line;                                 // get event name
                line  = file.ReadLine();
                start = Double.Parse(line);                   // get start time
                line  = file.ReadLine();
                end   = Double.Parse(line);                   // get end time

                addEvent(month, day, start, end, name, curr); // add event to calendar
            }

            file.Close();
            return(0);
        }
Exemplo n.º 3
0
        // load in the names of months
        public int loadCalender(Year curr, User user)
        {
            string line;
            int    monthCount = 1;
            //Year curr = new Year();
            //curr.setYear(2018);

            string year     = curr.getYear().ToString();
            string userName = user.getUserName();


            string path = "Files/" + year + "_" + userName + ".txt";

            if (!File.Exists(path))
            {
                path = "Files/" + year + ".txt";
            }

            System.IO.StreamReader file = new System.IO.StreamReader(path);
            while ((line = file.ReadLine()) != null)
            {
                //line = ReadLine()System.Console.WriteLine(line);     // read line

                curr.addMonth(monthCount, line);    // add mnth to year list

                //System.Console.WriteLine(line);     // read next line
                //System.Console.WriteLine(line);     // read next line
                line = file.ReadLine();
                int numberOfDays = Int32.Parse(line);   // turn string to int

                //System.Console.WriteLine(line);     // rad next line
                line = file.ReadLine();
                int startDay = Int32.Parse(line);       // turn string to int

                string dayName = "";

                for (int i = 1; i <= numberOfDays; i++)      // loop all days of month
                {
                    switch (startDay % 7)
                    {
                    case 1:
                        dayName = "Monday";
                        break;

                    case 2:
                        dayName = "Tuesday";
                        break;

                    case 3:
                        dayName = "Wednesday";
                        break;

                    case 4:
                        dayName = "Thursday";
                        break;

                    case 5:
                        dayName = "Friday";
                        break;

                    case 6:
                        dayName = "Saturday";
                        break;

                    case 0:
                        dayName = "Sunday";
                        break;

                    default:
                        Console.Write("ERROR.../n");
                        break;
                    }
                    // add a day to a month
                    curr.getMonth(monthCount - 1).addDay(i, dayName);
                    startDay++;
                }
                monthCount++;
            }
            file.Close();
            return(0);
        }