Beispiel #1
0
        public WeekForMonth getCalender(int month, int year)
        {
            WeekForMonth weeks = new WeekForMonth();

            weeks.Week1 = new List <Day>();
            weeks.Week2 = new List <Day>();
            weeks.Week3 = new List <Day>();
            weeks.Week4 = new List <Day>();
            weeks.Week5 = new List <Day>();
            weeks.Week6 = new List <Day>();

            List <DateTime> dt = new List <DateTime>();

            dt = GetDates(year, month);

            foreach (DateTime day in dt)
            {
                switch (GetWeekOfMonth(day))
                {
                case 1:
                    Day dy1 = new Day();

                    dy1.Date      = day;
                    dy1._Date     = day.ToShortDateString();
                    dy1.dateStr   = day.ToString("MM/dd/yyyy");
                    dy1.dtDay     = day.Day;
                    dy1.daycolumn = GetDateInfo(dy1.Date);
                    weeks.Week1.Add(dy1);
                    break;

                case 2:
                    Day dy2 = new Day();
                    dy2.Date      = day;
                    dy2._Date     = day.ToShortDateString();
                    dy2.dateStr   = day.ToString("MM/dd/yyyy");
                    dy2.dtDay     = day.Day;
                    dy2.daycolumn = GetDateInfo(dy2.Date);
                    weeks.Week2.Add(dy2);
                    break;

                case 3:
                    Day dy3 = new Day();
                    dy3.Date      = day;
                    dy3._Date     = day.ToShortDateString();
                    dy3.dateStr   = day.ToString("MM/dd/yyyy");
                    dy3.dtDay     = day.Day;
                    dy3.daycolumn = GetDateInfo(dy3.Date);
                    weeks.Week3.Add(dy3);
                    break;

                case 4:
                    Day dy4 = new Day();
                    dy4.Date      = day;
                    dy4._Date     = day.ToShortDateString();
                    dy4.dateStr   = day.ToString("MM/dd/yyyy");
                    dy4.dtDay     = day.Day;
                    dy4.daycolumn = GetDateInfo(dy4.Date);
                    weeks.Week4.Add(dy4);
                    break;

                case 5:
                    Day dy5 = new Day();
                    dy5.Date      = day;
                    dy5._Date     = day.ToShortDateString();
                    dy5.dateStr   = day.ToString("MM/dd/yyyy");
                    dy5.dtDay     = day.Day;
                    dy5.daycolumn = GetDateInfo(dy5.Date);
                    weeks.Week5.Add(dy5);
                    break;

                case 6:
                    Day dy6 = new Day();
                    dy6.Date      = day;
                    dy6._Date     = day.ToShortDateString();
                    dy6.dateStr   = day.ToString("MM/dd/yyyy");
                    dy6.dtDay     = day.Day;
                    dy6.daycolumn = GetDateInfo(dy6.Date);
                    weeks.Week6.Add(dy6);
                    break;
                }
                ;
            }

            while (weeks.Week1.Count < 7) // not starting from sunday
            {
                Day dy = null;
                weeks.Week1.Insert(0, dy);
            }

            if (month == 12)
            {
                weeks.nextMonth = (01).ToString() + "/" + (year + 1).ToString();
                weeks.prevMonth = (month - 1).ToString() + "/" + (year).ToString();
            }
            else if (month == 1)
            {
                weeks.nextMonth = (month + 1).ToString() + "/" + (year).ToString();
                weeks.prevMonth = (12).ToString() + "/" + (year - 1).ToString();
            }
            else
            {
                weeks.nextMonth = (month + 1).ToString() + "/" + (year).ToString();
                weeks.prevMonth = (month - 1).ToString() + "/" + (year).ToString();
            }

            return(weeks);
        }
        public WeekForMonth getCalender(int month, int year)
        {
            WeekForMonth weeks = new WeekForMonth();

            //set the month and yer..
            weeks.curMonth = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month);
            weeks.year     = year.ToString();

            weeks.Week1 = new List <Day>();
            weeks.Week2 = new List <Day>();
            weeks.Week3 = new List <Day>();
            weeks.Week4 = new List <Day>();
            weeks.Week5 = new List <Day>();
            weeks.Week6 = new List <Day>();

            List <DateTime> dt = new List <DateTime>();

            dt = GetDates(year, month);


            //get the events
            List <EventResult> events = SearchEvents(month, year);


            //DateTime[] events = new DateTime[]
            //    {
            //        new DateTime(DateTime.Now.Year, 7, 1),
            //        new DateTime(DateTime.Now.Year, 7, 2),
            //        new DateTime(DateTime.Now.Year, 7, 3)
            //    };


            foreach (DateTime day in dt)
            {
                //check if this date exist in the event List..
                // bool exist = events.Any(d => d.Month == day.Month && d.Day == day.Day);

                //get the particular event/s on that day.
                // IEnumerable<DateTime> evs = events.Where(d => d.Month == day.Month && d.Day == day.Day);


                IEnumerable <EventResult> evs = events.Where(d => d.month == day.Month && d.year == day.Year && d.day == day.Day).OrderBy(d => d.timeFrom);


                switch (GetWeekOfMonth(day))
                {
                case 1:
                    Day dy1 = new Day();

                    dy1.Date      = day;
                    dy1._Date     = day.ToShortDateString();
                    dy1.dateStr   = day.ToString("MM/dd/yyyy");
                    dy1.dtDay     = day.Day;
                    dy1.daycolumn = GetDateInfo(dy1.Date);

                    dy1.ShipEvents = new List <ShipEvent>();

                    //add the events if any.. max 2 for now
                    foreach (EventResult e in evs.Take(2))
                    {
                        dy1.ShipEvents.Add(
                            new ShipEvent
                        {
                            eventDesc = e.NodeName,
                            eventLink = e.Url,
                            eventTime = e.timeFrom + " - " + e.timeTo
                        });
                    }

                    weeks.Week1.Add(dy1);
                    break;

                case 2:
                    Day dy2 = new Day();
                    dy2.Date      = day;
                    dy2._Date     = day.ToShortDateString();
                    dy2.dateStr   = day.ToString("MM/dd/yyyy");
                    dy2.dtDay     = day.Day;
                    dy2.daycolumn = GetDateInfo(dy2.Date);

                    dy2.ShipEvents = new List <ShipEvent>();

                    //add the events if any.. max 2 for now
                    foreach (EventResult e in evs.Take(2))
                    {
                        dy2.ShipEvents.Add(
                            new ShipEvent
                        {
                            eventDesc = e.NodeName,
                            eventLink = e.Url,
                            eventTime = e.timeFrom + " - " + e.timeTo
                        });
                    }

                    weeks.Week2.Add(dy2);
                    break;

                case 3:
                    Day dy3 = new Day();
                    dy3.Date      = day;
                    dy3._Date     = day.ToShortDateString();
                    dy3.dateStr   = day.ToString("MM/dd/yyyy");
                    dy3.dtDay     = day.Day;
                    dy3.daycolumn = GetDateInfo(dy3.Date);

                    dy3.ShipEvents = new List <ShipEvent>();

                    //add the events if any.. max 2 for now
                    foreach (EventResult e in evs.Take(2))
                    {
                        dy3.ShipEvents.Add(
                            new ShipEvent
                        {
                            eventDesc = e.NodeName,
                            eventLink = e.Url,
                            eventTime = e.timeFrom + " - " + e.timeTo
                        });
                    }


                    weeks.Week3.Add(dy3);
                    break;

                case 4:
                    Day dy4 = new Day();
                    dy4.Date      = day;
                    dy4._Date     = day.ToShortDateString();
                    dy4.dateStr   = day.ToString("MM/dd/yyyy");
                    dy4.dtDay     = day.Day;
                    dy4.daycolumn = GetDateInfo(dy4.Date);

                    dy4.ShipEvents = new List <ShipEvent>();

                    //add the events if any.. max 2 for now
                    foreach (EventResult e in evs.Take(2))
                    {
                        dy4.ShipEvents.Add(
                            new ShipEvent
                        {
                            eventDesc = e.NodeName,
                            eventLink = e.Url,
                            eventTime = e.timeFrom + " - " + e.timeTo
                        });
                    }


                    weeks.Week4.Add(dy4);
                    break;

                case 5:
                    Day dy5 = new Day();
                    dy5.Date      = day;
                    dy5._Date     = day.ToShortDateString();
                    dy5.dateStr   = day.ToString("MM/dd/yyyy");
                    dy5.dtDay     = day.Day;
                    dy5.daycolumn = GetDateInfo(dy5.Date);

                    dy5.ShipEvents = new List <ShipEvent>();

                    //add the events if any.. max 2 for now
                    foreach (EventResult e in evs.Take(2))
                    {
                        dy5.ShipEvents.Add(
                            new ShipEvent
                        {
                            eventDesc = e.NodeName,
                            eventLink = e.Url,
                            eventTime = e.timeFrom + " - " + e.timeTo
                        });
                    }

                    weeks.Week5.Add(dy5);
                    break;

                case 6:
                    Day dy6 = new Day();
                    dy6.Date      = day;
                    dy6._Date     = day.ToShortDateString();
                    dy6.dateStr   = day.ToString("MM/dd/yyyy");
                    dy6.dtDay     = day.Day;
                    dy6.daycolumn = GetDateInfo(dy6.Date);

                    dy6.ShipEvents = new List <ShipEvent>();

                    //add the events if any.. max 2 for now
                    foreach (EventResult e in evs.Take(2))
                    {
                        dy6.ShipEvents.Add(
                            new ShipEvent
                        {
                            eventDesc = e.NodeName,
                            eventLink = e.Url,
                            eventTime = e.timeFrom + " - " + e.timeTo
                        });
                    }

                    weeks.Week6.Add(dy6);
                    break;
                }
                ;
            }

            while (weeks.Week1.Count < 7) // not starting from sunday
            {
                Day dy = null;
                weeks.Week1.Insert(0, dy);
            }

            if (month == 12)
            {
                weeks.nextMonth = (01).ToString() + "/" + (year + 1).ToString();
                weeks.prevMonth = (month - 1).ToString() + "/" + (year).ToString();
            }
            else if (month == 1)
            {
                weeks.nextMonth = (month + 1).ToString() + "/" + (year).ToString();
                weeks.prevMonth = (12).ToString() + "/" + (year - 1).ToString();
            }
            else
            {
                weeks.nextMonth = (month + 1).ToString() + "/" + (year).ToString();
                weeks.prevMonth = (month - 1).ToString() + "/" + (year).ToString();
            }

            return(weeks);
        }
        public WeekForMonth GetCalendar(int month, int year)
        {
            WeekForMonth weeks = new WeekForMonth
            {
                Week1 = new List <Day>(),
                Week2 = new List <Day>(),
                Week3 = new List <Day>(),
                Week4 = new List <Day>(),
                Week5 = new List <Day>(),
                Week6 = new List <Day>()
            };

            List <DateTime> dt = new List <DateTime>();
            List <BusyData> bd = GetBusies();

            dt = GetDates(year, month);


            foreach (DateTime day in dt)
            {
                switch (GetWeekOfMonth(day))
                {
                case 1:
                    Day dy1 = new Day
                    {
                        Date    = day,
                        _Date   = day.ToShortDateString(),
                        dateStr = day.ToString("MM/dd/yyyy"),
                        dtDay   = day.Day
                    };
                    dy1.daycolumn = GetDateInfo(dy1.Date);
                    dy1.BusyLevel = GetBusyLevel(day, bd);
                    dy1.BusyDayID = GetDescription(day, bd);
                    weeks.Week1.Add(dy1);
                    break;

                case 2:
                    Day dy2 = new Day
                    {
                        Date    = day,
                        _Date   = day.ToShortDateString(),
                        dateStr = day.ToString("MM/dd/yyyy"),
                        dtDay   = day.Day
                    };
                    dy2.daycolumn = GetDateInfo(dy2.Date);
                    dy2.BusyLevel = GetBusyLevel(day, bd);
                    dy2.BusyDayID = GetDescription(day, bd);
                    weeks.Week2.Add(dy2);
                    break;

                case 3:
                    Day dy3 = new Day
                    {
                        Date    = day,
                        _Date   = day.ToShortDateString(),
                        dateStr = day.ToString("MM/dd/yyyy"),
                        dtDay   = day.Day
                    };
                    dy3.daycolumn = GetDateInfo(dy3.Date);
                    dy3.BusyLevel = GetBusyLevel(day, bd);
                    dy3.BusyDayID = GetDescription(day, bd);
                    weeks.Week3.Add(dy3);
                    break;

                case 4:
                    Day dy4 = new Day
                    {
                        Date    = day,
                        _Date   = day.ToShortDateString(),
                        dateStr = day.ToString("MM/dd/yyyy"),
                        dtDay   = day.Day
                    };
                    dy4.daycolumn = GetDateInfo(dy4.Date);
                    dy4.BusyLevel = GetBusyLevel(day, bd);
                    dy4.BusyDayID = GetDescription(day, bd);
                    weeks.Week4.Add(dy4);
                    break;

                case 5:
                    Day dy5 = new Day
                    {
                        Date    = day,
                        _Date   = day.ToShortDateString(),
                        dateStr = day.ToString("MM/dd/yyyy"),
                        dtDay   = day.Day
                    };
                    dy5.daycolumn = GetDateInfo(dy5.Date);
                    dy5.BusyLevel = GetBusyLevel(day, bd);
                    dy5.BusyDayID = GetDescription(day, bd);
                    weeks.Week5.Add(dy5);
                    break;

                case 6:
                    Day dy6 = new Day
                    {
                        Date    = day,
                        _Date   = day.ToShortDateString(),
                        dateStr = day.ToString("MM/dd/yyyy"),
                        dtDay   = day.Day
                    };
                    dy6.daycolumn = GetDateInfo(dy6.Date);
                    dy6.BusyLevel = GetBusyLevel(day, bd);
                    dy6.BusyDayID = GetDescription(day, bd);
                    weeks.Week6.Add(dy6);
                    break;
                }
                ;
            }

            while (weeks.Week1.Count < 7)
            {
                Day dy = null;
                weeks.Week1.Insert(0, dy);
            }

            if (month == 12)
            {
                weeks.nextMonth = 1;
                weeks.nextYear  = (year + 1);
                weeks.prevMonth = (month - 1);
                weeks.prevYear  = year;
            }
            else if (month == 1)
            {
                weeks.nextMonth = month + 1;
                weeks.nextYear  = (year);
                weeks.prevMonth = 12;
                weeks.prevYear  = (year - 1);
            }
            else
            {
                weeks.nextMonth = month + 1;
                weeks.nextYear  = year;
                weeks.prevMonth = (month - 1);
                weeks.prevYear  = year;
            }

            return(weeks);
        }
        public ActionResult RenderEventCalander(WeekForMonth model)
        {
            bool hasloggedin = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;

            if (!hasloggedin)
            {
                //this does not work.. you can not redirect from Render
                //We can not show "NOAUTH"
                //we can show a login message..

                return(PartialView("authsurface/loginagain"));
                //return Redirect("/");
            }

            //Get the querystring
            var action = Request.QueryString["SubmitAction"];
            int month  = System.DateTime.Today.Month;
            int year   = System.DateTime.Today.Year;

            //Ensure we have a vlaue in QS
            if (string.IsNullOrEmpty(action))
            {
                //populate the calender -all the weeks
                //and assign to the model..

                model          = getCalender(month, year);
                model.intMonth = month; //assign the month
                model.intYear  = year;
            }
            else if (action == "Next")
            {
                int _mo   = model.intMonth + 1;
                int _year = model.intYear;

                if (model.intMonth == 12)
                {
                    _mo = 1;
                    _year++;
                }

                model = getCalender(_mo, _year);

                model.intMonth = _mo; //assign the next month
                model.intYear  = _year;
            }
            else if (action == "Prev")
            {
                int _mo   = model.intMonth - 1;
                int _year = model.intYear;
                if (model.intMonth == 1)
                {
                    _mo = 12;
                    _year--;
                }



                model = getCalender(_mo, _year);

                model.intMonth = _mo; //assign the prev month
                model.intYear  = _year;
            }


            //now add all the role basedd events to the populated calander

            return(PartialView("eventsurface/eventcalendar", model));
        }