Example #1
0
        protected void lbuLogin_Click(object sender, EventArgs e)
        {
            int count = DatabaseManager.ExecuteInt("SELECT count(*) FROM PS_PERSON WHERE PS_CITIZEN_ID = '" + tbUsername.Text + "'");
            if(count == 0) {
                Label12X.Text = "ไม่พบผู้ใช้งาน!";
            } else {
                if(DatabaseManager.ValidateUser(tbUsername.Text, tbPassword.Text)) {
                    PersonnelSystem ps = new PersonnelSystem();
                    ps.LoginPerson = DatabaseManager.GetPerson(tbUsername.Text);
                    Session["PersonnelSystem"] = ps;

                    if (DatabaseManager.ExecuteInt("SELECT COUNT(*) FROM LEV_CLAIM WHERE PS_CITIZEN_ID = '" + ps.LoginPerson.CitizenID + "' AND YEAR = " + Util.BudgetYear()) == 0) {
                        using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) {
                            con.Open();
                            using (OracleCommand com = new OracleCommand("INSERT INTO LEV_CLAIM (LEAVE_CLAIM_ID, PS_CITIZEN_ID, YEAR, SICK_NOW, SICK_REQ, BUSINESS_NOW, BUSINESS_REQ, GB_NOW, GB_REQ, REST_NOW, REST_REQ, REST_SAVE, REST_SAVE_FIX, REST_THIS, REST_THIS_FIX, REST_MAX, HGB_NOW, HGB_REQ, ORDAIN_NOW, ORDAIN_REQ, HUJ_NOW, HUJ_REQ, SICK_MAX, BUSINESS_MAX, HUJ_MAX, ORDAIN_MAX) VALUES (SEQ_LEV_CLAIM_ID.NEXTVAL, :PS_CITIZEN_ID, :YEAR, :SICK_NOW, :SICK_REQ, :BUSINESS_NOW, :BUSINESS_REQ, :GB_NOW, :GB_REQ, :REST_NOW, :REST_REQ, :REST_SAVE, :REST_SAVE_FIX, :REST_THIS, :REST_THIS_FIX, :REST_MAX, :HGB_NOW, :HGB_REQ, :ORDAIN_NOW, :ORDAIN_REQ, :HUJ_NOW, :HUJ_REQ, :SICK_MAX, :BUSINESS_MAX, :HUJ_MAX, :ORDAIN_MAX)", con)) {

                                com.Parameters.AddWithValue("PS_CITIZEN_ID", ps.LoginPerson.CitizenID);
                                com.Parameters.AddWithValue("YEAR", Util.BudgetYear());
                                int v1 = 0;
                                int v2 = 10;
                                int v60 = 60;
                                int v45 = 45;
                                int v120 = 120;
                                com.Parameters.AddWithValue("SICK_NOW", v1);
                                com.Parameters.AddWithValue("SICK_REQ", v1);
                                com.Parameters.AddWithValue("BUSINESS_NOW", v1);
                                com.Parameters.AddWithValue("BUSINESS_REQ", v1);
                                com.Parameters.AddWithValue("GB_NOW", v1);
                                com.Parameters.AddWithValue("GB_REQ", v1);
                                com.Parameters.AddWithValue("REST_NOW", v1);
                                com.Parameters.AddWithValue("REST_REQ", v1);
                                com.Parameters.AddWithValue("REST_SAVE", v1);
                                com.Parameters.AddWithValue("REST_SAVE_FIX", v1);
                                com.Parameters.AddWithValue("REST_THIS", v2);
                                com.Parameters.AddWithValue("REST_THIS_FIX", v2);
                                com.Parameters.AddWithValue("REST_MAX", v2);
                                com.Parameters.AddWithValue("HGB_NOW", v1);
                                com.Parameters.AddWithValue("HGB_REQ", v1);
                                com.Parameters.AddWithValue("ORDAIN_NOW", v1);
                                com.Parameters.AddWithValue("ORDAIN_REQ", v1);
                                com.Parameters.AddWithValue("HUJ_NOW", v1);
                                com.Parameters.AddWithValue("HUJ_REQ", v1);
                                com.Parameters.AddWithValue("SICK_MAX", v60);
                                com.Parameters.AddWithValue("BUSINESS_MAX", v45);
                                com.Parameters.AddWithValue("HUJ_MAX", v120);
                                com.Parameters.AddWithValue("ORDAIN_MAX", v120);
                                com.ExecuteNonQuery();
                            }

                        }

                    }

                    using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) {
                        con.Open();

                        using (OracleCommand com = new OracleCommand("SELECT LEAVE_ID FROM LEV_DATA WHERE CURRENT_DATE >= FROM_DATE AND LEAVE_TYPE_ID IN(2,4,6,7) AND LEAVE_STATUS_ID = 1", con)) {
                            using(OracleDataReader reader = com.ExecuteReader()) {
                                while(reader.Read()) {
                                    int leaveID = reader.GetInt32(0);
                                    LeaveData leaveData = new LeaveData();
                                    leaveData.Load(leaveID);
                                    leaveData.ExecuteCancelBySystem();
                                }
                            }

                        }

                        using (OracleCommand com = new OracleCommand("SELECT LEAVE_ID FROM LEV_DATA WHERE LEAVE_STATUS_ID = 1 AND TRUNC(CURRENT_DATE - REQ_DATE, 0) >= 3", con)) {
                            using (OracleDataReader reader = com.ExecuteReader()) {
                                while (reader.Read()) {
                                    int leaveID = reader.GetInt32(0);
                                    LeaveData leaveData = new LeaveData();
                                    leaveData.Load(leaveID);
                                    leaveData.ExecuteCancelBySystem();
                                }
                            }

                        }

                        /*using (OracleCommand com = new OracleCommand("SELECT LEAVE_ID FROM LEV_DATA WHERE CURRENT_DATE >= FROM_DATE AND LEAVE_TYPE_ID IN(2,4,6,7) AND LEAVE_STATUS_ID = 4", con)) {
                            using (OracleDataReader reader = com.ExecuteReader()) {
                                while (reader.Read()) {
                                    int leaveID = reader.GetInt32(0);
                                    LeaveData leaveData = new LeaveData();
                                    leaveData.Load(leaveID);
                                    leaveData.ExecuteCancelOfCancelBySystem();
                                }
                            }

                        }

                        using (OracleCommand com = new OracleCommand("SELECT LEAVE_ID FROM LEV_DATA WHERE LEAVE_STATUS_ID = 4 AND TRUNC(CURRENT_DATE - CANCEL_DATE, 0) >= 3", con)) {
                            using (OracleDataReader reader = com.ExecuteReader()) {
                                while (reader.Read()) {
                                    int leaveID = reader.GetInt32(0);
                                    LeaveData leaveData = new LeaveData();
                                    leaveData.Load(leaveID);
                                    leaveData.ExecuteCancelOfCancelBySystem();
                                }
                            }

                        }*/

                    //-------------

                        /*using (OracleCommand com = new OracleCommand("UPDATE LEV_DATA SET LEAVE_STATUS_ID = 10 WHERE LEAVE_ID = (SELECT LEAVE_ID FROM LEV_DATA WHERE CURRENT_DATE >= FROM_DATE AND LEAVE_TYPE_ID IN(2,4,6,7) AND LEAVE_STATUS_ID IN(1,2))", con)) {
                            com.ExecuteNonQuery();
                        }
                        using (OracleCommand com = new OracleCommand("UPDATE LEV_DATA SET LEAVE_STATUS_ID = 10 WHERE LEAVE_ID = (SELECT LEAVE_ID FROM LEV_DATA WHERE LEAVE_STATUS_ID IN(1,2) AND TRUNC(CURRENT_DATE - REQ_DATE, 0) >= 3)", con)) {
                            com.ExecuteNonQuery();
                        }*/
                    }

                        Response.Redirect("Default.aspx");
                } else {
                    Label12X.Text = "รหัสผ่านไม่ถูกต้อง!";
                }

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            PersonnelSystem ps = PersonnelSystem.GetPersonnelSystem(this);
            Person loginPerson = ps.LoginPerson;

            int count = DatabaseManager.GetLeaveRequiredCountByCommander(loginPerson.CitizenID);
               /* using (OleDbConnection con = new OleDbConnection(DatabaseManager.CONNECTION_STRING)) {
                con.Open();
                using (OleDbCommand com = new OleDbCommand("SELECT COUNT(LEAVE_ID) FROM LEV_LEAVE WHERE CMD_HIGH_ID = '" + loginPerson.CitizenID + "' AND LEV_LEAVE.STATE_ID = 2", con)) {
                    using (OleDbDataReader reader = com.ExecuteReader()) {
                        while (reader.Read()) {
                            count = int.Parse(reader.GetValue(0).ToString());
                        }
                    }
                }
            }*/
            if (count == 0) {
                error_area.InnerHtml = "ไม่มีรายการที่ท่านต้องอนุมัติ";
            } else {
                error_area.InnerHtml = "กรุณาเลือกรายการที่ต้องการอนุมัติ";
            }
            error_area.Attributes["class"] = null;
            error_area.InnerHtml = "";

            if (count > 0) {

                SqlDataSource sds = DatabaseManager.CreateSQLDataSource("SELECT LEV_DATA.LEAVE_ID รหัสการลา, (SELECT PS_FN_TH || ' ' || PS_LN_TH FROM PS_PERSON WHERE PS_CITIZEN_ID = LEV_DATA.PS_ID) ชื่อผู้ลา, (SELECT LEAVE_TYPE_NAME FROM LEV_TYPE WHERE LEV_TYPE.LEAVE_TYPE_ID = LEV_DATA.LEAVE_TYPE_ID) ประเภทการลา, REQ_DATE วันที่ข้อมูล, (SELECT LEAVE_STATUS_NAME FROM LEV_STATUS WHERE LEAVE_STATUS_ID = LEV_DATA.LEAVE_STATUS_ID) สถานะ FROM LEV_DATA, LEV_BOSS_DATA WHERE LEAVE_STATUS_ID IN(1,4) AND LEV_DATA.LEAVE_ID = LEV_BOSS_DATA.LEAVE_ID AND LEV_DATA.BOSS_STATE = LEV_BOSS_DATA.STATE AND LEV_BOSS_DATA.CITIZEN_ID = '" + loginPerson.CitizenID + "'");
                GridView1.DataSource = sds;
                GridView1.DataBind();

                Util.NormalizeGridViewDate(GridView1, 3);

                TableHeaderCell newHeader = new TableHeaderCell();
                newHeader.Text = "เลือก";
                GridView1.HeaderRow.Cells.Add(newHeader);

                GridView1.HeaderRow.Cells[0].Text = "<img src='Image/Small/ID.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[0].Text;
                GridView1.HeaderRow.Cells[1].Text = "<img src='Image/Small/person2.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[1].Text;
                GridView1.HeaderRow.Cells[2].Text = "<img src='Image/Small/list.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[2].Text;
                GridView1.HeaderRow.Cells[3].Text = "<img src='Image/Small/calendar.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[3].Text;
                GridView1.HeaderRow.Cells[4].Text = "<img src='Image/Small/question.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[4].Text;
                GridView1.HeaderRow.Cells[5].Text = "<img src='Image/Small/pointer.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[5].Text;

                for (int i = 0; i < GridView1.Rows.Count; ++i) {

                    string id = GridView1.Rows[i].Cells[0].Text;

                    LinkButton lbu = new LinkButton();
                    lbu.Text = "<img src='Image/Small/next.png'></img>";
                    lbu.CssClass = "ps-button";
                    lbu.Click += (e2, e3) => {

                        LeaveData leaveData = new LeaveData();
                        leaveData.Load(int.Parse(id));
                        Session["LeaveData"] = leaveData;

                        trPSBirthDate.Visible = false;
                        trPSWorkInDate.Visible = false;
                        trWifeName.Visible = false;
                        trGBDate.Visible = false;
                        trOrdained.Visible = false;
                        trTempleName.Visible = false;
                        trTempleLocation.Visible = false;
                        trOrdainDate.Visible = false;
                        trHujed.Visible = false;
                        trReason.Visible = false;
                        trContact.Visible = false;
                        trPhone.Visible = false;
                        trRestSave.Visible = false;
                        trRestLeft.Visible = false;
                        trRestTotal.Visible = false;
                        trStatistic.Visible = false;
                        //trCLOldComment.Visible = false;
                        //trCLOldDate.Visible = false;
                        //trCHOldComment.Visible = false;
                        //trCHOldDate.Visible = false;
                        trCancelReason.Visible = false;

                        if (leaveData.LeaveTypeID == 1) {
                            trStatistic.Visible = true;
                            trReason.Visible = true;
                            trContact.Visible = true;
                            trPhone.Visible = true;
                        } else if (leaveData.LeaveTypeID == 2) {
                            trStatistic.Visible = true;
                            trReason.Visible = true;
                            trContact.Visible = true;
                            trPhone.Visible = true;
                        } else if (leaveData.LeaveTypeID == 3) {
                            trStatistic.Visible = true;
                            trReason.Visible = true;
                            trContact.Visible = true;
                            trPhone.Visible = true;
                        } else if (leaveData.LeaveTypeID == 4) {
                            trRestSave.Visible = true;
                            trRestLeft.Visible = true;
                            trRestTotal.Visible = true;
                            trContact.Visible = true;
                            trPhone.Visible = true;
                        } else if (leaveData.LeaveTypeID == 5) {
                            trWifeName.Visible = true;
                            trGBDate.Visible = true;
                            trContact.Visible = true;
                            trPhone.Visible = true;
                        } else if (leaveData.LeaveTypeID == 6) {
                            trPSBirthDate.Visible = true;
                            trPSWorkInDate.Visible = true;
                            trOrdained.Visible = true;
                            trTempleName.Visible = true;
                            trTempleLocation.Visible = true;
                            trOrdainDate.Visible = true;
                        } else if (leaveData.LeaveTypeID == 7) {
                            trPSBirthDate.Visible = true;
                            trPSWorkInDate.Visible = true;
                            trHujed.Visible = true;
                        }

                        if (leaveData.LeaveStatusID == 2) {

                        } else if (leaveData.LeaveStatusID == 4) {
                            //trCLOldComment.Visible = true;
                            //trCLOldDate.Visible = true;
                            //trCHOldComment.Visible = true;
                            //trCHOldDate.Visible = true;
                            trCancelReason.Visible = true;
                        }

                        lbLeaveID.Text = leaveData.LeaveID.ToString();
                        lbLeaveTypeName.Text = leaveData.LeaveTypeName;
                        lbReqDate.Text = leaveData.RequestDate.Value.ToLongDateString();
                        lbPSName.Text = leaveData.Person.FirstName + " " + leaveData.Person.LastName;
                        lbPSPos.Text = leaveData.Person.PositionWorkName;
                        lbPSAPos.Text = leaveData.Person.AdminPositionName;
                        if(Util.IsBlank(leaveData.Person.WorkDivisionID)) {
                            lbPSDept.Text = leaveData.Person.DivisionName;
                        } else {
                            lbPSDept.Text = leaveData.Person.WorkDivisionName;
                        }

                        //if (leaveData.PS_BirthDate.HasValue) {
                            lbPSBirthDate.Text = leaveData.Person.BirthDate.Value.ToLongDateString();
                        //} else {
                        //    lbPSBirthDate.Text = "-";
                        //}
                        //if (leaveData.PS_WorkInDate.HasValue) {
                            lbPSWorkInDate.Text = leaveData.Person.InWorkDate.Value.ToLongDateString();
                        //} else {
                        //    lbPSWorkInDate.Text = "-";
                       // }

                        lbRestSave.Text = leaveData.RestSave + " วัน";
                        lbRestLeft.Text = leaveData.RestLeft + " วัน";
                        lbRestTotal.Text = leaveData.RestTotal + " วัน";

                        lbWifeName.Text = leaveData.WifeFirstName + " " + leaveData.WifeLastName;
                        if (leaveData.GiveBirthDate.HasValue) {
                            lbGBDate.Text = leaveData.GiveBirthDate.Value.ToLongDateString();
                        } else {
                            lbGBDate.Text = "-";
                        }

                        lbOrdained.Text = leaveData.Ordained == 1 ? "เคย" : "ไม่เคย";
                        lbTempleName.Text = leaveData.TempleName;
                        lbTempleLocation.Text = leaveData.TempleLocation;
                        if (leaveData.OrdainDate.HasValue) {
                            lbOrdainDate.Text = leaveData.OrdainDate.Value.ToLongDateString();
                        } else {
                            lbOrdainDate.Text = "-";
                        }

                        lbHujed.Text = leaveData.Hujed == 1 ? "เคย" : "ไม่เคย";

                        if (leaveData.FromDate.HasValue) {
                            lbFTTDate.Text = leaveData.FromDate.Value.ToLongDateString() + " ถึง " + leaveData.ToDate.Value.ToLongDateString() + " รวม " + leaveData.TotalDay + " วัน";
                        } else {
                            lbFTTDate.Text = "ไม่เคยลา";
                        }
                        lbStatistic.Text = "ลามาแล้ว " + leaveData.CountPast + " วัน / ลาครั้งนี้ " + leaveData.CountNow + " วัน / รวม " + leaveData.CountTotal + " วัน";

                        lbReason.Text = leaveData.Reason;
                        lbContact.Text = leaveData.Contact;
                        lbPhone.Text = leaveData.Telephone;

                        if (leaveData.LastFromDate.HasValue) {
                            lbLastFTTDate.Text = leaveData.LastFromDate.Value.ToLongDateString() + " ถึง " + leaveData.LastToDate.Value.ToLongDateString() + " รวม " + leaveData.LastTotalDay + " วัน";
                        } else {
                            lbLastFTTDate.Text = "ไม่เคยลา";
                        }

                        if (leaveData.DocterCertificationFileName != "") {
                            divDrCer.InnerHtml = "<a href='Upload/Drcer/" + leaveData.DocterCertificationFileName + "'><img src='Upload/DrCer/" + leaveData.DocterCertificationFileName + "' style='width: 200px;' /></a>";
                        }

                        /*lbCLComment.Text = "";
                        for (int j = 0; j < leaveData.LeaveBossDataList.Count; j++) {
                            if(!leaveData.LeaveBossDataList[j].Allow.HasValue) {
                                continue;
                            }
                            LeaveBossData leaveBossData = leaveData.LeaveBossDataList[j];
                            lbCLComment.Text += "<div style='color: #808080'>" + leaveBossData.Person.FirstNameAndLastName + " / " + leaveBossData.AllowDate.Value.ToLongDateString() +  "</div><div style='margin-bottom: 10px;'> - " + leaveBossData.Comment + "</div>";
                        }*/

                        {
                            TableRow row = new TableRow();
                            TableCell cell2;
                            Image image;
                            tbBoss.Rows.Add(row);

                            for (int j = 0; j < leaveData.BossStateMax; j++) {

                                LeaveBossData leaveBossData = leaveData.LeaveBossDataList[j];

                                cell2 = new TableCell();
                                cell2.Style.Add("vertical-align", "top");

                                Table tb = new Table();
                                tb.CssClass = "ps-table-1";
                                tb.Style.Add("text-align", "left");
                                {
                                    TableRow tr;
                                    TableCell cell3;

                                    tr = new TableRow();
                                    tb.Rows.Add(tr);

                                    cell3 = new TableCell();
                                    cell3.ColumnSpan = 2;
                                    cell3.Style.Add("text-align", "center");
                                    image = new Image();
                                    image.CssClass = "ps-ms-main-drop-profile-pic";

                                    string imagePath = DatabaseManager.GetPersonImageFileName(leaveBossData.CitizenID);
                                    if (imagePath != "") {
                                        image.Attributes["src"] = "Upload/PersonImage/" + imagePath;
                                        cell3.Controls.Add(image);
                                    }
                                    tr.Cells.Add(cell3);

                                    tr = new TableRow();
                                    tb.Rows.Add(tr);

                                    cell3 = new TableCell();
                                    cell3.Text = "ชื่อ";
                                    tr.Cells.Add(cell3);

                                    cell3 = new TableCell();
                                    cell3.Text = leaveBossData.Person.FirstNameAndLastName;
                                    tr.Cells.Add(cell3);

                                    tr = new TableRow();
                                    tb.Rows.Add(tr);

                                    cell3 = new TableCell();
                                    cell3.Text = "ตำแหน่ง";
                                    tr.Cells.Add(cell3);

                                    cell3 = new TableCell();
                                    cell3.Text = leaveBossData.Person.PositionWorkName;
                                    tr.Cells.Add(cell3);

                                    tr = new TableRow();
                                    tb.Rows.Add(tr);

                                    cell3 = new TableCell();
                                    cell3.Text = "ระดับ";
                                    tr.Cells.Add(cell3);

                                    cell3 = new TableCell();
                                    cell3.Text = leaveBossData.Person.AdminPositionName;// + "<br />" + leaveBossData.Person.AdminPositionNameExtra();
                                    tr.Cells.Add(cell3);

                                    tr = new TableRow();
                                    tb.Rows.Add(tr);

                                    cell3 = new TableCell();
                                    cell3.Text = "การอนุมัติ";
                                    tr.Cells.Add(cell3);

                                    cell3 = new TableCell();
                                    if (leaveData.LeaveStatusID == 1) {
                                        if (leaveBossData.Allow.HasValue) {
                                            cell3.Text = "<div style='color: #808080;'>" + leaveBossData.AllowDate.Value.ToLongDateString() + "</div>";
                                            if (leaveBossData.Allow.Value == 1) {
                                                cell3.Text += "<div style='color: green'>อนุญาต</div>";
                                            } else {
                                                cell3.Text += "<div style='color: red'>ไม่อนุญาต</div>";
                                            }
                                            cell3.Text += "<div style='color: #000000;'>" + leaveBossData.Comment + "</div>";

                                        }
                                    } else if(leaveData.LeaveStatusID == 4) {
                                        if (leaveBossData.CancelAllow.HasValue) {
                                            cell3.Text = "<div style='color: #808080;'>" + leaveBossData.CancelAllowDate.Value.ToLongDateString() + "</div>";
                                            if (leaveBossData.CancelAllow.Value == 1) {
                                                cell3.Text += "<div style='color: green'>อนุญาต</div>";
                                            } else {
                                                cell3.Text += "<div style='color: red'>ไม่อนุญาต</div>";
                                            }
                                            cell3.Text += "<div style='color: #000000;'>" + leaveBossData.CancelComment + "</div>";

                                        }
                                    }

                                    tr.Cells.Add(cell3);

                                }

                                cell2.Controls.Add(tb);

                                row.Cells.Add(cell2);
                            }
                        }

                        lbCancelReason.Text = leaveData.CancelReason;

                        /*if (leaveData.LeaveStatusID >= 1 && leaveData.LeaveStatusID <= 4) {
                            if(leaveData.CL_ID == null) {
                                lbCLComment.Text = "-";
                                lbCLDate.Text = "-";
                            } else {
                                lbCLComment.Text = leaveData.CL_Comment;
                                lbCLDate.Text = leaveData.CL_Date.Value.ToLongDateString();
                            }

                        } else if (leaveData.LeaveStatusID >= 5 && leaveData.LeaveStatusID <= 8) {
                            if(leaveData.CL_ID == null) {
                                lbCLOldComment.Text = "-";
                                lbCLOldDate.Text = "-";
                                lbCHOldComment.Text = leaveData.CH_Comment;
                                lbCHOldDate.Text = leaveData.CH_Date.Value.ToLongDateString();
                                lbCancelReason.Text = leaveData.CancelReason;
                                lbCLComment.Text = "-";
                                lbCLDate.Text = "-";
                            } else {
                                lbCLOldComment.Text = leaveData.CL_Comment;
                                lbCLOldDate.Text = leaveData.CL_Date.Value.ToLongDateString();
                                lbCHOldComment.Text = leaveData.CH_Comment;
                                lbCHOldDate.Text = leaveData.CH_Date.Value.ToLongDateString();
                                lbCancelReason.Text = leaveData.CancelReason;
                                lbCLComment.Text = leaveData.CL_CancelComment;
                                lbCLDate.Text = leaveData.CL_CancelDate.Value.ToLongDateString();
                            }

                        }*/

                        MultiView1.ActiveViewIndex = 1;

                        error_area.Attributes["class"] = null;
                        error_area.InnerHtml = "";
                    };
                    TableCell cell = new TableCell();
                    cell.Controls.Add(lbu);
                    GridView1.Rows[i].Cells.Add(cell);
                }

                lbNoData.Visible = false;
            } else {
                lbNoData.Visible = true;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            /*if (!IsPostBack) {
                ChangeNotification("info", "กรุณากรอกข้อมูล");
            }*/
                PersonnelSystem ps = PersonnelSystem.GetPersonnelSystem(this);
                Person loginPerson = ps.LoginPerson;

            //------

            {
                SqlDataSource sds = DatabaseManager.CreateSQLDataSource("SELECT LEAVE_ID รหัสการลา, (SELECT LEAVE_TYPE_NAME FROM LEV_TYPE WHERE LEV_TYPE.LEAVE_TYPE_ID = LEV_DATA.LEAVE_TYPE_ID) ประเภทการลา, REQ_DATE วันที่ข้อมูล, FROM_DATE จากวันที่, TO_DATE ถึงวันที่, TOTAL_DAY รวมวัน FROM LEV_DATA WHERE LEAVE_STATUS_ID = 1 AND PS_ID = '" + loginPerson.CitizenID + "' ORDER BY LEAVE_ID DESC");
                gvLeaveProgress.DataSource = sds;
                gvLeaveProgress.DataBind();

                if (gvLeaveProgress.Rows.Count > 0) {
                    lbLeaveProgress.Visible = false;
                    TableHeaderCell headerCell = new TableHeaderCell();
                    headerCell.Text = "เลือก";
                    gvLeaveProgress.HeaderRow.Cells.Add(headerCell);

                    gvLeaveProgress.HeaderRow.Cells[0].Text = "<img src='Image/Small/ID.png' class='icon_left'/>" + gvLeaveProgress.HeaderRow.Cells[0].Text;
                    gvLeaveProgress.HeaderRow.Cells[1].Text = "<img src='Image/Small/list.png' class='icon_left'/>" + gvLeaveProgress.HeaderRow.Cells[1].Text;
                    gvLeaveProgress.HeaderRow.Cells[2].Text = "<img src='Image/Small/calendar.png' class='icon_left'/>" + gvLeaveProgress.HeaderRow.Cells[2].Text;
                    gvLeaveProgress.HeaderRow.Cells[3].Text = "<img src='Image/Small/calendar.png' class='icon_left'/>" + gvLeaveProgress.HeaderRow.Cells[3].Text;
                    gvLeaveProgress.HeaderRow.Cells[4].Text = "<img src='Image/Small/calendar.png' class='icon_left'/>" + gvLeaveProgress.HeaderRow.Cells[4].Text;
                    gvLeaveProgress.HeaderRow.Cells[6].Text = "<img src='Image/Small/pointer.png' class='icon_left'/>" + gvLeaveProgress.HeaderRow.Cells[6].Text;

                    for (int i = 0; i < gvLeaveProgress.Rows.Count; ++i) {

                        string ID = gvLeaveProgress.Rows[i].Cells[0].Text;
                        TableCell cell = new TableCell();
                        LinkButton btn = new LinkButton();
                        btn.CssClass = "ps-button";
                        btn.Text = "<img src='Image/Small/next.png'></img>";
                        btn.Click += (e2, e3) => {

                            lbuCancelFinish.Visible = false;
                            lbuCancelProgressFinish.Visible = true;
                            trCancelReason.Visible = false;

                            LeaveData leaveData = new LeaveData();
                            leaveData.Load(int.Parse(ID));

                            trPSBirthDate.Visible = false;
                            trPSWorkInDate.Visible = false;
                            trWifeName.Visible = false;
                            trGBDate.Visible = false;
                            trOrdained.Visible = false;
                            trTempleName.Visible = false;
                            trTempleLocation.Visible = false;
                            trOrdainDate.Visible = false;
                            trHujed.Visible = false;
                            trReason.Visible = false;
                            trContact.Visible = false;
                            trPhone.Visible = false;
                            trRestSave.Visible = false;
                            trRestLeft.Visible = false;
                            trRestTotal.Visible = false;
                            trStatistic.Visible = false;

                            if (leaveData.LeaveTypeID == 1) {
                                trStatistic.Visible = true;
                                trReason.Visible = true;
                                trContact.Visible = true;
                                trPhone.Visible = true;
                            } else if (leaveData.LeaveTypeID == 2) {
                                trStatistic.Visible = true;
                                trReason.Visible = true;
                                trContact.Visible = true;
                                trPhone.Visible = true;
                            } else if (leaveData.LeaveTypeID == 3) {
                                trStatistic.Visible = true;
                                trReason.Visible = true;
                                trContact.Visible = true;
                                trPhone.Visible = true;
                            } else if (leaveData.LeaveTypeID == 4) {
                                trRestSave.Visible = true;
                                trRestLeft.Visible = true;
                                trRestTotal.Visible = true;
                                trContact.Visible = true;
                                trPhone.Visible = true;
                            } else if (leaveData.LeaveTypeID == 5) {
                                trWifeName.Visible = true;
                                trGBDate.Visible = true;
                                trContact.Visible = true;
                                trPhone.Visible = true;
                            } else if (leaveData.LeaveTypeID == 6) {
                                trPSBirthDate.Visible = true;
                                trPSWorkInDate.Visible = true;
                                trOrdained.Visible = true;
                                trTempleName.Visible = true;
                                trTempleLocation.Visible = true;
                                trOrdainDate.Visible = true;
                            } else if (leaveData.LeaveTypeID == 7) {
                                trPSBirthDate.Visible = true;
                                trPSWorkInDate.Visible = true;
                                trHujed.Visible = true;
                            }

                            lbLeaveID.Text = leaveData.LeaveID.ToString();
                            lbLeaveTypeName.Text = leaveData.LeaveTypeName;
                            lbReqDate.Text = leaveData.RequestDate.Value.ToLongDateString();
                            lbPSName.Text = leaveData.Person.FirstName + " " + leaveData.Person.LastName;
                            lbPSPos.Text = leaveData.Person.PositionWorkName;
                            lbPSAPos.Text = leaveData.Person.AdminPositionName;
                            if (Util.IsBlank(leaveData.Person.WorkDivisionID)) {
                                lbPSDept.Text = leaveData.Person.DivisionName;
                            } else {
                                lbPSDept.Text = leaveData.Person.WorkDivisionName;
                            }
                            lbPSBirthDate.Text = leaveData.Person.BirthDate.Value.ToLongDateString();
                            lbPSWorkInDate.Text = leaveData.Person.InWorkDate.Value.ToLongDateString();

                            lbRestSave.Text = leaveData.RestSave + " วัน";
                            lbRestLeft.Text = leaveData.RestLeft + " วัน";
                            lbRestTotal.Text = leaveData.RestTotal + " วัน";

                            lbWifeName.Text = leaveData.WifeFirstName + " " + leaveData.WifeLastName;
                            if (leaveData.GiveBirthDate.HasValue) {
                                lbGBDate.Text = leaveData.GiveBirthDate.Value.ToLongDateString();
                            } else {
                                lbGBDate.Text = "-";
                            }

                            lbOrdained.Text = leaveData.Ordained == 1 ? "เคย" : "ไม่เคย";
                            lbTempleName.Text = leaveData.TempleName;
                            lbTempleLocation.Text = leaveData.TempleLocation;
                            if (leaveData.OrdainDate.HasValue) {
                                lbOrdainDate.Text = leaveData.OrdainDate.Value.ToLongDateString();
                            } else {
                                lbOrdainDate.Text = "-";
                            }

                            lbHujed.Text = leaveData.Hujed == 1 ? "เคย" : "ไม่เคย";

                            if (leaveData.FromDate.HasValue) {
                                lbFTTDate.Text = leaveData.FromDate.Value.ToLongDateString() + " ถึง " + leaveData.ToDate.Value.ToLongDateString() + " รวม " + leaveData.TotalDay + " วัน";
                            } else {
                                lbFTTDate.Text = "ไม่เคยลา";
                            }
                            lbStatistic.Text = "ลามาแล้ว " + leaveData.CountPast + " วัน / ลาครั้งนี้ " + leaveData.CountNow + " วัน / รวม " + leaveData.CountTotal + " วัน";

                            lbReason.Text = leaveData.Reason;
                            lbContact.Text = leaveData.Contact;
                            lbPhone.Text = leaveData.Telephone;

                            if (leaveData.LastFromDate.HasValue) {
                                lbLastFTTDate.Text = leaveData.LastFromDate.Value.ToLongDateString() + " ถึง " + leaveData.LastToDate.Value.ToLongDateString() + " รวม " + leaveData.LastTotalDay + " วัน";
                            } else {
                                lbLastFTTDate.Text = "ไม่เคยลา";
                            }

                            if (leaveData.DocterCertificationFileName != "") {
                                divDrCer.InnerHtml = "<a href='Upload/Drcer/" + leaveData.DocterCertificationFileName + "'><img src='Upload/DrCer/" + leaveData.DocterCertificationFileName + "' style='width: 200px;' /></a>";
                            }

                            {
                                TableRow row = new TableRow();
                                TableCell cell2;
                                Image image;
                                tbBoss.Rows.Add(row);

                                for (int j = 0; j < leaveData.BossStateMax; j++) {

                                    LeaveBossData leaveBossData = leaveData.LeaveBossDataList[j];

                                    cell2 = new TableCell();
                                    cell2.Style.Add("vertical-align", "top");

                                    Table tb = new Table();
                                    tb.CssClass = "ps-table-1";
                                    tb.Style.Add("text-align", "left");
                                    {
                                        TableRow tr;
                                        TableCell cell3;

                                        tr = new TableRow();
                                        tb.Rows.Add(tr);

                                        cell3 = new TableCell();
                                        cell3.ColumnSpan = 2;
                                        cell3.Style.Add("text-align", "center");
                                        image = new Image();
                                        image.CssClass = "ps-ms-main-drop-profile-pic";

                                        string imagePath = DatabaseManager.GetPersonImageFileName(leaveBossData.CitizenID);
                                        if (imagePath != "") {
                                            image.Attributes["src"] = "Upload/PersonImage/" + imagePath;
                                            cell3.Controls.Add(image);
                                        }
                                        tr.Cells.Add(cell3);

                                        tr = new TableRow();
                                        tb.Rows.Add(tr);

                                        cell3 = new TableCell();
                                        cell3.Text = "ชื่อ";
                                        tr.Cells.Add(cell3);

                                        cell3 = new TableCell();
                                        cell3.Text = leaveBossData.Person.FirstNameAndLastName;
                                        tr.Cells.Add(cell3);

                                        tr = new TableRow();
                                        tb.Rows.Add(tr);

                                        cell3 = new TableCell();
                                        cell3.Text = "ตำแหน่ง";
                                        tr.Cells.Add(cell3);

                                        cell3 = new TableCell();
                                        cell3.Text = leaveBossData.Person.PositionWorkName;
                                        tr.Cells.Add(cell3);

                                        tr = new TableRow();
                                        tb.Rows.Add(tr);

                                        cell3 = new TableCell();
                                        cell3.Text = "ระดับ";
                                        tr.Cells.Add(cell3);

                                        cell3 = new TableCell();
                                        cell3.Text = leaveBossData.Person.AdminPositionName;// + "<br />" + leaveBossData.Person.AdminPositionNameExtra();
                                        tr.Cells.Add(cell3);

                                        tr = new TableRow();
                                        tb.Rows.Add(tr);

                                        cell3 = new TableCell();
                                        cell3.Text = "การอนุมัติ";
                                        tr.Cells.Add(cell3);

                                        cell3 = new TableCell();
                                        if (leaveBossData.Allow.HasValue) {
                                            cell3.Text = "<div style='color: #808080;'>" + leaveBossData.AllowDate.Value.ToLongDateString() + "</div>";
                                            if (leaveBossData.Allow.Value == 1) {
                                                cell3.Text += "<div style='color: green'>อนุญาต</div>";
                                            } else {
                                                cell3.Text += "<div style='color: red'>ไม่อนุญาต</div>";
                                            }
                                            cell3.Text += "<div style='color: #000000;'>" + leaveBossData.Comment + "</div>";

                                        }
                                        tr.Cells.Add(cell3);

                                    }

                                    cell2.Controls.Add(tb);

                                    row.Cells.Add(cell2);
                                }
                            }

                            Session["LeaveData"] = leaveData;

                            MV1.ActiveViewIndex = 1;
                            //Response.Redirect("ViewLeaveForm.aspx?Form=1&LeaveID=" + ID);
                        };
                        cell.Controls.Add(btn);
                        gvLeaveProgress.Rows[i].Cells.Add(cell);

                    }

                    Util.NormalizeGridViewDate(gvLeaveProgress, 2);
                    Util.NormalizeGridViewDate(gvLeaveProgress, 3);
                    Util.NormalizeGridViewDate(gvLeaveProgress, 4);
                } else {
                    lbLeaveProgress.Visible = true;
                }

            }

            //--------

            {
                SqlDataSource sds = DatabaseManager.CreateSQLDataSource("SELECT LEAVE_ID รหัสการลา, (SELECT LEAVE_TYPE_NAME FROM LEV_TYPE WHERE LEV_TYPE.LEAVE_TYPE_ID = LEV_DATA.LEAVE_TYPE_ID) ประเภทการลา, REQ_DATE วันที่ข้อมูล, FROM_DATE จากวันที่, TO_DATE ถึงวันที่, TOTAL_DAY รวมวัน FROM LEV_DATA WHERE LEAVE_STATUS_ID = 3 AND PS_ID = '" + loginPerson.CitizenID + "' AND V_ALLOW = 1 AND CEIL(FROM_DATE - CURRENT_DATE) >= 3 ORDER BY LEAVE_ID DESC");
                gvLeave.DataSource = sds;
                gvLeave.DataBind();

                if (gvLeave.Rows.Count > 0) {
                    lbLeave.Visible = false;
                    TableHeaderCell headerCell = new TableHeaderCell();
                    headerCell.Text = "เลือก";
                    gvLeave.HeaderRow.Cells.Add(headerCell);

                    gvLeave.HeaderRow.Cells[0].Text = "<img src='Image/Small/ID.png' class='icon_left'/>" + gvLeave.HeaderRow.Cells[0].Text;
                    gvLeave.HeaderRow.Cells[1].Text = "<img src='Image/Small/list.png' class='icon_left'/>" + gvLeave.HeaderRow.Cells[1].Text;
                    gvLeave.HeaderRow.Cells[2].Text = "<img src='Image/Small/calendar.png' class='icon_left'/>" + gvLeave.HeaderRow.Cells[2].Text;
                    gvLeave.HeaderRow.Cells[3].Text = "<img src='Image/Small/calendar.png' class='icon_left'/>" + gvLeave.HeaderRow.Cells[3].Text;
                    gvLeave.HeaderRow.Cells[4].Text = "<img src='Image/Small/calendar.png' class='icon_left'/>" + gvLeave.HeaderRow.Cells[4].Text;
                    gvLeave.HeaderRow.Cells[6].Text = "<img src='Image/Small/pointer.png' class='icon_left'/>" + gvLeave.HeaderRow.Cells[6].Text;

                    for (int i = 0; i < gvLeave.Rows.Count; ++i) {

                        string ID = gvLeave.Rows[i].Cells[0].Text;
                        TableCell cell = new TableCell();
                        LinkButton btn = new LinkButton();
                        btn.CssClass = "ps-button";
                        btn.Text = "<img src='Image/Small/next.png'></img>";
                        btn.Click += (e2, e3) => {

                            lbuCancelFinish.Visible = true;
                            lbuCancelProgressFinish.Visible = false;
                            trCancelReason.Visible = true;

                            LeaveData leaveData = new LeaveData();
                            leaveData.Load(int.Parse(ID));

                            trPSBirthDate.Visible = false;
                            trPSWorkInDate.Visible = false;
                            trWifeName.Visible = false;
                            trGBDate.Visible = false;
                            trOrdained.Visible = false;
                            trTempleName.Visible = false;
                            trTempleLocation.Visible = false;
                            trOrdainDate.Visible = false;
                            trHujed.Visible = false;
                            trReason.Visible = false;
                            trContact.Visible = false;
                            trPhone.Visible = false;
                            trRestSave.Visible = false;
                            trRestLeft.Visible = false;
                            trRestTotal.Visible = false;
                            trStatistic.Visible = false;

                            if (leaveData.LeaveTypeID == 1) {
                                trStatistic.Visible = true;
                                trReason.Visible = true;
                                trContact.Visible = true;
                                trPhone.Visible = true;
                            } else if (leaveData.LeaveTypeID == 2) {
                                trStatistic.Visible = true;
                                trReason.Visible = true;
                                trContact.Visible = true;
                                trPhone.Visible = true;
                            } else if (leaveData.LeaveTypeID == 3) {
                                trStatistic.Visible = true;
                                trReason.Visible = true;
                                trContact.Visible = true;
                                trPhone.Visible = true;
                            } else if (leaveData.LeaveTypeID == 4) {
                                trRestSave.Visible = true;
                                trRestLeft.Visible = true;
                                trRestTotal.Visible = true;
                                trContact.Visible = true;
                                trPhone.Visible = true;
                            } else if (leaveData.LeaveTypeID == 5) {
                                trWifeName.Visible = true;
                                trGBDate.Visible = true;
                                trContact.Visible = true;
                                trPhone.Visible = true;
                            } else if (leaveData.LeaveTypeID == 6) {
                                trPSBirthDate.Visible = true;
                                trPSWorkInDate.Visible = true;
                                trOrdained.Visible = true;
                                trTempleName.Visible = true;
                                trTempleLocation.Visible = true;
                                trOrdainDate.Visible = true;
                            } else if (leaveData.LeaveTypeID == 7) {
                                trPSBirthDate.Visible = true;
                                trPSWorkInDate.Visible = true;
                                trHujed.Visible = true;
                            }

                            lbLeaveID.Text = leaveData.LeaveID.ToString();
                            lbLeaveTypeName.Text = leaveData.LeaveTypeName;
                            lbReqDate.Text = leaveData.RequestDate.Value.ToLongDateString();
                            lbPSName.Text = leaveData.Person.FirstName + " " + leaveData.Person.LastName;
                            lbPSPos.Text = leaveData.Person.PositionWorkName;
                            lbPSAPos.Text = leaveData.Person.AdminPositionName;
                            if (Util.IsBlank(leaveData.Person.WorkDivisionID)) {
                                lbPSDept.Text = leaveData.Person.DivisionName;
                            } else {
                                lbPSDept.Text = leaveData.Person.WorkDivisionName;
                            }
                            lbPSBirthDate.Text = leaveData.Person.BirthDate.Value.ToLongDateString();
                            lbPSWorkInDate.Text = leaveData.Person.InWorkDate.Value.ToLongDateString();

                            lbRestSave.Text = leaveData.RestSave + " วัน";
                            lbRestLeft.Text = leaveData.RestLeft + " วัน";
                            lbRestTotal.Text = leaveData.RestTotal + " วัน";

                            lbWifeName.Text = leaveData.WifeFirstName + " " + leaveData.WifeLastName;
                            if (leaveData.GiveBirthDate.HasValue) {
                                lbGBDate.Text = leaveData.GiveBirthDate.Value.ToLongDateString();
                            } else {
                                lbGBDate.Text = "-";
                            }

                            lbOrdained.Text = leaveData.Ordained == 1 ? "เคย" : "ไม่เคย";
                            lbTempleName.Text = leaveData.TempleName;
                            lbTempleLocation.Text = leaveData.TempleLocation;
                            if (leaveData.OrdainDate.HasValue) {
                                lbOrdainDate.Text = leaveData.OrdainDate.Value.ToLongDateString();
                            } else {
                                lbOrdainDate.Text = "-";
                            }

                            lbHujed.Text = leaveData.Hujed == 1 ? "เคย" : "ไม่เคย";

                            if (leaveData.FromDate.HasValue) {
                                lbFTTDate.Text = leaveData.FromDate.Value.ToLongDateString() + " ถึง " + leaveData.ToDate.Value.ToLongDateString() + " รวม " + leaveData.TotalDay + " วัน";
                            } else {
                                lbFTTDate.Text = "ไม่เคยลา";
                            }
                            lbStatistic.Text = "ลามาแล้ว " + leaveData.CountPast + " วัน / ลาครั้งนี้ " + leaveData.CountNow + " วัน / รวม " + leaveData.CountTotal + " วัน";

                            lbReason.Text = leaveData.Reason;
                            lbContact.Text = leaveData.Contact;
                            lbPhone.Text = leaveData.Telephone;

                            if (leaveData.LastFromDate.HasValue) {
                                lbLastFTTDate.Text = leaveData.LastFromDate.Value.ToLongDateString() + " ถึง " + leaveData.LastToDate.Value.ToLongDateString() + " รวม " + leaveData.LastTotalDay + " วัน";
                            } else {
                                lbLastFTTDate.Text = "ไม่เคยลา";
                            }

                            if (leaveData.DocterCertificationFileName != "") {
                                divDrCer.InnerHtml = "<a href='Upload/Drcer/" + leaveData.DocterCertificationFileName + "'><img src='Upload/DrCer/" + leaveData.DocterCertificationFileName + "' style='width: 200px;' /></a>";
                            }

                            {
                            TableRow row = new TableRow();
                            TableCell cell2;
                            Image image;
                            tbBoss.Rows.Add(row);

                            for (int j = 0; j < leaveData.BossStateMax; j++) {

                                LeaveBossData leaveBossData = leaveData.LeaveBossDataList[j];

                                cell2 = new TableCell();
                                cell2.Style.Add("vertical-align", "top");

                                Table tb = new Table();
                                tb.CssClass = "ps-table-1";
                                tb.Style.Add("text-align", "left");
                                {
                                    TableRow tr;
                                    TableCell cell3;

                                    tr = new TableRow();
                                    tb.Rows.Add(tr);

                                    cell3 = new TableCell();
                                    cell3.ColumnSpan = 2;
                                    cell3.Style.Add("text-align", "center");
                                    image = new Image();
                                    image.CssClass = "ps-ms-main-drop-profile-pic";

                                    string imagePath = DatabaseManager.GetPersonImageFileName(leaveBossData.CitizenID);
                                    if (imagePath != "") {
                                        image.Attributes["src"] = "Upload/PersonImage/" + imagePath;
                                        cell3.Controls.Add(image);
                                    }
                                    tr.Cells.Add(cell3);

                                    tr = new TableRow();
                                    tb.Rows.Add(tr);

                                    cell3 = new TableCell();
                                    cell3.Text = "ชื่อ";
                                    tr.Cells.Add(cell3);

                                    cell3 = new TableCell();
                                    cell3.Text = leaveBossData.Person.FirstNameAndLastName;
                                    tr.Cells.Add(cell3);

                                    tr = new TableRow();
                                    tb.Rows.Add(tr);

                                    cell3 = new TableCell();
                                    cell3.Text = "ตำแหน่ง";
                                    tr.Cells.Add(cell3);

                                    cell3 = new TableCell();
                                    cell3.Text = leaveBossData.Person.PositionWorkName;
                                    tr.Cells.Add(cell3);

                                    tr = new TableRow();
                                    tb.Rows.Add(tr);

                                    cell3 = new TableCell();
                                    cell3.Text = "ระดับ";
                                    tr.Cells.Add(cell3);

                                    cell3 = new TableCell();
                                    cell3.Text = leaveBossData.Person.AdminPositionName;// + "<br />" + leaveBossData.Person.AdminPositionNameExtra();
                                    tr.Cells.Add(cell3);

                                    tr = new TableRow();
                                    tb.Rows.Add(tr);

                                    cell3 = new TableCell();
                                    cell3.Text = "การอนุมัติ";
                                    tr.Cells.Add(cell3);

                                    cell3 = new TableCell();
                                    if(leaveBossData.Allow.HasValue) {
                                        cell3.Text = "<div style='color: #808080;'>" + leaveBossData.AllowDate.Value.ToLongDateString() + "</div>";
                                        if(leaveBossData.Allow.Value == 1) {
                                            cell3.Text += "<div style='color: green'>อนุญาต</div>";
                                        } else {
                                            cell3.Text += "<div style='color: red'>ไม่อนุญาต</div>";
                                        }
                                        cell3.Text += "<div style='color: #000000;'>" + leaveBossData.Comment + "</div>";

                                    }
                                    tr.Cells.Add(cell3);

                                }

                                cell2.Controls.Add(tb);

                                row.Cells.Add(cell2);
                            }
                        }

                            Session["LeaveData"] = leaveData;

                            MV1.ActiveViewIndex = 1;
                            //Response.Redirect("ViewLeaveForm.aspx?Form=1&LeaveID=" + ID);
                        };
                        cell.Controls.Add(btn);
                        gvLeave.Rows[i].Cells.Add(cell);

                    }

                    Util.NormalizeGridViewDate(gvLeave, 2);
                    Util.NormalizeGridViewDate(gvLeave, 3);
                    Util.NormalizeGridViewDate(gvLeave, 4);
                } else {
                    lbLeave.Visible = true;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack) {

                int leaveID = int.Parse(Request.QueryString["LeaveID"]);
                LeaveData leaveData = new LeaveData();
                leaveData.Load(leaveID);

                if (!leaveData.HasData) {
                    return;
                }

                trPSBirthDate.Visible = false;
                trPSWorkInDate.Visible = false;
                trWifeName.Visible = false;
                trGBDate.Visible = false;
                trOrdained.Visible = false;
                trTempleName.Visible = false;
                trTempleLocation.Visible = false;
                trOrdainDate.Visible = false;
                trHujed.Visible = false;
                trReason.Visible = false;
                trContact.Visible = false;
                trPhone.Visible = false;
                trRestSave.Visible = false;
                trRestLeft.Visible = false;
                trRestTotal.Visible = false;
                trStatistic.Visible = false;
                trCancelReason.Visible = false;
              /*  trCLCancelComment.Visible = false;
                trCLCancelDate.Visible = false;
                trCHCancelComment.Visible = false;
                trCHCancelDate.Visible = false;
                trCHCancelAllow.Visible = false;*/

                if (leaveData.LeaveTypeID == 1) {
                    trStatistic.Visible = true;
                    trReason.Visible = true;
                    trContact.Visible = true;
                    trPhone.Visible = true;
                } else if (leaveData.LeaveTypeID == 2) {
                    trStatistic.Visible = true;
                    trReason.Visible = true;
                    trContact.Visible = true;
                    trPhone.Visible = true;
                } else if (leaveData.LeaveTypeID == 3) {
                    trStatistic.Visible = true;
                    trReason.Visible = true;
                    trContact.Visible = true;
                    trPhone.Visible = true;
                } else if (leaveData.LeaveTypeID == 4) {
                    trRestSave.Visible = true;
                    trRestLeft.Visible = true;
                    trRestTotal.Visible = true;
                    trContact.Visible = true;
                    trPhone.Visible = true;
                } else if (leaveData.LeaveTypeID == 5) {
                    trWifeName.Visible = true;
                    trGBDate.Visible = true;
                    trContact.Visible = true;
                    trPhone.Visible = true;
                } else if (leaveData.LeaveTypeID == 6) {
                    trPSBirthDate.Visible = true;
                    trPSWorkInDate.Visible = true;
                    trOrdained.Visible = true;
                    trTempleName.Visible = true;
                    trTempleLocation.Visible = true;
                    trOrdainDate.Visible = true;
                } else if (leaveData.LeaveTypeID == 7) {
                    trPSBirthDate.Visible = true;
                    trPSWorkInDate.Visible = true;
                    trHujed.Visible = true;
                }

                if (leaveData.LeaveStatusID >= 1 && leaveData.LeaveStatusID <= 3) {

                } else if (leaveData.LeaveStatusID >= 4 && leaveData.LeaveStatusID <= 6) {
                    trCancelReason.Visible = true;
                   /* trCLCancelComment.Visible = true;
                    trCLCancelDate.Visible = true;
                    trCHCancelComment.Visible = true;
                    trCHCancelDate.Visible = true;
                    trCHCancelAllow.Visible = true;*/
                }

                lbLeaveID.Text = leaveData.LeaveID.ToString();
                lbLeaveStatusID.Text = leaveData.LeaveStatusName;
                lbLeaveType.Text = leaveData.LeaveTypeName;
                lbReqDate.Text = leaveData.RequestDate.Value.ToLongDateString();
                lbPSName.Text = leaveData.Person.FirstName + " " + leaveData.Person.LastName;
                lbPSPos.Text = leaveData.Person.PositionWorkName;
                lbPSAPos.Text = leaveData.Person.AdminPositionName;
                if (Util.IsBlank(leaveData.Person.WorkDivisionID)) {
                    lbPSDept.Text = leaveData.Person.DivisionName;
                } else {
                    lbPSDept.Text = leaveData.Person.WorkDivisionName;
                }

                //if (leaveData.PS_BirthDate.HasValue) {
                lbPSBirthDate.Text = leaveData.Person.BirthDate.Value.ToLongDateString();
                //} else {
                //    lbPSBirthDate.Text = "-";
                //}
                //if (leaveData.PS_WorkInDate.HasValue) {
                lbPSWorkInDate.Text = leaveData.Person.InWorkDate.Value.ToLongDateString();
                //} else {
                //    lbPSWorkInDate.Text = "-";
                // }

                lbRestSave.Text = leaveData.RestSave + " วัน";
                lbRestLeft.Text = leaveData.RestLeft + " วัน";
                lbRestTotal.Text = leaveData.RestTotal + " วัน";

                lbWifeName.Text = leaveData.WifeFirstName + " " + leaveData.WifeLastName;
                if (leaveData.GiveBirthDate.HasValue) {
                    lbGBDate.Text = leaveData.GiveBirthDate.Value.ToLongDateString();
                } else {
                    lbGBDate.Text = "-";
                }

                lbOrdained.Text = leaveData.Ordained == 1 ? "เคย" : "ไม่เคย";
                lbTempleName.Text = leaveData.TempleName;
                lbTempleLocation.Text = leaveData.TempleLocation;
                if (leaveData.OrdainDate.HasValue) {
                    lbOrdainDate.Text = leaveData.OrdainDate.Value.ToLongDateString();
                } else {
                    lbOrdainDate.Text = "-";
                }

                lbHujed.Text = leaveData.Hujed == 1 ? "เคย" : "ไม่เคย";

                if (leaveData.FromDate.HasValue) {
                    lbFTTDate.Text = leaveData.FromDate.Value.ToLongDateString() + " ถึง " + leaveData.ToDate.Value.ToLongDateString() + " รวม " + leaveData.TotalDay + " วัน";
                } else {
                    lbFTTDate.Text = "ไม่เคยลา";
                }
                lbStatistic.Text = "ลามาแล้ว " + leaveData.CountPast + " วัน / ลาครั้งนี้ " + leaveData.CountNow + " วัน / รวม " + leaveData.CountTotal + " วัน";

                lbReason.Text = leaveData.Reason;
                lbContact.Text = leaveData.Contact;
                lbPhone.Text = leaveData.Telephone;

                if (leaveData.LastFromDate.HasValue) {
                    lbLastFTTDate.Text = leaveData.LastFromDate.Value.ToLongDateString() + " ถึง " + leaveData.LastToDate.Value.ToLongDateString() + " รวม " + leaveData.LastTotalDay + " วัน";
                } else {
                    lbLastFTTDate.Text = "ไม่เคยลา";
                }

                {
                    TableRow row = new TableRow();
                    TableCell cell2;
                    Image image;
                    tbBoss.Rows.Add(row);

                    for (int j = 0; j < leaveData.BossStateMax; j++) {

                        LeaveBossData leaveBossData = leaveData.LeaveBossDataList[j];

                        cell2 = new TableCell();
                        cell2.Style.Add("vertical-align", "top");

                        Table tb = new Table();
                        tb.CssClass = "ps-table-1";
                        tb.Style.Add("text-align", "left");
                        {
                            TableRow tr;
                            TableCell cell3;

                            tr = new TableRow();
                            tb.Rows.Add(tr);

                            cell3 = new TableCell();
                            cell3.ColumnSpan = 2;
                            cell3.Style.Add("text-align", "center");
                            image = new Image();
                            image.CssClass = "ps-ms-main-drop-profile-pic";

                            string imagePath = DatabaseManager.GetPersonImageFileName(leaveBossData.CitizenID);
                            if (imagePath != "") {
                                image.Attributes["src"] = "Upload/PersonImage/" + imagePath;
                                cell3.Controls.Add(image);
                            }
                            tr.Cells.Add(cell3);

                            tr = new TableRow();
                            tb.Rows.Add(tr);

                            cell3 = new TableCell();
                            cell3.Text = "ชื่อ";
                            tr.Cells.Add(cell3);

                            cell3 = new TableCell();
                            cell3.Text = leaveBossData.Person.FirstNameAndLastName;
                            tr.Cells.Add(cell3);

                            tr = new TableRow();
                            tb.Rows.Add(tr);

                            cell3 = new TableCell();
                            cell3.Text = "ตำแหน่ง";
                            tr.Cells.Add(cell3);

                            cell3 = new TableCell();
                            cell3.Text = leaveBossData.Person.PositionWorkName;
                            tr.Cells.Add(cell3);

                            tr = new TableRow();
                            tb.Rows.Add(tr);

                            cell3 = new TableCell();
                            cell3.Text = "ระดับ";
                            tr.Cells.Add(cell3);

                            cell3 = new TableCell();
                            cell3.Text = leaveBossData.Person.AdminPositionName;// + "<br />" + leaveBossData.Person.AdminPositionNameExtra();
                            tr.Cells.Add(cell3);

                            tr = new TableRow();
                            tb.Rows.Add(tr);

                            cell3 = new TableCell();
                            cell3.Text = "การอนุมัติ";
                            tr.Cells.Add(cell3);

                            cell3 = new TableCell();
                            if (leaveBossData.Allow.HasValue) {
                                cell3.Text = "<div style='color: #808080;'>" + leaveBossData.AllowDate.Value.ToLongDateString() + "</div>";
                                if (leaveBossData.Allow.Value == 1) {
                                    cell3.Text += "<div style='color: green'>อนุญาต</div>";
                                } else {
                                    cell3.Text += "<div style='color: red'>ไม่อนุญาต</div>";
                                }
                                cell3.Text += "<div style='color: #000000;'>" + leaveBossData.Comment + "</div>";

                            }
                            tr.Cells.Add(cell3);

                            if(leaveData.CancelAllow.HasValue) {
                                tr = new TableRow();
                                tb.Rows.Add(tr);

                                cell3 = new TableCell();
                                cell3.Text = "การอนุมัติยกเลิก";
                                tr.Cells.Add(cell3);

                                cell3 = new TableCell();
                                if (leaveBossData.CancelAllow.HasValue) {
                                    cell3.Text = "<div style='color: #808080;'>" + leaveBossData.CancelAllowDate.Value.ToLongDateString() + "</div>";
                                    if (leaveBossData.CancelAllow.Value == 1) {
                                        cell3.Text += "<div style='color: green'>อนุญาต</div>";
                                    } else {
                                        cell3.Text += "<div style='color: red'>ไม่อนุญาต</div>";
                                    }
                                    cell3.Text += "<div style='color: #000000;'>" + leaveBossData.CancelComment + "</div>";

                                }
                                tr.Cells.Add(cell3);
                            }

                        }

                        cell2.Controls.Add(tb);

                        row.Cells.Add(cell2);
                    }
                }

                /*if(leaveData.CL_ID == null) {
                    lbCLName.Text = "-";
                    lbCLPos.Text = "-";
                    lbCLCom.Text = "-";
                    lbCLDate.Text = "-";
                } else {
                    lbCLName.Text = leaveData.CL_Title + leaveData.CL_FirstName + " " + leaveData.CL_LastName;
                    lbCLPos.Text = leaveData.CL_Position;
                    if (leaveData.CL_Comment != "") {
                        lbCLCom.Text = leaveData.CL_Comment;
                    } else {
                        lbCLCom.Text = "-";
                    }
                    if (leaveData.CL_Date.HasValue) {
                        lbCLDate.Text = leaveData.CL_Date.Value.ToLongDateString();
                    } else {
                        lbCLDate.Text = "-";
                    }
                }

                lbCHName.Text = leaveData.CH_Title + leaveData.CH_FirstName + " " + leaveData.CH_LastName;
                lbCHPos.Text = leaveData.CH_Position;
                if (leaveData.CH_Comment != "") {
                    lbCHCom.Text = leaveData.CH_Comment;
                } else {
                    lbCHCom.Text = "-";
                }
                if (leaveData.CH_Date.HasValue) {
                    lbCHDate.Text = leaveData.CH_Date.Value.ToLongDateString();
                    lbCHAllow.Text = leaveData.CH_Allow == 1 ? "อนุมัติ" : "ไม่อนุมัติ";
                } else {
                    lbCHDate.Text = "-";
                    lbCHAllow.Text = "-";
                }

                if (leaveData.DocterCertificationFileName != "") {
                    string loc = "Upload/DrCer/" + leaveData.DocterCertificationFileName;
                    div_dr_cer.InnerHtml += "<a href='" + loc + "'><img src='" + loc + "' /></a>";
                }

                if (leaveData.LeaveStatusID >= 1 && leaveData.LeaveStatusID <= 4) {

                } else if (leaveData.LeaveStatusID >= 5 && leaveData.LeaveStatusID <= 8) {
                    lbCancelReason.Text = leaveData.CancelReason;
                    if (leaveData.CL_CancelDate.HasValue) {
                        lbCL_C_Com.Text = leaveData.CL_CancelComment;
                        lbCL_C_Date.Text = leaveData.CL_CancelDate.Value.ToLongDateString();
                    } else {
                        lbCL_C_Com.Text = "-";
                        lbCL_C_Date.Text = "-";
                    }
                    if (leaveData.CH_CancelDate.HasValue) {
                        lbCH_C_Com.Text = leaveData.CH_CancelComment;
                        lbCH_C_Date.Text = leaveData.CH_CancelDate.Value.ToLongDateString();
                        lbCH_C_Allow.Text = leaveData.CH_CancelAllow == 1 ? "อนุมัติ" : "ไม่อนุมัติ";
                    } else {
                        lbCH_C_Com.Text = "-";
                        lbCH_C_Date.Text = "-";
                        lbCH_C_Allow.Text = "-";
                    }

                }

                string _psCLImage = DatabaseManager.GetPersonImageFileName(leaveData.CL_ID);
                string _psCHImage = DatabaseManager.GetPersonImageFileName(leaveData.CH_ID);
                if (_psCLImage != "") {
                    psCLImage.Src = "Upload/PersonImage/" + _psCLImage;
                }
                if (_psCHImage != "") {
                    psCHImage.Src = "Upload/PersonImage/" + _psCHImage;
                }*/
            }
        }
        private void FuncGVFinish()
        {
            OracleConnection.ClearAllPools();
            SqlDataSource sds = DatabaseManager.CreateSQLDataSource("SELECT LEAVE_ID รหัสการลา, (SELECT LEAVE_TYPE_NAME FROM LEV_TYPE WHERE LEV_TYPE.LEAVE_TYPE_ID = LEV_DATA.LEAVE_TYPE_ID) ประเภทการลา, REQ_DATE วันที่ข้อมูล, FROM_DATE จากวันที่, TO_DATE ถึงวันที่, TOTAL_DAY รวมวัน, (SELECT LEAVE_STATUS_NAME FROM LEV_STATUS WHERE LEV_STATUS.LEAVE_STATUS_ID = LEV_DATA.LEAVE_STATUS_ID) สถานะ, NVL(V_ALLOW,0) ผลการอนุมัติ FROM LEV_DATA WHERE LEAVE_STATUS_ID in(2,5) AND PS_ID = '" + loginPerson.CitizenID + "' ORDER BY LEAVE_ID DESC");
            gvFinish.DataSource = sds;
            gvFinish.DataBind();

            if (gvFinish.Rows.Count > 0) {
                lbFinish.Visible = false;
                TableHeaderCell headerCell = new TableHeaderCell();
                headerCell.Text = "ตกลง";
                gvFinish.HeaderRow.Cells.Add(headerCell);

                gvFinish.HeaderRow.Cells[0].Text = "<img src='Image/Small/ID.png' class='icon_left'/>" + gvFinish.HeaderRow.Cells[0].Text;
                gvFinish.HeaderRow.Cells[1].Text = "<img src='Image/Small/list.png' class='icon_left'/>" + gvFinish.HeaderRow.Cells[1].Text;
                gvFinish.HeaderRow.Cells[2].Text = "<img src='Image/Small/calendar.png' class='icon_left'/>" + gvFinish.HeaderRow.Cells[2].Text;
                gvFinish.HeaderRow.Cells[3].Text = "<img src='Image/Small/calendar.png' class='icon_left'/>" + gvFinish.HeaderRow.Cells[3].Text;
                gvFinish.HeaderRow.Cells[4].Text = "<img src='Image/Small/calendar.png' class='icon_left'/>" + gvFinish.HeaderRow.Cells[4].Text;
                gvFinish.HeaderRow.Cells[6].Text = "<img src='Image/Small/question.png' class='icon_left'/>" + gvFinish.HeaderRow.Cells[6].Text;
                gvFinish.HeaderRow.Cells[7].Text = "<img src='Image/Small/correct.png' class='icon_left'/>" + gvFinish.HeaderRow.Cells[7].Text;

                for (int i = 0; i < gvFinish.Rows.Count; ++i) {
                    string ID = gvFinish.Rows[i].Cells[0].Text;
                    TableCell cell = new TableCell();
                    LinkButton btn = new LinkButton();
                    btn.CssClass = "ps-button-img";
                    btn.Text = "ตกลง";
                    btn.Click += (e2, e3) => {
                        LeaveData leaveData = new LeaveData();
                        leaveData.Load(int.Parse(ID));

                        if (leaveData.LeaveStatusID == 2) {
                            DatabaseManager.ExecuteNonQuery("UPDATE LEV_DATA SET LEAVE_STATUS_ID = 3 WHERE LEAVE_ID = " + ID);
                        } else if (leaveData.LeaveStatusID == 5) {
                            DatabaseManager.ExecuteNonQuery("UPDATE LEV_DATA SET LEAVE_STATUS_ID = 6 WHERE LEAVE_ID = " + ID);
                        }
                        Response.Redirect("LeaveHistory.aspx");
                    };
                    cell.Controls.Add(btn);
                    gvFinish.Rows[i].Cells.Add(cell);

                    if (Util.StringEqual(gvFinish.Rows[i].Cells[7].Text, new string[] { "2" })) {
                        gvFinish.Rows[i].Cells[7].Text = "ไม่อนุญาต";
                        gvFinish.Rows[i].Cells[7].ForeColor = System.Drawing.Color.Red;
                    }
                    if (Util.StringEqual(gvFinish.Rows[i].Cells[7].Text, new string[] { "1" })) {
                        gvFinish.Rows[i].Cells[7].Text = "อนุญาต";
                        gvFinish.Rows[i].Cells[7].ForeColor = System.Drawing.Color.Green;
                    }
                }

                Util.NormalizeGridViewDate(gvFinish, 2);
                Util.NormalizeGridViewDate(gvFinish, 3);
                Util.NormalizeGridViewDate(gvFinish, 4);
            } else {
                lbFinish.Visible = true;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            PersonnelSystem ps = PersonnelSystem.GetPersonnelSystem(this);
            Person loginPerson = ps.LoginPerson;

            int count = 0;// DatabaseManager.GetLeaveRequiredCountByCommanderLow(loginPerson.CitizenID); ;
            /*using (OleDbConnection con = new OleDbConnection(DatabaseManager.CONNECTION_STRING)) {
                con.Open();
                using (OleDbCommand com = new OleDbCommand("SELECT COUNT(LEV_MAIN.LEAVE_ID) FROM LEV_MAIN, LEV_FORM1 WHERE LEV_MAIN.LEAVE_ID = LEV_FORM1.LEAVE_ID AND CMD_LOW_ID = '" + loginPerson.CitizenID + "' AND LEAVE_STATE = 1", con)) {
                    using (OleDbDataReader reader = com.ExecuteReader()) {
                        while (reader.Read()) {
                            count = int.Parse(reader.GetValue(0).ToString());
                        }
                    }
                }
            }*/
            if (count == 0) {
                error_area.InnerHtml = "ไม่มีรายการที่ท่านต้องลงความเห็น";
            } else {
                error_area.InnerHtml = "กรุณาเลือกรายการที่ต้องการลงความเห็น";
            }
            //error_area.Attributes["class"] = "alert alert_info";
            error_area.Attributes["class"] = null;
            error_area.InnerHtml = "";

            if (count > 0) {

                SqlDataSource sds = DatabaseManager.CreateSQLDataSource("SELECT LEAVE_ID รหัสการลา, (SELECT PS_FN_TH || ' ' || PS_LN_TH FROM PS_PERSON WHERE PS_CITIZEN_ID = LEV_DATA.PS_ID) ชื่อผู้ลา, (SELECT LEAVE_TYPE_NAME FROM LEV_TYPE WHERE LEV_TYPE.LEAVE_TYPE_ID = LEV_DATA.LEAVE_TYPE_ID) ประเภทการลา, REQ_DATE วันที่ข้อมูล, (SELECT LEAVE_STATUS_NAME FROM LEV_STATUS WHERE LEAVE_STATUS_ID = LEV_DATA.LEAVE_STATUS_ID) สถานะ FROM LEV_DATA WHERE LEAVE_STATUS_ID in(1,5) AND CL_ID = '" + loginPerson.CitizenID + "'");
                GridView1.DataSource = sds;
                GridView1.DataBind();

                Util.NormalizeGridViewDate(GridView1, 3);

                TableHeaderCell newHeader = new TableHeaderCell();
                newHeader.Text = "เลือก";
                GridView1.HeaderRow.Cells.Add(newHeader);

                GridView1.HeaderRow.Cells[0].Text = "<img src='Image/Small/ID.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[0].Text;
                GridView1.HeaderRow.Cells[1].Text = "<img src='Image/Small/person2.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[1].Text;
                GridView1.HeaderRow.Cells[2].Text = "<img src='Image/Small/list.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[2].Text;
                GridView1.HeaderRow.Cells[3].Text = "<img src='Image/Small/calendar.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[3].Text;
                GridView1.HeaderRow.Cells[4].Text = "<img src='Image/Small/question.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[4].Text;
                GridView1.HeaderRow.Cells[5].Text = "<img src='Image/Small/pointer.png' class='icon_left'/>" + GridView1.HeaderRow.Cells[5].Text;

                for (int i=0; i<GridView1.Rows.Count; ++i) {

                    if(GridView1.Rows[i].Cells[4].Text == "1") {
                        GridView1.Rows[i].Cells[4].Text = "ขอลา";
                    }
                    if (GridView1.Rows[i].Cells[4].Text == "5") {
                        GridView1.Rows[i].Cells[4].Text = "ยกเลิกลา";
                    }

                    string id = GridView1.Rows[i].Cells[0].Text;

                    LinkButton lbu = new LinkButton();
                    lbu.Text = "<img src='Image/Small/next.png'></img>";
                    lbu.CssClass = "ps-button";
                    lbu.Click += (e2, e3) => {

                        LeaveData leaveData = new LeaveData();
                        leaveData.Load(int.Parse(id));
                        Session["LeaveData"] = leaveData;

                        trPSBirthDate.Visible = false;
                        trPSWorkInDate.Visible = false;
                        trWifeName.Visible = false;
                        trGBDate.Visible = false;
                        trOrdained.Visible = false;
                        trTempleName.Visible = false;
                        trTempleLocation.Visible = false;
                        trOrdainDate.Visible = false;
                        trHujed.Visible = false;
                        trReason.Visible = false;
                        trContact.Visible = false;
                        trPhone.Visible = false;
                        trRestSave.Visible = false;
                        trRestLeft.Visible = false;
                        trRestTotal.Visible = false;
                        trStatistic.Visible = false;
                        trOldComment.Visible = false;
                        trOldDate.Visible = false;
                        trCancelReason.Visible = false;

                        if (leaveData.LeaveTypeID == 1) {
                            trStatistic.Visible = true;
                            trReason.Visible = true;
                            trContact.Visible = true;
                            trPhone.Visible = true;
                        } else if (leaveData.LeaveTypeID == 2) {
                            trStatistic.Visible = true;
                            trReason.Visible = true;
                            trContact.Visible = true;
                            trPhone.Visible = true;
                        } else if (leaveData.LeaveTypeID == 3) {
                            trStatistic.Visible = true;
                            trReason.Visible = true;
                            trContact.Visible = true;
                            trPhone.Visible = true;
                        } else if (leaveData.LeaveTypeID == 4) {
                            trRestSave.Visible = true;
                            trRestLeft.Visible = true;
                            trRestTotal.Visible = true;
                            trContact.Visible = true;
                            trPhone.Visible = true;
                        } else if (leaveData.LeaveTypeID == 5) {
                            trWifeName.Visible = true;
                            trGBDate.Visible = true;
                            trContact.Visible = true;
                            trPhone.Visible = true;
                        } else if (leaveData.LeaveTypeID == 6) {
                            trPSBirthDate.Visible = true;
                            trPSWorkInDate.Visible = true;
                            trOrdained.Visible = true;
                            trTempleName.Visible = true;
                            trTempleLocation.Visible = true;
                            trOrdainDate.Visible = true;
                        } else if (leaveData.LeaveTypeID == 7) {
                            trPSBirthDate.Visible = true;
                            trPSWorkInDate.Visible = true;
                            trHujed.Visible = true;
                        }

                        if (leaveData.LeaveStatusID == 1) {

                        } else if (leaveData.LeaveStatusID == 5) {
                            trOldComment.Visible = true;
                            trOldDate.Visible = true;
                            trCancelReason.Visible = true;
                        }

                        lbLeaveID.Text = leaveData.LeaveID.ToString();
                        lbLeaveTypeName.Text = leaveData.LeaveTypeName;
                        lbReqDate.Text = leaveData.RequestDate.Value.ToLongDateString();
                       /* lbPSName.Text = leaveData.PS_Title + leaveData.PS_FirstName + " " + leaveData.PS_LastName;
                        lbPSPos.Text = leaveData.PS_Position;
                        lbPSAPos.Text = leaveData.PS_AdminPosition;
                        lbPSDept.Text = leaveData.PS_Department;

                        if (leaveData.PS_BirthDate.HasValue) {
                            lbPSBirthDate.Text = leaveData.PS_BirthDate.Value.ToLongDateString();
                        } else {
                            lbPSBirthDate.Text = "-";
                        }
                        if (leaveData.PS_WorkInDate.HasValue) {
                            lbPSWorkInDate.Text = leaveData.PS_WorkInDate.Value.ToLongDateString();
                        } else {
                            lbPSWorkInDate.Text = "-";
                        }*/

                        lbRestSave.Text = leaveData.RestSave + " วัน";
                        lbRestLeft.Text = leaveData.RestLeft + " วัน";
                        lbRestTotal.Text = leaveData.RestTotal + " วัน";

                        lbWifeName.Text = leaveData.WifeFirstName + " " + leaveData.WifeLastName;
                        if (leaveData.GiveBirthDate.HasValue) {
                            lbGBDate.Text = leaveData.GiveBirthDate.Value.ToLongDateString();
                        } else {
                            lbGBDate.Text = "-";
                        }

                        lbOrdained.Text = leaveData.Ordained == 1 ? "เคย" : "ไม่เคย";
                        lbTempleName.Text = leaveData.TempleName;
                        lbTempleLocation.Text = leaveData.TempleLocation;
                        if (leaveData.OrdainDate.HasValue) {
                            lbOrdainDate.Text = leaveData.OrdainDate.Value.ToLongDateString();
                        } else {
                            lbOrdainDate.Text = "-";
                        }

                        lbHujed.Text = leaveData.Hujed == 1 ? "เคย" : "ไม่เคย";

                        if (leaveData.FromDate.HasValue) {
                            lbFTTDate.Text = leaveData.FromDate.Value.ToLongDateString() + " ถึง " + leaveData.ToDate.Value.ToLongDateString() + " รวม " + leaveData.TotalDay + " วัน";
                        } else {
                            lbFTTDate.Text = "ไม่เคยลา";
                        }
                        lbStatistic.Text = "ลามาแล้ว " + leaveData.CountPast + " วัน / ลาครั้งนี้ " + leaveData.CountNow + " วัน / รวม " + leaveData.CountTotal + " วัน";

                        lbReason.Text = leaveData.Reason;
                        lbContact.Text = leaveData.Contact;
                        lbPhone.Text = leaveData.Telephone;

                        if (leaveData.LastFromDate.HasValue) {
                            lbLastFTTDate.Text = leaveData.LastFromDate.Value.ToLongDateString() + " ถึง " + leaveData.LastToDate.Value.ToLongDateString() + " รวม " + leaveData.LastTotalDay + " วัน";
                        } else {
                            lbLastFTTDate.Text = "ไม่เคยลา";
                        }

                       /* if(leaveData.LeaveStatusID >= 5 && leaveData.LeaveStatusID <= 8) {
                            lbOldComment.Text = leaveData.CL_Comment;
                            lbOldDate.Text = leaveData.CL_Date.Value.ToLongDateString();
                            lbCancelReason.Text = leaveData.CancelReason;
                        }*/

                        if (leaveData.DocterCertificationFileName != "") {
                            divDrCer.InnerHtml = "<a href='Upload/Drcer/" + leaveData.DocterCertificationFileName + "'><img src='Upload/DrCer/" + leaveData.DocterCertificationFileName + "' style='width: 200px;' /></a>";
                        }

                        MultiView1.ActiveViewIndex = 1;

                        error_area.Attributes["class"] = null;
                        error_area.InnerHtml = "";
                    };
                    TableCell cell = new TableCell();
                    cell.Controls.Add(lbu);
                    GridView1.Rows[i].Cells.Add(cell);
                }

            }
        }
Example #7
0
        protected void lbuS1Check_Click(object sender, EventArgs e)
        {
            ClearNotification();
            //PersonnelSystem ps = PersonnelSystem.GetPersonnelSystem(this);
            //Person loginPerson = ps.LoginPerson;

            trS2BirthDate.Visible = false;
            trS2WorkInDate.Visible = false;
            trS2WifeName.Visible = false;
            trS2GBDate.Visible = false;
            trS2Ordained.Visible = false;
            trS2TempleName.Visible = false;
            trS2TempleLocation.Visible = false;
            trS2OrdainDate.Visible = false;
            trS2Hujed.Visible = false;
            trS2Reason.Visible = false;
            trS2Contact.Visible = false;
            trS2Phone.Visible = false;
            trS2DrCer.Visible = false;
            trS2RestSave.Visible = false;
            trS2RestLeft.Visible = false;
            trS2RestTotal.Visible = false;

            if (hfLeaveTypeID.Value == "1") {
                trS2Reason.Visible = true;
                trS2Contact.Visible = true;
                trS2Phone.Visible = true;
                trS2DrCer.Visible = true;
            } else if (hfLeaveTypeID.Value == "2") {
                trS2Reason.Visible = true;
                trS2Contact.Visible = true;
                trS2Phone.Visible = true;
            } else if (hfLeaveTypeID.Value == "3") {
                trS2Reason.Visible = true;
                trS2Contact.Visible = true;
                trS2Phone.Visible = true;
            } else if (hfLeaveTypeID.Value == "4") {
                trS2RestSave.Visible = true;
                trS2RestLeft.Visible = true;
                trS2RestTotal.Visible = true;
                trS2Contact.Visible = true;
                trS2Phone.Visible = true;
            } else if (hfLeaveTypeID.Value == "5") {
                trS2WifeName.Visible = true;
                trS2GBDate.Visible = true;
                trS2Contact.Visible = true;
                trS2Phone.Visible = true;
            } else if (hfLeaveTypeID.Value == "6") {
                trS2BirthDate.Visible = true;
                trS2WorkInDate.Visible = true;
                trS2Ordained.Visible = true;
                trS2TempleName.Visible = true;
                trS2TempleLocation.Visible = true;
                trS2OrdainDate.Visible = true;
                trS2Phone.Visible = true;
            } else if (hfLeaveTypeID.Value == "7") {
                trS2BirthDate.Visible = true;
                trS2WorkInDate.Visible = true;
                trS2Hujed.Visible = true;
            }

            if(tbS1FromDate.Text == "" || tbS1ToDate.Text == "" || !Util.IsDateValid(tbS1FromDate.Text) || !Util.IsDateValid(tbS1ToDate.Text)) {
                ChangeNotification("danger", "กรุณากรอกวันที่ให้ถูกต้อง");
                return;
            } else {
                DateTime dtFromDate = Util.ToDateTimeOracle(tbS1FromDate.Text);
                DateTime dtToDate = Util.ToDateTimeOracle(tbS1ToDate.Text);
                int totalDay = (int)(dtToDate - dtFromDate).TotalDays + 1;
                int fromToNowtotalDay = (int)(dtFromDate - DateTime.Today).TotalDays;
                if (totalDay <= 0) {
                    ChangeNotification("danger", "วันที่ไม่ถูกต้อง");
                    return;
                }
                if ((DateTime.Today - dtFromDate).TotalDays >= 90) {
                    ChangeNotification("danger", "ไม่สามารถลาย้อนหลังมากกว่า 3 เดือน");
                    return;
                }
                if ((dtFromDate - DateTime.Today).TotalDays >= 90) {
                    ChangeNotification("danger", "ไม่สามารถลาล่วงหน้ามากกว่า 3 เดือน");
                    return;
                }
                if (dtFromDate.DayOfWeek == DayOfWeek.Saturday || dtFromDate.DayOfWeek == DayOfWeek.Sunday || dtToDate.DayOfWeek == DayOfWeek.Saturday || dtToDate.DayOfWeek == DayOfWeek.Sunday) {
                    ChangeNotification("danger", "ไม่สามารถเรื่มหรือจบการลาในวันเสาร์หรือาทิตย์ได้");
                    return;
                }
                int sick_now = -1;
                int sick_max = -1;
                int business_now = -1;
                int business_max = -1;
                int huj_now = -1;
                int huj_max = -1;
                int ordain_now = -1;
                int ordain_max = -1;
                {
                    OracleConnection.ClearAllPools();
                    using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) {
                        con.Open();
                        using (OracleCommand com = new OracleCommand("SELECT SICK_NOW, SICK_MAX, BUSINESS_NOW, BUSINESS_MAX, HUJ_NOW, HUJ_MAX, ORDAIN_NOW, ORDAIN_MAX FROM LEV_CLAIM WHERE YEAR = " + Util.BudgetYear() + " AND PS_CITIZEN_ID = '" + loginPerson.CitizenID + "'", con)) {
                            using (OracleDataReader reader = com.ExecuteReader()) {
                                while (reader.Read()) {
                                    sick_now = reader.GetInt32(0);
                                    sick_max = reader.GetInt32(1);
                                    business_now = reader.GetInt32(2);
                                    business_max = reader.GetInt32(3);
                                    huj_now = reader.GetInt32(4);
                                    huj_max = reader.GetInt32(5);
                                    ordain_now = reader.GetInt32(6);
                                    ordain_max = reader.GetInt32(7);
                                }
                            }
                        }

                    }
                }
                if(hfLeaveTypeID.Value == "1") {
                    if(sick_now + totalDay > sick_max) {
                        ChangeNotification("danger", "ไม่สามารถลาป่วยได้มากกว่า " + sick_max + " วัน คุณลาไปแล้ว " + sick_now + " วัน ครั้งนี้ " + totalDay + " วัน รวม " + (sick_now + totalDay) + " วัน");
                        return;
                    }
                }
                if (hfLeaveTypeID.Value == "2") {
                    if (fromToNowtotalDay < businessBeforeDay) {
                        ChangeNotification("danger", "ต้องลาล่วงหน้ามากกว่า " + businessBeforeDay + " วัน");
                        return;
                    } else if (business_now + totalDay > business_max) {
                        ChangeNotification("danger", "ไม่สามารถลากิจได้มากกว่า " + business_max + " วัน คุณลาไปแล้ว " + business_now + " วัน ครั้งนี้ " + totalDay + " วัน รวม " + (business_now + totalDay) + " วัน");
                        return;
                    }
                }
                if (hfLeaveTypeID.Value == "3") {
                    DateTime dt1 = DateTime.Today.AddDays(-giveBirthAfterDay);
                    if ((dtFromDate - dt1).TotalDays < 0) {
                        ChangeNotification("danger", "ไม่สามารถลาย้อนหลังได้มากกว่า " + giveBirthAfterDay + " วัน");
                        return;
                    }
                }
                if (hfLeaveTypeID.Value == "4") {
                    if (fromToNowtotalDay < restBeforeDay) {
                        ChangeNotification("danger", "ต้องลาล่วงหน้ามากกว่า " + restBeforeDay + " วัน");
                        return;
                    }
                }
                if (hfLeaveTypeID.Value == "5") {
                    DateTime dt1 = DateTime.Today.AddDays(-helpGiveBirthAfterDay);
                    if ((dtFromDate - dt1).TotalDays < 0) {
                        ChangeNotification("danger", "ไม่สามารถลาย้อนหลังได้มากกว่า " + helpGiveBirthAfterDay + " วัน");
                        return;
                    }
                }
                if (hfLeaveTypeID.Value == "6") {
                    if (fromToNowtotalDay < ordainBeforeDay) {
                        ChangeNotification("danger", "ต้องลาล่วงหน้ามากกว่า " + ordainBeforeDay + " วัน");
                        return;
                    } else if (huj_now + totalDay > huj_max) {
                        ChangeNotification("danger", "ไม่สามารถลาไปอุปสมบทได้มากกว่า " + ordain_max + " วัน คุณลาไปแล้ว " + ordain_now + " วัน ครั้งนี้ " + totalDay + " วัน รวม " + (ordain_now + totalDay) + " วัน");
                        return;
                    }
                }
                if (hfLeaveTypeID.Value == "7") {
                    if(fromToNowtotalDay < hujBeforeDay) {
                        ChangeNotification("danger", "ต้องลาล่วงหน้ามากกว่า " + hujBeforeDay + " วัน");
                        return;
                    }
                    else if (huj_now + totalDay > huj_max) {
                        ChangeNotification("danger", "ไม่สามารถลาไปประกอบพิธีฮัจญ์ได้มากกว่า " + huj_max + " วัน คุณลาไปแล้ว " + huj_now + " วัน ครั้งนี้ " + totalDay + " วัน รวม " + (huj_now + totalDay) + " วัน");
                        return;
                    }
                }

                {

                    OracleConnection.ClearAllPools();
                    using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) {
                        con.Open();
                        using (OracleCommand com = new OracleCommand("SELECT LEAVE_ID FROM LEV_DATA WHERE " + Util.DatabaseToDateSearch(tbS1FromDate.Text) + " <= TO_DATE AND " + Util.DatabaseToDateSearch(tbS1ToDate.Text) + " >= FROM_DATE AND PS_ID = '" + loginPerson.CitizenID + "' AND BUDGET_YEAR = " + Util.BudgetYear() + " AND LEAVE_STATUS_ID IN(3,4) AND V_ALLOW = 1", con)) {
                            using (OracleDataReader reader = com.ExecuteReader()) {
                                while (reader.Read()) {
                                    LeaveData leaveData = new LeaveData();
                                    leaveData.Load(reader.GetInt32(0));
                                    ChangeNotification("danger", "ไม่สามารถลาได้ พบวันลาซ้อนทับกัน (รหัสการลา " + leaveData.LeaveID + ", " + leaveData.FromDate.Value.ToLongDateString() + " ถึง " + leaveData.ToDate.Value.ToLongDateString() + ")");
                                    return;
                                }
                            }
                        }
                        using (OracleCommand com = new OracleCommand("SELECT TO_DATE FROM LEV_DATA WHERE PS_ID = '" + loginPerson.CitizenID + "' AND LEAVE_TYPE_ID = " + hfLeaveTypeID.Value + " AND EXTRACT(YEAR FROM FROM_DATE) = " + Util.BudgetYear() + " AND LEAVE_STATUS_ID IN(3,4) AND V_ALLOW = 1 ORDER BY LEAVE_ID DESC", con)) {
                            using (OracleDataReader reader = com.ExecuteReader()) {
                                if (reader.Read()) {
                                    DateTime dtLastToDate = reader.GetDateTime(0);
                                    if((dtFromDate - dtLastToDate).TotalDays <= 0) {
                                        ChangeNotification("danger", "ไม่สามารถลาก่อนวันที่ลาล่าสุดได้ (" + dtLastToDate.ToLongDateString() + ")");
                                        return;
                                    }
                                }
                            }
                        }

                    }
                }

            }

            if(hfLeaveTypeID.Value == "1" || hfLeaveTypeID.Value == "2" || hfLeaveTypeID.Value == "3") {
                if(tbS1FromDate.Text == "" || tbS1ToDate.Text == "" || !Util.IsDateValid(tbS1FromDate.Text) || !Util.IsDateValid(tbS1ToDate.Text)) {
                    ChangeNotification("danger", "วันที่ไม่ถูกต้อง");
                    return;
                }
                if(tbS1Reason.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกเหตุผล");
                    return;
                }
                if (tbS1Contact.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกติดต่อได้ที่");
                    return;
                }
                if (tbS1Phone.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกเบอร์โทรศัพท์");
                    return;
                }
                if(hfLeaveTypeID.Value == "1") {
                    DateTime dtFromDate = Util.ToDateTimeOracle(tbS1FromDate.Text);
                    DateTime dtToDate = Util.ToDateTimeOracle(tbS1ToDate.Text);
                    int totalDay = (int)(dtToDate - dtFromDate).TotalDays + 1;
                    if (totalDay >= 30 && !FileUpload1.HasFile) {
                        ChangeNotification("danger", "คุณต้องมีใบรับรองแพทย์เมื่อทำการลาเกิน 30 วัน ลาครั้งนี้ " + totalDay + " วัน");
                        return;
                    }
                }
            }
            if (hfLeaveTypeID.Value == "4") {
                if (tbS1FromDate.Text == "" || tbS1ToDate.Text == "" || !Util.IsDateValid(tbS1FromDate.Text) || !Util.IsDateValid(tbS1ToDate.Text)) {
                    ChangeNotification("danger", "วันที่ไม่ถูกต้อง");
                    return;
                }
                if (tbS1Contact.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกติดต่อได้ที่");
                    return;
                }
                if (tbS1Phone.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกเบอร์โทรศัพท์");
                    return;
                }
                DateTime dtFromDate = Util.ToDateTimeOracle(tbS1FromDate.Text);
                DateTime dtToDate = Util.ToDateTimeOracle(tbS1ToDate.Text);
                int totalDay = (int)(dtToDate - dtFromDate).TotalDays + 1;
                int max = DatabaseManager.ExecuteInt("SELECT REST_MAX FROM LEV_CLAIM WHERE PS_CITIZEN_ID = '" + loginPerson.CitizenID + "' AND YEAR = " + Util.BudgetYear());
                int now = DatabaseManager.ExecuteInt("SELECT REST_NOW FROM LEV_CLAIM WHERE PS_CITIZEN_ID = '" + loginPerson.CitizenID + "' AND YEAR = " + Util.BudgetYear());
                if (now + totalDay > max) {
                    ChangeNotification("danger", "ปีนี้คุณไม่สามารถลาพักผ่อนเกิน " + max + " วันได้ ลาไปแล้ว " + now + " วัน ครั้งนี้ " + totalDay + " วัน รวม " + (totalDay + now) + " วัน");
                    return;
                }
            }
            if (hfLeaveTypeID.Value == "5") {
                if (tbS1WifeFirstName.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกชื่อจริงภริยา");
                    return;
                }
                if (tbS1WifeLastName.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกนามสกุลภริยา");
                    return;
                }
                if (tbS1GBDate.Text == "" || !Util.IsDateValid(tbS1GBDate.Text)) {
                    ChangeNotification("danger", "วันที่คลอดบุตรไม่ถูกต้อง");
                    return;
                }
                if (tbS1FromDate.Text == "" || tbS1ToDate.Text == "" || !Util.IsDateValid(tbS1FromDate.Text) || !Util.IsDateValid(tbS1ToDate.Text)) {
                    ChangeNotification("danger", "วันที่ไม่ถูกต้อง");
                    return;
                }
                if (tbS1Contact.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกติดต่อได้ที่");
                    return;
                }
                if (tbS1Phone.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกเบอร์โทรศัพท์");
                    return;
                }
            }
            if (hfLeaveTypeID.Value == "6") {
                if (!rbS1OrdainedT.Checked && !rbS1OrdainedF.Checked) {
                    ChangeNotification("danger", "กรุณาเลือกการอุปสมบท");
                    return;
                }
                if (tbS1TempleName.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกชื่อวัด");
                    return;
                }
                if (tbS1TempleLocation.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกสถานที่");
                    return;
                }
                if (tbS1OrdainDate.Text == "" || !Util.IsDateValid(tbS1OrdainDate.Text)) {
                    ChangeNotification("danger", "วันที่อุปสมบทไม่ถูกต้อง");
                    return;
                }
                if (tbS1FromDate.Text == "" || tbS1ToDate.Text == "" || !Util.IsDateValid(tbS1FromDate.Text) || !Util.IsDateValid(tbS1ToDate.Text)) {
                    ChangeNotification("danger", "วันที่ไม่ถูกต้อง");
                    return;
                }
                if (tbS1Phone.Text == "") {
                    ChangeNotification("danger", "กรุณากรอกเบอร์โทรศัพท์");
                    return;
                }
            }
            if (hfLeaveTypeID.Value == "7") {
                if (!rbS1HujedT.Checked && !rbS1HujedF.Checked) {
                    ChangeNotification("danger", "กรุณาเลือกการไปประกอบพิธีฮัจย์");
                    return;
                }
                if (tbS1FromDate.Text == "" || tbS1ToDate.Text == "" || !Util.IsDateValid(tbS1FromDate.Text) || !Util.IsDateValid(tbS1ToDate.Text)) {
                    ChangeNotification("danger", "วันที่ไม่ถูกต้อง");
                    return;
                }
            }

            {

                MV1.ActiveViewIndex = 2;

                Session["LeaveSickFileUpload"] = FileUpload1;

                divReq.Visible = false;
                //ChangeNotification("info", "กรุณายืนยันข้อมูลอีกครั้ง");

                string leavedDate = "ไม่เคยลา";
                DateTime? lastFromDate = null;
                DateTime? lastToDate = null;
                int lastTotalDay = 0;

                int pastTotalDay = DatabaseManager.ExecuteInt("SELECT NVL(SUM(TOTAL_DAY),0) FROM LEV_DATA WHERE PS_ID = '" + loginPerson.CitizenID + "' AND LEAVE_TYPE_ID = " + hfLeaveTypeID.Value + " AND EXTRACT(YEAR FROM FROM_DATE) = " + Util.BudgetYear() + " AND V_ALLOW = 1");

                OracleConnection.ClearAllPools();
                using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) {
                    con.Open();
                    using (OracleCommand com = new OracleCommand("SELECT FROM_DATE, TO_DATE, TOTAL_DAY FROM LEV_DATA WHERE PS_ID = '" + loginPerson.CitizenID + "' AND LEAVE_TYPE_ID = " + hfLeaveTypeID.Value + " AND EXTRACT(YEAR FROM FROM_DATE) = " + Util.BudgetYear() + " AND V_ALLOW = 1 ORDER BY LEAVE_ID DESC", con)) {
                        using (OracleDataReader reader = com.ExecuteReader()) {
                            if (reader.Read()) {
                                lastFromDate = reader.GetDateTime(0);
                                lastToDate = reader.GetDateTime(1);
                                lastTotalDay = (int)(lastToDate.Value - lastFromDate.Value).TotalDays + 1;
                                leavedDate = lastFromDate.Value.ToLongDateString() + " ถึง " + lastToDate.Value.ToLongDateString() + " รวม " + lastTotalDay + " วัน ";
                            } else {
                                lastTotalDay = 0;
                            }
                        }
                    }

                }

                int restSave = -1;
                int restLeft = -1;
                int restTotal = -1;
                OracleConnection.ClearAllPools();
                using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) {
                    con.Open();
                    using (OracleCommand com = new OracleCommand("SELECT REST_SAVE, REST_THIS FROM LEV_CLAIM WHERE PS_CITIZEN_ID = '" + loginPerson.CitizenID + "' AND YEAR = " + Util.BudgetYear(), con)) {
                        using (OracleDataReader reader = com.ExecuteReader()) {
                            if (reader.Read()) {
                                restSave = reader.GetInt32(0);
                                restLeft = reader.GetInt32(1);
                                restTotal = restSave + restLeft;
                            }
                        }
                    }

                }

                lbS2PSName.Text = loginPerson.FullName;
                lbS2PSPos.Text = loginPerson.PositionWorkName;
                lbS2PSAPos.Text = loginPerson.AdminPositionName;
                lbS2PSDept.Text = loginPerson.DivisionName;
                lbS2PSBirthDate.Text = loginPerson.BirthDate.Value.ToLongDateString();
                lbS2PSWorkInDate.Text = loginPerson.InWorkDate.Value.ToLongDateString();
                lbS2RestSave.Text = restSave + " วัน";
                lbS2RestLeft.Text = restLeft + " วัน";
                lbS2RestTotal.Text = restTotal + " วัน";
                lbS2WifeName.Text = tbS1WifeFirstName.Text + " " + tbS1WifeLastName.Text;
                lbS2GBDate.Text = tbS1GBDate.Text;
                lbS2Ordained.Text = rbS1OrdainedT.Checked ? "เคย" : "ไม่เคย";
                lbS2TempleName.Text = tbS1TempleName.Text;
                lbS2TempleLocation.Text = tbS1TempleLocation.Text;
                lbS2OrdainDate.Text = tbS1OrdainDate.Text;
                lbS2Hujed.Text = rbS1HujedT.Checked ? "เคย" : "ไม่เคย";
                lbS2LastFTTDate.Text = leavedDate;
                lbS2LeaveTypeName.Text = hfLeaveTypeName.Value;
                DateTime dtFromDate = Util.ToDateTimeOracle(tbS1FromDate.Text);
                DateTime dtToDate = Util.ToDateTimeOracle(tbS1ToDate.Text);
                int totalDay = (int)(dtToDate - dtFromDate).TotalDays + 1;
                lbS2FTTDate.Text = dtFromDate.ToLongDateString() + " ถึง " + dtToDate.ToLongDateString() + " รวม " + totalDay + " วัน";
                lbS2Statistic.Text = "ลามาแล้ว " + pastTotalDay + " วัน / ลาครั้งนี้ " + totalDay + " วัน / รวม " + (pastTotalDay + totalDay) + " วัน";
                lbS2Reason.Text = tbS1Reason.Text;
                lbS2Contact.Text = tbS1Contact.Text;
                lbS2Phone.Text = tbS1Phone.Text;
                string drCer;
                if (FileUpload1.HasFile) {
                    lbS2DrCer.Text = "มี";
                    FileInfo fi = new FileInfo(FileUpload1.FileName);
                    drCer = Util.RandomFileName() + fi.Extension;
                } else {
                    lbS2DrCer.Text = "ไม่มี";
                    drCer = "";
                }

                //----------CL CH--

                //string psCLID = "";
                //string psCHID = "";
                List<Person> psBossID = new List<Person>();

                /*int อธิการบดีลาป่วยวัน = -1;
                int อธิการบดีลากิจวัน = -1;
                bool อธิการบดีลาคลอดบุตร = false;
                bool อธิการบดีลาช่วยเหลือภริยาคลอดบุตร = false;
                bool อธิการบดีลาพักผ่อน = false;
                bool อธิการบดีลาอุปสมบทฮัจญ์ = false;

                int คณะบดีลาป่วยวัน = -1;
                int คณะบดีลากิจวัน = -1;
                bool คณะบดีลาคลอดบุตร = false;
                bool คณะบดีลาช่วยเหลือภริยาคลอดบุตร = false;
                bool คณะบดีลาพักผ่อน = false;
                bool คณะบดีลาอุปสมบทฮัจญ์ = false;

                int หัวหน้าภาควิชาลาป่วยวัน = -1;
                int หัวหน้าภาควิชาลากิจวัน = -1;
                bool หัวหน้าภาควิชาลาคลอดบุตร = false;
                bool หัวหน้าภาควิชาลาช่วยเหลือภริยาคลอดบุตร = false;
                bool หัวหน้าภาควิชาลาพักผ่อน = false;
                bool หัวหน้าภาควิชาลาอุปสมบทฮัจญ์ = false;

                int หัวหน้าฝ่ายลาป่วยวัน = -1;
                int หัวหน้าฝ่ายลากิจวัน = -1;
                bool หัวหน้าฝ่ายลาคลอดบุตร = false;
                bool หัวหน้าฝ่ายลาช่วยเหลือภริยาคลอดบุตร = false;
                bool หัวหน้าฝ่ายลาพักผ่อน = false;
                bool หัวหน้าฝ่ายลาอุปสมบทฮัจญ์ = false;

                OracleConnection.ClearAllPools();
                using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) {
                    con.Open();
                    using (OracleCommand com = new OracleCommand("SELECT * FROM LEV_PERMISSION", con)) {
                        using (OracleDataReader reader = com.ExecuteReader()) {
                            while (reader.Read()) {
                                int APOWER = reader.GetInt32(1);
                                if (APOWER == 1) {
                                    อธิการบดีลาป่วยวัน = reader.GetInt32(2);
                                    อธิการบดีลากิจวัน = reader.GetInt32(3);
                                    อธิการบดีลาคลอดบุตร = Convert.ToBoolean(reader.GetInt32(4));
                                    อธิการบดีลาช่วยเหลือภริยาคลอดบุตร = Convert.ToBoolean(reader.GetInt32(5));
                                    อธิการบดีลาพักผ่อน = Convert.ToBoolean(reader.GetInt32(6));
                                    อธิการบดีลาอุปสมบทฮัจญ์ = Convert.ToBoolean(reader.GetInt32(7));
                                } else if (APOWER == 2) {
                                    คณะบดีลาป่วยวัน = reader.GetInt32(2);
                                    คณะบดีลากิจวัน = reader.GetInt32(3);
                                    คณะบดีลาคลอดบุตร = Convert.ToBoolean(reader.GetInt32(4));
                                    คณะบดีลาช่วยเหลือภริยาคลอดบุตร = Convert.ToBoolean(reader.GetInt32(5));
                                    คณะบดีลาพักผ่อน = Convert.ToBoolean(reader.GetInt32(6));
                                    คณะบดีลาอุปสมบทฮัจญ์ = Convert.ToBoolean(reader.GetInt32(7));
                                } else if (APOWER == 3) {
                                    หัวหน้าภาควิชาลาป่วยวัน = reader.GetInt32(2);
                                    หัวหน้าภาควิชาลากิจวัน = reader.GetInt32(3);
                                    หัวหน้าภาควิชาลาคลอดบุตร = Convert.ToBoolean(reader.GetInt32(4));
                                    หัวหน้าภาควิชาลาช่วยเหลือภริยาคลอดบุตร = Convert.ToBoolean(reader.GetInt32(5));
                                    หัวหน้าภาควิชาลาพักผ่อน = Convert.ToBoolean(reader.GetInt32(6));
                                    หัวหน้าภาควิชาลาอุปสมบทฮัจญ์ = Convert.ToBoolean(reader.GetInt32(7));
                                } else if (APOWER == 4) {
                                    หัวหน้าฝ่ายลาป่วยวัน = reader.GetInt32(2);
                                    หัวหน้าฝ่ายลากิจวัน = reader.GetInt32(3);
                                    หัวหน้าฝ่ายลาคลอดบุตร = Convert.ToBoolean(reader.GetInt32(4));
                                    หัวหน้าฝ่ายลาช่วยเหลือภริยาคลอดบุตร = Convert.ToBoolean(reader.GetInt32(5));
                                    หัวหน้าฝ่ายลาพักผ่อน = Convert.ToBoolean(reader.GetInt32(6));
                                    หัวหน้าฝ่ายลาอุปสมบทฮัจญ์ = Convert.ToBoolean(reader.GetInt32(7));
                                }
                            }
                        }
                    }

                }*/

                using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) {
                    con.Open();

                    List<Person> tempBossID = DatabaseManager.รหัสหัวหน้า(loginPerson.CitizenID);
                    for (int i = 0; i < tempBossID.Count; i++) {
                        int dayReq = 1;
                        bool ableAllow = false;
                        using (OracleCommand com = new OracleCommand("SELECT * FROM LEV_PERMISSION WHERE ADMIN_POSITION_POWER = " + tempBossID[i].AdminPositionPower + " ORDER BY LEAVE_PERMISSION_ID DESC", con)) {
                            using (OracleDataReader reader = com.ExecuteReader()) {
                                while (reader.Read()) {
                                    if (hfLeaveTypeID.Value == "1") {
                                        dayReq = reader.GetInt32(2);
                                    } else if (hfLeaveTypeID.Value == "2") {
                                        dayReq = reader.GetInt32(3);
                                    } else if (hfLeaveTypeID.Value == "3") {
                                        ableAllow = reader.GetInt32(4) == 1 ? true : false;
                                    } else if (hfLeaveTypeID.Value == "4") {
                                        ableAllow = reader.GetInt32(6) == 1 ? true : false;
                                    } else if (hfLeaveTypeID.Value == "5") {
                                        ableAllow = reader.GetInt32(5) == 1 ? true : false;
                                    } else if (hfLeaveTypeID.Value == "6") {
                                        ableAllow = reader.GetInt32(7) == 1 ? true : false;
                                    } else if (hfLeaveTypeID.Value == "7") {
                                        ableAllow = reader.GetInt32(7) == 1 ? true : false;
                                    }

                                }
                            }
                        }

                        if(hfLeaveTypeID.Value == "1" || hfLeaveTypeID.Value == "2") {
                            if (dayReq >= totalDay) {
                                psBossID.Add(tempBossID[i]);
                                break;
                            } else {
                                psBossID.Add(tempBossID[i]);
                            }
                        } else {
                            if(ableAllow) {
                                psBossID.Add(tempBossID[i]);
                                break;
                            } else {
                                psBossID.Add(tempBossID[i]);
                            }
                        }

                    }

                }

                {
                    TableRow row = new TableRow();
                    TableCell cell2;
                    System.Web.UI.WebControls.Image image;
                    tbBoss.Rows.Add(row);

                    for (int j = 0; j < psBossID.Count; j++) {

                        cell2 = new TableCell();
                        cell2.Style.Add("vertical-align", "top");

                        Table tb = new Table();
                        tb.CssClass = "ps-table-1";
                        tb.Style.Add("text-align", "left");
                        {
                            TableRow tr;
                            TableCell cell3;

                            tr = new TableRow();
                            tb.Rows.Add(tr);

                            cell3 = new TableCell();
                            cell3.ColumnSpan = 2;
                            cell3.Style.Add("text-align", "center");
                            image = new System.Web.UI.WebControls.Image();
                            image.CssClass = "ps-ms-main-drop-profile-pic";

                            string imagePath = DatabaseManager.GetPersonImageFileName(psBossID[j].CitizenID);
                            if (imagePath != "") {
                                image.Attributes["src"] = "Upload/PersonImage/" + imagePath;
                                cell3.Controls.Add(image);
                            }
                            tr.Cells.Add(cell3);

                            tr = new TableRow();
                            tb.Rows.Add(tr);

                            cell3 = new TableCell();
                            cell3.Text = "ชื่อ";
                            tr.Cells.Add(cell3);

                            cell3 = new TableCell();
                            cell3.Text = psBossID[j].FirstNameAndLastName;
                            tr.Cells.Add(cell3);

                            tr = new TableRow();
                            tb.Rows.Add(tr);

                            cell3 = new TableCell();
                            cell3.Text = "ตำแหน่ง";
                            tr.Cells.Add(cell3);

                            cell3 = new TableCell();
                            cell3.Text = psBossID[j].PositionWorkName;
                            tr.Cells.Add(cell3);

                            tr = new TableRow();
                            tb.Rows.Add(tr);

                            cell3 = new TableCell();
                            cell3.Text = "ระดับ";
                            tr.Cells.Add(cell3);

                            cell3 = new TableCell();
                            cell3.Text = psBossID[j].AdminPositionName + "<br />" + psBossID[j].AdminPositionNameExtra();
                            tr.Cells.Add(cell3);

                        }

                        cell2.Controls.Add(tb);

                        row.Cells.Add(cell2);
                    }
                }
                /*{
                    TableRow row = new TableRow();
                    TableCell cell;
                    System.Web.UI.WebControls.Image image;
                    tbBoss.Rows.Add(row);

                    for (int i = 0; i < psBossID.Count; i++) {

                        cell = new TableCell();
                        image = new System.Web.UI.WebControls.Image();
                        image.CssClass = "ps-ms-main-drop-profile-pic";

                        string imagePath = DatabaseManager.GetPersonImageFileName(psBossID[i].CitizenID);
                        if (imagePath != "") {
                            image.Attributes["src"] = "Upload/PersonImage/" + imagePath;
                            cell.Controls.Add(image);
                        }

                        Panel p2 = new Panel();
                        Label lb = new Label();
                        lb.Text = "<span class='ps-lb-red-b'>" + psBossID[i].FirstNameAndLastName + "</span><br /><span style='color: #808080;'>" + psBossID[i].CitizenID + "</span><br />" + psBossID[i].PositionWorkName + "<br />" + psBossID[i].AdminPositionName + "<br />" + psBossID[i].AdminPositionNameExtra();
                        p2.Controls.Add(lb);
                        cell.Controls.Add(p2);

                        row.Cells.Add(cell);
                    }
                }*/

                /*if(hfLeaveTypeID.Value == "1") {
                    if(totalDay <= หัวหน้าฝ่ายลาป่วยวัน) {
                        if(loginPerson.AdminPositionPower == "0") { //ไม่มี
                            if(loginPerson.IsTeacher()) {
                                psBossID.Add(DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID));
                            } else if(loginPerson.WorkDivisionID != null) {
                                psBossID.Add(DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.DivisionID));
                            } else {
                                psBossID.Add(DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID));
                            }

                        } else if (loginPerson.AdminPositionPower == "1") { //หัวหน้าฝ่าย

                            if (loginPerson.IsTeacher()) {
                                psBossID.Add(DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID));
                            } else if (loginPerson.WorkDivisionID != null) {
                                psBossID.Add(DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.DivisionID));
                            } else {
                                psBossID.Add(DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID));
                            }

                            psCHID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                        } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                            psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        }
                    } else if (totalDay <= หัวหน้าภาควิชาลาป่วยวัน) {
                        if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                            psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                            psCHID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                        } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                            psCHID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                        } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                            psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        }
                    } else if (totalDay <= คณะบดีลาป่วยวัน) {
                        if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                            psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                            psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                            psCLID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                            psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                            psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        }
                    } else if (totalDay <= อธิการบดีลาป่วยวัน) {
                        if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                            psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                            psCLID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                            psCLID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        }
                    } else {
                        if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                            psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                            psCLID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                            psCLID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                            psCLID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        }
                    }
                } else if (hfLeaveTypeID.Value == "2") {
                    if (totalDay <= หัวหน้าฝ่ายลากิจวัน) {
                        if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                            psCHID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                        } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                            psCHID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                        } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                            psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        }
                    } else if (totalDay <= หัวหน้าภาควิชาลากิจวัน) {
                        if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                            psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                            psCHID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                        } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                            psCHID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                        } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                            psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        }
                    } else if (totalDay <= คณะบดีลากิจวัน) {
                        if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                            psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                            psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                            psCLID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                            psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                            psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        }
                    } else if (totalDay <= อธิการบดีลากิจวัน) {
                        if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                            psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                            psCLID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                            psCLID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                            psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        }
                    } else {
                        if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                            psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                            psCLID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                            psCLID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                            psCLID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                            psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                        } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                            psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                        }
                    }
                } else if (hfLeaveTypeID.Value == "3") {
                    if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                        psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                        psCHID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                    } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                        psCHID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                    } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                        psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                    } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                        psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                    } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                        psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                    } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                        psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                    } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                        psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                    }
                } else if (hfLeaveTypeID.Value == "4") {
                    if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                        psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                        psCHID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                    } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                        psCHID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                    } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                        psCHID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                    } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                        psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                    } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                        psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                    } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                        psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                    } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                        psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                    }
                } else if (hfLeaveTypeID.Value == "5") {
                    if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                        psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                        psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                    } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                        psCLID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                        psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                    } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                        psCLID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                    } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                        psCHID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                    } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                        psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                    } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                        psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                    } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                        psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                    }
                } else if (hfLeaveTypeID.Value == "6" || hfLeaveTypeID.Value == "7") {
                    if (loginPerson.AdminPositionID == "0" || loginPerson.AdminPositionID == "8" || loginPerson.AdminPositionID == "9") { //ไม่มี
                        psCLID = DatabaseManager.รหัสหัวหน้าฝ่าย(loginPerson.WorkDivisionID);
                        psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                    } else if (loginPerson.AdminPositionID == "4") { //หัวหน้าฝ่าย
                        psCLID = DatabaseManager.รหัสหัวหน้าภาควิชา(loginPerson.DivisionID);
                        psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                    } else if (loginPerson.AdminPositionID == "7") { //หัวหน้าภาควิชา
                        psCLID = DatabaseManager.รหัสคณบดี(loginPerson.FacultyID);
                        psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                    } else if (loginPerson.AdminPositionID == "3" || loginPerson.AdminPositionID == "6") { //คณบดี
                        psCLID = DatabaseManager.รหัสอธิการบดี(loginPerson.CampusID);
                        psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                    } else if (loginPerson.AdminPositionID == "1" || loginPerson.AdminPositionID == "2" || loginPerson.AdminPositionID == "5") { //อธิการบดี
                        psCHID = DatabaseManager.รหัสเลขาธิการคณะกรรมการ();
                    } else if (loginPerson.AdminPositionID == "10022") { //เลขาธิการคณะกรรมการ
                        psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                    } else if (loginPerson.AdminPositionID == "10021") { //รัฐมนตรีเจ้าสังกัด
                        psCHID = DatabaseManager.รหัสรัฐมนตรีเจ้าสังกัด();
                    }
                }*/

                //Person psCL = DatabaseManager.GetPerson("1"/*psCLID*/);
                // Person psCH = DatabaseManager.GetPerson("1"/*psCHID*/);

                /* if(psCLID == "" && psCL == null) {
                     lbS2CL.Text = "ไม่มี";
                     psCLImage.Visible = false;
                 }

                 if (psCL != null) {
                     lbS2CL.Text = "<span class='ps-lb-red-b'>" + psCL.FirstNameAndLastName + "</span><br />" + psCL.CitizenID + "<br />" + psCL.PositionWorkName + "<br />" + psCL.AdminPositionName;
                     psCLImage.Visible = true;
                 } else {
                     lbS2CL.Text = "ไม่มี";
                     psCLImage.Visible = false;
                 }

                 if ( (psCLID != "" && psCL == null) || (psCHID != "" && psCH == null)) {

                     if (psCLID != "" && psCL == null) {
                         psCLImage.Visible = false;
                         lbS2CL.Text = "พบข้อผิดพลาด<br />ไม่พบพนักงาน";
                         lbS2CL.ForeColor = Color.Red;
                     }

                     if (psCHID != "" && psCH == null) {
                         psCHImage.Visible = false;
                         lbS2CH.Text = "พบข้อผิดพลาด<br />ไม่พบพนักงาน";
                         lbS2CH.ForeColor = Color.Red;
                     }

                     lbuS2Finish.Visible = false;
                     return;
                 }*/

                /* psCLImage.Visible = true;
                 psCHImage.Visible = true;
                 lbS2CL.ForeColor = Color.Black;
                 lbS2CH.ForeColor = Color.Black;
                 lbuS2Finish.Visible = true;*/

                //Person psCL = DatabaseManager.GetPerson("1700070000701");
                //Person psCH = DatabaseManager.GetPerson("1700070000702");

                /* if (psCL == null) {
                     lbS2CL.Text = "-";
                 }*/

                //----------- END CL CH--

                LeaveData leaveData = new LeaveData();
                leaveData.LeaveTypeID = int.Parse(hfLeaveTypeID.Value);
                leaveData.LeaveStatusID = 1;
                leaveData.PS_ID = loginPerson.CitizenID;
                leaveData.RequestDate = DateTime.Now;
                leaveData.FromDate = dtFromDate;
                leaveData.ToDate = dtToDate;
                leaveData.TotalDay = totalDay;
                leaveData.Reason = tbS1Reason.Text;
                leaveData.Contact = tbS1Contact.Text;
                leaveData.Telephone = tbS1Phone.Text;
                if (lastFromDate.HasValue) {
                    leaveData.LastFromDate = lastFromDate;
                    leaveData.LastToDate = lastToDate;
                }
                leaveData.LastTotalDay = lastTotalDay;

                leaveData.DocterCertificationFileName = drCer;
                leaveData.CountPast = pastTotalDay;
                leaveData.CountNow = totalDay;
                leaveData.CountTotal = pastTotalDay + totalDay;
                leaveData.RestLeft = restLeft;
                leaveData.RestSave = restSave;
                leaveData.RestTotal = restTotal;
                leaveData.WifeFirstName = tbS1WifeFirstName.Text;
                leaveData.WifeLastName = tbS1WifeLastName.Text;
                if(hfLeaveTypeID.Value == "5")
                    leaveData.GiveBirthDate = Util.ToDateTimeOracle(tbS1GBDate.Text);
                leaveData.Ordained = rbS1OrdainedT.Checked ? 1 : 0;
                leaveData.TempleName = tbS1TempleName.Text;
                leaveData.TempleLocation = tbS1TempleLocation.Text;
                if (hfLeaveTypeID.Value == "6")
                    leaveData.OrdainDate = Util.ToDateTimeOracle(tbS1OrdainDate.Text);
                leaveData.Hujed = rbS1HujedT.Checked ? 1 : 0;

                for (int i = 0; i < psBossID.Count; i++) {
                    LeaveBossData leaveBossData = new LeaveBossData();
                    leaveBossData.CitizenID = psBossID[i].CitizenID;
                    leaveData.AddBoss(leaveBossData);
                }

                Session["LeaveData"] = leaveData;

                hfFileUploadName.Value = drCer;

            }
        }
        private Table BindToTableLeaveID(int leaveID)
        {
            //Label1.Text = "(1 ตุลาคม " + (int.Parse(DropDownList1.SelectedValue) - 1) + " - 30 กันยายน " + DropDownList1.SelectedValue + ")";

            Table table = new Table();
            table.CssClass = "ps-table-1";

            int budgetYear = int.Parse(DropDownList1.SelectedValue) - 543;

            OracleConnection.ClearAllPools();
            using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) {
                con.Open();

                const int maxCol = 2;

                {
                    TableHeaderRow row = new TableHeaderRow();
                    { TableHeaderCell cell = new TableHeaderCell(); cell.Text = "สรุปข้อมูลการลาหยุดราชการ ขาดราชการ มาสาย ประจำปีงบประมาณ ประจำปีงบประมาณ พ.ศ. " + DropDownList1.SelectedValue; cell.ColumnSpan = maxCol; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }
                {
                    TableHeaderRow row = new TableHeaderRow();
                    { TableHeaderCell cell = new TableHeaderCell(); cell.Text = "มหาวิทยาลัยเทคโนโลยีราชมงคลตะวันออก"; cell.ColumnSpan = maxCol; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                TableHeaderRow rowXT = new TableHeaderRow();
                TableHeaderCell cellXT = new TableHeaderCell();
                {

                    { cellXT.Text = loginPerson.FirstNameAndLastName; cellXT.ColumnSpan = maxCol; rowXT.Cells.Add(cellXT); }
                    table.Rows.Add(rowXT);

                }

                {
                    TableHeaderRow row = new TableHeaderRow();
                    { TableHeaderCell cell = new TableHeaderCell(); cell.Text = ""; cell.ColumnSpan = maxCol; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableHeaderRow row = new TableHeaderRow();
                    { TableHeaderCell cell = new TableHeaderCell(); cell.Text = "ข้อมูลการลา"; cell.ColumnSpan = maxCol; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                LeaveData leaveData = new LeaveData();
                leaveData.Load(leaveID);

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "รหัสการลา"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = "" + leaveData.LeaveID; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "สถานะการลา"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = "" + leaveData.LeaveStatusName; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "ประเภทการลา"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = "" + leaveData.LeaveTypeName; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "วันที่ข้อมูล"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = "" + leaveData.RequestDate.Value.ToLongDateString(); row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "ชื่อผู้ลา"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = "" + leaveData.Person.FirstNameAndLastName; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "ตำแหน่ง"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = "" + leaveData.Person.PositionWorkName; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "ระดับ"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = "" + leaveData.Person.AdminPositionName + leaveData.Person.AdminPositionNameExtra() == "ไม่มี" ? "" : leaveData.Person.AdminPositionNameExtra(); row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "สังกัด"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = Util.IsBlank(leaveData.Person.WorkDivisionID) ? leaveData.Person.DivisionName : leaveData.Person.WorkDivisionName; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                if (leaveData.LeaveTypeID == 4) {
                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = "วันลาพักผ่อนสะสม"; row.Cells.Add(cell); }
                        { TableCell cell = new TableCell(); cell.Text = leaveData.RestSave + " วัน"; row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }

                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = "มีสิทธิลาประจำปีนี้อีก"; row.Cells.Add(cell); }
                        { TableCell cell = new TableCell(); cell.Text = leaveData.RestLeft + " วัน"; row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }

                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = "รวม"; row.Cells.Add(cell); }
                        { TableCell cell = new TableCell(); cell.Text = leaveData.RestTotal + " วัน"; row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }
                }

                if (leaveData.LeaveTypeID == 6) {
                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = "การอุปสมบท"; row.Cells.Add(cell); }
                        { TableCell cell = new TableCell(); cell.Text = leaveData.Ordained == 1 ? "เคย" : "ไม่เคย"; row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }

                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = "ชื่อวัด"; row.Cells.Add(cell); }
                        { TableCell cell = new TableCell(); cell.Text = leaveData.TempleName; row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }

                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = "สถานที่"; row.Cells.Add(cell); }
                        { TableCell cell = new TableCell(); cell.Text = leaveData.TempleLocation; row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }

                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = "อุปสมบทวันที่"; row.Cells.Add(cell); }
                        { TableCell cell = new TableCell(); cell.Text = leaveData.OrdainDate.Value.ToLongDateString(); row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "วันที่ลาล่าสุด"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = leaveData.LastFromDate.HasValue ? leaveData.LastFromDate.Value.ToLongDateString() + " ถึง " + leaveData.LastToDate.Value.ToLongDateString() + " รวม " + leaveData.LastTotalDay + " วัน " : "ยังไม่เคยลา"; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "วันที่ลา"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = leaveData.FromDate.Value.ToLongDateString() + " ถึง " + leaveData.ToDate.Value.ToLongDateString() + " รวม " + leaveData.TotalDay + " วัน "; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "สถิติการลา"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = "ลามาแล้ว " + leaveData.CountPast + " วัน / รวมครั้งนี้ " + leaveData.CountNow + " วัน / รวม " + leaveData.CountTotal + " วัน "; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                if(leaveData.LeaveTypeID == 1 || leaveData.LeaveTypeID == 2 || leaveData.LeaveTypeID == 3) {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "เหตุผล"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = leaveData.Reason; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                if (leaveData.LeaveStatusID >= 4 && leaveData.LeaveStatusID <= 6){
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "เหตุผลที่ยกเลิก"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = leaveData.CancelReason; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "ติดต่อได้ที่"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = leaveData.Contact; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableRow row = new TableRow();
                    { TableCell cell = new TableCell(); cell.Text = "เบอร์โทรศัพท์"; row.Cells.Add(cell); }
                    { TableCell cell = new TableCell(); cell.Text = "'" + leaveData.Telephone; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableHeaderRow row = new TableHeaderRow();
                    { TableHeaderCell cell = new TableHeaderCell(); cell.Text = ""; cell.ColumnSpan = maxCol; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                {
                    TableHeaderRow row = new TableHeaderRow();
                    { TableHeaderCell cell = new TableHeaderCell(); cell.Text = "ผู้อนุมัติการลา"; cell.ColumnSpan = maxCol; row.Cells.Add(cell); }
                    table.Rows.Add(row);
                }

                List<LeaveBossData> leaveBossDataList = leaveData.LeaveBossDataList;
                for (int i = 0; i < leaveBossDataList.Count; i++) {
                    LeaveBossData leaveBossData = leaveBossDataList[i];
                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = "ชื่อ"; row.Cells.Add(cell); }
                        { TableCell cell = new TableCell(); cell.Text = leaveBossData.Person.FirstNameAndLastName; row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }
                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = "ตำแหน่ง"; row.Cells.Add(cell); }
                        { TableCell cell = new TableCell(); cell.Text = leaveBossData.Person.PositionWorkName; row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }
                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = "ระดับ"; row.Cells.Add(cell); }
                        { TableCell cell = new TableCell(); cell.Text = leaveBossData.Person.AdminPositionName; row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }
                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = "การอนุมัติ"; row.Cells.Add(cell); }
                        string sss = "";
                        sss += "<div>" + leaveBossData.AllowDate.Value.ToLongDateString() + "</div>";
                        if(leaveBossData.Allow == 1) {
                            sss += "<div style='color:green;'>อนุญาต</div>";
                        } else {
                            sss += "<div style='color:red;'>ไม่อนุญาต</div>";
                        }
                        sss += "<div>" + leaveBossData.Comment + "</div>";
                        { TableCell cell = new TableCell(); cell.Text = sss; row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }

                    if (leaveData.LeaveStatusID >= 4 && leaveData.LeaveStatusID <= 6) {
                        {
                            TableRow row = new TableRow();
                            { TableCell cell = new TableCell(); cell.Text = "การอนุมัติยกเลิก"; row.Cells.Add(cell); }
                            string sss = "";
                            sss += "<div>" + leaveBossData.CancelAllowDate.Value.ToLongDateString() + "</div>";
                            if (leaveBossData.CancelAllow == 1) {
                                sss += "<div style='color:green;'>อนุญาต</div>";
                            } else {
                                sss += "<div style='color:red;'>ไม่อนุญาต</div>";
                            }
                            sss += "<div>" + leaveBossData.CancelComment + "</div>";
                            { TableCell cell = new TableCell(); cell.Text = sss; row.Cells.Add(cell); }
                            table.Rows.Add(row);
                        }
                    }
                    {
                        TableRow row = new TableRow();
                        { TableCell cell = new TableCell(); cell.Text = ""; cell.ColumnSpan = 2; row.Cells.Add(cell); }
                        table.Rows.Add(row);
                    }

                }

            }

            return table;
        }