//Generate a month view
        void GenerateSingleMonth(DateTime monthDate)
        {
            //clean the month view if it's a redraw
            if (_monthView.Superview != null)
            {
                foreach (var subview in _monthView.Subviews)
                {
                    subview.RemoveFromSuperview();
                }
            }

            var daysInMonth    = DateTime.DaysInMonth(monthDate.Year, monthDate.Month);
            var firstDay       = new DateTime(monthDate.Year, monthDate.Month, 1).DayOfWeek;
            var weekdayOfFirst = (int)firstDay;             //the name of the first day of the current month

            var position = weekdayOfFirst + 1;
            var line     = 0;

            // draw the days
            for (int i = 1; i <= daysInMonth; i++)
            {
                var viewDay = new DateTime(monthDate.Year, monthDate.Month, i);

                var dayView = new CalendarDayView
                {
                    Frame = new CGRect((position - 1) * _singleDayFrameSize + _borderOffset, (line * _singleDayFrameSize) + Y_BORDER_OFFSET, _singleDayFrameSize, _singleDayFrameSize),
                    Today = (DateTime.Now.Date == viewDay.Date),
                    Text  = i.ToString(),
                    Date  = viewDay,

                    Active   = true,
                    Tag      = i,
                    Selected = (i == DateTime.Now.Date.AddDays(1).Day)
                };

                //by vishal
                if (DateTime.Now.Date == viewDay.Date)
                {
                    dayView.BackgroundColor = UIColor.Green;
                }
                dayView.AddGestureRecognizer(new UITapGestureRecognizer(sw =>
                {
                    //by vishal
                    #region
                    if (DateTime.Now.Date <= viewDay.Date)
                    {
                        if (!ProcessMultipleSelection(ListofSelectedDates, (int)dayView.Tag))
                        {
                            ListofSelectedDates.Add((int)dayView.Tag);
                            DayHasBeenSelected((int)dayView.Tag);
                            dayView.BackgroundColor = UIColor.Red;
                        }
                        else
                        {
                            dayView.BackgroundColor = UIColor.White;
                            if (DateTime.Now.Date == viewDay.Date)
                            {
                                dayView.BackgroundColor = UIColor.Green;
                            }
                            DayHasBeenSelected((int)dayView.Tag);
                        }
                    }
                    #endregion
                }));

                _monthView.Add(dayView);

                position++;
                if (position > DAYS_IN_A_WEEK)
                {
                    position = 1;
                    line++;
                }
            }
        }
Beispiel #2
0
        //Generate a month view
        void GenerateSingleMonth(DateTime monthDate)
        {
            //clean the month view if it's a redraw
            if (_monthView.Superview != null)
            {
                foreach (var subview in _monthView.Subviews)
                {
                    subview.RemoveFromSuperview();
                }
            }

            var daysInMonth    = DateTime.DaysInMonth(monthDate.Year, monthDate.Month);
            var firstDay       = new DateTime(monthDate.Year, monthDate.Month, 1).DayOfWeek;
            var weekdayOfFirst = (int)firstDay;                     //the name of the first day of the current month

            var position   = weekdayOfFirst + 1;
            var line       = 0;
            int absentdate = 0;

            // draw the days
            for (int i = 1; i <= daysInMonth; i++)
            {
                var viewDay = new DateTime(monthDate.Year, monthDate.Month, i);

                var dayView = new CalendarDayView
                {
                    Frame = new CGRect((position - 1) * _singleDayFrameSize + _borderOffset, (line * _singleDayFrameSize) + Y_BORDER_OFFSET, _singleDayFrameSize, _singleDayFrameSize),
                    Today = (DateTime.Now.Date == viewDay.Date),
                    Text  = i.ToString(),
                    Date  = viewDay,

                    Active   = true,
                    Tag      = i,
                    Selected = (i == DateTime.Now.Date.AddDays(1).Day)
                };

                //red
                dayView.BackgroundColor = new UIColor(0.775f, 0.311f, 0.308f, 1);



                //Present indication
                if (WebService.Presentlist != null)
                {
                    for (int j = 0; j < WebService.Presentlist.Count; j++)
                    {
                        Console.WriteLine("Present day" + WebService.Presentlist[j].date.Date.ToString() + "ViewDay" + viewDay.Date.ToString());
                        if (viewDay.Year == WebService.Presentlist[j].date.Year &&
                            viewDay.Month == WebService.Presentlist[j].date.Month)
                        {
                            if (WebService.Presentlist[j].date.Date == viewDay.Date)
                            {
                                Present = Present + 1;
                                //dayView.BackgroundColor = UIColor.White;
                                dayView.BackgroundColor = new UIColor(0.011f, 0.687f, 0.491f, 1);
                            }
                        }
                        //else
                        //{
                        //dayView.BackgroundColor = new UIColor(0.775f, 0.311f, 0.308f, 1);

                        //}
                    }
                }
                //Future date
                if (viewDay.Date > DateTime.Now.Date && DayOfWeek.Sunday != viewDay.Date.DayOfWeek &&
                    DayOfWeek.Friday != viewDay.Date.DayOfWeek && DayOfWeek.Saturday != viewDay.Date.DayOfWeek)
                {
                    FutureDays = FutureDays + 1;

                    dayView.BackgroundColor = new UIColor(0.538f, 0.492f, 0.491f, 1);
                }
                //by sunday
                if (DayOfWeek.Sunday == viewDay.Date.DayOfWeek)
                {
                    dayView.BackgroundColor = new UIColor(0.93f, 0.93f, 0.93f, 1);
                    if (viewDay.Year == WebService.Holidaylist[0].holiday_date.Year &&
                        viewDay.Month == WebService.Holidaylist[0].holiday_date.Month)
                    {
                        //Sunday = Sunday + 1;
                    }
                    Sunday = Sunday + 1;
                }
                //Holiday indication
                if (WebService.Holidaylist != null)
                {
                    for (int k = 0; k < WebService.Holidaylist.Count; k++)
                    {
                        if (viewDay.Year == WebService.Holidaylist[k].holiday_date.Year &&
                            viewDay.Month == WebService.Holidaylist[k].holiday_date.Month)
                        {
                            if (WebService.Holidaylist[k].holiday_date.Date == viewDay.Date)
                            {
                                dayView.BackgroundColor = new UIColor(0.018f, 0.541f, 0.593f, 1);
                                Holidays = Holidays + 1;
                            }
                        }
                    }
                }

                //Absent
                //if (WebService.Holidaylist[k].holiday_date.Date < DateTime.Now.Date)
                //{
                //dayView.BackgroundColor = new UIColor(0.775f, 0.311f, 0.308f, 1);
                //}
                dayView.AddGestureRecognizer(new UITapGestureRecognizer(sw =>
                {
                    //by vishal
                    #region
                    //if (DateTime.Now.Date <= viewDay.Date)
                    //	{
                    //		if (!ProcessMultipleSelection(ListofSelectedDates, (int)dayView.Tag))
                    //		{
                    //			ListofSelectedDates.Add((int)dayView.Tag);
                    //			DayHasBeenSelected((int)dayView.Tag);
                    //			dayView.BackgroundColor = UIColor.Red;
                    //		}
                    //		else
                    //		{
                    //			dayView.BackgroundColor = UIColor.White;
                    //			if (DateTime.Now.Date == viewDay.Date)
                    //			{
                    //				dayView.BackgroundColor = UIColor.Green;
                    //			}
                    //			DayHasBeenSelected((int)dayView.Tag);
                    //		}
                    //	}
                    #endregion
                }));

                _monthView.Add(dayView);

                position++;
                if (position > DAYS_IN_A_WEEK)
                {
                    position = 1;
                    line++;
                }
                DaysInMonth = daysInMonth;
            }
        }