public static void MigrateElements() { var context = new ChemContext(); var path = "Elements.csv"; if (!File.Exists(path)) { MessageBox.Show("Error reading Elements.csv file. Does it exist?", "Error!"); return; } int addedElements = 0; int modifiedElements = 0; using (StreamReader file = File.OpenText(path)) { string line; while ((line = file.ReadLine()) != null) { string[] substrings = line.Split(";"); int atomNumber = int.Parse(substrings[0]); string name = substrings[1].ToLower(); string symbol = substrings[2]; double molarMass = double.Parse(substrings[3]); Element el = context.Elements.Find(atomNumber); if (el != null) { if (el.Name != name || el.Symbol != symbol || el.MolarMass != molarMass) { el.Name = name; el.Symbol = symbol; el.MolarMass = molarMass; context.Elements.Update(el); modifiedElements++; } continue; } context.Elements.Add(new Element { ElementId = atomNumber, AtomNumber = atomNumber, Name = name, Symbol = symbol, MolarMass = molarMass }); addedElements++; } if (addedElements != 0 || modifiedElements != 0) { context.SaveChanges(); } } MessageBox.Show( String.Format("A total of {0} elements were successfully added and {1} modified.", addedElements, modifiedElements), "Success!" ); }
private static string BFormulaOrNull(string s) { var context = ChemContext.Create(); var elements = context.Set <Element>().Select(x => x.Sign.ToLower()).ToList(); PPP(s, elements, ""); var iii = _store.Select(x => ParseFormula1(x)).ToList(); return(null); }
private static void RenweDatabase() { using (var context = ChemContext.Create()) { var elements = context.Set <Element>().Select(x => x.Sign.ToLower()).ToList(); var l = context.Set <Substance>(); foreach (var item in l) { var ttt = ParseFormula1(item.Formula); if (ttt.HasValue()) { item.Formula = ttt; } else { } } context.SaveChanges(); } }
static void GetData() { using (var context = ChemContext.Create()) { // var categories = context.Set<Category>().Include(x => x.Parents).ToList(); var substancies = context.Set <Substance>() .Include(x => x.Names) .Include(x => x.Scheme) .Include(x => x.Categories) .Include(x => x.Categories.Select(y => y.Parents)).FirstOrDefault(x => x.Names.Any(n => n.Value == "Хлорид кальция")); if (substancies != null) { Console.WriteLine(substancies.Formula + " " + substancies.CAS); } else { Console.WriteLine("nety$"); } } }
static void Clear() { using (var context = ChemContext.Create()) { //foreach (var entity in context.Set<Category>()) // context.Set<Category>().Remove(entity); foreach (var name in context.Set <SubstanceName>()) { context.Set <SubstanceName>().Remove(name); } foreach (var scheme in context.Set <SubstanceScheme>()) { context.Set <SubstanceScheme>().Remove(scheme); } foreach (var entity in context.Set <Substance>()) { context.Set <Substance>().Remove(entity); } context.SaveChanges(); } }
static void AddData() { using (var context = ChemContext.Create()) { var c = context.Set <Category>().FirstOrDefault(x => x.Name == "Hernya"); var c2 = context.Set <Category>().FirstOrDefault(x => x.Id == 5); c.Parents.Add(c2); //var s = new Substance //{ // BoilingPoint = 0.34343, // CAS = "cas jjjJjjJjJ", // Categories = new List<Category>(new Category[] { c }), // Formula = "C2H6O", // Names = GetNames("Этиловый спирт1", "etilovii spirt1"), // Scheme = GetSchemes("scheme12", "scheme22"), // WaterSolubility = true //}; //context.Set<Substance>().Add(s); context.SaveChanges(); } }
public ElementManager() { _context = new ChemContext(); }
public ElementManager(DbContext context) { _context = context as ChemContext; }
public CategoryManager(DbContext context) { _context = context as ChemContext; }
public CategoryManager() { _context = new ChemContext(); }
public SubstanceManager() { _context = new ChemContext(); }
public static String getAllReactionsStr(int reactionType, int catId) { var reacts = String.Join(",", ChemContext.db().getReactions(reactionType, catId)); return(reacts); }
protected String getAllCategories(int reactionType) { var cats = String.Join("', '", ChemContext.db().getAllCategories(reactionType)); return(cats); }
public SubstanceManager(DbContext context) { _context = context as ChemContext; }