public bool Save(productprice p) { using (var scope = new PetaPoco.Transaction(_db)) { if (string.IsNullOrEmpty(p.ID)) {//新增 p.ID = Guid.NewGuid().ToString(); _db.Insert(p); } else {//编辑 var old = _db.FirstOrDefault <productprice>("where id=@0", p.ID); var model = new oldprice(); model.ID = Guid.NewGuid().ToString(); model.PriceID = old.ID; model.LimitNum = old.LimitNum; model.Price = old.Price; model.MemberPrice = old.MemberPrice; model.StaffName = p.StaffName; model.CreatDate = DateTime.Now; model.ProductName = ""; model.ProductID = old.ProductID; _db.Update(p); _db.Insert(model); } scope.Complete(); return(true); } }
/** * Create pizza products from the pizzaIngredient table. Also imports the sauce since the pizza_ingredient import file * is the only source for both sauces and pizzas. */ private product createPizzaProduct(DataRow lineInformation) { productcategory category = this.productImporter.findOrCreateCategory((string)lineInformation.ItemArray[0]); product product = new product(); product.name = (string)lineInformation.ItemArray[2]; product.productcategory1 = this.productImporter.findOrCreateCategory((string)lineInformation.ItemArray[1], category); product.description = (string)lineInformation.ItemArray[3]; product.isspicy = lineInformation.ItemArray[6].ToString().ToUpper() == "JA"; product.isvegetarian = lineInformation.ItemArray[7].ToString().ToUpper() == "JA"; productprice price = new productprice(); price.countrycode = this.countrycode; price.price = Decimal.Parse(Regex.Replace(lineInformation.ItemArray[4].ToString(), "[^0-9.]", "")) / 100; sauce sauce = this.GetOrCreateSauce((string)lineInformation.ItemArray[11]); product.sauce = sauce; database.products.Add(product); Console.WriteLine( "New pizza {0} created with sauce {1}", (string)lineInformation.ItemArray[2], (string)lineInformation.ItemArray[11] ); database.SaveChanges(); return(product); }
public ApiMessage <string> Save(PriceEx n, CurrentUser user) { var res = new ApiMessage <string>(); var p = new productprice(); p.ID = n.ID; p.Price = n.Price; p.MemberPrice = n.MemberPrice; p.LimitNum = n.LimitNum; p.ProductID = n.ProductID; p.UnitID = n.UnitID; p.UnitName = n.UnitID; p.StaffID = user.Id; p.StaffName = user.UserName; p.CreateDate = DateTime.Now; _dal.Save(p); return(res); }
protected override int Import(string path) { int insertedProducts = 0; DataTable productTable = new DataTable(); // Begin Excel using (OleDbConnection localDbConnection = new OleDbConnection(string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0;", filePath))) { localDbConnection.Open(); OleDbDataAdapter dataAdapter = new OleDbDataAdapter("select * from [Sheet1$]", localDbConnection); dataAdapter.Fill(productTable); localDbConnection.Close(); } foreach (DataRow row in productTable.Rows) { //categorie;subcategorie;productnaam;productomschrijving;prijs;spicy;vegetarisch;available;amount;name if (row.ItemArray.Length < 7) { Logger.Instance.LogError(path, "Could not create product for line: " + row.ToString()); continue; } string categoryName = (string)row.ItemArray[0]; string subcategoryName = (string)row.ItemArray[1]; string name = (string)row.ItemArray[2]; string description = row.ItemArray[3].ToString(); Decimal price = Decimal.Parse(Regex.Replace(Convert.ToString(row.ItemArray[4]).Replace(".", ","), "[^0-9,]", "")); bool spicy = ((string)row.ItemArray[5]).ToUpper() == "JA"; bool vegetarian = ((string)row.ItemArray[6]).ToUpper() == "JA"; productcategory category = findOrCreateCategory(categoryName); productcategory subcategory = findOrCreateCategory(subcategoryName, category); product product = database.products.SingleOrDefault(i => i.name == name); if (product == null) { product = new product(); product.name = name; product.description = description; product.isspicy = spicy; product.isvegetarian = vegetarian; product.productcategory = subcategory.id; database.products.Add(product); // Create a productprice for the current price. productprice productprice = new productprice(); productprice.product = product; productprice.price = price; productprice.currency = "EUR"; productprice.startdate = DateTime.Now; productprice.countrycode = countrycode; database.productprices.Add(productprice); Console.WriteLine("New product {0} created", name); insertedProducts++; } // If the product already exists, update every field except name, this includes creating a new price. else { product.description = description; product.isspicy = spicy; product.isvegetarian = vegetarian; product.productcategory = subcategory.id; // Create a productprice for the current price. productprice productprice = new productprice(); productprice.product = product; productprice.price = price; productprice.currency = "EUR"; productprice.startdate = DateTime.Now; productprice.countrycode = countrycode; database.productprices.Add(productprice); Console.WriteLine("Updating existing product {0}", name); } database.SaveChanges(); } return(insertedProducts); }