public InstrumentAttachmentsControl(Instrument instrument) { InitializeComponent(); mInstrument = instrument; CompositionInitializer.SatisfyImports(this); ViewModel = new InstrumentAttachmentsViewModel(instrument) { View = this }; ViewModel.UploadComplete += () => { }; ViewModel.Loaded += (s1) => { Utils.ResetOriginalValues(AttachedFilesGridView); Utils.SetUpChangeEvents(AttachedFilesGridView, EventAggregator, instrument); DataContext = ViewModel; }; ViewModel.ErrorOccurred += (message) => { List<string> errors = new List<string>(); errors.Add(message); this.ValidationPopup.Show(Utils.BuildValidationResultFromServerErrors("", errors)); }; ViewModel.CollectionChanged += (count) => { OnCollectionChanged(count); }; }
public bool GetInstrumentType(string typeName, Instrument newEquipment, int rowIndex) { if (string.IsNullOrEmpty(typeName)) { if (MetaData.ImportType == CommonUtils.ImportType.UpdateInstrument) { return false; } } if (string.IsNullOrEmpty(typeName)) { RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Type row is blank. Skipping.", WorkSheetName, rowIndex)); return true; } InstrumentType equipmentType = (from x in mExistingInstrumentTypes where string.Compare(x.Name, typeName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault(); if (equipmentType == null) { if (CanCreateProperties) { equipmentType = new InstrumentType { Name = typeName, IsActive = true, Code = typeName.Replace(" ", "").ToUpper().Trim() }; mExistingInstrumentTypes.Add(equipmentType); } else { RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}':Could not match '{2}' InstrumentType. Skipping.", WorkSheetName, rowIndex, typeName)); return true; } } newEquipment.InstrumentType = equipmentType; return false; }
public InstrumentDocumentsControl(Instrument electricalEquipment) { InitializeComponent(); mViewModel = new InstrumentDocumentsViewModel(electricalEquipment) {View = this}; mViewModel.Loaded += ViewModelLoaded; mViewModel.CollectionChanged += count => OnCollectionChanged(count); }
public CalibrationComponentsControl(Instrument instrument) { InitializeComponent(); CompositionInitializer.SatisfyImports(this); mViewModel = new CalibrationComponentsViewModel(instrument, this); mViewModel.CollectionChanged += OnCollectionChanged; DataContext = mViewModel; mViewModel.SelectFirst(); }
public InstrumentComponentsControl(Instrument instrument) { InitializeComponent(); CompositionInitializer.SatisfyImports(this); mViewModel = new InstrumentComponentsViewModel(instrument); mViewModel.CollectionChanged += (count) => { OnCollectionChanged(count); }; mViewModel.View = this; DataContext = mViewModel; }
public InstrumentRelatedIssuesControl(Instrument instrument) { if (DesignerProperties.IsInDesignTool) { return; } InitializeComponent(); InstrumentRelatedIssuesViewModel model = new InstrumentRelatedIssuesViewModel(instrument); model.CollectionChanged += (count) => { OnCollectionChanged(count); }; model.View = this; DataContext = model; }
public InstrumentComponentsViewModel(Instrument instrumentEquipment) { CompositionInitializer.SatisfyImports(this); mInstrument = instrumentEquipment; MovedComponents = new List<InstrumentComponent>(); AddComponentCommand = new DelegateCommand<object>(AddButtonHandler, CanAdd); RemoveComponentCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete); EditComponentCommand = new DelegateCommand<object>(EditComponentHandler, CanModify); SelectComponentCommand = new DelegateCommand<object>(SelectButtonHandler, CanView); MoveComponentCommand = new DelegateCommand<object>(MoveComponentHandler, CanModify); mDictionary = Utils.BuildDictionaryForCollection(mInstrument.InstrumentComponents.Select(x => x.Id).ToList()); }
public InstrumentAttachmentsViewModel(Instrument instrumentEquipment) { AddAttachmentCommand = new DelegateCommand<object>(AddFileHandler, CanAdd); RemoveAttachmentCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete); ExportButton = new DelegateCommand<object>(ExportButtonHandler, x => true); CompositionInitializer.SatisfyImports(this); mInstrument = instrumentEquipment; Attachments = new ObservableCollection<InstrumentAttachment>(); CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.GetAttachmentTypesCompleted += cmsWebServiceClient_GetAttachmentTypesCompleted; cmsWebServiceClient.GetAttachmentTypesAsync(); }
public CalibrationComponentsViewModel(Instrument instrumentEquipment, CalibrationComponentsControl view) { CompositionInitializer.SatisfyImports(this); mInstrument = instrumentEquipment; Instrument = instrumentEquipment; this.View = view; AddComponentCommand = new DelegateCommand<object>(AddButtonHandler, CanAdd); RemoveComponentCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete); EditComponentCommand = new DelegateCommand<object>(EditComponentHandler, CanModify); SelectComponentCommand = new DelegateCommand<object>(SelectButtonHandler, CanView); mDictionary = Utils.BuildDictionaryForCollection(mInstrument.CalibrationComponents.Select(x => x.Id).ToList()); SetAllAttachmentControlsdContent(); }
private List<UpperEquipment> mAllUpperEquipments; //everytime the Selected Area is bound we need to reset the upper equipment list using the area id selected. #endregion Fields #region Constructors public AddInstrumentViewModel() { CompositionInitializer.SatisfyImports(this); Equipment = new Instrument(); var pidDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypePidCode); var specificationDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypeFuncspecCode); var getInstrumentTypes = DatabaseLoader.GetInstrumentTypes(); var getUpperEquipments = DatabaseLoader.GetUpperEquipments(); List<Task> tasks = new List<Task>(); tasks.Add(pidDocumentsTask); tasks.Add(specificationDocumentsTask); tasks.Add(getInstrumentTypes); tasks.Add(getUpperEquipments); Task.Factory.ContinueWhenAll(tasks.ToArray(), x => { CMS.UiFactory.StartNew(() => { PandIDDocuments = pidDocumentsTask.Result; RaisePropertyChanged("PandIDDocuments"); SpecificationDocuments = specificationDocumentsTask.Result; RaisePropertyChanged("SpecificationDocuments"); Types = getInstrumentTypes.Result; RaisePropertyChanged("Types"); mAllUpperEquipments = getUpperEquipments.Result; mAllUpperEquipments.Insert(0, new UpperEquipment { Name = CMS.Constants.UpperEquipmentNullName }); RaisePropertyChanged("UpperEquipments"); Areas = (from a in CMS.Cache.Areas where a.IsActive && a.SiteId == CMS.AppSetting.DefaultSiteId select a).ToList(); RaisePropertyChanged("Areas"); OnDataSourceLoaded(); }); }); OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanModify); CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, x => true); }
private void SaveInstrumentRelatedIssues(Instrument instrument, CmsEntities cee) { //Delete List<IssueRelatedInstrument> originals = (from x in cee.IssueRelatedInstruments where x.InstrumentId == instrument.Id select x).ToList(); originals.ForEach(x => cee.IssueRelatedInstruments.Remove(x)); foreach (IssueRelatedInstrument issueRelatedInstrument in instrument.IssueRelatedInstruments) { IssueRelatedInstrument newObject = new IssueRelatedInstrument { InstrumentId = instrument.Id, IssueId = issueRelatedInstrument.IssueId, Notes = issueRelatedInstrument.Notes, TestedById = issueRelatedInstrument.TestedById, TestedDate = issueRelatedInstrument.TestedDate, ImplementedById = issueRelatedInstrument.ImplementedById, ImplementedDate = issueRelatedInstrument.ImplementedDate }; cee.IssueRelatedInstruments.Add(newObject); } }
private void SaveInstrumentDocuments(Instrument instrument, CmsEntities cee) { if (instrument.InstrumentDocuments == null) { return; } //Delete originals List<DocumentEquipment> originals = (from x in cee.DocumentEquipments where x.EquipmentId == instrument.Id && x.EquipmentTypeId == (int)CommonUtils.EquipmentTypeCode.INSTR select x).ToList(); originals.ForEach(x => cee.DocumentEquipments.Remove(x)); foreach (DocumentEquipment document in instrument.InstrumentDocuments) { DocumentEquipment newObject = new DocumentEquipment { EquipmentId = instrument.Id, DocumentId = document.DocumentId, EquipmentTypeId = (int)CommonUtils.EquipmentTypeCode.INSTR }; cee.DocumentEquipments.Add(newObject); } }
private void BuildRevisionHistory(Instrument equip, CmsEntities cee) { var latestPrh = (from x in cee.InstrumentRevisionHistories where x.InstrumentId == equip.Id select x.Revision).ToList(); if (latestPrh.Count > 0) { foreach (InstrumentRevisionHistory revisionHistory in equip.InstrumentRevisionHistories) { if (revisionHistory.Id == 0) { revisionHistory.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT; cee.InstrumentRevisionHistories.Add(revisionHistory); } } } else { foreach (InstrumentRevisionHistory revisionHistory in equip.InstrumentRevisionHistories) { if (revisionHistory.Id == 0) { revisionHistory.Revision = VERSIONINCREMENT; cee.InstrumentRevisionHistories.Add(revisionHistory); } } } }
private static InstrumentRevisionHistory BuildRevisionHistory(Instrument equip, int userId, IEnumerable<InstrumentComponent> instrumentComponentsToBeDeleted, CmsEntities cee, out bool hasRevHist) { hasRevHist = false; InstrumentRevisionHistory rh = new InstrumentRevisionHistory(); hasRevHist = false; string[] componentMessages = (from x in instrumentComponentsToBeDeleted select "Name: " + x.Name + " Type: " + x.InstrumentComponentType.Name).ToArray(); if (componentMessages.Length > 0) { string removedItems = string.Join(",", componentMessages); rh.Description = string.Format("Instrument Components were removed : {0}", removedItems); rh.InstrumentId = equip.Id; rh.Date = DateTime.Now; rh.UserId = userId; rh.IsSystemMessage = true; var latestPrh = (from x in cee.InstrumentRevisionHistories where x.InstrumentId == equip.Id select x.Revision).ToList(); if (latestPrh.Count > 0) { rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT; } else { rh.Revision = VERSIONINCREMENT; } rh.IsSystemMessage = true; cee.InstrumentRevisionHistories.Add(rh); hasRevHist = true; } return rh; }
private static void BuildRevisionHistory(Instrument equip, int userId, IEnumerable<CalibrationComponent> calibrationComponentsToBeDeleted, InstrumentRevisionHistory rh, bool hasRevHist, CmsEntities cee) { string[] calibrationMessages = (from x in calibrationComponentsToBeDeleted select "Name: " + x.Name + " Type: " + x.CalibrationComponentType.Name).ToArray(); if (calibrationMessages.Length > 0) { string removedItems = string.Join(",", calibrationMessages); rh.Description = string.Format("Calibration Components were removed : {0}", removedItems); rh.InstrumentId = equip.Id; rh.Date = DateTime.Now; rh.UserId = userId; rh.IsSystemMessage = true; if (hasRevHist) { rh.Revision += VERSIONINCREMENT; } else { var latestPrh = (from x in cee.InstrumentRevisionHistories where x.InstrumentId == equip.Id select x.Revision).ToList(); if (latestPrh.Count > 0) { rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT; } else { rh.Revision = VERSIONINCREMENT; } } cee.InstrumentRevisionHistories.Add(rh); } }
public DbOperationResult<QuickInstrument> SaveInstrument(Instrument equip, int userId) { try { using (CmsEntities cee = new CmsEntities()) { Instrument originalObject = (from x in cee.Instruments .Include("InstrumentComponents") .Include("InstrumentComponents.InstrumentComponentType") .Include("CalibrationComponents") .Include("CalibrationComponents.CalibrationComponentType") where x.Id == equip.Id select x).FirstOrDefault(); if (originalObject != null) { IEnumerable<InstrumentComponent> instrumentComponentsToBeDeleted = (from x in originalObject.InstrumentComponents where !equip.InstrumentComponents.Any(x1 => x1.Id == x.Id) select x); bool hasRevHist = false; var rh = BuildRevisionHistory(equip, userId, instrumentComponentsToBeDeleted, cee, out hasRevHist); foreach (var instrumentComponent in instrumentComponentsToBeDeleted) { DeleteInstrumentComponent(instrumentComponent); } IEnumerable<CalibrationComponent> calibrationComponentsToBeDeleted = (from x in originalObject.CalibrationComponents where !equip.CalibrationComponents.Any(x1 => x1.Id == x.Id ) select x); BuildRevisionHistory(equip, userId, calibrationComponentsToBeDeleted, rh, hasRevHist, cee); BuildRevisionHistory(equip, cee); foreach (var calibrationComponent in calibrationComponentsToBeDeleted) { DeleteCalibrationComponent(calibrationComponent); } SaveInstrumentComponents(equip.InstrumentComponents.ToList(), userId); SaveCalibrationComponents(equip.CalibrationComponents.ToList()); SaveInstrumentAttachments(equip.InstrumentAttachments.ToList()); SaveInstrumentRelatedIssues(equip, cee); SaveInstrumentDocuments(equip, cee); cee.Entry(originalObject).CurrentValues.SetValues(equip); cee.SaveChanges(); } else { equip.InstrumentType = null; equip.Area = null; equip.IsActive = true; equip.VerificationFrequencyId = 1; cee.Instruments.Add(equip); cee.SaveChanges(); } QuickInstrument quickInstrument = BuildQuickInstrument(cee, equip.Id); return new DbOperationResult<QuickInstrument> { EntityResult = quickInstrument }; } } catch (Exception ex) { log.Error("", ex, ex.ToString()); return BuildOperationalErrorResults<QuickInstrument>(ex); } }
private void InsertData(IList<InstrumentDataAdapter> importData) { if (importData.Count == 0) { RaiseMessage(CommonUtils.MessageType.Warning, NoDataFoundForWorkSheetMessage()); return; } for (int i = 0; i < importData.Count; i++) { InstrumentDataAdapter adapter = importData[i]; IList<string> tags = (from x in importData select x.Tag).ToList(); if (DuplicateItemNameFoundInExcell(adapter.Tag, tags, adapter.RowNumber)) { continue; } Instrument instrument = (from x in Cee.Instruments where x.Name.Equals(adapter.Tag, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault(); if (instrument != null) { RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildDuplicateNameExistsInDbMessage(adapter.Tag, adapter.RowNumber))); continue; } instrument = new Instrument(); if (!adapter.IsValid()) { foreach (string message in adapter.ErrorMessages) { RaiseMessage(CommonUtils.MessageType.Error, message); } continue; } if (adapter.IsActive.HasValue) { instrument.IsActive = adapter.IsActive.Value; } else { instrument.IsActive = true; //assume true } //AREA int areaId; if (GetAreaFailed(adapter.AreaNumber, i, out areaId, false)) { continue; } if (areaId > 0) { instrument.AreaId = areaId; } if (GetInstrumentType(adapter.EquipmentType, instrument, adapter.RowNumber)) continue; instrument.Description = adapter.Description; instrument.Notes = adapter.Notes; instrument.Name = adapter.Tag; //Specification if (!string.IsNullOrEmpty(adapter.Specification)) { int docId; if (GetSpecDocumentFailed(adapter.Specification, out docId, adapter.RowNumber)) { continue; } instrument.SpecificationDocumentId = docId; } //PandID if (!string.IsNullOrEmpty(adapter.PandID)) { int docId; if (GetPIDDocumentFailed(adapter.PandID, out docId, adapter.RowNumber)) { continue; } instrument.PandIDDocumentId = docId; } if (!String.IsNullOrEmpty(adapter.MaintSysId)) { instrument.MaintSystemId = adapter.MaintSysId; } if (!adapter.Classified.HasValue) { RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': Classified row is blank. Skipping.", WorkSheetName, adapter.RowNumber)); continue; } //VERIFICATIONFREQUENCY int verificationFrequencyId; if (GetVerificationFrequencyFailed(adapter.VerificationFrequency, i + 1, out verificationFrequencyId, false)) { continue; } if (verificationFrequencyId <= 0) { continue; } instrument.VerificationFrequencyId = verificationFrequencyId; instrument.Classified = adapter.Classified.Value; AddInsertRevisionHistory(instrument); mSavedResults.Add(instrument); } if (mSavedResults.Count == 0) { RaiseMessage(CommonUtils.MessageType.Warning, string.Format("No Equipments were added from from worksheet {0}.", WorkSheetName)); } else { //SAVE Cee.SaveChanges(); foreach (Instrument equipment in mSavedResults) { RaiseMessage(CommonUtils.MessageType.Added, string.Format("Processed Equipment '{0}'.", equipment.Name)); } } }
private void AddUpdateRevisionHisatory(Instrument equipment) { const decimal incrediment = 0.001m; decimal revision = new decimal(1.000); List<decimal> foo = (from x in Cee.InstrumentRevisionHistories where x.InstrumentId == equipment.Id orderby x.Revision descending select x.Revision).ToList(); if (foo.Count > 0) { revision = foo[0] + incrediment; } InstrumentRevisionHistory rvh = new InstrumentRevisionHistory { Date = DateTime.Now, InstrumentId = equipment.Id, UserId = MetaData.UserId, Description = BuildRevisionHistoryUpdateComment(MetaData.RevisionHistoryComment), Revision = revision, IsSystemMessage = true }; equipment.InstrumentRevisionHistories.Add(rvh); }
private void AddInsertRevisionHistory(Instrument newEquipment) { decimal revision = new decimal(1.000); Cee.Instruments.Add(newEquipment); InstrumentRevisionHistory rvh = new InstrumentRevisionHistory { Date = DateTime.Now, UserId = MetaData.UserId, Description = BuildRevisionHistoryInsertComment(MetaData.RevisionHistoryComment), Revision = revision, IsSystemMessage = true }; newEquipment.InstrumentRevisionHistories.Add(rvh); }