//******************************************************* // // SortGridData methods sorts the TimeEntryGrid based on which // sort field is being selected. Also does reverse sorting based on the boolean. // //******************************************************* private void SortGridData(TimeEntriesCollection list, string sortField, bool asc) { TimeEntriesCollection.TimeEntryFields sortCol = TimeEntriesCollection.TimeEntryFields.InitValue; switch (sortField) { case "EntryDate": sortCol = TimeEntriesCollection.TimeEntryFields.Day; break; case "ProjectName": sortCol = TimeEntriesCollection.TimeEntryFields.Project; break; case "CategoryName": sortCol = TimeEntriesCollection.TimeEntryFields.Category; break; case "Duration": sortCol = TimeEntriesCollection.TimeEntryFields.Hours; break; case "Description": sortCol = TimeEntriesCollection.TimeEntryFields.Description; break; default: break; } list.Sort(sortCol, asc); }
private static TimeEntriesCollection <T> CreateTimeEntriesCollection <T> ( TestFeed feed, int bufferMilliseconds, params TimeEntryData[] timeEntries) where T : ITimeEntryHolder { // First create a collection with no time buffer to add the firs items var col1 = new TimeEntriesCollection <T> (feed, 0, false, false); foreach (var entry in timeEntries) { // Create a new entry to protect the reference; // This will run synchronous as we're not querying data from the database feed.Push(new TimeEntryData(entry), DataAction.Put); } // Create a new collection with the desired buffer if (bufferMilliseconds > 0) { var col2 = new TimeEntriesCollection <T> (feed, bufferMilliseconds, false, false); col2.Reset(col1.Data); return(col2); } else { return(col1); } }
//******************************************************* // // DrawTimeGraph method creates the bar graph on the fly. // Binds accordingly to number hours in each day of the week. // //******************************************************* private void DrawTimeGraph(TimeEntriesCollection chartData, DataTable dtWeek) { // Assume dtWeek is already in the correct order according to FirstDayOfWeek Setting. Hashtable htWeekSummary = new Hashtable(7); //7 days of data - key: EntryDate | value: Duration. // x & y values holder StringBuilder xValues = new StringBuilder(); StringBuilder yValues = new StringBuilder(); //Initialize htWeekSummary to start with first day of week setting. foreach (DataRow row in dtWeek.Rows) { htWeekSummary.Add(Convert.ToDateTime(row["Date"]).ToShortDateString(), 0m); } // Summarize data from grid Group By Days of Week. foreach (BusinessLogicLayer.TimeEntry time in chartData) { string key = time.EntryDate.ToShortDateString(); Decimal dayDuration = Convert.ToDecimal(htWeekSummary[key]); dayDuration += time.Duration; htWeekSummary[key] = dayDuration; } //Build x & y values for graph. int index = 1; CultureInfo cultureRo = new CultureInfo("ro-RO"); foreach (DataRow row in dtWeek.Rows) { string key = Convert.ToDateTime(row["Date"]).ToShortDateString(); string currentDay = Convert.ToDateTime(key).ToString("dddd", cultureRo); string currentHour = Convert.ToString(htWeekSummary[key]); xValues.Append(currentDay); yValues.Append(currentHour); //Don't append separator if this is the last item. if (index != dtWeek.Rows.Count) { xValues.Append("|"); yValues.Append("|"); } index++; } //Attach image generator to image. TimeGraph.ImageUrl = "TimeEntryBarChart.aspx?" + "xValues=" + xValues.ToString() + "&yValues=" + yValues.ToString(); }
//******************************************************* // // BindTimeSheet method databinds the TimeEntryGrid based on the user // currently logged in and user which is being queried. // //******************************************************* private void BindTimeSheet(int queryUserID, int userID, DateTime start, DateTime end) { TimeEntriesCollection entryList = BusinessLogicLayer.TimeEntry.GetEntries(queryUserID, userID, start, end); // Sort datagrid if it is not empty. if (entryList != null) { SortGridData(entryList, SortField, SortAscending); } // Draw time graph with new dataset. DrawTimeGraph(entryList, _dayListTable); TimeEntryGrid.DataSource = entryList; TimeEntryGrid.DataBind(); }
private void SyncCollectionView () { DisposeCollection (); IsGroupedMode = ServiceContainer.Resolve<ISettingsStore> ().GroupedTimeEntries; collectionFeed = new TimeEntriesFeed (); var col = new TimeEntriesCollection (collectionFeed, IsGroupedMode); Collection = col; }