public void LoadChemistryByTagItems() { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; try { ChemistryByTagItems.Clear(); SQLiteDataReader allTags = LibraryModel.GetChemistryByTags(); while (allTags.Read()) { var tag = new ChemistryByTag(); tag.ID = (long)allTags["ID"]; tag.GalleryID = (long)allTags["GalleryID"]; tag.tagID = (long)allTags["TagID"]; ChemistryByTagItems.Add(tag); } allTags.Close(); allTags.Dispose(); } catch (Exception ex) { new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog(); } }
public static Dictionary <string, int> GetLibraryNames() { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; try { Dictionary <string, int> allNames = new Dictionary <string, int>(); SQLiteDataReader names = LibraryModel.GetAllNames(); while (names.Read()) { string name = names["Name"] as string; if (!string.IsNullOrEmpty(name) && name.Length > 3) { int id = int.Parse(names["ChemistryId"].ToString()); if (!allNames.ContainsKey(name)) { allNames.Add(name, id); } } } names.Close(); names.Dispose(); return(allNames); } catch (Exception ex) { new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog(); return(null); } }
public ObservableCollection <UserTag> LoadUserTagItems(int ChemistryID) { var results = new ObservableCollection <UserTag>(); string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; try { SQLiteDataReader allTags = LibraryModel.GetAllUserTags(ChemistryID); while (allTags.Read()) { var tag = new UserTag(); tag.ID = (long)allTags["ID"]; tag.Text = (string)allTags["UserTag"]; results.Add(tag); } allTags.Close(); allTags.Dispose(); } catch (Exception ex) { new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog(); } return(results); }
public void Save() { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; try { LibraryModel.UpdateChemistry(ID, Name, XML, Formula); Dirty = false; } catch (Exception ex) { new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog(); } }
private void DeleteButton_OnClick(object sender, RoutedEventArgs e) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; try { if (AskUserYesNo("Do you want to delete this structure from the Library?") == DialogResult.Yes) { LibraryModel.DeleteChemistry(((LibraryViewModel.Chemistry) this.DataContext).ID); Globals.Chem4WordV3.LibraryNames = LibraryModel.GetLibraryNames(); ParentControl.MainGrid.DataContext = new LibraryViewModel(); } } catch (Exception ex) { new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog(); } }
private void AddNewChemistry(IList eNewItems) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; try { if (!_initializing) { foreach (Chemistry chemistry in eNewItems) { chemistry.ID = LibraryModel.AddChemistry(chemistry.XML, chemistry.Name, chemistry.Formula); } } } catch (Exception ex) { new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog(); } }
public static Dictionary <string, int> GetLibraryNames() { Dictionary <string, int> allNames = new Dictionary <string, int>(); SQLiteDataReader names = LibraryModel.GetAllNames(); while (names.Read()) { string name = names["Name"] as string; if (!string.IsNullOrEmpty(name) && name.Length > 3) { int id = int.Parse(names["ChemistryId"].ToString()); if (!allNames.ContainsKey(name)) { allNames.Add(name, id); } } } names.Close(); names.Dispose(); return(allNames); }
public void LoadChemistryItems(string filter) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; try { _initializing = true; ChemistryItems.Clear(); SQLiteDataReader chemistry = LibraryModel.GetAllChemistry(filter); while (chemistry.Read()) { var mol = new Chemistry(); mol.Initializing = true; mol.ID = (long)chemistry["ID"]; var byteArray = (Byte[])chemistry["Chemistry"]; mol.XML = Encoding.UTF8.GetString(byteArray); mol.Name = chemistry["name"] as string; mol.Formula = chemistry["formula"] as string; ChemistryItems.Add(mol); LoadOtherNames(mol); mol.Initializing = false; } chemistry.Close(); chemistry.Dispose(); _initializing = false; } catch (Exception ex) { new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog(); } }
public static bool ImportCml(string cmlFile) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; bool result = false; try { var converter = new CMLConverter(); Model.Model model = converter.Import(cmlFile); if (model.AllAtoms.Count > 0) { double before = model.MeanBondLength; if (before < Constants.MinimumBondLength - Constants.BondLengthTolerance || before > Constants.MaximumBondLength + Constants.BondLengthTolerance) { model.ScaleToAverageBondLength(Constants.StandardBondLength); double after = model.MeanBondLength; Globals.Chem4WordV3.Telemetry.Write(module, "Information", $"Structure rescaled from {before.ToString("#0.00")} to {after.ToString("#0.00")}"); } // Ensure each molecule has a Consise Formula set foreach (var molecule in model.Molecules) { if (string.IsNullOrEmpty(molecule.ConciseFormula)) { molecule.ConciseFormula = molecule.CalculatedFormula(); } } CMLConverter cmlConverter = new CMLConverter(); model.CustomXmlPartGuid = ""; var cml = cmlConverter.Export(model); string chemicalName = model.ConciseFormula; var mol = model.Molecules[0]; if (mol.ChemicalNames.Count > 0) { foreach (var name in mol.ChemicalNames) { long temp; if (!long.TryParse(name.Name, out temp)) { chemicalName = name.Name; break; } } } var id = AddChemistry(cml, chemicalName, model.ConciseFormula); foreach (var name in mol.ChemicalNames) { LibraryModel.AddChemicalName(id, name.Name, name.DictRef); } result = true; } } catch (Exception ex) { new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog(); } return(result); }