コード例 #1
0
        private void button7_Click(object sender, EventArgs e)
        {
            comboBox6.SelectedIndex = -1;

            comboBox6.Items.Clear();
            if (comboBox4.SelectedIndex == -1 || comboBox5.SelectedIndex == -1)
            {
                MessageBox.Show("Must enter hours before");
                return;
            }
            string    start = comboBox4.SelectedItem.ToString();
            string    end = comboBox5.SelectedItem.ToString();
            string    start2, end2, ClassName, ClassName2, day2;
            int       capacity;
            bool      flag    = true;
            DataTable Lessons = Program.get_dt("select StartH,EndH,ClassName,day from lessons");
            DataTable Classes = Program.get_dt("select id,capacity from classes");

            if (comboBox7.SelectedItem.ToString().Equals("Prac"))
            {
                capacity = 25;
            }
            else
            {
                capacity = 50;
            }
            for (int i = 0; i < Classes.Rows.Count; i++)// move over classes
            {
                if (capacity > Int32.Parse(Classes.Rows[i][1].ToString()))
                {
                    continue;
                }
                ClassName = Classes.Rows[i][0].ToString();
                for (int j = 0; j < Lessons.Rows.Count; j++)    //move over lessons
                {
                    start2     = Lessons.Rows[j][0].ToString(); //start time
                    end2       = Lessons.Rows[j][1].ToString(); //end time
                    ClassName2 = Lessons.Rows[j][2].ToString(); //class name
                    day2       = Lessons.Rows[j][3].ToString();
                    if (!Sec.notSameTime(start, start2, end, end2) && ClassName2.Equals(ClassName) && day.Equals(day2))
                    {
                        flag = false;
                    }
                }
                if (flag)//if class is free at this time
                {
                    comboBox6.Items.Add(ClassName);
                }
                flag = true;
            }
        }