Beispiel #1
0
        public void Update8500(TanChemicalVM newChemicalNameVM)
        {
            try
            {
                if (SelectedTanChemicalVM != null && SelectedTanChemicalVM.ChemicalType == ChemicalType.S8500 && SelectedTanChemicalVM.NUM > 8000)
                {
                    var newlySelectedTanChemicalVM = TanChemicalVMList.Where(c => c.RegNumber == newChemicalNameVM.RegNumber).FirstOrDefault();
                    if (newlySelectedTanChemicalVM != null)
                    {
                        newlySelectedTanChemicalVM.NUM = SelectedTanChemicalVM.NUM;
                        newlySelectedTanChemicalVM.Id  = SelectedTanChemicalVM.Id;

                        SelectedTanChemicalVM.NUM = 0;
                        SelectedTanChemicalVM.Id  = Guid.Empty;
                        SelectedTanChemicalVM     = null;

                        SelectedTanChemicalVM = newlySelectedTanChemicalVM;
                        UpdateChemicalName(newlySelectedTanChemicalVM);
                        UpdateChemicalsView();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
            }
        }
Beispiel #2
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 #3
0
 public bool VerifyNewStructure(string inchiKey)
 {
     try
     {
         return(TanChemicalVMList.Where(c => c.InChiKey == inchiKey).Any());
     }
     catch (Exception ex)
     {
         Log.This(ex);
         return(false);
     }
 }
Beispiel #4
0
 private void PopupViewModel_PublishNUMAssign(object sender, TanChemicalVM e)
 {
     try
     {
         var sameRegChemical = TanChemicalVMList.Where(c => c.RegNumber == e.RegNumber).FirstOrDefault();
         if (sameRegChemical != null)
         {
             sameRegChemical.NUM = e.NUM;
         }
     }
     catch (Exception ex)
     {
         Log.This(ex);
     }
 }
Beispiel #5
0
 private void DeleteTanChemical(object obj)
 {
     try
     {
         var mainViewModel     = (App.Current.MainWindow as MainWindow).DataContext as MainVM;
         var EditedTanChemical = (from c in mainViewModel.TanVM.TanChemicals where c.Id == SelectedTanChemicalVM.Id select c).FirstOrDefault();
         var EditedParticipant = (from p in mainViewModel.TanVM.ReactionParticipants where p.TanChemicalId == SelectedTanChemicalVM.Id select p);
         if (SelectedTanChemicalVM.ChemicalType != ChemicalType.S9000 && SelectedTanChemicalVM.ChemicalType != ChemicalType.NUM && (EditedParticipant == null || !EditedParticipant.Any()))
         {
             DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("Are you Sure You want to Delete selected Chemical", "Reactions", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
             if (dialogResult == DialogResult.Yes)
             {
                 mainViewModel.TanVM.TanChemicals.Remove(EditedTanChemical);
                 var EditedChemical = TanChemicalVMList.Where(i => i.Id == SelectedTanChemicalVM.Id).FirstOrDefault();
                 if (EditedChemical.ChemicalType == ChemicalType.S8000)
                 {
                     TanChemicalVMList.Remove(EditedChemical);
                 }
                 else if (EditedChemical.ChemicalType == ChemicalType.S8500)
                 {
                     EditedChemical.NUM = 0;
                 }
                 mainViewModel.TanVM.UpdateUnusedNUMs();
                 mainViewModel.TanVM.UpdateNumsView();
                 mainViewModel.TanVM.PerformAutoSave($"{EditedChemical.ChemicalType} chemical deleted");
             }
         }
         else if (EditedParticipant != null && EditedParticipant.Any())
         {
             mainViewModel.PrepareInfo(EditedParticipant.FirstOrDefault());
             mainViewModel.ChemicalUsedPlacesVM.PreviewTabIndex = 0;
             mainViewModel.CallChemicalUsedPlacesWindow(mainViewModel.ChemicalUsedPlacesVM);
             //AppInfoBox.ShowInfoMessage($"Selected Chemical already involved in : {string.Join(",", EditedParticipant.Select(ep => ep.ReactionVM.DisplayName).ToList())} as {string.Join(",", EditedParticipant.Select(ep => ep.ParticipantType.ToString()).ToList())} Respectively. If You want to delete Please delete the participant In reaction.");
         }
     }
     catch (Exception ex)
     {
         Log.This(ex);
     }
 }
Beispiel #6
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);
     }
 }
Beispiel #7
0
 private void Add8000SeriesChemical(object s)
 {
     try
     {
         if (!string.IsNullOrEmpty(MolString))
         {
             if (S8000Metas != null && S8000Metas.Count > 0 && S8000Metas.Where(meta => !meta.ValidClass()).Count() == 0 &&
                 (!string.IsNullOrEmpty(SubstanceName) || !string.IsNullOrEmpty(CompoundNum) || !string.IsNullOrEmpty(GenericName)))
             {
                 if ((EditingChemicalId == Guid.Empty && !string.IsNullOrEmpty(SubstanceName) && (from cn in TanChemicalVMList where cn.Name.SafeEqualsLower(SubstanceName) select cn).Any()))
                 {
                     AppInfoBox.ShowInfoMessage("Substance name Already exist in Chemical Names List");
                     return;
                 }
                 if ((EditingChemicalId == Guid.Empty && !string.IsNullOrEmpty(GenericName) && (from cn in TanChemicalVMList where cn.GenericName.SafeEqualsLower(GenericName) select cn).Any()))
                 {
                     AppInfoBox.ShowInfoMessage("GenericName Already exist in Chemical Names List");
                     return;
                 }
                 if ((EditingChemicalId == Guid.Empty && !string.IsNullOrEmpty(CompoundNum) && (from cn in TanChemicalVMList where cn.GenericName.SafeEqualsLower(CompoundNum) select cn).Any()))
                 {
                     AppInfoBox.ShowInfoMessage("CompoundNum Already exist in Chemical Names List");
                     return;
                 }
                 var inchiKey = MolToInchi.Mol2Inchi(MolString);
                 if (!String.IsNullOrEmpty(inchiKey))
                 {
                     var chemical = T.FindByInchiKey(inchiKey);
                     if (chemical != null)
                     {
                         AppInfoBox.ShowInfoMessage(chemical.GetDuplicateChemicalString(inchiKey));
                         return;
                     }
                     chemical = TanChemicalVMList.Where(cn => cn.InChiKey != null && cn.InChiKey == inchiKey).FirstOrDefault();
                     if (chemical != null && EditingChemicalId == Guid.Empty)
                     {
                         AppInfoBox.ShowInfoMessage(chemical.GetDuplicateChemicalString(inchiKey));
                         return;
                     }
                 }
                 var mainViewModel = (App.Current.MainWindow as MainWindow).DataContext as MainVM;
                 var MetaDataList  = new List <TanChemicalMetaData>();
                 foreach (var item in S8000Metas)
                 {
                     var tanChemicalMeta = new TanChemicalMetaData
                     {
                         Id         = Guid.NewGuid(),
                         ColumnNo   = item.Column,
                         Figure     = item.Figure,
                         FootNote   = item.FootNote,
                         LineNo     = item.Line,
                         OtherNotes = item.Other,
                         PageNo     = item.Page,
                         ParaNo     = item.Para,
                         Scheme     = item.Scheme,
                         Sheet      = item.Sheet,
                         TableNo    = item.Table
                     };
                     MetaDataList.Add(tanChemicalMeta);
                 }
                 if (EditingChemicalId != Guid.Empty)
                 {
                     var EditedChemical = TanChemicalVMList.Where(i => i.Id == EditingChemicalId).FirstOrDefault();
                     if (EditedChemical != null)
                     {
                         EditedChemical.Name             = SubstanceName;
                         EditedChemical.SearchName       = string.IsNullOrEmpty(SubstanceName) ? (string.IsNullOrEmpty(GenericName) ? CompoundNum : GenericName) : SubstanceName;
                         EditedChemical.ChemicalType     = ChemicalType.S8000;
                         EditedChemical.CompoundNo       = CompoundNum;
                         EditedChemical.GenericName      = GenericName;
                         EditedChemical.StructureType    = StructureType.CGM;
                         EditedChemical.ChemicalmataData = MetaDataList;
                         EditedChemical.MolString        = MolString;
                         EditedChemical.MolFormula       = MolFormula;
                         EditedChemical.InChiKey         = inchiKey;
                     }
                     UpdateChemicalName(EditedChemical);
                     SelectedTanChemicalVM = null;
                     SelectedTanChemicalVM = EditedChemical;
                     mainViewModel.TanVM.UpdateUnusedNUMs();
                     mainViewModel.TanVM.UpdateNumsView();
                     Clear8000EditArea();
                     SelectedTabIndex = 0;
                 }
                 else
                 {
                     var newChemical = new TanChemicalVM
                     {
                         Id               = Guid.NewGuid(),
                         Name             = SubstanceName,
                         SearchName       = SubstanceName,
                         ChemicalType     = ChemicalType.S8000,
                         CompoundNo       = CompoundNum,
                         GenericName      = GenericName,
                         StructureType    = StructureType.CGM,
                         ChemicalmataData = MetaDataList,
                         MolString        = MolString,
                         MolFormula       = MolFormula,
                         InChiKey         = inchiKey
                     };
                     foreach (var item in MetaDataList)
                     {
                         item.TanChemicalId = newChemical.Id;
                     }
                     Add8000Chemical(newChemical);
                 }
                 EditingChemicalId = Guid.Empty;
             }
             else
             {
                 AppInfoBox.ShowInfoMessage("New Chemical data missed. To save new chemical SubstanceName/CompoundNum/GenericName and PageNo are mandatory.");
             }
         }
         else
         {
             AppInfoBox.ShowInfoMessage("Please draw structure to add");
         }
     }
     catch (Exception ex)
     {
         Log.This(ex);
     }
 }
Beispiel #8
0
 private void EditTanChemical(object s)
 {
     try
     {
         var mainViewModel = (App.Current.MainWindow as MainWindow).DataContext as MainVM;
         if (SelectedTanChemicalVM != null)
         {
             if (SelectedTanChemicalVM.ChemicalType == ChemicalType.S8000)
             {
                 EditingChemicalId = SelectedTanChemicalVM.Id;
                 SubstanceName     = SelectedTanChemicalVM.Name;
                 CompoundNum       = SelectedTanChemicalVM.CompoundNo;
                 GenericName       = SelectedTanChemicalVM.GenericName;
                 MolString         = SelectedTanChemicalVM.MolString;
                 List <S8000MetaVM> MetaList = new List <S8000MetaVM>();
                 foreach (var item in SelectedTanChemicalVM.ChemicalmataData)
                 {
                     var metavm = new S8000MetaVM
                     {
                         Column   = item.ColumnNo,
                         Figure   = item.Figure,
                         FootNote = item.FootNote,
                         Id       = item.Id,
                         Line     = item.LineNo,
                         Other    = item.OtherNotes,
                         Page     = item.PageNo,
                         Para     = item.ParaNo,
                         Scheme   = item.Scheme,
                         Sheet    = item.Sheet,
                         Table    = item.TableNo
                     };
                     MetaList.Add(metavm);
                 }
                 S8000Metas       = new ObservableCollection <ViewModels.S8000MetaVM>(MetaList);
                 SelectedTabIndex = 1;
             }
             else if (SelectedTanChemicalVM.ChemicalType == ChemicalType.S8500)
             {
                 if (SelectedTanChemicalVM.NUM > 8500)
                 {
                     var s8500Chemicals = new List <TanChemicalVM>();
                     var chemicalName   = new TanChemicalVM(SelectedTanChemicalVM);
                     foreach (var e in TanChemicalVMList.Where(c => c.ChemicalType == ChemicalType.S8500 && c.NUM == 0))
                     {
                         s8500Chemicals.Add(new TanChemicalVM(e));
                     }
                     EditS8500Chemical.Invoke(this, new EditChemicalName {
                         ChemicalNameVM = chemicalName, ChoosableChemicalVMs = s8500Chemicals
                     });
                     var AllNumsList       = TanChemicalVMList.Where(tc => tc.NUM > 0).Select(tc => tc.NUM);
                     var duplicateNumsList = AllNumsList.GroupBy(num => num);
                     if (AllNumsList.Count() != duplicateNumsList.Count())
                     {
                         Log.This(new Exception("Duplicate Nums were generated"));
                     }
                 }
                 else
                 {
                     AppInfoBox.ShowInfoMessage("NUM Not Generated For This Chemical . .");
                 }
             }
             else
             {
                 AppInfoBox.ShowInfoMessage("Only 8500 And 8000 NUMs Are Editable . .");
             }
         }
     }
     catch (Exception ex)
     {
         Log.This(ex);
     }
 }