public DocumentAttachmentsControl(Document document)
        {
            InitializeComponent();

            mDocument = document;

            CompositionInitializer.SatisfyImports(this);

            mViewModel = new DocumentAttachmentsViewModel(document) { View = this };
            mViewModel.UploadComplete += () =>
            {

            };

            mViewModel.Loaded += (s1) =>
                                     {
                                         Utils.ResetOriginalValues(AttachedFilesGridView);
                                         Utils.SetUpChangeEvents(AttachedFilesGridView, EventAggregator, document);
                                         DataContext = mViewModel;
                                     };

            mViewModel.ErrorOccurred += (message) =>
            {

                List<string> errors = new List<string>();
                errors.Add(message);
                this.ValidationPopup.Show(Utils.BuildValidationResultFromServerErrors("", errors));
            };

            mViewModel.CollectionChanged += (count) => { OnCollectionChanged(count); };
        }
        /// <summary>
        ///     WE ARE ADDING A NEW DOC VERSION
        /// </summary>
        /// <param name="document"> The document. </param>
        public AddDocumentVersionModel(Document document, AddEditDocumentVersionDialog view)
        {
            DialogView = view;
            ProgressBarView = view as IProgressBarView;

            mDocument = document;
            mDocumentId = document.Id;
            mCurrentEditMode = EditMode.Add;
            mDocumentVersion = new DocumentVersion { DocumentId = document.Id };
            mDocumentVersion.Date = DateTime.Now;

            OkButtonCommand = new DelegateCommand<object>(OkButtonHandler, CanExecuteOkButtonHandler);
            CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, CanExecuteOkButtonHandler);
            OpenFileDialogCommand = new DelegateCommand<object>(OpenFileDialogButtonHander, CanExecuteOkButtonHandler);

            mLatestVersion = (from x in document.DocumentVersions orderby x.Version descending select x).Take(1).FirstOrDefault();

            if (mLatestVersion != null)
            {
                Version = mLatestVersion.Version;
                AutoIncrementVersion = false;
                RaisePropertyChanged("AutoIncrementVersion");
            }

            if (DataModelLoaded != null)
            {
                DataModelLoaded();
            }
        }
        public AddEditDocumentVersionDialog(Document document, DocumentVersion documentVersion)
        {
            // Required to initialize variables
            InitializeComponent();

            Title = "Edit Document Version";
            mInEditMode = true;

            mModel = new AddDocumentVersionModel(document, documentVersion);
            mModel.DialogView = this;
            DataContext = mModel;

            mModel.OKButtonClicked += ModelOkButtonClicked;
            mModel.CancelButtonClicked += ModelCancelButtonClicked;
            mModel.TransferCompleted += () =>
                {
                    //busyIndicator.IsBusy = false;
                    this.Close();
                };

            mModel.ErrorOccurred += (message) =>
            {
                //busyIndicator.IsBusy = false;
                List<string> errors = new List<string>();
                errors.Add(message);
                this.ValidationPopup.Show(Utils.BuildValidationResultFromServerErrors("", errors));
            };
        }
        public DocumentRelatedDocumentsView(Document document)
        {
            InitializeComponent();

            mViewModel = new DocumentRelatedDocumentsViewModel(document);
            mViewModel.CollectionChanged += count => OnCollectionChanged(count);
            mViewModel.View = this;
            mViewModel.Loaded += ViewModelLoaded;
        }
Esempio n. 5
0
        public AddEditDocumentModel()
        {
            Document = new Document();
            Document.IsActive = true; //default

            LoadModel();

            OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanModify);
            CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, (x) => true);
        }
        public DocumentVersionsViewModel(Document document)
        {
            CompositionInitializer.SatisfyImports(this);
            mDocument = document;

            SelectDocumentVersionButton = new DelegateCommand<object>(SelectButtonHandler, CanModifyHandler);
            AddButton = new DelegateCommand<object>(AddButtonHandler, CanAddHandler);
            EditButton = new DelegateCommand<object>(EditButtonHandler, CanModifyHandler);
            DeleteButton = new DelegateCommand<object>(DeleteButtonHandler, CanDeleteHandler);
        }
        public DocumentLocationView(Document document)
        {
            if (DesignerProperties.IsInDesignTool) { return; }
            InitializeComponent();

            DocumentLocationsViewModel model = new DocumentLocationsViewModel(document);

            model.CollectionChanged += (count) => OnCollectionChanged(count);
            DataContext = model;
            model.View = this;
        }
        public DocumentRelatedIssuesViewModel(Document document)
        {
            CompositionInitializer.SatisfyImports(this);
            mDocument = document;

            LoadData();

            CreateCommand = new DelegateCommand<object>(AddRelatedIssueHandler, CanCreate);
            LinkCommand = new DelegateCommand<object>(LinkIssueButtonHandler, CanLink);
            ViewCommand = new DelegateCommand<object>(OpenIssueButtonHandler, CanView);
        }
        public DocumentLocationsViewModel(Document document)
        {
            CompositionInitializer.SatisfyImports(this);
            mDocument = document;

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetDocumentLocationsAsync(document.Id);

            AddCommand = new DelegateCommand<object>(AddButtonHandler, CanAdd);
            DeleteCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
        }
        public DocumentRelatedIssuesControl(Document instrument)
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            InitializeComponent();

            DocumentRelatedIssuesViewModel model = new DocumentRelatedIssuesViewModel(instrument);
            model.CollectionChanged += (count) => { OnCollectionChanged(count); };
            model.View = this;
            DataContext = model;
        }
        public AddEditDocumentVersionDialog(Document document)
        {
            // Required to initialize variables
            InitializeComponent();

            mModel = new AddDocumentVersionModel(document, this);
            DataContext = mModel;

            mModel.OKButtonClicked += ModelOkButtonClicked;
            mModel.TransferCompleted += Close;

            mModel.ErrorOccurred += (message) =>
            {
                //busyIndicator.IsBusy = false;
                List<string> errors = new List<string>();
                errors.Add(message);
                ValidationPopup.Show(Utils.BuildValidationResultFromServerErrors("", errors));
            };
        }
Esempio n. 12
0
        public DocumentViewModel(Document document)
        {
            if (document == null) throw new ArgumentNullException("document");

            CompositionInitializer.SatisfyImports(this);

            mDocument = document;

            SaveButtonCommand = new DelegateCommand<object>(SaveButtonHandler, CanExecuteOkButtonHandler);
            RemoveButtonCommand = new DelegateCommand<object>(RemoveButtonHandler, CanExecuteDeleteButtonHandler);

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetDocumentTypesCompleted += cmsWebServiceClient_GetDocumentTypesCompleted;
            cmsWebServiceClient.GetDocumentTypesAsync();

            Areas = new ObservableCollection<Area>(from x in CMS.Cache.Areas where x.IsActive && x.SiteId == CMS.AppSetting.DefaultSiteId select x);

            cmsWebServiceClient.GetDocumentAuthorsCompleted += cmsWebServiceClient_GetDocumentAuthorsCompleted;
            cmsWebServiceClient.GetDocumentAuthorsAsync();

            cmsWebServiceClient.GetDocumentDisciplinesCompleted += (s, e) =>
                {
                    DocumentDisciplines = new ObservableCollection<DocumentDiscipline>(e.Result);
                    mDisciplinesLoaded = true;
                    OnDataSourceLoaded();
                };
            cmsWebServiceClient.GetDocumentDisciplinesAsync();

            cmsWebServiceClient.GetDocumentPurchaseOrdersCompleted += (s, e) =>
            {
                DocumentPurchaseOrders = new ObservableCollection<DocumentPurchaseOrder>(e.Result);
                DocumentPurchaseOrders.Insert(0, new DocumentPurchaseOrder { Name = BLANK, Id = -1 });
                mPurchaseOrdersLoaded = true;
                OnDataSourceLoaded();
            };
            cmsWebServiceClient.GetDocumentPurchaseOrdersAsync();

            if (mDocument.DocumentVersions != null && mDocument.DocumentVersions.Count > 0)
            {
                mSelectedVersion = Document.DocumentVersions[0];
            }
        }
        public DocumentEquipmentsViewModel(Document document)
        {
            CompositionInitializer.SatisfyImports(this);
            mDocument = document;

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetDocumentEquipmentsCompleted +=
                (s1, e1) =>
                    {
                        mDocument.ModifiedObjects.EquipmentsModified = true; //mark as modified if opened.

                        cmsWebServiceClient.GetEquipmentTypesCompleted += (sender2, e2) =>
                            {
                                mEquipmentTypes = e2.Result;

                                DatabaseLoader.GetBuildEquipmentModelList(mEquipmentTypes, e1.Result).ContinueWith(getBuildEquipmentModelListTask =>
                                {
                                    CMS.UiFactory.StartNew(() =>
                                    {
                                        ModelEquipments = new ObservableCollection<CommonDocumentEquipmentModel>(getBuildEquipmentModelListTask.Result);

                                        RaisePropertyChanged("ModelEquipments");
                                        mDocument.DocumentEquipments = DocumentEquipments;

                                        TryFireLoadedEvent();
                                    });
                                });
                            };

                        cmsWebServiceClient.GetEquipmentTypesAsync();
                    };

            cmsWebServiceClient.GetDocumentEquipmentsAsync(document.Id);

            LinkCommand = new DelegateCommand<object>(LinkButtonHandler, CanLinkHandler);
            DeleteCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
            OpenEquipmentCommand = new DelegateCommand<object>(OpenEquipmentHandler, CanOpenEquipment);
        }
        public DocumentRelatedDocumentsViewModel(Document document)
        {
            CompositionInitializer.SatisfyImports(this);

            mDocument = document;

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetDocumentRelatedDocumentsCompleted += (sender, args) =>
            {
                mDocument.DocumentDocuments = args.Result;

                RaiseLoaded();

                mDictionary = Utils.BuildDictionaryForCollection(mDocument.DocumentDocuments.Select(x => x.DocumentId).ToList());
            };
            cmsWebServiceClient.GetDocumentRelatedDocumentsAsync(mDocument.Id);

            AddCommand = new DelegateCommand<object>(AddButtonHandler, CanAdd);
            DeleteCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
            OpenCommand = new DelegateCommand<object>(OpenDocumentHandler, CanView);
        }
Esempio n. 15
0
        private void InsertData(IList<DocumentDataAdapter> importData)
        {
            if (importData.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, NoDataFoundForWorkSheetMessage());
                return;
            }

            for (int i = 0; i < importData.Count; i++)
            {
                DocumentDataAdapter adapter = importData[i];

                Document document = Cee.Documents.FirstOrDefault(x => string.Compare(x.Name, adapter.Name, true, CultureInfo.CurrentCulture) == 0);

                if (MetaData.ImportType == CommonUtils.ImportType.CreateDocument)
                {
                    if (document != null)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildDuplicateNameExistsInDbMessage(adapter.Name, adapter.RowNumber)));
                        continue;
                    }

                    document = new Document();
                }

                if (!adapter.IsValid())
                {
                    foreach (string message in adapter.ErrorMessages)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, message);
                    }
                    continue;
                }
                if (!adapter.IsActive.HasValue)
                {
                    //assume true
                    document.IsActive = true;
                }
                else
                {
                    document.IsActive = adapter.IsActive.Value;
                }

                if (GetDocumentType(adapter.DocumentType, document, i)) continue;
                if (GetAuthor(adapter.Author, document, i)) continue;

                //AREA
                int areaId;
                if (base.GetAreaFailed(adapter.Area, i, out areaId, false))
                {
                    continue;
                }
                if (areaId > 0)
                {
                    document.AreaId = areaId;
                }

                if (GetDiscipline(adapter.DisciplineName, document, i))
                {
                    continue;
                }

                if (GetPurchaseOrder(adapter.PurchaseOrderName, document, i))
                {
                    continue;
                }

                document.Description = adapter.Description.ChangeNullToEmptyString();

                document.Name = adapter.Name;
                document.Notes = adapter.Notes.ChangeNullToEmptyString();

                document.VendorReference = adapter.VendorReference.ChangeNullToEmptyString();
                document.Originator = adapter.Originator.ChangeNullToEmptyString();
                document.MaintSystemId = adapter.MaintSystemId.ChangeNullToEmptyString();

                if (MetaData.ImportType == CommonUtils.ImportType.CreateDocument)
                {
                    Document savedDup = mSavedResults.FirstOrDefault(x => string.Compare(x.Name, adapter.Name, true, CultureInfo.CurrentCulture) == 0);

                    if (savedDup != null)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildDuplicateNameExistsInExcelMessage(adapter.Name, adapter.RowNumber)));
                        continue;
                    }

                    AddRevisionHistory(document);
                    Cee.Documents.Add(document);
                }

                mSavedResults.Add(document);
            }

            if (mSavedResults.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, string.Format("No Documents were processed from worksheet {0}.", WorkSheetName));
            }
            else
            {
                //SAVE
                Cee.SaveChanges();
            }
        }
Esempio n. 16
0
        private bool GetPurchaseOrder(string orderName, Document document, int i)
        {
            if (string.IsNullOrEmpty(orderName))
            {
                return false;
            }

            if (orderName.ToLower() == "null")
            {
                document.PurchaseOrderId = null;
                return true;
            }

            DocumentPurchaseOrder purchaseOrder = (from x in Cee.DocumentPurchaseOrders where x.Name.Equals(orderName, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();
            if (purchaseOrder != null)
            {
                document.PurchaseOrderId = purchaseOrder.Id;
            }
            else
            {
                RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': Could not match orderName '{2}'. Skipping this row.", WorkSheetName, i, orderName));
                return true;
            }

            return false;
        }
Esempio n. 17
0
        private bool GetDocumentType(string typeName, Document document, int i)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                if (MetaData.ImportType == CommonUtils.ImportType.CreateDocument)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': document Type is empty. Skipping this row.", WorkSheetName, i));
                    return true;
                }
                return false;
            }

            DocumentType documentType = (from x in mExistingDocumentTypes where string.Compare(x.Name, typeName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
            if (documentType == null)
            {
                RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': Could not match document Type '{2}'. Skipping this row.", WorkSheetName, i, typeName));
                return true;
            }

            document.DocumentTypeId = documentType.Id;
            return false;
        }
Esempio n. 18
0
        private bool GetDiscipline(string disciplineName, Document document, int i)
        {
            if (string.IsNullOrEmpty(disciplineName))
            {
                return false;
            }

            if (disciplineName.ToLower() == "null")
            {
                document.DisciplineId = null;
                return false;
            }

            DocumentDiscipline discipline = (from x in mExistingDisciplines where string.Compare(x.Name, disciplineName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
            if (discipline != null)
            {
                document.DisciplineId = discipline.Id;
            }
            else
            {
                RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': Could not match discipline Name '{2}'. Skipping this row.",
                    WorkSheetName, i, disciplineName));
                return true;
            }

            return false;
        }
Esempio n. 19
0
        private void AddRevisionHistory(Document document)
        {
            const decimal incrediment = 0.001m;
            var revision = new decimal(1.000);

            using (var context = new CmsEntities(5000))
            {
                List<decimal> revisions = (from x in context.DocumentRevisionHistories where x.DocumentId == document.Id orderby x.Revision descending select x.Revision).ToList();

                if (revisions.Count > 0)
                {
                    revision = revisions[0] + incrediment;
                }

                var rvh = new DocumentRevisionHistory
                {
                    Date = DateTime.Now,
                    UserId = MetaData.UserId,
                    Description = BuildRevisionHistoryInsertComment(MetaData.RevisionHistoryComment),
                    Revision = revision,
                    IsSystemMessage = true
                };

                document.DocumentRevisionHistories.Add(rvh);
            }
        }
Esempio n. 20
0
        public void ImportDocuments()
        {
            mForm.AddMessage(MessageType.Info, "-------------------- Importing Documents --------------------");
            List<Document> documents = (from x in mOldIssuesDataContext.Documents select x).ToList();
            var authors = ( from x in mCee.DocumentAuthors select x).ToList();

            foreach (Document document in documents)
            {
                if (!String.IsNullOrEmpty(document.Name))
                {
                    int areaId = Int32.Parse(document.Area);

                    var area = (from x in mCee.Areas where x.AreaNumber == areaId select x).FirstOrDefault();

                    if (area == null)
                    {
                        area = new Area {Name = document.Area, AreaNumber = areaId, SiteId = 1};
                        mCee.Areas.AddObject(area);
                        mCee.SaveChanges();
                    }

                    var documentExist = (from x in mCee.Documents where x.Name == document.Name select x).FirstOrDefault();

                    if (documentExist == null)
                    {
                        CmsEquipmentDatabase.CmsWebService.Document newDocument = new CmsEquipmentDatabase.CmsWebService.Document()
                        {
                            Name = document.Name,
                            Description = document.Description,
                            DocumentTypeId = (from x in  mCee.DocumentTypes where x.Name == document.DocumentType.Name select x).FirstOrDefault().Id,
                            AreaId = area.Id,
                            DocumentAuthorId = (from x in authors where x.Name == document.Author select x.Id).FirstOrDefault()
                        };

                        string message = String.Format("Adding Document '{0}'", newDocument.Name);
                        mForm.AddMessage(MessageType.Info, message);
                        mCee.Documents.AddObject(newDocument);
                        mCee.SaveChanges();
                    }
                    else
                    {
                        documentExist.AreaId = area.Id;
                        string message = String.Format("Document '{0}' already exist, skipping", document.Name);
                        mForm.AddMessage(MessageType.Warning, message);
                    }
                }
                else
                {
                    string message = String.Format("Document name '{0}' not valid, skipping", document.Name);
                    mForm.AddMessage(MessageType.Warning, message);
                }
            }
            mCee.SaveChanges();
        }
Esempio n. 21
0
        private static void BuildRevisonHistoryForMadeInactive(Document document, CmsEntities cee, int userId)
        {
            DocumentRevisionHistory rh = new DocumentRevisionHistory();

            rh.Description = string.Format("Document was made inactive  : {0}", document.Name);
            rh.DocumentId = document.Id;
            rh.Date = DateTime.Now;
            rh.UserId = userId;
            rh.IsSystemMessage = true;

            var latestPrh = (from x in cee.DocumentRevisionHistories
                             where x.DocumentId == document.Id
                             select x.Revision).ToList();

            if (latestPrh.Count > 0)
            {
                rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT;
            }
            else
            {
                rh.Revision = VERSIONINCREMENT;
            }
            cee.DocumentRevisionHistories.Add(rh);
        }
Esempio n. 22
0
        private void SaveDocumentInternal(int userId, Document document, CmsEntities cee)
        {
            //detach doc type
            int documentTypeId = document.DocumentTypeId;
            document.DocumentType = null;
            document.DocumentTypeId = documentTypeId;

            //detach doc author
            int documentAuthorId = document.DocumentAuthorId;
            document.DocumentAuthor = null;
            document.DocumentAuthorId = documentAuthorId;

            if (document.DisciplineId.HasValue)
            {
                //detach doc discipline
                int disciplineId = document.DisciplineId.Value;
                document.DocumentDiscipline = null;
                document.DisciplineId = disciplineId;
            }

            if (document.PurchaseOrderId.HasValue && document.PurchaseOrderId < 0)
            {
                document.DocumentPurchaseOrder = null;
                document.PurchaseOrderId = null;
            }

            if (document.PurchaseOrderId.HasValue && document.PurchaseOrderId > 0)
            {
                //detach doc purchaseOrder
                int documentPurchaseOrderId = document.PurchaseOrderId.Value;
                document.DocumentPurchaseOrder = null;
                document.PurchaseOrderId = documentPurchaseOrderId;
            }

            //detach doc Area //JB 21 DEC 2011
            int areaId = document.AreaId;
            document.Area = null;
            document.AreaId = areaId;

            Document originalObject = (from x in cee.Documents where x.Id == document.Id select x).FirstOrDefault();

            if (originalObject == null)
            {
                //Add new
                cee.Documents.Add(document);
            }
            else
            {
                originalObject.Name = document.Name;
                originalObject.AreaId = document.AreaId;
                originalObject.Description = document.Description;
                originalObject.DocumentTypeId = documentTypeId;
                originalObject.DocumentAuthorId = documentAuthorId;
                originalObject.VendorReference = document.VendorReference;
                originalObject.DisciplineId = document.DisciplineId;
                originalObject.PurchaseOrderId = document.PurchaseOrderId;
                originalObject.IsActive = document.IsActive;
                originalObject.Originator = document.Originator;
                originalObject.MaintSystemId = document.MaintSystemId;

                if (!document.IsActive)
                {
                    BuildRevisonHistoryForMadeInactive(document, cee, userId);
                }

                originalObject.Notes = document.Notes;
            }
        }
Esempio n. 23
0
        private void SaveDocumentRelatedDocuments(Document document, CmsEntities cee)
        {
            if (document.DocumentDocuments == null) { return; }

            //Delete originals
            List<DocumentEquipment> originals = (from x in cee.DocumentEquipments
                                                 where x.EquipmentId == document.Id
                                                       && x.EquipmentTypeId == (int)CommonUtils.EquipmentTypeCode.DOC
                                                 select x).ToList();
            originals.ForEach(x => cee.DocumentEquipments.Remove(x));

            foreach (DocumentEquipment documentEquipment in document.DocumentDocuments)
            {
                DocumentEquipment newObject = new DocumentEquipment
                {
                    EquipmentId = document.Id,
                    DocumentId = documentEquipment.DocumentId,
                    EquipmentTypeId = (int)CommonUtils.EquipmentTypeCode.DOC
                };

                cee.DocumentEquipments.Add(newObject);

                DocumentEquipment reverseNewObject = new DocumentEquipment
                {
                    EquipmentId = documentEquipment.DocumentId,
                    DocumentId = document.Id,
                    EquipmentTypeId = (int)CommonUtils.EquipmentTypeCode.DOC
                };

                cee.DocumentEquipments.Add(reverseNewObject);
            }
        }
Esempio n. 24
0
        private DocumentRevisionHistory BuildRevisionHistory(Document document, decimal version, CmsEntities context)
        {
            const decimal incrediment = 0.001m;
            decimal revision = new decimal(1.000);

            List<decimal> revisions = (from x in context.DocumentRevisionHistories where x.DocumentId == document.Id orderby x.Revision descending select x.Revision).ToList();

            if (revisions.Count > 0)
            {
                revision = revisions[0] + incrediment;
            }

            DocumentRevisionHistory rvh = new DocumentRevisionHistory
                {
                    Date = DateTime.Now,
                    DocumentId = document.Id,
                    UserId = MetaData.UserId,
                    Description = BuildRevisionHistoryInsertVersionComment(MetaData.RevisionHistoryComment, version),
                    Revision = revision,
                    IsSystemMessage = true
                };

            return rvh;
        }
Esempio n. 25
0
        /// <summary>
        ///     WE ARE EDITING AN EXISTING DOC VERSION
        /// </summary>
        /// <param name="document"> The document. </param>
        /// <param name="documentVersion"> The document version. </param>
        public AddDocumentVersionModel(Document document, DocumentVersion documentVersion)
        {
            mDocument = document;
            mDocumentId = documentVersion.DocumentId;
            mCurrentEditMode = EditMode.Edit;
            mDocumentVersion = documentVersion;
            mOriginalVersionNumber = documentVersion.Version;

            mLatestVersion = (from x in document.DocumentVersions orderby x.Version descending select x).Take(1).FirstOrDefault();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetDocumentVersionCompleted += GetDocumentVersionCompleted;
            cmsWebServiceClient.GetDocumentVersionAsync(documentVersion.Id);

            OkButtonCommand = new DelegateCommand<object>(OkButtonHandler, CanExecuteOkButtonHandler);
            CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, CanExecuteOkButtonHandler);
            OpenFileDialogCommand = new DelegateCommand<object>(OpenFileDialogButtonHander, CanExecuteOkButtonHandler);

            if (DataModelLoaded != null)
            {
                DataModelLoaded();
            }
        }
Esempio n. 26
0
        public DbOperationResult<QuickDocument> SaveDocument(Document document, int userId)
        {
            try
            {
                QuickDocument quickDocument;

                using (CmsEntities cee = new CmsEntities())
                {
                    //Save only changed objects
                    if (document.ModifiedObjects != null)
                    {
                        if (document.ModifiedObjects.RelatedIssuesModified)
                        {
                            SaveDocumentRelatedIssues(document, cee);
                        }

                        if (document.ModifiedObjects.DocumentAttachementsModified)
                        {
                            SaveDocumentAttachments(document.DocumentAttachments);
                        }

                        if (document.ModifiedObjects.RelatedDocumentsModified)
                        {
                            SaveDocumentRelatedDocuments(document, cee);
                        }
                    }

                    SaveDocumentInternal(userId, document, cee);
                    SaveDocumentEquipments(document, cee);
                    string docLocations = SaveDocumentLocations(document, cee);

                    cee.SaveChanges();

                    quickDocument = (from x in cee.Documents
                        where x.Id == document.Id
                        select new QuickDocument
                        {
                            Id = x.Id,
                            Name = x.Name,
                            Description = x.Description,
                            IsActive = x.IsActive
                        }).FirstOrDefault();

                    //quickDocument = (from x in cee.Documents
                    //                 where x.Id == document.Id
                    //                 select new QuickDocument
                    //                 {
                    //                     Id = x.Id,
                    //                     Name = x.Name,
                    //                     Description = x.Description,
                    //                     CheckedOutStatus = x.DocumentVersions.Any() == false
                    //                                            ? "NoVersions"
                    //                                            : x.DocumentVersions.All(p => p.CheckedOut)
                    //                                                  ? "Checked Out"
                    //                                                  : x.DocumentVersions.All(p => p.CheckedOut == false) ? "Checked In" : "Mixed",
                    //                     DocumentType = x.DocumentType.Name,
                    //                     FormattedDocumentType = x.DocumentType.Name + " (" + x.DocumentType.Description + ")",
                    //                     FormattedDocumentDiscipline = x.DisciplineId.HasValue ? x.DocumentDiscipline.Name + " (" + x.DocumentDiscipline.Description + ")" :
                    //                     x.DocumentDiscipline.Name,
                    //                     DocumentTypeCode = x.DocumentType.Code,
                    //                     Area = x.Area.Name,
                    //                     Author = x.DocumentAuthor.Name,
                    //                     VendorRef = x.VendorReference,
                    //                     MaintSystemId = x.MaintSystemId,
                    //                     Originator = x.Originator,
                    //                     Notes = x.Notes,
                    //                     DocumentDiscipline = x.DisciplineId.HasValue ? x.DocumentDiscipline.Name : "",
                    //                     DocumentPurchaseOrder = x.PurchaseOrderId.HasValue ? x.DocumentPurchaseOrder.Name : "",
                    //                     VersionFilter = x.DocumentVersions.Any()
                    //                                                               ? x.DocumentVersions.Any(n => !n.Native) == false
                    //                                                                     ? (int)CommonUtils.DocumentVersionFilter.Latest //was All
                    //                                                                     : x.DocumentVersions.Max(v => v.Version) > 0
                    //                                                                           ? x.DocumentVersions.Max(v => v.Version) - Math.Floor(x.DocumentVersions.Max(v => v.Version)) > 0
                    //                                                                                 ? (int)CommonUtils.DocumentVersionFilter.RequireDrafting
                    //                                                                                 : (int)CommonUtils.DocumentVersionFilter.All
                    //                                                                           : x.DocumentVersions.Max(v => v.Version) - Math.Ceiling(x.DocumentVersions.Max(v => v.Version)) > 0
                    //                                                                                 ? (int)CommonUtils.DocumentVersionFilter.RequireDrafting
                    //                                                                                 : (int)CommonUtils.DocumentVersionFilter.All
                    //                                                               : (int)CommonUtils.DocumentVersionFilter.NoVersions,
                    //                     NoNativeExist = x.DocumentVersions.Any() && x.DocumentVersions.All(v => v.Native == false),
                    //                     NoPdfExist = x.DocumentVersions.Any() && x.DocumentVersions.All(v => v.Native),
                    //                     DocumentLocations = docLocations,
                    //                     IsActive = x.IsActive
                    //                 }).FirstOrDefault();

                    //RequireDrafting is a Document which latest DocumentVersion version number is not 0 and it is not native
                }

                return new DbOperationResult<QuickDocument> { EntityResult = quickDocument };
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                return BuildOperationalErrorResults<QuickDocument>(ex);
            }
        }
Esempio n. 27
0
        public DocumentPanel(QuickDocument document)
        {
            InitializeComponent();

            TabChanges = new List<string>();

            CompositionInitializer.SatisfyImports(this);

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetDocumentCompleted +=
                (s, e) =>
                {
                    mDocument = e.Result;
                    mDocumentViewModel = new DocumentViewModel(mDocument);
                    mDocumentViewModel.View = this;

                    mDocumentViewModel.DataSourceLoaded +=
                        (s1) =>
                        {
                            DataContext = mDocumentViewModel;
                            LoadedDocument = mDocument;

                            //This will hook up change events on all controls
                            Utils.SetUpChangeEvents(Content, EventAggregator, mDocument);

                            DocumentControl.LoadedDocument = mDocument;

                            //Versions
                            mDocumentVersionsControl = new DocumentVersionsControl(mDocument, this);
                            mDocumentVersionsControl.CollectionChanged += (count) =>
                            {
                                mDocument.DocumentRelatedItemsCount.Versions = count;
                                SetTabHeadersText();
                            };
                            VersionsTab.Content = mDocumentVersionsControl;

                            //Issues
                            mDocumentRelatedIssuesControl = new DocumentRelatedIssuesControl(mDocument);
                            mDocumentRelatedIssuesControl.CollectionChanged += (count) =>
                            {
                                mDocument.DocumentRelatedItemsCount.Issues = count;
                                SetTabHeadersText();
                            };
                            IssuesTab.Content = mDocumentRelatedIssuesControl;

                            if (CMS.EffectivePrivileges.AdminTab.CanView ||
                                CMS.EffectivePrivileges.ElectricalTab.CanView ||
                                CMS.EffectivePrivileges.MechanicalTab.CanView ||
                                CMS.EffectivePrivileges.InstrumentTab.CanView ||
                                CMS.EffectivePrivileges.MobilePlantTab.CanView ||
                                CMS.EffectivePrivileges.PipeTab.CanView
                                )
                            {
                                DocumentEquipmentsTab.Visibility = Visibility.Visible;
                                //DocumentEquipments
                                DocumentEquipmentsView documentEquipmentsView = new DocumentEquipmentsView(mDocument);
                                documentEquipmentsView.CollectionChanged += (count) =>
                                {
                                    mDocument.DocumentRelatedItemsCount.RelatedEquipments = count;
                                    SetTabHeadersText();
                                };
                                DocumentEquipmentsTab.Content = documentEquipmentsView;
                            }

                            //HardCopyLocations
                            DocumentLocationView documentLocationView = new DocumentLocationView(mDocument);
                            documentLocationView.CollectionChanged += (count) =>
                            {
                                mDocument.DocumentRelatedItemsCount.HardCopyLocations = count;
                                SetTabHeadersText();
                            };
                            DocumentLocationsTab.Content = documentLocationView;

                            //Document Related Documents
                            DocumentRelatedDocumentsView documentRelatedDocumentsView = new DocumentRelatedDocumentsView(mDocument);
                            documentRelatedDocumentsView.CollectionChanged += (count) =>
                            {
                                mDocument.DocumentRelatedItemsCount.RelatedDocuments = count;
                                SetTabHeadersText();
                            };

                            RoutedEventHandler docsloaded = null;
                            docsloaded += (s6, e6) =>
                            {
                                //This will hook up change events on all controls
                                Utils.SetUpChangeEvents((UIElement)RelatedDocumentsTab.Content, EventAggregator, mDocument);
                                RelatedDocumentsTab.Loaded -= docsloaded;
                            };
                            RelatedDocumentsTab.Content = documentRelatedDocumentsView;

                            RelatedDocumentsTab.Loaded += docsloaded;

                            //Attachments
                            DocumentAttachmentsControl documentAttachmentsControl = new DocumentAttachmentsControl(mDocument);
                            documentAttachmentsControl.CollectionChanged += (count) =>
                            {
                                mDocument.DocumentRelatedItemsCount.Attachments = count;
                                SetTabHeadersText();
                            };
                            AttachmentsTab.Content = documentAttachmentsControl;

                            //GET Tab Counts --------------------------------------------------
                            cmsWebServiceClient.GetDocumentRelatedItemsCountCompleted += (s2, e2) =>
                            {
                                mDocument.DocumentRelatedItemsCount = e2.Result;
                                SetTabHeadersText();
                            };
                            cmsWebServiceClient.GetDocumentRelatedItemsCountAsync(mDocument.Id);

                        };
                };
            cmsWebServiceClient.GetDocumentAsync(document.Id);

            //Load Revision History
            RevisionHistory.LoadRevisionHistory(CommonUtils.TabId.Documents, document.Id);
        }
Esempio n. 28
0
        //        private List<QuickDocument> GetDocuments(string documentCodeName)
        //        {
        //            using (CmsEntities cee = new CmsEntities())
        //            {
        //                var documentTypeId = (from x in cee.DocumentTypes where x.Code.ToLower() == documentCodeName.ToLower().Trim() select x.Id).FirstOrDefault();
        //#if DEBUG
        //                Stopwatch sw = new Stopwatch();
        //                sw.Start();
        //#endif
        //                var documents = (from x in cee.Documents
        //                                 where x.DocumentTypeId == documentTypeId
        //                                 orderby x.Name
        //                                 select new QuickDocument
        //                                     {
        //                                         Id = x.Id,
        //                                         Name = x.Name,
        //                                         Description = x.Description
        //                                     }).ToList();
        //#if DEBUG
        //                sw.Stop();
        //#endif
        //                return documents;
        //            }
        //        }
        private void SaveDocumentRelatedIssues(Document document, CmsEntities cee)
        {
            //Delete IssueRelatedDocuments
            var originalIssueRelatedDocuments =
                (from x in cee.IssueRelatedDocuments where x.DocumentId == document.Id select x).ToList();
            originalIssueRelatedDocuments.ForEach(x => cee.IssueRelatedDocuments.Remove(x));

            //Save IssueRelatedDocuments
            foreach (var issueRelatedDocument in document.IssueRelatedDocuments.ToList())
            {
                issueRelatedDocument.Issue = null;
                issueRelatedDocument.Document = null;
                if (issueRelatedDocument.Documented)
                {
                    if (issueRelatedDocument.DocumentedByUser != null)
                    {
                        int documentedById = issueRelatedDocument.DocumentedByUser.Id;
                        issueRelatedDocument.DocumentedByUser = null;
                        issueRelatedDocument.DocumentedById = documentedById;
                    }
                }
                else
                {
                    issueRelatedDocument.DocumentedByUser = null;
                }
                cee.IssueRelatedDocuments.Add(issueRelatedDocument);
            }
        }