protected void btnSave_Click(object sender, EventArgs e) { Cms.Model.ProductInfo model = new Cms.Model.ProductInfo(); string strErr = ""; if (!PageValidate.IsDateTime(txtPubTime.Text)) { strErr += "发布时间格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } if (this.ddlTypeId.SelectedValue == "") { MessageBox.Show(this, "请选择商品类型!"); return; } if (this.ddlBrandId.SelectedValue == "") { MessageBox.Show(this, "请选择商品品牌!"); return; } if (this.ddlNameId.SelectedValue == "") { MessageBox.Show(this, "请选择商品名称!"); return; } Cms.DAL.ProductInfo dal = new Cms.DAL.ProductInfo(); model.Specifications = txtSpec.Text.Trim(); model.ImgUrl = txtImgUrl.Text.Trim(); model.SmallImgUrl = txtImgUrl.Text.Trim(); model.Description = Cms.Common.Utils.ToHtml(ProductDetail.Text); model.Click = int.Parse(txtClick.Text.Trim()); model.PubTime = DateTime.Parse(txtPubTime.Text); model.IsTop = 0; if (cblItem.Items[0].Selected == true) { model.IsTop = 1; } model.TypeId = int.Parse(this.ddlTypeId.SelectedValue.Trim()); model.BrandId = int.Parse(this.ddlBrandId.SelectedValue.Trim()); model.NameId = int.Parse(this.ddlNameId.SelectedValue.Trim()); int ReId = dal.Add(model); if (ReId > 0) { MessageBox.Show(this, "产品型号信息添加成功!"); //Coolite.Ext.Web.Ext.MessageBox.Alert("提示", "产品型号信息修改成功").Show(); } else { MessageBox.Show(this, "添加过程中发生错误!"); //Coolite.Ext.Web.Ext.MessageBox.Alert("提示", "发布过程中发生错误").Show(); } }
protected void lbtnImport_Click(object sender, EventArgs e) { string fullPath = HttpContext.Current.Server.MapPath(importFilePath.Text); if (!File.Exists(fullPath)) { //保存日志 MessageBox.Show(this, "请上传导入文件!"); return; } DataSet ds = ExcelToDS( fullPath ); DataTable tb = ds.Tables[0]; if (tb.Rows.Count > 0) { Cms.DAL.Channel dal = new Cms.DAL.Channel(); Cms.DAL.ProductInfo proDAL = new Cms.DAL.ProductInfo(); for (int i = 0; i < tb.Rows.Count; i++) { DataRow proRow = tb.Rows[i]; string type = proRow["商品类型"].ToString(); string brand = proRow["商品品牌"].ToString(); string name = proRow["商品名称"].ToString(); string spec = proRow["商品型号"].ToString(); int procNum = int.Parse(proRow["数量"].ToString()); int typeID = dal.GetProductTypeID(type); if (typeID == -1) typeID = dal.AddProductType(type); int brandID = dal.GetProductBrandID(brand, typeID); if (brandID == -1) brandID = dal.AddProductBrand(brand, typeID); int nameID = dal.GetProductNameID(name, typeID, brandID); if (nameID == -1) nameID = dal.AddProductName(name, typeID, brandID); int specID = 0; if (!proDAL.Exists(spec, typeID, brandID, nameID)) { Cms.Model.ProductInfo model = new Cms.Model.ProductInfo(); model.Specifications = spec; model.ImgUrl = ""; model.SmallImgUrl = ""; model.Description = ""; model.Click = 0; model.PubTime = DateTime.Now; model.IsTop = 0; model.TypeId = typeID; model.BrandId = brandID; model.NameId = nameID; specID = proDAL.Add(model); } if (specID > 0) { proDAL.AddStock(typeID, brandID, nameID, specID, procNum, procNum); } } } File.Delete( fullPath ); //保存日志 MessageBox.Show(this, "数据导入成功!"); }
protected void btnSave_Click(object sender, EventArgs e) { Cms.Model.ProductInfo model = new Cms.Model.ProductInfo(); string strErr = ""; if (!PageValidate.IsDateTime(txtPubTime.Text)) { strErr += "发布时间格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } if (this.ddlTypeId.SelectedValue == "") { MessageBox.Show(this, "请选择商品类型!"); return; } if (this.ddlBrandId.SelectedValue == "") { MessageBox.Show(this, "请选择商品品牌!"); return; } if (this.ddlNameId.SelectedValue == "") { MessageBox.Show(this, "请选择商品名称!"); return; } Cms.DAL.ProductInfo dal = new Cms.DAL.ProductInfo(); model.Specifications = txtSpec.Text.Trim(); model.ImgUrl = txtImgUrl.Text.Trim(); model.SmallImgUrl = txtImgUrl.Text.Trim(); model.Description = Cms.Common.Utils.ToHtml(ProductDetail.Text); model.Click = int.Parse(txtClick.Text.Trim()); model.PubTime = DateTime.Parse(txtPubTime.Text); model.IsTop = 0; if (cblItem.Items[0].Selected == true) { model.IsTop = 1; } model.TypeId = int.Parse(this.ddlTypeId.SelectedValue.Trim()); model.BrandId = int.Parse(this.ddlBrandId.SelectedValue.Trim()); model.NameId = int.Parse(this.ddlNameId.SelectedValue.Trim()); int ReId = dal.Add(model); if (ReId > 0) { MessageBox.Show(this, "产品型号信息添加成功!"); //Coolite.Ext.Web.Ext.MessageBox.Alert("提示", "产品型号信息修改成功").Show(); } else { MessageBox.Show(this, "添加过程中发生错误!"); //Coolite.Ext.Web.Ext.MessageBox.Alert("提示", "发布过程中发生错误").Show(); } }
protected void lbtnImport_Click(object sender, EventArgs e) { string fullPath = HttpContext.Current.Server.MapPath(importFilePath.Text); if (!File.Exists(fullPath)) { //保存日志 MessageBox.Show(this, "请上传导入文件!"); return; } DataSet ds = ExcelToDS(fullPath); DataTable tb = ds.Tables[0]; if (tb.Rows.Count > 0) { Cms.DAL.Channel dal = new Cms.DAL.Channel(); Cms.DAL.ProductInfo proDAL = new Cms.DAL.ProductInfo(); for (int i = 0; i < tb.Rows.Count; i++) { DataRow proRow = tb.Rows[i]; string type = proRow["商品类型"].ToString(); string brand = proRow["商品品牌"].ToString(); string name = proRow["商品名称"].ToString(); string spec = proRow["商品型号"].ToString(); int procNum = int.Parse(proRow["数量"].ToString()); int typeID = dal.GetProductTypeID(type); if (typeID == -1) { typeID = dal.AddProductType(type); } int brandID = dal.GetProductBrandID(brand, typeID); if (brandID == -1) { brandID = dal.AddProductBrand(brand, typeID); } int nameID = dal.GetProductNameID(name, typeID, brandID); if (nameID == -1) { nameID = dal.AddProductName(name, typeID, brandID); } int specID = 0; if (!proDAL.Exists(spec, typeID, brandID, nameID)) { Cms.Model.ProductInfo model = new Cms.Model.ProductInfo(); model.Specifications = spec; model.ImgUrl = ""; model.SmallImgUrl = ""; model.Description = ""; model.Click = 0; model.PubTime = DateTime.Now; model.IsTop = 0; model.TypeId = typeID; model.BrandId = brandID; model.NameId = nameID; specID = proDAL.Add(model); } if (specID > 0) { proDAL.AddStock(typeID, brandID, nameID, specID, procNum, procNum); } } } File.Delete(fullPath); //保存日志 MessageBox.Show(this, "数据导入成功!"); }