/// <summary> /// Deprecated Method for adding a new object to the Products EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToProducts(Product product) { base.AddObject("Products", product); }
/// <summary> /// Create a new Product object. /// </summary> /// <param name="productID">Initial value of the ProductID property.</param> /// <param name="storeID">Initial value of the StoreID property.</param> /// <param name="productName">Initial value of the ProductName property.</param> /// <param name="productsTypeID">Initial value of the ProductsTypeID property.</param> /// <param name="discount">Initial value of the Discount property.</param> /// <param name="oldPrice">Initial value of the OldPrice property.</param> /// <param name="newPrice">Initial value of the NewPrice property.</param> /// <param name="startDate">Initial value of the StartDate property.</param> /// <param name="endDate">Initial value of the EndDate property.</param> /// <param name="imageURL">Initial value of the ImageURL property.</param> public static Product CreateProduct(global::System.String productID, global::System.Int32 storeID, global::System.String productName, global::System.Int32 productsTypeID, global::System.Int32 discount, global::System.String oldPrice, global::System.String newPrice, global::System.String startDate, global::System.String endDate, global::System.String imageURL) { Product product = new Product(); product.ProductID = productID; product.StoreID = storeID; product.ProductName = productName; product.ProductsTypeID = productsTypeID; product.Discount = discount; product.OldPrice = oldPrice; product.NewPrice = newPrice; product.StartDate = startDate; product.EndDate = endDate; product.ImageURL = imageURL; return product; }
private void parseSite() { HttpWebRequest req; HttpWebResponse resp; StreamReader sr; string allContent; req = (HttpWebRequest)WebRequest.Create("http://tomall.ru/allmarket/okey/"); resp = (HttpWebResponse)req.GetResponse(); sr = new StreamReader(resp.GetResponseStream(), Encoding.GetEncoding("windows-1251")); allContent = sr.ReadToEnd(); sr.Close(); cleanTableProducts(); using (var ctx = new DiscountDBContext()) { for (int i = 10; i < 30; i++) { int startInd = allContent.IndexOf("all" + i.ToString()) + 7; int endInd = allContent.IndexOf("];", startInd); string content = allContent.Remove(endInd).Remove(0, startInd); //textBox1.Text = content; List<string> productsList = new List<string>(); for (int index = 0; index < content.Length - 1; ) { int startInd_ = content.IndexOf("[", index) + 1; int endInd_ = content.IndexOf("]", startInd_); //textBox1.Text += startInd_.ToString() + " " + endInd_.ToString() + " "; index = endInd_; string oneLine = content.Remove(endInd_).Remove(0, startInd_); productsList.Add(oneLine); } foreach (string line in productsList) { int index = 0; int startInd_ = 0; int endInd_ = line.IndexOf(",", index); string id = line.Remove(endInd_); /* var r = from c in ctx.Products where c.ProductID == id select c; if (r.Count() > 0) continue; */ index = endInd_; startInd_ = line.IndexOf("'", index) + 1; endInd_ = line.IndexOf("'", startInd_); string productName = line.Remove(endInd_).Remove(0, startInd_); index = endInd_; startInd_ = line.IndexOf(",", index) + 2; endInd_ = line.IndexOf(",", startInd_); string oldPrice = line.Remove(endInd_).Remove(0, startInd_); index = endInd_; startInd_ = line.IndexOf("'", index) + 1; endInd_ = line.IndexOf("'", startInd_); string newPrice = line.Remove(endInd_).Remove(0, startInd_); index = endInd_; startInd_ = line.IndexOf(",", index) + 2; endInd_ = line.IndexOf(",", startInd_); string discount = line.Remove(endInd_).Remove(0, startInd_); index = endInd_; startInd_ = line.IndexOf("'", index) + 1; endInd_ = line.IndexOf("'", startInd_); string storeName = line.Remove(endInd_).Remove(0, startInd_); index = endInd_; startInd_ = line.IndexOf(",", index) + 2; endInd_ = line.IndexOf(",", startInd_); string storeID = line.Remove(endInd_).Remove(0, startInd_); index = endInd_; startInd_ = line.IndexOf("'", index) + 1; endInd_ = line.IndexOf("'", startInd_); string startDate = line.Remove(endInd_).Remove(0, startInd_); index = endInd_ + 1; startInd_ = line.IndexOf("'", index) + 1; endInd_ = line.IndexOf("'", startInd_); string endDate = line.Remove(endInd_).Remove(0, startInd_); string imageURLFolder = Convert.ToInt32(id.Remove(3)).ToString(); string imageURLFile = Convert.ToInt32(id.Remove(0, 3)).ToString(); string imageURL = @"http://tomall.ru/allmarket/foto/" + imageURLFolder + @"/" + imageURLFile + ".jpg"; Product p = new Product { ProductID = id, StoreID = Convert.ToInt32(storeID), ProductName = productName, ProductsTypeID = i, Discount = Convert.ToInt32(discount), OldPrice = oldPrice, NewPrice = newPrice, StartDate = startDate, EndDate = endDate, ImageURL = imageURL }; ctx.Products.AddObject(p); ctx.SaveChanges(); } } updateHash(); } }