public void PreviousDate_Tests() { DateTime thursdayFourteenthFebruary2008 = new DateTime(2008, 2, 14); Assert.AreEqual(new DateTime(2008, 2, 11), thursdayFourteenthFebruary2008.Previous(DayOfWeek.Monday)); Assert.AreEqual(new DateTime(2008, 2, 7), thursdayFourteenthFebruary2008.Previous(DayOfWeek.Thursday)); Assert.AreEqual(new DateTime(2008, 2, 8), thursdayFourteenthFebruary2008.Previous(DayOfWeek.Friday)); Assert.AreEqual(new DateTime(2008, 2, 11), thursdayFourteenthFebruary2008.Previous(DayOfWeek.Monday, true)); Assert.AreEqual(new DateTime(2008, 2, 8), thursdayFourteenthFebruary2008.Previous(DayOfWeek.Friday, true)); Assert.AreEqual(new DateTime(2008, 2, 14), thursdayFourteenthFebruary2008.Previous(DayOfWeek.Thursday, true)); DateTime fridayFirstOfFeb2008 = new DateTime(2008, 2, 1); Assert.AreEqual(new DateTime(2008, 1, 28), fridayFirstOfFeb2008.Previous(DayOfWeek.Monday, true)); }
private static DateTime UTCDateFromYearMonthWeekDay(int year, int month, int week, int day) { var date = new DateTime (year, month, 1).ToUniversalTime (); var dayOfWeekWanted = (DayOfWeek)Enum.ToObject (typeof(DayOfWeek), day); var beginningDay = (int) date.DayOfWeek; if (beginningDay < day) date = date.Next (dayOfWeekWanted); else if (beginningDay > day) { var previous = date.Previous (dayOfWeekWanted); if (previous.Month == month) date = previous; else date = date.Next (dayOfWeekWanted); } var daysToAdd = (week - 1) * 7; return date.AddDays (daysToAdd); }
private void Page_Load(object sender, System.EventArgs e) { if (this.Visible) { if (Personalise) Usr.KickUserIfNotLoggedIn("You must be logged in to use the My Calendar or Buddy Calendar pages."); if (BuddyDisplay) selectTab(BuddyCalendarTab); else if (Personalise) selectTab(MyCalendarTab); //else //CalendarTab.Visible=true; HotTicketsIntroPanel.Visible = HotTickets; NotHotTicketsIntroPanel.Visible = !HotTickets; if (Personalise && !BuddyDisplay) { if (Usr.Current.MusicTypesFavouriteCount == 0) Response.Redirect("/pages/mymusic"); if (Usr.Current.PlacesVisitCount == 0) Response.Redirect("/pages/placesivisit"); } MusicTypeDropDownPanel.Visible = !Personalise && !(eventsForDisplay.FilterByVenue || eventsForDisplay.FilterByBrand || eventsForDisplay.FilterByGroup); MusicFilterLabel1.Visible = MusicTypeDropDownPanel.Visible; MusicFilterLabel2.Visible = MusicTypeDropDownPanel.Visible; if (eventsForDisplay.FilterByVenue || eventsForDisplay.FilterByBrand || eventsForDisplay.FilterByGroup) eventsForDisplay.IgnoreMusicType = true; #region //Set up intro panel if (HotTickets) { TopIcon.Src = "/gfx/icon-hottickets.png"; EventFinderTab.InnerText = "Hot tickets"; HotTicketsIntroPanelWorldwideP.Visible = eventsForDisplay.FilterWorldwide; HotTicketsIntroPanelBrandP.Visible = eventsForDisplay.FilterByBrand; HotTicketsIntroPanelNonBrandP.Visible = eventsForDisplay.FilterByVenue || eventsForDisplay.FilterByPlace || eventsForDisplay.FilterByCountry || eventsForDisplay.FilterByGroup; if (eventsForDisplay.FilterWorldwide) { HotTicketsIntroPanelWorldwideHomeCountryLink.InnerText = HotTicketsIntroPanelWorldwideHomeCountryLink.InnerText.Replace("???", Country.Current.FriendlyName); HotTicketsIntroPanelWorldwideHomeCountryLink.HRef = Country.Current.UrlApp("hottickets"); } } else { AllEventsIntroPanel.Visible = eventsForDisplay.FilterWorldwide; ObjectCalendarIntroPanel.Visible = eventsForDisplay.FilterByVenue || eventsForDisplay.FilterByPlace || eventsForDisplay.FilterByCountry || eventsForDisplay.FilterByBrand || eventsForDisplay.FilterByGroup; MyCalendarIntroPanel.Visible = Personalise && !Tickets && !BuddyDisplay; BuddyCalendarIntroPanel.Visible = BuddyDisplay; TicketsCalendarIntroPanel.Visible = Personalise && Tickets; if (Tickets) TopIcon.Src = "/gfx/icon-tickets.png"; else if (FreeGuestlist) TopIcon.Src = "/gfx/icon-freeguestlist.png"; if (Tickets) EventFinderTab.InnerText = "Tickets"; else if (FreeGuestlist) EventFinderTab.InnerText = "Free Guestlist"; if (Tickets) { AllEventsIntroPanelEventsLabel1.Text = "events with tickets available"; AllEventsIntroPanelEventsLabel2.Text = "events with tickets available"; AllEventsIntroPanelEventsLabel3.Text = "events with tickets available"; } else if (FreeGuestlist) { AllEventsIntroPanelEventsLabel1.Text = "Free Guestlist events"; AllEventsIntroPanelEventsLabel2.Text = "Free Guestlist events"; AllEventsIntroPanelEventsLabel3.Text = "Free Guestlist events"; } else { AllEventsIntroPanelEventsLabel1.Text = "events"; AllEventsIntroPanelEventsLabel2.Text = "events"; AllEventsIntroPanelEventsLabel3.Text = "events"; } AllEventsIntroPanelHomeCountryLink.InnerText = AllEventsIntroPanelHomeCountryLink.InnerText.Replace("???", Country.Current.FriendlyName); if (DateTime.Now.Month == Month && DateTime.Now.Year == Year && Day == 0) AllEventsIntroPanelHomeCountryLink.HRef = Country.Current.UrlCalendar(Tickets, FreeGuestlist); else AllEventsIntroPanelHomeCountryLink.HRef = Country.Current.UrlCalendarDay(Tickets, FreeGuestlist, Year, Month, Day); } #endregion string dateFilterString = ""; if (HotTickets) { MonthViewPanel.Visible = false; DayViewPanel.Visible = false; HotTicketsEventListPanel.Visible = true; EventSet es = eventsForDisplay.GetTopHotTicketEvents(); HotTicketsEventListNoEventsP.Visible = es.Count == 0; HotTicketsEventListEventsDiv.Visible = es.Count > 0; if (es.Count > 0) { HotTicketsEventList.DataSource = es; HotTicketsEventList.ItemTemplate = this.LoadTemplate("/Templates/Events/EventList0.ascx"); HotTicketsEventList.DataBind(); } } else if (Day == 0) { MonthViewPanel.Visible = true; DayViewPanel.Visible = false; HotTicketsEventListPanel.Visible = false; #region firstCellDate, lastCellDate DateTime firstOfMonth = new DateTime(Year, Month, 1); DateTime firstCellDate = firstOfMonth.Previous(DayOfWeek.Monday, true); DateTime lastOfMonth = firstOfMonth.AddDays(DateTime.DaysInMonth(Year, Month) - 1); DateTime lastCellDate = lastOfMonth.Next(DayOfWeek.Sunday, true); #endregion dateFilterString = firstOfMonth.ToString("MMMM yyyy"); #region get event set EventSet es = eventsForDisplay.GetEventsBetweenDates(firstCellDate, lastCellDate); #endregion #region bind to calendar CustomControls.DsiCalendar uiCal = this.BuddyDisplay ? new CustomControls.BuddyCalendar() : new CustomControls.DsiCalendar(); uiCalPlaceHolder.Controls.Add(uiCal); uiCal.ShowCountryFriendlyName = !(eventsForDisplay.FilterByCountry || eventsForDisplay.FilterByPlace || eventsForDisplay.FilterByVenue); uiCal.ShowPlace = !(eventsForDisplay.FilterByPlace || eventsForDisplay.FilterByVenue); uiCal.ShowVenue = !eventsForDisplay.FilterByVenue; uiCal.Tickets = Tickets; uiCal.Month = Month; uiCal.AllEvents = es; uiCal.StartDate = firstCellDate; uiCal.EndDate = lastCellDate; #endregion #region set up next / prev month links string nextMonthUrl = ChangeMonthUrl(lastOfMonth.AddDays(1).Month, lastOfMonth.AddDays(1).Year); string prevMonthUrl = ChangeMonthUrl(firstOfMonth.AddDays(-1).Month, firstOfMonth.AddDays(-1).Year); #region set up links uiCal.NextMonthUrl = nextMonthUrl; uiCal.PrevMonthUrl = prevMonthUrl; MonthNameLabel.Text = firstOfMonth.ToString("MMMM") + " " + Year.ToString(); MonthNameLabel1.Text = firstOfMonth.ToString("MMMM") + " " + Year.ToString(); BackLink.InnerHtml = "< " + firstOfMonth.AddDays(-1).ToString("MMMM"); BackLink1.InnerHtml = "< " + firstOfMonth.AddDays(-1).ToString("MMMM"); BackLink.HRef = prevMonthUrl; BackLink1.HRef = prevMonthUrl; NextLink.InnerHtml = lastOfMonth.AddDays(1).ToString("MMMM") + " >"; NextLink1.InnerHtml = lastOfMonth.AddDays(1).ToString("MMMM") + " >"; NextLink.HRef = nextMonthUrl; NextLink1.HRef = nextMonthUrl; #endregion if (uiCal.AllEvents.Count == 0) { Event latestPastEvent = eventsForDisplay.GetLatestPastEvent(firstOfMonth); if (latestPastEvent == null) { #region disable the back link if we have no past events BackLink.HRef = ""; BackLink1.HRef = ""; BackLink.Disabled = true; BackLink1.Disabled = true; #endregion } else { #region set up the back link with the month of the latest past event BackLink.HRef = ChangeMonthUrl(latestPastEvent.DateTime.Month, latestPastEvent.DateTime.Year); BackLink1.HRef = ChangeMonthUrl(latestPastEvent.DateTime.Month, latestPastEvent.DateTime.Year); BackLink.InnerHtml = "< " + latestPastEvent.DateTime.ToString("MMMM"); BackLink1.InnerHtml = "< " + latestPastEvent.DateTime.ToString("MMMM"); if (latestPastEvent.DateTime.Year != Year) { BackLink.InnerHtml = "< " + latestPastEvent.DateTime.ToString("MMMM") + " " + latestPastEvent.DateTime.Year.ToString(); BackLink1.InnerHtml = "< " + latestPastEvent.DateTime.ToString("MMMM") + " " + latestPastEvent.DateTime.Year.ToString(); } #endregion } Event nextFutureEvent = eventsForDisplay.GetNextFutureEvent(lastOfMonth); if (nextFutureEvent == null) { #region disable the forward link if we have no future events NextLink.HRef = ""; NextLink1.HRef = ""; NextLink.Disabled = true; NextLink1.Disabled = true; #endregion } else { #region set up the back link with the month of the first future event NextLink.HRef = ChangeMonthUrl(nextFutureEvent.DateTime.Month, nextFutureEvent.DateTime.Year); NextLink1.HRef = ChangeMonthUrl(nextFutureEvent.DateTime.Month, nextFutureEvent.DateTime.Year); NextLink.InnerHtml = nextFutureEvent.DateTime.ToString("MMMM") + " >"; NextLink1.InnerHtml = nextFutureEvent.DateTime.ToString("MMMM") + " >"; if (nextFutureEvent.DateTime.Year != Year) { NextLink.InnerHtml = nextFutureEvent.DateTime.ToString("MMMM") + " " + nextFutureEvent.DateTime.Year.ToString() + " >"; NextLink1.InnerHtml = nextFutureEvent.DateTime.ToString("MMMM") + " " + nextFutureEvent.DateTime.Year.ToString() + " >"; } #endregion } #region ensure links are fully disabled if (BackLink.Disabled) BackLink.Attributes["class"] = "DisabledAnchor"; if (BackLink1.Disabled) BackLink1.Attributes["class"] = "DisabledAnchor"; if (NextLink.Disabled) NextLink.Attributes["class"] = "DisabledAnchor"; if (NextLink1.Disabled) NextLink1.Attributes["class"] = "DisabledAnchor"; #endregion } #endregion } else { MonthViewPanel.Visible = false; DayViewPanel.Visible = true; HotTicketsEventListPanel.Visible = false; DateTime day = new DateTime(Year, Month, Day); dateFilterString = day.ToString("dddd dd MMMM yyyy"); #region get event set EventSet es = eventsForDisplay.GetEventsForDay(day); #endregion DayViewNoEventsP.Visible = es.Count == 0; DayViewEventsDiv.Visible = es.Count > 0; if (es.Count > 0) { DayViewDataList.DataSource = es; if (es.Count < 20) DayViewDataList.ItemTemplate = this.LoadTemplate("/Templates/Events/EventList0.ascx"); else if (es.Count < 50) DayViewDataList.ItemTemplate = this.LoadTemplate("/Templates/Events/EventList1.ascx"); else DayViewDataList.ItemTemplate = this.LoadTemplate("/Templates/Events/EventList2.ascx"); //DayViewDataList.ItemTemplate = this.LoadTemplate("/Templates/Events/EventList2.ascx"); DayViewDataList.DataBind(); } #region set up next / prev day links DayMonthLink.InnerText = "Show calendar for " + day.ToString("MMMM yyyy"); DayMonthLink1.InnerText = "Show calendar for " + day.ToString("MMMM yyyy"); DayMonthLink.HRef = ChangeMonthUrl(day.Month, day.Year); DayMonthLink1.HRef = ChangeMonthUrl(day.Month, day.Year); string nextDayUrl = ChangeDayUrl(day.AddDays(1).Month, day.AddDays(1).Year, day.AddDays(1).Day); string prevDayUrl = ChangeDayUrl(day.AddDays(-1).Month, day.AddDays(-1).Year, day.AddDays(-1).Day); #region set up links DayNameLabel.Text = dateFilterString; DayNameLabel1.Text = dateFilterString; DayBackLink.InnerHtml = "< " + day.AddDays(-1).ToString("dddd dd"); DayBackLink1.InnerHtml = "< " + day.AddDays(-1).ToString("dddd dd"); DayBackLink.HRef = prevDayUrl; DayBackLink1.HRef = prevDayUrl; DayNextLink.InnerHtml = day.AddDays(1).ToString("dddd dd") + " >"; DayNextLink1.InnerHtml = day.AddDays(1).ToString("dddd dd") + " >"; DayNextLink.HRef = nextDayUrl; DayNextLink1.HRef = nextDayUrl; #endregion if (es.Count == 0) { Event latestPastEvent = eventsForDisplay.GetLatestPastEvent(day); if (latestPastEvent == null) { #region disable the back link if we have no past events DayBackLink.HRef = ""; DayBackLink1.HRef = ""; DayBackLink.Disabled = true; DayBackLink1.Disabled = true; #endregion } else { #region set up the back link with the month of the latest past event DayBackLink.HRef = ChangeDayUrl(latestPastEvent.DateTime.Month, latestPastEvent.DateTime.Year, latestPastEvent.DateTime.Day); DayBackLink1.HRef = ChangeDayUrl(latestPastEvent.DateTime.Month, latestPastEvent.DateTime.Year, latestPastEvent.DateTime.Day); if (latestPastEvent.DateTime.Year != Year) { DayBackLink.InnerHtml = "< " + latestPastEvent.DateTime.ToString("dddd dd MMMM yyyy"); DayBackLink1.InnerHtml = "< " + latestPastEvent.DateTime.ToString("dddd dd MMMM yyyy"); } else if (latestPastEvent.DateTime.Month != Month) { DayBackLink.InnerHtml = "< " + latestPastEvent.DateTime.ToString("dddd dd MMMM"); DayBackLink1.InnerHtml = "< " + latestPastEvent.DateTime.ToString("dddd dd MMMM"); } else { DayBackLink.InnerHtml = "< " + latestPastEvent.DateTime.ToString("dddd dd"); DayBackLink1.InnerHtml = "< " + latestPastEvent.DateTime.ToString("dddd dd"); } #endregion } Event nextFutureEvent = eventsForDisplay.GetNextFutureEvent(day); if (nextFutureEvent == null) { #region disable the forward link if we have no future events DayNextLink.HRef = ""; DayNextLink1.HRef = ""; DayNextLink.Disabled = true; DayNextLink1.Disabled = true; #endregion } else { #region set up the back link with the month of the first future event DayNextLink.HRef = ChangeDayUrl(nextFutureEvent.DateTime.Month, nextFutureEvent.DateTime.Year, nextFutureEvent.DateTime.Day); DayNextLink1.HRef = ChangeDayUrl(nextFutureEvent.DateTime.Month, nextFutureEvent.DateTime.Year, nextFutureEvent.DateTime.Day); if (nextFutureEvent.DateTime.Year != Year) { DayNextLink.InnerHtml = nextFutureEvent.DateTime.ToString("dddd dd MMMM yyyy") + " >"; DayNextLink1.InnerHtml = nextFutureEvent.DateTime.ToString("dddd dd MMMM yyyy") + " >"; } if (nextFutureEvent.DateTime.Month != Month) { DayNextLink.InnerHtml = nextFutureEvent.DateTime.ToString("dddd dd MMMM") + " >"; DayNextLink1.InnerHtml = nextFutureEvent.DateTime.ToString("dddd dd MMMM") + " >"; } else { DayNextLink.InnerHtml = nextFutureEvent.DateTime.ToString("dddd dd") + " >"; DayNextLink1.InnerHtml = nextFutureEvent.DateTime.ToString("dddd dd") + " >"; } #endregion } #region ensure links are fully disabled if (DayBackLink.Disabled) DayBackLink.Attributes["class"] = "DisabledAnchor"; if (DayBackLink1.Disabled) DayBackLink1.Attributes["class"] = "DisabledAnchor"; if (DayNextLink.Disabled) DayNextLink.Attributes["class"] = "DisabledAnchor"; if (DayNextLink1.Disabled) DayNextLink1.Attributes["class"] = "DisabledAnchor"; #endregion } #endregion } #region Set up intro text and page title if (HotTickets) { if (eventsForDisplay.FilterByBrand) { Brand b = new Brand(BrandK); HotTicketsIntroPanelBrandLink.HRef = b.Url(); HotTicketsIntroPanelBrandLink.InnerText = b.Name; ((Spotted.Master.DsiPage)this.Page).SetPageTitle("Hot tickets for " + b.FriendlyName + " events", b.FriendlyName); HotTicketsIntroPanelTicketsCalendarLink.HRef = b.UrlCalendar(true, false); } else if (eventsForDisplay.FilterByGroup) { Group g = new Group(GroupK); HotTicketsIntroPanelNonBrandInAtLabel.Text = "recommended by"; HotTicketsIntroPanelNonBrandObjectLink.HRef = g.Url(); HotTicketsIntroPanelNonBrandObjectLink.InnerText = g.FriendlyName; ((Spotted.Master.DsiPage)this.Page).SetPageTitle("Hot tickets recommended by " + g.FriendlyName, g.FriendlyName); HotTicketsIntroPanelTicketsCalendarLink.HRef = g.UrlCalendar(true, false); } else if (eventsForDisplay.FilterByVenue) { HotTicketsIntroPanelNonBrandInAtLabel.Text = "at"; Venue v = new Venue(VenueK); HotTicketsIntroPanelNonBrandObjectLink.InnerText = v.FriendlyName; HotTicketsIntroPanelNonBrandObjectLink.HRef = v.Url(); ((Spotted.Master.DsiPage)this.Page).SetPageTitle("Hot tickets for events at " + v.FriendlyName, v.Name); HotTicketsIntroPanelTicketsCalendarLink.HRef = v.UrlCalendar(true, false); } else if (eventsForDisplay.FilterByPlace) { HotTicketsIntroPanelNonBrandInAtLabel.Text = "in"; Place p = new Place(PlaceK); HotTicketsIntroPanelNonBrandObjectLink.InnerText = p.FriendlyName; HotTicketsIntroPanelNonBrandObjectLink.HRef = p.Url(); ((Spotted.Master.DsiPage)this.Page).SetPageTitle("Hot tickets for events in " + p.FriendlyName, p.Name); HotTicketsIntroPanelTicketsCalendarLink.HRef = p.UrlCalendar(true, false); } else if (eventsForDisplay.FilterByCountry) { HotTicketsIntroPanelNonBrandInAtLabel.Text = "in"; HotTicketsIntroPanelNonBrandObjectLink.InnerText = FilterCountry.FriendlyName; HotTicketsIntroPanelNonBrandObjectLink.HRef = FilterCountry.Url(); ((Spotted.Master.DsiPage)this.Page).SetPageTitle("Hot tickets for events in " + FilterCountry.FriendlyName, FilterCountry.Name); HotTicketsIntroPanelTicketsCalendarLink.HRef = FilterCountry.UrlCalendar(true, false); } else if (eventsForDisplay.FilterWorldwide) { ((Spotted.Master.DsiPage)this.Page).SetPageTitle("Hot tickets worldwide"); HotTicketsIntroPanelTicketsCalendarLink.HRef = Calendar.UrlCalendar(true, false); } } else { ObjectCalendarIntroBrand.Visible = eventsForDisplay.FilterByBrand; ObjectCalendarIntroNonBrand.Visible = !eventsForDisplay.FilterByBrand; if (eventsForDisplay.FilterByBrand) { Brand b = new Brand(BrandK); ObjectCalendarIntroBrandAnchor.HRef = b.Url(); ObjectCalendarIntroBrandAnchor.InnerText = b.Name; ((Spotted.Master.DsiPage)this.Page).SetPageTitle(b.FriendlyName + (FreeGuestlist ? " Free Guestlist" : "") + " calendar for " + dateFilterString, b.FriendlyName); } else if (eventsForDisplay.FilterByGroup) { Group g = new Group(GroupK); ObjectCalendarIntroInAtLabel.Text = "recommended by"; ObjectCalendarIntroObjectLink.HRef = g.Url(); ObjectCalendarIntroObjectLink.InnerText = g.FriendlyName; ((Spotted.Master.DsiPage)this.Page).SetPageTitle(g.FriendlyName + (FreeGuestlist ? " Free Guestlist" : "") + " calendar for " + dateFilterString, g.FriendlyName); } else if (eventsForDisplay.FilterByVenue) { ObjectCalendarIntroInAtLabel.Text = "at"; Venue v = new Venue(VenueK); ObjectCalendarIntroObjectLink.InnerText = v.FriendlyName; ObjectCalendarIntroObjectLink.HRef = v.Url(); ((Spotted.Master.DsiPage)this.Page).SetPageTitle(v.FriendlyName + (FreeGuestlist ? " Free Guestlist" : "") + " events calendar for " + dateFilterString, v.Name); } else if (eventsForDisplay.FilterByPlace) { ObjectCalendarIntroInAtLabel.Text = "in"; Place p = new Place(PlaceK); ObjectCalendarIntroObjectLink.InnerText = p.FriendlyName; ObjectCalendarIntroObjectLink.HRef = p.Url(); ((Spotted.Master.DsiPage)this.Page).SetPageTitle(p.FriendlyName + (FreeGuestlist ? " Free Guestlist" : "") + " events calendar for " + dateFilterString, p.Name); } else if (eventsForDisplay.FilterByCountry) { ObjectCalendarIntroInAtLabel.Text = "in"; ObjectCalendarIntroObjectLink.InnerText = FilterCountry.FriendlyName; ObjectCalendarIntroObjectLink.HRef = FilterCountry.Url(); ((Spotted.Master.DsiPage)this.Page).SetPageTitle((FreeGuestlist ? "Free Guestlist calendar" : " Calendar") + " for " + FilterCountry.FriendlyName + ", " + dateFilterString, FilterCountry.Name); } else if (eventsForDisplay.FilterWorldwide) { ((Spotted.Master.DsiPage)this.Page).SetPageTitle((FreeGuestlist ? "Free Guestlist calendar" : " Calendar") + " for " + dateFilterString); } if (Personalise && !BuddyDisplay) ((Spotted.Master.DsiPage)this.Page).SetPageTitle("My calendar"); else if (BuddyDisplay) ((Spotted.Master.DsiPage)this.Page).SetPageTitle("Buddy calendar"); } #endregion } }
protected void Page_Load(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); // if (Vars.DevEnv) // System.Threading.Thread.Sleep(new Random().Next(2000)); if (Request.QueryString["type"] == "calendar") { bool freeGuestlist = Request.QueryString["freeGuestlist"] == null || Request.QueryString["freeGuestlist"].Length == 0 || Request.QueryString["freeGuestlist"] == "0" ? false : true; Brand brand = Request.QueryString["brandk"] == null || Request.QueryString["brandk"].Length == 0 || Request.QueryString["brandk"] == "0" ? null : new Brand(int.Parse(Request.QueryString["brandk"])); Place place = Request.QueryString["placek"] == null || Request.QueryString["placek"].Length == 0 || Request.QueryString["placek"] == "0" ? null : new Place(int.Parse(Request.QueryString["placek"])); Venue venue = Request.QueryString["venuek"] == null || Request.QueryString["venuek"].Length == 0 || Request.QueryString["venuek"] == "0" || Request.QueryString["venuek"] == "1" ? null : new Venue(int.Parse(Request.QueryString["venuek"])); int key = Request.QueryString["key"] == null || Request.QueryString["key"].Length == 0 || Request.QueryString["key"] == "0" ? 0 : int.Parse(Request.QueryString["key"]); MusicType music = Request.QueryString["musictypek"] == null || Request.QueryString["musictypek"].Length == 0 || Request.QueryString["musictypek"] == "0" ? null : new MusicType(int.Parse(Request.QueryString["musictypek"])); bool me = Request.QueryString["me"] != null && Request.QueryString["me"] == "1"; bool addGalleryButton = Request.QueryString["addgallery"] != null && Request.QueryString["addgallery"] == "1"; bool allVenues = Request.QueryString["venuek"] != null && Request.QueryString["venuek"] == "1"; DateTime date = new DateTime( int.Parse(Request.QueryString["date"].Substring(0, 4)), int.Parse(Request.QueryString["date"].Substring(4, 2)), int.Parse(Request.QueryString["date"].Substring(6, 2)) > 0 ? int.Parse(Request.QueryString["date"].Substring(6, 2)) : 1 ); //if (date == DateTime.Today) // System.Threading.Thread.Sleep(1000); DateTime from = date.Previous(DayOfWeek.Monday, true); DateTime to = date.Next(DayOfWeek.Sunday, true); Event.EventsForDisplay events = new Event.EventsForDisplay(); events.IgnoreMusicType = true; if (me) { events.AttendedUsrK = Usr.Current.K; } else if (brand != null) { events.BrandK = brand.K; } else if (venue != null) { events.VenueK = venue.K; } else if (place != null && music != null) { events.PlaceK = place.K; events.MusicTypeK = music.K; } else if (place != null && freeGuestlist) { events.PlaceK = place.K; events.FreeGuestlist = freeGuestlist; } else if (key > 0) { } else throw new Exception(); EventSet es; if (key == 0) es = events.GetEventsBetweenDates(from, to); else es = new EventSet(new Query(new Q(Event.Columns.K, key))); CustomControls.DsiCalendar calendar = new Spotted.CustomControls.DsiCalendar(); calendar.AllEvents = es; calendar.Month = date.Month; calendar.ShowCountryFriendlyName = !(events.FilterByCountry || events.FilterByPlace || events.FilterByVenue); calendar.ShowPlace = !(events.FilterByPlace || events.FilterByVenue); calendar.ShowVenue = !events.FilterByVenue; calendar.ShowAddGalleryButton = addGalleryButton; calendar.Tickets = true; calendar.StartDate = from; calendar.EndDate = to; Out.Controls.Add(calendar); } else { sb.AppendLine("{"); if (Request.QueryString["type"] == "music") { #region Music types Query q = new Query(); q.QueryCondition = new Q(MusicType.Columns.K, QueryOperator.NotEqualTo, 1); q.Columns = new ColumnSet(MusicType.Columns.Name, MusicType.Columns.ParentK, MusicType.Columns.K); q.OrderBy = new OrderBy(MusicType.Columns.Order, OrderBy.OrderDirection.Ascending); q.CacheDuration = TimeSpan.FromDays(1); MusicTypeSet mts = new MusicTypeSet(q); append(sb, "Select your music...", "0"); append(sb, "", ""); foreach (MusicType mt in mts) { append(sb, (mt.ParentK == 1 ? "" : "... ") + mt.Name, mt.K.ToString()); } #endregion } else if (Request.QueryString["type"] == "country") { #region Countries append(sb, "Select a country...", "0"); Query qTop = new Query(); qTop.Columns = new ColumnSet(Country.Columns.FriendlyName, Country.Columns.K); qTop.OrderBy = new OrderBy(Country.Columns.TotalEvents, OrderBy.OrderDirection.Descending); qTop.QueryCondition = new Q(Country.Columns.Enabled, true); qTop.TopRecords = 10; qTop.CacheDuration = TimeSpan.FromDays(1); CountrySet csTop = new CountrySet(qTop); append(sb, "", ""); append(sb, "--- TOP COUNTRIES ---", "0"); foreach (Country c in csTop) { append(sb, c.FriendlyName.TruncateWithDots(maxLength), c.K.ToString()); } Query qAll = new Query(); qAll.Columns = new ColumnSet(Country.Columns.FriendlyName, Country.Columns.K); qAll.OrderBy = new OrderBy(Country.Columns.FriendlyName); qAll.QueryCondition = new And(new Q(Country.Columns.Enabled, true), new StringQueryCondition("(SELECT COUNT(*) FROM [Place] WHERE [Place].[Enabled] = 1 AND [Place].[CountryK] = [Country].[K]) > 0")); qAll.CacheDuration = TimeSpan.FromDays(1); CountrySet csAll = new CountrySet(qAll); append(sb, "", ""); append(sb, "--- ALL COUNTRIES ---", "0"); foreach (Country c in csAll) { append(sb, c.FriendlyName.TruncateWithDots(maxLength), c.K.ToString()); } #endregion } else if (Request.QueryString["type"] == "place") { #region Places int countryK = int.Parse(Request.QueryString["countryk"]); Country country = new Country(countryK); Query qTop = new Query(); qTop.Columns = new ColumnSet(Place.Columns.Name, Place.Columns.K, Place.LinkColumns); qTop.TopRecords = 10; qTop.QueryCondition = new And(new Q(Place.Columns.CountryK, country.K), new Q(Place.Columns.Enabled, true)); qTop.OrderBy = new OrderBy(Place.Columns.TotalEvents, OrderBy.OrderDirection.Descending); PlaceSet psTop = new PlaceSet(qTop); if (psTop.Count == 0) { append(sb, "No towns in our database for this country", ""); } else { append(sb, "Towns in " + country.FriendlyName.Truncate(maxLength) + "...", ""); append(sb, "", ""); if (psTop.Count < 10) { foreach (Place p in psTop) append(sb, p.NamePlainRegion.TruncateWithDots(maxLength), Request.QueryString["return"] == "k" ? p.K.ToString() : p.Url()); } else { append(sb, "--- TOP TOWNS ---", ""); foreach (Place p in psTop) append(sb, p.NamePlainRegion.TruncateWithDots(maxLength), Request.QueryString["return"] == "k" ? p.K.ToString() : p.Url()); Query qAll = new Query(); qAll.Columns = new ColumnSet(Place.Columns.Name, Place.Columns.K, Place.LinkColumns); qAll.OrderBy = new OrderBy(Place.Columns.UrlName); qAll.QueryCondition = new And(new Q(Place.Columns.CountryK, countryK), new Q(Place.Columns.Enabled, true)); PlaceSet psAll = new PlaceSet(qAll); append(sb, "", ""); append(sb, "--- ALL TOWNS ---", ""); foreach (Place p in psAll) append(sb, p.NamePlainRegion.TruncateWithDots(maxLength), Request.QueryString["return"] == "k" ? p.K.ToString() : p.Url()); } } #endregion } else if (Request.QueryString["type"] == "venue") { #region Venues int placeK = int.Parse(Request.QueryString["placek"]); Place place = new Place(placeK); Query qTop = new Query(); qTop.Columns = new ColumnSet(Venue.Columns.Name, Venue.Columns.K, Venue.LinkColumns); qTop.TopRecords = 10; qTop.QueryCondition = new Q(Venue.Columns.PlaceK, place.K); qTop.OrderBy = new OrderBy(Venue.Columns.TotalEvents, OrderBy.OrderDirection.Descending); VenueSet vsTop = new VenueSet(qTop); if (vsTop.Count == 0) { append(sb, "No venues in our database for this town", ""); } else { append(sb, "Venues in " + place.NamePlainRegion.Truncate(maxLength) + "...", ""); append(sb, "", ""); if (Request.QueryString["all"] == "1") { append(sb, "All venues", "1"); append(sb, "", ""); } if (vsTop.Count < 10) { appendVenues(sb, vsTop); } else { append(sb, "--- TOP VENUES ---", ""); appendVenues(sb, vsTop); Query qAll = new Query(); qAll.Columns = new ColumnSet(Venue.Columns.Name, Venue.Columns.K, Venue.LinkColumns); qAll.OrderBy = new OrderBy("( CASE WHEN [Venue].[UrlName] LIKE 'the-%' THEN SUBSTRING([Venue].[UrlName], 4, LEN([Venue].[UrlName]) - 4) ELSE [Venue].[UrlName] END )"); qAll.QueryCondition = new Q(Venue.Columns.PlaceK, placeK); VenueSet vsAll = new VenueSet(qAll); append(sb, "", ""); append(sb, "--- ALL VENUES ---", ""); if (vsAll.Count <= 300) { appendVenues(sb, vsAll); } else { append(sb, "Select the first letter:", ""); append(sb, "", ""); append(sb, "0-9", "*0"); string ch; for (int i = 65; i <= 90; i++) { ch = char.ConvertFromUtf32(i); append(sb, ch.ToUpper() + "...", "*" + ch.ToLower()); } } } } #endregion } else if (Request.QueryString["type"] == "venuebyletter") { #region Venues int placeK = int.Parse(Request.QueryString["placek"]); string letter = Request.QueryString["letter"]; if (letter.Length > 1) throw new Exception(); Place place = new Place(placeK); string qu = ""; if (letter.ToLower() == "0") { qu = "([Venue].[UrlName] LIKE '[0-9]%' OR [Venue].[UrlName] LIKE 'the-[0-9]%')"; } else if (letter.ToLower() == "t") { qu = "(([Venue].[UrlName] LIKE 't%' AND [Venue].[UrlName] NOT LIKE 'the-%' ) OR [Venue].[UrlName] LIKE 'the-t%')"; } else { qu = "([Venue].[UrlName] LIKE '" + letter.ToLower() + "%' OR [Venue].[UrlName] LIKE 'the-" + letter.ToLower() + "%')"; } Query q = new Query(); q.Columns = new ColumnSet(Venue.Columns.Name, Venue.Columns.K, Venue.LinkColumns); //q.OrderBy = new OrderBy(Venue.Columns.UrlName); q.OrderBy = new OrderBy("( CASE WHEN [Venue].[UrlName] LIKE 'the-%' THEN SUBSTRING([Venue].[UrlName], 4, LEN([Venue].[UrlName]) - 4) ELSE [Venue].[UrlName] END )"); q.QueryCondition = new And( new Q(Venue.Columns.PlaceK, placeK), new StringQueryCondition(qu)); VenueSet vs = new VenueSet(q); if (vs.Count == 0) { append(sb, "No venues starting with " + letter.ToUpper(), ""); } else { append(sb, "Venues starting with " + letter.ToUpper() + "...", ""); append(sb, "", ""); appendVenues(sb, vs); } #endregion } else if (Request.QueryString["type"] == "event") { #region Events int venueK = int.Parse(Request.QueryString["venuek"]); int brandK = int.Parse(Request.QueryString["brandk"]); int key = int.Parse(Request.QueryString["key"]); int year = int.Parse(Request.QueryString["date"].Substring(0, 4)); int month = int.Parse(Request.QueryString["date"].Substring(4, 2)); DateTime dateFrom = new DateTime(year, month, 1); DateTime dateTo = dateFrom.AddMonths(1); Venue venue = venueK > 1 ? new Venue(venueK) : null; Brand brand = brandK > 0 ? new Brand(brandK) : null; EventSet es; if (key == 0) { Query q = new Query(); if (brand == null) q.Columns = new ColumnSet(Event.Columns.DateTime, Event.Columns.Name, Event.Columns.K); else q.Columns = new ColumnSet(Event.Columns.DateTime, Event.Columns.Name, Event.Columns.K, Event.FriendlyLinkColumns); q.QueryCondition = new And( new Q(Event.Columns.DateTime, QueryOperator.GreaterThanOrEqualTo, dateFrom), new Q(Event.Columns.DateTime, QueryOperator.LessThan, dateTo), venue != null ? new Q(Event.Columns.VenueK, venue.K) : new Q(true), brand != null ? new Q(EventBrand.Columns.BrandK, brand.K) : new Q(true)); q.OrderBy = Event.FutureEventOrder; if (brandK > 0) { q.TableElement = new Join( Event.CountryAllJoin, new TableElement(TablesEnum.EventBrand), QueryJoinType.Inner, Event.Columns.K, EventBrand.Columns.EventK); } es = new EventSet(q); } else es = new EventSet(new Query(new Q(Event.Columns.K, key))); if (es.Count == 0) { append(sb, "No events in our database for this selection", ""); } else { //append(sb, "Events at " + venue.FriendlyName.Truncate(maxLength) + ", " + dateFrom.ToString("MMM yyyy") + "...", ""); //append(sb, "", ""); Dictionary<string, int> counter = new Dictionary<string, int>(); foreach (Event ev in es) { string key1 = eventString(ev, brand != null); if (counter.ContainsKey(key1.ToLower())) counter[key1.ToLower()]++; else counter[key1.ToLower()] = 1; } foreach (Event ev in es) { string key1 = eventString(ev, brand != null); if (counter[key1.ToLower()] > 1) key1 = key1.Substring(0, 8) + " - #" + ev.K.ToString() + key1.Substring(8); append(sb, key1, ev.K.ToString()); } } #endregion } sb.AppendLine(""); sb.Append("}"); } Out.Controls.Add(new LiteralControl(sb.ToString())); }
public void Next_ReturnsPreviousFridayProperly() { var friday = new DateTime(2009, 7, 17, 1, 0, 0, 0, DateTimeKind.Local); var reallyPreviousFriday = new DateTime(2009, 7, 10, 1, 0, 0, 0, DateTimeKind.Local); var previousFriday = friday.Previous(DayOfWeek.Friday); DateAssert.AreEqual(reallyPreviousFriday, previousFriday); }
public void BasicTests() { var now = DateTime.Now; DateAssert.AreEqual(new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999, DateTimeKind.Local), DateTime.Now.EndOfDay(), " End of the day wrong"); DateAssert.AreEqual(new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, 0, DateTimeKind.Local), DateTime.Now.BeginningOfDay(), "Start of the day wrong"); var firstBirthDay = new DateTime(1977, 12, 31, 17, 0, 0, 0, DateTimeKind.Local); DateAssert.AreEqual(firstBirthDay + new TimeSpan(1, 0, 5, 0, 0), firstBirthDay + 1.Days() + 5.Minutes()); DateAssert.AreEqual(now + TimeSpan.FromDays(1), now.NextDay()); DateAssert.AreEqual(now - TimeSpan.FromDays(1), now.PreviousDay()); DateAssert.AreEqual(now + TimeSpan.FromDays(7), now.WeekAfter()); DateAssert.AreEqual(now - TimeSpan.FromDays(7), now.WeekEarlier()); Assert.AreEqual(new DateTime(2009, 1, 1, 0, 0, 0, 0, DateTimeKind.Local), new DateTime(2008, 12, 31, 0, 0, 0, DateTimeKind.Local).Add(1.Days())); Assert.AreEqual(new DateTime(2009, 1, 2, 0, 0, 0, 0, DateTimeKind.Local), new DateTime(2009, 1, 1, 0, 0, 0, 0, DateTimeKind.Local).Add(1.Days())); var sampleDate = new DateTime(2009, 1, 1, 13, 0, 0, 0, DateTimeKind.Local); DateAssert.AreEqual(new DateTime(2009, 1, 1, 12, 0, 0, 0, DateTimeKind.Local), sampleDate.Noon()); DateAssert.AreEqual(new DateTime(2009, 1, 1, 0, 0, 0, 0, DateTimeKind.Local), sampleDate.Midnight()); Assert.AreEqual(3.Days() + 3.Days(), 6.Days()); Assert.AreEqual(102.Days() - 3.Days(), 99.Days()); Assert.AreEqual(24.Hours(), 1.Days()); sampleDate = new DateTime(2008, 1, 1, 0, 0, 0, 0, DateTimeKind.Local); DateAssert.AreEqual(3.Days().Since(sampleDate), sampleDate + 3.Days()); var saturday = new DateTime(2008, 10, 25, 12, 0, 0, DateTimeKind.Local); DateAssert.AreEqual(new DateTime(2008, 11, 1, 12, 0, 0, DateTimeKind.Local), saturday.Next(DayOfWeek.Saturday)); DateAssert.AreEqual(new DateTime(2008, 10, 18, 12, 0, 0, DateTimeKind.Local), saturday.Previous(DayOfWeek.Saturday)); // ReSharper disable UnusedVariable var nextWeek = DateTime.Now + 1.Weeks(); var tomorrow = DateTime.Now + 1.Days(); var yesterday = DateTime.Now - 1.Days(); var changedHourTo14H = DateTime.Now.SetHour(14); var todayNoon = DateTime.Now.Noon(); var tomorrowNoon = DateTime.Now.NextDay().Noon(); var fiveDaysAgo = 5.Days().Ago(); var twoDaysFromNow = 2.Days().FromNow(); var nextYearSameDateAsTodayNoon = 1.Years().FromNow().Noon(); var twoWeeksFromNow = 2.Weeks().FromNow(); // ReSharper restore UnusedVariable }