public void show(TanVM tanVM) { var RSNWindowVM = this.DataContext as RSNWindowVM; if (RSNWindowVM != null && tanVM != null && tanVM.SelectedReaction != null) { RSNWindowVM.RSNTitle = $"{S.RSNTitle} - {tanVM.SelectedReaction.DisplayName}"; ((App.Current.MainWindow as MainWindow).DataContext as MainVM).IsRsnWindowOpened = true; this.Height = 650; this.Width = 780; this.Show(); this.Focus(); } }
public void PrepareData(TanVM tanVM) { var rsns = tanVM.Rsns.Where(rsn => !string.IsNullOrEmpty(rsn.FreeText)); this.TanFreetexts = new ObservableCollection <FreetextPropertiesVM>(); foreach (RsnVM rsnVM in rsns) { { var reaction = new FreetextPropertiesVM(); reaction.RsnId = rsnVM.Id; reaction.RXNName = rsnVM.Reaction.KeyProductSeq; reaction.StageName = rsnVM.Stage != null ? rsnVM.Stage.Name : string.Empty; reaction.FreeText = rsnVM.FreeText; reaction.Selected = false; this.TanFreetexts.Add(reaction); } } this.TanFreetexts.UpdateDisplayOrder(); this.TanFreeTextsView = new ListCollectionView(this.TanFreetexts); }
public static TanVM GetTanVMFromTan(Tan MasterTan, Tan serializedTan) { var tanComments = new ObservableCollection <ViewModels.Core.Comments>(); foreach (var comment in serializedTan.TanComments) { var com = new ViewModels.Core.Comments { Comment = comment.Comment, TotalComment = comment.TotalComment, CommentType = comment.CommentType, Id = comment.Id, Column = comment.Column, Figure = comment.Figure, FootNote = comment.FootNote, Line = comment.Line, Num = comment.Num, Page = comment.Page, Para = comment.Para, Schemes = comment.Schemes, Sheet = comment.Sheet, Table = comment.Table }; tanComments.Add(com); } var tanVM = new TanVM { Id = MasterTan.Id, TanNumber = MasterTan.tanNumber, BatchNumber = MasterTan.Batch.Name, DocumentPath = MasterTan.DocumentPath, TanComments = new TanCommentsVM(tanComments), IsQCCompleted = serializedTan.IsQCCompleted }; return(tanVM); }
private void Stages_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { try { if (enableUpdate) { Stages.UpdateDisplayOrder(); //if (U.RoleId == 1) // LastupdatedDate = DateTime.Now; //else if (U.RoleId == 2) // ReviewLastupdatedDate = DateTime.Now; //else if (U.RoleId == 3) // QCLastupdatedDate = DateTime.Now; TanVM.UpdateParticipantsView(); TanVM.UpdateReactionPreview(); if (TanVM.ReactionParticipants != null && TanVM.SelectedReaction != null) { string RSDString = Common.ReactionValidations.GetRSDString(TanVM.ReactionParticipants.Where(rp => rp.ReactionVM.Id == TanVM.SelectedReaction.Id).ToList(), TanVM.SelectedReaction); TanVM.Rsd = RSDString; if (U.RoleId == 1) { TanVM.SelectedReaction.IsCurationCompleted = false; } else if (U.RoleId == 2) { TanVM.SelectedReaction.IsReviewCompleted = false; } ((App.Current.MainWindow as MainWindow).DataContext as MainVM).Validate(true); } } } catch (Exception ex) { Log.This(ex); } }
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; }
public void PrepareData(TanVM tanVM) { var GroupedParticipants = tanVM.ReactionParticipants.GroupBy(rp => rp.ReactionVM.Id).ToDictionary(k => k.Key, k => k.ToList()); var GroupedRsns = tanVM.Rsns.GroupBy(rp => rp.Reaction.Id).ToDictionary(k => k.Key, k => k.ToList()); this.CuratedTanData = new ObservableCollection <CuratedTanVM>(); this.Temp = 0; this.Time = 0; this.Pressure = 0; this.PH = 0; foreach (ReactionVM reactionVM in tanVM.Reactions) { var FirstStage = reactionVM.Stages.OrderBy(s => s.DisplayOrder).FirstOrDefault(); if (FirstStage != null) { var reaction = new CuratedTanVM(); reaction.Id = reactionVM.DisplayOrder; reaction.Sno = reactionVM.DisplayOrder.ToString(); reaction.RxnNumWithSequence = reactionVM.KeyProductSeq; reaction.Products = GroupedParticipants.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedParticipants[reactionVM.Id].Where(rp => rp.ParticipantType == DTO.ParticipantType.Product).Select(rp => $"{rp.Num} {(!String.IsNullOrEmpty(rp.Yield) ? "(" + rp.Yield + ")" : string.Empty )}")) : string.Empty; reaction.Reactants = GroupedParticipants.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedParticipants[reactionVM.Id].Where(rp => rp.ParticipantType == DTO.ParticipantType.Reactant && rp.StageVM != null && rp.StageVM.Id == FirstStage.Id).Select(rp => $"{rp.Num}")) : string.Empty; reaction.Agents = GroupedParticipants.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedParticipants[reactionVM.Id].Where(rp => rp.ParticipantType == DTO.ParticipantType.Agent && rp.StageVM != null && rp.StageVM.Id == FirstStage.Id).Select(rp => $"{rp.Num}")) : string.Empty; reaction.Catalysts = GroupedParticipants.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedParticipants[reactionVM.Id].Where(rp => rp.ParticipantType == DTO.ParticipantType.Catalyst && rp.StageVM != null && rp.StageVM.Id == FirstStage.Id).Select(rp => $"{rp.Num}")) : string.Empty; reaction.Solvents = GroupedParticipants.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedParticipants[reactionVM.Id].Where(rp => rp.ParticipantType == DTO.ParticipantType.Solvent && rp.StageVM != null && rp.StageVM.Id == FirstStage.Id).Select(rp => $"{rp.Num}")) : string.Empty; reaction.Time = string.Join(",", FirstStage.Conditions.Where(c => !string.IsNullOrEmpty(c.Time)).Select(c => c.Time).ToList()); this.Time = !string.IsNullOrEmpty(reaction.Time) ? this.time + reaction.Time.Split(',').Count() : this.Time; reaction.Temperature = string.Join(",", FirstStage.Conditions.Where(c => !string.IsNullOrEmpty(c.Temperature)).Select(c => c.Temperature).ToList()); this.Temp = !string.IsNullOrEmpty(reaction.Temperature) ? this.Temp + reaction.Temperature.Split(',').Count() : this.Temp; reaction.Pressure = string.Join(",", FirstStage.Conditions.Where(c => !string.IsNullOrEmpty(c.Pressure)).Select(c => c.Pressure).ToList()); this.Pressure = !string.IsNullOrEmpty(reaction.Pressure) ? this.Pressure + reaction.Pressure.Split(',').Count() : this.Pressure; reaction.PH = string.Join(",", FirstStage.Conditions.Where(c => !string.IsNullOrEmpty(c.PH)).Select(c => c.PH).ToList()); this.PH = !string.IsNullOrEmpty(reaction.PH) ? this.PH + reaction.PH.Split(',').Count() : this.PH; reaction.Cvt = GroupedRsns.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedRsns[reactionVM.Id].Where(rsn => (rsn.Stage == null || rsn.Stage.Id == FirstStage.Id) && !string.IsNullOrEmpty(rsn.CvtText)).Select(cvt => cvt.CvtText)) : string.Empty; reaction.Freetext = GroupedRsns.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedRsns[reactionVM.Id].Where(rsn => (rsn.Stage == null || rsn.Stage.Id == FirstStage.Id) && !string.IsNullOrEmpty(rsn.FreeText)).Select(cvt => cvt.FreeText)) : string.Empty; this.CuratedTanData.Add(reaction); foreach (StageVM stage in reactionVM.Stages) { if (stage.Id != FirstStage.Id) { var stagereaction = new CuratedTanVM(); stagereaction.Id = reactionVM.DisplayOrder; stagereaction.Reactants = GroupedParticipants.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedParticipants[reactionVM.Id].Where(rp => rp.ParticipantType == DTO.ParticipantType.Reactant && rp.StageVM != null && rp.StageVM.Id == stage.Id).Select(rp => $"{rp.Num}")) : string.Empty; stagereaction.Agents = GroupedParticipants.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedParticipants[reactionVM.Id].Where(rp => rp.ParticipantType == DTO.ParticipantType.Agent && rp.StageVM != null && rp.StageVM.Id == stage.Id).Select(rp => $"{rp.Num}")) : string.Empty; stagereaction.Catalysts = GroupedParticipants.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedParticipants[reactionVM.Id].Where(rp => rp.ParticipantType == DTO.ParticipantType.Catalyst && rp.StageVM != null && rp.StageVM.Id == stage.Id).Select(rp => $"{rp.Num}")) : string.Empty; stagereaction.Solvents = GroupedParticipants.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedParticipants[reactionVM.Id].Where(rp => rp.ParticipantType == DTO.ParticipantType.Solvent && rp.StageVM != null && rp.StageVM.Id == stage.Id).Select(rp => $"{rp.Num}")) : string.Empty; stagereaction.Time = string.Join(",", stage.Conditions.Where(c => !string.IsNullOrEmpty(c.Time)).Select(c => c.Time).ToList()); stagereaction.Temperature = string.Join(",", stage.Conditions.Where(c => !string.IsNullOrEmpty(c.Temperature)).Select(c => c.Temperature).ToList()); stagereaction.Pressure = string.Join(",", stage.Conditions.Where(c => !string.IsNullOrEmpty(c.Pressure)).Select(c => c.Pressure).ToList()); stagereaction.PH = string.Join(",", stage.Conditions.Where(c => !string.IsNullOrEmpty(c.PH)).Select(c => c.PH).ToList()); this.Time = !string.IsNullOrEmpty(stagereaction.Time) ? this.time + stagereaction.Time.Split(',').Count() : this.Time; this.Temp = !string.IsNullOrEmpty(stagereaction.Temperature) ? this.Temp + stagereaction.Temperature.Split(',').Count() : this.Temp; this.Pressure = !string.IsNullOrEmpty(stagereaction.Pressure) ? this.Pressure + stagereaction.Pressure.Split(',').Count() : this.Pressure; this.PH = !string.IsNullOrEmpty(stagereaction.PH) ? this.PH + stagereaction.PH.Split(',').Count() : this.PH; stagereaction.Cvt = GroupedRsns.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedRsns[reactionVM.Id].Where(rsn => rsn.Stage != null && rsn.Stage.Id == stage.Id && !string.IsNullOrEmpty(rsn.CvtText)).Select(cvt => cvt.CvtText)) : string.Empty; stagereaction.Freetext = GroupedRsns.ContainsKey(reactionVM.Id) ? string.Join(",", GroupedRsns[reactionVM.Id].Where(rsn => rsn.Stage != null && rsn.Stage.Id == stage.Id && !string.IsNullOrEmpty(rsn.FreeText)).Select(cvt => cvt.FreeText)) : string.Empty; this.CuratedTanData.Add(stagereaction); } } } } this.TotalReactions = tanVM.Reactions.Count(); this.TotalParticipants = tanVM.ReactionParticipants.Count(); this.TotalStages = tanVM.Reactions.Select(r => r.Stages.Count()).Sum(); this.Products = tanVM.ReactionParticipants.Where(rp => rp.ParticipantType == DTO.ParticipantType.Product).Count(); this.Distinct8000Count = tanVM.TanChemicals.Where(tc => tc.ChemicalType == DTO.ChemicalType.S8000).Count(); this.Reactants = tanVM.ReactionParticipants.Where(rp => rp.ParticipantType == DTO.ParticipantType.Reactant).Count(); this.ReactionsWith8000 = GroupedParticipants.Where(D => D.Value.Where(C => C.ChemicalType == DTO.ChemicalType.S8000).Any()).Count(); this.Catalyst = tanVM.ReactionParticipants.Where(rp => rp.ParticipantType == DTO.ParticipantType.Catalyst).Count(); this.Solvent = tanVM.ReactionParticipants.Where(rp => rp.ParticipantType == DTO.ParticipantType.Solvent).Count(); this.Agent = tanVM.ReactionParticipants.Where(rp => rp.ParticipantType == DTO.ParticipantType.Agent).Count(); }