Example #1
0
        public PipeControlViewModel(Pipe pipe)
        {
            CompositionInitializer.SatisfyImports(this);

            OriginalName = pipe.Name;
            mPipe = pipe;

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

            var pidDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypePidCode);
            var upperEquipmentsTask = DatabaseLoader.GetUpperEquipments();

            List<Task> tasks = new List<Task>();
            tasks.Add(pidDocumentsTask);
            tasks.Add(upperEquipmentsTask);

            Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    mPidDocuments = pidDocumentsTask.Result;
                    mPidDocumentsLoaded = true;

                    mAllUpperEquipments = upperEquipmentsTask.Result;
                    mAllUpperEquipments.Insert(0, new UpperEquipment { Name = CMS.Constants.UpperEquipmentNullName });
                    UpperEquipments = mAllUpperEquipments;
                    mUpperEquipmentsLoaded = true;
                    RaiseLoaded();
                });
            });

            SaveButton = new DelegateCommand<object>(SaveButtonHandler, CanSaveHandler);
            DeleteButton = new DelegateCommand<object>(DeleteButtonHandler, CanDeleteHandler);
        }
        public PipeDocumentsControl(Pipe pipe)
        {
            InitializeComponent();
            mPipe = pipe;

            Loaded += PipeDocumentsControl_Loaded;
        }
        public AddEditPipeComponentDialog(Pipe pipe)
        {
            InitializeComponent();

            mModel = new AddEditPipeComponentViewModel(pipe, pipe.PipeComponents.Select(x => x.Name).ToList()) {View = this};
            mModel.Loaded += () => { DataContext = mModel; };
        }
        public PipeComponentsControl(Pipe pipe)
        {
            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);

            mPipe = pipe;
            Loaded += PipeComponentsControl_Loaded;
        }
Example #5
0
        public AddPipeDialog()
        {
            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);

            mNewPipe = new Pipe();
            PopulateData();
        }
        public PipeRelatedIssuesViewModel(Pipe pipe)
        {
            CompositionInitializer.SatisfyImports(this);
            mPipe = pipe;

            LoadData();

            CreateCommand = new DelegateCommand<object>(AddRelatedIssueHandler, CanCreate);
            LinkCommand = new DelegateCommand<object>(LinkIssueButtonHandler, CanLink);
            ViewCommand = new DelegateCommand<object>(OpenIssueButtonHandler, CanView);
        }
        public PipeComponentsViewModel(Pipe pipe)
        {
            CompositionInitializer.SatisfyImports(this);
            mPipe = pipe;

            AddComponentCommand = new DelegateCommand<object>(AddButtonHandler, CanAddHandler);
            RemoveComponentCommand = new DelegateCommand<object>(DeleteButtonHandler, CanRemoveHandler);
            EditComponentCommand = new DelegateCommand<object>(EditComponentHandler, CanModifyHandler);
            SelectComponentCommand = new DelegateCommand<object>(SelectButtonHandler, CanSelectHandler);
            MoveComponentCommand = new DelegateCommand<object>(MoveComponentHandler, CanModifyHandler);

            mDictionary = Utils.BuildDictionaryForCollection(mPipe.PipeComponents.Select(x => x.Id).ToList());
        }
        public AddEditPipeComponentDialog(Pipe pipe, PipeComponent pipeComponent)
        {
            InitializeComponent();

            Title = "Edit Pipe Component";

            mModel = new AddEditPipeComponentViewModel(pipeComponent, pipe.PipeComponents.Select(x => x.Name).ToList()) { View = this };
            mModel.Loaded += () =>
            {
                DataContext = mModel;
                Utils.ResetOriginalValues(this);
            };
        }
        public PipeAttachmentsViewModel(Pipe pipe)
        {
            CompositionInitializer.SatisfyImports(this);
            mPipe = pipe;

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetAttachmentTypesCompleted += cmsWebServiceClient_GetAttachmentTypesCompleted;
            cmsWebServiceClient.GetAttachmentTypesAsync();

            AddButtonClick = new DelegateCommand<object>(AddButtonHandler, CanAddHandler);
            DeleteButtonClick = new DelegateCommand<object>(DeleteButtonHandler, CanDeleteHandler);
            ExportButton = new DelegateCommand<object>(ExportButtonHandler, x => true);
        }
        public AddEditPipeComponentViewModel(Pipe pipe, IList<string> existingNonSavedComponents)
        {
            //NEW
            InEditMode = false;
            ExistingComponentNames = existingNonSavedComponents;

            OKButton = new DelegateCommand<object>(OKButtonHandler, CanAddHandler);
            CancelButton = new DelegateCommand<object>(CancelButtonHandler, CanAddHandler);

            mPipeComponent = new PipeComponent {Pipe = pipe, PipeId = pipe.Id};

            PopulateData();
        }
        public PipeDocumentsViewModel(Pipe pipe)
        {
            CompositionInitializer.SatisfyImports(this);
            mPipe = pipe;

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

            cmsWebServiceClient.GetPipeDocumentsCompleted += cmsWebServiceClient_GetPipeDocumentsCompleted;
            cmsWebServiceClient.GetPipeDocumentsAsync(mPipe.Id);

            AddButton = new DelegateCommand<object>(AddButtonHandler, CanAddHandler);
            DeleteButton = new DelegateCommand<object>(DeleteButtonHandler, CanDeleteHandler);
            OpenDocumentLink = new DelegateCommand<object>(OpenDocumentHandler, CanModifyHandler);
        }
        public PipeRelatedIssuesControl(Pipe pipe)
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            InitializeComponent();

            PipeRelatedIssuesViewModel model = new PipeRelatedIssuesViewModel(pipe);
            model.CollectionChanged += (count) => { OnCollectionChanged(count); };
            model.View = this;
            DataContext = model;
        }
Example #13
0
        //COMMENTED OUT BY JB 16 MAY 2013.  It seems from the UI we no longer require Category to be entered for PIPEs.
        //public bool GetCategoryFailed(string categoryName, Pipe newPipe, int rowIndex)
        //{
        //    if (string.IsNullOrEmpty(categoryName))
        //    {
        //        RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Category is blank. Skipping.", WorkSheetName, rowIndex));
        //        return true;
        //    }
        //    PipeCategory cat = (from x in mPipeRelatedObjects.PipeCategories where string.Compare(x.Name, categoryName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
        //    if (cat == null)
        //    {
        //        RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}':Could not match '{2}' Category. Skipping.", WorkSheetName, rowIndex, categoryName));
        //        return true;
        //    }
        //    newPipe.CategoryId = cat.Id;
        //    return false;
        //}
        public void GetFrom(string from, Pipe newPipe, int rowIndex)
        {
            if (string.IsNullOrEmpty(@from))
            {
                if (MetaData.ImportType == CommonUtils.ImportType.UpdatePipe)
                {
                    return;
                }
            }

            if (string.IsNullOrEmpty(@from))
            {
                RaiseMessage(CommonUtils.MessageType.Warning, String.Format("WorkSheet '{0}' Row '{1}': From is empty.", WorkSheetName, rowIndex));
                return;
            }

            newPipe.From = from.ChangeNullToEmptyString();
        }
Example #14
0
        public void GetTo(string to, Pipe newPipe, int rowIndex)
        {
            if (string.IsNullOrEmpty(to))
            {
                if (MetaData.ImportType == CommonUtils.ImportType.UpdatePipe)
                {
                    return;
                }
            }

            if (string.IsNullOrEmpty(to))
            {
                RaiseMessage(CommonUtils.MessageType.Warning, String.Format("WorkSheet '{0}' Line '{1}': To is empty.", WorkSheetName, rowIndex));
                return;
            }

            newPipe.To = to.ChangeNullToEmptyString();
        }
Example #15
0
        public DbOperationResult<QuickPipe> SavePipe(Pipe pipe, int userId)
        {
            try
            {
                using (CmsEntities cee = new CmsEntities())
                {
                    var originalPipe = (from x in cee.Pipes
                                                     .Include("Area")
                                                     .Include("PipeComponents")
                                                     .Include("PipeComponents.PipeComponentType")
                                        where x.Id == pipe.Id
                                        select x).FirstOrDefault();

                    pipe.Area = null;
                    pipe.PipeClass = null;
                    pipe.PipeSize = null;
                    pipe.PipeFluidCode = null;
                    pipe.PipeCategory = null;
                    pipe.PipeSpecialFeature = null;

                    if (originalPipe != null)
                    {
                        DeletePipeAddHistory(pipe, userId, originalPipe, cee);

                        //Save only changed objects
                        if (pipe.ModifiedObjects.PipeComponentsModified)
                        {
                            SavePipeComponents(pipe, cee, pipe.Id, userId);
                        }
                        if (pipe.ModifiedObjects.AttachmentsModified)
                        {
                            UpdatePipeAttachments(pipe, cee);
                        }
                        if (pipe.ModifiedObjects.DocumentationsModified)
                        {
                            SavePipeDocuments(pipe, cee);
                        }
                        if (pipe.ModifiedObjects.RelatedIssuesModified)
                        {
                            SavePipeRelatedIssues(pipe, cee);
                        }
                        if (pipe.ModifiedObjects.PipeAttachmentsModified)
                        {
                            SavePipeAttachments(originalPipe.PipeAttachments);
                        }

                        BuildRevisionHistory(pipe, cee);

                        cee.Entry(originalPipe).CurrentValues.SetValues(pipe);
                        cee.SaveChanges();
                    }
                    else
                    {
                        pipe.IsActive = true;
                        cee.Pipes.Add(pipe);
                        cee.SaveChanges();
                    }

                    var quickPipe = BuildQuickPipe(cee, pipe.Id);
                    return new DbOperationResult<QuickPipe> { EntityResult = quickPipe };
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());

                return BuildOperationalErrorResults<QuickPipe>(ex);
            }
        }
Example #16
0
        private bool GetSpecialFeature(Worksheet worksheet, string specialFeature, Pipe newPipe, int rowIndex)
        {
            bool skipRow = false;

            if (!string.IsNullOrEmpty(specialFeature))
            {
                //Check if the FluidCode exist in the database
                PipeSpecialFeature pipeSpecialFeature = mPipeRelatedObjects.PipeSpecialFeatures.Where(x => x.Name.ToLower() == specialFeature.Trim().ToLower()).FirstOrDefault();
                if (pipeSpecialFeature != null)
                {
                    newPipe.SpecialFeatureId = pipeSpecialFeature.Id;
                }
                else
                {
                    //Add new pipe area to the database
                    pipeSpecialFeature = new PipeSpecialFeature();
                    pipeSpecialFeature.Name = specialFeature;

                    mCee.PipeSpecialFeatures.AddObject(pipeSpecialFeature);
                    mCee.SaveChanges();

                    mPipeRelatedObjects.PipeSpecialFeatures.Add(pipeSpecialFeature);

                    RaiseMessage(MessageType.Added, string.Format("WorkSheet '{0}' Line '{1}': Added new '{2}' special feature to database.", worksheet.Name, rowIndex, specialFeature));

                    newPipe.SpecialFeatureId = pipeSpecialFeature.Id;
                }
            }
            else
            {
                RaiseMessage(MessageType.Warning, string.Format("WorkSheet '{0}' Line '{1}': special feature is empty. Skipping this row.", worksheet.Name, rowIndex));
                skipRow = true;
            }
            return skipRow;
        }
Example #17
0
        public PipePanelViewModel(int pipeId)
        {
            CompositionInitializer.SatisfyImports(this);

            var getPipeTask = DatabaseLoader.GetPipe(pipeId, true);
            List<Task> tasks = new List<Task>();
            tasks.Add(getPipeTask);

            Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    mPipe = getPipeTask.Result;
                    Pipe = mPipe;

                    mPipeControl = new PipeControl(mPipe);

                    mPipeComponentsControl = new PipeComponentsControl(mPipe);
                    View.PipeControl.Content = mPipeControl;

                    //Components
                    mPipeComponentsControl.CollectionChanged += (count) =>
                    {
                        mPipe.GeneralEquipmentRelatedItemsCount.PropertyOrComponents = count;
                        SetTabHeadersText();
                    };
                    View.ComponentsTab.Content = mPipeComponentsControl;

                    //PipeAttachmentsControl
                    mPipeAttachmentsControl = new PipeAttachmentsControl(mPipe);
                    mPipeAttachmentsControl.CollectionChanged += (count) =>
                    {
                        mPipe.GeneralEquipmentRelatedItemsCount.Attachments = count;
                        SetTabHeadersText();
                    };
                    View.AttachmentsTab.Content = mPipeAttachmentsControl;

                    //PipeIssuesControl
                    mPipeRelatedIssuesControl = new PipeRelatedIssuesControl(mPipe);
                    mPipeRelatedIssuesControl.CollectionChanged += (count) =>
                    {
                        mPipe.GeneralEquipmentRelatedItemsCount.Issues = count;
                        SetTabHeadersText();
                    };

                    View.IssueTab.Content = mPipeRelatedIssuesControl;

                    //PipeDocumentsControl
                    mPipeDocumentsControl = new PipeDocumentsControl(mPipe);
                    mPipeDocumentsControl.CollectionChanged += (count) =>
                    {
                        mPipe.GeneralEquipmentRelatedItemsCount.Documents = count;
                        SetTabHeadersText();
                    };
                    View.DocumentsTab.Content = mPipeDocumentsControl;

                    //GET Tab Counts --------------------------------------------------
                    CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
                    cmsWebServiceClient.GetPipeRelatedItemsCountCompleted += (s1, e1) =>
                    {
                        mPipe.GeneralEquipmentRelatedItemsCount = e1.Result;

                        if (Loaded != null)
                        {
                            Loaded();
                        }

                        //do this post data binding
                        SetHeadersBindings();
                        SetTabHeadersText();
                    };
                    cmsWebServiceClient.GetPipeRelatedItemsCountAsync(mPipe.Id);
                    //-------------------------------------------------------------
                });
            });
        }
Example #18
0
        private void GetDocument(Worksheet worksheet, string document, Pipe newPipe, int rowIndex)
        {
            if (!string.IsNullOrEmpty(document))
            {
                var pidDocument = (from x in mPidDocuments where x.Name.Trim().ToLower().Contains(document.ToLower()) select x).FirstOrDefault();

                if (pidDocument != null)
                {
                    newPipe.PIDDocumentId = pidDocument.Id;
                }
                else
                {
                    RaiseMessage(MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}':Could not match '{2}' P&ID document.", worksheet.Name, rowIndex, document));
                }
            }
            else
            {
                RaiseMessage(MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Document is empty.", worksheet.Name, rowIndex));
            }
        }
Example #19
0
        private bool GetFluidCode(Worksheet worksheet, string fluidCode, string fluidDescription, string fuidType, Pipe newPipe, int rowIndex)
        {
            bool skipRow = false;

            if (!string.IsNullOrEmpty(fluidCode))
            {
                //Check if the FluidCode exist in the database
                PipeFluidCode pipeFluidCode = mPipeRelatedObjects.PipeFluidCodes.Where(x => x.Name.ToLower() == fluidCode.Trim().ToLower()).FirstOrDefault();
                if (pipeFluidCode != null)
                {
                    newPipe.FluidCodeId = pipeFluidCode.Id;
                }
                else
                {
                    //Add new 
                    pipeFluidCode = new PipeFluidCode();
                    pipeFluidCode.Name = fluidCode;
                    pipeFluidCode.PhaseFluidType = fuidType;
                    pipeFluidCode.Description = fluidDescription;

                    if (!string.IsNullOrEmpty(fluidDescription))
                    {
                        pipeFluidCode.Description = fluidDescription;
                    }

                    mCee.PipeFluidCodes.AddObject(pipeFluidCode);
                    mCee.SaveChanges();

                    mPipeRelatedObjects.PipeFluidCodes.Add(pipeFluidCode);

                    RaiseMessage(MessageType.Added, string.Format("WorkSheet '{0}' Line '{1}': Added new '{2}' fluid code to database.", worksheet.Name, rowIndex, fluidCode));

                    newPipe.FluidCodeId = pipeFluidCode.Id;
                }
            }
            else
            {
                RaiseMessage(MessageType.Warning, string.Format("WorkSheet '{0}' Line '{1}': Fluid Code is empty. Skipping this row.", worksheet.Name, rowIndex));

                skipRow = true;
            }
            return skipRow;
        }
Example #20
0
        private void SavePipeRelatedIssues(Pipe pipe, CmsEntities cee)
        {
            //Delete
            List<IssueRelatedPipe> issueRelatedPipes =
                (from x in cee.IssueRelatedPipes where x.PipeId == pipe.Id select x).ToList();
            issueRelatedPipes.ForEach(x => cee.IssueRelatedPipes.Remove(x));

            //Save SaveIssueRelatedElectricalEquipments
            foreach (IssueRelatedPipe issueRelatedPipe in pipe.IssueRelatedPipes.ToList())
            {
                int oldIssueId = issueRelatedPipe.IssueId;
                int oldPipeId = issueRelatedPipe.PipeId;

                issueRelatedPipe.Issue = null;
                issueRelatedPipe.Pipe = null;

                issueRelatedPipe.IssueId = oldIssueId;
                issueRelatedPipe.PipeId = oldPipeId;

                if (issueRelatedPipe.Implemented)
                {
                    if (issueRelatedPipe.ImplementedByUser != null)
                    {
                        int implementedByUserId = issueRelatedPipe.ImplementedByUser.Id;
                        issueRelatedPipe.ImplementedByUser = null;
                        issueRelatedPipe.ImplementedById = implementedByUserId;
                    }
                }
                else
                {
                    issueRelatedPipe.ImplementedByUser = null;
                }

                if (issueRelatedPipe.Tested)
                {
                    if (issueRelatedPipe.TestedByUser != null)
                    {
                        int testedByUserId = issueRelatedPipe.TestedByUser.Id;
                        issueRelatedPipe.TestedByUser = null;
                        issueRelatedPipe.TestedById = testedByUserId;
                    }
                }
                else
                {
                    issueRelatedPipe.TestedByUser = null;
                }

                cee.IssueRelatedPipes.Add(issueRelatedPipe);
            }
        }
Example #21
0
        private void SavePipeComponents(Pipe pipe, CmsEntities cee, int pipeId, int userId)
        {
            foreach (var pipeComponent in pipe.PipeComponents)
            {
                var q = (from x in cee.PipeComponents
                         where x.Id == pipeComponent.Id
                         select x).FirstOrDefault();

                if (q != null)
                {
                    if (q.LastInspectedDate != pipeComponent.LastInspectedDate)
                    {
                        PipeRevisionHistory rv = new PipeRevisionHistory
                        {
                            PipeId = pipeId,
                            Date = DateTime.Now,
                            UserId = userId,
                            Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.", pipeComponent.Name, q.LastInspectedDate, pipeComponent.LastInspectedDate),
                            IsSystemMessage = true
                        };

                        AddPipeRevisionHistoryInternal(rv, cee);
                    }

                    //Update Pipe Componet
                    cee.Entry(q).CurrentValues.SetValues(pipeComponent);
                }
                else
                {
                    q = new PipeComponent
                    {
                        PipeId = pipeComponent.PipeId,
                        PipeComponentTypeId = pipeComponent.PipeComponentTypeId,
                        SpecialFeature = pipeComponent.SpecialFeature,
                        Ordinal = pipeComponent.Ordinal,
                        Description = pipeComponent.Description,
                        SubArea = pipeComponent.SubArea,
                        Number = pipeComponent.Number,
                        DrawingId = pipeComponent.DrawingId,
                        NextInspectionDate = pipeComponent.NextInspectionDate,
                        LastInspectedById = pipeComponent.LastInspectedById,
                        LastInspectedDate = pipeComponent.LastInspectedDate,
                        LastModifiedDate = pipeComponent.LastModifiedDate,
                        LastModifiedById = pipeComponent.LastModifiedById,
                        ManufacturerId = pipeComponent.ManufacturerId,
                        ModelId = pipeComponent.ModelId,
                        AreaId = pipeComponent.AreaId
                    };

                    //Add new Pipe Component
                    cee.PipeComponents.Add(q);
                }

                foreach (var pipeComponentPropertyValue in pipeComponent.PipePropertyValues)
                {
                    var qq = (from x in cee.PipePropertyValues
                              where x.Id == pipeComponentPropertyValue.Id
                              select x).FirstOrDefault();

                    if (qq != null)
                    {
                        cee.Entry(qq).CurrentValues.SetValues(pipeComponentPropertyValue);
                    }
                    else
                    {
                        cee.PipePropertyValues.Add(pipeComponentPropertyValue);
                    }
                }
            }
            cee.SaveChanges();
        }
Example #22
0
        private void BuildRevisionHistory(Pipe equip, CmsEntities cee)
        {
            var latestPrh = (from x in cee.PipeRevisionHistories
                             where x.PipeId == equip.Id
                             select x.Revision).ToList();

            if (latestPrh.Count > 0)
            {
                foreach (var revisionHistory in equip.PipeRevisionHistories)
                {
                    if (revisionHistory.Id == 0)
                    {
                        revisionHistory.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT;
                        cee.PipeRevisionHistories.Add(revisionHistory);
                    }
                }
            }
            else
            {
                foreach (var revisionHistory in equip.PipeRevisionHistories)
                {
                    if (revisionHistory.Id == 0)
                    {
                        revisionHistory.Revision = VERSIONINCREMENT;
                        cee.PipeRevisionHistories.Add(revisionHistory);
                    }
                }
            }
        }
Example #23
0
        private bool GetPipeClass(Worksheet worksheet, string pipeClass, Pipe newPipe, int rowIndex)
        {
            bool skipRow = false;

            if (!string.IsNullOrEmpty(pipeClass))
            {
                //Check if the Class exist in the database
                PipeClass pipeClassObj = mPipeRelatedObjects.PipeClasses.Where(x => x.Name.ToLower() == pipeClass.Trim().ToLower()).FirstOrDefault();
                if (pipeClassObj != null)
                {
                    newPipe.ClassId = pipeClassObj.Id;
                }
                else
                {
                    //Add new pipe class to the database
                    pipeClassObj = new PipeClass();
                    pipeClassObj.Name = pipeClass;

                    mCee.PipeClasses.AddObject(pipeClassObj);
                    mCee.SaveChanges();


                    mPipeRelatedObjects.PipeClasses.Add(pipeClassObj);

                    RaiseMessage(MessageType.Added, string.Format("WorkSheet '{0}' Line '{1}': Added new '{2}' class to database.", worksheet.Name, rowIndex, pipeClass));

                    newPipe.ClassId = pipeClassObj.Id;
                }
            }
            else
            {
                RaiseMessage(MessageType.Warning, string.Format("WorkSheet '{0}' Line '{1}': Class is empty. Skipping this row.", worksheet.Name, rowIndex));
                skipRow = true;
            }
            return skipRow;
        }
Example #24
0
        private bool GetSeqNo(Worksheet worksheet, string seqNo, Pipe newPipe, int rowIndex)
        {
            bool skipRow = false;

            if (!string.IsNullOrEmpty(seqNo))
            {
                int intSeqNo;

                if (Int32.TryParse(seqNo, out intSeqNo))
                {
                    newPipe.SequenceNo = intSeqNo;
                }
                else
                {
                    RaiseMessage(MessageType.Added, string.Format("WorkSheet '{0}' Line '{1}': Could not convert sequence no '{2}' to integer. Skipping this row.", worksheet.Name, rowIndex, seqNo));
                    skipRow = true;
                }
            }

            return skipRow;
        }
Example #25
0
        private void DeletePipeAddHistory(Pipe pipe, int userId, Pipe originalPipe, CmsEntities cee)
        {
            IEnumerable<PipeComponent> componentsToBeDeleted = (from x in originalPipe.PipeComponents
                                                                where !pipe.PipeComponents.Any(x1 => x1.Id == x.Id)
                                                                select x);

            PipeRevisionHistory rh = new PipeRevisionHistory();

            string[] componentMessages = (from x in componentsToBeDeleted select "Name: " + x.Name + " Type: " + x.PipeComponentType.Name).ToArray();

            if (componentMessages.Length > 0)
            {
                string removedItems = string.Join(",", componentMessages);

                rh.Description = string.Format("Pipe Components were removed : {0}", removedItems);
                rh.PipeId = pipe.Id;
                rh.Date = DateTime.Now;
                rh.UserId = userId;
                rh.IsSystemMessage = true;

                var latestPrh = (from x in cee.PipeRevisionHistories
                                 where x.PipeId == pipe.Id
                                 select x.Revision).ToList();

                if (latestPrh.Count > 0)
                {
                    rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT;
                }
                else
                {
                    rh.Revision = VERSIONINCREMENT;
                }
                cee.PipeRevisionHistories.Add(rh);
            }
            cee.SaveChanges();

            foreach (var pipeComponent in componentsToBeDeleted)
            {
                DeletePipeComponent(pipeComponent);
            }
        }
Example #26
0
        private bool GetArea(Worksheet worksheet, string area, Pipe newPipe, int rowIndex)
        {
            bool skipRow = false;

            if (!string.IsNullOrEmpty(area))
            {
                //Check if the Area exist in the database
                Area pipeArea = mPipeRelatedObjects.Areas.Where(x => x.AreaNumber.ToString() == area.Trim()).FirstOrDefault();
                if (pipeArea != null)
                {
                    newPipe.AreaId = pipeArea.Id;
                }
                else
                {
                    int intArea = 0;

                    if (Int32.TryParse(area, out intArea))
                    {
                        //Add new pipe area to the database
                        pipeArea = new Area();
                        pipeArea.Name = area;
                        pipeArea.AreaNumber = intArea;


                        mCee.Areas.AddObject(pipeArea);
                        mCee.SaveChanges();

                        mPipeRelatedObjects.Areas.Add(pipeArea);

                        RaiseMessage(MessageType.Added, string.Format("WorkSheet '{0}' Line '{1}': Added new '{2}' Area to database.", worksheet.Name, rowIndex, area));

                        newPipe.AreaId = pipeArea.Id;
                    }
                    else
                    {
                        RaiseMessage(MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Could not convert area '{2}' to integer. Skipping this row.", worksheet.Name, rowIndex, area));

                        skipRow = true;
                    }
                }
            }
            else
            {
                RaiseMessage(MessageType.Warning, string.Format("WorkSheet '{0}' Line '{1}': Area is empty. Skipping this row.", worksheet.Name, rowIndex));

                skipRow = true;
            }
            return skipRow;
        }
Example #27
0
        private void SavePipeDocuments(Pipe pipe, CmsEntities cee)
        {
            //Delete originals
            List<DocumentEquipment> originals = (from x in cee.DocumentEquipments
                                                 where x.EquipmentId == pipe.Id
                                                       && x.EquipmentTypeId == (int)CommonUtils.EquipmentTypeCode.PIPE
                                                 select x).ToList();
            originals.ForEach(x => cee.DocumentEquipments.Remove(x));

            foreach (DocumentEquipment document in pipe.PipeDocuments)
            {
                DocumentEquipment newObject = new DocumentEquipment
                    {
                        EquipmentId = pipe.Id,
                        DocumentId = document.DocumentId,
                        EquipmentTypeId = (int)CommonUtils.EquipmentTypeCode.PIPE
                    };

                cee.DocumentEquipments.Add(newObject);
            }
        }
Example #28
0
        private bool GetPipe(PipeComponentDataAdapter adapter, int rowIndex, out Pipe pipeOut)
        {
            pipeOut = null;

            int areaNumber = int.Parse(adapter.PipeAreaNumber);
            int seq = int.Parse(adapter.PipeSequence);

            Pipe pipe = (from x in Cee.Pipes
                .Include("Area")
                .Include("PipeClass")
                .Include("PipeSize")
                .Include("PipeFluidCode")
                .Include("PipeSpecialFeature")
                where
                    x.CategoryId == PIPECAT_NOTUSED
                    && x.Area.AreaNumber == areaNumber
                    && x.SequenceNo == seq
                    && String.Equals(x.PipeClass.Name, adapter.PipeClass, StringComparison.CurrentCultureIgnoreCase)
                    && String.Equals(x.PipeSize.Name, adapter.PipeSize, StringComparison.CurrentCultureIgnoreCase)
                    && String.Equals(x.PipeFluidCode.Name, adapter.PipeFluidCode, StringComparison.CurrentCultureIgnoreCase)
                    && String.Equals(x.PipeSpecialFeature.Name, adapter.PipeSpecialFeature, StringComparison.CurrentCultureIgnoreCase)
                select x).FirstOrDefault();

            if (pipe != null)
            {
                pipeOut = pipe;
            }
            else
            {
                RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Could not find pipe '{2}' in database. Skipping this row.", WorkSheetName, rowIndex, adapter.PipeTag));
                return true;
            }

            return false;
        }
Example #29
0
        private void UpdatePipeAttachments(Pipe pipe, CmsEntities cee)
        {
            foreach (PipeAttachment attachment in pipe.PipeAttachments)
            {
                PipeAttachment existing = (from x in cee.PipeAttachments
                                           where x.Filename == attachment.Filename && x.Path == attachment.Path
                                           select x).FirstOrDefault();

                if (existing != null)
                {
                    int uploadedById = existing.UploadedById;
                    int equipmentId = existing.PipeId;

                    existing.User = null;
                    existing.Pipe = null;
                    existing.AttachmentType = null;
                    existing.AttachmentTypeId = attachment.AttachmentTypeId;
                    existing.UploadedById = attachment.UploadedById;
                    existing.Description = attachment.Description;

                    existing.PipeId = equipmentId;
                    existing.UploadedById = uploadedById;
                }
            }
        }
Example #30
0
        private bool GetPipeSize(Worksheet worksheet, string size, Pipe newPipe, int rowIndex)
        {
            bool skipRow = false;
            if (!string.IsNullOrEmpty(size))
            {
                //Check if the Size exist in the database
                PipeSize pipeSize = mPipeRelatedObjects.PipeSizes.Where(x => x.Name.ToLower() == size.Trim().ToLower()).FirstOrDefault();
                if (pipeSize != null)
                {
                    newPipe.SizeId = pipeSize.Id;
                }
                else
                {
                    int intSize;

                    if (Int32.TryParse(size, out intSize))
                    {
                        //Add new pipe size to the database
                        pipeSize = new PipeSize();
                        pipeSize.Name = size;

                        mCee.PipeSizes.AddObject(pipeSize);
                        mCee.SaveChanges();

                        mPipeRelatedObjects.PipeSizes.Add(pipeSize);

                        RaiseMessage(MessageType.Added, string.Format("WorkSheet '{0}' Line '{1}': Added new '{2}' size to database.", worksheet.Name, rowIndex, size));

                        newPipe.SizeId = pipeSize.Id;
                    }
                    else
                    {
                        RaiseMessage(MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Could not convert size '{2}' to integer. Skipping this row.", worksheet.Name, rowIndex, size));
                        skipRow = true;
                    }
                }
            }
            else
            {
                RaiseMessage(MessageType.Warning, string.Format("WorkSheet '{0}' Line '{1}': Size is empty. Skipping this row.", worksheet.Name, rowIndex));
                skipRow = true;
            }

            return skipRow;
        }