/// <summary> /// Generates LINQ which selected surfaces. /// </summary> /// <param name="db">WebMech.Web.WebMechDataContext which specifies /// object relation mapping to database.</param> /// <param name="filter">WebMech.Web.SearchFilterData which specifies /// filter for selection of surfaces.</param> /// <param name="allRows">System.Boolean that indicates /// whether query will contain all rows or selected rows.</param> /// <returns>System.Linq.IQueryable that specifies /// the final query to database.</returns> private IQueryable<Surface> GetSurfaceQuery(WebMechDataContext db, SearchFilterData filter, bool allRows) { IQueryable<Surface> query = (from s in db.Surfaces select s); // filtering if (filter.SearchType == SearchType.LastMonths) query = query.Where(s => s.modification_date > DateTime.Now.Date.AddMonths(-filter.LastMonths)); else if (filter.SearchType == SearchType.DateRange) query = query.Where(s => (s.creation_date >= filter.From) && (s.creation_date <= filter.To)); // sorting if (filter.SortType == SortType.Name) { if (filter.SortDirection == SortDirection.Ascending) query = query.OrderBy(s => s.name); else query = query.OrderByDescending(s => s.name); } else if (filter.SortType == SortType.Date) { if (filter.SortDirection == SortDirection.Ascending) query = query.OrderBy(s => s.creation_date); else query = query.OrderByDescending(s => s.creation_date); } else if (filter.SortType == SortType.NumberOfSamples) { if (filter.SortDirection == SortDirection.Ascending) query = query.OrderBy(s => s.Samples.Count); else query = query.OrderByDescending(s => s.Samples.Count); } if (allRows) return query; return query.Skip(filter.Start - 1).Take(filter.Count); }
/// <summary> /// Gets information about surface's pagination according to filter. /// </summary> /// <param name="filterData">WebMech.Web.SearchFilterData which specifies /// filter for selection of surfaces.</param> /// <returns>A WebMech.Web.PageInfoData that specifies /// data object of pagination.</returns> public PageInfoData GetSurfaceListPageInfo(SearchFilterData filterData) { LogIt.Info("GetSurfaceListPageInfo(SearchType = " + filterData.SearchType.ToString() + ", SortType = " + filterData.SortType.ToString() + ")"); WebMechDataContext db = new WebMechDataContext(); int total = GetSurfaceQuery(db, filterData, true).Count(); bool isNext = (filterData.Start + filterData.Count) <= total; bool isPrev = filterData.Start > filterData.Count; return new PageInfoData { Start = filterData.Start, End = Math.Min(filterData.Start + filterData.Count - 1, total), Total = total, IsNext = isNext, IsPrevious = isPrev }; }
/// <summary> /// Gets information about sample's pagination according to filter. /// </summary> /// <param name="filterData">WebMech.Web.SearchFilterData which specifies /// filter for selection of surfaces.</param> /// <param name="surfaceData">A WebMech.Web.SurfaceData that specifies /// data object of surface.</param> /// <returns>A WebMech.Web.PageInfoData that specifies /// data object of pagination.</returns> public PageInfoData GetSampleListPageInfo(SearchFilterData filterData, SurfaceData surfaceData) { LogIt.Info("GetSampleListPageInfo(Id = " + surfaceData.Id.ToString() + ")"); WebMechDataContext db = new WebMechDataContext(); var totalQuery = from s in db.Samples where s.surface_id == surfaceData.Id orderby s.sample_date descending select s; int total = totalQuery.Count(); bool isNext = (filterData.Start + filterData.Count) <= total; bool isPrev = filterData.Start > filterData.Count; return new PageInfoData { Start = filterData.Start, End = Math.Min(filterData.Start + filterData.Count - 1, total), Total = total, IsNext = isNext, IsPrevious = isPrev }; }
/// <summary> /// Gets list of surfaces according to filter. /// </summary> /// <param name="filterData">WebMech.Web.SearchFilterData which specifies /// filter for selection of surfaces.</param> /// <returns>A System.Collections.Generic.List that specifies /// list of data objects of surface.</returns> public List<SurfaceData> GetSurfaceList(SearchFilterData filterData) { LogIt.Info("GetSurfaceList(Start = " + filterData.Start.ToString() + ", Count = " + filterData.Count.ToString() + ")"); WebMechDataContext db = new WebMechDataContext(); List<SurfaceData> surfaceList = new List<SurfaceData>(); IQueryable<Surface> surfaces = GetSurfaceQuery(db, filterData, false); foreach (Surface surface in surfaces) surfaceList.Add(SurfaceToData(surface)); return surfaceList; }
/// <summary> /// Gets list of samples according to filter. /// </summary> /// <param name="filterData">WebMech.Web.SearchFilterData which specifies /// filter for selection of surfaces.</param> /// <param name="surfaceData">A WebMech.Web.SurfaceData that specifies /// data object of surface.</param> /// <returns>A System.Collections.Generic.List that specifies /// list of data objects of sample.</returns> public List<SampleData> GetSampleList(SearchFilterData filterData, SurfaceData surfaceData) { LogIt.Info("GetSampleList(Id = " + surfaceData.Id.ToString() + ")"); WebMechDataContext db = new WebMechDataContext(); var samples = (from m in db.Samples where m.surface_id == surfaceData.Id orderby m.sample_date descending select m).Skip(filterData.Start - 1).Take(filterData.Count); List<SampleData> sampleList = new List<SampleData>(); foreach (Sample sample in samples) { SampleData sampleData = SampleToData(sample); var parameters = (from p in db.Parameters where p.sample_id == sample.sample_id orderby p.order select p); sampleData.ParameterList = new List<ParameterData>(); foreach (Parameter parameter in parameters) sampleData.ParameterList.Add(ParameterToData(parameter)); sampleList.Add(sampleData); } return sampleList; }