protected void Page_Load(object sender, EventArgs e)
    {
        divFail.Visible          = false;
        divSuccess.Visible       = false;
        lblSubDreditPass.Visible = false;
        Session["isOK"]          = false;

        if ((Session["save_data"] != null) && (Session["save_student"] != null) && (Session["save_teaching"] != null) && (Session["save_lecturer"] != null) && (Session["academic_year"] != null) && (Session["semester"] != null) && (Session["course_code"] != null) && (Session["Sec"] != null) && (Session["subsec_num"] != null))
        {
            try
            {
                available_data    = (AvailableCourseData)Session["save_data"];
                available_student = (List <AvailableStudentData>)Session["save_student"];
                teachtable        = (List <TeachingTableData>)Session["save_teaching"];
                lecturertable     = (List <LecturerTableData>)Session["save_lecturer"];

                CurriculumGeneralData curr = new Curriculum().getCurriculum(available_data.Curr_Code);
                degree_char = curr.Degree_Char;

                string old_academic_year = (string)Session["academic_year"];
                string old_semester      = (string)Session["semester"];
                string old_course_code   = (string)Session["course_code"];
                int    old_sec_num       = (int)Session["Sec"];
                int    old_subsec_num    = (int)Session["subsec_num"];

                old_available_data.AcademicYear = old_academic_year;
                old_available_data.Semester     = old_semester;
                old_available_data.Course_Code  = old_course_code;
                old_available_data.Sec_No       = old_sec_num;

                old_available_student.AcademicYear = old_academic_year;
                old_available_student.Semester     = old_semester;
                old_available_student.Course_Code  = old_course_code;
                old_available_student.Sec_No       = old_sec_num;
                old_available_student.SubSec_No    = old_subsec_num;

                old_teaching.AcademicYear = old_academic_year;
                old_teaching.Semester     = old_semester;
                old_teaching.Course_Code  = old_course_code;
                old_teaching.Sec_No       = old_sec_num;
                old_teaching.SubSec_No    = old_subsec_num;

                old_lecturer.AcademicYear = old_academic_year;
                old_lecturer.Semester     = old_semester;
                old_lecturer.Course_Code  = old_course_code;
                old_lecturer.Sec_No       = old_sec_num;
                old_lecturer.SubSec_No    = old_subsec_num;


                CourseData course_data = new Course().getCourse(available_data.Course_Code);

                lblSemester.Text     = available_data.Semester;
                lblAcademicYear.Text = available_data.AcademicYear;
                //lblFaculty.Text = new Faculty().getFaculty(available_data.Faculty_Code).Faculty_Thai;
                //lblCurriculum.Text = available_data.Curr_Code + " " + new Curriculum().getCurriculum(available_data.Curr_Code).Curr_ThaiName;
                lblCourse.Text = course_data.Course_Code + " : " + course_data.Course_Thainame + " " + course_data.Credit.ToString() + "(" + course_data.Theory.ToString() + "-" + course_data.Practice.ToString() + "-" + course_data.Self_Study.ToString() + ")";

                lblSecNo.Text         = teachtable[0].SubSec_No.ToString();
                lblNumberStudent.Text = teachtable[0].SubNumber_Student.ToString();
                lblCourseType.Text    = new CourseType().getCourseType(teachtable[0].Course_Type).CourseType_Thainame;

                if (available_data.Curr_Code.Substring(4) == "999999999")
                {
                    lblFaculty.Text    = "วิชาบริการศึกษา";
                    lblCurriculum.Text = curr.Curr_ThaiName + " (ปีหลักสูตร " + curr.Curr_Year + ")";
                }
                else
                {
                    lblFaculty.Text    = new Faculty().getFaculty(available_data.Faculty_Code).Faculty_Thai;
                    lblCurriculum.Text = curr.Curr_Code + " " + curr.Curr_ThaiName;
                }

                // Head Table
                string[] ar1 = { "หลักสูตร", "ประเภทนักศึกษา", "รอบ", "ชั้นปี", "กลุ่ม" };
                Table    tb1 = new Table();
                tb1.Attributes.Add("class", "table table-bordered table-striped");
                tb1.Attributes.Add("id", "dt_basic1");
                TableHeaderRow tRowHead = new TableHeaderRow();
                tRowHead.TableSection = TableRowSection.TableHeader;
                for (int cellCtr = 1; cellCtr <= ar1.Length; cellCtr++)
                {
                    // Create a new cell and add it to the row.
                    TableHeaderCell cellHead = new TableHeaderCell();
                    cellHead.Text = ar1[cellCtr - 1];
                    tRowHead.Cells.Add(cellHead);
                }

                tb1.Rows.Add(tRowHead);

                foreach (AvailableStudentData available in available_student)
                {
                    if (available.Student_Group_Code != "-")
                    {
                        TableRow tRowBody = new TableRow();
                        tRowBody.TableSection = TableRowSection.TableBody;


                        TableCell             cellCurriculum = new TableCell();
                        CurriculumGeneralData std_curr       = new Curriculum().getCurriculum(available.Curr_Code);
                        cellCurriculum.Text = std_curr.Curr_Code + " " + std_curr.Curr_ThaiName;
                        tRowBody.Cells.Add(cellCurriculum);

                        TableCell cellStdCategory = new TableCell();
                        cellStdCategory.Text = new StdCategory().getStdCategory(available.Student_Category_Code).StdCategory_Thai;
                        tRowBody.Cells.Add(cellStdCategory);

                        TableCell cellSection = new TableCell();
                        cellSection.Text = new Section().getSection(available.Section_Code).Section_Thai;
                        tRowBody.Cells.Add(cellSection);

                        TableCell cellStudentYear = new TableCell();
                        cellStudentYear.Text = available.Student_Year.ToString();
                        tRowBody.Cells.Add(cellStudentYear);

                        TableCell cellStudentGroup = new TableCell();
                        cellStudentGroup.Text = new StdGroup().getStdGroup(available.Student_Group_Code).StdGroup_Thai;
                        tRowBody.Cells.Add(cellStudentGroup);

                        tb1.Rows.Add(tRowBody);
                    }
                }

                TableRow  row  = new TableRow();
                TableCell cell = new TableCell();
                cell.Controls.Add(tb1);
                row.Cells.Add(cell);
                tblStudentList.Rows.Add(row);

                if (tb1.Rows.Count <= 1)
                {
                    tblStudentList.Visible = false;
                }


                // Head Table
                string[] ar3 = { "คณะ" };
                Table    tb3 = new Table();
                tb3.Attributes.Add("class", "table table-bordered table-striped");
                tb3.Attributes.Add("id", "dt_basic3");
                TableHeaderRow tRowHead3 = new TableHeaderRow();
                tRowHead3.TableSection = TableRowSection.TableHeader;
                for (int cellCtr = 1; cellCtr <= ar3.Length; cellCtr++)
                {
                    // Create a new cell and add it to the row.
                    TableHeaderCell cellHead3 = new TableHeaderCell();
                    cellHead3.Text = ar3[cellCtr - 1];
                    tRowHead3.Cells.Add(cellHead3);
                }

                tb3.Rows.Add(tRowHead3);

                foreach (AvailableStudentData available in available_student)
                {
                    if (available.Faculty_Code != "-" && available.Student_Group_Code == "-")
                    {
                        TableRow tRowBody = new TableRow();
                        tRowBody.TableSection = TableRowSection.TableBody;

                        TableCell cellFaculty = new TableCell();
                        cellFaculty.Text = new Faculty().getFaculty(available.Faculty_Code).Faculty_Thai;
                        tRowBody.Cells.Add(cellFaculty);


                        tb3.Rows.Add(tRowBody);
                    }
                }

                TableRow  row3  = new TableRow();
                TableCell cell3 = new TableCell();
                cell3.Controls.Add(tb3);
                row3.Cells.Add(cell3);
                tblStudentList2.Rows.Clear();
                tblStudentList2.Rows.Add(row3);

                if (tb3.Rows.Count <= 1)
                {
                    tblStudentList2.Visible = false;
                }

                // Head Table
                string[] ar4 = { "หลักสูตร" };
                Table    tb4 = new Table();
                tb4.Attributes.Add("class", "table table-bordered table-striped");
                tb4.Attributes.Add("id", "dt_basic4");
                TableHeaderRow tRowHead4 = new TableHeaderRow();
                tRowHead4.TableSection = TableRowSection.TableHeader;
                for (int cellCtr = 1; cellCtr <= ar4.Length; cellCtr++)
                {
                    // Create a new cell and add it to the row.
                    TableHeaderCell cellHead4 = new TableHeaderCell();
                    cellHead4.Text = ar4[cellCtr - 1];
                    tRowHead4.Cells.Add(cellHead4);
                }

                tb4.Rows.Add(tRowHead4);

                foreach (AvailableStudentData available in available_student)
                {
                    if (available.Curr_Code != "-" && available.Student_Group_Code == "-")
                    {
                        TableRow tRowBody = new TableRow();
                        tRowBody.TableSection = TableRowSection.TableBody;

                        TableCell             cellCurri = new TableCell();
                        CurriculumGeneralData std_curr2 = new Curriculum().getCurriculum(available.Curr_Code);
                        cellCurri.Text = std_curr2.Curr_Code + " " + std_curr2.Curr_ThaiName;
                        tRowBody.Cells.Add(cellCurri);


                        tb4.Rows.Add(tRowBody);
                    }
                }

                TableRow  row4  = new TableRow();
                TableCell cell4 = new TableCell();
                cell4.Controls.Add(tb4);
                row4.Cells.Add(cell4);
                tblStudentList3.Rows.Clear();
                tblStudentList3.Rows.Add(row4);

                if (tb4.Rows.Count <= 1)
                {
                    tblStudentList3.Visible = false;
                }

                // Head Table
                string[] ar2     = { "ช่วงที่", "วันสอน", "เวลา", "อาคาร", "ห้องเรียน", "ผู้สอน" };
                int      num_row = 1;

                Table tb2 = new Table();
                tb2.Attributes.Add("class", "table table-bordered table-striped");
                tb2.Attributes.Add("id", "dt_basic2");
                TableHeaderRow tRowHead2 = new TableHeaderRow();
                tRowHead2.TableSection = TableRowSection.TableHeader;
                for (int cellCtr = 1; cellCtr <= ar2.Length; cellCtr++)
                {
                    // Create a new cell and add it to the row.
                    TableHeaderCell cellHead2 = new TableHeaderCell();
                    cellHead2.Text = ar2[cellCtr - 1];
                    tRowHead2.Cells.Add(cellHead2);
                }

                tb2.Rows.Add(tRowHead2);

                foreach (TeachingTableData table in teachtable)
                {
                    TableRow tRowBody2 = new TableRow();
                    tRowBody2.TableSection = TableRowSection.TableBody;


                    TableCell cellRow = new TableCell();
                    cellRow.Text = num_row.ToString();
                    tRowBody2.Cells.Add(cellRow);

                    TableCell cellDay = new TableCell();
                    cellDay.Text = utlObj.getDayOfWeek_Thai(table.Teaching_Day);
                    tRowBody2.Cells.Add(cellDay);

                    TableCell cellTime = new TableCell();
                    cellTime.Attributes.Add("class", "text-center");
                    cellTime.Text = table.Teaching_Start_Time + " - " + table.Teaching_End_Time;
                    tRowBody2.Cells.Add(cellTime);

                    TableCell cellBuilding = new TableCell();
                    cellBuilding.Text = new Building().getBuilding(table.Building_Code).Building_ThaiName;
                    tRowBody2.Cells.Add(cellBuilding);

                    TableCell cellRoom = new TableCell();
                    if (table.Room_Code == "0")     // ไม่ระบุห้องเรียน
                    {
                        cellRoom.Text = "ไม่ระบุ";
                    }
                    else
                    {
                        cellRoom.Text = new Room().getRoom(table.Campus_Code, table.Building_Code, table.Room_Code).Room_ThaiName;
                    }
                    tRowBody2.Cells.Add(cellRoom);



                    string lec_all = "";

                    foreach (LecturerTableData lect_data in lecturertable)
                    {
                        if (table.Room_Code == lect_data.Room_Code && table.Teaching_Day == lect_data.Teaching_Day && table.Teaching_Start_Time == lect_data.Teaching_Start_Time && table.Teaching_End_Time == lect_data.Teaching_End_Time)
                        {
                            lec_all += lecturerObj.getLecturer(lect_data.Lecturer).First_ThaiName + " " + lecturerObj.getLecturer(lect_data.Lecturer).Family_ThaiName + "<br />";
                        }
                    }

                    TableCell cellLecturer = new TableCell();
                    cellLecturer.Text = lec_all;
                    tRowBody2.Cells.Add(cellLecturer);



                    tb2.Rows.Add(tRowBody2);
                    num_row++;
                }

                TableRow  row2  = new TableRow();
                TableCell cell2 = new TableCell();
                cell2.Controls.Add(tb2);
                row2.Cells.Add(cell2);
                tblTeaching.Rows.Add(row2);

                if (!Page.IsPostBack)
                {
                    createCreditTable();
                }
                else
                {
                    createCreditTable2();
                }

                divSuccess.Visible = false;
                divFail.Visible    = false;
                divBody.Visible    = true;
            }
            catch
            {
                divSuccess.Visible = false;
                divFail.Visible    = true;
                divBody.Visible    = false;
            }
        }
        else
        {
            divShow.Visible = false;
            divFail.Visible = true;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        row_edit        = Request.QueryString["row"];
        edit_teach_data = (TeachingTableData)Session["edit_teachtable" + row_edit];

        lblGeneralDataError.Text = "";
        lblTableError.Text       = "";
        lblStudentError.Text     = "";

        courseData = new Course().getCourse(edit_teach_data.Course_Code);

        // Course Detail
        lblSemester.Text     = edit_teach_data.Semester;
        lblAcadimicYear.Text = edit_teach_data.AcademicYear;
        lblCourseCode.Text   = edit_teach_data.Course_Code;
        lblCourseName.Text   = courseData.Course_Engname;
        lblCourseCredit.Text = courseData.Credit + "(" + courseData.Theory + "-" + courseData.Practice + "-" + courseData.Self_Study + ")";

        /* =======  Not Postback ======= */

        if (!Page.IsPostBack)
        {
            currData     = new Curriculum().getCurriculum();
            stdcatData   = new StdCategory().getStdCategory();
            secData      = new Section().getSection();
            stdgroupData = new StdGroup().getStdGroup();

            txtSEC_NO.Text         = edit_teach_data.Sec_No.ToString();
            txtNUMBER_STUDENT.Text = edit_teach_data.SubNumber_Student.ToString();

            // ประเภทตอนเรียน
            ddlCourseType.Items.Clear();
            if (courseData.Course_Type_Code == "1")
            {
                ddlCourseType.Items.Insert(ddlCourseType.Items.Count, new ListItem("--- ทฤษฎี ---", "1"));
            }
            else if (courseData.Course_Type_Code == "2")
            {
                ddlCourseType.Items.Insert(ddlCourseType.Items.Count, new ListItem("--- ปฏิบัติ ---", "2"));
            }
            else if (courseData.Course_Type_Code == "3")
            {
                ddlCourseType.Items.Insert(ddlCourseType.Items.Count, new ListItem("--- ทฤษฎี ---", "1"));
            }
            else if (courseData.Course_Type_Code == "4")
            {
                ddlCourseType.Items.Insert(ddlCourseType.Items.Count, new ListItem("--- วิทยานิพนธ์ ---", "4"));
            }
            else if (courseData.Course_Type_Code == "5")
            {
                ddlCourseType.Items.Insert(ddlCourseType.Items.Count, new ListItem("--- สารนิพนธ์นิพนธ์ ---", "5"));
            }
            else if (courseData.Course_Type_Code == "6")
            {
                ddlCourseType.Items.Insert(ddlCourseType.Items.Count, new ListItem("--- ปัญหาพิเศษ ---", "6"));
            }
            else
            {
                ddlCourseType.Items.Insert(ddlCourseType.Items.Count, new ListItem("--- ไม่พบรายการ ---", "0"));
            }

            // หลักสูตร
            ddlCurriculum.Items.Clear();
            ddlCurriculum.Items.Insert(ddlCurriculum.Items.Count, new ListItem("--- เลือกหลักสูตร ---", "0"));
            foreach (CurriculumGeneralData data in currData)
            {
                ddlCurriculum.Items.Insert(ddlCurriculum.Items.Count, new ListItem(data.Curr_ThaiName, data.Curr_Code));
            }

            // ประเภทนักศึกษา
            ddlStdCategory.Items.Clear();
            ddlStdCategory.Items.Insert(ddlStdCategory.Items.Count, new ListItem("--- เลือกประเภทนักศึกษา ---", "0"));
            foreach (StdCategoryData data in stdcatData)
            {
                ddlStdCategory.Items.Insert(ddlStdCategory.Items.Count, new ListItem(data.StdCategory_Thai, data.StdCategory_Code));
            }

            // รอบ
            ddlSection.Items.Clear();
            ddlSection.Items.Insert(ddlSection.Items.Count, new ListItem("--- เลือกรอบ ---", "0"));
            foreach (SectionData data in secData)
            {
                ddlSection.Items.Insert(ddlSection.Items.Count, new ListItem(data.Section_Thai, data.Section_Code));
            }

            //กลุ่ม
            ddlStdGroup.Items.Clear();
            foreach (StdGroupData data in stdgroupData)
            {
                ddlStdGroup.Items.Insert(ddlStdGroup.Items.Count, new ListItem(data.StdGroup_Thai, data.StdGroup_Code));
            }

            // อาคาร
            ddlBUILING_CODE.Items.Clear();
            buildingData = new Building().getBuilding();
            foreach (BuildingData data in buildingData)
            {
                ddlBUILING_CODE.Items.Insert(ddlBUILING_CODE.Items.Count, new ListItem(data.Building_ThaiName, data.Building_Code));
            }
            ddlBUILING_CODE.SelectedIndex = 0;

            // ห้อง
            ddlROOM_CODE.Items.Clear();
            roomData = new Room().getRoom_withBuilding(ddlBUILING_CODE.SelectedValue);
            foreach (RoomData data in roomData)
            {
                ddlROOM_CODE.Items.Insert(ddlROOM_CODE.Items.Count, new ListItem(data.Room_ThaiName, data.Room_Code));
            }
            ddlROOM_CODE.SelectedIndex = 0;


            ddlLecturer.Items.Clear();
            lecturerData = lecturerObj.getLecturer();
            foreach (LectuereInformationData data in lecturerData)
            {
                ddlLecturer.Items.Insert(ddlLecturer.Items.Count, new ListItem(data.Lecturer_ShortName + " " + data.First_ThaiName + " " + data.Family_ThaiName, data.Lecturer_ID));
            }
        }

        /* ============================= */

        /* ============= Load Student ==============*/
        if (Session["save_student"] == null)
        {
            available_student       = new AvailableStudent().getAvailableStudent(edit_teach_data.AcademicYear, edit_teach_data.Semester, edit_teach_data.Course_Code, edit_teach_data.Sec_No, edit_teach_data.SubSec_No, "degree_char");
            Session["save_student"] = available_student;
        }

        if (Session["save_student"] != null)
        {
            int num_row1 = 1;

            available_student = (List <AvailableStudentData>)Session["save_student"];

            // Head Table
            string[] ar2 = { "หลักสูตร", "ประเภทนักศึกษา", "รอบ", "ชั้นปี", "กลุ่ม", "ลบ" };
            Table    tb2 = new Table();
            tb2.Attributes.Add("class", "table table-bordered table-striped table-hover");
            tb2.Attributes.Add("id", "dt_basic1");
            TableHeaderRow tRowHead2 = new TableHeaderRow();
            tRowHead2.TableSection = TableRowSection.TableHeader;
            for (int cellCtr = 1; cellCtr <= ar2.Length; cellCtr++)
            {
                // Create a new cell and add it to the row.
                TableHeaderCell cellHead = new TableHeaderCell();
                cellHead.Text = ar2[cellCtr - 1];
                tRowHead2.Cells.Add(cellHead);
            }

            tb2.Rows.Add(tRowHead2);



            foreach (AvailableStudentData available in available_student)
            {
                TableRow tRowBody = new TableRow();
                tRowBody.TableSection = TableRowSection.TableBody;

                TableCell cellCurriculum = new TableCell();

                cellCurriculum.Text += new Curriculum().getCurriculum(available.Curr_Code).Curr_ThaiName;
                tRowBody.Cells.Add(cellCurriculum);

                TableCell cellStdCategory = new TableCell();
                cellStdCategory.Text = new StdCategory().getStdCategory(available.Student_Category_Code).StdCategory_Thai;
                tRowBody.Cells.Add(cellStdCategory);

                TableCell cellSection = new TableCell();
                cellSection.Text = new Section().getSection(available.Section_Code).Section_Thai;
                tRowBody.Cells.Add(cellSection);

                TableCell cellStudentYear = new TableCell();
                cellStudentYear.Text = available.Student_Year.ToString();
                tRowBody.Cells.Add(cellStudentYear);

                TableCell cellStudentGroup = new TableCell();
                cellStudentGroup.Text = new StdGroup().getStdGroup(available.Student_Group_Code).StdGroup_Thai;
                tRowBody.Cells.Add(cellStudentGroup);

                TableCell  cellDel = new TableCell();
                LinkButton lbt     = new LinkButton();
                lbt.Text = "<i class=\"fa fa-trash-o\"></i>";
                lbt.ID   = "link" + num_row1.ToString();

                lbt.Click += new EventHandler(ibt_click);
                cellDel.Controls.Add(lbt);
                cellDel.Attributes.Add("class", "text-center");
                tRowBody.Cells.Add(cellDel);

                tb2.Rows.Add(tRowBody);

                num_row1++;
            }

            TableRow  row2  = new TableRow();
            TableCell cell2 = new TableCell();
            cell2.Controls.Add(tb2);
            row2.Cells.Add(cell2);
            tblAvailableList.Rows.Clear();
            tblAvailableList.Rows.Add(row2);
        }

        /* ========================================= */

        /* ============= Load Teach Table ============= */

        teachtable.Add(edit_teach_data);

        Session["save_teaching"] = teachtable;

        if (Session["save_teaching"] != null)
        {
            teachtable = (List <TeachingTableData>)Session["save_teaching"];

            if (Session["save_lecturer"] != null)
            {
                lecturertable = (List <LecturerTableData>)Session["save_lecturer"];
            }

            // Head Table
            string[] ar3     = { "ช่วงที่", "ตอนที่", "วันสอน", "เวลา", "อาคาร", "ห้องเรียน", "ผู้สอบ", "จำนวนผู้เรียน", "ลบ" };
            int      num_row = 1;

            Table tb3 = new Table();
            tb3.Attributes.Add("class", "table table-bordered table-striped table-hover");
            tb3.Attributes.Add("id", "dt_basic1");
            TableHeaderRow tRowHead3 = new TableHeaderRow();
            tRowHead3.TableSection = TableRowSection.TableHeader;
            for (int cellCtr = 1; cellCtr <= ar3.Length; cellCtr++)
            {
                // Create a new cell and add it to the row.
                TableHeaderCell cellHead = new TableHeaderCell();
                cellHead.Text = ar3[cellCtr - 1];
                tRowHead3.Cells.Add(cellHead);
            }

            tb3.Rows.Add(tRowHead3);

            foreach (TeachingTableData table in teachtable)
            {
                TableRow tRowBody = new TableRow();
                tRowBody.TableSection = TableRowSection.TableBody;

                TableCell cellRow = new TableCell();



                cellRow.Text += num_row.ToString();
                tRowBody.Cells.Add(cellRow);

                TableCell cellSubSec = new TableCell();
                cellSubSec.Text = "S." + table.Sec_No.ToString();
                tRowBody.Cells.Add(cellSubSec);

                TableCell cellDay = new TableCell();
                cellDay.Text = utlObj.getDayOfWeek_Thai(table.Teaching_Day);
                tRowBody.Cells.Add(cellDay);

                TableCell cellTime = new TableCell();
                cellTime.Attributes.Add("class", "text-center");
                cellTime.Text = table.Teaching_Start_Time + " - " + table.Teaching_End_Time;
                tRowBody.Cells.Add(cellTime);

                TableCell cellBuilding = new TableCell();
                cellBuilding.Text = new Building().getBuilding(table.Building_Code).Building_ThaiName;
                tRowBody.Cells.Add(cellBuilding);

                TableCell cellRoom = new TableCell();
                cellRoom.Text = new Room().getRoom(table.Campus_Code, table.Building_Code, table.Room_Code).Room_ThaiName;
                tRowBody.Cells.Add(cellRoom);


                string lec_all = "";
                foreach (LecturerTableData lect_data in lecturertable)
                {
                    if (table.Room_Code == lect_data.Room_Code && table.Teaching_Day == lect_data.Teaching_Day && table.Teaching_Start_Time == lect_data.Teaching_Start_Time && table.Teaching_End_Time == lect_data.Teaching_End_Time)
                    {
                        lec_all += lecturerObj.getLecturer(lect_data.Lecturer).First_ThaiName + " " + lecturerObj.getLecturer(lect_data.Lecturer).Family_ThaiName + "<br />";
                    }
                }

                TableCell cellLecturer = new TableCell();
                cellLecturer.Text = lec_all;
                tRowBody.Cells.Add(cellLecturer);

                TableCell cellNumStudent = new TableCell();
                cellNumStudent.Text = table.SubNumber_Student.ToString();
                tRowBody.Cells.Add(cellNumStudent);

                TableCell cellDel = new TableCell();
                cellDel.Attributes.Add("class", "text-center");
                LinkButton lbt = new LinkButton();
                lbt.Text   = "<i class=\"fa fa-trash-o\"></i>";
                lbt.ID     = "tech" + num_row.ToString();
                lbt.Click += new EventHandler(ibt2_click);
                cellDel.Controls.Add(lbt);
                tRowBody.Cells.Add(cellDel);

                tb3.Rows.Add(tRowBody);

                num_row++;
            }

            TableRow  row3  = new TableRow();
            TableCell cell3 = new TableCell();
            cell3.Controls.Add(tb3);
            row3.Cells.Add(cell3);
            tblTeaching.Rows.Clear();
            tblTeaching.Rows.Add(row3);
        }
        /* ============================================ */
    }
    protected void btnSEARCH_Click(object sender, EventArgs e)
    {
        divShow.Visible = true;

        txtCOURSE_CODE.Text = new utility().removeAllQuotes(txtCOURSE_CODE.Text);

        try
        {
            divShow.Visible = true;
            uint chknum;

            if (txtACADEMIC_YEAR.Text.Length != 4)
            {
                MsgValidate("โปรดระบุ ปีการศึกษาเป็นตัวเลขจำนวน 4 ตัว");
            }
            else if (!uint.TryParse(txtACADEMIC_YEAR.Text, out chknum))
            {
                MsgValidate("โปรดระบุ ปีการศึกษาเป็นตัวเลขเท่านั้น");
            }
            else
            {
                degree_char = ddlDegreeLevel.SelectedValue;
                string   table_struct1 = "";
                string   course_code1  = "";
                Lecturer lecturerObj   = new Lecturer();
                List <TeachingTableData>    teachtable        = new List <TeachingTableData>();
                List <TeachingTableData>    subteachtable     = new List <TeachingTableData>();
                List <AvailableStudentData> available_student = new List <AvailableStudentData>();

                available_data = new AvailableCourse().getAvailableCourse(txtACADEMIC_YEAR.Text, ddlSEMESTER.SelectedValue, txtCOURSE_CODE.Text, degree_char);

                CourseData course = new CourseData();
                int        loop   = available_data.Count;

                for (int i = 0; i < loop; i++)
                {
                    AvailableCourseData ava_course = available_data[i];

                    course = new Course().getCourse(ava_course.Course_Code);

                    string course_code = ava_course.Course_Code;

                    string course_name   = course.Course_Thainame;
                    string course_credit = course.Credit.ToString();
                    if (course.Course_Type_Code == "1" || course.Course_Type_Code == "2" || course.Course_Type_Code == "6")
                    {
                        course_credit += "(" + course.Theory + "-" + course.Practice + "-" + course.Self_Study + ")";
                    }

                    teachtable    = new TeachingTable().getTeachingTable(ava_course.AcademicYear, ava_course.Semester, ava_course.Course_Code, ava_course.Sec_No, degree_char);
                    subteachtable = new TeachingTable().getSubTeachingTable(ava_course.AcademicYear, ava_course.Semester, ava_course.Course_Code, ava_course.Sec_No, degree_char);


                    if (course_code != course_code1)
                    {
                        course_code1 = course_code;

                        table_struct1 += "<div class='row'>";
                        table_struct1 += "<article class='col-sm-12 col-md-12 col-lg-12'>";
                        table_struct1 += "<div class='jarviswidget jarviswidget-color-primary' id='" + course_code + "' data-widget-editbutton='false' data-widget-deletebutton='false' data-widget-fullscreenbutton='false' data-widget-sortable='false'>";
                        table_struct1 += "<header><span class='widget-icon'><i class='fa fa-table'></i></span><h2>" + course_code + " : " + course_name + " " + course_credit + "</h2></header>";
                        table_struct1 += "<div><div class='widget-body no-padding'><div class='widget-body-toolbar'></div>";
                        table_struct1 += "<table class='table table-bordered table-striped table-hover smart-form'>";
                        table_struct1 += "<thead><tr><th class='text-center' style='width:50px'>ตอนที่</th><th class='text-center' style='width:50px'>วัน</th><th class='text-center' style='width:70px'>เวลา</th><th class='text-center'>ผู้สอน</th><th class='text-center'>ห้องเรียน</th><th class='text-center'>ข้อมูล น.ศ.</th><th class='text-center' style='width:50px'>จำนวน น.ศ.</th></tr></thead>";
                        table_struct1 += "<tbody>";
                    }

                    foreach (TeachingTableData teach_table in teachtable)
                    {
                        available_student = new AvailableStudent().getAvailableStudent(teach_table.AcademicYear, teach_table.Semester, teach_table.Course_Code, teach_table.Sec_No, teach_table.SubSec_No, degree_char);


                        string week_day   = utlObj.getDayOfWeek_Thai(teach_table.Teaching_Day);
                        string teach_time = teach_table.Teaching_Start_Time + " - " + teach_table.Teaching_End_Time;

                        string building_room = new Building().getBuilding(teach_table.Building_Code).Building_ShortName;

                        if (teach_table.Room_Code == "0") // ไม่ระบุห้องเรียน
                        {
                            building_room += "-ไม่ระบุ";
                        }
                        else
                        {
                            building_room += "-" + teach_table.Room_Code;
                        }


                        string course_type = "";

                        if (teach_table.Course_Type == "1")
                        {
                            course_type = "S.";
                        }
                        else if (teach_table.Course_Type == "2")
                        {
                            course_type = "L.";
                        }
                        else if (teach_table.Course_Type == "4")
                        {
                            course_type = "T.";
                        }
                        else if (teach_table.Course_Type == "5")
                        {
                            course_type = "M.";
                        }
                        else if (teach_table.Course_Type == "6")
                        {
                            course_type = "SP.";
                        }
                        else if (teach_table.Course_Type == "7")
                        {
                            course_type = "D.";
                        }


                        string lec_all = "";
                        List <LecturerTableData> lecturerData = new List <LecturerTableData>();
                        lecturerData = new LecturerTable().getLecturerTable(teach_table, degree_char);
                        foreach (LecturerTableData lect in lecturerData)
                        {
                            lec_all += lecturerObj.getLecturer(lect.Lecturer).Title_ThaiName + " " + lecturerObj.getLecturer(lect.Lecturer).First_ThaiName + " " + lecturerObj.getLecturer(lect.Lecturer).Family_ThaiName + "<br>";
                        }

                        string student_list = "";
                        foreach (AvailableStudentData student in available_student)
                        {
                            if (student.Student_Group_Code != "-")
                            {
                                student_list += student.Curr_Code.Substring(4) + " - " + student.Student_Year + " " + new Section().getSection(student.Section_Code).Section_Short + new StdGroup().getStdGroup(student.Student_Group_Code).StdGroup_Thai + " " + new StdCategory().getStdCategory(student.Student_Category_Code).StdCategory_Thai + "<br/>";
                            }
                            else if (student.Student_Group_Code == "-" && student.Faculty_Code != "-")
                            {
                                student_list += new Faculty().getFaculty(student.Faculty_Code).Faculty_Thai + "<br/>";
                            }
                            else if (student.Student_Group_Code == "-" && student.Curr_Code != "-")
                            {
                                student_list += student.Curr_Code.Substring(4) + " " + new Curriculum().getCurriculum(student.Curr_Code).Curr_ThaiName + "<br/>";
                            }
                        }

                        table_struct1 += "<tr>";
                        table_struct1 += "<td class='text-center'>" + course_type + ava_course.Sec_No.ToString() + "</td>";
                        table_struct1 += "<td class='text-center'>" + week_day + "</td>";
                        table_struct1 += "<td>" + teach_time + "</td>";
                        table_struct1 += "<td>" + lec_all + "</td>";
                        table_struct1 += "<td class='text-center'>" + building_room + "</td>";
                        table_struct1 += "<td class='text-center'>" + student_list + "</td>";
                        table_struct1 += "<td class='text-center'>" + ava_course.Number_Student.ToString() + "</td>";
                        table_struct1 += "</tr>";
                    }

                    // Pratice Extened
                    foreach (TeachingTableData teach_table in subteachtable)
                    {
                        available_student = new AvailableStudent().getAvailableStudent(teach_table.AcademicYear, teach_table.Semester, teach_table.Course_Code, teach_table.Sec_No, teach_table.SubSec_No, degree_char);

                        string week_day   = utlObj.getDayOfWeek_Thai(teach_table.Teaching_Day);
                        string teach_time = teach_table.Teaching_Start_Time + " - " + teach_table.Teaching_End_Time;

                        string building_room = new Building().getBuilding(teach_table.Building_Code).Building_ShortName;

                        if (teach_table.Room_Code == "0") // ไม่ระบุห้องเรียน
                        {
                            building_room += "-ไม่ระบุ";
                        }
                        else
                        {
                            building_room += "-" + teach_table.Room_Code;
                        }

                        string course_type = "";

                        if (teach_table.Course_Type == "1")
                        {
                            course_type = "S.";
                        }
                        else if (teach_table.Course_Type == "2")
                        {
                            course_type = "L.";
                        }


                        string lec_all = "";
                        List <LecturerTableData> lecturerData = new List <LecturerTableData>();
                        lecturerData = new LecturerTable().getLecturerTable(teach_table, degree_char);
                        foreach (LecturerTableData lect in lecturerData)
                        {
                            lec_all += lecturerObj.getLecturer(lect.Lecturer).Title_ThaiName + " " + lecturerObj.getLecturer(lect.Lecturer).First_ThaiName + " " + lecturerObj.getLecturer(lect.Lecturer).Family_ThaiName + "<br>";
                        }

                        string student_list = "";
                        foreach (AvailableStudentData student in available_student)
                        {
                            if (student.Student_Group_Code != "-")
                            {
                                student_list += student.Curr_Code.Substring(4) + " - " + student.Student_Year + " " + new Section().getSection(student.Section_Code).Section_Short + new StdGroup().getStdGroup(student.Student_Group_Code).StdGroup_Thai + " " + new StdCategory().getStdCategory(student.Student_Category_Code).StdCategory_Thai + "<br/>";
                            }
                            else if (student.Student_Group_Code == "-" && student.Faculty_Code != "-")
                            {
                                student_list += new Faculty().getFaculty(student.Faculty_Code).Faculty_Thai + "<br/>";
                            }
                            else if (student.Student_Group_Code == "-" && student.Curr_Code != "-")
                            {
                                student_list += student.Curr_Code.Substring(4) + " " + new Curriculum().getCurriculum(student.Curr_Code).Curr_ThaiName + "<br/>";
                            }
                        }

                        table_struct1 += "<tr>";
                        table_struct1 += "<td class='text-center'>" + course_type + teach_table.SubSec_No.ToString() + "</td>";
                        table_struct1 += "<td class='text-center'>" + week_day + "</td>";
                        table_struct1 += "<td>" + teach_time + "</td>";
                        table_struct1 += "<td>" + lec_all + "</td>";
                        table_struct1 += "<td class='text-center'>" + building_room + "</td>";
                        table_struct1 += "<td class='text-center'>" + student_list + "</td>";
                        table_struct1 += "<td class='text-center'>" + teach_table.SubNumber_Student.ToString() + "</td>";
                        table_struct1 += "</tr>";
                    }

                    if (i < (available_data.Count - 1))
                    {
                        if (available_data[i + 1].Course_Code != course_code)
                        {
                            table_struct1 += "</tbody>";
                            table_struct1 += "</table></div></div></div></article></div>";
                        }
                    }
                    else
                    {
                        table_struct1 += "</tbody>";
                        table_struct1 += "</table></div></div></div></article></div>";
                    }
                }

                LiteralControl div_row = new LiteralControl(table_struct1);
                panelListAvailableCourse.Controls.Add(div_row);
            }
        }
        catch
        {
            divShow.Visible = false;
            divFail.Visible = true;
        }
    }