Пример #1
0
        public bool GetMobilePlantOwner(string hirerName, MobilePlant newEquipment, int rowIndex)
        {
            if (string.IsNullOrEmpty(hirerName))
            {
                if (MetaData.ImportType == CommonUtils.ImportType.UpdateMobilePlant)
                {
                    return false;
                }
            }

            if (string.IsNullOrEmpty(hirerName))
            {
                RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': Owner row  is blank. Skipping.", WorkSheetName, rowIndex));
                return true;
            }

            MobileOwner mobileOwner = (from x in mExistingMobileOwners where string.Compare(x.Name, hirerName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
            if (mobileOwner == null)
            {
                if (CanCreateProperties)
                {
                    mobileOwner = new MobileOwner {Name = hirerName};
                    mExistingMobileOwners.Add(mobileOwner);
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}':Could not match '{2}'Mobile Plant Owner. Skipping.",
                        WorkSheetName, rowIndex, hirerName));
                    return true;
                }
            }

            newEquipment.MobileOwnerId = mobileOwner.Id;
            return false;
        }
Пример #2
0
        public AddMobilePlantViewModel()
        {
            CompositionInitializer.SatisfyImports(this);

            mMobilePlant = new MobilePlant();

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

            //MobileHirers
            cmsWebServiceClient.GetMobileHirersCompleted += cmsWebServiceClient_GetMobileHirersCompleted;
            cmsWebServiceClient.GetMobileHirersAsync();

            //Owners
            cmsWebServiceClient.GetMobileOwnersCompleted += cmsWebServiceClient_GetMobileOwnersCompleted;
            cmsWebServiceClient.GetMobileOwnersAsync();

            //Types
            cmsWebServiceClient.GetMobilePlantTypesCompleted += cmsWebServiceClient_GetMobilePlantTypesCompleted;
            cmsWebServiceClient.GetMobilePlantTypesAsync();

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

            OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanExecuteOkButtonHandler);
            CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, x => true);
        }
        public MobilePlantDocumentsControl(MobilePlant mobilePlant)
        {
            InitializeComponent();

            mViewModel = new MobilePlantDocumentsViewModel(mobilePlant);
            mViewModel.CollectionChanged += count => OnCollectionChanged(count);
            mViewModel.View = this;
            mViewModel.Loaded += ViewModelLoaded;
        }
        public MobilePlantComponentsControl(MobilePlant mobilePlant)
        {
            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);
            mViewModel = new MobilePlantComponentsViewModel(mobilePlant);
            mViewModel.CollectionChanged += (count) => { OnCollectionChanged(count); };

            mViewModel.View = this;
            DataContext = mViewModel;
        }
        public MobilePlantRelatedIssuesViewModel(MobilePlant mobilePlant)
        {
            CompositionInitializer.SatisfyImports(this);
            mMobilePlant = mobilePlant;

            LoadData();

            CreateCommand = new DelegateCommand<object>(AddRelatedIssueHandler, CanCreate);
            LinkCommand = new DelegateCommand<object>(LinkIssueButtonHandler, CanLink);
            ViewCommand = new DelegateCommand<object>(OpenIssueButtonHandler, CanView);
        }
        public MobilePlantRelatedIssuesControl(MobilePlant mobilePlant)
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            InitializeComponent();

            MobilePlantRelatedIssuesViewModel model = new MobilePlantRelatedIssuesViewModel(mobilePlant);
            model.CollectionChanged += (count) => { OnCollectionChanged(count); };
            model.View = this;
            DataContext = model;
        }
        public MobilePlantDocumentsViewModel(MobilePlant mobilePlant)
        {
            CompositionInitializer.SatisfyImports(this);
            mMobilePlant = mobilePlant;

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

            cmsWebServiceClient.GetMobilePlantDocumentsCompleted += cmsWebServiceClient_GetMobilePlantDocumentsCompleted;
            cmsWebServiceClient.GetMobilePlantDocumentsAsync(MobilePlant.Id);

            AddButton = new DelegateCommand<object>(AddButtonHandler, CanAdd);
            DeleteButton = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
            OpenDocumentLink = new DelegateCommand<object>(OpenDocumentHandler, CanView);
        }
        public MobilePlantIssuesViewModel(MobilePlant mobilePlant)
        {
            CompositionInitializer.SatisfyImports(this);
            mMobilePlant = mobilePlant;

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

            cmsWebServiceClient.GetMobileRelatedIssuesCompleted += cmsWebServiceClient_GetMobileRelatedIssuesCompleted;
            cmsWebServiceClient.GetMobileRelatedIssuesAsync(mobilePlant.Id);

            AddButton = new DelegateCommand<object>(AddButtonHandler, CanCreateHandler);
            LinkButton = new DelegateCommand<object>(LinkButtonHandler, CanCreateHandler);
            OpenIssueLink = new DelegateCommand<object>(OpenIssueHandler, CanLinkHandler);
        }
        public MobilePlantAttachmentsViewModel(MobilePlant mobilePlant, MobilePlantAttachmentsControl view)
        {
            CompositionInitializer.SatisfyImports(this);

            View = view;

            AddAttachmentCommand = new DelegateCommand<object>(AddFileHandler, CanAdd);
            RemoveAttachmentCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
            ExportButton = new DelegateCommand<object>(ExportButtonHandler, x => true);

            mMobilePlant = mobilePlant;

            Attachments = new ObservableCollection<MobilePlantAttachment>();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetAttachmentTypesCompleted += cmsWebServiceClient_GetAttachmentTypesCompleted;
            cmsWebServiceClient.GetAttachmentTypesAsync();
        }
        public MobilePlantAttachmentsControl(MobilePlant mobilePlant)
        {
            InitializeComponent();

            mMobilePlant = mobilePlant;

            CompositionInitializer.SatisfyImports(this);

            ViewModel = new MobilePlantAttachmentsViewModel(mobilePlant, this)
            {
                View = this
            };

            ViewModel.Loaded += (s1) =>
            {
                Utils.ResetOriginalValues(AttachedFilesGridView);

                DataContext = ViewModel;

                if (ModelLoaded != null)
                {
                    ModelLoaded();

                }
            };

            ViewModel.ErrorOccurred += (message) =>
            {

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

            ViewModel.CollectionChanged += (count) => { OnCollectionChanged(count); };
        }
Пример #11
0
        public bool GetMobilePlantType(string typeName, MobilePlant newEquipment, int rowIndex)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                if (MetaData.ImportType == CommonUtils.ImportType.UpdateMobilePlant)
                {
                    return false;
                }
            }

            if (string.IsNullOrEmpty(typeName))
            {
                RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': Type row  is blank. Skipping.", WorkSheetName, rowIndex));
                return true;
            }

            MobilePlantType equipmentType = (from x in mExistingEquipmentTypes where string.Compare(x.Name, typeName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
            if (equipmentType == null)
            {
                if (CanCreateProperties)
                {
                    equipmentType = new MobilePlantType {Name = typeName};
                    mExistingEquipmentTypes.Add(equipmentType);
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}':Could not match '{2}' Mech Equip Type. Skipping.",
                        WorkSheetName, rowIndex, typeName));
                    return true;
                }
            }

            newEquipment.MobilePlantTypeId = equipmentType.Id;
            return false;
        }
Пример #12
0
        public DbOperationResult<QuickMobilePlant> SaveMobilePlant(MobilePlant equip, int userId)
        {
            try
            {
                using (CmsEntities cee = new CmsEntities())
                {
                    var originalObject = (from x in cee.MobilePlants
                                                       .Include("MobilePlantComponents")
                                                       .Include("MobilePlantComponents.MobilePlantComponentType")
                                          where x.Id == equip.Id
                                          select x).FirstOrDefault();

                    if (originalObject != null)
                    {
                        IEnumerable<MobilePlantComponent> mobilePlantComponentsToBeDeleted = from x in originalObject.MobilePlantComponents
                                                                                                    where equip.MobilePlantComponents.All(x1 => x1.Id != x.Id)
                                                                                                    select x;

                        BuildRevisonHistory(equip, userId, mobilePlantComponentsToBeDeleted, cee);

                        BuildRevisionHistory(equip, cee);

                        foreach (var electricalComponent in mobilePlantComponentsToBeDeleted)
                        {
                            DeleteMobilePlantComponent(electricalComponent);
                        }

                        SaveMobilePlantComponents(equip.MobilePlantComponents.ToList(), cee, equip.Id, userId);

                        SaveMobilePlantAttachments(equip.MobilePlantAttachments.ToList());
                        SaveMobilePlantRelatedIssues(equip, cee);
                        SaveMobilePlantDocuments(equip, cee);

                        cee.Entry(originalObject).CurrentValues.SetValues(equip);
                        cee.SaveChanges();
                    }
                    else
                    {
                        equip.MobilePlantType = null;
                        equip.MobileHirer = null;
                        equip.MobileOwner = null;
                        equip.Area = null;
                        equip.IsActive = true;

                        cee.MobilePlants.Add(equip);
                        cee.SaveChanges();
                    }

                    QuickMobilePlant quickMobilePlant = BuildQuickMobilePlant(cee, equip.Id);

                    return new DbOperationResult<QuickMobilePlant> { EntityResult = quickMobilePlant };
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                return BuildOperationalErrorResults<QuickMobilePlant>(ex);
            }
        }
Пример #13
0
        private static MobilePlantRevisionHistory BuildRevisonHistory(MobilePlant equip, int userId, IEnumerable<MobilePlantComponent> mobilePlantComponentsToBeDeleted, CmsEntities cee)
        {
            MobilePlantRevisionHistory rh = new MobilePlantRevisionHistory();

            string[] deleted = (from x in mobilePlantComponentsToBeDeleted select "Name: " + x.Name + " Type: " + x.MobilePlantComponentType.Name).ToArray();

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

                rh.Description = string.Format("Mobile Plant Components were removed : {0}", removedItems);
                rh.MobilePlantId = equip.Id;
                rh.Date = DateTime.Now;
                rh.UserId = userId;
                rh.IsSystemMessage = true;
                const decimal incrediment = 0.001m;

                var latestPrh = (from x in cee.MobilePlantRevisionHistories
                                 where x.MobilePlantId == equip.Id
                                 select x.Revision).ToList();

                if (latestPrh.Count > 0)
                {
                    rh.Revision = latestPrh.AsQueryable().Max() + incrediment;
                }
                else
                {
                    rh.Revision = incrediment;
                }

                cee.MobilePlantRevisionHistories.Add(rh);
            }
            return rh;
        }
Пример #14
0
        private void BuildRevisionHistory(MobilePlant mobilePlant, CmsEntities cee)
        {
            var latestPrh = (from x in cee.MobilePlantRevisionHistories
                             where x.MobilePlantId == mobilePlant.Id
                             select x.Revision).ToList();

            if (latestPrh.Count > 0)
            {
                foreach (MobilePlantRevisionHistory revisionHistory in mobilePlant.MobilePlantRevisionHistories)
                {
                    if (revisionHistory.Id == 0)
                    {
                        revisionHistory.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT;
                        cee.MobilePlantRevisionHistories.Add(revisionHistory);
                    }
                }
            }
            else
            {
                foreach (MobilePlantRevisionHistory revisionHistory in mobilePlant.MobilePlantRevisionHistories)
                {
                    if (revisionHistory.Id == 0)
                    {
                        revisionHistory.Revision = VERSIONINCREMENT;
                        cee.MobilePlantRevisionHistories.Add(revisionHistory);
                    }
                }
            }
        }
Пример #15
0
        private void SaveMobilePlantDocuments(MobilePlant mobilePlant, CmsEntities cee)
        {
            //Delete originals
            List<DocumentEquipment> originals = (from x in cee.DocumentEquipments
                                                 where x.EquipmentId == mobilePlant.Id
                                                 && x.EquipmentTypeId == (int)CommonUtils.EquipmentTypeCode.MOB
                                                 select x).ToList();
            originals.ForEach(x => cee.DocumentEquipments.Remove(x));

            if (mobilePlant.MobilePlantDocuments != null)
            {
                foreach (DocumentEquipment document in mobilePlant.MobilePlantDocuments)
                {
                    DocumentEquipment newObject = new DocumentEquipment
                    {
                        EquipmentId = mobilePlant.Id,
                        DocumentId = document.DocumentId,
                        EquipmentTypeId = (int)CommonUtils.EquipmentTypeCode.MOB
                    };

                    cee.DocumentEquipments.Add(newObject);
                }
            }
        }
Пример #16
0
        private void InsertData(IList<MobilePlantDataAdapter> importData)
        {
            if (importData.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, NoDataFoundForWorkSheetMessage());
                return;
            }

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

                IList<string> tags = (from x in importData select x.Tag).ToList();
                if (DuplicateItemNameFoundInExcell(adapter.Tag, tags, adapter.RowNumber))
                {
                    continue;
                }

                MobilePlant equipment = Cee.MobilePlants.FirstOrDefault(x => string.Compare(x.Name, adapter.Tag, true, CultureInfo.CurrentCulture) == 0);

                if (equipment != null)
                {
                    RaiseMessage(CommonUtils.MessageType.Warning, string.Format(BuildDuplicateNameExistsInDbMessage(adapter.Tag, adapter.RowNumber)));
                    continue;
                }

                equipment = new MobilePlant();

                if (!adapter.IsValid())
                {
                    foreach (string message in adapter.ErrorMessages)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, message);
                    }
                    continue;
                }

                equipment.Name = adapter.Tag;
                if (GetMobilePlantType(adapter.EquipmentType, equipment, adapter.RowNumber)) continue;
                equipment.Description = adapter.Description;
                equipment.Notes = adapter.Notes;

                if (GetMobilePlantHirer(adapter.Hirer, equipment, adapter.RowNumber)) continue;
                if (GetMobilePlantOwner(adapter.Owner, equipment, adapter.RowNumber)) continue;

                //AREA
                int areaId;
                if (GetAreaFailed(adapter.AreaNumber, adapter.RowNumber, out areaId, false))
                {
                    continue;
                }

                if (areaId > 0)
                {
                    equipment.AreaId = areaId;
                }

                equipment.Registration = adapter.Registration;
                equipment.Expiry = adapter.Expiry;

                if (!String.IsNullOrEmpty(adapter.MaintSysId))
                {
                    equipment.MaintSystemId = adapter.MaintSysId;
                }

                if (!adapter.Classified.HasValue)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': Classified row is blank or could not be parsed to boolean (please use true or false). Skipping.", WorkSheetName, adapter.RowNumber));
                    continue;
                }
                equipment.Classified = adapter.Classified.Value;

                if (adapter.IsActive.HasValue)
                {
                    equipment.IsActive = adapter.IsActive.Value;
                }
                else
                {
                    equipment.IsActive = true; //assume true
                }

                AddInsertRevisionHistory(equipment);

                mSavedResults.Add(equipment);
            }

            if (mSavedResults.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, string.Format("No Equipments were added from from worksheet {0}.", WorkSheetName));
            }
            else
            {
                //SAVE
                Cee.SaveChanges();

                foreach (MobilePlant equipment in mSavedResults)
                {
                    RaiseMessage(CommonUtils.MessageType.Added, string.Format("Processed Equipment '{0}'.", equipment.Name));
                }
            }
        }
Пример #17
0
        private MobilePlantRevisionHistory BuildRevisionHistory(MobilePlant equipment)
        {
            const decimal incrediment = 0.001m;
            var revision = new decimal(1.000);

            List<decimal> foo = (from x in Cee.MobilePlantRevisionHistories where x.MobilePlantId == equipment.Id orderby x.Revision descending select x.Revision).ToList();

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

            var rvh = new MobilePlantRevisionHistory
            {
                Date = DateTime.Now,
                MobilePlantId = equipment.Id,
                UserId = MetaData.UserId,
                Description = BuildRevisionHistoryUpdateComment(MetaData.RevisionHistoryComment),
                Revision = revision,
                IsSystemMessage = true
            };
            return rvh;
        }
Пример #18
0
        private void AddUpdateRevisionHistory(MobilePlant equipment)
        {
            MobilePlantRevisionHistory rvh = BuildRevisionHistory(equipment);

            equipment.MobilePlantRevisionHistories.Add(rvh);
        }
Пример #19
0
        private void AddInsertRevisionHistory(MobilePlant newEquipment)
        {
            var revision = new decimal(1.000);

            Cee.MobilePlants.Add(newEquipment);
            var rvh = new MobilePlantRevisionHistory
            {
                Date = DateTime.Now,
                UserId = MetaData.UserId,
                Description = BuildRevisionHistoryInsertComment(MetaData.RevisionHistoryComment),
                Revision = revision,
                IsSystemMessage = true
            };
            newEquipment.MobilePlantRevisionHistories.Add(rvh);
        }
Пример #20
0
        private void SaveMobilePlantRelatedIssues(MobilePlant mobilePlant, CmsEntities cee)
        {
            //Delete original
            List<IssueRelatedMobilePlant> originals =
                (from x in cee.IssueRelatedMobilePlants where x.MobilePlantId == mobilePlant.Id select x).ToList();
            originals.ForEach(x => cee.IssueRelatedMobilePlants.Remove(x));

            foreach (IssueRelatedMobilePlant relatedMobilePlant in mobilePlant.IssueRelatedMobilePlants)
            {
                IssueRelatedMobilePlant newObject = new IssueRelatedMobilePlant
                                                            {
                                                                MobilePlantId = mobilePlant.Id,
                                                                IssueId = relatedMobilePlant.IssueId,
                                                                Notes = relatedMobilePlant.Notes,
                                                                TestedById = relatedMobilePlant.TestedById,
                                                                TestedDate = relatedMobilePlant.TestedDate,
                                                                ImplementedById = relatedMobilePlant.ImplementedById,
                                                                ImplementedDate = relatedMobilePlant.ImplementedDate
                                                            };

                cee.IssueRelatedMobilePlants.Add(newObject);
            }
        }
Пример #21
0
        private void UpdateMobilePlantAttachments(MobilePlant mobilePlant, CmsEntities cee)
        {
            foreach (MobilePlantAttachment attachment in mobilePlant.MobilePlantAttachments)
            {
                MobilePlantAttachment existing = (from x in cee.MobilePlantAttachments
                                                  where x.Filename == attachment.Filename && x.Path == attachment.Path
                                                  select x).FirstOrDefault();

                if (existing != null)
                {
                    int uploadedById = existing.UploadedById;
                    int mobilePlantId = existing.MobilePlantId;

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

                    existing.MobilePlantId = mobilePlantId;
                    existing.UploadedById = uploadedById;
                }
            }
        }