private void button4_Click(object sender, EventArgs e) { DBContext myDb = new DBContext(); myDb.categories.Where(o => o.Name == "دسته1").Load(); var cats = myDb.categories.ToList(); StoreModels.Category c; if (cats.Count == 0) { c = new StoreModels.Category() { Name = "دسته جدید" }; } else { c = cats[0]; } StoreModels.Product p = new StoreModels.Product() { Availability = 10, BuyPrice = 1000, SellPrice = 1500, Category = c, Name = "محصول1", }; myDb.save(p); }
private void button3_Click(object sender, EventArgs e) { DBContext myDb = new DBContext(); myDb.superCategories.Where(o => o.Name == "سوپر دسته1").Load(); var scats = myDb.superCategories.ToList(); StoreModels.SuperCategory sc; if (scats.Count == 0) { sc = new StoreModels.SuperCategory() { Name = "سوپر دسته جدید" } } ; else { sc = scats[0]; } StoreModels.Category c = new StoreModels.Category() { Name = "دسته1", SuperCategory = sc }; myDb.save(c); }
private void button23_Click(object sender, EventArgs e) { DBContext myDb = null; try { myDb = new DBContext(); myDb.products.Load(); var lst = myDb.products.ToList(); if (lst.Count == 0) { //لیست خالی } else { bool flag = false; myDb.superCategories.Load(); var lst1 = myDb.superCategories.ToList(); for (int i = 0; i < lst1.Count; i++) { if (lst1[i].Name == "") { flag = true; } if (!flag) { StoreModels.SuperCategory sc = new StoreModels.SuperCategory() { Name = "سوپر دسته" }; myDb.save(sc); } } myDb.categories.Load(); var lst2 = myDb.categories.ToList(); for (int i = 0; i < lst1.Count; i++) { if (lst2[i].Name == "دسته1") { flag = true; } if (!flag) { StoreModels.Category c = new StoreModels.Category() { Name = "کالا" }; myDb.save(c); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button18_Click(object sender, EventArgs e) { DBContext myDb = null; try { myDb = new DBContext(); StoreModels.Category c = myDb.categories.Where(i => i.Code == 2).FirstOrDefault(); myDb.categories.Attach(c); myDb.delete(c); } catch (Exception ex) { MessageBox.Show(ex.Message); } }