Esempio n. 1
0
        private void Lecture_CheckedChanged(object sender, EventArgs e)
        {
            //the function checks if the checkbox that was checked is lecture
            //if it does, the function will load the lectures info into the listboxes accordingly
            int Count = 0, val = 0;

            if (Lecture.Checked && Practice.Checked)
            {
                Practice.Checked = false;
            }
            if (!Lecture.Checked)
            {
                Lecture_Select.Enabled = false;
                Lecture_Select.Enabled = false;
                ID.ResetText();
                ID.Items.Clear();
                Start_Time.ResetText();
                Start_Time.Items.Clear();
                End_Time.ResetText();
                End_Time.Items.Clear();
                Courses.ResetText();
                Courses.Items.Clear();
                Days.ResetText();
                Days.Items.Clear();
                Day.Text = "";
                Teacher_ID.ResetText();
                Teacher_ID.Items.Clear();
                Lecture_Select.Enabled = true;
                Lecture_Select.Items.Clear();
                Lecture_Select.ResetText();
                Search.Enabled = false;
                StartTime.ResetText();
                StartTime.Items.Clear();
                EndTime.ResetText();
                EndTime.Items.Clear();
                Teacher.ResetText();
                Teacher.Items.Clear();
                ClassCombobox.ResetText();
                ClassCombobox.Items.Clear();
                ClassCombobox.Enabled = false;
                Teacher.Enabled       = false;
                StartTime.Enabled     = false;
                EndTime.Enabled       = false;
                Day.Enabled           = false;
            }
            else
            {
                ID.ResetText();
                ID.Items.Clear();
                Start_Time.ResetText();
                Start_Time.Items.Clear();
                End_Time.ResetText();
                End_Time.Items.Clear();
                Courses.ResetText();
                Courses.Items.Clear();
                Days.ResetText();
                Days.Items.Clear();
                Day.Text = "";
                Teacher_ID.ResetText();
                Teacher_ID.Items.Clear();
                Lecture_Select.Enabled = true;
                Lecture_Select.Items.Clear();
                Lecture_Select.ResetText();
                Search.Enabled = false;
                StartTime.ResetText();
                StartTime.Items.Clear();
                EndTime.ResetText();
                EndTime.Items.Clear();
                Teacher.ResetText();
                Teacher.Items.Clear();
                ClassCombobox.ResetText();
                ClassCombobox.Items.Clear();
                ClassCombobox.Enabled = false;
                Teacher.Enabled       = false;
                StartTime.Enabled     = false;
                EndTime.Enabled       = false;
                Day.Enabled           = false;
                if (StartTime.Items.Count == 0)
                {
                    for (int i = 8; i < 21; i++)
                    {
                        StartTime.Items.Add(i + ":00");
                    }
                }
                Lesson = "Lecture";

                if (!SqlWorker.CheckForInternetConnection())
                {
                    MessageBox.Show("There is no internet connection.\nPlease try again later.", "Error"
                                    , MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                DataSet TableShow = SqlWorker.GetDataSet("SELECT CourseName , StartTime , Day ,EndTime , Lecturer, ID From Lecture");
                val = TableShow.Tables[0].Rows.Count;
                while (val > Count)
                {
                    Lecture_Select.Items.Add(TableShow.Tables[0].Rows[Count]["ID"].ToString());
                    ID.Items.Add(TableShow.Tables[0].Rows[Count]["ID"].ToString());
                    Courses.Items.Add(TableShow.Tables[0].Rows[Count]["CourseName"].ToString());
                    Start_Time.Items.Add(TableShow.Tables[0].Rows[Count]["StartTime"].ToString());
                    End_Time.Items.Add(TableShow.Tables[0].Rows[Count]["EndTime"].ToString());
                    Days.Items.Add(TableShow.Tables[0].Rows[Count]["Day"].ToString());
                    Teacher_ID.Items.Add(TableShow.Tables[0].Rows[Count]["Lecturer"].ToString());
                    Count++;
                }
            }
        }
Esempio n. 2
0
        private void Search_Click(object sender, EventArgs e)
        {
            //here we will search for a suiting class and practitioner/lecturer according to the data we have
            New_Teacher_ID.ResetText();
            New_Teacher_ID.Items.Clear();
            New_Teacher_Name.ResetText();
            New_Teacher_Name.Items.Clear();
            Class.ResetText();
            Class.Items.Clear();
            Teacher.Items.Clear();
            Teacher.ResetText();
            ClassCombobox.ResetText();
            ClassCombobox.Items.Clear();
            Teacher.Enabled       = true;
            ClassCombobox.Enabled = true;
            UpdateDB.Enabled      = true;

            string  AvailTime = "", Time = "", TeacherKind = "", Teacherid = "", Name = "";
            int     countClass = 0, countUsers = 0, countConst = 0, Start_h = 0, End_h = 0, IsLab = -1, TeacherID = 0;
            DataSet dataset1, dataset2 = null, dataset3 = null, Classes = null, ArrLength = null;

            if (!SqlWorker.CheckForInternetConnection())
            {
                MessageBox.Show("There is no internet connection.\nPlease try again later.", "Error"
                                , MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (Lesson == "Practice")
            {
                dataset1    = SqlWorker.GetDataSet("SELECT ID,Name From Users WHERE Type LIKE 'Practitioner'");
                dataset3    = SqlWorker.GetDataSet("SELECT Practitioner, StartTime, EndTime, Day,Type From TeachingExercises WHERE ID LIKE'" + Lecture_Select.SelectedItem.ToString() + "'");
                TeacherKind = "Practitioner";
                Teacherid   = dataset3.Tables[0].Rows[0]["Practitioner"].ToString();
                dataset2    = SqlWorker.GetDataSet("SELECT HoursAvail,Day From Constraines_PraLec WHERE TeacherId ='" + Teacherid + "'AND Day LIKE'" + Day.SelectedItem.ToString() + "'");
            }
            else
            {
                dataset1    = SqlWorker.GetDataSet("SELECT ID,Name From Users WHERE Type LIKE 'Lecturer'");
                dataset3    = SqlWorker.GetDataSet("SELECT Lecturer, StartTime, EndTime, Day From Lecture WHERE ID LIKE'" + Lecture_Select.SelectedItem.ToString() + "'");
                TeacherKind = "Lecturer";
                Teacherid   = dataset3.Tables[0].Rows[0]["Lecturer"].ToString();
                dataset2    = SqlWorker.GetDataSet("SELECT HoursAvail,Day From Constraines_PraLec WHERE TeacherId ='" + Teacherid + "'AND Day LIKE'" + Day.SelectedItem.ToString() + "'");
            }
            Classes = SqlWorker.GetDataSet("SELECT * From Class WHERE Days LIKE'" + getday(Day.SelectedItem.ToString()) + "'");
            Start_h = Int32.Parse(StartTime.SelectedItem.ToString().Split(':')[0]);
            End_h   = Int32.Parse(EndTime.SelectedItem.ToString().Split(':')[0]);

            for (int i = Start_h; i < End_h; i++)
            {
                Time += i;
                if (i != End_h - 1)
                {
                    Time += ',';
                }
            }

            Start_h = Int32.Parse(dataset3.Tables[0].Rows[0]["StartTime"].ToString().Split(':')[0]);
            End_h   = Int32.Parse(dataset3.Tables[0].Rows[0]["EndTime"].ToString().Split(':')[0]);

            ArrLength = SqlWorker.GetDataSet("SELECT StartingTime, EndingTime From Constraines_PraLec WHERE TeacherId LIKE'" + Teacherid + "'AND Day LIKE'" + Day.SelectedItem.ToString() + "'");
            int Len = Int32.Parse(ArrLength.Tables[0].Rows[0]["EndingTime"].ToString().Split(':')[0]) - Int32.Parse(ArrLength.Tables[0].Rows[0]["StartingTime"].ToString().Split(':')[0]) + 1;

            int[] LPhours = new int[Len];
            int   j       = Start_h;

            if (dataset3.Tables[0].Rows[0]["Day"].ToString() == Day.SelectedItem.ToString())
            {
                Convert(LPhours, dataset2.Tables[0].Rows[0]["HoursAvail"].ToString(), true);
                for (int i = 0; i < LPhours.Length - 1; i++)
                {
                    if (Start_h != 8 && LPhours[i] >= Start_h - 1 && LPhours[i] < End_h)
                    {
                        LPhours[i + 1] = j;
                        j++;
                    }
                    else if (Start_h == 8)
                    {
                        LPhours[i] = 8;
                    }
                }
                for (int i = 0; i < LPhours.Length; i++)
                {
                    AvailTime += LPhours[i];
                    if (i != LPhours.Length - 1)
                    {
                        AvailTime += ',';
                    }
                }
            }
            else
            {
                AvailTime = dataset2.Tables[0].Rows[0]["HoursAvail"].ToString();
            }
            if (AvailTime.Contains(Time))
            {
                if (!((AvailTime[0] == '0' && Time == "8") || (AvailTime[1] == '0' && Time == "9")))
                {
                    while (dataset1.Tables[0].Rows.Count > countUsers)
                    {
                        if (dataset1.Tables[0].Rows[countUsers]["ID"].ToString() == Teacherid)
                        {
                            Name = dataset1.Tables[0].Rows[0]["Name"].ToString();
                        }
                        countUsers++;
                    }
                    Teacher.Items.Add(Teacherid);
                    New_Teacher_ID.Items.Add(Teacherid);
                    New_Teacher_Name.Items.Add(Name);
                }
            }
            countUsers = 0;
            if (Teacher.Items.Count == 0)
            {
                dataset2 = SqlWorker.GetDataSet("SELECT TeacherId,HoursAvail,Day From Constraines_PraLec WHERE Day LIKE'" + Day.SelectedItem.ToString() + "'");
                while (dataset1.Tables[0].Rows.Count > countUsers)
                {
                    while (dataset1.Tables[0].Rows.Count > countConst)
                    {
                        if (dataset1.Tables[0].Rows[countUsers]["ID"].ToString() == dataset2.Tables[0].Rows[countConst]["TeacherId"].ToString())
                        {
                            ArrLength = SqlWorker.GetDataSet("SELECT StartingTime, EndingTime From Constraines_PraLec WHERE TeacherId LIKE'" + Teacherid + "'AND Day LIKE'" + Day.SelectedItem.ToString() + "'");
                            Len       = Int32.Parse(ArrLength.Tables[0].Rows[0]["EndingTime"].ToString().Split(':')[0]) - Int32.Parse(ArrLength.Tables[0].Rows[0]["StartingTime"].ToString().Split(':')[0]) + 1;
                            LPhours   = new int[Len];
                            if (dataset3.Tables[0].Rows[0]["Day"].ToString() == Day.SelectedItem.ToString())
                            {
                                Convert(LPhours, dataset2.Tables[0].Rows[0]["HoursAvail"].ToString(), true);
                                j = Start_h;
                                for (int i = 0; i < LPhours.Length - 1; i++)
                                {
                                    if (Start_h != 8 && LPhours[i] >= Start_h - 1 && LPhours[i] < End_h)
                                    {
                                        LPhours[i + 1] = j;
                                        j++;
                                    }
                                    else if (Start_h == 8)
                                    {
                                        LPhours[i] = 8;
                                    }
                                }
                                for (int i = 0; i < LPhours.Length; i++)
                                {
                                    AvailTime += LPhours[i];
                                    if (i != LPhours.Length - 1)
                                    {
                                        AvailTime += ',';
                                    }
                                }
                            }
                            else
                            {
                                AvailTime = dataset2.Tables[0].Rows[0]["HoursAvail"].ToString();
                            }
                            if (AvailTime.Contains(Time))
                            {
                                if (!((AvailTime[0] == '0' && Time == "8") || (AvailTime[1] == '0' && Time == "9")))
                                {
                                    Teacher.Items.Add(dataset2.Tables[0].Rows[countConst]["TeacherId"].ToString());
                                    New_Teacher_ID.Items.Add(dataset2.Tables[0].Rows[countConst]["TeacherId"].ToString());
                                    New_Teacher_Name.Items.Add(dataset1.Tables[0].Rows[countConst]["Name"].ToString());
                                }
                            }
                            AvailTime = "";
                        }
                        countConst++;
                    }
                    countUsers++;
                    countConst = 0;
                }
            }

            if (New_Teacher_ID.Items.Count == 0 && New_Teacher_Name.Items.Count == 0)
            {
                UpdateDB.Enabled = false;
                MessageBox.Show("No teacher was found, please try to search again with new data.", "Error"
                                , MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            AvailTime  = "";
            countClass = 0;

            while (Classes.Tables[0].Rows.Count > countClass)
            {
                if (dataset3.Tables[0].Rows[0]["Day"].ToString() == Day.SelectedItem.ToString())
                {
                    Convert(hours, Classes.Tables[0].Rows[0]["Hours"].ToString(), false);
                    for (int i = Start_h; i < End_h; i++)
                    {
                        hours[i] = i;
                    }
                    for (int i = 0; i < hours.Length; i++)
                    {
                        AvailTime += hours[i];
                        if (i != hours.Length - 1)
                        {
                            AvailTime += ',';
                        }
                    }
                }
                else
                {
                    AvailTime = Classes.Tables[0].Rows[countClass]["Hours"].ToString();
                }

                if (Lesson == "Practice")
                {
                    IsLab = Int32.Parse(Classes.Tables[0].Rows[countClass]["IsLab"].ToString());
                    if (AvailTime.Contains(Time) && (CheckIfLab(dataset3.Tables[0].Rows[0]["Type"].ToString()) == IsLab))
                    {
                        if (!((AvailTime[0] == '0' && Time == "8") || (AvailTime[1] == '0' && Time == "9")))
                        {
                            ClassCombobox.Items.Add(Classes.Tables[0].Rows[countClass]["Room"].ToString());
                            Class.Items.Add(Classes.Tables[0].Rows[countClass]["Room"].ToString());
                        }
                    }
                }
                else
                {
                    if (AvailTime.Contains(Time))
                    {
                        if (!((AvailTime[0] == '0' && Time == "8") || (AvailTime[1] == '0' && Time == "9")))
                        {
                            ClassCombobox.Items.Add(Classes.Tables[0].Rows[countClass]["Room"].ToString());
                            Class.Items.Add(Classes.Tables[0].Rows[countClass]["Room"].ToString());
                        }
                    }
                }
                AvailTime = "";
                countClass++;
            }

            if (Class.Items.Count == 0)
            {
                UpdateDB.Enabled = true;
                MessageBox.Show("No class was found, please try to search again with new data.", "Error"
                                , MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }