Beispiel #1
0
        private bool SlotTeacherConstraint(UControl child, List <Assignment> assignments, ref string msg)
        {
            bool TeacherContraintViolated = true;

            if (txtTeacherId.Text == "" || txtTeacherId.Text == null)
            {
                return(false);
            }
            int row    = int.Parse(child.Row) - 1;
            int column = int.Parse(child.Column) - 1;

            //check if teacher is busy on that slot
            List <Assignment> allBusyPeriods = assignments.FindAll(x => x.Teacher_id == int.Parse(txtTeacherId.Text)).ToList();

            if (allBusyPeriods == null)
            {
                TeacherContraintViolated = false;
            }
            else
            {
                var checkGivenPeriod = allBusyPeriods.Find(x => x.Day == column && x.Starting_period <= row && x.Ending_period > row);
                if (checkGivenPeriod == null)
                {
                    TeacherContraintViolated = false;
                }
                else
                {
                    msg += ((msg == "") ? "" : ", ") + " Teacher is busy \n(Class " + checkGivenPeriod.Course_name.Replace("_", ", ")
                           + " \nfrom " + checkGivenPeriod.getCourseTextPeriod() + ")";
                    TeacherContraintViolated = true;
                }
            }

            return(TeacherContraintViolated);
        }
Beispiel #2
0
        private bool CoursePeriodPreferences(UControl child, ref string msg)
        {
            int cRow    = int.Parse(child.Row);
            int cColumn = int.Parse(child.Column);

            int parentPeriod = ((cRow - 1) / 4) + 1;

            bool PeriodContraintViolated = true;

            DataTable courseData = DBConnection.Select("course_periods_preferences ", " day, period  ", " course_id=" + int.Parse(txtClassId.Text) + " AND day=" + cColumn + " AND period=" + parentPeriod);

            if (courseData != null && courseData.Rows.Count > 0)
            {
                PeriodContraintViolated = true;
            }
            else
            {
                PeriodContraintViolated = false;
            }

            if (PeriodContraintViolated)
            {
                msg += ((msg == "") ? "" : ", ") + " Teacher doesn't teach at this time";
            }
            return(PeriodContraintViolated);
        }
 public UControl(bool addRows, string row = null, string column = null)
 {
     try
     {
         InitializeComponent();
         lblClicked.Text         = "false";
         lblControlAssigned.Text = "false";
         if (addRows == true)
         {
             for (int i = 0; i < 4; i++)
             {
                 gridPanel.RowDefinitions.Add(new RowDefinition());
                 UControl panel = new UControl(false);
                 panel.Row    = (((Convert.ToInt32(row) - 1) * 4) + i + 1).ToString();
                 panel.Column = column;
                 Grid.SetColumn(panel, 0);
                 Grid.SetRow(panel, i);
                 gridPanel.Children.Add(panel);
             }
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Beispiel #4
0
        private string getCurrentPeriod(UControl position, int courseId)
        {
            string returnText = "";

            Dictionary <string, string> first = new Dictionary <string, string>();
            string    name;
            ArrayList rec = DBConnection.Get("subPeriods", int.Parse(position.Row));

            first = (Dictionary <string, string>)rec[0];
            first.TryGetValue("name", out name);

            returnText = name + " to " + TimetablingResultDisplay.getEndingPeriod(name, courseId);

            return(returnText);
        }
Beispiel #5
0
        private bool SlotRoomConstraint(UControl child, List <Assignment> assignments, ref string msg)
        {
            bool RoomContraintViolated = true;

            int roomId = int.Parse(comboBoxRooms.SelectedValue.ToString());
            Dictionary <string, string> first = new Dictionary <string, string>();

            ArrayList data = DBConnection.Get("rooms", roomId);

            first = (Dictionary <string, string>)data[0];

            string code;

            first.TryGetValue("code", out code);

            int row    = int.Parse(child.Row) - 1;
            int column = int.Parse(child.Column) - 1;

            //check if room is busy on that slot
            List <Assignment> allBusyPeriods = assignments.FindAll(x => x.Room_code == code).ToList();

            if (allBusyPeriods == null)
            {
                RoomContraintViolated = false;
            }
            else
            {
                var checkGivenPeriod = allBusyPeriods.Find(x => x.Day == column && x.Starting_period <= row && x.Ending_period > row);
                if (checkGivenPeriod == null)
                {
                    RoomContraintViolated = false;
                }
                else
                {
                    msg += ((msg == "") ? "" : ", ") + " Room is busy\n (Class " + checkGivenPeriod.Course_name.Replace("_", ", ") +
                           " \nfrom " + checkGivenPeriod.getCourseTextPeriod() + ")";
                    RoomContraintViolated = true;
                }
            }

            return(RoomContraintViolated);
        }
Beispiel #6
0
        private bool SlotHardConstraints(UControl child, List <Assignment> assignments)
        {
            bool   ContraintViolated = true;
            string message           = "";

            if (comboBoxRooms.SelectedIndex >= 0)
            {
                ContraintViolated = (SlotTeacherConstraint(child, assignments, ref message) || SlotCurriculaConstraint(child, assignments, ref message) || SlotRoomConstraint(child, assignments, ref message) || CoursePeriodPreferences(child, ref message));
                if (message != "")
                {
                    child.gridPanel.ToolTip = message;
                }
            }
            else
            {
                ContraintViolated = (SlotTeacherConstraint(child, assignments, ref message) || SlotCurriculaConstraint(child, assignments, ref message) || CoursePeriodPreferences(child, ref message));
                if (message != "")
                {
                    child.gridPanel.ToolTip = message;
                }
            }
            return(ContraintViolated);
        }
Beispiel #7
0
        private bool SlotCurriculaConstraint(UControl child, List <Assignment> assignments, ref string msg)
        {
            bool CurriculaContraintViolated = true;

            string columns = " c.id, c.code ";
            string from    = "courses c" +
                             " LEFT JOIN course_department_rel cdr ON c.id = cdr.course_id ";
            string conditions = "";

            switch (txtDetail.Text)
            {
            case "lecture":
                conditions = "c.parent_id IS NOT null AND c.semester_id=" + int.Parse(txtSemester.Text) + " AND cdr.department_id IN (" + txtDepartmentIds.Text + ") AND c.lecture_group='" + txtLectureGroup.Text + "' ";
                break;

            case "numeric":
                conditions = "c.parent_id IS NOT null AND c.semester_id=" + int.Parse(txtSemester.Text) + " AND cdr.department_id IN (" + txtDepartmentIds.Text + ") AND c.lecture_group='" + txtLectureGroup.Text +
                             "' AND c.id IN (SELECT c1.id FROM courses c1 WHERE (c1.numeric_group='" + txtNumericGroup.Text +
                             "' OR c1.numeric_group IS NULL) AND c1.lecture_group = c.lecture_group) ";
                break;

            case "laboratory":
                conditions = "c.parent_id IS NOT null AND c.semester_id=" + int.Parse(txtSemester.Text) + " AND cdr.department_id IN (" + txtDepartmentIds.Text + ") AND c.lecture_group='" + txtLectureGroup.Text +
                             "' AND c.id IN (SELECT c1.id FROM courses c1 WHERE (c1.laboratory_group='" + txtLaboratoryGroup.Text + "' OR c1.laboratory_group IS NULL) AND(c1.numeric_group='" + txtNumericGroup.Text +
                             "' OR c1.numeric_group IS NULL) AND c1.lecture_group = c.lecture_group) ";
                break;
            }

            DataTable curricula = DBConnection.Select(from, columns, conditions);

            if (curricula != null && curricula.Rows.Count > 0)
            {
                int row    = int.Parse(child.Row) - 1;
                int column = int.Parse(child.Column) - 1;

                foreach (DataRow c in curricula.Rows)
                {
                    //check if students are busy on that slot
                    List <Assignment> allBusyPeriods = assignments.FindAll(x => x.Course_code == c.ItemArray[1].ToString()).ToList();
                    if (allBusyPeriods == null)
                    {
                        CurriculaContraintViolated = false;
                    }
                    else
                    {
                        var checkGivenPeriod = allBusyPeriods.Find(x => x.Day == column && x.Starting_period <= row && x.Ending_period > row);
                        if (checkGivenPeriod == null)
                        {
                            CurriculaContraintViolated = false;
                        }
                        else
                        {
                            msg += ((msg == "") ? "" : ", ") + " Students are busy\n (Class " + checkGivenPeriod.Course_name.Replace("_", ", ") +
                                   " \nfrom " + checkGivenPeriod.getCourseTextPeriod() + ")";
                            CurriculaContraintViolated = true;
                            break;
                        }
                    }
                }
            }
            else
            {
                CurriculaContraintViolated = false;
            }

            return(CurriculaContraintViolated);
        }
Beispiel #8
0
        private int GetWindowViolation(UControl child, List <Assignment> assignments, ref string message)
        {
            //Each time window in a curriculum counts as many violation as its length (in periods).
            int window = 0;

            int row    = int.Parse(child.Row) - 1;
            int column = int.Parse(child.Column) - 1;

            int breaks = 0;

            switch (int.Parse(txtNumberofLectures.Text) % 2)
            {
            case 0:
                breaks = (int.Parse(txtNumberofLectures.Text) - 2) / 2;
                break;

            case 1:
                breaks = (int.Parse(txtNumberofLectures.Text) - 1) / 2;
                break;
            }

            int lecturePeriods = 3 * int.Parse(txtNumberofLectures.Text);
            int endPeriod      = int.Parse(child.Row) + (3 * int.Parse(txtNumberofLectures.Text)) + breaks - 1;

            string columns = " c.id, c.code ";
            string from    = "courses c" +
                             " LEFT JOIN course_department_rel cdr ON c.id = cdr.course_id ";
            string conditions = "";

            switch (txtDetail.Text)
            {
            case "lecture":
                conditions = "c.parent_id IS NOT null AND c.semester_id=" + int.Parse(txtSemester.Text) + " AND cdr.department_id IN (" + txtDepartmentIds.Text + ") AND c.lecture_group='" + txtLectureGroup.Text + "' ";
                break;

            case "numeric":
                conditions = "c.parent_id IS NOT null AND c.semester_id=" + int.Parse(txtSemester.Text) + " AND cdr.department_id IN (" + txtDepartmentIds.Text + ") AND c.lecture_group='" + txtLectureGroup.Text +
                             "' AND c.id IN (SELECT c1.id FROM courses c1 WHERE (c1.numeric_group='" + txtNumericGroup.Text +
                             "' OR c1.numeric_group IS NULL) AND c1.lecture_group = c.lecture_group) ";
                break;

            case "laboratory":
                conditions = "c.parent_id IS NOT null AND c.semester_id=" + int.Parse(txtSemester.Text) + " AND cdr.department_id IN (" + txtDepartmentIds.Text + ") AND c.lecture_group='" + txtLectureGroup.Text +
                             "' AND c.id IN (SELECT c1.id FROM courses c1 WHERE (c1.laboratory_group='" + txtLaboratoryGroup.Text + "' OR c1.laboratory_group IS NULL) AND(c1.numeric_group='" + txtNumericGroup.Text +
                             "' OR c1.numeric_group IS NULL) AND c1.lecture_group = c.lecture_group) ";
                break;
            }

            DataTable         curricula    = DBConnection.Select(from, columns, conditions);
            List <Assignment> beforeAssign = new List <Assignment>();
            List <Assignment> afterAssign  = new List <Assignment>();

            if (curricula != null && curricula.Rows.Count > 0)
            {
                foreach (DataRow c in curricula.Rows)
                {
                    //check if students are busy on that slot
                    var before = assignments.FindAll(x => x.Course_code == c.ItemArray[1].ToString() && x.Day == column && x.Ending_period < int.Parse(child.Row)).FirstOrDefault();
                    if (before != null)
                    {
                        beforeAssign.Add(before);
                    }

                    var after = assignments.FindAll(x => x.Course_code == c.ItemArray[1].ToString() && x.Day == column && x.Starting_period > row).FirstOrDefault();
                    if (after != null)
                    {
                        afterAssign.Add(after);
                    }
                }
                Assignment beforeAssign1;
                if (beforeAssign.Count > 0)
                {
                    beforeAssign1 = beforeAssign.OrderByDescending(x => x.Ending_period).FirstOrDefault();
                    window       += (row - beforeAssign1.Ending_period);
                }

                Assignment afterAssign1;
                if (afterAssign.Count > 0)
                {
                    afterAssign1 = afterAssign.OrderBy(x => x.Starting_period).FirstOrDefault();

                    int difference = (afterAssign1.Starting_period - endPeriod);
                    if (difference < 0) //for same period result = 0
                    {
                        window += 100;
                    }
                    else
                    {
                        window += difference;
                    }
                }
                else
                {
                    UControl        otherAfterItem = childs.FindAll(x => x.Column == child.Column && int.Parse(x.Row) > row && x.ControlAssigned == "true").OrderBy(x => int.Parse(x.Row)).FirstOrDefault();
                    List <UControl> dayItems       = childs.FindAll(x => x.Column == child.Column);
                    int             assignedDiff   = 0;
                    if (otherAfterItem != null)
                    {
                        assignedDiff = (int.Parse(otherAfterItem.Row) - (endPeriod + 1));
                    }

                    int difference = (dayItems.Count - endPeriod);
                    if ((difference < 0) || assignedDiff < 0)
                    {
                        window += 100;
                    }
                }

                // Calculate room busy periods
                if (comboBoxRooms.SelectedIndex >= 0)
                {
                    Dictionary <string, string> first = new Dictionary <string, string>();

                    ArrayList data = DBConnection.Get("rooms", int.Parse(comboBoxRooms.SelectedValue.ToString()));
                    first = (Dictionary <string, string>)data[0];

                    string roomCode;
                    first.TryGetValue("code", out roomCode);
                    List <Assignment> roomAssign = assignments.FindAll(x => x.Room_code == roomCode && x.Day == column && (x.Starting_period <endPeriod && x.Starting_period> row));
                    if (roomAssign.Count > 0)
                    {
                        window += 100;
                    }
                }

                // Calculate teacher busy periods
                if (txtTeacherId.Text != "" && txtTeacherId.Text != null)
                {
                    List <Assignment> teacherAssign = assignments.FindAll(x => x.Teacher_id == int.Parse(txtTeacherId.Text) && x.Day == column && (x.Starting_period <endPeriod && x.Starting_period> row));
                    if (teacherAssign.Count > 0)
                    {
                        window += 100;
                    }
                }
            }
            if (window > 0 && window < 100)
            {
                int      minutes = window * 15;
                TimeSpan ts      = TimeSpan.FromMinutes(minutes);
                var      res     = (((int)ts.TotalHours > 0) ? ((int)ts.TotalHours + "h ") : "") + ((ts.Minutes > 0) ? (ts.Minutes + "mins") : "");
                message += ", \nbut students will wait for " + res;
            }
            else if (window >= 100)
            {
                message = " \n(Class " + txtClass.Text.Replace("_", ", ") + " \nfrom " + getCurrentPeriod(child, int.Parse(txtClassId.Text)) + ")";
            }
            return(window);
        }
Beispiel #9
0
        public void initPanels()
        {
            int iRow = -1;

            foreach (RowDefinition row in GridMain.RowDefinitions)
            {
                iRow++;
                int      iCol = -1;
                UControl ucPanel;
                foreach (ColumnDefinition col in GridMain.ColumnDefinitions)
                {
                    iCol++;

                    if (iRow == 0)
                    {
                        ucPanel = new UControl(false);
                        switch (iCol)
                        {
                        case 1:
                            ucPanel.Caption = "Monday";
                            break;

                        case 2:
                            ucPanel.Caption = "Tuesday";
                            break;

                        case 3:
                            ucPanel.Caption = "Wednesday";
                            break;

                        case 4:
                            ucPanel.Caption = "Thursday";
                            break;

                        case 5:
                            ucPanel.Caption = "Friday";
                            break;

                        case 6:
                            ucPanel.Caption = "Saturday";
                            break;

                        case 7:
                            ucPanel.Caption = "Sunday";
                            break;

                        default:
                            ucPanel.Caption = "";
                            break;
                        }
                    }
                    else
                    {
                        switch (iCol)
                        {
                        case 0:
                            ucPanel         = new UControl(false);
                            ucPanel.Caption = "";

                            switch (iRow)
                            {
                            case 1:
                                ucPanel.Caption = "08:00-09:00";
                                break;

                            case 2:
                                ucPanel.Caption = "09:00-10:00";
                                break;

                            case 3:
                                ucPanel.Caption = "10:00-11:00";
                                break;

                            case 4:
                                ucPanel.Caption = "11:00-12:00";
                                break;

                            case 5:
                                ucPanel.Caption = "12:00-13:00";
                                break;

                            case 6:
                                ucPanel.Caption = "13:00-14:00";
                                break;

                            case 7:
                                ucPanel.Caption = "14:00-15:00";
                                break;

                            case 8:
                                ucPanel.Caption = "15:00-16:00";
                                break;

                            case 9:
                                ucPanel.Caption = "16:00-17:00";
                                break;

                            case 10:
                                ucPanel.Caption = "17:00-18:00";
                                break;

                            case 11:
                                ucPanel.Caption = "18:00-19:00";
                                break;

                            case 12:
                                ucPanel.Caption = "19:00-20:00";
                                break;

                            case 13:
                                ucPanel.Caption = "20:00-21:00";
                                break;

                            case 14:
                                ucPanel.Caption = "21:00-22:00";
                                break;

                            default:
                                ucPanel.Caption = "";
                                break;
                            }
                            break;

                        default:
                            ucPanel         = new UControl(true, iRow.ToString(), iCol.ToString());
                            ucPanel.Caption = "";
                            break;
                        }
                    }

                    Grid.SetColumn(ucPanel, iCol);
                    Grid.SetRow(ucPanel, iRow);

                    GridMain.Children.Add(ucPanel);
                }
            }
        }