private void BegNtsClick(object sender, RoutedEventArgs e) { TreeViewItem cur = (TreeViewItem)Tree.SelectedItem; for (int i = 0; i < Sems.Count; i++) { //Find semester of cur Semester sem = (Semester)Sems[i]; if (cur.Name.Contains(sem.Name)) { //Find class of cur for (int j = 0; j < sem.classes.Count; j++) { SchoolClass cls = (SchoolClass)sem.classes[j]; if (cur.Name.Contains(cls.Name)) { //cur is a day, find it for (int h = 0; h < cls.days.Count; h++) { Day day = (Day)cls.days[h]; if (CleanString(cur.Header.ToString()) == day.date) { TreeViewItem newtvi = new TreeViewItem() { Header = "Notes", Name = "Notes_" + sem.Name + "_" + cls.Name + "_" + CleanString(day.date) }; cur.Items.Add(newtvi); cur.IsExpanded = true; newtvi.IsSelected = true; LargeTxt.SelectAll(); LargeTxt.Selection.Text = ""; TextRange t = new TextRange(LargeTxt.Document.ContentStart, LargeTxt.Document.ContentEnd); FileStream file = new FileStream("Notes_" + sem.Name + "_" + cls.Name + "_" + CleanString(day.date) + ".rtf", FileMode.Create); t.Save(file, System.Windows.DataFormats.Rtf); file.Close(); return; //stop iterating after adding the assignment } } } } } } }
private void TreeClicked(object sender, RoutedEventArgs e) { TreeViewItem cur = (TreeViewItem)Tree.SelectedItem; if (cur == null) { return; } if (cur.Name.Contains("asg_")) { //Clicked on an assignment, display the description! for (int i = 0; i < Sems.Count; i++) { //Find semester of cur Semester sem = (Semester)Sems[i]; if (cur.Name.Contains(sem.Name)) { //Find class of cur for (int j = 0; j < sem.classes.Count; j++) { SchoolClass cls = (SchoolClass)sem.classes[j]; if (cur.Name.Contains(cls.Name)) { //cur is a day, find it for (int h = 0; h < cls.days.Count; h++) { Day day = (Day)cls.days[h]; if (cur.Name.Contains(day.date)) { for (int z = 0; z < day.Assigns.Count; z++) { string assign = (string)day.Assigns[z]; if (assign.Contains(cur.Header.ToString())) { LargeTxt.SelectAll(); LargeTxt.Selection.Text = ""; LargeTxt.AppendText(assign); return; } } //stop iterating after displaying } } } } } } } else if (cur.Name.Contains("Notes_")) { LargeTxt.SelectAll(); LargeTxt.Selection.Text = ""; TextRange t = new TextRange(LargeTxt.Document.ContentStart, LargeTxt.Document.ContentEnd); FileStream file = new FileStream(cur.Name + ".rtf", FileMode.Open); t.Load(file, System.Windows.DataFormats.Rtf); file.Close(); } else if (cur.Name.Contains("sem_")) { for (int i = 0; i < Sems.Count; i++) { Semester sem = (Semester)Sems[i]; if (cur.Name.Contains(sem.Name)) { if (sem.DueDates.Count > 0) { int closedues = 0; StringBuilder sb = new StringBuilder(); for (int j = 0; j < sem.DueDates.Count; j = j + 2) { DateTime dt = (DateTime)sem.DueDates[j]; DateTime current = DateTime.Today; for (int h = 0; h < 8; h++) { DateTime tempcur = current.AddDays(h); if (tempcur == dt) { string temp = (string)sem.DueDates[j + 1]; sb.Append(dt.ToShortDateString() + ": " + temp); sb.Append(Environment.NewLine); closedues++; } } } if (closedues > 0) { SmallTxt.Text = ""; SmallTxt.Text = sb.ToString(); } } } } } }