public static void SaveCompoundMatrixCategory(compound_matrix_category category)
 {
     var old = (from d in DB.LEGACY.compound_matrix_category where d.ID == category.ID select d).SingleOrDefault();
     if (old != null)
     {
         old.Name = category.Name;
         DB.LSave();
     }
     else
     {
         DB.LEGACY.compound_matrix_category.Add(category);
         DB.LSave();
     }
 }
 public static void DeleteCompoundMatrixCategory(compound_matrix_category category)
 {
     var old = (from d in DB.LEGACY.compound_matrix_category where d.ID == category.ID select d).SingleOrDefault();
     if (old != null)
     {
         DB.LEGACY.compound_matrix_category.Remove(old);
         DB.LSave();
     }
 }
 private void copyCompoundFormulaCategory_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     var category = compoundFormulaCategoryList.SelectedItem as compound_matrix_category;
     if (category == null)
         return;
     long maxid = (from d in LegacyToolBox.Data.CompoundFormulaCategory select d.ID).Max() + 1;
     var newCategory = new compound_matrix_category()
     {
         ID = maxid,
         Name = category.Name
     };
     LegacyToolBox.Data.CompoundFormulaCategory.Add(newCategory);
     DataProcessor.SaveCompoundMatrixCategory(newCategory);
 }