public IList <NotParcedStat> FindStat(ISession session)
        {
            SortKeyMap = new Dictionary <string, string> {
                { "Supplier", "Supplier" },
                { "SupplierId", "SupplierId" },
                { "RegionName", "RegionName" },
                { "DocumentsCount", "DocumentsCount" }
            };
            OnlyNoParsed = true;
            var criteria = GetCriteriaForView(Period.Begin, Period.End);

            criteria.Add(Expression.IsNull("d.Id"));
            criteria.Add(Expression.Eq("DocumentType", DocumentType.Waybill));

            var documents = criteria.GetExecutableCriteria(session).ToList <DocumentLog>();

            //var documents = AcceptPaginator(criteria);

            var groupedDocs   = documents.GroupBy(d => d.SupplierId);
            var documentStats = new List <NotParcedStat>();

            foreach (var groupedDoc in groupedDocs)
            {
                var stat = new NotParcedStat {
                    SupplierId     = int.Parse(groupedDoc.Key),
                    Supplier       = groupedDoc.First().Supplier,
                    RegionName     = groupedDoc.First().RegionName,
                    DocumentsCount = groupedDoc.Count()
                };
                foreach (var clientGroup in groupedDoc.GroupBy(s => s.ClientId))
                {
                    stat.DocumentToClientsCount += String.Format("{0}: {1}; ", clientGroup.First().Client, clientGroup.Count());
                }
                documentStats.Add(stat);
            }
            if (!String.IsNullOrEmpty(SortBy))
            {
                var propertyInfo = typeof(NotParcedStat).GetProperty(SortBy);
                if (SortDirection.Contains("asc"))
                {
                    documentStats = documentStats.OrderBy(d => propertyInfo.GetValue(d, null)).ToList();
                }
                else
                {
                    documentStats = documentStats.OrderByDescending(d => propertyInfo.GetValue(d, null)).ToList();
                }
            }
            else
            {
                documentStats = documentStats.OrderBy(d => d.Supplier).ThenBy(d => d.RegionName).ToList();
            }
            return(documentStats);
        }
        private IList <ParsedWaybillsHeader> ApplySort(IList <ParsedWaybillsHeader> items)
        {
            if (String.IsNullOrEmpty(SortBy))
            {
                return(items);
            }
            var propertyInfo = typeof(ParsedWaybillsHeader).GetProperty(SortBy);

            if (SortDirection.Contains("asc"))
            {
                items = items.OrderBy(r => propertyInfo.GetValue(r, null)).ToList();
            }
            else
            {
                items = items.OrderByDescending(r => propertyInfo.GetValue(r, null)).ToList();
            }
            return(items);
        }
Ejemplo n.º 3
0
        private IList <BaseItemForTable> ApplySort(IList <FormPositionItem> items)
        {
            if (String.IsNullOrEmpty(SortBy))
            {
                return(items.Cast <BaseItemForTable>().ToList());
            }
            var propertyInfo = typeof(FormPositionItem).GetProperty(SortBy);

            var groupedItems = items.GroupBy(r => r.SupplierCode);

            if (SortDirection.Contains("asc"))
            {
                groupedItems = groupedItems.OrderBy(r => r.Max(item => propertyInfo.GetValue(item, null)));
            }
            else
            {
                groupedItems = groupedItems.OrderByDescending(r => r.Max(item => propertyInfo.GetValue(item, null)));
            }
            return(groupedItems.SelectMany(r => r.Where(a => true)).Cast <BaseItemForTable>().ToList());
        }