Beispiel #1
0
        public void Add8000Chemical(TanChemicalVM newChemical)
        {
            try
            {
                var mainViewModel = (App.Current.MainWindow as MainWindow).DataContext as MainVM;
                if (TanChemicalVMList != null)
                {
                    //generate new 8000 number
                    int seriesNumber          = 8001;
                    var maxSeriesNumChecmical = TanChemicalVMList.
                                                Where(rp => rp.ChemicalType == ChemicalType.S8000)
                                                .OrderBy(rp => rp.NUM).LastOrDefault();
                    if (maxSeriesNumChecmical != null && maxSeriesNumChecmical.NUM < 8499)
                    {
                        seriesNumber = maxSeriesNumChecmical.NUM + 1;
                    }
                    else if (maxSeriesNumChecmical != null && maxSeriesNumChecmical.NUM >= 8499)
                    {
                        seriesNumber = 7001;
                        var _7000SeriesNumChecmical = TanChemicalVMList.
                                                      Where(rp => rp.ChemicalType == ChemicalType.S8000 && rp.NUM < 8000)
                                                      .OrderBy(rp => rp.NUM).LastOrDefault();
                        if (_7000SeriesNumChecmical != null && _7000SeriesNumChecmical.NUM < 8500)
                        {
                            seriesNumber = _7000SeriesNumChecmical.NUM + 1;
                        }
                    }

                    TanChemicalVM c = new TanChemicalVM();
                    c.ChemicalType     = ChemicalType.S8000;
                    c.RegNumber        = String.Empty;
                    c.SearchName       = string.IsNullOrEmpty(newChemical.Name) ? (string.IsNullOrEmpty(newChemical.GenericName) ? newChemical.CompoundNo : newChemical.GenericName) : newChemical.Name;
                    c.Name             = string.IsNullOrEmpty(newChemical.Name) ? (string.IsNullOrEmpty(newChemical.GenericName) ? newChemical.CompoundNo : newChemical.GenericName) : newChemical.Name;
                    c.NUM              = seriesNumber;
                    c.InChiKey         = newChemical.InChiKey;
                    c.ChemicalmataData = newChemical.ChemicalmataData;
                    c.CompoundNo       = newChemical.CompoundNo;
                    c.GenericName      = newChemical.GenericName;
                    c.Id = newChemical.Id;
                    c.ChemicalmataData = newChemical.ChemicalmataData;
                    c.MolString        = newChemical.MolString;
                    c.MolFormula       = newChemical.MolFormula;
                    TanChemicalVMList.Add(c);
                    mainViewModel.S8000Chemicals.Add(c);
                    TanChemical tanchemical = (from p in mainViewModel.TanVM.TanChemicals where p.Id == newChemical.Id select p).FirstOrDefault();
                    if (tanchemical == null)
                    {
                        TanChemicalsCrud.AddTanChemicalToList(mainViewModel.TanVM.TanChemicals, c, mainViewModel.TanVM.Id);
                    }
                    mainViewModel.TanVM.PerformAutoSave("8000 chemical generated");
                    Clear8000EditArea();
                    SelectedTabIndex = 0;
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
            }
        }
Beispiel #2
0
 public void AddParticipant(object participant)
 {
     try
     {
         var StartTime = DateTime.Now;
         Debug.WriteLine($"Add Participant Started at {StartTime.DMYHMT()}");
         var mainViewModel = (App.Current.MainWindow as MainWindow).DataContext as MainVM;
         if (SelectedTanChemicalVM != null && mainViewModel.TanVM != null && mainViewModel.IsParticipatTypeSelected)
         {
             if (S.AllowedDuplicateChemicals.Where(c => SelectedTanChemicalVM.SearchName.Contains(c)).Count() > 0)
             {
                 var ListOfNames           = SelectedTanChemicalVM.SearchName.Split(new string[] { "; " }, StringSplitOptions.RemoveEmptyEntries);
                 DuplicateNamesList dnList = new Views.DuplicateNamesList();
                 (dnList.DataContext as DuplicateNamesVM).DuplicateNamesView = new ObservableCollection <Names>(ListOfNames.Select(s => new Names {
                     Name = s
                 }));
                 dnList.ShowDialog();
                 if ((dnList.DataContext as DuplicateNamesVM).DialogStatus)
                 {
                     SelectedTanChemicalVM.Name = (dnList.DataContext as DuplicateNamesVM).SelectedName.Name;
                 }
                 else
                 {
                     return;
                 }
             }
             if (SelectedTanChemicalVM.RegNumber == "5137553")
             {
                 AppInfoBox.ShowInfoMessage("You can't add Aliquat 336. If still you want please Add RSN as 'Aliquat 336 Used'");
                 return;
             }
             if (SelectedTanChemicalVM.RegNumber == "69849452")
             {
                 AppInfoBox.ShowInfoMessage("Davis reagent (REGNUM: 69849452) cannot be used in RSD, please capture in RSN");
                 return;
             }
             //this is required only for 8500 series. All other series will have Num values.
             if (SelectedTanChemicalVM != null && SelectedTanChemicalVM.NUM == 0)
             {
                 var numChemical = TanChemicalVMList.Where(cn => cn.ChemicalType == ChemicalType.NUM && cn.RegNumber == SelectedTanChemicalVM.RegNumber).FirstOrDefault();
                 if (numChemical != null)
                 {
                     StringBuilder sb = new StringBuilder();
                     sb.Append($"Selected chemical already Present in NUMS section with num {numChemical.NUM}");
                     AppInfoBox.ShowInfoMessage(sb.ToString());
                     return;
                 }
                 SelectedTanChemicalVM.Id = Guid.NewGuid();
                 var maxNum = TanChemicalVMList.
                              Where(rp => rp.ChemicalType == ChemicalType.S8500).
                              Select(rp => rp.NUM).
                              Max();
                 if (maxNum > 0)
                 {
                     SelectedTanChemicalVM.NUM = maxNum + 1;
                 }
                 else
                 {
                     SelectedTanChemicalVM.NUM = 8501;
                 }
                 TanChemical tanchemical = (from p in mainViewModel.TanVM.TanChemicals where p.RegNumber == SelectedTanChemicalVM.RegNumber select p).FirstOrDefault();
                 if (tanchemical == null)
                 {
                     TanChemicalsCrud.AddTanChemicalToList(mainViewModel.TanVM.TanChemicals, SelectedTanChemicalVM, mainViewModel.TanVM.Id);
                 }
                 if (!AddAsParticipant)
                 {
                     mainViewModel.TanVM.PerformAutoSave("8500 Chemical Added");
                 }
             }
             var chemical = TanChemicalVMList.Where(cn => cn.ChemicalType == ChemicalType.NUM && cn.RegNumber == SelectedTanChemicalVM.RegNumber && SelectedTanChemicalVM.ChemicalType != ChemicalType.NUM).FirstOrDefault();
             if (chemical != null)
             {
                 SelectedTanChemicalVM = chemical;
             }
             if (SelectedTanChemicalVM.RegNumber == "30525894" && SelectedTanChemicalVM.ChemicalType == ChemicalType.NUM)
             {
                 SelectedTanChemicalVM      = TanChemicalVMList.Where(cn => cn.ChemicalType == ChemicalType.S9000 && cn.RegNumber == "50000").FirstOrDefault();
                 SelectedTanChemicalVM.Name = S.PARA_FORM;
             }
             Debug.WriteLine($"Before adding Participant to Json {System.DateTime.Now}");
             if (SelectedTanChemicalVM != null && AddAsParticipant)
             {
                 (App.Current.MainWindow as MainWindow).ChemicalNameAdded(SelectedTanChemicalVM);
             }
             ReactionValidations.AddJonesReAgentRSN(mainViewModel.TanVM);
             Debug.WriteLine($"After adding Participant to Json {System.DateTime.Now}");
             Debug.WriteLine($"Add Participant Done in {(DateTime.Now - StartTime).TotalSeconds} seconds");
         }
     }
     catch (Exception ex)
     {
         Log.This(ex);
     }
 }