private void chemEditor_ComStructureChanged() { try { string MolFormula = GetMoleculeFormula(chemEditor.MolfileString); if (EditChemicalString && !String.IsNullOrEmpty(chemEditor.MolfileString)) { var inchiKey = MolToInchi.Mol2Inchi(chemEditor.MolfileString); if (!string.IsNullOrEmpty(inchiKey)) { var chemical = T.FindByInchiKey(inchiKey); if (chemical == null) { chemical = popupViewModel.TanChemicalVMList.Where(cn => cn.InChiKey != null && cn.Id != popupViewModel.SelectedTanChemicalVM.Id && cn.InChiKey == inchiKey).FirstOrDefault(); } if (chemical != null) { AppInfoBox.ShowInfoMessage(chemical.GetDuplicateChemicalString(inchiKey)); chemEditor.MolfileString = string.Empty; return; } } } if (!String.IsNullOrEmpty(chemEditor.MolfileString) && !EditChemicalString) { var inchiKey = MolToInchi.Mol2Inchi(chemEditor.MolfileString); if (!String.IsNullOrEmpty(inchiKey)) { var chemical = T.FindByInchiKey(inchiKey); if (chemical == null) { chemical = popupViewModel.TanChemicalVMList.Where(cn => cn.InChiKey != null && cn.InChiKey == inchiKey).FirstOrDefault(); } if (chemical != null) { AppInfoBox.ShowInfoMessage(chemical.GetDuplicateChemicalString(inchiKey)); chemEditor.MolfileString = string.Empty; return; } } popupViewModel.MolString = chemEditor.MolfileString; popupViewModel.MolFormula = MolFormula; } } catch (Exception ex) { Log.This(ex); } }
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); } }