예제 #1
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);
        }
예제 #2
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);
            }
        }
예제 #3
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;
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
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);
            }
        }
예제 #8
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);
        }
예제 #9
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);
        }