private AggregationPeriod(int id, string description, char flag, Func <DateTime, DateTime> roundDown, Func <DateTime, DateTime> next, Func <DateTime, string> dateText) { Flag = flag; RoundDown = roundDown; Next = next; DateText = dateText; Id = id; Description = description; AllPeriods.Add(this); }
public TimetableStructureWeek(string name, IList <string> days, IList <string> periods, IList <int> unschedulable) { Name = name; DayNames = days; PeriodNames = periods; TotalPeriods = periods.Count * days.Count; TotalSchedulable = TotalPeriods; UnavailablePeriods = unschedulable; for (int i = 0; i < DayNames.Count; i++) { DaySchedulable.Add(0); } for (int i = 0; i < TotalPeriods; i++) { AllPeriods.Add(true); } foreach (int index in unschedulable) { AllPeriods[index] = false; TotalSchedulable--; DaySchedulable[index / PeriodNames.Count]++; } }
public List <GraphPeriod> InitRange(DateTime?minDate, DateTime?maxDate, List <Order> orders) { if (orders.Any()) { MinDateThresh = orders.Min(x => x.CreateDate); MaxDateThresh = orders.Max(x => x.CreateDate); } if (!maxDate.HasValue) { maxDate = DateTime.Now; } if (!minDate.HasValue) { minDate = DateTime.Now.AddDays(-30); } if (minDate < MinDateThresh) { minDate = MinDateThresh; } if (MaxDateThresh < maxDate) { maxDate = MaxDateThresh; } MinDate = minDate; MaxDate = maxDate; /* * if (MinDate.Value.Date == MaxDate.Value.Date) * MinDate = MaxDate.Value.AddDays(Days * -1); */ var range = (int)MaxDate.Value.Subtract(MinDate.Value).TotalDays; AccessiblePeriods = AllPeriods.Select(x => new { Val = x, Can = (range / x) >= 2 }) .Where(x => x.Can) .Select(x => x.Val) .ToList(); if (AccessiblePeriods.Count == 0) { AccessiblePeriods = new List <int>() { 1 } } ; _orders = orders; Range = new List <GraphPeriod>(); var currentMaxPoint = MaxDate.Value; int counter = 0; while (currentMaxPoint.Date >= MinDate.Value.Date) { Range.Add(new GraphPeriod(Days, orders) { MaxDate = currentMaxPoint, MinDate = currentMaxPoint.AddDays(Days * -1), AccessiblePeriods = AccessiblePeriods, }); currentMaxPoint = currentMaxPoint.AddDays(Days * -1); counter++; if (counter > 60) { break; } } Range.Reverse(); return(Range); }
protected void ProcessPageRequest(SPWeb web) { if (!string.IsNullOrWhiteSpace(Page.Request[NewPeriod])) { Page.Response.Cookies.Remove(EpmLiveTsPeriod); Page.Request.Cookies.Remove(EpmLiveTsPeriod); var myCookie = new HttpCookie(EpmLiveTsPeriod) { [PeriodText] = Page.Request[NewPeriod], Expires = DateTime.Now.AddMinutes(30) }; Page.Response.Cookies.Add(myCookie); } var period = string.Empty; if (Page.Request.Cookies[EpmLiveTsPeriod] != null) { period = Page.Request.Cookies[EpmLiveTsPeriod][PeriodText]; } if (string.IsNullOrWhiteSpace(period)) { using (var sqlCommand = new SqlCommand( "SELECT period_id from TSPERIOD where period_start<=@dtchecked and period_end>=@dtchecked and locked = 0 and site_id=@siteid", Connection) { CommandType = CommandType.Text }) { sqlCommand.Parameters.AddWithValue("@dtchecked", DateTime.Now); sqlCommand.Parameters.AddWithValue("@siteid", web.Site.ID); using (var dataReader = sqlCommand.ExecuteReader()) { Period = dataReader.Read() ? dataReader.GetInt32(0) : int.Parse(Periods.GetKey(0).ToString()); } } } else { Period = int.Parse(period); } var tempAllPeriods = new StringBuilder(AllPeriods); foreach (DictionaryEntry dictionaryEntry in Periods) { tempAllPeriods.Append($",{dictionaryEntry.Value}|{dictionaryEntry.Key}"); if (Period == (int)dictionaryEntry.Key) { CurrentPeriodName = dictionaryEntry.Value.ToString(); if (Periods.IndexOfKey(dictionaryEntry.Key) > 0) { PreviousPeriod = Periods.GetKey(Periods.IndexOfKey(dictionaryEntry.Key) - 1).ToString(); } if (Periods.IndexOfKey(dictionaryEntry.Key) < Periods.Count - 1) { NextPeriod = Periods.GetKey(Periods.IndexOfKey(dictionaryEntry.Key) + 1).ToString(); } } } AllPeriods = tempAllPeriods.ToString(); if (AllPeriods.Length > 0) { AllPeriods = AllPeriods.Substring(1); } using (var command = new SqlCommand("SELECT locked from TSPERIOD where period_id=@periodid and site_id=@site_id", Connection) { CommandType = CommandType.Text }) { command.Parameters.AddWithValue("@periodid", Period); command.Parameters.AddWithValue("@site_id", web.Site.ID); using (var executeReader = command.ExecuteReader()) { Status = OpenStatus; if (executeReader.Read()) { if (executeReader.GetBoolean(0)) { Status = ClosedStatus; SetToolBarControlsVisible(); } } } } }