Exemple #1
0
        protected void cldExam_DayRender(object sender, DayRenderEventArgs e)
        {
            #region Day Render Rows
            /********** render day ************/
            daysCounter++;
            if (e.Day.Date.Day == 1 && !e.Day.IsOtherMonth) // 1st of current month. Turn visibility of row to ON.
            {
                isLastRow = false;
            }
            else if (daysCounter == 36 && e.Day.IsOtherMonth) // 5 rows already rendered. If its the next row is next month, hide it.
            {
                isLastRow = true;
            }
            else if (daysCounter == 1 && e.Day.IsOtherMonth && e.Day.Date.Month == e.Day.Date.AddDays(6).Month)
            {   // If first row completely is previous month, hide it.
                // Actually the flag should be isFirstRow, but I dont want one more boolean just for the sake of it.
                isLastRow = true;
            }

            if (isLastRow)
            {
                e.Cell.Visible = false;
                return;
            }
            if (e.Day.IsWeekend && !e.Day.IsSelected)
            {
                e.Cell.Style.Add("background-color", "#f0e7f1");
            }
            /********* end render ************/
            #endregion
            e.Day.IsSelectable = false;
            e.Cell.Enabled     = false;
            e.Cell.ForeColor   = System.Drawing.Color.Gray;

            BLL.ExamScheduleBiz   biz     = new BLL.ExamScheduleBiz();
            Func <string, string> GetCrit = anyString =>
            {
                return(string.IsNullOrEmpty(anyString) ? string.Empty : anyString);
            };

            if (ExamSchedules.Count() > 0)
            {
                DateTime exam = ExamSchedules.FirstOrDefault(a => a.Date == e.Day.Date);


                if (exam != null && exam != DateTime.MinValue)
                {
                    LinkButton lnk = new LinkButton();
                    e.Cell.Controls.Add(new LiteralControl("</br>"));

                    DateTime datenow    = DateTime.Now;
                    DateTime adddate    = DateTime.Now.AddDays(5);
                    DateTime renderdate = e.Day.Date;
                    if (renderdate > datenow && renderdate < adddate)
                    {
                        lnk.ID        = "lnkButton";
                        lnk.Text      = "รายละเอียด";
                        lnk.Enabled   = false;
                        lnk.ForeColor = System.Drawing.Color.Gray;
                        e.Cell.Attributes.Remove("onclick");
                        e.Cell.Style.Remove("cursor");
                        e.Cell.Style.Remove("pointer");
                    }
                    else
                    {
                        lnk.ID        = "lnkButton";
                        lnk.Text      = "รายละเอียด";
                        lnk.ForeColor = System.Drawing.Color.Green;
                        e.Cell.Attributes.Add("onclick", e.SelectUrl);
                        e.Cell.Style.Add("cursor", "pointer");
                    }
                    e.Cell.Controls.Add(lnk);
                }
            }


            if (Holidays.Count() > 0)
            {
                //DataTable dt = dsHoliday.Tables[0];
                GBHoliday holiday  = Holidays.FirstOrDefault(s => s.HL_DATE.Date == e.Day.Date);
                DateTime  dtToday  = DateTime.Today.AddDays(-1);
                DateTime  dtFinish = DateTime.Today.AddDays(+5);

                //ExamRender examrender = new ExamRender();
                if (holiday != null)
                {
                    e.Cell.Controls.Add(new LiteralControl("</br>"));
                    Label lnk = new Label();
                    lnk.ID        = "lnkButton";
                    lnk.Enabled   = false;
                    lnk.Text      = holiday.HL_DESC;
                    lnk.ForeColor = System.Drawing.Color.Red;
                    lnk.BackColor = System.Drawing.Color.FromArgb(250, 200, 135);
                    e.Cell.Attributes.Add("onclick", e.SelectUrl);
                    e.Cell.Style.Add("cursor", "pointer");
                    e.Cell.Controls.Add(lnk);
                }
            }

            e.Cell.DataBind();
        }