Example #1
0
        /// <summary>
        /// Try find holiday for date field. If found return true and set founded holiday parameter.
        /// <para lang="tr">date alanı ile belirtilen tarih için tatil olup olmadığını belirler. Eğer varsa holiday alanına atar.</para>
        /// </summary>
        /// <param name="date">Check date</param>
        /// <param name="holiday">Return holiday if date in holiday</param>
        /// <returns></returns>
        public bool TryFindHoliday(DateTime date, out Holiday holiday)
        {
            holiday = Holidays.FirstOrDefault(e => e.Begin <= date && e.End > date);
            var ret = holiday != null;

            return(ret);
        }
Example #2
0
        private void GetMonth(DateTime day)
        {
            // add holidays
            var holidays = new HolidayCalculator(day, Utils.ReadConfig("Holidays", "Path"));

            foreach (HolidayCalculator.Holiday h in holidays.OrderedHolidays)
            {
                if (h.Date.Month == day.Month)
                {
                    Holidays.Add(new Holiday(h.Name, h.Date));
                }
                // and days before holidays if theye're not weekends or holidays
                var yesterday = h.Date.AddDays(-1);
                if (yesterday.Month == day.Month &&
                    Holidays.FirstOrDefault(hl => hl.Date == yesterday) == default(Holiday) &&
                    yesterday.DayOfWeek != DayOfWeek.Saturday &&
                    yesterday.DayOfWeek != DayOfWeek.Sunday)
                {
                    SpecialDays.Add(new SpecialDay("Day before " + h.Name, yesterday.Date));
                }
            }

            // if the last day in month is day before holiday
            var firstInNextMonth = Last.AddDays(1);
            var hol = Holidays.FirstOrDefault(h => h.Date == firstInNextMonth);

            if (hol != null &&
                Last.Date.DayOfWeek != DayOfWeek.Saturday &&
                Last.Date.DayOfWeek != DayOfWeek.Sunday)
            {
                SpecialDays.Add(new SpecialDay("Day before " + hol.Name, Last.Date));
            }

            // get all fridays, if they're not holidays
            var startDate = First;

            while (startDate.DayOfWeek != DayOfWeek.Friday)
            {
                startDate = startDate.AddDays(1);
            }

            while (startDate < Last)
            {
                if (Holidays.FirstOrDefault(h => h.Date == startDate) == default(Holiday))
                {
                    SpecialDays.Add(new SpecialDay("Friday", startDate));
                }
                startDate = startDate.AddDays(7);
            }

            // get all weekends, if they're not holidays
            startDate = First;
            while (startDate.DayOfWeek != DayOfWeek.Saturday)
            {
                startDate = startDate.AddDays(1);
            }

            while (startDate < Last)
            {
                if (Holidays.FirstOrDefault(h => h.Date == startDate) == default(Holiday))
                {
                    NonWorkingDays.Add(new NonWorkingDay(startDate));
                }
                startDate = startDate.AddDays(1);
                if (Holidays.FirstOrDefault(h => h.Date == startDate) == default(Holiday))
                {
                    NonWorkingDays.Add(new NonWorkingDay(startDate));
                }
                startDate = startDate.AddDays(6);
            }
        }
 private HolidayItem getHolidayItem(int curDay)
 {
     return(Holidays.FirstOrDefault(item => item.Year == _year && item.Month == _month && item.Day == curDay));
 }
Example #4
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();
        }