//Save the current event info in the array protected bool saveEvent() { bool errorx = false; xmlEvent tempevent = new xmlEvent(); if (textBox1.Text.Length < 1) { MessageBox.Show("Please enter a valid name", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); errorx = true; } else { tempevent.name = textBox1.Text; } events[day, eventnum] = tempevent; try { xmltime sTime = new xmltime(); sTime.setHour(int.Parse(sHour.Text)); sTime.setMin(int.Parse(sMin.Text)); sTime.setDayTime(sDayTime.Text); tempevent.starttime = sTime; } catch (Exception ex) { if (ex is FormatException || ex is NullReferenceException) { MessageBox.Show("Incorrect Start Time", "Start Time Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); errorx = true; } } try { xmltime eTime = new xmltime(); eTime.setHour(int.Parse(eHour.Text)); eTime.setMin(int.Parse(eMin.Text)); eTime.setDayTime(eDayTime.Text); tempevent.endtime = eTime; } catch (Exception ex) { if (ex is FormatException || ex is NullReferenceException) { MessageBox.Show("Incorrect End Time", "Start Time Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } errorx = true; } tempevent.location = loc.Text; return(errorx); }
// Display the current event in the generator protected void displayEvent() { try { xmlEvent tempevent = new xmlEvent(); tempevent = events[day, eventnum]; textBox1.Text = tempevent.name; sHour.Text = tempevent.starttime.getHour(); sMin.Text = tempevent.starttime.getMin(); sDayTime.Text = tempevent.starttime.getDayTime(); eHour.Text = tempevent.endtime.getHour(); eMin.Text = tempevent.endtime.getMin(); eDayTime.Text = tempevent.endtime.getDayTime(); loc.Text = tempevent.location; daylabel.Text = "Day " + day; eventlabel.Text = "Event " + eventnum; textBox1.Focus(); } catch (NullReferenceException) { } }
private void openExistingFile() { clearArray(); xmlEvent[,] createEvents = new xmlEvent[rows, cols]; xmltime[,] startTimes = new xmltime[rows, cols]; xmltime[,] endTimes = new xmltime[rows, cols]; System.IO.StreamReader fileReader; if (newSessionForm.sessionLevel) { //load session sched fileReader = new System.IO.StreamReader(sessionSched); } else { //load course sched fileReader = new System.IO.StreamReader(courseSched); } if (File.Exists(sessionSched)) { //Parse String string nextLine = ""; string dayEx = "<day count=\"(.*?)\">"; string eventEx = "<event id=\"(.*?)\">"; string nameEx = "<name>(.*?)</name>"; string startHourEx = "<starttime>(.*?):"; string startMinEx = ":(.*?)</starttime>"; string endHourEx = "<endtime>(.*?):"; string endMinEx = ":(.*?)</endtime>"; string locEx = "<location>(.*?)</location>"; while ((nextLine = fileReader.ReadLine()) != null) { Match matchday = Regex.Match(nextLine, dayEx); if (matchday.Success) { string newDay = matchday.Groups[1].Value; day = int.Parse(newDay); } Match matchevent = Regex.Match(nextLine, eventEx); if (matchevent.Success) { createEvents[day, eventnum] = new xmlEvent();; string newEvent = matchevent.Groups[1].Value; try { eventnum = int.Parse(newEvent); } catch (NullReferenceException) { } } Match matchname = Regex.Match(nextLine, nameEx); if (matchname.Success) { string newName = matchname.Groups[1].Value; // try { xmlEvent tempEvent = new xmlEvent(); createEvents[day, eventnum] = tempEvent; createEvents[day, eventnum].setName(newName); events[day, eventnum] = createEvents[day, eventnum]; } //Get Start Time Hour Match matchstarth = Regex.Match(nextLine, startHourEx); if (matchstarth.Success) { string newHour = matchstarth.Groups[1].Value; xmltime tempTime = new xmltime(); startTimes[day, eventnum] = tempTime; startTimes[day, eventnum].setHour(int.Parse(newHour)); if (int.Parse(newHour) < 12) { startTimes[day, eventnum].setDayTime("AM"); } else { startTimes[day, eventnum].setDayTime("PM"); if (int.Parse(newHour) > 12) { startTimes[day, eventnum].setHour(int.Parse(newHour) - 12); } } createEvents[day, eventnum].starttime = startTimes[day, eventnum]; events[day, eventnum] = createEvents[day, eventnum]; } //Get Start Time Minute Match matchstartm = Regex.Match(nextLine, startMinEx); if (matchstartm.Success) { string newMin = matchstartm.Groups[1].Value; startTimes[day, eventnum].setMin(int.Parse(newMin)); createEvents[day, eventnum].starttime = startTimes[day, eventnum]; events[day, eventnum] = createEvents[day, eventnum]; } //Get End Time Hour Match matchendh = Regex.Match(nextLine, endHourEx); if (matchendh.Success) { string newHour = matchendh.Groups[1].Value; xmltime tempTime = new xmltime(); endTimes[day, eventnum] = tempTime; endTimes[day, eventnum].setHour(int.Parse(newHour)); if (int.Parse(newHour) < 12) { endTimes[day, eventnum].setDayTime("AM"); } else { endTimes[day, eventnum].setDayTime("PM"); if (int.Parse(newHour) > 12) { endTimes[day, eventnum].setHour(int.Parse(newHour) - 12); } } createEvents[day, eventnum].endtime = endTimes[day, eventnum]; events[day, eventnum] = createEvents[day, eventnum]; } //Get End Time Minute Match matchendm = Regex.Match(nextLine, endMinEx); if (matchendm.Success) { string newMin = matchendm.Groups[1].Value; endTimes[day, eventnum].setMin(int.Parse(newMin)); createEvents[day, eventnum].endtime = endTimes[day, eventnum]; events[day, eventnum] = createEvents[day, eventnum]; } //Get Location Match matchloc = Regex.Match(nextLine, locEx); if (matchloc.Success) { string newLoc = matchloc.Groups[1].Value; createEvents[day, eventnum].location = newLoc; events[day, eventnum] = createEvents[day, eventnum]; } } } day = 1; eventnum = 1; displayEvent(); xmlOutputWindow = generateXML(); outputWindow.Text = xmlOutputWindow; }
//Open an existing xml file, parse through the file and generate the array to edit private void openToolStripMenuItem_Click(object sender, EventArgs e) { clearArray(); xmlEvent[,] createEvents = new xmlEvent[rows, cols]; xmltime[,] startTimes = new xmltime[rows, cols]; xmltime[,] endTimes = new xmltime[rows, cols]; OpenFileDialog openFile = new OpenFileDialog(); openFile.InitialDirectory = Convert.ToString(Environment.SpecialFolder.MyDocuments); openFile.Filter = "Text Files (.xml)|*.xml|All Files (*.*)|*.*"; openFile.FilterIndex = 1; openFile.Multiselect = false; if (openFile.ShowDialog() == DialogResult.OK) { System.IO.StreamReader fileReader = new System.IO.StreamReader(openFile.FileName); //Parse String string nextLine = ""; string dayEx = "<day count=\"(.*?)\">"; string eventEx = "<event id=\"(.*?)\">"; string nameEx = "<name>(.*?)</name>"; string startHourEx = "<starttime>(.*?):"; string startMinEx = ":(.*?)</starttime>"; string endHourEx = "<endtime>(.*?):"; string endMinEx = ":(.*?)</endtime>"; string locEx = "<location>(.*?)</location>"; while ((nextLine = fileReader.ReadLine()) != null) { Match matchday = Regex.Match(nextLine, dayEx); if (matchday.Success) { string newDay = matchday.Groups[1].Value; day = int.Parse(newDay); } Match matchevent = Regex.Match(nextLine, eventEx); if (matchevent.Success) { createEvents[day, eventnum] = new xmlEvent();; string newEvent = matchevent.Groups[1].Value; try { eventnum = int.Parse(newEvent); } catch (NullReferenceException) { } } Match matchname = Regex.Match(nextLine, nameEx); if (matchname.Success) { string newName = matchname.Groups[1].Value; // try { xmlEvent tempEvent = new xmlEvent(); createEvents[day, eventnum] = tempEvent; createEvents[day, eventnum].setName(newName); events[day, eventnum] = createEvents[day, eventnum]; } //Get Start Time Hour Match matchstarth = Regex.Match(nextLine, startHourEx); if (matchstarth.Success) { string newHour = matchstarth.Groups[1].Value; xmltime tempTime = new xmltime(); startTimes[day, eventnum] = tempTime; startTimes[day, eventnum].setHour(int.Parse(newHour)); if (int.Parse(newHour) < 12) { startTimes[day, eventnum].setDayTime("AM"); } else { startTimes[day, eventnum].setDayTime("PM"); if (int.Parse(newHour) > 12) { startTimes[day, eventnum].setHour(int.Parse(newHour) - 12); } } createEvents[day, eventnum].starttime = startTimes[day, eventnum]; events[day, eventnum] = createEvents[day, eventnum]; } //Get Start Time Minute Match matchstartm = Regex.Match(nextLine, startMinEx); if (matchstartm.Success) { string newMin = matchstartm.Groups[1].Value; startTimes[day, eventnum].setMin(int.Parse(newMin)); createEvents[day, eventnum].starttime = startTimes[day, eventnum]; events[day, eventnum] = createEvents[day, eventnum]; } //Get End Time Hour Match matchendh = Regex.Match(nextLine, endHourEx); if (matchendh.Success) { string newHour = matchendh.Groups[1].Value; xmltime tempTime = new xmltime(); endTimes[day, eventnum] = tempTime; endTimes[day, eventnum].setHour(int.Parse(newHour)); if (int.Parse(newHour) < 12) { endTimes[day, eventnum].setDayTime("AM"); } else { endTimes[day, eventnum].setDayTime("PM"); if (int.Parse(newHour) > 12) { endTimes[day, eventnum].setHour(int.Parse(newHour) - 12); } } createEvents[day, eventnum].endtime = endTimes[day, eventnum]; events[day, eventnum] = createEvents[day, eventnum]; } //Get End Time Minute Match matchendm = Regex.Match(nextLine, endMinEx); if (matchendm.Success) { string newMin = matchendm.Groups[1].Value; endTimes[day, eventnum].setMin(int.Parse(newMin)); createEvents[day, eventnum].endtime = endTimes[day, eventnum]; events[day, eventnum] = createEvents[day, eventnum]; } //Get Location Match matchloc = Regex.Match(nextLine, locEx); if (matchloc.Success) { string newLoc = matchloc.Groups[1].Value; createEvents[day, eventnum].location = newLoc; events[day, eventnum] = createEvents[day, eventnum]; } } } day = 1; eventnum = 1; displayEvent(); xmlOutputWindow = generateXML(); outputWindow.Text = xmlOutputWindow; }