Exemple #1
0
        public static Task<List<QuickDocument>> GetQuickDocuments(DocumentsFilterObject documentsFilterObject)
        {
            var task = new TaskCompletionSource<List<QuickDocument>>();
            var cee = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cee.GetDocumentsByFilterCompleted += (s, e) => task.SetResult(Serializer.Deserialize<List<QuickDocument>>(new MemoryStream(e.Result)));
            cee.GetDocumentsByFilterAsync(documentsFilterObject);
            return task.Task;
        }
        public byte[] GetDocumentsByFilter(DocumentsFilterObject documentsFilterObject)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();

                List<QuickDocument> documents = new List<QuickDocument>();

                var query = (from x in cee.Documents.Include("DocumentVersions").Include("DocumentAssignedLocations") select x);

                //Keyword
                if (!String.IsNullOrEmpty(documentsFilterObject.Keyword))
                {
                    string[] textArray = CommonUtils.GetSearchTextArray(documentsFilterObject.Keyword);

                    query = query.Where(BuildDocumentKeywordPredicate(documentsFilterObject, textArray));

                }

                //AreaId
                if (documentsFilterObject.AreaId.HasValue)
                {
                    query = query.Where(x => x.AreaId == documentsFilterObject.AreaId.Value);
                }

                //Document Discipline
                if (documentsFilterObject.DocumentDisciplineId.HasValue)
                {
                    query = query.Where(x => x.DisciplineId == documentsFilterObject.DocumentDisciplineId.Value);
                }

                //Document Type
                if (documentsFilterObject.DocumentTypeId.HasValue)
                {
                    query = query.Where(x => x.DocumentTypeId == documentsFilterObject.DocumentTypeId.Value);
                }

                //Document Purchase Order
                if (documentsFilterObject.DocumentPurchaseOrderId.HasValue)
                {
                    query = query.Where(x => x.PurchaseOrderId == documentsFilterObject.DocumentPurchaseOrderId.Value);
                }

                //Document Author
                if (documentsFilterObject.DocumentAuthorId.HasValue)
                {
                    query = query.Where(x => x.DocumentAuthorId == documentsFilterObject.DocumentAuthorId.Value);
                }

                //Versions
                switch (documentsFilterObject.DocumentVersionFilter)
                {
                    case CommonUtils.DocumentVersionFilter.RequireDrafting:
                        query = query.Where(x =>
                            x.DocumentVersions.Select(d => d.Version).Max() > 0
                            && (x.DocumentVersions.Select(d => d.Version).Max() - Math.Floor((x.DocumentVersions.Select(d => d.Version).Max()))) > 0);
                        break;
                    case CommonUtils.DocumentVersionFilter.NoVersions:
                        query = query.Where(x => x.DocumentVersions.Count == 0);
                        break;
                    case CommonUtils.DocumentVersionFilter.NoNativeExist:
                        query = query.Where(x => x.DocumentVersions.All(dv => dv.Native == false));
                        break;
                    case CommonUtils.DocumentVersionFilter.NoPdfExist:
                        query = query.Where(x => x.DocumentVersions.All(dv => dv.Native));
                        break;

                    case CommonUtils.DocumentVersionFilter.Latest:
                        query = query.Where(x =>
                            x.DocumentVersions.Any());
                        break;

                }

                //IN Out Status
                if (documentsFilterObject.CheckedOut.HasValue)
                {
                    query = query.Where(x => x.DocumentVersions.Any(v => v.CheckedOut == documentsFilterObject.CheckedOut.Value));
                }

                //DOc Status (IsActive)
                if (documentsFilterObject.IsActive.HasValue)
                {
                    query = query.Where(x => x.IsActive == documentsFilterObject.IsActive.Value);
                }

                //Document Location
                if (documentsFilterObject.DocumentLocationId.HasValue)
                {
                    query = query.Where(x => x.DocumentAssignedLocations.Select(l => l.Id).Contains(documentsFilterObject.DocumentLocationId.Value));
                }

                documents = (from x in query orderby x.Name
                    select new QuickDocument
                    {
                        Id = x.Id,
                        Name = x.Name,
                        Description = x.Description,
                        IsActive = x.IsActive
                    }).ToList();

                sw.Stop();
                Debug.WriteLine("It took {0} seconds to get documents from GetDocumentsByFilter()", sw.Elapsed.TotalSeconds);

                MemoryStream byteStream = new MemoryStream();
                Serializer.Serialize(byteStream, documents);

                return byteStream.ToArray();

            }
        }
        private void ProcessSearchFilter()
        {
            DocumentsFilterObject dfo = new DocumentsFilterObject();

            //IsActive
            if (SelectedDocumentStatus != null && SelectedDocumentStatus != All) dfo.IsActive = SelectedDocumentStatus.ToLower() == "active";

            //Keyword

            if (!String.IsNullOrEmpty(Keyword))
            {
                dfo.Keyword = Keyword;
                dfo.SearchDescription = DescriptionChecked;
                dfo.SearchOriginator = OriginatorChecked;
                dfo.SearchVendorRef = VendorRefChecked;
                dfo.SearchMaintSysId = MaintSysIdChecked;
                dfo.SearchNotes = NotesChecked;
            }

            //Area
            if (SelectedArea != null && SelectedArea.Name != All) dfo.AreaId = SelectedArea.Id;

            //DISCIPLINE
            if (SelectedDocumentDiscipline != null && SelectedDocumentDiscipline.Name != All) dfo.DocumentDisciplineId = SelectedDocumentDiscipline.Id;

            //DocumentType
            if (SelectedDocumentType != null && SelectedDocumentType.Name != All) dfo.DocumentTypeId = SelectedDocumentType.Id;

            //PURCHASEORDER
            if (SelectedPurchaseOrder != null && SelectedPurchaseOrder.Name != All) dfo.DocumentPurchaseOrderId = SelectedPurchaseOrder.Id;

            //DocumentAuthor
            if (SelectedDocumentAuthor != null && SelectedDocumentAuthor.Name != All) dfo.DocumentAuthorId = SelectedDocumentAuthor.Id;

            //VERSIONS
            if (SelectedDocumentVersionFilter != null) dfo.DocumentVersionFilter = (CommonUtils.DocumentVersionFilter) SelectedDocumentVersionFilter.Id;

            //STATUS (CHecked In/ Out)
            if (SelectedInOutStatus != null && SelectedInOutStatus != All) dfo.CheckedOut = SelectedInOutStatus == "Checked Out";

            //DocumentLocation
            if (SelectedDocumentLocation != null && SelectedDocumentLocation.Name != All) dfo.DocumentLocationId = SelectedDocumentLocation.Id;

            IsGridBusy = true;

            DatabaseLoader.GetQuickDocuments(dfo).ContinueWith((getDocumentsTask) =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    var documents = getDocumentsTask.Result;
                    Documents = new ObservableCollection<QuickDocument>(documents);

                   //Update Id Cache!
                    CMS.Cache.FilteredExportDocIdList = (from x in Documents select x.Id).ToList();

                    RaisePropertyChanged("Documents");
                    IsGridBusy = false;
                });
            });
        }
        private void ProcessSearchFilter()
        {
            IsGridBusy = true;
            DocumentsFilterObject dfo = new DocumentsFilterObject {SearchDescription = true};

            //IsActive
            if (SelectedDocumentStatus != null && SelectedDocumentStatus != All) dfo.IsActive = SelectedDocumentStatus.ToLower() == "active";

            //Keyword
            if (!String.IsNullOrEmpty(Keyword)) { dfo.Keyword = Keyword; }

            //Area
            if (SelectedArea != null && SelectedArea.Name != All) dfo.AreaId = SelectedArea.Id;

            //DISCIPLINE
            if (SelectedDocumentDiscipline != null && SelectedDocumentDiscipline.Name != All) dfo.DocumentDisciplineId = SelectedDocumentDiscipline.Id;

            //DocumentType
            if (SelectedDocumentType != null && SelectedDocumentType.Name != All) dfo.DocumentTypeId = SelectedDocumentType.Id;

            //PURCHASEORDER
            if (SelectedPurchaseOrder != null && SelectedPurchaseOrder.Name != All) dfo.DocumentPurchaseOrderId = SelectedPurchaseOrder.Id;

            //DocumentAuthor
            if (SelectedDocumentAuthor != null && SelectedDocumentAuthor.Name != All) dfo.DocumentAuthorId = SelectedDocumentAuthor.Id;

            //VERSIONS
            if (SelectedDocumentVersionFilter != null) dfo.DocumentVersionFilter = (CommonUtils.DocumentVersionFilter) SelectedDocumentVersionFilter.Id;

            //STATUS (CHecked In/ Out)
            if (SelectedInOutStatus != null && SelectedInOutStatus != All) dfo.CheckedOut = SelectedInOutStatus == "Checked Out";

            //DocumentLocation
            if (SelectedDocumentLocation != null && SelectedDocumentLocation.Name != All) dfo.DocumentLocationId = SelectedDocumentLocation.Id;

            DatabaseLoader.GetQuickDocuments(dfo).ContinueWith((getDocumentsTask) =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    var documents = getDocumentsTask.Result;

                    if (mExistingDocIds != null)
                    {
                        Documents = (from x in documents where !mExistingDocIds.Contains(x.Id) select x).ToList();
                    }
                    else
                    {
                        Documents = documents;
                    }
                    RaisePropertyChanged("Documents");
                    IsGridBusy = false;
                });
            });
        }