Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
 private void UpdateRsnLengths()
 {
     try
     {
         CurrentStageRSNLength = OtherStagesRSNLength = TotalRSNLength = 0;
         var rsnIds = new List <Guid>();
         if (RsnsView != null)
         {
             var currentRsns = RsnsView.Cast <RsnVM>();
             rsnIds = currentRsns.Select(rsn => rsn.Id).ToList();
             CurrentStageRSNLength = currentRsns.Select(rsn => (!string.IsNullOrEmpty(rsn.CvtText) ? rsn.CvtText.Length : 0) + (!string.IsNullOrEmpty(rsn.FreeText) ? rsn.FreeText.Length : 0)).Sum();
         }
         if (Rsns != null)
         {
             var otherRsns = Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && !rsnIds.Contains(r.Id)).ToList();
             OtherStagesRSNLength = otherRsns.Select(rsn => (!string.IsNullOrEmpty(rsn.CvtText) ? rsn.CvtText.Length : 0) + (!string.IsNullOrEmpty(rsn.FreeText) ? rsn.FreeText.Length : 0)).Sum();
         }
         TotalRSNLength = CurrentStageRSNLength + OtherStagesRSNLength;
         Debug.WriteLine(CurrentStageRSNLength + " + " + OtherStagesRSNLength + " = " + TotalRSNLength);
     }
     catch (Exception ex)
     {
         Log.This(ex);
         AppErrorBox.ShowErrorMessage("Some error occured in RSNLength.", ex.Message);
     }
 }
Esempio n. 3
0
        public ViewAnalogousVM CollectExistingAnalogousReactions()
        {
            var               mainViewModel   = ((MainWindow)(App.Current.MainWindow)).DataContext as MainVM;
            List <RsnVM>      tanRsns         = new List <RsnVM>();
            List <ReactionVM> tanReactions    = new List <ReactionVM>();
            var               tanParticipants = new List <ReactionParticipantVM>();

            AnalogousReactions.Clear();
            AllParticipants.Clear();
            ReactionParticipants.Clear();
            try
            {
                var analogousReactions = mainViewModel.TanVM.Reactions.Where(r => r.AnalogousVMId == SelectedMasterReaction.Id);
                foreach (var existingAnalogousReaction in analogousReactions)
                {
                    AnalogousReactions.Add(existingAnalogousReaction);
                    AllParticipants.AddRange(mainViewModel.TanVM.ReactionParticipants.Where(rp => rp.ReactionVM.Id == existingAnalogousReaction.Id));
                    ReactionParticipants.AddRange(mainViewModel.TanVM.ReactionParticipants.Where(rp => rp.ReactionVM.Id == existingAnalogousReaction.Id));
                    foreach (var rsn in (mainViewModel.TanVM.Rsns.Where(rsn => rsn.Reaction.Id == existingAnalogousReaction.Id)))
                    {
                        Rsns.Add(rsn);
                    }
                }
            }
            catch (Exception ex)
            {
                AppErrorBox.ShowErrorMessage("Error while collecting analogous reactions", ex.Message);
            }
            return(this);
        }
 public bool ReplaceFreeTexts(string TargetText, string ReplaceText, MainVM mainvm, out string ResponceText, List <Guid> rsnIds = null)
 {
     if (Rsns != null && Rsns.Any())
     {
         var freetexts = Rsns.Where(rsn => (rsnIds != null ? rsnIds.Contains(rsn.Id) : true) && rsn.FreeText != null && rsn.FreeText.Contains(TargetText));
         foreach (var freetext in freetexts)
         {
             freetext.FreeText = freetext.FreeText.Replace(TargetText, ReplaceText);
         }
         ResponceText = string.Empty;
         return(true);
     }
     ResponceText = string.Empty;
     return(true);
 }
Esempio n. 5
0
        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());
            }
        }