protected void GridView_MultiImage_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.ToLower() == "d") { int ImageID = Convert.ToInt32(e.CommandArgument); ProductImageModel model = new ProductImageModelBll().GetModel(ImageID); ProductMultiImageRule.DeleteMultiImage(model.LargeImage); ProductMultiImageRule.DeleteMultiImage(model.OriginImage); ProductMultiImageRule.DeleteMultiImage(model.SmallImage); new ProductImageModelBll().Delete(ImageID); BindMultiImageData(); } if (e.CommandName.ToLower() == "u") { int ImageID = Convert.ToInt32(e.CommandArgument); int ImageCount = GridView_MultiImage.Rows.Count; int Position = 0; for (int i = 0; i < ImageCount; i++) { if (ImageID == Convert.ToInt32(GridView_MultiImage.Rows[i].Cells[0].Text)) { Position = i; break; } } if (Position != 0) { new ProductImageModelBll().SwitchOrder(ImageID, Convert.ToInt32(GridView_MultiImage.Rows[Position - 1].Cells[0].Text)); } BindMultiImageData(); } if (e.CommandName.ToLower() == "l") { int ImageID = Convert.ToInt32(e.CommandArgument); int ImageCount = GridView_MultiImage.Rows.Count; int Position = 0; for (int i = 0; i < ImageCount; i++) { if (ImageID == Convert.ToInt32(GridView_MultiImage.Rows[i].Cells[0].Text)) { Position = i; break; } } if (Position != ImageCount) { new ProductImageModelBll().SwitchOrder(ImageID, Convert.ToInt32(GridView_MultiImage.Rows[Position + 1].Cells[0].Text)); } BindMultiImageData(); } }
private void BindMultiImageData() { DataTable multiImageDataTable = new ProductImageModelBll().GetList(ProductID).Tables[0]; foreach (DataRow row in multiImageDataTable.Rows) { row["smallimage"] = ProductMultiImageRule.GetMultiImageUrl(Convert.ToString(row["smallimage"])); row["largeimage"] = ProductMultiImageRule.GetMultiImageUrl(Convert.ToString(row["largeimage"])); row["originimage"] = ProductMultiImageRule.GetMultiImageUrl(Convert.ToString(row["originimage"])); } GridView_MultiImage.DataSource = multiImageDataTable; GridView_MultiImage.DataBind(); }
private static void AddProductMultiImage(int ProductID, string CatePath, string ImageRelativeURL) { string ImageFullURL = UrlPrefix + ImageRelativeURL; FileInfo ImageFile = DownloadImage(ImageFullURL); if (!ImageFile.Directory.Exists) { Directory.CreateDirectory(ImageFile.Directory.FullName); } string[] MultiImages; ProductMultiImageRule.SaveProductMultiImage(ProductID, CatePath, ImageFile, out MultiImages); ProductImageModel model = new ProductImageModel(); model.ImageId = CommDataHelper.GetNewSerialNum("pd"); model.ProductId = ProductID; model.LargeImage = MultiImages[1]; model.OriginImage = MultiImages[2]; model.SmallImage = MultiImages[0]; model.Title = String.Empty; imgBll.Add(model); }
private void SaveData() { string strErr = ""; if (this.txtProductName.Text == "") { strErr += "产品名称不能为空!\\n"; } if (!PageValidate.IsDecimal(txtTradePrice.Text)) { strErr += "市场价输入有误!\\n"; } if (!PageValidate.IsDecimal(txtMerchantPrice.Text)) { strErr += "销售价输入有误!\\n"; } if (!PageValidate.IsDecimal(txtReducePrice.Text)) { strErr += "直降价输入有误!\\n"; } if (!PageValidate.IsNumber(txtScore.Text)) { strErr += "商品积分输入有误!\\n"; } if (!PageValidate.IsDecimal(txtWeight.Text)) { strErr += "商品重量输入有误!\\n"; } if (this.txtKeywords.Text == "") { strErr += "关键词不能为空!\\n"; } if (this.TextBox_Brief.Text == "") { strErr += "商品简介不能为空!\\n"; } if (!PageValidate.IsNumber(drpStatus.SelectedValue)) { strErr += "商品状态选择有误!\\n"; } int TempNewsID = 0; if (!String.IsNullOrEmpty(txtNewsID.Text) && !int.TryParse(txtNewsID.Text, out TempNewsID)) { strErr += "关联资讯ID输入有误"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } ProductModel product = bll.GetModel(ProductID); product.ProductName = txtProductName.Text; product.ProductCode = txtProductCode.Text; product.CateId = Convert.ToInt32(txtCategoryID.Value); product.TradePrice = Convert.ToDecimal(txtTradePrice.Text); product.MerchantPrice = Convert.ToDecimal(txtMerchantPrice.Text); product.ReducePrice = Convert.ToDecimal(txtReducePrice.Text); product.Status = Convert.ToInt32(drpStatus.SelectedValue); product.Keywords = txtKeywords.Text; product.Brief = TextBox_Brief.Text; product.BrandID = Convert.ToInt32(DropDown_Brand.SelectedValue); product.Specifications = TextBox_Specification.Text; product.OfferSet = TextBox_OfferSet.Text; product.PackingList = TextBox_Packing.Text; product.AfterSaleService = TextBox_Service.Text; product.Weight = Convert.ToDecimal(txtWeight.Text); product.StockTip = GetStockTip(); product.RelateProducts = txtRelateProduct.Text.Replace(",", ","); product.ChangeTime = DateTime.Now; if (fulImage.FileName != String.Empty) { string[] MainImages; ProductMainImageRule.SaveProductMainImage(ProductID, product.CatePath, fulImage.PostedFile, out MainImages); product.SmallImage = MainImages[0]; product.MediumImage = MainImages[1]; product.LargeImage = MainImages[2]; } //更新检索属性 foreach (GridViewRow row in GridView_Parameter.Rows) { RadioButtonList ParameterValueList = ((RadioButtonList)row.Cells[0].FindControl("RadioList_ParameterValue")); if (!String.IsNullOrEmpty(ParameterValueList.SelectedValue)) { int ParameterID = Convert.ToInt32(((HiddenField)row.Cells[0].FindControl("Hidden_ParameterID")).Value); string ParameterValue = Convert.ToString(ParameterValueList.SelectedItem.Text); ProductParaModel para = new ProductParaModel(); para.ParaId = ParameterID; para.ProductId = product.ProductId; para.ParaValue = ParameterValue; pvBll.Save(para); } } //更新基本属性 foreach (GridViewRow row in GridView_Specification.Rows) { RadioButtonList ParameterValueList = ((RadioButtonList)row.Cells[0].FindControl("RadioList_SpecificationValue")); if (!String.IsNullOrEmpty(ParameterValueList.SelectedValue)) { int ParameterID = Convert.ToInt32(((HiddenField)row.Cells[0].FindControl("Hidden_SpecificationID")).Value); string ParameterValue = Convert.ToString(ParameterValueList.SelectedItem.Text); ProductParaModel para = new ProductParaModel(); para.ParaId = ParameterID; para.ProductId = product.ProductId; para.ParaValue = ParameterValue; pvBll.Save(para); } } //添加商品多图 foreach (string s in Request.Files.AllKeys) { if (s.StartsWith("multiImageUpload") && Request.Files[s].ContentLength > 0) { string[] FileNames; ProductMultiImageRule.SaveProductMultiImage(ProductID, product.CatePath, Request.Files[s], out FileNames); if (FileNames != null) { ProductImageModel model = new ProductImageModel(); model.ImageId = CommDataHelper.GetNewSerialNum("pd"); model.ProductId = ProductID; model.LargeImage = FileNames[1]; model.OriginImage = FileNames[2]; model.SmallImage = FileNames[0]; model.Title = String.Empty; new ProductImageModelBll().Add(model); } } } //更新关联资讯ID new ProductNewsBll().Save(new ProductNewsModel() { ProdutID = product.ProductId, NewsID = TempNewsID }); bll.Update(product); //重建索引 try { DataIndexerProduct SearchIndexer = new DataIndexerProduct(Config.Searches["product"]); SearchIndexer.DeleteSingleIndex(product.ProductId); SearchIndexer.CreateSingleIndex(new Search.Entities.ProductModel() { EntityIdentity = product.ProductId, CategoryID = product.CateId, CategoryPath = product.CatePath, CreateTime = product.InsertTime, Description = product.Brief, Keywords = product.Keywords, Price = product.MerchantPrice, ProcessType = NoName.NetShop.Search.Entities.EntityProcessType.insert, ProductImage = product.MediumImage, ProductName = product.ProductName, UpdateTime = product.ChangeTime }); } catch { } }
public XmlNode GetProductInfo() { XmlNode ProductInfoNode = xdoc.CreateElement("productinfo"); //产品信息节点 XmlNode ProductNode = XmlUtility.AddNewNode(ProductInfoNode, "product", null); DataTable dt = dal.GetProductInfo(Parameter.ProductID); if (dt == null || dt.Rows == null || dt.Rows.Count <= 0) { throw new PublishException("商品不存在"); } if (Convert.ToInt32(dt.Rows[0]["status"]) != 1) { throw new PublishException("商品已下架"); } DataRow row = dt.Rows[0]; XmlUtility.AddNewNode(ProductNode, "productid", Convert.ToString(row["ProductId"])); XmlUtility.AddNewNode(ProductNode, "productname", Convert.ToString(row["ProductName"])); XmlUtility.AddNewNode(ProductNode, "productcode", Convert.ToString(row["ProductCode"])); XmlUtility.AddNewNode(ProductNode, "categorypath", Convert.ToString(row["CatePath"])); XmlUtility.AddNewNode(ProductNode, "categoryid", Convert.ToString(row["CateId"])); XmlUtility.AddNewNode(ProductNode, "tradeprice", Convert.ToString(row["TradePrice"])); XmlUtility.AddNewNode(ProductNode, "merchantprice", Convert.ToString(row["MerchantPrice"])); XmlUtility.AddNewNode(ProductNode, "actualprice", Convert.ToString(Convert.ToDecimal(row["MerchantPrice"]) - Convert.ToDecimal(row["reduceprice"]))); XmlUtility.AddNewNode(ProductNode, "tradeprice", Convert.ToString(row["ReducePrice"])); XmlUtility.AddNewNode(ProductNode, "stock", Convert.ToString(row["Stock"])); XmlUtility.AddNewNode(ProductNode, "stocktip", Convert.ToString(row["stocktip"])); XmlUtility.AddNewNode(ProductNode, "smallimage", ProductMainImageRule.GetMainImageUrl(Convert.ToString(row["SmallImage"]))); XmlUtility.AddNewNode(ProductNode, "mediumimage", ProductMainImageRule.GetMainImageUrl(Convert.ToString(row["MediumImage"]))); XmlUtility.AddNewNode(ProductNode, "largeimage", ProductMainImageRule.GetMainImageUrl(Convert.ToString(row["LargeImage"]))); XmlUtility.AddNewNode(ProductNode, "keywords", Convert.ToString(row["Keywords"])); XmlUtility.AddCDataNode(ProductNode, "brief", Convert.ToString(row["Brief"])); XmlUtility.AddNewNode(ProductNode, "pageview", Convert.ToString(row["PageView"])); XmlUtility.AddNewNode(ProductNode, "inserttime", Convert.ToString(row["InsertTime"])); XmlUtility.AddNewNode(ProductNode, "changetime", Convert.ToString(row["ChangeTime"])); XmlUtility.AddNewNode(ProductNode, "score", Convert.ToString(row["Score"])); XmlUtility.AddCDataNode(ProductNode, "specifications", Convert.ToString(row["specifications"])); XmlUtility.AddCDataNode(ProductNode, "packinglist", Convert.ToString(row["packinglist"])); XmlUtility.AddCDataNode(ProductNode, "saleservice", Convert.ToString(row["aftersaleservice"])); XmlUtility.AddCDataNode(ProductNode, "offerset", Convert.ToString(row["offerset"])); XmlNode MultiImagesNode = XmlUtility.AddNewNode(ProductNode, "multiimages", null); XmlNode MainImageNode = XmlUtility.AddNewNode(MultiImagesNode, "image", null); XmlUtility.AddNewNode(MainImageNode, "smallimage", ProductMainImageRule.GetMainImageUrl(Convert.ToString(row["SmallImage"]))); XmlUtility.AddNewNode(MainImageNode, "largeimage", ProductMainImageRule.GetMainImageUrl(Convert.ToString(row["MediumImage"]))); XmlUtility.AddNewNode(MainImageNode, "originimage", ProductMainImageRule.GetMainImageUrl(Convert.ToString(row["LargeImage"]))); foreach (DataRow imageRow in dal.GetProductMultiImage(Parameter.ProductID).Rows) { XmlNode MultiImageNode = XmlUtility.AddNewNode(MultiImagesNode, "image", null); XmlUtility.AddNewNode(MultiImageNode, "smallimage", ProductMultiImageRule.GetMultiImageUrl(Convert.ToString(imageRow["smallimage"]))); XmlUtility.AddNewNode(MultiImageNode, "largeimage", ProductMultiImageRule.GetMultiImageUrl(Convert.ToString(imageRow["largeimage"]))); XmlUtility.AddNewNode(MultiImageNode, "originimage", ProductMultiImageRule.GetMultiImageUrl(Convert.ToString(imageRow["originimage"]))); } //相关产品节点 XmlNode RelatedProductNode = XmlUtility.AddNewNode(ProductInfoNode, "relatedproducts", null); DataTable RelatedProductTable = dal.GetRelatedProduct(dt.Rows[0]["relateproducts"].ToString()); if (RelatedProductTable.Rows.Count > 0) { foreach (DataRow RelatedProductRow in RelatedProductTable.Rows) { XmlNode RelatedProduct = XmlUtility.AddNewNode(RelatedProductNode, "product", null); XmlUtility.AddNewNode(RelatedProduct, "productid", Convert.ToString(RelatedProductRow["productid"])); XmlUtility.AddNewNode(RelatedProduct, "productimage", ProductMainImageRule.GetMainImageUrl(Convert.ToString(RelatedProductRow["smallimage"]))); XmlUtility.AddNewNode(RelatedProduct, "productname", Convert.ToString(RelatedProductRow["productname"])); XmlUtility.AddNewNode(RelatedProduct, "productnameshort", Convert.ToString(RelatedProductRow["productname"]).Length > 10 ? Convert.ToString(RelatedProductRow["productname"]).Substring(0, 10) + ".." : Convert.ToString(RelatedProductRow["productname"])); XmlUtility.AddNewNode(RelatedProduct, "price", Convert.ToDecimal(Convert.ToDecimal(RelatedProductRow["MerchantPrice"]) - Convert.ToDecimal(RelatedProductRow["reduceprice"])).ToString("00")); } } //关联资讯节点 XmlNode RelatedNewsNode = XmlUtility.AddNewNode(ProductInfoNode, "relatednews", null); DataTable RelatedNewsTable = dal.GetRelatedNewsInfo(Parameter.ProductID); if (RelatedNewsTable != null && RelatedNewsTable.Rows.Count > 0) { XmlNode NewsNode = XmlUtility.AddNewNode(RelatedNewsNode, "news", null); XmlUtility.AddNewNode(NewsNode, "newsid", RelatedNewsTable.Rows[0]["newsid"].ToString()); XmlUtility.AddNewNode(NewsNode, "newscontent", RelatedNewsTable.Rows[0]["newscontent"].ToString()); } return(ProductInfoNode); }