public void DeleteRsn(RsnVM rsnVM) { try { if (Rsns != null) { var mainVM = (App.Current.MainWindow as MainWindow).DataContext as MainVM; if (rsnVM.IsIgnorableInDelivery && rsnVM.ReactionParticipantId != null && rsnVM.ReactionParticipantId.Count > 0 && mainVM.TanVM.ReactionParticipants.OfReaction(ReactionVM.Id).Where(rp => rsnVM.ReactionParticipantId.Contains(rp.Id)).FirstOrDefault() != null) { var RP = mainVM.TanVM.ReactionParticipants.OfReaction(ReactionVM.Id).Where(rp => rsnVM.ReactionParticipantId.Contains(rp.Id)).FirstOrDefault(); StringBuilder sb = new StringBuilder(); sb.Append("Special CVT has assoiciated Participant : "); sb.Append(RP.Reg); sb.AppendLine(); sb.AppendLine("RXN : " + RP.ReactionVM.Name); sb.AppendLine("Stage : " + RP.StageVM?.Name); sb.AppendLine("Category : " + RP.ParticipantType); sb.AppendLine("NUM : " + RP.Num); sb.AppendLine("Series : " + RP.ChemicalType); sb.AppendLine("Please remove participant from Reaction to delete Selected RSN"); AppInfoBox.ShowInfoMessage(sb.ToString()); } else { Rsns.Remove(rsnVM); } } } catch (Exception ex) { Log.This(ex); } }
public void EditRsn(RsnVM rsnVM) { try { RsnLevel = rsnVM.Stage != null ? RsnLevel.STAGE : RsnLevel.REACTION; EditingRsn = rsnVM; } catch (Exception ex) { Log.This(ex); } }
public RsnVM(RsnVM otherRsnVM) { this.Id = otherRsnVM.Id; this.IsRXN = otherRsnVM.IsRXN; this.ChooseRXN = otherRsnVM.ChooseRXN; this.CvtText = otherRsnVM.CvtText; this.FreeText = otherRsnVM.FreeText; this.Reaction = otherRsnVM.Reaction; this.Stage = otherRsnVM.Stage; this.DisplayOrder = otherRsnVM.DisplayOrder; this.SelectedChemical = otherRsnVM.SelectedChemical; this.ReactionParticipantId = otherRsnVM.ReactionParticipantId; this.IsIgnorableInDelivery = otherRsnVM.IsIgnorableInDelivery; BindEvents(); }
private void DoSaveForm(object obj) { try { string outMsg = string.Empty; if (!string.IsNullOrEmpty(FreeText.Trim()) || !string.IsNullOrEmpty(CVT)) { if (!RV.ValidateRsnFreetext(FreeText, ReactionVM, StageVM, RsnLevel, out outMsg)) { AppInfoBox.ShowInfoMessage(outMsg); return; } if (RV.ValidateRsnReactionLevel(ReactionVM, StageVM, RsnLevel, CVT, FreeText, Rsns.ToList(), out outMsg, EditingRsn)) { if (EditingRsn != null) { EditingRsn.CvtText = CVT; EditingRsn.IsIgnorableInDelivery = IsIgnorableInDelivery; EditingRsn.FreeText = FreeText.Trim().TrimEnd('.'); EditingRsn.Stage = RsnLevel == RsnLevel.STAGE ? StageVM : null; UpdateRsnLengths(); } else { var rsn = new RsnVM { }; rsn.CvtText = CVT; rsn.IsIgnorableInDelivery = IsIgnorableInDelivery; rsn.FreeText = FreeText.Trim().TrimEnd('.'); rsn.Reaction = ReactionVM; rsn.Id = Guid.NewGuid(); rsn.Stage = RsnLevel == RsnLevel.STAGE ? StageVM : null; rsn.RSNWindowVM = this; Rsns.Add(rsn); } } else { AppInfoBox.ShowInfoMessage(outMsg); return; } if (Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.ENZYMIC_CVT)).Count() > 0 && Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.BIOTRANSFORMATION_CVT)).Count() == 0) { var enzymicRSN = Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.ENZYMIC_CVT)).FirstOrDefault(); string freeTextToAdd = !string.IsNullOrEmpty(enzymicRSN.FreeText) ? RV.GetStageInfoWithOutFreeText(enzymicRSN.FreeText) : string.Empty; Rsns.Add(new RsnVM { CvtText = S.BIOTRANSFORMATION_CVT, FreeText = RsnLevel == RsnLevel.STAGE ? $"{S.BIOTRANSFORMATION_FREETEXT} {freeTextToAdd}" : string.Empty, IsRXN = true, Stage = enzymicRSN.Stage != null ? enzymicRSN.Stage : null, Reaction = ReactionVM, RSNWindowVM = this, Id = Guid.NewGuid() }); } ClearEditForm.Execute(this); } else { AppInfoBox.ShowInfoMessage("Either CVT or FreeText mandatory to save RSN"); } } catch (Exception ex) { Log.This(ex); AppErrorBox.ShowErrorMessage(ex.Message, ex.ToString()); } }
private void CopySelectedStages(object obj) { if (SelectedStages.Count > 0) { var mainViewModel = ((MainWindow)(App.Current.MainWindow)).DataContext as MainVM; if (SelectedStageOption != CopyStageOptions.APPEND && (mainViewModel.TanVM.SelectedReaction == null || mainViewModel.TanVM.SelectedReaction.SelectedStage == null)) { AppInfoBox.ShowInfoMessage("Please select stage to Add stages before/after in curation window."); return; } List <ReactionParticipantVM> allParticipants = new List <ReactionParticipantVM>(); List <StageVM> reactionStages = new List <StageVM>(); var tanParticipants = new List <ReactionParticipantVM>(); if (IsReactantsSelected) { var reactants = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Reactant select p).ToList(); allParticipants.AddRange(reactants); } if (IsSolventsSelected || IsAgentsSelected || IsCatalystSelected) { if (IsSolventsSelected) { var solvents = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Solvent select p).ToList(); allParticipants.AddRange(solvents); } if (IsAgentsSelected) { var agents = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Agent select p).ToList(); allParticipants.AddRange(agents); } if (IsCatalystSelected) { var catalysts = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Catalyst select p).ToList(); allParticipants.AddRange(catalysts); } } else { AppInfoBox.ShowInfoMessage("Please select Atleast one type of Participants to Copy."); return; } var selectedreaction = mainViewModel.TanVM.SelectedReaction; List <RsnVM> tanRsns = new List <RsnVM>(); var stages = new List <StageVM>(); for (int i = 0; i < StagesCountToCopy; i++) { foreach (var selectedstage in SelectedStages) { var newStageToAdd = new StageVM { Id = Guid.NewGuid(), ReactionVm = selectedreaction }; if (IsConditionsSelected) { var Conditions = new List <StageConditionVM>(); foreach (var selectedCondition in selectedstage.Conditions) { var condition = new StageConditionVM { DisplayOrder = selectedCondition.DisplayOrder, Id = Guid.NewGuid(), PH = selectedCondition.PH, PH_TYPE = selectedCondition.PH_TYPE, Pressure = selectedCondition.Pressure, PRESSURE_TYPE = selectedCondition.PRESSURE_TYPE, StageId = newStageToAdd.Id, Temperature = selectedCondition.Temperature, TEMP_TYPE = selectedCondition.TEMP_TYPE, Time = selectedCondition.Time, TIME_TYPE = selectedCondition.TIME_TYPE }; Conditions.Add(condition); } newStageToAdd.SetConditions(Conditions); } else { newStageToAdd.Conditions = new ObservableCollection <StageConditionVM>(); } var stageParticipants = (from sp in allParticipants where sp.StageVM.Id == selectedstage.Id select sp).ToList(); foreach (var participant in stageParticipants) { var newParticipant = new ReactionParticipantVM { ChemicalType = participant.ChemicalType, DisplayOrder = participant.DisplayOrder, Name = participant.Name, Num = participant.Num, ParticipantType = participant.ParticipantType, ReactionVM = selectedreaction, Reg = participant.Reg, StageVM = newStageToAdd, TanChemicalId = participant.TanChemicalId, Yield = participant.Yield, Id = Guid.NewGuid() }; tanParticipants.Add(newParticipant); } if (IsRSNSelected) { var stagersnList = (from rsn in mainViewModel.TanVM.Rsns where rsn.Reaction.Id == selectedreaction.Id && rsn.Stage != null && rsn.Stage.Id == selectedstage.Id select rsn).ToList(); foreach (var rsn in stagersnList) { var newRsn = new RsnVM { CvtText = rsn.CvtText, Reaction = selectedreaction, IsRXN = false, Stage = newStageToAdd, FreeText = rsn.FreeText, Id = Guid.NewGuid(), DisplayOrder = rsn.DisplayOrder, IsIgnorableInDelivery = rsn.IsIgnorableInDelivery, ReactionParticipantId = rsn.ReactionParticipantId, SelectedChemical = rsn.SelectedChemical }; tanRsns.Add(newRsn); } } stages.Add(newStageToAdd); } } mainViewModel.TanVM.EnablePreview = false; foreach (var participant in tanParticipants) { mainViewModel.TanVM.ReactionParticipants.Add(participant); } foreach (var rsn in tanRsns) { mainViewModel.TanVM.Rsns.Add(rsn); } mainViewModel.TanVM.EnablePreview = true; if (SelectedStageOption != CopyStageOptions.APPEND && mainViewModel.TanVM.SelectedReaction != null && mainViewModel.TanVM.SelectedReaction.SelectedStage != null) { var stagesList = mainViewModel.TanVM.SelectedReaction.Stages.ToList(); var index = stagesList.Count() >= 1 ? stagesList.FindIndex(x => x.Id == mainViewModel.TanVM.SelectedReaction.SelectedStage.Id) : 0; if (SelectedStageOption == CopyStageOptions.AFTER) { selectedreaction.SetStages(stages, index + 1, true); } else if (SelectedStageOption == CopyStageOptions.BEFORE) { selectedreaction.SetStages(stages, index, true); } } else { selectedreaction.SetStages(stages); } mainViewModel.TanVM.PerformAutoSave("Stage Added"); Visible = System.Windows.Visibility.Hidden; AppInfoBox.ShowInfoMessage("Please Update the Stage Freetext Stage Information for newly created stages."); } else { AppInfoBox.ShowInfoMessage("Please Select AtLeast One stage"); } }