private void OKButton_Click(object sender, RoutedEventArgs e) { if (mModel.AreAllValid()) { CmsWebServiceClient mCmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); mCmsWebServiceClient.AddInstrumentRevisionHistoryCompleted += (s1, e1) => { AddedRevisionHistory = e1.Result; DialogResult = true; }; mModel.User = CMS.User; mModel.Date = DateTime.Now; mModel.History.IsSystemMessage = false; mCmsWebServiceClient.AddInstrumentRevisionHistoryAsync(mModel.History); } }
private InstrumentRevisionHistory BuildRevisionHistory(CalibrationComponent componentIn) { const decimal incrediment = 0.001m; decimal revision = new decimal(1.000); List<decimal> foo = (from x in Cee.InstrumentRevisionHistories where x.InstrumentId == componentIn.InstrumentId orderby x.Revision descending select x.Revision).ToList(); if (foo.Count > 0) { revision = foo[0] + incrediment; } InstrumentRevisionHistory rvh = new InstrumentRevisionHistory { Date = DateTime.Now, InstrumentId = componentIn.InstrumentId, UserId = MetaData.UserId, Description = BuildRevisionHistoryUpdateComment(MetaData.RevisionHistoryComment), Revision = revision, IsSystemMessage = true }; return rvh; }
public InstrumentRevisionHistory AddInstrumentRevisionHistory(InstrumentRevisionHistory history) { using (CmsEntities cee = new CmsEntities()) { const decimal incrediment = 0.001m; var latestPrh = (from x in cee.InstrumentRevisionHistories where x.InstrumentId == history.InstrumentId select x.Revision).ToList(); if (latestPrh.Count > 0) { history.Revision = latestPrh.AsQueryable().Max() + incrediment; } else { history.Revision = incrediment; } int userid = history.UserId; int? issueId = history.IssueId; history.Issue = null; history.User = null; history.IssueId = null; if (issueId.HasValue && issueId.Value > 0) { history.IssueId = issueId; } history.UserId = userid; cee.InstrumentRevisionHistories.Add(history); cee.SaveChanges(); return (from x in cee.InstrumentRevisionHistories.Include("Issue").Include("User") where x.Id == history.Id select x).FirstOrDefault(); } }
private void AddInstrumentRevisionHistoryInternal(InstrumentRevisionHistory history, CmsEntities cee) { const decimal incrediment = 0.001m; var latestPrh = (from x in cee.InstrumentRevisionHistories where x.InstrumentId == history.InstrumentId select x.Revision).ToList(); if (latestPrh.Count > 0) { history.Revision = latestPrh.AsQueryable().Max() + incrediment; } else { history.Revision = incrediment; } int userid = history.UserId; int? issueId = history.IssueId; history.Issue = null; history.User = null; history.IssueId = null; if (issueId.HasValue && issueId.Value > 0) { history.IssueId = issueId; } history.UserId = userid; cee.InstrumentRevisionHistories.Add(history); cee.SaveChanges(); }
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 SaveInstrumentComponents(List<InstrumentComponent> instrumentComponents, int userId) { DbOperationResult result = new DbOperationResult(); using (CmsEntities cee = new CmsEntities()) { try { foreach (var instrumentComponent in instrumentComponents) { var q = (from x in cee.InstrumentComponents where x.Id == instrumentComponent.Id select x).FirstOrDefault(); if (q != null) { if (q.LastInspectedDate != instrumentComponent.LastInspectedDate) { InstrumentRevisionHistory rv = new InstrumentRevisionHistory { InstrumentId = instrumentComponent.InstrumentId, Date = DateTime.Now, UserId = userId, Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.", instrumentComponent.Name, q.LastInspectedDate, instrumentComponent.LastInspectedDate), IsSystemMessage = true }; AddInstrumentRevisionHistoryInternal(rv, cee); } //Update Instrument Componet cee.Entry(q).CurrentValues.SetValues(instrumentComponent); } else { q = new InstrumentComponent(); q.InstrumentId = instrumentComponent.InstrumentId; q.InstrumentComponentTypeId = instrumentComponent.InstrumentComponentTypeId; q.Name = instrumentComponent.Name; q.Ordinal = instrumentComponent.Ordinal; q.NextInspectionDate = instrumentComponent.NextInspectionDate; q.LastInspectedById = instrumentComponent.LastInspectedById; q.LastInspectedDate = instrumentComponent.LastInspectedDate; q.LastModifiedById = instrumentComponent.LastModifiedById; q.LastModifiedDate = instrumentComponent.LastModifiedDate; q.Description = instrumentComponent.Description; q.ManufacturerId = instrumentComponent.ManufacturerId; q.ModelId = instrumentComponent.ModelId; //Add new Instrument Component cee.InstrumentComponents.Add(q); } foreach (var instrumentComponentPropertyValue in instrumentComponent.InstrumentPropertyValues) { var qq = (from x in cee.InstrumentPropertyValues where x.Id == instrumentComponentPropertyValue.Id select x).FirstOrDefault(); if (qq != null) { cee.Entry(qq).CurrentValues.SetValues(instrumentComponentPropertyValue); } else { cee.InstrumentPropertyValues.Add(instrumentComponentPropertyValue); } } cee.SaveChanges(); } } catch (Exception ex) { result.ServerErrorMessages.Add(String.Format("Error moving components: {0}", ex.Message)); } } return result; }
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); }
private void BuildMoveComponentRevisionHistory(InstrumentComponentsControl componentsControl) { if (componentsControl == null || componentsControl.Model == null || componentsControl.Model.MovedComponents == null) { return; } foreach (var movedComponent in componentsControl.Model.MovedComponents) { var rv = new InstrumentRevisionHistory(); rv.Date = DateTime.Now; rv.UserId = CMS.User.Id; rv.InstrumentId = ViewModel.Instrument.Id; rv.Description = string.Format("Moved Component {0} to Intrument {1}.", movedComponent.Name, movedComponent.Instrument.Name); ViewModel.Instrument.InstrumentRevisionHistories.Add(rv); } }
private void SaveAcceptanceTestButton_Click(object sender, RoutedEventArgs e) { CmsWebServiceClient mCmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); mCmsWebServiceClient.AddInstrumentRevisionHistoryCompleted += (s1, e1) => { AddedRevisionHistory = e1.Result; DialogResult = true; }; mModel.User = CMS.User; mModel.Date = DateTime.Now; mModel.Description = "Site Acceptance Testing"; mModel.Issue = null; mCmsWebServiceClient.AddInstrumentRevisionHistoryAsync(mModel.History); }
public InstrumentRevisionHistoryViewModel(InstrumentRevisionHistory history) { mHistory = history; }
private void OkButtonHander(object parameter) { if (AreAllValid()) { var cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); //Save cmsWebServiceClient.SaveInstrumentCompleted += (s2, e2) => { DbOperationResultQuickInstrument resultQuickInstrument = e2.Result; if (!resultQuickInstrument.HasErrors) { View.SavedEquipment = resultQuickInstrument.EntityResult; View.DialogResult = true; EventAggregator.GetEvent<PrismEvents.RefreshNavigationEvent>().Publish(new QuickInstrument()); } else { View.ValidationPopup.Show(Utils.BuildValidationResultFromServerErrors("Save Failed", e2.Result.ServerErrorMessages)); } }; Equipment.InstrumentRevisionHistories = new List<InstrumentRevisionHistory>(); var rh = new InstrumentRevisionHistory(); rh.Date = DateTime.Now; rh.Description = "Initial Creation"; rh.Revision = new decimal(0.001); rh.UserId = CMS.User.Id; Equipment.InstrumentRevisionHistories.Add(rh); cmsWebServiceClient.SaveInstrumentAsync(Equipment, CMS.User.Id); } }