示例#1
0
        // Show the teachers
        private void lecturersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showPanel("Students");
            lbl_Students.Text = ("Lecturers");
            listViewStudents.Items.Clear();
            pnl_CashRegister.Hide();


            SomerenLogic.Lecturer_Service lecturerService = new SomerenLogic.Lecturer_Service();
            List <Teacher> lecturerList = lecturerService.GetTeachers();


            foreach (SomerenModel.Teacher t in lecturerList)
            {
                ListViewItem li = new ListViewItem(t.Name);
                listViewStudents.Items.Add(li);
            }
        }
        private void showPanel(string panelName)
        {
            if (panelName == "Dashboard")
            {
                HideAllPanels();

                // show dashboard
                pnl_Dashboard.Show();
                img_Dashboard.Show();
            }
            else if (panelName == "Students")
            {
                // hide all other panels
                HideAllPanels();

                // show students
                pnl_Students.Show();



                // fill the students listview within the students panel with a list of students
                SomerenLogic.Student_Service studService = new SomerenLogic.Student_Service();
                List <Student> studentList = studService.GetStudents();

                // clear the listview before filling it again
                listViewStudents.Clear();

                //add columns
                listViewStudents.Columns.Add("Student number");
                listViewStudents.Columns[0].Width = 100;
                listViewStudents.Columns.Add("First name");
                listViewStudents.Columns[1].Width = 100;
                listViewStudents.Columns.Add("Last name");
                listViewStudents.Columns[2].Width = 100;

                foreach (SomerenModel.Student s in studentList)
                {
                    ListViewItem li = new ListViewItem(s.Number.ToString());
                    li.SubItems.Add(s.FirstName);
                    li.SubItems.Add(s.LastName);
                    listViewStudents.Items.Add(li);
                }
            }

            else if (panelName == "Lecturers")
            {
                // Hide other panels
                HideAllPanels();

                // Show lecturers panel; clear listView
                pnl_Lecturers.Show();
                listViewLecturers.Clear();

                // Add columns
                listViewLecturers.Columns.Add("Lecturer ID");
                listViewLecturers.Columns[0].Width = 100;
                listViewLecturers.Columns.Add("First Name");
                listViewLecturers.Columns[1].Width = 100;
                listViewLecturers.Columns.Add("Last Name");
                listViewLecturers.Columns[2].Width = 100;
                listViewLecturers.Columns.Add("Is Supervisor");
                listViewLecturers.Columns[3].Width = 100;

                // Fill the lecturers listview within the lecturers panel with a list of lecturers
                SomerenLogic.Lecturer_Service lecService = new SomerenLogic.Lecturer_Service();
                List <Teacher> lecturerList = lecService.GetTeachers();

                // Iterate over teachers
                foreach (SomerenModel.Teacher t in lecturerList)
                {
                    ListViewItem li = new ListViewItem(t.Number.ToString());
                    li.SubItems.Add(t.FirstName);
                    li.SubItems.Add(t.LastName);

                    // Parse supervisor status which is either 0 or 1.
                    if (t.Supervisor == 1)
                    {
                        li.SubItems.Add("Yes");
                    }
                    else
                    {
                        li.SubItems.Add("No");
                    }
                    listViewLecturers.Items.Add(li);
                }
            }
            else if (panelName == "Drinks Supplies")
            {
                HideAllPanels();
                //Show the panel
                pnl_Drinks.Show();
                listViewDrinks.Clear();

                //Add columns
                listViewDrinks.Columns.Add("Drink");
                listViewDrinks.Columns[0].Width = 100;
                listViewDrinks.Columns.Add("Token");
                listViewDrinks.Columns[1].Width = 100;
                listViewDrinks.Columns.Add("Stock");
                listViewDrinks.Columns[2].Width = 100;
                listViewDrinks.Columns.Add("Amount");
                listViewDrinks.Columns[3].Width = 50;

                // Fill the lecturers listview within the lecturers panel with a list of lecturers
                SomerenLogic.Drink_Service drinkService = new SomerenLogic.Drink_Service();
                List <Drink> drinksList = drinkService.GetDrinks();

                foreach (SomerenModel.Drink d in drinksList)
                {
                    ListViewItem li = new ListViewItem(d.Name);
                    li.SubItems.Add(d.Token.ToString());
                    li.SubItems.Add(d.Stock.ToString());
                    d.Amount = d.Stock;

                    //listing the sufficiency
                    if (d.Amount >= 10)
                    {
                        li.SubItems.Add("✔️");
                    }
                    else
                    {
                        li.SubItems.Add("⚠️");
                    }
                    li.SubItems.Add(d.DrinksSold.ToString());


                    listViewDrinks.Items.Add(li);
                }
            }
            else if (panelName == "Edit drinks")
            {
                pnl_Drinks.Hide();

                //show panel
                pnl_UpdateDrinks.Show();
            }

            else if (panelName == "Revenue Report")
            {
                HideAllPanels();

                SomerenLogic.Report_Service reportService = new SomerenLogic.Report_Service();
                List <Report> reportsList = reportService.GetReports();

                pnl_Report.Show();
            }
            else if (panelName == "Activities")
            {
                HideAllPanels();
                pnl_Activities.Show();

                // fill the students listview within the students panel with a list of students
                SomerenLogic.Activity_Service actService = new SomerenLogic.Activity_Service();
                List <Activity> studentList = actService.GetActivities();

                // clear the listview before filling it again
                listViewActivities.Clear();

                //add columns
                listViewActivities.Columns.Add("activity_id");
                listViewActivities.Columns[0].Width = 100;
                listViewActivities.Columns.Add("name");
                listViewActivities.Columns[1].Width = 100;
                listViewActivities.Columns.Add("number of students");
                listViewActivities.Columns[2].Width = 100;
                listViewActivities.Columns.Add("number of supervisors");
                listViewActivities.Columns[2].Width = 100;

                foreach (SomerenModel.Activity s in studentList)
                {
                    ListViewItem li = new ListViewItem(s.activity_id.ToString());
                    li.SubItems.Add(s.name);
                    li.SubItems.Add(s.numberofstudents.ToString());
                    li.SubItems.Add(s.numberofsupervisors.ToString());

                    listViewActivities.Items.Add(li);
                }
            }
            else if (panelName == "Supervisors")
            {
                HideAllPanels();

                //show panel
                pnl_Supervisor.Show();
                listViewSupervisors.Clear();

                DisplayAddCB();
                DisplayRemoveCB();

                SomerenLogic.Supervisor_Service supservice = new SomerenLogic.Supervisor_Service();
                List <Supervisor> supList = supservice.GetSupervisors();

                //Add columns
                listViewSupervisors.View = View.Details;
                listViewSupervisors.Columns.Add("Lecturer ID");
                listViewSupervisors.Columns[0].Width = 80;
                listViewSupervisors.Columns.Add("Name");
                listViewSupervisors.Columns[1].Width = 120;

                foreach (SomerenModel.Supervisor s in supList)
                {
                    ListViewItem li = new ListViewItem(s.SupervisorID.ToString());
                    li.SubItems.Add(s.Name);
                    listViewSupervisors.Items.Add(li);
                }
            }

            else if (panelName == "Time Table")
            {
                HideAllPanels();
                clearTimetable();
                SomerenLogic.Timetable_Service ttService = new SomerenLogic.Timetable_Service();
                List <Activity> activities = ttService.GetTimetableData();

                Dictionary <int, string> teacherNames = ttService.GetTeacherNames();

                // Sort activities by day
                DateTime actdate = activities[0].date;
                foreach (Activity act in activities)
                {
                    //int teacher1Id = (int)act.supervisor1;
                    string t1name = TeacherLookup(teacherNames, act.supervisor1);
                    string t2name = TeacherLookup(teacherNames, act.supervisor2);

                    // Check if no supervisor is assigned
                    if (t1name == "" && t2name == "")
                    {
                        t1name = "UNSUPERVISED!";
                    }

                    string day   = act.date.DayOfWeek.ToString();
                    int    month = act.date.Month;
                    int    year  = act.date.Year;

                    // Only check activities that are within the correct year and month.
                    if (year == 2016 && month == 4)
                    {
                        // Create a list view item
                        string       time = act.date.ToString("H:mm");
                        ListViewItem item = new ListViewItem(time);
                        item.SubItems.Add(act.name);
                        item.SubItems.Add(t1name);
                        item.SubItems.Add(t2name);

                        // Switch case that filters activities by weekday. Since only monday and tuesday are relevant,
                        // those values are hardcoded as well.
                        switch (day)
                        {
                        case "Monday":
                            lv_mon.Items.Add(item);
                            break;

                        case "Tuesday":
                            lv_tue.Items.Add(item);
                            break;
                        }
                    }
                }
                SetColumnSizes();
                pnl_Timetable.Show();
            }
        }