예제 #1
0
        public static List <ValidationError> ValidatePressure(bool highPressure, ReactionVM reaction, StageVM stage, List <RsnVM> Rsns)
        {
            var errors = new List <ValidationError>();
            ExtentionMethods common        = new Common.ExtentionMethods();
            List <string>    pressureTypes = new List <string> {
                PressureEnum.Pressure.ToString(), PressureEnum.Directional.ToString(), PressureEnum.Range.ToString()
            };
            var StagePressureConditions = stage.Conditions != null?stage.Conditions.Where(p => pressureTypes.Contains(p.PRESSURE_TYPE)).ToList() : null;

            var HighPressureCVTs = Rsns.Where(f => f.Reaction.Id == reaction.Id && f.Stage == null && (f.CvtText.SafeContainsLower(S.HIGH_PRESSURE_CVT_TERM) || f.FreeText.SafeContainsLower(S.HIGH_PRESSURE_FREETEXT_TERM)));
            var lowPressureCVTs  = Rsns.Where(f => f.Stage == null && (f.CvtText.SafeContainsLower(S.LOW_PRESSURE_CVT_TERM) || f.FreeText.SafeContainsLower(S.LOW_PRESSURE_FREETEXT_TERM)));
            var stageHighPressureDisplayOrders = GetStageDisplayOrdersFromFreetexts(Rsns.ToList(), reaction, S.HIGH_PRESSURE_FREETEXT_TERM);
            var stageLowPressureDisplayOrders  = GetStageDisplayOrdersFromFreetexts(Rsns.ToList(), reaction, S.LOW_PRESSURE_FREETEXT_TERM);

            #region 12-21
            if (highPressure)
            {
                if ((HighPressureCVTs.Any() || stageHighPressureDisplayOrders.Contains(stage.DisplayOrder)) && (!StagePressureConditions.Any() || StagePressureConditions.Where(con => !string.IsNullOrEmpty(con.Pressure)).Count() == 0))
                {
                    errors.Add(VF.OfRSN(reaction, "RSN Conatins 'High Pressure' in CVT/FreeText. High Pressure is Allowed only when Pressure Exceeds Normal Pressure", stage));
                }
                errors.AddRange(HighAndLowPresssureValidations(StagePressureConditions, highPressure, reaction, stage, stageHighPressureDisplayOrders, HighPressureCVTs.ToList()));
            }
            #endregion

            #region 12-22
            else
            {
                if ((lowPressureCVTs.Any() || stageLowPressureDisplayOrders.Contains(stage.DisplayOrder)) && (!StagePressureConditions.Any() || StagePressureConditions.Where(con => !string.IsNullOrEmpty(con.Pressure)).Count() == 0))
                {
                    errors.Add(VF.OfRSN(reaction, "RSN Conatins 'Low Pressure' in CVT/FreeText. Low Pressure is Allowed only when Pressure below Normal Pressure", stage));
                }
                errors.AddRange(HighAndLowPresssureValidations(StagePressureConditions, highPressure, reaction, stage, stageLowPressureDisplayOrders, lowPressureCVTs.ToList()));
            }
            #endregion
            //if (highPressure)
            //{
            //    #region 12-21
            //    if (stageHighPressureDisplayOrders.Contains(stage.DisplayOrder) && (!StagePressureConditions.Any() || StagePressureConditions.Where(con => !string.IsNullOrEmpty(con.Pressure)).Count() == 0))
            //        errors.Add(VF.OfRSN(reaction, "RSN Conatins 'High Pressure' in CVT/FreeText. High Pressure is Allowed only when Pressure Exceeds Noraml Pressure", stage));
            //    errors.AddRange(HighAndLowPresssureValidations(StagePressureConditions, highPressure, reaction, stage, stageHighPressureDisplayOrders,HighPressureCVTs.ToList()));
            //    #endregion
            //}

            //else
            //{
            //    #region 12-22

            //    if (stageLowPressureDisplayOrders.Contains(stage.DisplayOrder) && (!StagePressureConditions.Any() || StagePressureConditions.Where(con => !string.IsNullOrEmpty(con.Pressure)).Count() == 0))
            //        errors.Add(VF.OfRSN(reaction, "RSN Conatins 'Low Pressure' in CVT/FreeText. Low Pressure is Allowed only when Pressure below Noraml Pressure", stage));
            //    errors.AddRange(HighAndLowPresssureValidations(StagePressureConditions, highPressure, reaction, stage, stageLowPressureDisplayOrders,lowPressureCVTs.ToList()));
            //    #endregion
            //}
            return(errors);
        }
예제 #2
0
 private void AnalogousUC_MasterReactionChangedInAnalogousTab(object sender, ReactionVM e)
 {
     try
     {
         ClearAll();
         ShowExistingAnalogousReactions(e);
     }
     catch (Exception ex)
     {
         Log.This(ex);
     }
 }
예제 #3
0
 void ShowExistingAnalogousReactions(ReactionVM masterReaction)
 {
     try
     {
         var viewModel = this.DataContext as ViewAnalogousVM;
         if (viewModel != null)
         {
             ViewAnalogousVM analogousReactionVM = viewModel.CollectExistingAnalogousReactions();
             AnalogousBuilder.BuildAnalogousGrid(analogousReactionVM, ConsolidatedGrid, false);
         }
     }
     catch (Exception ex)
     {
         Log.This(ex);
     }
 }
        public static ReactionParticipantVM ValidateWithCVT1(Dictionary <ParticipantType, List <ReactionParticipantVM> > otherstageReactants, List <RsnVM> Rsns, ReactionVM SelectedReaction, TanChemicalVM chemicalName, ParticipantType participanttype)
        {
            var groupedValidations = S.GetGroupedCVTs();

            if (otherstageReactants != null && otherstageReactants.Any())
            {
                foreach (var type in otherstageReactants.Keys)
                {
                    if (groupedValidations.ContainsKey(participanttype) && groupedValidations[participanttype].Select(s => s.ExistingType).Contains(type))
                    {
                        var        cvt          = groupedValidations[participanttype].Where(c => c.ExistingType == type).FirstOrDefault();
                        List <int> StageNumbers = PressureValidations.GetStageDisplayOrdersFromFreetexts(Rsns.ToList(), SelectedReaction, cvt.AssociatedFreeText);
                        if (StageNumbers.Contains(SelectedReaction.SelectedStage.DisplayOrder))
                        {
                            var rsnVM = Rsns.Where(rsn => rsn.Reaction.Id == SelectedReaction.Id && rsn.Stage != null && StageNumbers.Contains(rsn.Stage.DisplayOrder) && rsn.SelectedChemical == null &&
                                                   rsn.FreeText.SafeContainsLower(cvt.AssociatedFreeText)).FirstOrDefault();
                            if (rsnVM != null)
                            {
                                rsnVM.SelectedChemical = chemicalName;
                            }
                            return(null);
                        }
                        else
                        {
                            return(otherstageReactants[type].FirstOrDefault());
                        }
                    }
                    else
                    {
                        return(otherstageReactants.Select(s => s.Value).FirstOrDefault().FirstOrDefault());
                    }
                }
            }
            return(null);
        }
        public static ReactionParticipantVM AlreadyContains(TanChemical selectedChemical, ViewAnalogousVM analogousreactionVM, ReactionVM SelectedReaction, ParticipantType participantType, [Optional] List <ReactionParticipantVM> ReactionParticipant, [Optional] List <RsnVM> Rsn, [Optional] bool BulkValidation)
        {
            try
            {
                var ReactionParticipants = ReactionParticipant == null?analogousreactionVM.ReactionParticipants.OfReaction(SelectedReaction.Id) : ReactionParticipant;

                var Rsns = Rsn == null?analogousreactionVM.Rsns.OfReaction(SelectedReaction.Id, true).ToList() : Rsn;

                var chemicalName = new Models.TanChemicalVM
                {
                    Id        = selectedChemical.Id,
                    Name      = selectedChemical.Name,
                    NUM       = selectedChemical.NUM,
                    RegNumber = selectedChemical.RegNumber
                };
                var groupedValidations = S.GetGroupedCVTs();
                if (ReactionParticipants.Count() > 0)
                {
                    if (participantType == ParticipantType.Product)
                    {
                        var existingProducts = ReactionParticipants.OfReaction(SelectedReaction.Id).OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber);
                        if (existingProducts != null && existingProducts.Any())
                        {
                            return(existingProducts.FirstOrDefault());
                        }
                    }

                    else if (SelectedReaction.SelectedStage != null)
                    {
                        #region Reactant Validations
                        if (participantType == ParticipantType.Reactant)
                        {
                            var stageReactants = ReactionParticipants.OfReactionAndStage(SelectedReaction.Id, SelectedReaction.SelectedStage.Id).OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber).OfExceptTypes(ParticipantType.Solvent);
                            if (stageReactants != null && stageReactants.OfType(ParticipantType.Reactant).Any())
                            {
                                return(stageReactants.FirstOrDefault());
                            }
                            List <int> StageNumbers = new List <int>();
                            if (SelectedReaction.Stages.Count > 1)
                            {
                                StageNumbers = PressureValidations.GetStageDisplayOrdersFromFreetexts(Rsns, SelectedReaction, S.DUAL_ROLE_STRING);
                            }
                            else if (Rsns.Where(rsn => rsn.Reaction.Id == SelectedReaction.Id && rsn.Stage == null && rsn.CvtText.SafeEqualsLower(S.DUAL_ROLE_STRING)).Any())
                            {
                                StageNumbers.Add(1);
                            }
                            if (stageReactants != null && stageReactants.OfExceptTypes(ParticipantType.Reactant).Any())
                            {
                                if (!StageNumbers.Contains(SelectedReaction.SelectedStage.DisplayOrder))
                                {
                                    return(stageReactants.OfExceptTypes(ParticipantType.Reactant).FirstOrDefault());
                                }
                                else
                                {
                                    var rsnVM = Rsns.Where(rsn => rsn.Reaction.Id == SelectedReaction.Id &&
                                                           rsn.SelectedChemical == null &&
                                                           (rsn.FreeText.SafeContainsLower(S.DUAL_ROLE_STRING) || rsn.CvtText.SafeEqualsLower(S.DUAL_ROLE_STRING))).FirstOrDefault();
                                    if (rsnVM != null)
                                    {
                                        rsnVM.SelectedChemical = chemicalName;
                                    }
                                }
                            }

                            var Products = ReactionParticipants.OfReactionOfType(SelectedReaction.Id, ParticipantType.Product).OfNum(selectedChemical.NUM);
                            if (Products != null && Products.Any())
                            {
                                return(Products.FirstOrDefault());
                            }

                            var AmdProducts = ReactionParticipants.OfReactionOfType(SelectedReaction.Id, ParticipantType.Product).Where(ro => ro.Reg == selectedChemical.RegNumber && ro.Num != selectedChemical.NUM);
                            if (AmdProducts != null && AmdProducts.Any())
                            {
                                string       msg          = $"Selected chemical with same Reg and different num already involved in {AmdProducts.FirstOrDefault().ReactionVM.DisplayName} as a Product. Do you want to still add as Reactant?";
                                DialogResult dialogResult = System.Windows.Forms.MessageBox.Show(msg, "Reactions", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (dialogResult == DialogResult.No)
                                {
                                    return(AmdProducts.FirstOrDefault());
                                }
                            }

                            var otherstageReactants = ReactionParticipants.OfReactionAndExceptStage(SelectedReaction.Id, SelectedReaction.SelectedStage.Id)
                                                      .OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber)
                                                      .OfExceptTypes(ParticipantType.Solvent, ParticipantType.Product)
                                                      .GroupBy(p => p.ParticipantType)
                                                      .ToDictionary(p => p.Key, p => p.ToList());
                            var duplicate = ValidateWithCVT1(otherstageReactants, Rsns, SelectedReaction, chemicalName, ParticipantType.Reactant);
                            if (duplicate != null)
                            {
                                return(duplicate);
                            }
                        }
                        #endregion

                        #region Solvent Validation
                        if (participantType == ParticipantType.Solvent)
                        {
                            var InStageSolvents = ReactionParticipants.OfReactionAndStage(SelectedReaction.Id, SelectedReaction.SelectedStage.Id).OfExceptTypes(ParticipantType.Reactant).OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber);
                            if (InStageSolvents != null && InStageSolvents.OfType(ParticipantType.Solvent).Any())
                            {
                                return(InStageSolvents.FirstOrDefault());
                            }
                            List <int> StageNumbers = new List <int>();
                            if (SelectedReaction.Stages.Count > 1)
                            {
                                StageNumbers = PressureValidations.GetStageDisplayOrdersFromFreetexts(Rsns, SelectedReaction, S.DUAL_ROLE_STRING);
                            }
                            else if (Rsns.Where(rsn => rsn.Reaction.Id == SelectedReaction.Id && rsn.Stage == null && rsn.CvtText.SafeEqualsLower(S.DUAL_ROLE_STRING)).Any())
                            {
                                StageNumbers.Add(1);
                            }
                            if (InStageSolvents != null && InStageSolvents.OfExceptTypes(ParticipantType.Solvent).Any())
                            {
                                if (!StageNumbers.Contains(SelectedReaction.SelectedStage.DisplayOrder))
                                {
                                    return(InStageSolvents.OfExceptTypes(ParticipantType.Solvent).FirstOrDefault());
                                }
                                else
                                {
                                    var rsnVM = Rsns.Where(rsn => rsn.Reaction.Id == SelectedReaction.Id &&
                                                           rsn.SelectedChemical == null &&
                                                           (rsn.FreeText.SafeContainsLower(S.DUAL_ROLE_STRING) || rsn.CvtText.SafeEqualsLower(S.DUAL_ROLE_STRING))).FirstOrDefault();
                                    if (rsnVM != null)
                                    {
                                        rsnVM.SelectedChemical = chemicalName;
                                    }
                                }
                            }

                            var Products = ReactionParticipants.OfReactionOfType(SelectedReaction.Id, ParticipantType.Product).OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber);
                            if (Products != null && Products.Any())
                            {
                                return(Products.FirstOrDefault());
                            }
                            var otherthanProductsAndSolvents = ReactionParticipants.OfReactionAndExceptStage(SelectedReaction.Id, SelectedReaction.SelectedStage.Id)
                                                               .OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber)
                                                               .OfExceptTypes(ParticipantType.Solvent, ParticipantType.Reactant, ParticipantType.Product)
                                                               .GroupBy(p => p.ParticipantType)
                                                               .ToDictionary(p => p.Key, p => p.ToList());
                            var duplicate = ValidateWithCVT1(otherthanProductsAndSolvents, Rsns, SelectedReaction, chemicalName, ParticipantType.Solvent);
                            if (duplicate != null)
                            {
                                return(duplicate);
                            }
                        }
                        #endregion

                        #region Catalyst Validations
                        if (participantType == ParticipantType.Catalyst)
                        {
                            var InStageCatalysts = ReactionParticipants.OfReactionAndStage(SelectedReaction.Id, SelectedReaction.SelectedStage.Id).OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber);
                            if (InStageCatalysts != null && InStageCatalysts.OfType(ParticipantType.Catalyst).Any())
                            {
                                return(InStageCatalysts.FirstOrDefault());
                            }
                            List <int> StageNumbers = new List <int>();
                            if (SelectedReaction.Stages.Count > 1)
                            {
                                StageNumbers = PressureValidations.GetStageDisplayOrdersFromFreetexts(Rsns, SelectedReaction, S.DUAL_ROLE_STRING);
                            }
                            else if (Rsns.Where(rsn => rsn.Reaction.Id == SelectedReaction.Id && rsn.Stage == null && rsn.CvtText.SafeEqualsLower(S.DUAL_ROLE_STRING)).Any())
                            {
                                StageNumbers.Add(1);
                            }
                            if (InStageCatalysts != null && InStageCatalysts.OfExceptTypes(ParticipantType.Catalyst).Any())
                            {
                                if (!StageNumbers.Contains(SelectedReaction.SelectedStage.DisplayOrder))
                                {
                                    return(InStageCatalysts.OfExceptTypes(ParticipantType.Catalyst).FirstOrDefault());
                                }
                                else
                                {
                                    var rsnVM = Rsns.Where(rsn => rsn.Reaction.Id == SelectedReaction.Id &&
                                                           rsn.SelectedChemical == null &&
                                                           (rsn.FreeText.SafeContainsLower(S.DUAL_ROLE_STRING) || rsn.CvtText.SafeEqualsLower(S.DUAL_ROLE_STRING))).FirstOrDefault();
                                    if (rsnVM != null)
                                    {
                                        rsnVM.SelectedChemical = chemicalName;
                                    }
                                }
                            }
                            var Products = ReactionParticipants.OfReactionOfType(SelectedReaction.Id, ParticipantType.Product).OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber);
                            if (Products != null && Products.Any())
                            {
                                return(Products.FirstOrDefault());
                            }

                            var otherThanCatalysts = ReactionParticipants.OfReactionAndExceptStage(SelectedReaction.Id, SelectedReaction.SelectedStage.Id)
                                                     .OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber)
                                                     .OfExceptTypes(ParticipantType.Catalyst, ParticipantType.Product)
                                                     .GroupBy(p => p.ParticipantType)
                                                     .ToDictionary(p => p.Key, p => p.ToList());
                            var duplicate = ValidateWithCVT1(otherThanCatalysts, Rsns, SelectedReaction, chemicalName, ParticipantType.Catalyst);
                            if (duplicate != null)
                            {
                                return(duplicate);
                            }
                        }
                        #endregion
                        #region Agent Validations
                        if (participantType == ParticipantType.Agent)
                        {
                            var InStageAgents = ReactionParticipants.OfReactionAndStage(SelectedReaction.Id, SelectedReaction.SelectedStage.Id).OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber);
                            if (InStageAgents != null && InStageAgents.OfType(ParticipantType.Agent).Any())
                            {
                                return(InStageAgents.FirstOrDefault());
                            }
                            List <int> StageNumbers = new List <int>();
                            if (SelectedReaction.Stages.Count > 1)
                            {
                                StageNumbers = PressureValidations.GetStageDisplayOrdersFromFreetexts(Rsns, SelectedReaction, S.DUAL_ROLE_STRING);
                            }
                            else if (Rsns.Where(rsn => rsn.Reaction.Id == SelectedReaction.Id && rsn.Stage == null && rsn.CvtText.SafeEqualsLower(S.DUAL_ROLE_STRING)).Any())
                            {
                                StageNumbers.Add(1);
                            }
                            if (InStageAgents != null && InStageAgents.OfExceptTypes(ParticipantType.Agent).Any())
                            {
                                if (!StageNumbers.Contains(SelectedReaction.SelectedStage.DisplayOrder))
                                {
                                    return(InStageAgents.OfExceptTypes(ParticipantType.Agent).FirstOrDefault());
                                }
                                else
                                {
                                    var rsnVM = Rsns.Where(rsn => rsn.Reaction.Id == SelectedReaction.Id &&
                                                           rsn.SelectedChemical == null &&
                                                           (rsn.FreeText.SafeContainsLower(S.DUAL_ROLE_STRING) || rsn.CvtText.SafeEqualsLower(S.DUAL_ROLE_STRING))).FirstOrDefault();
                                    if (rsnVM != null)
                                    {
                                        rsnVM.SelectedChemical = chemicalName;
                                    }
                                }
                            }

                            var Products = ReactionParticipants.OfReactionOfType(SelectedReaction.Id, ParticipantType.Product).OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber);
                            if (Products != null && Products.Any())
                            {
                                return(Products.FirstOrDefault());
                            }

                            var otherStageAgents = ReactionParticipants.OfReactionAndExceptStage(SelectedReaction.Id, SelectedReaction.SelectedStage.Id)
                                                   .OfNumOrReg(selectedChemical.NUM, selectedChemical.RegNumber)
                                                   .OfExceptTypes(ParticipantType.Agent, ParticipantType.Product)
                                                   .GroupBy(p => p.ParticipantType)
                                                   .ToDictionary(p => p.Key, p => p.ToList());

                            var duplicate = ValidateWithCVT1(otherStageAgents, Rsns, SelectedReaction, chemicalName, ParticipantType.Agent);
                            if (duplicate != null)
                            {
                                return(duplicate);
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        return(null);
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                Log.This(ex);
                return(null);
            }
        }
예제 #6
0
        public static bool ValidateRsnReactionLevel(ReactionVM ReactionVM, StageVM StageVM, RsnLevel RsnLevel, string CVT, string FreeText, List <RsnVM> Rsns, out string outMsg, RsnVM EditingRsn = null)
        {
            if (RsnLevel == RsnLevel.STAGE)
            {
                if (!string.IsNullOrEmpty(CVT) && string.IsNullOrEmpty(FreeText))
                {
                    outMsg = "Stage Level CVT Used, Then Freetext is mandatory..";
                    return(false);
                }
                else if (!string.IsNullOrEmpty(FreeText))
                {
                    if (!ValidateRsnEditArea(FreeText, ReactionVM, StageVM, RsnLevel, out outMsg))
                    {
                        return(false);
                    }
                }
                else
                {
                    outMsg = "Stage Level Information missed in Freetext Term... / Ends with some Special characters";
                    return(false);
                }
            }
            var  reactionRsns = Rsns.Where(rsn => rsn.Reaction != null && rsn.Reaction.Id == ReactionVM.Id);
            bool OnlyOneFreeTextInReactionLevel = (CVT == String.Empty && RsnLevel == RsnLevel.REACTION && Rsns.Any(r => r.Reaction != null && r.Reaction.Id == ReactionVM.Id && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.Stage == null && r.CvtText == String.Empty)) ? false : true;

            if (OnlyOneFreeTextInReactionLevel)
            {
                bool OnlyOneFreeTextInStageLevel = (CVT == String.Empty && RsnLevel == RsnLevel.STAGE && Rsns.Any(r => r.Reaction != null && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.Reaction.Id == ReactionVM.Id && r.Stage != null && r.Stage.Id == StageVM.Id && r.CvtText == String.Empty)) ? false : true;
                if (OnlyOneFreeTextInStageLevel)
                {
                    if (!String.IsNullOrEmpty(CVT) && reactionRsns.Where(r => (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.CvtText.SafeEqualsLower(CVT)).Any())
                    {
                        var SelectedRSNTerm = reactionRsns.Where(r => (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.CvtText == CVT).FirstOrDefault();
                        outMsg = "Selected CVT " + (!String.IsNullOrEmpty(CVT) ? CVT : FreeText) + " Already used in " + (SelectedRSNTerm?.Stage != null ? SelectedRSNTerm?.Stage.Name : SelectedRSNTerm.Reaction.DisplayName);
                        return(false);
                    }
                    if (!string.IsNullOrEmpty(FreeText))
                    {
                        var splittedFreetexts = FreeText.Split(new String[] { RsnLevel == RsnLevel.REACTION ? ", " : "), " }, StringSplitOptions.RemoveEmptyEntries).Select(c => FreeTextWithOutStageInfo(c));
                        foreach (var item in splittedFreetexts)
                        {
                            if (S.CommentDictionary.CVT.Where(cvt => item.Trim().SafeEqualsLower(cvt.CVTS.Trim())).Any())
                            {
                                outMsg = $"Selected FreeText contains CVT term \"{item}\"";
                                return(false);
                            }
                            var result = reactionRsns.Where(r => (EditingRsn != null ? r.Id != EditingRsn.Id : true) && ((!String.IsNullOrEmpty(r.FreeText) && r.FreeText.Split(new String[] { r.IsRXN ? ", " : "), " }, StringSplitOptions.RemoveEmptyEntries).Where(eachText => FreeTextWithOutStageInfo(eachText).SafeEqualsLower(item)).Any()) || ((!string.IsNullOrEmpty(r.CvtText)) && item.SafeEqualsLower(r.CvtText.Trim()))));
                            if (!string.IsNullOrEmpty(item) && result != null && result.Any())
                            {
                                var SelectedRSNTerm = result.FirstOrDefault();
                                outMsg = "Selected FreeText " + item + " Already used in " + (SelectedRSNTerm?.Stage != null ? SelectedRSNTerm?.Stage.Name : SelectedRSNTerm.Reaction.DisplayName);
                                return(false);
                            }
                        }
                    }
                    outMsg = string.Empty;
                    return(true);
                }
                else
                {
                    outMsg = "Only One Stage Level Free Text Is Allowed With out CVT . .";
                    return(false);
                }
            }
            else
            {
                outMsg = "Only One Reaction Level Free Text Is Allowed With out CVT . .";
                return(false);
            }
        }
예제 #7
0
        public static bool ValidateRsnFreetext(string FreeText, ReactionVM ReactionVM, StageVM StageVM, RsnLevel RsnLevel, out string outMsg)
        {
            string freetextREstring = S.RegularExpressions.Where(re => re.RegulerExpressionFor == ProductTracking.Models.Core.RegulerExpressionFor.FreeText).Select(re => re.Expression).FirstOrDefault();
            Regex  FreetextRE       = new Regex(freetextREstring);
            var    SPLList          = new List <string> {
                "==", "%%", ",,", "((", "))", "{{", "}}", "++", "//", "\\", "::", ";;", "--", "..", "  ", "''", "<<", ">>", "**", "@@", "[[", "]]", ", ,", ").", ".,", " ."
            };

            if (!string.IsNullOrEmpty(FreeText) && SPLList.Where(spl => FreeText.Contains(spl)).FirstOrDefault() != null)
            {
                outMsg = $"Freetext contains invalid repetation of special Characters <SPL Char Start>{SPLList.Where(spl => FreeText.Contains(spl)).FirstOrDefault()}</SPL Char End>.";
                return(false);
            }
            if (!string.IsNullOrEmpty(FreeText) && StageVM != null && RsnLevel == RsnLevel.STAGE)
            {
                string[] list = FreeText.Split(new string[] { "), " }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var freetext in list)
                {
                    string     newText = !freetext.EndsWith(")") ? $"{freetext})" : freetext;
                    List <int> data    = PressureValidations.GetStageDisplayOrdersFromFreetexts(new List <RsnVM> {
                        new ViewModels.RsnVM {
                            Reaction = ReactionVM, Stage = StageVM, FreeText = newText
                        }
                    }, ReactionVM, FreeTextWithOutStageInfo(newText));
                    if (!data.Contains(StageVM.DisplayOrder) && RsnLevel == RsnLevel.STAGE)
                    {
                        outMsg = $"Freetext must contain current stage Number in '{freetext}'";
                        return(false);
                    }
                }
            }
            if (RsnLevel == RsnLevel.REACTION && !string.IsNullOrEmpty(FreeText) && FreeText.Contains(","))
            {
                var list = $" {FreeText}".Split(',');
                if (list.Where(l => !l.StartsWith(" ")).Any())
                {
                    outMsg = "FreeText must seperated by comma and space in Reaction level.";
                    return(false);
                }
            }
            if (RsnLevel == RsnLevel.STAGE && !string.IsNullOrEmpty(FreeText) && FreeText.Contains("),"))
            {
                var list = $" {FreeText}".Split(new string[] { ")," }, StringSplitOptions.RemoveEmptyEntries);
                if (list.Where(l => !l.StartsWith(" ")).Any())
                {
                    outMsg = "FreeText must seperated by comma and space in stage level.";
                    return(false);
                }
            }
            if (!string.IsNullOrEmpty(FreeText) && FreeText.Contains(", ") && FreeText.ToLower().Split(new string[] { RsnLevel == RsnLevel.REACTION ? ", " : "), " }, StringSplitOptions.RemoveEmptyEntries).GroupBy(s => FreeTextWithOutStageInfo(s)).SelectMany(grp => grp.Skip(1)).Count() > 0)
            {
                outMsg = "FreeText Contains duplicates.";
                return(false);
            }

            if (!string.IsNullOrEmpty(FreeText) && FreeText.Contains(", ") && FreeText.ToLower().Split(new string[] { RsnLevel == RsnLevel.REACTION ? ", " : "), " }, StringSplitOptions.RemoveEmptyEntries).Where(s => s.EndsWith(".")).Count() > 0)
            {
                outMsg = "FreeText ending with .(Period)";
                return(false);
            }

            if (RsnLevel == RsnLevel.STAGE && StageVM == null)
            {
                outMsg = "Please Select Stage to Add Stage RSN";
                return(false);
            }

            if (RsnLevel == RsnLevel.REACTION && !String.IsNullOrEmpty(FreeText) && FreeText.Contains("(stage"))
            {
                outMsg = "Reaction Level stage information Not allowed";
                return(false);
            }

            if (!string.IsNullOrEmpty(FreeText) && !FreetextRE.IsMatch(FreeText))
            {
                outMsg = "FreeText Contains special characters.";
                return(false);
            }
            outMsg = string.Empty;
            return(true);
        }
예제 #8
0
        public static bool ValidateRsnEditArea(string FreeText, ReactionVM ReactionVM, StageVM StageVM, RsnLevel RsnLevel, out string outMsg)
        {
            bool result = false;

            if (RsnLevel == RsnLevel.STAGE && !FreeText.EndsWith(")"))
            {
                outMsg = $"Freetext must ends with ) in Stage level";
                return(result);
            }
            var splittedFreetexts = FreeText.Split(new string[] { RsnLevel == RsnLevel.REACTION ? ", " : "), " }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var splittedText in splittedFreetexts)
            {
                string updatedFreetext = splittedText;
                if (RsnLevel == RsnLevel.STAGE && !updatedFreetext.EndsWith(")"))
                {
                    updatedFreetext = updatedFreetext + ")";
                }
                if (RsnLevel == RsnLevel.STAGE && !updatedFreetext.Contains(" (stage"))
                {
                    outMsg = $"Freetext and Stage information must be seperated by 'Single Space' in {splittedText}";
                    return(result);
                }

                List <int> stageNumbers = new List <int>();
                outMsg = "";
                if (GetStageNumbersFromFreeText(updatedFreetext, ref stageNumbers, ref outMsg))
                {
                    if (stageNumbers.Count > 1)
                    {
                        if (!stageNumbers.SequenceEqual(stageNumbers.OrderBy(n => n)))
                        {
                            outMsg = S.STAGE_ASCE_ERR_MSG;
                            return(result);
                        }
                        var duplicates = stageNumbers.GroupBy(s => s).SelectMany(grp => grp.Skip(1));
                        if (duplicates.Any())
                        {
                            outMsg = S.STAGE_DUPLICATE_ERR_MSG;
                            return(result);
                        }
                        if (stageNumbers[0] > stageNumbers[stageNumbers.Count - 1] || stageNumbers.Max() > ReactionVM.Stages.Max(s => s.DisplayOrder) || stageNumbers.Min() <= 0 ||
                            stageNumbers.Min() > ReactionVM.Stages.Max(s => s.DisplayOrder) || stageNumbers.Min() != StageVM.DisplayOrder)
                        {
                            outMsg = $"{S.STAGE_RANGE_ERR_MSG}{updatedFreetext}";
                            return(result);
                        }
                    }
                }
                else
                {
                    return(false);
                }

                #region Commented
                //if (Regex.IsMatch(updatedFreetext, S.STAGEINFO_RANGE))
                //{
                //    var itemlist = regex.Match(updatedFreetext).Value.Replace("(stages ", "").Replace(")", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
                //    if (itemlist[0] > itemlist[1] || itemlist[0] == itemlist[1] || itemlist[1] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] < 0 ||
                //        itemlist[0] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] != StageVM.DisplayOrder)
                //    {
                //        outMsg = $"{S.STAGE_RANGE_ERR_MSG}{updatedFreetext}";
                //        return result;
                //    }
                //}
                //else if (Regex.IsMatch(updatedFreetext, S.STAGEINFO_AND))
                //{
                //    var itemlist = regex.Match(updatedFreetext).Value.Replace("(stages ", "").Replace(" and ", "-").Replace(")", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
                //    if (itemlist[0] > itemlist[1] || itemlist[0] == itemlist[1] || itemlist[1] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] < 0 ||
                //        itemlist[0] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] != StageVM.DisplayOrder)
                //    {
                //        outMsg = $"{S.STAGE_RANGE_ERR_MSG}{updatedFreetext}";
                //        return result;
                //    }
                //}

                //else if (Regex.IsMatch(updatedFreetext, S.STAGEINFO_MULTIPLE_COMMA))
                //{
                //    var itemlist = regex.Match(updatedFreetext).Value.Replace("(stages ", "").Replace(",", "-").Replace(")", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
                //    if (itemlist[0] > itemlist[itemlist.Count - 1] || itemlist[0] == itemlist[1] || itemlist[itemlist.Count - 1] > ReactionVM.Stages.Max(s => s.DisplayOrder) ||
                //        itemlist[0] < 0 || itemlist[0] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] != StageVM.DisplayOrder)
                //    {
                //        outMsg = $"{S.STAGE_RANGE_ERR_MSG}{updatedFreetext}";
                //        return result;
                //    }
                //    if (!itemlist.SequenceEqual(itemlist.OrderBy(n => n)))
                //    {
                //        outMsg = S.STAGE_ASCE_ERR_MSG;
                //        return result;
                //    }
                //    var duplicates = itemlist.GroupBy(s => s).SelectMany(grp => grp.Skip(1));
                //    if (duplicates.Count() > 0)
                //    {
                //        outMsg = S.STAGE_DUPLICATE_ERR_MSG;
                //        return result;
                //    }
                //}
                //else if (Regex.IsMatch(updatedFreetext, S.STAGEINFO_MULTIPLE_COMMA_AND))
                //{
                //    var itemlist = regex.Match(updatedFreetext).Value.Replace("(stages ", "").Replace(",", "-").Replace(" and ", "-").Replace(")", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
                //    if (itemlist[0] > itemlist[itemlist.Count - 1] || itemlist.Distinct().Count() != itemlist.Count() || itemlist.Max() > ReactionVM.Stages.Max(s => s.DisplayOrder) ||
                //        itemlist[0] < 0 || itemlist[0] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] != StageVM.DisplayOrder)
                //    {
                //        outMsg = $"{S.STAGE_RANGE_ERR_MSG}{updatedFreetext}";
                //        return result;
                //    }
                //    if (!itemlist.SequenceEqual(itemlist.OrderBy(n => n)))
                //    {
                //        outMsg = S.STAGE_ASCE_ERR_MSG;
                //        return result;
                //    }
                //    var duplicates = itemlist.GroupBy(s => s).SelectMany(grp => grp.Skip(1));
                //    if (duplicates.Count() > 0)
                //    {
                //        outMsg = S.STAGE_DUPLICATE_ERR_MSG;
                //        return result;
                //    }
                //}
                //else if (Regex.IsMatch(updatedFreetext, S.STAGEINFO_RANGE_AND_RANGE))
                //{
                //    var itemlist = regex.Match(updatedFreetext).Value.Replace("(stages ", string.Empty).Replace(" and ", "-").Replace(")", string.Empty).Split('-').Select(c => Convert.ToInt32(c)).ToList();
                //    if (itemlist[0] > itemlist[1] || itemlist.Distinct().Count() != itemlist.Count() || itemlist.Max() > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] < 0 ||
                //        itemlist[0] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] != StageVM.DisplayOrder)
                //    {
                //        outMsg = $"{S.STAGE_RANGE_ERR_MSG}{updatedFreetext}";
                //        return result;
                //    }
                //    if (!itemlist.SequenceEqual(itemlist.OrderBy(n => n)))
                //    {
                //        outMsg = S.STAGE_ASCE_ERR_MSG;
                //        return result;
                //    }
                //    var duplicates = itemlist.GroupBy(s => s).SelectMany(grp => grp.Skip(1));
                //    if (duplicates.Count() > 0)
                //    {
                //        outMsg = S.STAGE_DUPLICATE_ERR_MSG;
                //        return result;
                //    }
                //}

                //else if (Regex.IsMatch(updatedFreetext, S.STAGEINFO_RANGE_COMMA_AND))
                //{
                //    List<int> StageNumbers = new List<int>();
                //    var itemlist = regex.Match(updatedFreetext).Value.Replace("(stages ", "").Replace(")", "").Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();
                //    var splittedListWithRange = itemlist[0].Split('-').Select(c => Convert.ToInt32(c)).ToList();
                //    if (splittedListWithRange.Count > 1)
                //        for (int r = splittedListWithRange[0]; r <= splittedListWithRange[1]; r++)
                //            StageNumbers.Add(r);
                //    var splittedList = itemlist[1].Replace(" and ", "-").Split('-').Select(c => Convert.ToInt32(c)).ToList();
                //    StageNumbers.AddRange(splittedList);


                //    if (StageNumbers[0] > StageNumbers[1] || itemlist.Distinct().Count() != itemlist.Count() || StageNumbers.Max() > ReactionVM.Stages.Max(s => s.DisplayOrder) || StageNumbers[0] < 0 || StageNumbers[0] > ReactionVM.Stages.Max(s => s.DisplayOrder) || StageNumbers[0] != StageVM.DisplayOrder)
                //    {
                //        outMsg = $"{S.STAGE_RANGE_ERR_MSG}{updatedFreetext}";
                //        return result;
                //    }
                //    if (!StageNumbers.SequenceEqual(StageNumbers.OrderBy(n => n)))
                //    {
                //        outMsg = S.STAGE_ASCE_ERR_MSG;
                //        return result;
                //    }
                //    var duplicates = StageNumbers.GroupBy(s => s).SelectMany(grp => grp.Skip(1));
                //    if (duplicates.Count() > 0)
                //    {
                //        outMsg = S.STAGE_DUPLICATE_ERR_MSG;
                //        return result;
                //    }
                //}
                //else if (Regex.IsMatch(updatedFreetext, S.STAGEINFO_SINGLE_STAGE))
                //{
                //    string s = regex.Match(updatedFreetext).Value.Replace("(stage ", "").Replace(")", "");
                //    if (!int.TryParse(s, out value) || value != StageVM.DisplayOrder)
                //    {
                //        outMsg = "Stage Level Information must be selected stage information";
                //        return result;
                //    }
                //}
                #endregion
            }
            result = true;
            outMsg = string.Empty;
            return(result);
        }
예제 #9
0
        public static List<ValidationError> TermalValidations(IEnumerable<ReactionParticipantVM> participants, List<string> SolventReg, List<SolventBoilingPointDTO> solventBoilingPoints, TanVM tanVM, ReactionVM reaction, StageVM stage, List<RsnVM> freeTexts)
        {
            ExtentionMethods common = new ExtentionMethods();

            var errors = new List<ValidationError>();
            try
            {
                var solvents = participants.OfStageOfType(stage.Id, ParticipantType.Solvent).Where(s => SolventReg.Contains(s.Reg)).ToList();
                bool unUsedCVT = false;
                #region 12-4
                var CVTList = tanVM.Rsns.OfReactionAndStage(reaction.Id, stage.Id).Where(c => !string.IsNullOrEmpty(c.CvtText)).Select(cvt => cvt.CvtText);
                List<int> StageThermalNumbers = PressureValidations.GetStageDisplayOrdersFromFreetexts(freeTexts, reaction, S.THERMAL_STRING, new List<string> { S.HYDRO_THERMAL_STRING, S.SOLVO_THERMAL_STRING });
                List<int> MicrowaveStageNumbers = PressureValidations.GetStageDisplayOrdersFromFreetexts(freeTexts, reaction, S.MICROWAVE_STRING);
                if (CVTList.Contains(S.MIC_IRR) || MicrowaveStageNumbers.Contains(stage.DisplayOrder))
                    if (CVTList.Contains(S.THERMAL_STRING) || StageThermalNumbers.Contains(stage.DisplayOrder))
                        errors.Add(VF.OfRSN(reaction, "Microwave irradiation has no Thermal RSN even though it exceeds boiling point of solvent", stage));
                #endregion
                if ((tanVM.Rsns.OfReaction(reaction.Id).Where(cvt=> (cvt.CvtText.SafeEqualsLower(S.THERMAL_STRING) || (cvt.FreeText.IncludeExclude(S.THERMAL_STRING, new List<string> { S.HYDRO_THERMAL_STRING, S.SOLVO_THERMAL_STRING })))).Any()
                    || StageThermalNumbers.Contains(stage.DisplayOrder)) && (stage.Conditions == null || !stage.Conditions.Any() || stage.Conditions.Where(con => !string.IsNullOrEmpty(con.Temperature)).Count() == 0 || solvents == null || solvents.Count == 0 || solvents.Count > 1))
                    errors.Add(VF.OfRSN(reaction,"RSN CVT/FreeText 'thermal' Present. It allowed only when Solvent Boiling point exceeds.", stage));

                if (solvents.Any() && solvents.Count == 1 && stage.Conditions != null)
                {
                    var TemperatureList = stage.Conditions.Where(con => !string.IsNullOrEmpty(con.Temperature) && con.TEMP_TYPE != TemperatureEnum.RefluxtoRoomTemp.ToString() && con.TEMP_TYPE != TemperatureEnum.RoomTemptoReflux.ToString());
                    foreach (var condition in TemperatureList)
                    {
                        try
                        {
                            string TempUnit = string.Empty;
                            var sol = (from p in solventBoilingPoints where solvents.Select(r => r.Reg).Contains(p.RegNo) select p).FirstOrDefault();
                            common.GetTemperatureAndUnitsFromString(condition.Temperature, out TempUnit, condition);
                            float i = 0, j = 0, k = 0;
                            var temperatureValue = Regex.Replace(condition.Temperature, "[^0-9.\\-\\]]", "");
                            if (temperatureValue.Contains("-") || temperatureValue.Contains("]"))
                            {
                                string[] splitterRange = { "-", "]" };
                                string[] strValsRange = temperatureValue.Split(splitterRange, StringSplitOptions.RemoveEmptyEntries);
                                if (temperatureValue.Contains($"-{strValsRange[0]}"))
                                    strValsRange[0] = $"-{strValsRange[0]}";
                                if (strValsRange.Count() > 1 && (temperatureValue.Contains($"--{strValsRange[1]}") || temperatureValue.Contains($"]-{strValsRange[1]}")))
                                    strValsRange[1] = $"-{strValsRange[1]}";
                                if (strValsRange.Count() > 1)
                                {
                                    if (float.TryParse(common.GetTemperatureAndUnitsFromString(strValsRange[0], out TempUnit), out j) && float.TryParse(common.GetTemperatureAndUnitsFromString(strValsRange[1], out TempUnit), out k))
                                    {
                                        if (j > k)
                                            temperatureValue = j.ToString();
                                        else
                                            temperatureValue = k.ToString();
                                    }
                                }
                                else
                                    temperatureValue = common.GetTemperatureAndUnitsFromString(strValsRange[0], out TempUnit);
                            }
                            if (float.TryParse(temperatureValue, out i) && ((TempUnit == S.FH_UNIT && i > sol.fahrenheitBoilingPoint) || (TempUnit == S.K_UNIT && i > sol.KelvinBoilingPoint) || (TempUnit == S.RANKINE_UNIT && i > sol.RankineBoilingPoint) || (TempUnit == S.CENTI_UNIT && i > sol.DegreesBoilingPoint)))
                            {
                                List<int> StagemicrowaveNumbers = PressureValidations.GetStageDisplayOrdersFromFreetexts(freeTexts, reaction, S.MICROWAVE_STRING);
                                if (freeTexts.Where(f => f.Stage != null && f.Stage.Id == stage.Id && (f.FreeText.IncludeExclude(S.THERMAL_STRING, new List<string> { S.HYDRO_THERMAL_STRING, S.SOLVO_THERMAL_STRING }) || f.CvtText.IncludeExclude(S.THERMAL_STRING, new List<string> { S.SOLVO_THERMAL_STRING, S.HYDRO_THERMAL_STRING }))).Count() == 0 && !StageThermalNumbers.Contains(stage.DisplayOrder) && !StagemicrowaveNumbers.Contains(stage.DisplayOrder) &&
                                    tanVM.Rsns.Where(r => r.Reaction.Id == reaction.Id && r.Stage == null && r.CvtText.SafeEqualsLower(S.MIC_IRR)).Count() == 0 && tanVM.Rsns.Where(r => r.Reaction.Id == reaction.Id && r.Stage == null && (r.CvtText.SafeContainsLower(S.THERMAL_STRING) || r.FreeText.IncludeExclude(S.THERMAL_STRING, new List<string> { S.HYDRO_THERMAL_STRING, S.SOLVO_THERMAL_STRING }))).Count() == 0)
                                    errors.Add(VF.OfRSN(reaction, 
                                                        $"Solvent {sol.Name} Boiling Point is  {(TempUnit == S.K_UNIT ? sol.KelvinBoilingPoint : TempUnit == S.RANKINE_UNIT ? sol.RankineBoilingPoint : TempUnit == S.FH_UNIT ? sol.fahrenheitBoilingPoint : sol.DegreesBoilingPoint)} {TempUnit} Exceeded. RSN CVT/Free should be 'thermal'",
                                                        stage));

                            }
                            if ((float.TryParse(temperatureValue, out i) && ((TempUnit == S.FH_UNIT && i <= sol.fahrenheitBoilingPoint) || (TempUnit == S.K_UNIT && i <= sol.KelvinBoilingPoint) || (TempUnit == S.RANKINE_UNIT && i <= sol.RankineBoilingPoint) || (TempUnit == S.CENTI_UNIT && i <= sol.DegreesBoilingPoint))) || (condition.TEMP_TYPE == TemperatureEnum.Cool.ToString() || condition.TEMP_TYPE == TemperatureEnum.Roomtemp.ToString() || condition.TEMP_TYPE == TemperatureEnum.RefluxBoiled.ToString() || condition.TEMP_TYPE == TemperatureEnum.Heated.ToString() || condition.TEMP_TYPE == TemperatureEnum.LessthanRoomTemp.ToString() || condition.TEMP_TYPE == TemperatureEnum.RoomTempgraterthan.ToString() || condition.TEMP_TYPE == TemperatureEnum.Cool.ToString()))
                            {
                                if ((freeTexts.Where(f => f.Stage != null && f.Stage.Id == stage.Id && (f.FreeText.IncludeExclude(S.THERMAL_STRING, new List<string> { S.HYDRO_THERMAL_STRING, S.SOLVO_THERMAL_STRING }) || f.CvtText.SafeContainsLower(S.THERMAL_STRING))).Count() > 0 || StageThermalNumbers.Contains(stage.DisplayOrder) ||
                                     tanVM.Rsns.Where(r => r.Reaction.Id == reaction.Id && r.Stage == null && (r.CvtText.SafeContainsLower(S.THERMAL_STRING) || r.FreeText.IncludeExclude(S.THERMAL_STRING, new List<string> { S.HYDRO_THERMAL_STRING, S.SOLVO_THERMAL_STRING }))).Count() > 0) && !unUsedCVT)
                                    unUsedCVT = false;
                            }
                            else
                                unUsedCVT = true;
                        }
                        catch (Exception ex)
                        {
                            Log.This(ex);
                        }
                    }
                    if ((StageThermalNumbers.Contains(stage.DisplayOrder) || tanVM.Rsns.Where(cvt => cvt.Reaction.Id == reaction.Id && cvt.Stage == null && (cvt.CvtText.SafeEqualsLower(S.THERMAL_STRING) || cvt.FreeText.IncludeExclude(S.THERMAL_STRING, new List<string> { S.HYDRO_THERMAL_STRING, S.SOLVO_THERMAL_STRING }))).Count() > 0) && !unUsedCVT)
                        errors.Add(VF.OfRSN(reaction,"RSN CVT/FreeText 'thermal' Present. It allowed only when Solvent Boiling point exceeds.", stage));
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
            }
            return errors;
        }
예제 #10
0
        public static ViewAnalogousVM GenerateNewAnalogousReactions(
            ReactionVM SelectedReaction,
            bool IsReactantsSelected,
            bool IsSolventsSelected,
            bool IsAgentsSelected,
            bool IsCatalystSelected,
            bool IspHSelected,
            bool IsTempSelected,
            bool IsTimeSelected,
            bool IsPressureSelected,
            bool IsRSNSelected,
            int ReactionsCountToCopy, int IndexToAdd
            )
        {
            ViewAnalogousVM vm            = new ViewAnalogousVM();
            var             mainViewModel = ((MainWindow)(App.Current.MainWindow)).DataContext as MainVM;

            mainViewModel.ProgressText = "Creating Analogous Reacions . .";
            try
            {
                vm.SelectedMasterReaction = SelectedReaction;
                List <ReactionParticipantVM> allParticipants = new List <ReactionParticipantVM>();
                List <RsnVM>      tanRsns      = new List <RsnVM>();
                List <ReactionVM> tanReactions = new List <ReactionVM>();
                var tanParticipants            = new List <ReactionParticipantVM>();
                if (IsReactantsSelected)
                {
                    var reactants = mainViewModel.TanVM.ReactionParticipants.OfType(ParticipantType.Reactant);
                    allParticipants.AddRange(reactants);
                }
                if (IsSolventsSelected)
                {
                    var solvents = mainViewModel.TanVM.ReactionParticipants.OfType(ParticipantType.Solvent);
                    allParticipants.AddRange(solvents);
                }

                if (IsAgentsSelected)
                {
                    var agents = mainViewModel.TanVM.ReactionParticipants.OfType(ParticipantType.Agent);
                    allParticipants.AddRange(agents);
                }

                if (IsCatalystSelected)
                {
                    var catalysts = mainViewModel.TanVM.ReactionParticipants.OfType(ParticipantType.Catalyst);
                    allParticipants.AddRange(catalysts);
                }
                for (int i = 0; i < ReactionsCountToCopy; i++)
                {
                    var reaction = new ReactionVM
                    {
                        DisplayOrder  = ++IndexToAdd,
                        Id            = Guid.NewGuid(),
                        TanVM         = SelectedReaction.TanVM,
                        AnalogousVMId = SelectedReaction.Id
                    };
                    #region Stages
                    var stages = new List <StageVM>();
                    foreach (var masterStage in SelectedReaction.Stages)
                    {
                        bool ValidStage     = true;
                        var  analogousStage = new StageVM {
                            Id = Guid.NewGuid(), ReactionVm = reaction
                        };
                        var Conditions = new List <StageConditionVM>();
                        if (masterStage.Conditions != null)
                        {
                            foreach (var selectedCondition in masterStage.Conditions)
                            {
                                var condition = new StageConditionVM
                                {
                                    DisplayOrder  = selectedCondition.DisplayOrder,
                                    Id            = Guid.NewGuid(),
                                    PH            = IspHSelected ? selectedCondition.PH : "",
                                    Pressure      = IsPressureSelected ? selectedCondition.Pressure : "",
                                    StageId       = analogousStage.Id,
                                    Temperature   = IsTempSelected ? selectedCondition.Temperature : "",
                                    Time          = IsTimeSelected ? selectedCondition.Time : "",
                                    TIME_TYPE     = IsTimeSelected ? selectedCondition.TIME_TYPE : "",
                                    PRESSURE_TYPE = IsPressureSelected ? selectedCondition.PRESSURE_TYPE : "",
                                    TEMP_TYPE     = IsTempSelected ? selectedCondition.TEMP_TYPE : "",
                                    PH_TYPE       = IspHSelected ? selectedCondition.PH_TYPE : "",
                                };
                                if ((IspHSelected && !string.IsNullOrEmpty(selectedCondition.PH)) || (IsPressureSelected && !string.IsNullOrEmpty(selectedCondition.Pressure)) ||
                                    (IsTempSelected && !string.IsNullOrEmpty(selectedCondition.Temperature)) || (IsTimeSelected && !string.IsNullOrEmpty(selectedCondition.Time)))
                                {
                                    Conditions.Add(condition);
                                }
                            }
                            analogousStage.SetConditions(Conditions);
                        }
                        var stageParticipants = (from sp in allParticipants where sp.StageVM.Id == masterStage.Id select sp).ToList();
                        foreach (var stageParticipant in stageParticipants)
                        {
                            var newParticipant = new ReactionParticipantVM
                            {
                                ChemicalType    = stageParticipant.ChemicalType,
                                DisplayOrder    = stageParticipant.DisplayOrder,
                                Name            = stageParticipant.Name,
                                Num             = stageParticipant.Num,
                                ParticipantType = stageParticipant.ParticipantType,
                                ReactionVM      = reaction,
                                Reg             = stageParticipant.Reg,
                                StageVM         = analogousStage,
                                TanChemicalId   = stageParticipant.TanChemicalId,
                                Yield           = stageParticipant.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 == masterStage.Id select rsn).ToList();
                            foreach (var rsn in stagersnList)
                            {
                                var newRsn = new RsnVM
                                {
                                    CvtText  = rsn.CvtText,
                                    Reaction = reaction,
                                    IsRXN    = rsn.IsRXN,
                                    Stage    = analogousStage,
                                    FreeText = rsn.FreeText,
                                    Id       = Guid.NewGuid(),
                                    IsIgnorableInDelivery = rsn.IsIgnorableInDelivery,
                                    DisplayOrder          = rsn.DisplayOrder,
                                    ReactionParticipantId = rsn.ReactionParticipantId,
                                    SelectedChemical      = rsn.SelectedChemical
                                };
                                tanRsns.Add(newRsn);
                            }
                        }
                        if ((analogousStage.Conditions == null || !analogousStage.Conditions.Any()) &&
                            (tanParticipants == null || !tanParticipants.Where(tp => tp.StageVM != null && tp.StageVM.Id == analogousStage.Id).Any()) &&
                            (tanRsns == null || !tanRsns.Where(tp => tp.Stage != null && tp.Stage.Id == analogousStage.Id).Any()) && !mainViewModel.TanVM.ReactionParticipants.OfReactionAndStage(SelectedReaction.Id, masterStage.Id).OfType(ParticipantType.Reactant).Any())
                        {
                            ValidStage = false;
                        }
                        if (ValidStage)
                        {
                            stages.Add(analogousStage);
                        }
                    }
                    #endregion
                    reaction.SetStages(stages, 0, false, true);
                    tanReactions.Add(reaction);
                    var reactionParticipants = (from sp in allParticipants where sp.ReactionVM.Id == SelectedReaction.Id && sp.StageVM == null select sp).ToList();
                    foreach (var participant in reactionParticipants)
                    {
                        var newParticipant = new ReactionParticipantVM
                        {
                            ChemicalType    = participant.ChemicalType,
                            DisplayOrder    = participant.DisplayOrder,
                            Name            = participant.Name,
                            Num             = participant.Num,
                            ParticipantType = participant.ParticipantType,
                            ReactionVM      = reaction,
                            Reg             = participant.Reg,
                            StageVM         = null,
                            TanChemicalId   = participant.TanChemicalId,
                            Yield           = participant.Yield,
                            Id = Guid.NewGuid()
                        };
                        tanParticipants.Add(newParticipant);
                    }

                    if (IsRSNSelected)
                    {
                        var reationrsnList = (from rsn in mainViewModel.TanVM.Rsns where rsn.Reaction.Id == SelectedReaction.Id && rsn.Stage == null select rsn).ToList();
                        foreach (var rsn in reationrsnList)
                        {
                            var newRsn = new RsnVM
                            {
                                CvtText               = rsn.CvtText,
                                Reaction              = reaction,
                                FreeText              = rsn.FreeText,
                                IsRXN                 = rsn.IsRXN,
                                Stage                 = null,
                                Id                    = Guid.NewGuid(),
                                SelectedChemical      = rsn.SelectedChemical,
                                ReactionParticipantId = rsn.ReactionParticipantId,
                                DisplayOrder          = rsn.DisplayOrder,
                                IsIgnorableInDelivery = rsn.IsIgnorableInDelivery
                            };
                            tanRsns.Add(newRsn);
                        }
                    }
                }
                foreach (var participant in tanParticipants)
                {
                    vm.AllParticipants.Add(participant);
                    vm.ReactionParticipants.Add(participant);
                }
                vm.Rsns.Clear();
                foreach (var rsn in tanRsns)
                {
                    vm.Rsns.Add(rsn);
                }
                foreach (var reaction in tanReactions)
                {
                    vm.AnalogousReactions.Add(reaction);
                }
            }
            catch (Exception ex)
            {
                AppErrorBox.ShowErrorMessage("Can't Create Analogous Reactions", ex.Message);
            }
            return(vm);
        }
예제 #11
0
        public static bool ValidateRsnEditArea(string FreeText, Regex regex, ReactionVM ReactionVM, StageVM StageVM, out string outMsg)
        {
            bool result = false;
            int  value;
            var  splittedFreetexts = FreeText.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var splittedText in splittedFreetexts)
            {
                if (Regex.IsMatch(splittedText, S.STAGEINFO_RANGE))
                {
                    var itemlist = regex.Match(splittedText).Value.Replace("(stages ", "").Replace(")", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
                    if (itemlist[0] > itemlist[1] || itemlist[0] == itemlist[1] || itemlist[1] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] < 0 || itemlist[0] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] != StageVM.DisplayOrder)
                    {
                        outMsg = "Invalid Stage Range. Please Check Stage range in splittedText";
                        return(result);
                    }
                }
                else if (Regex.IsMatch(splittedText, S.STAGEINFO_AND))
                {
                    var itemlist = regex.Match(splittedText).Value.Replace("(stages ", "").Replace(" and ", "-").Replace(")", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
                    if (itemlist[0] > itemlist[1] || itemlist[0] == itemlist[1] || itemlist[1] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] < 0 || itemlist[0] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] != StageVM.DisplayOrder)
                    {
                        outMsg = "Invalid Stage Range. Please Check Stage range in splittedText";
                        return(result);
                    }
                }

                else if (Regex.IsMatch(splittedText, S.STAGEINFO_MULTIPLE_COMMA))
                {
                    var itemlist = regex.Match(splittedText).Value.Replace("(stages ", "").Replace(",", "-").Replace(")", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
                    if (itemlist[0] > itemlist[itemlist.Count - 1] || itemlist[0] == itemlist[1] || itemlist[itemlist.Count - 1] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] < 0 || itemlist[0] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] != StageVM.DisplayOrder)
                    {
                        outMsg = "Invalid Stage Range. Please Check Stage range in splittedText";
                        return(result);
                    }
                    if (!itemlist.SequenceEqual(itemlist.OrderBy(n => n)))
                    {
                        outMsg = "Stage Information values are must in ascending Order";
                        return(result);
                    }
                    var duplicates = itemlist.GroupBy(s => s).SelectMany(grp => grp.Skip(1));
                    if (duplicates.Count() > 0)
                    {
                        outMsg = "Stage Information values contains Duplicates";
                        return(result);
                    }
                }
                else if (Regex.IsMatch(splittedText, S.STAGEINFO_MULTIPLE_COMMA_AND))
                {
                    var itemlist = regex.Match(splittedText).Value.Replace("(stages ", "").Replace(",", "-").Replace(" and ", "-").Replace(")", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
                    if (itemlist[0] > itemlist[itemlist.Count - 1] || itemlist.Distinct().Count() != itemlist.Count() || itemlist.Max() > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] < 0 || itemlist[0] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] != StageVM.DisplayOrder)
                    {
                        outMsg = "Invalid Stage Range. Please Check Stage range in splittedText";
                        return(result);
                    }
                    if (!itemlist.SequenceEqual(itemlist.OrderBy(n => n)))
                    {
                        outMsg = "Stage Information values are must in ascending Order";
                        return(result);
                    }
                    var duplicates = itemlist.GroupBy(s => s).SelectMany(grp => grp.Skip(1));
                    if (duplicates.Count() > 0)
                    {
                        outMsg = "Stage Information values contains Duplicates";
                        return(result);
                    }
                }
                //else if (Regex.IsMatch(splittedText, S.STAGEINFO_RANGE_AND_RANGE))
                //{
                //    var itemlist = regex.Match(splittedText).Value.Replace("(stages ", string.Empty).Replace(" and ", "-").Replace(")", string.Empty).Split('-').Select(c => Convert.ToInt32(c)).ToList();
                //    if (itemlist[0] > itemlist[1] || itemlist.Distinct().Count() != itemlist.Count() || itemlist.Max() > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] < 0 || itemlist[0] > ReactionVM.Stages.Max(s => s.DisplayOrder) || itemlist[0] != StageVM.DisplayOrder)
                //    {
                //        outMsg = "Invalid Stage Range. Please Check Stage range in splittedText";
                //        return result;
                //    }
                //    if (!itemlist.SequenceEqual(itemlist.OrderBy(n => n)))
                //    {
                //        outMsg = "Stage Information values are must in ascending Order";
                //        return result;
                //    }
                //    var duplicates = itemlist.GroupBy(s => s).SelectMany(grp => grp.Skip(1));
                //    if (duplicates.Count() > 0)
                //    {
                //        outMsg = "Stage Information values contains Duplicates";
                //        return result;
                //    }
                //}

                else if (Regex.IsMatch(splittedText, S.STAGEINFO_SINGLE_STAGE))
                {
                    string s = regex.Match(splittedText).Value.Replace("(stage ", "").Replace(")", "");
                    if (int.TryParse(s, out value) && value == StageVM.DisplayOrder)
                    {
                    }
                    else
                    {
                        outMsg = "Stage Level Information must be selected stage information";
                        return(result);
                    }
                }
            }
            result = true;
            outMsg = string.Empty;
            return(result);
        }
예제 #12
0
        public static bool ValidateAndAddRsn(string FreeText, string CVT, List <RsnVM> Rsns, List <CvtVM> CVTData, ReactionVM ReactionVM, StageVM StageVM, RsnLevel RsnLevel, Regex regex, RSNWindowVM RSNWindowVM, RsnVM EditingRsn = null)
        {
            try
            {
                if (!string.IsNullOrEmpty(FreeText.Trim()) || !string.IsNullOrEmpty(CVT))
                {
                    string freetextREstring = S.RegularExpressions.Where(re => re.RegulerExpressionFor == ProductTracking.Models.Core.RegulerExpressionFor.FreeText).Select(re => re.Expression).FirstOrDefault();
                    Regex  FreetextRE       = new Regex(freetextREstring);
                    var    SPLList          = new List <string> {
                        "==", "%%", ",,", "((", "))", "{{", "}}", "++", "//", "\\", "::", ";;", "--", "..", "  ", "''", "<<", ">>", "**", "@@", "[[", "]]", ", ,", ").", ".,", " ."
                    };
                    if (!string.IsNullOrEmpty(FreeText) && SPLList.Where(spl => FreeText.Contains(spl)).FirstOrDefault() != null)
                    {
                        AppInfoBox.ShowInfoMessage($"Freetext contains invalid repetation of special Characters <SPL Char Start>{SPLList.Where(spl => FreeText.Contains(spl)).FirstOrDefault()}</SPL Char End>.");
                        //MessageBox.Show($"Freetext contains invalid repetation of special Characters {SPLList.Where(spl => FreeText.Contains(spl)).FirstOrDefault()}.", "Reactions", MessageBoxButton.OK, MessageBoxImage.Information);
                        return(false);
                    }
                    if (!string.IsNullOrEmpty(FreeText) && FreeText.Contains("), ") && StageVM != null && RsnLevel == RsnLevel.STAGE)
                    {
                        string[] list = FreeText.Split(new string[] { "), " }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var freetext in list)
                        {
                            string newText = !freetext.EndsWith(")") ? $"{freetext})" : freetext;
                            if (regex.IsMatch(newText))
                            {
                                List <int> data = PressureValidations.GetStageDisplayOrdersFromFreetexts(new List <RsnVM> {
                                    new ViewModels.RsnVM {
                                        Reaction = ReactionVM, Stage = StageVM, FreeText = newText
                                    }
                                }, ReactionVM, FreeTextWithOutStageInfo(newText));
                                if (!data.Contains(StageVM.DisplayOrder) && RsnLevel == RsnLevel.STAGE)
                                {
                                    AppInfoBox.ShowInfoMessage("Comma and space allowed only after stage information");
                                    return(false);
                                }
                            }
                            else
                            {
                                AppInfoBox.ShowInfoMessage($"Invalid freetext '{newText}'");
                                return(false);
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(FreeText) && FreeText.Contains(","))
                    {
                        string[] list = FreeText.Split(',');
                        for (int i = 1; i < list.Length; i++)
                        {
                            if (!Regex.IsMatch(list[i], @"^\s|\d"))
                            {
                                AppInfoBox.ShowInfoMessage("invalid freetext. It contains extra characters");
                                return(false);
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(FreeText) && FreeText.Contains(", ") && FreeText.ToLower().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).GroupBy(s => FreeTextWithOutStageInfo(s)).SelectMany(grp => grp.Skip(1)).Count() > 0)
                    {
                        AppInfoBox.ShowInfoMessage("FreeText Contains duplicates.");
                        return(false);
                    }

                    if (!string.IsNullOrEmpty(FreeText) && FreeText.Contains(", ") && FreeText.ToLower().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Where(s => s.EndsWith(".")).Count() > 0)
                    {
                        AppInfoBox.ShowInfoMessage("FreeText Contains .(Period)");
                        return(false);
                    }

                    if (RsnLevel == RsnLevel.STAGE && StageVM == null)
                    {
                        AppInfoBox.ShowInfoMessage("Please Select Stage to Add Stage RSN");
                        return(false);
                    }

                    if (RsnLevel == RsnLevel.REACTION && !String.IsNullOrEmpty(FreeText) && FreeText.Contains("(stage"))
                    {
                        AppInfoBox.ShowInfoMessage("Reaction Level stage information Not allowed");
                        return(false);
                    }

                    if (!string.IsNullOrEmpty(FreeText) && !FreetextRE.IsMatch(FreeText))
                    {
                        AppInfoBox.ShowInfoMessage("FreeText Contains special characters.");
                        return(false);
                    }
                    if (EditingRsn != null)
                    {
                        bool OnlyOneFreeTextInReactionLevel = (CVT == String.Empty && RsnLevel == RsnLevel.REACTION && Rsns.Any(r => r.Reaction != null && r.Reaction.Id == ReactionVM.Id && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.Stage == null && r.CvtText == String.Empty)) ? false : true;
                        if (OnlyOneFreeTextInReactionLevel)
                        {
                            bool OnlyOneFreeTextInStageLevel = (CVT == String.Empty && RsnLevel == RsnLevel.STAGE && Rsns.Any(r => r.Reaction != null && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.Reaction.Id == ReactionVM.Id && r.Stage != null && r.Stage.Id == StageVM.Id && r.CvtText == String.Empty)) ? false : true;
                            if (OnlyOneFreeTextInStageLevel)
                            {
                                if (!String.IsNullOrEmpty(CVT) && Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.CvtText != string.Empty && r.CvtText == CVT).Count() > 0)
                                {
                                    var SelectedRSNTerm = Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.CvtText == CVT).FirstOrDefault();
                                    AppInfoBox.ShowInfoMessage("Selected CVT " + (!String.IsNullOrEmpty(CVT) ? CVT : FreeText) + " Already used in " + (SelectedRSNTerm?.Stage != null ? SelectedRSNTerm?.Stage.Name : SelectedRSNTerm.Reaction.Name));
                                    return(false);
                                }
                                if (!string.IsNullOrEmpty(FreeText))
                                {
                                    var splittedFreetexts = FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Select(c => FreeTextWithOutStageInfo(c));
                                    foreach (var item in splittedFreetexts)
                                    {
                                        if (CVTData.Where(cvt => item.Trim().SafeEqualsLower(cvt.Text.Trim()) && !cvt.Text.Trim().SafeEqualsLower(CVT.Trim())).Count() > 0)
                                        {
                                            AppInfoBox.ShowInfoMessage($"Selected FreeText contains CVT \"{item}\"");
                                            return(false);
                                        }
                                        if (!string.IsNullOrEmpty(item) && Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && ((!String.IsNullOrEmpty(r.FreeText) && r.FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Where(c => FreeTextWithOutStageInfo(c).Trim().SafeEqualsLower(item.Trim())).Count() > 0) || (!string.IsNullOrEmpty(r.CvtText) && item.Trim().SafeContainsLower(r.CvtText.Trim())))).Count() > 0)
                                        {
                                            var SelectedRSNTerm = Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && ((!String.IsNullOrEmpty(r.FreeText) && r.FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Where(c => FreeTextWithOutStageInfo(c).Trim().SafeEqualsLower(item.Trim())).Count() > 0) || (!string.IsNullOrEmpty(r.CvtText) && item.Trim().SafeContainsLower(r.CvtText.Trim())))).FirstOrDefault();
                                            AppInfoBox.ShowInfoMessage("Selected FreeText " + FreeText + " Already used in " + (SelectedRSNTerm?.Stage != null ? SelectedRSNTerm?.Stage.Name : SelectedRSNTerm.Reaction.Name));
                                            return(false);
                                        }
                                    }
                                }

                                if (RsnLevel == RsnLevel.STAGE)
                                {
                                    if (!string.IsNullOrEmpty(CVT) && string.IsNullOrEmpty(FreeText))
                                    {
                                        AppInfoBox.ShowInfoMessage("Stage Level CVT Used, Then Freetext is mandatory..");
                                        return(false);
                                    }
                                    else if (!string.IsNullOrEmpty(FreeText) && regex.IsMatch(FreeText))
                                    {
                                        string outMsg = string.Empty;
                                        if (!ValidateRsnEditArea(FreeText, regex, ReactionVM, StageVM, out outMsg))
                                        {
                                            AppInfoBox.ShowInfoMessage(outMsg);
                                            return(false);
                                        }
                                        return(true);
                                    }
                                    else
                                    {
                                        AppInfoBox.ShowInfoMessage("Stage Level Information missed in Freetext Term... / Ends with some Special characters");
                                        return(false);
                                    }
                                }
                                return(true);
                            }
                            else
                            {
                                AppInfoBox.ShowInfoMessage("Only One Stage Level Free Text Is Allowed With out CVT . .");
                                return(false);
                            }
                        }
                        else
                        {
                            AppInfoBox.ShowInfoMessage("Only One Reaction Level Free Text Is Allowed With out CVT . .");
                            return(false);
                        }
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(CVT) || !String.IsNullOrEmpty(FreeText))
                        {
                            bool OnlyOneFreeTextInReactionLevel = (CVT == String.Empty && RsnLevel == RsnLevel.REACTION && Rsns.Any(r => r.Reaction != null && r.Reaction.Id == ReactionVM.Id && r.Stage == null && string.IsNullOrEmpty(r.CvtText))) ? false : true;
                            if (OnlyOneFreeTextInReactionLevel)
                            {
                                bool OnlyOneFreeTextInStageLevel = (CVT == String.Empty && RsnLevel == RsnLevel.STAGE && Rsns.Any(r => r.Reaction != null && r.Reaction.Id == ReactionVM.Id && r.Stage != null && r.Stage.Id == StageVM.Id && string.IsNullOrEmpty(r.CvtText))) ? false : true;
                                if (OnlyOneFreeTextInStageLevel)
                                {
                                    if (!String.IsNullOrEmpty(CVT) && Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && r.CvtText.SafeEqualsLower(CVT)).Count() > 0)
                                    {
                                        var SelectedRSNTerm = Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && r.CvtText.SafeEqualsLower(CVT)).FirstOrDefault();
                                        AppInfoBox.ShowInfoMessage("Selected CVT " + (!String.IsNullOrEmpty(CVT) ? CVT : FreeText) + " Already used in " + (SelectedRSNTerm?.Stage != null ? SelectedRSNTerm?.Stage.Name : SelectedRSNTerm.Reaction.Name));
                                        return(false);
                                    }

                                    if (!string.IsNullOrEmpty(FreeText))
                                    {
                                        var splittedFreetexts = FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Select(c => FreeTextWithOutStageInfo(c));
                                        foreach (var item in splittedFreetexts)
                                        {
                                            if (CVTData.Where(cvt => item.Trim().SafeEqualsLower(cvt.Text.Trim()) && !cvt.Text.Trim().SafeEqualsLower(CVT.Trim())).Count() > 0)
                                            {
                                                AppInfoBox.ShowInfoMessage($"Selected FreeText contains CVT \"{item}\"");
                                                return(false);
                                            }
                                            if (!string.IsNullOrEmpty(item) && Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && ((!String.IsNullOrEmpty(r.FreeText) && r.FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Where(c => FreeTextWithOutStageInfo(c).Trim().SafeEqualsLower(item.Trim())).Count() > 0) || (!string.IsNullOrEmpty(r.CvtText) && item.Trim().SafeContainsLower(r.CvtText.Trim())))).Count() > 0)
                                            {
                                                var SelectedRSNTerm = Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && ((!String.IsNullOrEmpty(r.FreeText) && r.FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Where(c => FreeTextWithOutStageInfo(c).Trim().SafeEqualsLower(item.Trim())).Count() > 0) || (!string.IsNullOrEmpty(r.CvtText) && item.Trim().SafeContainsLower(r.CvtText.Trim())))).FirstOrDefault();
                                                AppInfoBox.ShowInfoMessage($"Selected FreeText '{FreeText}' Already used in {(SelectedRSNTerm?.Stage != null ? SelectedRSNTerm?.Stage.Name : SelectedRSNTerm.Reaction.Name)}");
                                                return(false);
                                            }
                                        }
                                    }
                                    if (RsnLevel == RsnLevel.STAGE)
                                    {
                                        if (!string.IsNullOrEmpty(CVT) && string.IsNullOrEmpty(FreeText))
                                        {
                                            AppInfoBox.ShowInfoMessage("Stage Level CVT Used, Then Freetext is mandatory..");
                                            return(false);
                                        }
                                        else if (!string.IsNullOrEmpty(FreeText) && regex.IsMatch(FreeText))
                                        {
                                            string OutMsg = string.Empty;
                                            if (!ValidateRsnEditArea(FreeText, regex, ReactionVM, StageVM, out OutMsg))
                                            {
                                                AppErrorBox.ShowErrorMessage(OutMsg, String.Empty);
                                                return(false);
                                            }
                                            return(true);
                                        }
                                        else
                                        {
                                            AppInfoBox.ShowInfoMessage("Stage Level Information missed in Freetext Term...");
                                            return(false);
                                        }
                                    }
                                    return(true);
                                }
                                else
                                {
                                    AppInfoBox.ShowInfoMessage("Only One Stage Level Free Text Is Allowed With out CVT . .");
                                    return(false);
                                }
                            }
                            else
                            {
                                AppInfoBox.ShowInfoMessage("Only One Reaction Level Free Text Is Allowed With out CVT . .");
                                return(false);
                            }
                        }
                        return(false);
                    }
                    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) ? StageInfoWithOutFreeText(enzymicRSN.FreeText, regex) : string.Empty;
                        Rsns.Add(new RsnVM
                        {
                            CvtText     = S.BIOTRANSFORMATION_CVT,
                            FreeText    = $"{S.BIOTRANSFORMATION_FREETEXT} {freeTextToAdd}",
                            IsRXN       = true,
                            Stage       = enzymicRSN.Stage != null ? enzymicRSN.Stage : null,
                            Reaction    = ReactionVM,
                            RSNWindowVM = RSNWindowVM,
                            Id          = Guid.NewGuid()
                        });
                    }
                    //ClearEditForm.Execute(this);
                }
                else
                {
                    AppInfoBox.ShowInfoMessage("Either CVT or FreeText mandatory to save RSN");
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log.This(ex);
                AppErrorBox.ShowErrorMessage(ex.Message, ex.ToString());
                return(false);
            }
        }
예제 #13
0
        public static ReactionViewVM GetReactionView(ReactionVM reaction, List <ReactionParticipantVM> ReactionParticipants)
        {
            try
            {
                ReactionViewVM reactionView = new ReactionViewVM();
                if (reaction != null && ReactionParticipants != null && ReactionParticipants.Count > 0)
                {
                    reactionView.Name = reaction.Name;
                    reactionView.IsReviewCompleted = reaction.IsReviewCompleted;
                    reactionView.ReviewEnable      = U.RoleId == 2 ? true : false;
                    reactionView.ReactionId        = reaction.Id;

                    #region Reactants
                    var reactants = ReactionParticipants.Where(rp => rp.ReactionVM == reaction &&
                                                               rp.ParticipantType == ParticipantType.Reactant).ToList();
                    foreach (var reactant in reactants)
                    {
                        var view = GetParticipantView(reactant);
                        view.NextImagePath = PLUS_ICON;
                        reactionView.ReactantsViews.Add(view);
                    }
                    var lastReactant = reactionView.ReactantsViews.LastOrDefault();
                    if (lastReactant != null)
                    {
                        lastReactant.NextImagePath = ARROW_ICON;
                    }
                    #endregion

                    foreach (var view in reactionView.ReactantsViews)
                    {
                        reactionView.EquationViews.Add(view);
                    }

                    #region Products
                    var products = ReactionParticipants.Where(rp => rp.ReactionVM == reaction &&
                                                              rp.ParticipantType == ParticipantType.Product).ToList();
                    foreach (var product in products)
                    {
                        var view = GetParticipantView(product);
                        view.NextImagePath = PLUS_ICON;
                        reactionView.ProductViews.Add(view);
                    }
                    var lastProduct = reactionView.ProductViews.LastOrDefault();
                    if (lastProduct != null)
                    {
                        lastProduct.NextImagePath = null;
                    }
                    #endregion
                    foreach (var view in reactionView.ProductViews)
                    {
                        reactionView.EquationViews.Add(view);
                    }

                    foreach (var stage in reaction.Stages)
                    {
                        var stageView = new StageViewVM()
                        {
                            StageVM = stage
                        };

                        var agentViews = (from rp in ReactionParticipants
                                          where rp.ReactionVM == reaction && rp.StageVM != null && rp.StageVM.Id == stage.Id && rp.ParticipantType == ParticipantType.Agent
                                          select GetParticipantView(rp));
                        foreach (var agentView in agentViews)
                        {
                            stageView.AgentsViews.Add(agentView);
                        }
                        stageView.ShowAgents = stageView.AgentsViews.Any() ? Visibility.Visible : Visibility.Collapsed;

                        var reactantViews = (from rp in ReactionParticipants
                                             where rp.ReactionVM == reaction && rp.StageVM != null && rp.StageVM.Id == stage.Id && rp.ParticipantType == ParticipantType.Reactant
                                             select GetParticipantView(rp));
                        foreach (var reactantView in reactantViews)
                        {
                            stageView.ReactantsViews.Add(reactantView);
                        }
                        stageView.ShowReactants = stageView.ReactantsViews.Any() ? Visibility.Visible : Visibility.Collapsed;

                        var solventViews = (from rp in ReactionParticipants
                                            where rp.ReactionVM == reaction && rp.StageVM != null && rp.StageVM.Id == stage.Id && rp.ParticipantType == ParticipantType.Solvent
                                            select GetParticipantView(rp));
                        foreach (var solventView in solventViews)
                        {
                            stageView.SolventsViews.Add(solventView);
                        }
                        stageView.ShowSolvents = stageView.SolventsViews.Any() ? Visibility.Visible : Visibility.Collapsed;

                        var catalystViews = (from rp in ReactionParticipants
                                             where rp.ReactionVM == reaction && rp.StageVM != null && rp.StageVM.Id == stage.Id && rp.ParticipantType == ParticipantType.Catalyst
                                             select GetParticipantView(rp));
                        foreach (var catalystView in catalystViews)
                        {
                            stageView.CatalystsViews.Add(catalystView);
                        }
                        stageView.ShowCatalysts = stageView.CatalystsViews.Any() ? Visibility.Visible : Visibility.Collapsed;

                        stageView.Temperature          = (stage.Conditions != null && stage.Conditions.Select(temp => temp.Temperature).Any()) ? string.Join(",", stage.Conditions.Select(temp => temp.Temperature).ToList()) : string.Empty;
                        stageView.Time                 = (stage.Conditions != null && stage.Conditions.Select(temp => temp.Time).Any()) ? string.Join(",", stage.Conditions.Select(temp => temp.Time).ToList()) : string.Empty;
                        stageView.Pressure             = (stage.Conditions != null && stage.Conditions.Select(pres => pres.Pressure).Any()) ? string.Join(",", stage.Conditions.Select(pres => pres.Pressure).ToList()) : string.Empty;
                        stageView.Ph                   = (stage.Conditions != null && stage.Conditions.Select(ph => ph.PH).Any()) ? string.Join(",", stage.Conditions.Select(ph => ph.PH).ToList()) : string.Empty;
                        stageView.ConditionsVisibility = stageView.GetConditionsVisibility();
                        //stageView.Temperature = string.Join(",", stage.Conditions.Where(temp => !string.IsNullOrEmpty(temp.Temperature)).Select(temp => temp.Temperature).ToList());
                        //stageView.Time = string.Join(",", stage.Conditions.Where(temp => !string.IsNullOrEmpty(temp.Time)).Select(temp => temp.Time).ToList());
                        //stageView.Pressure = string.Join(",", stage.Conditions.Where(pres => !string.IsNullOrEmpty(pres.Pressure)).Select(pres => pres.Pressure).ToList());
                        //stageView.Ph = string.Join(",", stage.Conditions.Where(ph => !string.IsNullOrEmpty(ph.PH)).Select(ph => ph.PH).ToList());

                        var rsns = reaction.TanVM.Rsns.Where(rsn => rsn.Stage != null && rsn.Stage.Id == stage.Id).ToList();
                        if (stage.DisplayOrder == 1)
                        {
                            rsns.InsertRange(0, reaction.TanVM.Rsns.Where(rsn => rsn.Reaction.Id == reaction.Id && rsn.Stage == null).ToList());
                        }
                        stageView.FreeText = rsns.Select(rsn => rsn.FreeTextWithRxn).Count() > 0 ? string.Join(",", rsns.Where(rsn => !string.IsNullOrEmpty(rsn.FreeTextWithRxn)).Select(rsn => rsn.FreeTextWithRxn)) : string.Empty;
                        stageView.CVT      = string.Join(",", rsns.Select(rsn => rsn.Stage == null ? !string.IsNullOrEmpty(rsn.CvtText) ? $"{rsn.CvtText} (Reaction)" : string.Empty : rsn.CvtText).Where(s => !string.IsNullOrEmpty(s)));

                        reactionView.Stages.Add(stageView);
                    }
                    reactionView.YieldProducts = new ObservableCollection <string>(products.Select(p => (p.Num + ((!string.IsNullOrEmpty(p.Yield) && p.Yield != "0") ? " (" + p.Yield + ")" : string.Empty))));
                }
                return(reactionView);
            }
            catch (Exception ex)
            {
                Log.This(ex);
                throw;
            }
        }
예제 #14
0
 public static List <int> GetStageDisplayOrdersFromFreetexts(List <RsnVM> Rsns, ReactionVM SelectedReaction, string SearchString, List <string> excludestrings = null, bool AllowEmpty = false, bool IncludeCVTVerification = false, string cvtTerm = "")
 {
     try
     {
         List <int> StageNumbers          = new List <int>();
         var        freetextDisplayOrders = Rsns.Where(f => f.Reaction.Id == SelectedReaction.Id &&
                                                       f.FreeText.Split(new String[] { "), " }, StringSplitOptions.RemoveEmptyEntries).Where(s => s.IncludeExclude(SearchString, excludestrings, AllowEmpty)).Any() &&
                                                       (f.FreeText.Split(new String[] { "), " }, StringSplitOptions.RemoveEmptyEntries).Where(s => s.IncludeExclude(SearchString, excludestrings, AllowEmpty)).First().TrimEnd(')') + ")").Contains("(stage"))
                                            .Select(f => RV.GetStageInfoWithOutFreeText(f.FreeText.Split(new String[] { "), " }, StringSplitOptions.RemoveEmptyEntries).Where(s => s.IncludeExclude(SearchString, excludestrings, AllowEmpty)).First().TrimEnd(')') + ")"))
                                            .ToList();
         foreach (var item in freetextDisplayOrders)
         {
             string outMsg = string.Empty;
             RV.GetStageNumbersFromFreeText(item, ref StageNumbers, ref outMsg);
             #region Commented RSNFreetexts
             //if (Regex.IsMatch(item, S.STAGEINFO_RANGE))
             //{
             //    var itemlist = Regex.Replace(item, @"[a-z\(\)\s]", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
             //    if (itemlist.Count > 1)
             //        for (int r = itemlist[0]; r <= itemlist[1]; r++)
             //            StageNumbers.Add(r);
             //}
             //else if (Regex.IsMatch(item, S.STAGEINFO_AND))
             //{
             //    var itemlist = item.Replace("(stages ", "").Replace(" and ", "-").Replace(")", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
             //    StageNumbers.AddRange(itemlist);
             //}
             //else if (Regex.IsMatch(item, S.STAGEINFO_SINGLE_STAGE))
             //    StageNumbers.Add(Convert.ToInt32(item.Replace("(stage ", "").Replace(")", "")));
             //else if (Regex.IsMatch(item, S.STAGEINFO_MULTIPLE_COMMA))
             //{
             //    var itemlist = item.Replace("(stages ", "").Replace(",", "-").Replace(")", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
             //    StageNumbers.AddRange(itemlist);
             //}
             //else if (Regex.IsMatch(item, S.STAGEINFO_MULTIPLE_COMMA_AND))
             //{
             //    var itemlist = item.Replace("(stages ", "").Replace(",", "-").Replace(" and ", "-").Replace(")", "").Split('-').Select(c => Convert.ToInt32(c)).ToList();
             //    StageNumbers.AddRange(itemlist);
             //}
             //else if (Regex.IsMatch(item, S.STAGEINFO_RANGE_AND_RANGE))
             //{
             //    var itemlist = item.Replace("(stages ", "").Replace(")", "").Split(new string[] { " and " }, StringSplitOptions.RemoveEmptyEntries).ToList();
             //    foreach (string range in itemlist)
             //    {
             //        var splittedList = range.Split('-').Select(c => Convert.ToInt32(c)).ToList();
             //        if (splittedList.Count > 1)
             //            for (int r = splittedList[0]; r <= splittedList[1]; r++)
             //                StageNumbers.Add(r);
             //    }
             //}
             //else if (Regex.IsMatch(item, S.STAGEINFO_RANGE_COMMA_AND))
             //{
             //    var itemlist = item.Replace("(stages ", "").Replace(")", "").Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();
             //    var splittedListWithRange = itemlist[0].Split('-').Select(c => Convert.ToInt32(c)).ToList();
             //    if (splittedListWithRange.Count > 1)
             //        for (int r = splittedListWithRange[0]; r <= splittedListWithRange[1]; r++)
             //            StageNumbers.Add(r);
             //    var splittedList = itemlist[1].Replace(" and ", "-").Split('-').Select(c => Convert.ToInt32(c)).ToList();
             //    StageNumbers.AddRange(splittedList);
             //}
             #endregion
         }
         return(StageNumbers.OrderBy(c => c).Distinct().ToList());
     }
     catch (Exception ex)
     {
         Log.This(ex);
         throw;
     }
 }
예제 #15
0
        public static List <ValidationError> HighAndLowPresssureValidations(List <StageConditionVM> StagePressureConditions, bool highPressure, ReactionVM reaction, StageVM stage, List <int> stageHighPressureDisplayOrders, List <RsnVM> ReactionLevelRsns = null)
        {
            var  errors    = new List <ValidationError>();
            bool unUsedCVT = false;

            if (StagePressureConditions.Any())
            {
                foreach (var pres in StagePressureConditions)
                {
                    string           pressureUnit = string.Empty;
                    ExtentionMethods common = new Common.ExtentionMethods();
                    var    normalvalue = common.GetPressureAndUnitsFromString(pres.Pressure, out pressureUnit);
                    float  i = 0, j = 0, k = 0;
                    string value = Regex.Replace(pres.Pressure, "[^0-9.\\-\\]]", "");


                    if (value.Contains("-") || value.Contains("]"))
                    {
                        string[] splitterRange = { "-", "]" };
                        string[] strValsRange  = pres.Pressure.Split(splitterRange, StringSplitOptions.RemoveEmptyEntries);
                        if (pres.Pressure.Contains($"-{strValsRange[0]}"))
                        {
                            strValsRange[0] = $"-{strValsRange[0]}";
                        }
                        if (strValsRange.Count() > 1 && (pres.Pressure.Contains($"--{strValsRange[1]}") || pres.Pressure.Contains($"]-{strValsRange[1]}")))
                        {
                            strValsRange[1] = $"-{strValsRange[1]}";
                        }
                        if (strValsRange.Count() > 1)
                        {
                            if (float.TryParse(common.GetPressureAndUnitsFromString(strValsRange[0], out pressureUnit), out j) && float.TryParse(common.GetPressureAndUnitsFromString(strValsRange[1], out pressureUnit), out k))
                            {
                                value = highPressure ? Math.Max(j, k).ToString() : Math.Min(j, k).ToString();
                            }
                        }
                        else
                        {
                            value = normalvalue;
                        }
                    }

                    if (float.TryParse(value, out i) && pressureUnit == "kp" && (highPressure ? i >= S.KP_HIGHVALUE : i < S.K_LOWVALUE) &&
                        (!stageHighPressureDisplayOrders.Contains(stage.DisplayOrder) && (ReactionLevelRsns == null || !ReactionLevelRsns.Any())))
                    {
                        errors.Add(VF.OfRSN(reaction, $"If pressure { (highPressure ? S.EXCEEDS_KP_HIGH : S.BELOW_KP_VALUE)} kPa then Free text must contains {(highPressure ? "'High Pressure'" : "'Low Pressure'")}", stage));
                    }
                    else if (float.TryParse(value, out i) && pressureUnit == "s" && (highPressure ? i >= S.S_HIGHVALUE : i < S.S_LOWVALUE) &&
                             !stageHighPressureDisplayOrders.Contains(stage.DisplayOrder) && (ReactionLevelRsns == null || !ReactionLevelRsns.Any()))
                    {
                        errors.Add(VF.OfRSN(reaction, $"If pressure { (highPressure ? S.EXCEEDS_S_HIGH : S.BELOW_S_VALUE)} Psi then Free text must contains {(highPressure ? "'High Pressure'" : "'Low Pressure'")}", stage));
                    }
                    else if (float.TryParse(value, out i) && (highPressure ? i >= S.A_B_HIGHVALUE : i < S.A_B_LOWVALUE) && (pressureUnit == "a" || pressureUnit == "b") &&
                             !stageHighPressureDisplayOrders.Contains(stage.DisplayOrder) && (ReactionLevelRsns == null || !ReactionLevelRsns.Any()))
                    {
                        errors.Add(VF.OfRSN(reaction, $"If pressure { (highPressure ? S.EXCEEDS_A_B_HIGH : S.BELOW_A_B_VALUE)} atm/Bars then Free text must contains {(highPressure ? "'High Pressure'" : "'Low Pressure'")}", stage));
                    }
                    if (stageHighPressureDisplayOrders.Contains(stage.DisplayOrder) || (ReactionLevelRsns != null && ReactionLevelRsns.Any()))
                    {
                        if (float.TryParse(value, out i) && ((pressureUnit == "kp" && (highPressure ? i < S.KP_HIGHVALUE : i >= S.K_LOWVALUE)) || (pressureUnit == "s" && (highPressure ? i < S.S_HIGHVALUE : i >= S.S_LOWVALUE) || ((highPressure ? i < S.A_B_HIGHVALUE : i >= S.A_B_LOWVALUE) && (pressureUnit == "a" || pressureUnit == "b")))) && !unUsedCVT)
                        {
                            unUsedCVT = false;
                        }
                        else
                        {
                            unUsedCVT = true;
                        }
                    }
                }
            }
            if ((stageHighPressureDisplayOrders.Contains(stage.DisplayOrder) || (ReactionLevelRsns != null && ReactionLevelRsns.Any())) && !unUsedCVT)
            {
                errors.Add(VF.OfRSN(reaction, $"RSN Contains { (highPressure ? "High" : "Low")} pressure in CVT/Freetext. {(highPressure ? "'High Pressure'" : "'Low Pressure'")} is Allowed only when certain Pressure exists.", stage));
            }
            return(errors);
        }
예제 #16
0
 public static List <ReactionParticipantVM> ParticipantOfNUMOrReg(this List <ReactionParticipantVM> participants, TanChemical tanChemical, ReactionVM reaction)
 {
     if (participants == null)
     {
         return(null);
     }
     return(participants.Where(p =>
                               (p.Num == tanChemical.NUM || p.Reg == tanChemical.RegNumber) &&
                               p.ReactionVM.Id == reaction.Id &&
                               p.StageVM != null &&
                               reaction.SelectedStage != null &&
                               p.StageVM.Id == reaction.SelectedStage.Id
                               ).ToList());
 }