public ItemLinkedListEnumerator(ItemLinkedList linkedList) { this.linkedList = linkedList; startingNode = new ItemNode(null); //linkedList.HeaderNode; startingNode.NextNode = linkedList.HeaderNode; currentNode = startingNode; //currentNode.NextNode = linkedList.HeaderNode; }
/// <summary> /// Generic function for creating matrix populated with events /// on appropriate positions. /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="period"></param> /// <returns></returns> public IMatrix CreateMatrix(DateTime startDate, DateTime endDate, MatrixSpan period) { // Cycle date DateTime cycleDate = new DateTime(startDate.Ticks); // Maximum Rows per Element int rowsMax = 0; // initialize constants here int columns = 0; // Array list with index'es of columns ArrayList usedColsArray = new ArrayList(); // remove unused items ItemLinkedList items = new ItemLinkedList(); foreach (CalendarItem item in Items) { if(item.EndDate >= startDate && endDate >= item.StartDate) { items.Add(item); } } // Initialized number of columns based on span length switch(period) { case MatrixSpan.WeekHourSpan: case MatrixSpan.HourSpan: // calculates number of hours //columns = (int)((TimeSpan)(endDate - startDate)).TotalHours * 2; //1.2.0: columns = (int)System.Math.Ceiling(((TimeSpan)(Helper.GetHourDate(endDate) // - Helper.GetHourStartDate(startDate))).TotalHours * 2); // changed cause hour span resolution is actually 30 minutes // 1.3.0 columns = (int)System.Math.Ceiling(((TimeSpan)(endDate - startDate)).TotalHours * 2); // changed cause hour span resolution is actually 30 minutes break; case MatrixSpan.WeekDaySpan: case MatrixSpan.DaySpan: columns = Helper.GetDaySpan(startDate, endDate); break; case MatrixSpan.MonthSpan: columns = endDate.Month - startDate.Month; break; } // Create Array consisting of Linked List's for each cell to improve performance object[] llEventsArray = new object[columns]; // Initialize ll array for(int index=0;index<columns;index++) { llEventsArray[index] = new ItemLinkedList(); /* foreach (CalendarItem item in Items) { if(item.IsWithinSpanEvent(period, cycleDate)) { RowsCurrent++; ((ItemLinkedList)llEventsArray[columnIndex]).Add(item); } } // Initialized number of columns based on span length cycleDate = Helper.IncrementDate(period, cycleDate); */ } //TODO: add optimization code here // Add hash table with linked list for each data cell // data cell is a row in day view, month day cell in month view // Calculate maximum number of rows for element #region Optimized CODE /* foreach(CalendarItem item in items) { int startIndex = 0; int endIndex = 0; switch(period) { case MatrixSpan.WeekHourSpan: case MatrixSpan.HourSpan: if(item.StartDate<startDate) { item.EndDate } break; case MatrixSpan.WeekDaySpan: case MatrixSpan.DaySpan: break; case MatrixSpan.MonthSpan: columns = endDate.Month - startDate.Month; break; } ((ItemLinkedList)llEventsArray[columnIndex]).Add(item); } */ /* foreach (CalendarItem item in Items) { int columnIndex = 0; columnIndex = 1; if(this.ViewType == CalendarViewType.DayView && this.MultiOwner && item.Owner != this.CurrentOwner) continue; if(item.IsWithinSpanEvent(MatrixSpan.MonthSpan, cycleDate.Date)) { if(item.StartDate < cycleDate.Date) // first item { ((ItemLinkedList)llEventsArray[columnIndex]).Add(item); } RowsCurrent++; ((ItemLinkedList)llEventsArray[columnIndex]).Add(item); } } */ #endregion #region OLD CODE that was optimized for(int columnIndex=0;columnIndex<columns;columnIndex++) { int RowsCurrent = 0; int itemsPerIncrement = 0; // determines how many items are rendered/started in current increment // Check for workweek foreach (CalendarItem item in items) { if(this.ViewType == CalendarViewType.DayView && this.MultiOwner && item.Owner != this.CurrentOwner) continue; // Skip max number for day view if(this.ViewType != CalendarViewType.DayView && period != MatrixSpan.WeekHourSpan) { if(item.IsCurrentSpanEvent(columnIndex, period, cycleDate)) itemsPerIncrement++; // dont render more than specified if(itemsPerIncrement > this.MaxDisplayedItems && this.MaxDisplayedItems != 0) { // Increment for dummy node RowsCurrent++; ((ItemLinkedList)llEventsArray[columnIndex]).Add(item); break; } } if(item.IsWithinSpanEvent(period, cycleDate)) { RowsCurrent++; ((ItemLinkedList)llEventsArray[columnIndex]).Add(item); } } if(RowsCurrent > rowsMax) rowsMax = RowsCurrent; // Initialized number of columns based on span length cycleDate = Helper.IncrementDate(period, cycleDate); } #endregion // Check if Maximum number of rows is reached and adjust maximum // add 1 extra space for more element index //if(this.ViewType!=CalendarViewType.DayView || this.ViewType!=CalendarViewType.TaskView) //if(this.MaxDisplayedItems < rowsMax) // rowsMax = MaxDisplayedItems + 1; // Item MATRIX, rank = 7 IMatrix matrix = new Matrix(rowsMax, columns); // Initialize matrix with -1 values for (int i = 0; i < rowsMax; i++) for (int j = 0; j < columns; j++) matrix[i,j] = (int)MatrixConstants.EmptyField; // Return cycle back switch(period) { case MatrixSpan.WeekHourSpan: case MatrixSpan.HourSpan: // return cycle back one day cycleDate = cycleDate.AddHours(-24); break; case MatrixSpan.WeekDaySpan: case MatrixSpan.DaySpan: // return cycle back one week cycleDate = cycleDate.AddDays(-7); break; case MatrixSpan.MonthSpan: // return cycle back one week cycleDate = cycleDate.AddMonths(-12); break; } // populate matrix for(int columnIndex=0;columnIndex<columns&&rowsMax>0;columnIndex++) { // Render items within that date int rowIndex = 0; int itemsPerIncrement = 0; // determines how many items are rendered/started in current increment ItemLinkedList llItems = (ItemLinkedList)llEventsArray[columnIndex]; if(llItems.Count > 0) foreach(CalendarItem item in llItems) { /* foreach (CalendarItem item in Items) { */ if(this.ViewType == CalendarViewType.DayView && this.MultiOwner && item.Owner != this.CurrentOwner) continue; // show if current item falls into date span bool foundValue = false; foundValue = item.IsCurrentSpanEvent(columnIndex, period, cycleDate); if(foundValue) itemsPerIncrement++; // Skip max number for day view if(this.ViewType != CalendarViewType.DayView && period != MatrixSpan.WeekHourSpan) { // dont render more than specified if(itemsPerIncrement > this.MaxDisplayedItems && this.MaxDisplayedItems != 0 && rowIndex < rowsMax) { matrix[rowIndex, columnIndex] = (int)MatrixConstants.MoreElementsField; break; } } if(foundValue && rowIndex < rowsMax) PopulateMatrix(item, cycleDate, ref matrix, ref rowIndex, columnIndex, period); } // Initialized number of columns based on span length cycleDate = Helper.IncrementDate(period, cycleDate); } return matrix; }
public ItemLinkedListEnumerator(ItemLinkedList linkedList) { this.linkedList = linkedList; startingNode = new ItemNode(null);//linkedList.HeaderNode; startingNode.NextNode = linkedList.HeaderNode; currentNode = startingNode; //currentNode.NextNode = linkedList.HeaderNode; }