public void FillDataGrid()
        {
            string term_id = this.comboBox1.SelectedValue.ToString();
            string day_id  = this.comboBox2.SelectedValue.ToString();
            string hour_id;
            string class_id;

            string query;

            DataTable result;

            for (int rowcounter = 0; rowcounter < this.dataGridViewX1.Rows.Count; rowcounter++)
            {
                for (int columncounter = 1; columncounter < this.dataGridViewX1.Columns.Count; columncounter++)
                {
                    class_id = this.dataGridViewX1.Rows[rowcounter].Cells[0].Tag.ToString();
                    hour_id  = this.dataGridViewX1.Columns[columncounter].Name;

                    query = string.Format("SELECT * FROM timetable WHERE time_table_term_id={0} " +
                                          "AND time_table_day_id={1} AND time_table_hour_id={2} AND time_table_class_id={3}", term_id, day_id, hour_id, class_id);

                    result = CrudClass.SelectAll(query, "timetable");

                    if (result.Rows.Count > 0)
                    {
                        query = string.Format("SELECT teacher_name,lesson_name FROM timetable,teachers,lessons WHERE time_table_term_id={0} " +
                                              "AND time_table_day_id={1} AND time_table_hour_id={2} AND time_table_class_id={3} AND time_table_teacher_id = teacher_id AND time_table_lesson_id=lesson_id"
                                              , term_id, day_id, hour_id, class_id);

                        result = CrudClass.SelectByQuery(query);

                        this.dataGridViewX1.Rows[rowcounter].Cells[columncounter].Value = result.Rows[0].ItemArray[1].ToString() + " / "
                                                                                          + result.Rows[0].ItemArray[0].ToString();

                        this.dataGridViewX1.Rows[rowcounter].Cells[columncounter].Style.BackColor = Color.GreenYellow;
                    }
                    else
                    {
                        this.dataGridViewX1.Rows[rowcounter].Cells[columncounter].Style.BackColor = Color.Red;
                    }
                }
            }
        }
        private void timetable_Load(object sender, EventArgs e)
        {
            DataTable ClassNames;
            DataTable HourNames;

            ClassNames = CrudClass.SelectAll("SELECT * FROM classes", "classes");
            HourNames  = CrudClass.SelectAll("SELECT * FROM hours", "hours");


            this.dataGridViewX1.Columns.Add("empty", "ساعت/نام کلاس");

            for (int i = 0; i < HourNames.Rows.Count; i++)
            {
                dataGridViewX1.Columns.Add(new DataGridViewTextBoxColumn()
                {
                    Name = HourNames.Rows[i].ItemArray[0].ToString(), HeaderText = HourNames.Rows[i].ItemArray[2].ToString()
                });
            }


            for (int classCounter = 0; classCounter < ClassNames.Rows.Count; classCounter++)
            {
                this.dataGridViewX1.Rows.Add(new object[] { ClassNames.Rows[classCounter].ItemArray[2].ToString() });
                this.dataGridViewX1.Rows[classCounter].Cells[0].Tag = ClassNames.Rows[classCounter].ItemArray[0].ToString();
            }


            //------------------------ fill combobox ------------------------------

            DataTable termValues = CrudClass.SelectAll("SELECT * FROM terms", "terms");
            DataTable dayValues  = CrudClass.SelectAll("SELECT * FROM days", "days");

            this.comboBox1.DataSource    = termValues;
            this.comboBox1.DisplayMember = "term_name";
            this.comboBox1.ValueMember   = "term_id";


            this.comboBox2.DataSource    = dayValues;
            this.comboBox2.DisplayMember = "day_name";
            this.comboBox2.ValueMember   = "day_id";
        }