// remove one panel from the pannel array private void removePanelFromArray(PanelLsn p) { if (pnl_Lessons == null || p == null) { return; } pnl_Lessons.Remove(p); }
// init the lesson that should be showing public void setSelectedLessons_callback(Lesson lsn = null, bool dontAddThisLesson = false, bool updateSource = false) { if (lsn != null) { PanelLsn pn = pnl_Lessons.Find(ps => ps.lsn.courseName.Equals(lsn.courseName) && ps.lsn.type.Equals(lsn.type)); pnl_Lessons.Remove(pn); pnl_Schedule.Controls.Remove(pn); pnl_Schedule.Invalidate(); for (int i = 0; i < lessons.amount(); i++) { if (lessons[i].courseName.Equals(lsn.courseName) && lessons[i].type.Equals(lsn.type)) { lessons.remove(lessons[i]); break; } } if (!dontAddThisLesson) { addLessonToPanel(lsn); lessons.add(lsn); } if (updateSource) { mainForm.checkedLessonsFromCourses = lessons.getList(); mainForm.dataProgram.checkedCourses = lessons.getList(); } checkCollision(lessons); } else { List <Lesson> list = new List <Lesson>(); for (int i = 0; i < cards.Length; i++) { Lesson[] arr = cards[i].getSelectedLessons(); for (int j = 0; j < arr.Length; j++) { if (arr[j] != null) { list.Add(arr[j]); } } } LessonList temp = new LessonList(list.ToArray()); setSceduleByList(temp); return; } }
// Add panel of lesson to the panels array private void addPanelToArray(ref PanelLsn p) { if (pnl_Lessons == null) { pnl_Lessons = new List <PanelLsn>(); pnl_Lessons.Add(p); return; } if (p == null) { p = new PanelLsn(); } pnl_Lessons.Add(p); }
// add lesson panel to the week schedule panel private void addLessonToPanel(Lesson lsn) { if (lsn == null || lessons.getLessons() == null || (pnl_Lessons != null && pnl_Lessons.Find(ps => ps.lsn.courseName.Equals(lsn.courseName) && ps.lsn.type.Equals(lsn.type) && ps.lsn.getShortDay().Equals(lsn.getShortDay()) && ps.lsn.start == lsn.start && ps.lsn.end == lsn.end) != null)) { return; } PanelLsn p = new PanelLsn(); initPanelLessonData(ref p, lsn); addPanelToArray(ref p); pnl_Schedule.Controls.Add(p); pnl_Lessons.ForEach(delegateToBringToFront); pnl_Schedule.Invalidate(); }
// Remove one panel list from the schedule panel private bool removeLessonFromPanel(Lesson lsn) { if (lsn == null) { return(true); } PanelLsn p = foundPanelLesson(lsn); if (p != null) { removePanelFromArray(p); pnl_Schedule.Controls.Remove(p); pnl_Schedule.Invalidate(); return(true); } return(false); }
// need to work on this function, find the currect panels, and disable them public void enableCards_callback(Lesson lsn, bool enable) { //Panel[] arr = pnl_Lessons.ToArray(); for (int i = 0; i < lessons.amount(); i++) { if (lessons[i].courseName.Equals(lsn.courseName)) { PanelLsn p = foundPanelLesson(lessons[i]); if (p != null) { if (!enable) { p.Hide(); } else { p.Show(); } p.Invalidate(); } } } }
// delegate function to bring panel on the scedule panel private void delegateToBringToFront(PanelLsn p) { p.BringToFront(); }
// init the properties data of the panel Lesson private void initPanelLessonData(ref PanelLsn p, Lesson lsn) { if (lsn == null) { return; } if (p == null) { p = new PanelLsn(); } p.lsn = lsn; int dayIndex = Array.IndexOf(DAYS, lsn.getFullDay()); if (dayIndex >= 0) { p.Width = (days[dayIndex].Width - 1); } p.Height = (hours[lsn.end - START_HOUR].Location.Y + hours[lsn.end - START_HOUR].Height) - (hours[lsn.start - START_HOUR].Location.Y + hours[lsn.start - START_HOUR].Height) - 2 * THICKNESS_HR_SEPERADE; p.RightToLeft = RightToLeft.Yes; p.Location = new Point(days[dayIndex].Location.X + 1, (hours[lsn.start - START_HOUR].Location.Y) + 1); // round edges panel p.Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, p.Width, p.Height, 20, 20)); // the content lables Label[] lbl_lessons = new Label[3]; // name+type, lecturer, className//GrowLabel[] lbl_lessons = new GrowLabel[3]; // name+type, lecturer, className for (int k = 0; k < lbl_lessons.Length; k++) { lbl_lessons[k] = new GrowLabel(); lbl_lessons[k].AutoSize = false; lbl_lessons[k].Height = p.Height / 3; lbl_lessons[k].Width = p.Width; lbl_lessons[k].BackColor = Color.Transparent; lbl_lessons[k].TextAlign = ContentAlignment.MiddleCenter; int size = 10; switch (lsn.weekHour) { case 1: size = 9; break; case 2: size = 11; break; case 3: size = 11; break; case 4: size = 11; break; case 5: size = 11; break; default: size = 13; break; } lbl_lessons[k].Font = new Font(FONT_TEXT, size); switch (k) { case 0: // course name lbl_lessons[k].Text = lsn.type + "-" + lsn.courseName; lbl_lessons[k].Location = new Point(0, 0); lbl_lessons[k].TextAlign = ContentAlignment.MiddleCenter; lbl_lessons[k].Font = new Font(lbl_lessons[k].Font, FontStyle.Underline | FontStyle.Bold); break; case 1: // lecturer name lbl_lessons[k].Text = lsn.lecturer; lbl_lessons[k].Location = new Point(0, p.Height / 2 - lbl_lessons[k].Height / 2); break; case 2: // class name lbl_lessons[k].Text = "כיתה: " + lsn.className; lbl_lessons[k].Location = new Point(0, p.Height - lbl_lessons[k].Height); break; default: break; } if (!lbl_lessons[k].Text.Equals("")) { if (lbl_lessons[k].Width != days[dayIndex].Width - 1) { if (lsn.weekHour == 1 || lsn.weekHour == 2) { if (k == 0 || k == 2) { p.Controls.Add(lbl_lessons[k]); } } else { p.Controls.Add(lbl_lessons[k]); } } else { if (lsn.weekHour == 1 && k != 1) { p.Controls.Add(lbl_lessons[k]); } else if (lsn.weekHour > 1) { p.Controls.Add(lbl_lessons[k]); } } } p.BringToFront(); for (int i = 0; i < cards.Length; i++) { if (cards[i].getCourseName().Equals(lsn.courseName)) { p.BackColor = cards[i].getCard().BackColor; break; } } } p.Tag = lsn.courseName + " " + lsn.type.Substring(0, 1); }