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()); } } } } }
// adds and event to the calendar // @ parameters // month of event // day of event // start time of event // end time of event // name of event public void addEvent(int month, int day, double start, double end, string name, Year curr) { //Year curr = new Year(); // event time is available, can input event if (curr.getMonth(month - 1).getDay(day - 1).checkAvailability(start, end)) { curr.getMonth(month - 1).getDay(day - 1).setAvailability(start, end); // set availability array curr.getMonth(month - 1).getDay(day - 1).setEvent(name, start, end); // set event } else { Console.Write("Cannot add event, time overlap.../n"); //Console.Write("No event found.../n"); } }
// find all events with a certain name public List <Event> findEvent_byName(string eventName) { Year curr = new Year(); List <Event> allEvents = new List <Event>(); // iterate through months for (int i = 0; i < curr.getMonthRange(); i++) { // iterate through days of the month for (int j = 0; j < curr.getMonth(i).getDayRange(); j++) { // add list of events to final list allEvents.AddRange(curr.getMonth(i).getDay(j).findEvent(eventName)); } } return(allEvents); }
// find all events in a certain date public List <Event> findEvent_byDate(int year, int month, int day) { Year curr = new Year(); //List<Event> allEvents = new List<Event>(); // return a list of events return(curr.getMonth(month).getDay(day).getEvents()); }
public Form1(User user) { InitializeComponent(); scheduler = new Calander(pictureBox1); dayNameMap = new Dictionary <String, int>(); initDayNameMap(); year = new Year(2018); // will need to change this later scheduler.loadCalender(year, user); picMap = new Dictionary <int, PictureBox>(); createPicMap(); populate(year.getMonth(scheduler.curMonth - 1)); // change this to current date }
private void showNextMonth(int direction) { scheduler.curMonth += direction; if (scheduler.curMonth > 11) { scheduler.curMonth = 0; } if (scheduler.curMonth < 0) { scheduler.curMonth = 11; } clearCalander(); scheduler.getDayMap().Clear(); scheduler.selected = 10; scheduler.selected = 10; populate(year.getMonth(scheduler.curMonth)); //scheduler.selected = }
// 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); }