Exemplo n.º 1
0
 private void PopupVM_StageSelectedEvent(object sender, StageVM e)
 {
     if (e != null)
     {
         if (e.DisplayOrder > 1)
         {
             IsProductEnable = false;
             ParticipantType = ParticipantType == ParticipantType.Product ? ParticipantType.Reactant : ParticipantType;
         }
         else
         {
             IsProductEnable = true;
             ParticipantType = ParticipantType.Product;
         }
     }
 }
Exemplo n.º 2
0
 public static ValidationError OfRSN(ReactionVM reaction, string message, StageVM stageVM = null)
 {
     return(new ValidationError {
         ReactionVM = reaction, StageVM = stageVM, Message = message, Category = ValidationError.RSN
     });
 }
Exemplo n.º 3
0
 public static ValidationError OfStage(ReactionVM reaction, string message, StageVM stageVM)
 {
     return(new ValidationError {
         ReactionVM = reaction, StageVM = stageVM, Message = message, Category = ValidationError.STAGE
     });
 }
Exemplo n.º 4
0
        private void CopySelectedStages(object obj)
        {
            if (SelectedStages.Count > 0)
            {
                var mainViewModel = ((MainWindow)(App.Current.MainWindow)).DataContext as MainVM;
                if (SelectedStageOption != CopyStageOptions.APPEND && (mainViewModel.TanVM.SelectedReaction == null || mainViewModel.TanVM.SelectedReaction.SelectedStage == null))
                {
                    AppInfoBox.ShowInfoMessage("Please select stage to Add stages before/after in curation window.");
                    return;
                }
                List <ReactionParticipantVM> allParticipants = new List <ReactionParticipantVM>();
                List <StageVM> reactionStages  = new List <StageVM>();
                var            tanParticipants = new List <ReactionParticipantVM>();
                if (IsReactantsSelected)
                {
                    var reactants = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Reactant select p).ToList();
                    allParticipants.AddRange(reactants);
                }
                if (IsSolventsSelected || IsAgentsSelected || IsCatalystSelected)
                {
                    if (IsSolventsSelected)
                    {
                        var solvents = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Solvent select p).ToList();
                        allParticipants.AddRange(solvents);
                    }

                    if (IsAgentsSelected)
                    {
                        var agents = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Agent select p).ToList();
                        allParticipants.AddRange(agents);
                    }

                    if (IsCatalystSelected)
                    {
                        var catalysts = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Catalyst select p).ToList();
                        allParticipants.AddRange(catalysts);
                    }
                }
                else
                {
                    AppInfoBox.ShowInfoMessage("Please select Atleast one type of Participants to Copy.");
                    return;
                }

                var          selectedreaction = mainViewModel.TanVM.SelectedReaction;
                List <RsnVM> tanRsns          = new List <RsnVM>();
                var          stages           = new List <StageVM>();
                for (int i = 0; i < StagesCountToCopy; i++)
                {
                    foreach (var selectedstage in SelectedStages)
                    {
                        var newStageToAdd = new StageVM
                        {
                            Id         = Guid.NewGuid(),
                            ReactionVm = selectedreaction
                        };
                        if (IsConditionsSelected)
                        {
                            var Conditions = new List <StageConditionVM>();
                            foreach (var selectedCondition in selectedstage.Conditions)
                            {
                                var condition = new StageConditionVM
                                {
                                    DisplayOrder  = selectedCondition.DisplayOrder,
                                    Id            = Guid.NewGuid(),
                                    PH            = selectedCondition.PH,
                                    PH_TYPE       = selectedCondition.PH_TYPE,
                                    Pressure      = selectedCondition.Pressure,
                                    PRESSURE_TYPE = selectedCondition.PRESSURE_TYPE,
                                    StageId       = newStageToAdd.Id,
                                    Temperature   = selectedCondition.Temperature,
                                    TEMP_TYPE     = selectedCondition.TEMP_TYPE,
                                    Time          = selectedCondition.Time,
                                    TIME_TYPE     = selectedCondition.TIME_TYPE
                                };
                                Conditions.Add(condition);
                            }
                            newStageToAdd.SetConditions(Conditions);
                        }
                        else
                        {
                            newStageToAdd.Conditions = new ObservableCollection <StageConditionVM>();
                        }
                        var stageParticipants = (from sp in allParticipants where sp.StageVM.Id == selectedstage.Id select sp).ToList();
                        foreach (var participant in stageParticipants)
                        {
                            var newParticipant = new ReactionParticipantVM
                            {
                                ChemicalType    = participant.ChemicalType,
                                DisplayOrder    = participant.DisplayOrder,
                                Name            = participant.Name,
                                Num             = participant.Num,
                                ParticipantType = participant.ParticipantType,
                                ReactionVM      = selectedreaction,
                                Reg             = participant.Reg,
                                StageVM         = newStageToAdd,
                                TanChemicalId   = participant.TanChemicalId,
                                Yield           = participant.Yield,
                                Id = Guid.NewGuid()
                            };
                            tanParticipants.Add(newParticipant);
                        }
                        if (IsRSNSelected)
                        {
                            var stagersnList = (from rsn in mainViewModel.TanVM.Rsns where rsn.Reaction.Id == selectedreaction.Id && rsn.Stage != null && rsn.Stage.Id == selectedstage.Id select rsn).ToList();
                            foreach (var rsn in stagersnList)
                            {
                                var newRsn = new RsnVM
                                {
                                    CvtText               = rsn.CvtText,
                                    Reaction              = selectedreaction,
                                    IsRXN                 = false,
                                    Stage                 = newStageToAdd,
                                    FreeText              = rsn.FreeText,
                                    Id                    = Guid.NewGuid(),
                                    DisplayOrder          = rsn.DisplayOrder,
                                    IsIgnorableInDelivery = rsn.IsIgnorableInDelivery,
                                    ReactionParticipantId = rsn.ReactionParticipantId,
                                    SelectedChemical      = rsn.SelectedChemical
                                };
                                tanRsns.Add(newRsn);
                            }
                        }
                        stages.Add(newStageToAdd);
                    }
                }
                mainViewModel.TanVM.EnablePreview = false;
                foreach (var participant in tanParticipants)
                {
                    mainViewModel.TanVM.ReactionParticipants.Add(participant);
                }
                foreach (var rsn in tanRsns)
                {
                    mainViewModel.TanVM.Rsns.Add(rsn);
                }
                mainViewModel.TanVM.EnablePreview = true;
                if (SelectedStageOption != CopyStageOptions.APPEND && mainViewModel.TanVM.SelectedReaction != null && mainViewModel.TanVM.SelectedReaction.SelectedStage != null)
                {
                    var stagesList = mainViewModel.TanVM.SelectedReaction.Stages.ToList();
                    var index      = stagesList.Count() >= 1 ? stagesList.FindIndex(x => x.Id == mainViewModel.TanVM.SelectedReaction.SelectedStage.Id) : 0;
                    if (SelectedStageOption == CopyStageOptions.AFTER)
                    {
                        selectedreaction.SetStages(stages, index + 1, true);
                    }
                    else if (SelectedStageOption == CopyStageOptions.BEFORE)
                    {
                        selectedreaction.SetStages(stages, index, true);
                    }
                }
                else
                {
                    selectedreaction.SetStages(stages);
                }
                mainViewModel.TanVM.PerformAutoSave("Stage Added");
                Visible = System.Windows.Visibility.Hidden;
                AppInfoBox.ShowInfoMessage("Please Update the Stage Freetext Stage Information for newly created stages.");
            }
            else
            {
                AppInfoBox.ShowInfoMessage("Please Select AtLeast One stage");
            }
        }