Example #1
0
        private void PractitionerCheck_CheckedChanged(object sender, EventArgs e)
        {
            if (LecturerCheck.Checked && PractitionerCheck.Checked)
            {
                LecturerCheck.Checked = false;
            }
            if (!PractitionerCheck.Checked)
            {
                StartTime.Enabled = false;
                EndTime.Enabled   = false;
                Day.Enabled       = false;
                Search.Enabled    = false;
            }

            else
            {
                StartTime.ResetText();
                StartTime.Items.Clear();
                EndTime.ResetText();
                EndTime.Items.Clear();
                IDListBox.ResetText();
                IDListBox.Items.Clear();
                NameListBox.ResetText();
                NameListBox.Items.Clear();
                Day.Enabled = true;
                for (int i = 8; i < 21; i++)
                {
                    StartTime.Items.Add(i + ":00");
                }
                Teacher = "P";
            }
        }
Example #2
0
        private void Search_Click(object sender, EventArgs e)
        {//here we will search the practitioner/lecturer
            IDListBox.Items.Clear();
            IDListBox.ResetText();
            NameListBox.Items.Clear();
            NameListBox.ResetText();

            string  AvailTime = "", Time = "", Teacherid = "", Name = "";
            int     countUsers = 0, Start_h = 0, End_h = 0, CountConstraints = 0;
            DataSet dataset1, dataset2 = null;

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

            if (Teacher == "P")
            {
                dataset1 = SqlWorker.GetDataSet("SELECT ID,Name From Users WHERE Type LIKE 'Practitioner'");
                dataset2 = SqlWorker.GetDataSet("SELECT TeacherId,HoursAvail From Constraines_PraLec WHERE Day LIKE'" + Day.SelectedItem.ToString() + "'");
            }
            else
            {
                dataset1 = SqlWorker.GetDataSet("SELECT ID,Name From Users WHERE Type LIKE 'Lecturer'");
                dataset2 = SqlWorker.GetDataSet("SELECT TeacherId,HoursAvail From Constraines_PraLec WHERE Day LIKE'" + 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 += ',';
                }
            }


            {
                while (dataset1.Tables[0].Rows.Count > countUsers)
                {
                    while (dataset2.Tables[0].Rows.Count > CountConstraints)
                    {
                        if (dataset1.Tables[0].Rows[countUsers]["ID"].ToString() == dataset2.Tables[0].Rows[CountConstraints]["TeacherId"].ToString())
                        {
                            AvailTime = dataset2.Tables[0].Rows[CountConstraints]["HoursAvail"].ToString();
                            if (AvailTime.Contains(Time))
                            {
                                if (!((AvailTime[0] == '0' && Time == "8") || (AvailTime[1] == '0' && Time == "9")))
                                {
                                    Teacherid = dataset1.Tables[0].Rows[countUsers]["ID"].ToString();
                                    Name      = dataset1.Tables[0].Rows[0]["Name"].ToString();
                                    IDListBox.Items.Add(Teacherid);
                                    NameListBox.Items.Add(Name);
                                }
                            }
                        }
                        CountConstraints++;
                    }
                    CountConstraints = 0;
                    countUsers++;
                }
            }

            if (IDListBox.Items.Count == 0 && NameListBox.Items.Count == 0)
            {
                MessageBox.Show("No teacher was found, please try to search again with new data.", "Error"
                                , MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }