Esempio n. 1
0
        public DocumentSearchResult SearchDocuements(DocumentsSearchCriteria searchCriteria, int page, int itemsOnPage)
        {
            DocumentSearchResult searchResult = new DocumentSearchResult()
            {
            };

            return(new DocumentSearchResult());
        }
Esempio n. 2
0
        public ActionResult Search(FormCollection formValues, int ItemsCount, int?p)
        {
            int?page        = p;
            int itemsOnPage = ItemsCount;

            DocumentsSearchCriteria searchCriteria = new DocumentsSearchCriteria();

            if (formValues != null)
            {
                UpdateModel <DocumentsSearchCriteria>(searchCriteria, formValues.AllKeys);
            }
            else
            {
                searchCriteria = Session["doc_sc"] as DocumentsSearchCriteria;
            }

            // olewamy sortowanie bo zmniejsza wydajnoϾ
            //DocumentsSortCriteria sortCriteria = new DocumentsSortCriteria();
            //if (formValues != null)
            //    UpdateModel<DocumentsSortCriteria>(sortCriteria, formValues.AllKeys);
            //else
            //    sortCriteria = Session["doc_soc"] as DocumentsSortCriteria;


            DocumentSearchViewModel viewModel = new DocumentSearchViewModel()
            {
                SearchCriteria = searchCriteria,
                //SortCriteria = sortCriteria,
                //SearchResults = new PaginatedList<DocumentDetails>(_repository.SearchDocuments(searchCriteria).SortDocuments(sortCriteria).AsQueryable<DocumentDetails>(), page ?? 0, itemsOnPage),
                IsSearchPerformed = true,
                Categories        = _dictRepository.GetCategories().ToList(),
                Senders           = _dictRepository.GetSenders().ToList(),
                Types2            = _dictRepository.GetTypes2().ToList()
            };


            Session["doc_sc"] = searchCriteria;
            //Session["doc_soc"] = sortCriteria;
            Session["doc_ic"] = ItemsCount;
            Session["doc_p"]  = p;


            if (searchCriteria.CategoryID.HasValue)
            {
                viewModel.Types = _dictRepository.GetTypes(searchCriteria.CategoryID.Value).ToList();
            }

            return(View(viewModel));
        }
Esempio n. 3
0
        public List <DocumentDetails> SearchDocuments(DocumentsSearchCriteria searchCriteria)
        {
            List <DocumentDetails> result = new List <DocumentDetails>();

            IQueryable <DocumentInfo> documents = _context.DocumentInfos.Where(s => s.ClientID == AppContext.GetCID());

            if (searchCriteria.DocumentNumber != null)
            {
                documents = documents.Where(d => d.DocumentNumber.StartsWith(searchCriteria.DocumentNumber));
            }

            if (searchCriteria.CaseNumber != null)
            {
                documents = documents.Where(d => d.CaseNumber.StartsWith(searchCriteria.CaseNumber));
            }

            if (searchCriteria.Date.HasValue && searchCriteria.Date != DateTime.MinValue)
            {
                documents = documents.Where(d => d.Date.Value.Date >= searchCriteria.Date.Value.Date);
            }

            if (searchCriteria.DateTo.HasValue && searchCriteria.DateTo != DateTime.MinValue)
            {
                documents = documents.Where(d => d.Date.Value.Date <= searchCriteria.DateTo.Value.Date);
            }

            if (searchCriteria.CategoryID.HasValue)
            {
                documents = documents.Where(d => d.CategoryID == searchCriteria.CategoryID.Value);
            }

            if (searchCriteria.TypeID.HasValue)
            {
                documents = documents.Where(d => d.TypeID == searchCriteria.TypeID.Value);
            }

            if (searchCriteria.Type2ID.HasValue)
            {
                documents = documents.Where(d => d.Type2ID == searchCriteria.Type2ID.Value);
            }

            if (!string.IsNullOrEmpty(searchCriteria.Company))
            {
                var ds = _context.Senders.Where(s => s.Company.ToLower().Contains(searchCriteria.Company.ToLower())).Select(s => s.SenderID).ToList();

                var ds2 = _context.DocumentSenders.Where(d => ds.Contains(d.SenderID)).Select(d => d.DocumentID).ToList();
                documents = documents = documents.Where(d => ds2.Contains(d.DocumentID));
            }

            if (searchCriteria.SenderID.HasValue)
            {
                var ds = _context.DocumentSenders.Where(d => d.SenderID == searchCriteria.SenderID).Select(d => d.DocumentID).ToList();
                documents = documents.Where(d => ds.Contains(d.DocumentID));
            }

            if (!string.IsNullOrEmpty(searchCriteria.Description))
            {
                documents = documents.Where(d => d.Description.Contains(searchCriteria.Description));
            }

            if (searchCriteria.CreateDate.HasValue && searchCriteria.CreateDate != DateTime.MinValue)
            {
                documents = documents.Where(d => d.CreateDate.Date >= searchCriteria.CreateDate.Value.Date);
            }

            if (searchCriteria.CreateDateTo.HasValue && searchCriteria.CreateDateTo != DateTime.MinValue)
            {
                documents = documents.Where(d => d.CreateDate.Date <= searchCriteria.CreateDateTo.Value.Date);
            }

            #region serch by tags

            if (!string.IsNullOrEmpty(searchCriteria.Tags))
            {
                documents = applySearchByTags(documents, searchCriteria.Tags);
            }

            #endregion

            #region Search In OCR Content
            Dictionary <Guid, Dictionary <Guid, string> > contentInfos = new Dictionary <Guid, Dictionary <Guid, string> >();
            if (!string.IsNullOrEmpty(searchCriteria.Text))
            {
                List <Scan> scans = new List <Scan>();
                foreach (var document in documents)
                {
                    scans.AddRange(GetDocument(document.DocumentID).Scans.ToList());
                }

                IQueryable <OcrContent> ocrContentList = _context.OcrContents
                                                         .Where(c => scans.Select(s => s.ScanID).Contains(c.ScanID));

                if (!searchCriteria.SearchOCR)
                {
                    ocrContentList = ocrContentList.Where(c => c.PageNumber == 0);
                }

                ocrContentList = ocrContentList.Where(c => c.TextContent.Contains(searchCriteria.Text));

                foreach (var ocrContent in ocrContentList)
                {
                    //jesli skan jest w jakims dokumencie
                    if (ocrContent.Scan.DocumentID.HasValue)
                    {
                        //dodajemy informacje o skanach tego dokumentu
                        if (!contentInfos.ContainsKey(ocrContent.Scan.DocumentID.Value))
                        {
                            Dictionary <Guid, string> dict = new Dictionary <Guid, string>();
                            dict.Add(ocrContent.ScanID, string.Format("{0} ({1})", ocrContent.Scan.FileName, ocrContent.PageNumber));

                            contentInfos.Add(ocrContent.Scan.DocumentID.Value, dict);
                        }
                        //a jeśli już wcześniej dodaliśmy ten dokument
                        else
                        {
                            //sprawdzamy czy dodaliśmy cos o tym skanie
                            if (contentInfos[ocrContent.Scan.DocumentID.Value].ContainsKey(ocrContent.ScanID))
                            {
                                contentInfos[ocrContent.Scan.DocumentID.Value][ocrContent.ScanID] =
                                    contentInfos[ocrContent.Scan.DocumentID.Value][ocrContent.ScanID].Replace(")", string.Concat(", ", ocrContent.PageNumber, ")"));
                            }
                            //dodajemy informacje o kolejnym skanie w tym dokumencie
                            else
                            {
                                contentInfos[ocrContent.Scan.DocumentID.Value].Add(ocrContent.ScanID, string.Format("{0}({1})", ocrContent.Scan.FileName, ocrContent.PageNumber));
                            }
                        }
                    }
                }

                List <Guid> scansWithTextIDs = ocrContentList.Select(c => c.ScanID).Distinct().ToList();

                List <Guid?> documentIDs = _context.Scans
                                           .Where(s => scansWithTextIDs.Contains(s.ScanID))
                                           .Select(s => s.DocumentID).Distinct().ToList();

                documents = documents.Where(d => documentIDs.Contains(d.DocumentID));
            }
            #endregion

            foreach (DocumentInfo d in documents.ToList())
            {
                DocumentDetails details = GetDocumentDetails(d.DocumentID);
                details.DocumentSenders = d.Sender;
                if (contentInfos.ContainsKey(d.DocumentID))
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var scansDict in contentInfos[d.DocumentID])
                    {
                        sb.Append(scansDict.Value).Append(", ");
                    }
                    string scanContentInfo = sb.ToString().Substring(0, sb.ToString().Length - 2);
                    details.ScanContentInfo = scanContentInfo.Replace("(0)", "");
                }
                result.Add(details);
            }

            return(result);
        }
Esempio n. 4
0
        public ActionResult Index(FormCollection formValues, int ItemsCount, int?p)
        {
            int?page        = p;
            int itemsOnPage = ItemsCount;

            if (formValues == null)
            {
                formValues = new FormCollection();
            }


            DocumentsSearchCriteria searchCriteria = new DocumentsSearchCriteria();

            if (!TryUpdateModel <DocumentsSearchCriteria>(searchCriteria, formValues.AllKeys))
            {
                searchCriteria = Session["doc_sc"] as DocumentsSearchCriteria;
            }
            if (searchCriteria == null)
            {
                searchCriteria = new DocumentsSearchCriteria();
            }

            DocumentsSortCriteria sortCriteria = new DocumentsSortCriteria();

            if (!TryUpdateModel <DocumentsSortCriteria>(sortCriteria, formValues.AllKeys))
            {
                sortCriteria = Session["doc_soc"] as DocumentsSortCriteria;
            }

            if (sortCriteria == null)
            {
                sortCriteria = new DocumentsSortCriteria();
            }

            DocumentsViewModel viewModel = new DocumentsViewModel()
            {
                DocumentSearchModel = new DocumentSearchViewModel()
                {
                    SearchCriteria    = searchCriteria,
                    SortCriteria      = sortCriteria,
                    SearchResults     = new PaginatedList <DocumentDetails>(_repository.SearchDocuments(searchCriteria).SortDocuments(sortCriteria).AsQueryable <DocumentDetails>(), page ?? 0, itemsOnPage),
                    IsSearchPerformed = true,
                    Categories        = _dictRepository.GetCategories().ToList(),
                    Senders           = _dictRepository.GetSenders().ToList(),
                    Types2            = _dictRepository.GetTypes2().ToList()
                }
            };


            Session["doc_sc"]  = searchCriteria;
            Session["doc_soc"] = sortCriteria;
            Session["doc_ic"]  = ItemsCount;
            Session["doc_p"]   = p;


            if (searchCriteria.CategoryID.HasValue)
            {
                viewModel.DocumentSearchModel.Types = _dictRepository.GetTypes(searchCriteria.CategoryID.Value).ToList();
            }

            return(View(viewModel));
        }