private void OKButton_Click(object sender, RoutedEventArgs e) { if (mModel.AreAllValid()) { CmsWebServiceClient mCmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); mCmsWebServiceClient.AddControlSystemRevisionHistoryCompleted += (s1, e1) => { AddedRevisionHistory = e1.Result; DialogResult = true; }; mModel.User = CMS.User; mModel.Date = DateTime.Now; mCmsWebServiceClient.AddControlSystemRevisionHistoryAsync(mModel.History); } }
public ControlSystemRevisionHistory AddControlSystemRevisionHistory(ControlSystemRevisionHistory history) { using (var cee = new CmsEntities()) { const decimal incrediment = 0.001m; var latestPrh = (from x in cee.ControlSystemRevisionHistories where x.ControlSystemId == history.ControlSystemId select x.Revision).ToList(); if (latestPrh.Count > 0) { history.Revision = latestPrh.AsQueryable().Max() + incrediment; } else { history.Revision = incrediment; } var userid = history.UserId; var issueId = history.IssueId; history.Issue = null; history.User = null; history.IssueId = null; if (issueId.HasValue && issueId.Value > 0) { history.IssueId = issueId; } history.UserId = userid; history.IsSystemMessage = false; cee.ControlSystemRevisionHistories.Add(history); cee.SaveChanges(); return (from x in cee.ControlSystemRevisionHistories.Include("Issue").Include("User") where x.Id == history.Id select x).FirstOrDefault(); } }
private void OkButtonHander(object parameter) { if (!AreAllValid()) { return; } CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); //Save cmsWebServiceClient.SaveControlSystemCompleted += (s2, e2) => { var dbOperationalResultTest = e2.Result; if (!dbOperationalResultTest.HasErrors) { View.SavedControlSystem = dbOperationalResultTest.EntityResult; View.DialogResult = true; EventAggregator.GetEvent<PrismEvents.RefreshNavigationEvent>().Publish(new QuickControlSystem()); } else { View.ValidationPopup.Show(Utils.BuildValidationResultFromServerErrors("Save Failed", e2.Result.ServerErrorMessages)); } }; ControlSystem.ControlSystemRevisionHistories = new List<ControlSystemRevisionHistory>(); ControlSystemRevisionHistory rh = new ControlSystemRevisionHistory { Date = DateTime.Now, Description = "Initial Creation", Revision = new decimal(0.001), UserId = CMS.User.Id }; ControlSystem.ControlSystemRevisionHistories.Add(rh); cmsWebServiceClient.SaveControlSystemAsync(ControlSystem, CMS.User.Id); }
private ControlSystemRevisionHistory BuildRevisionHistory(ControlSystem controlSystem) { const decimal incrediment = 0.001m; var revision = new decimal(1.000); List<decimal> foo = (from x in Cee.ControlSystemRevisionHistories where x.ControlSystemId == controlSystem.Id orderby x.Revision descending select x.Revision).ToList(); if (foo.Count > 0) { revision = foo[0] + incrediment; } var rvh = new ControlSystemRevisionHistory { Date = DateTime.Now, ControlSystemId = controlSystem.Id, UserId = MetaData.UserId, Description = BuildRevisionHistoryUpdateComment(MetaData.RevisionHistoryComment), Revision = revision, IsSystemMessage = true }; return rvh; }
private void AddInsertRevisionHistory(ControlSystem newContrlControlSystem) { var revision = new decimal(1.000); Cee.ControlSystems.Add(newContrlControlSystem); var rvh = new ControlSystemRevisionHistory { Date = DateTime.Now, UserId = MetaData.UserId, Description = BuildRevisionHistoryInsertComment(MetaData.RevisionHistoryComment), Revision = revision, IsSystemMessage = true }; newContrlControlSystem.ControlSystemRevisionHistories.Add(rvh); }
private bool InsertRevisionHistoryFailed(ControlSystemComponent newComponent, ControlSystem controlSystem) { var revision = new decimal(1.000); string comment = string.Empty; if (!string.IsNullOrEmpty(MetaData.RevisionHistoryComment)) { if (MetaData.ImportType == CommonUtils.ImportType.CreateControlComponents) { if (!string.IsNullOrEmpty(MetaData.RevisionHistoryComment)) { comment = BuildRevisionHistoryInsertComment(string.Format("Created Component '{0}' {1}.", newComponent.Name, MetaData.RevisionHistoryComment)); } else { comment = BuildRevisionHistoryInsertComment(string.Format("Created Component '{0}'", newComponent.Name)); } } else { if (!string.IsNullOrEmpty(MetaData.RevisionHistoryComment)) { comment = BuildRevisionHistoryUpdateComment(string.Format("Updated Component '{0}' {1}.", newComponent.Name, MetaData.RevisionHistoryComment)); } else { comment = BuildRevisionHistoryUpdateComment(string.Format("Updated Component '{0}'", newComponent.Name)); } } } var rvh = new ControlSystemRevisionHistory { Date = DateTime.Now, UserId = MetaData.UserId, Description = comment, Revision = revision }; if (controlSystem == null) { controlSystem = (from x in Cee.ControlSystems where x.Id == newComponent.ControlSystemId select x).FirstOrDefault(); if (controlSystem == null) { RaiseMessage(CommonUtils.MessageType.Error, string.Format("Could not find existing Control System by Id '{0}'.", newComponent.ControlSystemId)); return true; } } rvh.IsSystemMessage = true; controlSystem.ControlSystemRevisionHistories.Add(rvh); return false; }
private void BuildMoveComponentRevisionHistory(ControlSystemComponentsControl componentsControl) { if (componentsControl == null || componentsControl.Model == null || componentsControl.Model.MovedComponents == null) { return; } foreach (var movedComponent in componentsControl.Model.MovedComponents) { var rv = new ControlSystemRevisionHistory(); rv.Date = DateTime.Now; rv.UserId = CMS.User.Id; rv.ControlSystemId = ControlSystem.Id; rv.Description = string.Format("Moved Component {0} to Intrument {1}.", movedComponent.Name, movedComponent.ControlSystem.Name); ControlSystem.ControlSystemRevisionHistories.Add(rv); } }
private void SaveAcceptanceTestButton_Click(object sender, RoutedEventArgs e) { CmsWebServiceClient mCmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); mCmsWebServiceClient.AddControlSystemRevisionHistoryCompleted += (s1, e1) => { AddedRevisionHistory = e1.Result; DialogResult = true; }; mModel.User = CMS.User; mModel.Date = DateTime.Now; mModel.Description = "Site Acceptance Testing"; mModel.Issue = null; mCmsWebServiceClient.AddControlSystemRevisionHistoryAsync(mModel.History); }
public ControlSystemRevisionHistoryViewModel(ControlSystemRevisionHistory history) { mHistory = history; }
private void InsertRevisionHistory(InterlockType interLockType, int interlockNumber, ControlSystem controlSystem) { var revision = new decimal(1.000); string comment = string.Empty; if (MetaData.ImportType == CommonUtils.ImportType.CreateInterlocks) { if (!string.IsNullOrEmpty(MetaData.RevisionHistoryComment)) { comment = BuildRevisionHistoryInsertComment(string.Format("Added Interlock Type '{0}' Number '{1}' to Control '{2}'. {3}", interLockType.Name, interlockNumber, controlSystem.Name, MetaData.RevisionHistoryComment)); } else { comment = BuildRevisionHistoryInsertComment(string.Format("Added Interlock Type '{0}' Number '{1}' to Control '{2}'.", interLockType.Name, interlockNumber, controlSystem.Name)); } } else { if (!string.IsNullOrEmpty(MetaData.RevisionHistoryComment)) { comment = BuildRevisionHistoryUpdateComment(string.Format("Updated Interlock Type '{0}' Number '{1}' on Control '{2}'. {3}", interLockType.Name, interlockNumber, controlSystem.Name, MetaData.RevisionHistoryComment)); } else { comment = BuildRevisionHistoryUpdateComment(string.Format("Updated Interlock Type '{0}' Number '{1}' on Control '{2}'.", interLockType.Name, interlockNumber, controlSystem.Name)); } } var rvh = new ControlSystemRevisionHistory { Date = DateTime.Now, UserId = MetaData.UserId, Description = comment, Revision = revision, IsSystemMessage = true }; controlSystem.ControlSystemRevisionHistories.Add(rvh); }
private void BuildInterlocksToBeDeletedRevisionHistory(ControlSystem controlSystem, int userId, IEnumerable<Interlock> interlocksToBeDeleted, CmsEntities cee) { var rh = new ControlSystemRevisionHistory(); var messages = new List<string>(); var user = (from x in cee.Users where x.Id == userId select x).FirstOrDefault(); if (user == null) { throw new NullReferenceException("User not found for Id " + userId); } var ids = (from x in interlocksToBeDeleted select x.Id).ToList(); var results = (from x in cee.Interlocks .Include("InterlockType") .Include("InterlockRisks") .Include("InterlockRisks.InterlockRiskCategory") .Include("InterlockRisks.InterlockRiskMatrix") .Include("InterlockRisks.InterlockRiskMatrix.InterlockRiskConsequence") .Include("InterlockRisks.InterlockRiskMatrix.InterlockRiskLikelihood") .Include("InterlockRisks.InterlockRiskMatrix.InterlockRiskRating") where ids.Contains(x.Id) select x).ToList(); foreach (var interlock in results) { var toprisk = GetHighestInterlockRisk(interlock.InterlockRisks); string riskText; if (toprisk != null && toprisk.InterlockRiskMatrix != null) { riskText = string.Format("Override Override Risk = ({0} - {1})", toprisk.InterlockRiskMatrix.RiskRatingNumber, toprisk.InterlockRiskMatrix.InterlockRiskRating.Name, Environment.NewLine); } else { riskText = "No Override Risk present"; } var properties = GetPropertiesFromInterlock(interlock.Id, cee); var message = string.Format("Interlock deleted by : {0} - ({1}{2} - {3} ({4})){5}" + "{6}{7}" + "{8}", user.FirstLastName, interlock.InterlockType.Name, interlock.Number, interlock.Description, interlock.Cause, Environment.NewLine, riskText, Environment.NewLine, properties); messages.Add(message); } if (messages.Any()) { var joined = string.Join(Environment.NewLine, messages); rh.Description = joined; rh.ControlSystemId = controlSystem.Id; rh.Date = DateTime.Now; rh.UserId = userId; rh.IsSystemMessage = true; var latestPrh = (from x in cee.ControlSystemRevisionHistories where x.ControlSystemId == controlSystem.Id select x.Revision).ToList(); if (latestPrh.Count > 0) { rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT; } else { rh.Revision = VERSIONINCREMENT; } cee.ControlSystemRevisionHistories.Add(rh); } }
private void BuildInterlocksModifiedRevisionHistory(ControlSystem controlSystem, int userId, List<ModifiedInterlockDto> modifiedInterlocksDtoList, CmsEntities cee) { var rh = new ControlSystemRevisionHistory(); var messages = new List<string>(); var user = (from x in cee.Users where x.Id == userId select x).FirstOrDefault(); if (user == null) { throw new NullReferenceException("User not found for Id " + userId); } var ids = (from x in modifiedInterlocksDtoList select x.Interlock.Id).ToList(); var results = (from x in cee.Interlocks .Include("InterlockType") .Include("InterlockRisks") .Include("InterlockRisks.InterlockRiskCategory") .Include("InterlockRisks.InterlockRiskMatrix") .Include("InterlockRisks.InterlockRiskMatrix.InterlockRiskConsequence") .Include("InterlockRisks.InterlockRiskMatrix.InterlockRiskLikelihood") .Include("InterlockRisks.InterlockRiskMatrix.InterlockRiskRating") where ids.Contains(x.Id) select x).ToList(); foreach (var interlock in results) { var toprisk = GetHighestInterlockRisk(interlock.InterlockRisks); string riskText; if (toprisk != null && toprisk.InterlockRiskMatrix != null) { riskText = string.Format("Override Override Risk = ({0} - {1})", toprisk.InterlockRiskMatrix.RiskRatingNumber, toprisk.InterlockRiskMatrix.InterlockRiskRating.Name, Environment.NewLine); } else { riskText = "No Override Risk present"; } //find matching dto from our list var interlockDto = (from x in modifiedInterlocksDtoList where x.Interlock.Id == interlock.Id select x).FirstOrDefault(); if (interlockDto == null) { continue; } //make a nice comm sep list var interlockMessage = new List<string> { interlockDto.ToString() }; var interlockCommaSepList = string.Join(", ", interlockMessage); //build message var message = string.Format("Interlock modified by : {0} - ({1}{2} - {3} ({4})){5}" + "{6}{7}" + "{8}", user.FirstLastName, interlock.InterlockType.Name, interlock.Number, interlock.Description, interlock.Cause, Environment.NewLine, riskText, Environment.NewLine, interlockCommaSepList); //add it messages.Add(message); } if (messages.Any()) { var joined = string.Join(Environment.NewLine, messages); rh.Description = joined; rh.ControlSystemId = controlSystem.Id; rh.Date = DateTime.Now; rh.UserId = userId; rh.IsSystemMessage = true; var latestPrh = (from x in cee.ControlSystemRevisionHistories where x.ControlSystemId == controlSystem.Id select x.Revision).ToList(); if (latestPrh.Count > 0) { rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT; } else { rh.Revision = VERSIONINCREMENT; } cee.ControlSystemRevisionHistories.Add(rh); } }
private void BuildComponentsTypeChangedRevisionHistory(ControlSystem controlSystem, int userId, ControlSystem originalControlSystem, CmsEntities cee) { var componentsTypeChanged = (from x in originalControlSystem.ControlSystemComponents where controlSystem.ControlSystemComponents.All(x1 => x1.ControlSystemComponentTypeId != x.ControlSystemComponentTypeId) select x).ToList(); if (!componentsTypeChanged.Any()) { return; } var rh = new ControlSystemRevisionHistory(); StringBuilder sb = new StringBuilder(); foreach (ControlSystemComponent component in componentsTypeChanged) { sb.Append(controlSystem.Name); sb.Append(" : "); sb.Append(component.Name); sb.Append(" from "); sb.Append(component.ControlSystemComponentType.Name); sb.Append(" to "); var changed = (from x in controlSystem.ControlSystemComponents where x.Id == component.Id select x).FirstOrDefault(); if (changed != null) sb.Append(changed.ControlSystemComponentType.Name); sb.AppendLine(); } if (sb.Length > 0) { rh.Description = string.Format("ControlSystem Components had their Type changed : {0}{1}", Environment.NewLine, sb.ToString()); rh.ControlSystemId = controlSystem.Id; rh.Date = DateTime.Now; rh.UserId = userId; rh.IsSystemMessage = true; var latestPrh = (from x in cee.ControlSystemRevisionHistories where x.ControlSystemId == controlSystem.Id select x.Revision).ToList(); if (latestPrh.Count > 0) { rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT; } else { rh.Revision = VERSIONINCREMENT; } cee.ControlSystemRevisionHistories.Add(rh); } }
private void BuildAlarmRevisionHistory(int controlSystemId, int userId, List<ControlSystemComponent> controlSystemComponents, CmsEntities cee) { var modifiedList = new List<ControlSystemAlarmPropertyValue>(); foreach (var component in controlSystemComponents) { if (component.ControlSystemAlarmPropertyValues != null && component.ControlSystemAlarmPropertyValues.Any()) { modifiedList.AddRange(component.ControlSystemAlarmPropertyValues); } } if (!modifiedList.Any()) { return; } var idList = (from x in modifiedList select x.Id).ToArray(); var dbMatches = (from x in cee.ControlSystemAlarmPropertyValues where idList.Contains(x.Id) select x).ToList(); var purposes = (from x in cee.ControlSystemAlarmPurposes select x).ToList(); var consequences = (from x in cee.ControlSystemAlarmConsequences select x).ToList(); var responses = (from x in cee.ControlSystemAlarmResponses select x).ToList(); var priorities = (from x in cee.ControlSystemAlarmPriorities select x).ToList(); var users = GetQuickUsersInternal(true, cee); var messages = new List<string>(); foreach (var pv in modifiedList) { ControlSystemAlarmPropertyValue db; if (pv.Id != 0) { db = (from x in dbMatches where x.Id == pv.Id select x).FirstOrDefault(); } else { db = new ControlSystemAlarmPropertyValue(); } if (db != null) { var propertyComparer = new ModifiedAlarmPropertyComparer(db, pv, priorities, purposes, consequences, responses, users); if (!string.IsNullOrEmpty(propertyComparer.Result)) { var heading = string.Format("[Component: {0}, Alarm: {1}] ", pv.ControlSystemComponent.Name, pv.ControlSystemAlarmProperty.Name); messages.Add(heading); messages.Add(propertyComparer.Result.TrimEnd(Environment.NewLine.ToCharArray())); } } } var rh = new ControlSystemRevisionHistory(); if (messages.Any()) { var joined = string.Join(Environment.NewLine, messages); rh.Description = joined; rh.ControlSystemId = controlSystemId; rh.Date = DateTime.Now; rh.UserId = userId; rh.IsSystemMessage = true; var latestPrh = (from x in cee.ControlSystemRevisionHistories where x.ControlSystemId == controlSystemId select x.Revision).ToList(); if (latestPrh.Count > 0) { rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT; } else { rh.Revision = VERSIONINCREMENT; } cee.ControlSystemRevisionHistories.Add(rh); } }
private static void BuildComponentsToBeDeletedRevisionHistory(ControlSystem controlSystem, int userId, IEnumerable<ControlSystemComponent> componentsToBeDeleted, CmsEntities cee) { var rh = new ControlSystemRevisionHistory(); var componentMessages = (from x in componentsToBeDeleted select "Name: " + x.Name + " Type: " + x.ControlSystemComponentType.Name).ToArray(); if (componentMessages.Length > 0) { var removedItems = string.Join(",", componentMessages); rh.Description = string.Format("ControlSystem Components were removed : {0}", removedItems); rh.ControlSystemId = controlSystem.Id; rh.Date = DateTime.Now; rh.UserId = userId; rh.IsSystemMessage = true; var latestPrh = (from x in cee.ControlSystemRevisionHistories where x.ControlSystemId == controlSystem.Id select x.Revision).ToList(); if (latestPrh.Count > 0) { rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT; } else { rh.Revision = VERSIONINCREMENT; } cee.ControlSystemRevisionHistories.Add(rh); } }