private void ProcessProductDetails(System.Web.HttpContext context) { string str = "http://" + System.Web.HttpContext.Current.Request.Url.Host + ((System.Web.HttpContext.Current.Request.Url.Port == 80) ? "" : (":" + System.Web.HttpContext.Current.Request.Url.Port)); int distributorId = int.Parse(context.Request["distributorUserId"]); int productId = int.Parse(context.Request["productId"]); PublishToTaobaoProductInfo taobaoProduct = SubSiteProducthelper.GetTaobaoProduct(productId, distributorId); System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); stringBuilder.Append("{"); stringBuilder.AppendFormat("\"Cid\":\"{0}\",", taobaoProduct.Cid); stringBuilder.AppendFormat("\"StuffStatus\":\"{0}\",", taobaoProduct.StuffStatus); stringBuilder.AppendFormat("\"ProductId\":\"{0}\",", taobaoProduct.ProductId); stringBuilder.AppendFormat("\"ProTitle\":\"{0}\",", taobaoProduct.ProTitle); stringBuilder.AppendFormat("\"Num\":\"{0}\",", taobaoProduct.Num); stringBuilder.AppendFormat("\"LocationState\":\"{0}\",", taobaoProduct.LocationState); stringBuilder.AppendFormat("\"LocationCity\":\"{0}\",", taobaoProduct.LocationCity); stringBuilder.AppendFormat("\"FreightPayer\":\"{0}\",", taobaoProduct.FreightPayer); stringBuilder.AppendFormat("\"PostFee\":\"{0}\",", taobaoProduct.PostFee.ToString("F2")); stringBuilder.AppendFormat("\"ExpressFee\":\"{0}\",", taobaoProduct.ExpressFee.ToString("F2")); stringBuilder.AppendFormat("\"EMSFee\":\"{0}\",", taobaoProduct.EMSFee.ToString("F2")); stringBuilder.AppendFormat("\"HasInvoice\":\"{0}\",", taobaoProduct.HasInvoice); stringBuilder.AppendFormat("\"HasWarranty\":\"{0}\",", taobaoProduct.HasWarranty); stringBuilder.AppendFormat("\"HasDiscount\":\"{0}\",", taobaoProduct.HasDiscount); stringBuilder.AppendFormat("\"ValidThru\":\"{0}\",", taobaoProduct.ValidThru); stringBuilder.AppendFormat("\"ListTime\":\"{0}\",", taobaoProduct.ListTime); stringBuilder.AppendFormat("\"PropertyAlias\":\"{0}\",", taobaoProduct.PropertyAlias); stringBuilder.AppendFormat("\"InputPids\":\"{0}\",", taobaoProduct.InputPids); stringBuilder.AppendFormat("\"InputStr\":\"{0}\",", taobaoProduct.InputStr); stringBuilder.AppendFormat("\"SkuProperties\":\"{0}\",", taobaoProduct.SkuProperties); stringBuilder.AppendFormat("\"SkuQuantities\":\"{0}\",", taobaoProduct.SkuQuantities); stringBuilder.AppendFormat("\"SkuPrices\":\"{0}\",", taobaoProduct.SkuPrices); stringBuilder.AppendFormat("\"SkuOuterIds\":\"{0}\",", taobaoProduct.SkuOuterIds); stringBuilder.AppendFormat("\"FoodAttributes\":\"{0}\",", System.Web.HttpUtility.UrlEncode(taobaoProduct.FoodAttributes)); stringBuilder.AppendFormat("\"TaobaoProductId\":\"{0}\",", taobaoProduct.TaobaoProductId); stringBuilder.AppendFormat("\"ProductCode\":\"{0}\",", taobaoProduct.ProductCode); stringBuilder.AppendFormat("\"Description\":\"{0}\",", taobaoProduct.Description.Replace(string.Format("src=\"{0}/Storage/master/gallery", Globals.ApplicationPath), string.Format("src=\"{0}/Storage/master/gallery", str + Globals.ApplicationPath)).Replace('"', '“')); string text = str + Globals.ApplicationPath + taobaoProduct.ImageUrl1; if (System.IO.File.Exists(Globals.MapPath(Globals.ApplicationPath + taobaoProduct.ImageUrl1)) && (text.EndsWith(".jpg", System.StringComparison.CurrentCultureIgnoreCase) || text.EndsWith(".gif", System.StringComparison.CurrentCultureIgnoreCase) || text.EndsWith(".png", System.StringComparison.CurrentCultureIgnoreCase) || text.EndsWith(".jpeg", System.StringComparison.CurrentCultureIgnoreCase))) { stringBuilder.AppendFormat("\"ImageName\":\"{0}\",", text); } if (!string.IsNullOrEmpty(taobaoProduct.ImageUrl2)) { string text2 = str + Globals.ApplicationPath + taobaoProduct.ImageUrl2; if (System.IO.File.Exists(Globals.MapPath(Globals.ApplicationPath + taobaoProduct.ImageUrl2)) && (text2.EndsWith(".jpg", System.StringComparison.CurrentCultureIgnoreCase) || text2.EndsWith(".gif", System.StringComparison.CurrentCultureIgnoreCase) || text2.EndsWith(".png", System.StringComparison.CurrentCultureIgnoreCase) || text2.EndsWith(".jpeg", System.StringComparison.CurrentCultureIgnoreCase))) { stringBuilder.AppendFormat("\"ImageName2\":\"{0}\",", text2); } } if (!string.IsNullOrEmpty(taobaoProduct.ImageUrl3)) { string text3 = str + Globals.ApplicationPath + taobaoProduct.ImageUrl3; if (System.IO.File.Exists(Globals.MapPath(Globals.ApplicationPath + taobaoProduct.ImageUrl3)) && (text3.EndsWith(".jpg", System.StringComparison.CurrentCultureIgnoreCase) || text3.EndsWith(".gif", System.StringComparison.CurrentCultureIgnoreCase) || text3.EndsWith(".png", System.StringComparison.CurrentCultureIgnoreCase) || text3.EndsWith(".jpeg", System.StringComparison.CurrentCultureIgnoreCase))) { stringBuilder.AppendFormat("\"ImageName3\":\"{0}\",", text3); } } if (!string.IsNullOrEmpty(taobaoProduct.ImageUrl4)) { string text4 = str + Globals.ApplicationPath + taobaoProduct.ImageUrl4; if (System.IO.File.Exists(Globals.MapPath(Globals.ApplicationPath + taobaoProduct.ImageUrl4)) && (text4.EndsWith(".jpg", System.StringComparison.CurrentCultureIgnoreCase) || text4.EndsWith(".gif", System.StringComparison.CurrentCultureIgnoreCase) || text4.EndsWith(".png", System.StringComparison.CurrentCultureIgnoreCase) || text4.EndsWith(".jpeg", System.StringComparison.CurrentCultureIgnoreCase))) { stringBuilder.AppendFormat("\"ImageName4\":\"{0}\",", text4); } } if (!string.IsNullOrEmpty(taobaoProduct.ImageUrl5)) { string text5 = str + Globals.ApplicationPath + taobaoProduct.ImageUrl5; if (System.IO.File.Exists(Globals.MapPath(Globals.ApplicationPath + taobaoProduct.ImageUrl5)) && (text5.EndsWith(".jpg", System.StringComparison.CurrentCultureIgnoreCase) || text5.EndsWith(".gif", System.StringComparison.CurrentCultureIgnoreCase) || text5.EndsWith(".png", System.StringComparison.CurrentCultureIgnoreCase) || text5.EndsWith(".jpeg", System.StringComparison.CurrentCultureIgnoreCase))) { stringBuilder.AppendFormat("\"ImageName5\":\"{0}\",", text5); } } stringBuilder.AppendFormat("\"SalePrice\":\"{0}\"", taobaoProduct.SalePrice.ToString("F2")); stringBuilder.Append("}"); context.Response.Write(stringBuilder.ToString()); }
public PublishToTaobaoProductInfo GetTaobaoProduct(int productId) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("SELECT tp.*, p.TaobaoProductId,p.ProductCode, p.Description, p.ImageUrl1, p.ImageUrl2, p.ImageUrl3, p.ImageUrl4, p.ImageUrl5,"); stringBuilder.Append(" (SELECT MIN(SalePrice) FROM Ecshop_SKUs WHERE ProductId = p.ProductId) AS SalePrice,"); stringBuilder.Append(" (SELECT MIN(Weight) FROM Ecshop_SKUs WHERE ProductId = p.ProductId) AS Weight"); stringBuilder.AppendFormat(" FROM Ecshop_Products p JOIN Taobao_Products tp ON p.ProductId = tp.ProductId WHERE p.ProductId = {0}", productId); DbCommand sqlStringCommand = this.database.GetSqlStringCommand(stringBuilder.ToString()); PublishToTaobaoProductInfo publishToTaobaoProductInfo = null; using (IDataReader dataReader = this.database.ExecuteReader(sqlStringCommand)) { if (dataReader.Read()) { publishToTaobaoProductInfo = new PublishToTaobaoProductInfo(); publishToTaobaoProductInfo.Cid = (long)dataReader["Cid"]; if (dataReader["StuffStatus"] != DBNull.Value) { publishToTaobaoProductInfo.StuffStatus = (string)dataReader["StuffStatus"]; } publishToTaobaoProductInfo.ProductId = (int)dataReader["ProductId"]; publishToTaobaoProductInfo.ProTitle = (string)dataReader["ProTitle"]; publishToTaobaoProductInfo.Num = (long)dataReader["Num"]; publishToTaobaoProductInfo.LocationState = (string)dataReader["LocationState"]; publishToTaobaoProductInfo.LocationCity = (string)dataReader["LocationCity"]; publishToTaobaoProductInfo.FreightPayer = (string)dataReader["FreightPayer"]; if (dataReader["PostFee"] != DBNull.Value) { publishToTaobaoProductInfo.PostFee = (decimal)dataReader["PostFee"]; } if (dataReader["ExpressFee"] != DBNull.Value) { publishToTaobaoProductInfo.ExpressFee = (decimal)dataReader["ExpressFee"]; } if (dataReader["EMSFee"] != DBNull.Value) { publishToTaobaoProductInfo.EMSFee = (decimal)dataReader["EMSFee"]; } publishToTaobaoProductInfo.HasInvoice = (bool)dataReader["HasInvoice"]; publishToTaobaoProductInfo.HasWarranty = (bool)dataReader["HasWarranty"]; publishToTaobaoProductInfo.HasDiscount = (bool)dataReader["HasDiscount"]; publishToTaobaoProductInfo.ValidThru = (long)dataReader["ValidThru"]; if (dataReader["ListTime"] != DBNull.Value) { publishToTaobaoProductInfo.ListTime = (DateTime)dataReader["ListTime"]; } if (dataReader["PropertyAlias"] != DBNull.Value) { publishToTaobaoProductInfo.PropertyAlias = (string)dataReader["PropertyAlias"]; } if (dataReader["InputPids"] != DBNull.Value) { publishToTaobaoProductInfo.InputPids = (string)dataReader["InputPids"]; } if (dataReader["InputStr"] != DBNull.Value) { publishToTaobaoProductInfo.InputStr = (string)dataReader["InputStr"]; } if (dataReader["SkuProperties"] != DBNull.Value) { publishToTaobaoProductInfo.SkuProperties = (string)dataReader["SkuProperties"]; } if (dataReader["SkuQuantities"] != DBNull.Value) { publishToTaobaoProductInfo.SkuQuantities = (string)dataReader["SkuQuantities"]; } if (dataReader["SkuPrices"] != DBNull.Value) { publishToTaobaoProductInfo.SkuPrices = (string)dataReader["SkuPrices"]; } if (dataReader["SkuOuterIds"] != DBNull.Value) { publishToTaobaoProductInfo.SkuOuterIds = (string)dataReader["SkuOuterIds"]; } if (dataReader["FoodAttributes"] != DBNull.Value) { publishToTaobaoProductInfo.FoodAttributes = (string)dataReader["FoodAttributes"]; } if (dataReader["TaobaoProductId"] != DBNull.Value) { publishToTaobaoProductInfo.TaobaoProductId = (long)dataReader["TaobaoProductId"]; } if (dataReader["ProductCode"] != DBNull.Value) { publishToTaobaoProductInfo.ProductCode = (string)dataReader["ProductCode"]; } if (dataReader["Description"] != DBNull.Value) { publishToTaobaoProductInfo.Description = (string)dataReader["Description"]; } if (dataReader["ImageUrl1"] != DBNull.Value) { publishToTaobaoProductInfo.ImageUrl1 = (string)dataReader["ImageUrl1"]; } if (dataReader["ImageUrl2"] != DBNull.Value) { publishToTaobaoProductInfo.ImageUrl2 = (string)dataReader["ImageUrl2"]; } if (dataReader["ImageUrl3"] != DBNull.Value) { publishToTaobaoProductInfo.ImageUrl3 = (string)dataReader["ImageUrl3"]; } if (dataReader["ImageUrl4"] != DBNull.Value) { publishToTaobaoProductInfo.ImageUrl4 = (string)dataReader["ImageUrl4"]; } if (dataReader["ImageUrl5"] != DBNull.Value) { publishToTaobaoProductInfo.ImageUrl5 = (string)dataReader["ImageUrl5"]; } publishToTaobaoProductInfo.SalePrice = (decimal)dataReader["SalePrice"]; if (dataReader["Weight"] != DBNull.Value) { publishToTaobaoProductInfo.Weight = (decimal)dataReader["Weight"]; } } } return(publishToTaobaoProductInfo); }
private void ProcessTaobaoProductDetails(HttpContext context) { string text = "http://" + HttpContext.Current.Request.Url.Host; int productId = int.Parse(context.Request.Form["productId"]); PublishToTaobaoProductInfo taobaoProduct = ProductHelper.GetTaobaoProduct(productId); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("{"); stringBuilder.AppendFormat("\"Cid\":\"{0}\",", taobaoProduct.Cid); stringBuilder.AppendFormat("\"StuffStatus\":\"{0}\",", taobaoProduct.StuffStatus); stringBuilder.AppendFormat("\"ProductId\":\"{0}\",", taobaoProduct.ProductId); stringBuilder.AppendFormat("\"ProTitle\":\"{0}\",", HttpUtility.UrlEncode(taobaoProduct.ProTitle)); stringBuilder.AppendFormat("\"Num\":\"{0}\",", taobaoProduct.Num); stringBuilder.AppendFormat("\"LocationState\":\"{0}\",", taobaoProduct.LocationState); stringBuilder.AppendFormat("\"LocationCity\":\"{0}\",", taobaoProduct.LocationCity); stringBuilder.AppendFormat("\"FreightPayer\":\"{0}\",", taobaoProduct.FreightPayer); stringBuilder.AppendFormat("\"PostFee\":\"{0}\",", taobaoProduct.PostFee.F2ToString("f2")); stringBuilder.AppendFormat("\"ExpressFee\":\"{0}\",", taobaoProduct.ExpressFee.F2ToString("f2")); stringBuilder.AppendFormat("\"EMSFee\":\"{0}\",", taobaoProduct.EMSFee.F2ToString("f2")); stringBuilder.AppendFormat("\"HasInvoice\":\"{0}\",", taobaoProduct.HasInvoice); stringBuilder.AppendFormat("\"HasWarranty\":\"{0}\",", taobaoProduct.HasWarranty); stringBuilder.AppendFormat("\"HasDiscount\":\"{0}\",", taobaoProduct.HasDiscount); stringBuilder.AppendFormat("\"ValidThru\":\"{0}\",", taobaoProduct.ValidThru); stringBuilder.AppendFormat("\"ListTime\":\"{0}\",", taobaoProduct.ListTime); stringBuilder.AppendFormat("\"PropertyAlias\":\"{0}\",", taobaoProduct.PropertyAlias); stringBuilder.AppendFormat("\"InputPids\":\"{0}\",", taobaoProduct.InputPids); stringBuilder.AppendFormat("\"InputStr\":\"{0}\",", taobaoProduct.InputStr); stringBuilder.AppendFormat("\"SkuProperties\":\"{0}\",", taobaoProduct.SkuProperties); stringBuilder.AppendFormat("\"SkuQuantities\":\"{0}\",", taobaoProduct.SkuQuantities); stringBuilder.AppendFormat("\"SkuPrices\":\"{0}\",", taobaoProduct.SkuPrices); stringBuilder.AppendFormat("\"SkuOuterIds\":\"{0}\",", taobaoProduct.SkuOuterIds); stringBuilder.AppendFormat("\"TaobaoProductId\":\"{0}\",", taobaoProduct.TaobaoProductId); stringBuilder.AppendFormat("\"ProductCode\":\"{0}\",", taobaoProduct.ProductCode); if (string.IsNullOrEmpty(taobaoProduct.Description)) { taobaoProduct.Description = "暂无描述信息"; } stringBuilder.AppendFormat("\"Description\":\"{0}\",", HttpUtility.UrlEncode(taobaoProduct.Description.Replace("src=\"/Storage/master/gallery", $"src=\"{text}/Storage/master/gallery").Replace('"', '“'))); string text2 = text + taobaoProduct.ImageUrl1; if (File.Exists(Globals.MapPath(taobaoProduct.ImageUrl1)) && (text2.EndsWith(".jpg", StringComparison.CurrentCultureIgnoreCase) || text2.EndsWith(".gif", StringComparison.CurrentCultureIgnoreCase) || text2.EndsWith(".png", StringComparison.CurrentCultureIgnoreCase) || text2.EndsWith(".jpeg", StringComparison.CurrentCultureIgnoreCase))) { stringBuilder.AppendFormat("\"ImageName1\":\"{0}\",", text2); } string text3 = text + taobaoProduct.ImageUrl2; if (File.Exists(Globals.MapPath(taobaoProduct.ImageUrl2)) && (text3.EndsWith(".jpg", StringComparison.CurrentCultureIgnoreCase) || text3.EndsWith(".gif", StringComparison.CurrentCultureIgnoreCase) || text3.EndsWith(".png", StringComparison.CurrentCultureIgnoreCase) || text3.EndsWith(".jpeg", StringComparison.CurrentCultureIgnoreCase))) { stringBuilder.AppendFormat("\"ImageName2\":\"{0}\",", text3); } string text4 = text + taobaoProduct.ImageUrl3; if (File.Exists(Globals.MapPath(taobaoProduct.ImageUrl3)) && (text4.EndsWith(".jpg", StringComparison.CurrentCultureIgnoreCase) || text4.EndsWith(".gif", StringComparison.CurrentCultureIgnoreCase) || text4.EndsWith(".png", StringComparison.CurrentCultureIgnoreCase) || text4.EndsWith(".jpeg", StringComparison.CurrentCultureIgnoreCase))) { stringBuilder.AppendFormat("\"ImageName3\":\"{0}\",", text4); } string text5 = text + taobaoProduct.ImageUrl4; if (File.Exists(Globals.MapPath(taobaoProduct.ImageUrl4)) && (text5.EndsWith(".jpg", StringComparison.CurrentCultureIgnoreCase) || text5.EndsWith(".gif", StringComparison.CurrentCultureIgnoreCase) || text5.EndsWith(".png", StringComparison.CurrentCultureIgnoreCase) || text5.EndsWith(".jpeg", StringComparison.CurrentCultureIgnoreCase))) { stringBuilder.AppendFormat("\"ImageName4\":\"{0}\",", text5); } string text6 = text + taobaoProduct.ImageUrl5; if (File.Exists(Globals.MapPath(taobaoProduct.ImageUrl5)) && (text6.EndsWith(".jpg", StringComparison.CurrentCultureIgnoreCase) || text6.EndsWith(".gif", StringComparison.CurrentCultureIgnoreCase) || text6.EndsWith(".png", StringComparison.CurrentCultureIgnoreCase) || text6.EndsWith(".jpeg", StringComparison.CurrentCultureIgnoreCase))) { stringBuilder.AppendFormat("\"ImageName5\":\"{0}\",", text6); } stringBuilder.AppendFormat("\"SalePrice\":\"{0}\",", taobaoProduct.SalePrice.F2ToString("f2")); stringBuilder.AppendFormat("\"FoodAttributes\":\"{0}\"", HttpUtility.UrlEncode(taobaoProduct.FoodAttributes)); stringBuilder.Append("}"); context.Response.Write(stringBuilder.ToString()); }