/// <summary> /// 修改商品信息 /// </summary> /// <param name="mcpd">商品实体类</param> /// <returns>数据库中受影响的行数</returns> public int UpdateProduct(McPdMaintain mcpd) { DBConnection dbc = new DBConnection(); string sqlString = @"UPDATE [shuaka].[dbo].[mc_PdMaintain] SET [mer_id] = @mer_id ,[pd_name] = @pd_name ,[pd_price] = @pd_price ,[pd_mem_price] = @pd_mem_price ,[pd_info] = @pd_info ,[pd_pic] = @pd_pic ,[pd_state] = @pd_state ,[pd_note] = @pd_note WHERE [pd_id]=@pd_id"; SqlParameter[] paras = { new SqlParameter("mer_id", mcpd.MerID), new SqlParameter("pd_name", mcpd.PdName), new SqlParameter("pd_price", mcpd.PdPrice), new SqlParameter("pd_mem_price", mcpd.PdMemPrice), new SqlParameter("pd_info", mcpd.PdInfo), new SqlParameter("pd_pic", mcpd.PdPic), new SqlParameter("pd_state", mcpd.PdState), new SqlParameter("pd_note", mcpd.PdNote), new SqlParameter("pd_id", mcpd.PdID) }; return(dbc.Execute(sqlString, paras)); }
/// <summary> /// 商家添加商品信息,返回商品ID /// </summary> /// <param name="mc">商品信息实体</param> /// <returns>商品ID</returns> public int AddPd(McPdMaintain mpm) { dbc = new DBConnection(); strSql = @"INSERT INTO [shuaka].[dbo].[mc_PdMaintain] ([mer_id] ,[pd_name] ,[pd_price] ,[pd_mem_price] ,[pd_info] ,[pd_pic] ,[pd_state] ,[pd_note]) VALUES (@MerID ,@PdName ,@PdPrice ,@PdMemPrice ,@PdInfo ,@PdPic ,@PdState ,@PdNote) SELECT @@IDENTITY AS 'pd_id'"; SqlParameter[] paras = { new SqlParameter("MerID", mpm.MerID), new SqlParameter("PdName", mpm.PdName), new SqlParameter("PdPrice", mpm.PdPrice), new SqlParameter("PdMemPrice", mpm.PdMemPrice), new SqlParameter("PdInfo", mpm.PdInfo), new SqlParameter("PdPic", mpm.PdPic), new SqlParameter("PdState", mpm.PdState), new SqlParameter("PdNote", mpm.PdNote) }; ds = dbc.GetDataSet(strSql, paras); string temp = ds.Tables[0].Rows[0]["pd_id"].ToString(); return(Convert.ToInt32(temp)); }
public void InitPage() { MerInfoMaintDAL func = new MerInfoMaintDAL(); int pro_id = int.Parse(Request.QueryString["pro_id"]); McPdMaintain mcpd = func.GetProductInfoByID(pro_id); ProdInfo_Name.Text = mcpd.PdName; ProdInfo_Price.Text = mcpd.PdPrice.ToString(); ProdInfo_DiscountPrice.Text = mcpd.PdMemPrice.ToString(); ProdMod_Introduce.Text = mcpd.PdInfo; ProdMod_Pic.Src = Request.ApplicationPath + "/" + mcpd.PdPic; ProdMod_Able.SelectedValue = mcpd.PdState == true ? "1" : "0"; ProdMod_Info.Text = mcpd.PdNote; }
protected void UploadBtn_Click(object sender, EventArgs e) { if (!(uploadF.Value == null || uploadF.Value.Equals(""))) { string path = uploadF.PostedFile.FileName; string fileExt = path.Substring(path.LastIndexOf('.') + 1); if (fileExt.ToLower().Equals("jpg") || fileExt.ToLower().Equals("png") || fileExt.ToLower().Equals("gif")) { string filePath = Server.MapPath("../../") + "/UpFiles/prd_pic"; string serverName = DateTime.Now.ToString("yyyyMMddHHmmss") + "." + fileExt; uploadF.PostedFile.SaveAs(filePath + "/" + serverName); McPdMaintain UPmcpd = new McPdMaintain(); MerInfoMaintDAL func = new MerInfoMaintDAL(); int pro_id = int.Parse(Request.QueryString["pro_id"]); McPdMaintain mcpd = func.GetProductInfoByID(pro_id); UPmcpd.PdID = pro_id; UPmcpd.MerID = mcpd.MerID; UPmcpd.PdPic = "UpFiles/prd_pic/" + serverName; UPmcpd.PdName = ProdInfo_Name.Text; UPmcpd.PdPrice = float.Parse(ProdInfo_Price.Text); UPmcpd.PdMemPrice = float.Parse(ProdInfo_DiscountPrice.Text); UPmcpd.PdInfo = ProdMod_Introduce.Text; UPmcpd.PdState = ProdMod_Able.SelectedValue.Equals("1") ? true : false; UPmcpd.PdNote = ProdMod_Info.Text; func.UpdateProduct(UPmcpd); ProdMod_Pic.Src = "UpFiles/prd_pic/" + serverName; } else { Response.Write("<script>alert('不被允许的文件格式');</script>"); } } else { Response.Write("<script>alert('没有文件');</script>"); } }
public void ProdMod_Submit_Click(object sender, EventArgs e) { McPdMaintain UPmcpd = new McPdMaintain(); MerInfoMaintDAL func = new MerInfoMaintDAL(); int pro_id = int.Parse(Request.QueryString["pro_id"]); McPdMaintain mcpd = func.GetProductInfoByID(pro_id); UPmcpd.PdID = pro_id; UPmcpd.MerID = mcpd.MerID; UPmcpd.PdPic = mcpd.PdPic; UPmcpd.PdName = ProdInfo_Name.Text; UPmcpd.PdPrice = float.Parse(ProdInfo_Price.Text); UPmcpd.PdMemPrice = float.Parse(ProdInfo_DiscountPrice.Text); UPmcpd.PdInfo = ProdMod_Introduce.Text; UPmcpd.PdState = ProdMod_Able.SelectedValue.Equals("1") ? true : false; UPmcpd.PdNote = ProdMod_Info.Text; func.UpdateProduct(UPmcpd); Response.Redirect("../MerShowInfoMaintain.aspx?mer_id=" + mcpd.MerID); }
/// <summary> /// 添加产品,返回产品的ID /// </summary> /// <param name="mcpd"></param> /// <returns></returns> public int AddProduct(McPdMaintain mcpd) { DBConnection dbc = new DBConnection(); string sqlString = @"INSERT INTO [shuaka].[dbo].[mc_PdMaintain] ([mer_id] ,[pd_name] ,[pd_price] ,[pd_mem_price] ,[pd_info] ,[pd_pic] ,[pd_state] ,[pd_note]) VALUES (@mer_id ,@pd_name ,@pd_price ,@pd_memprice ,@pd_info ,@pd_pic ,@pd_state ,@pd_note) SELECT @@IDENTITY as 'identity'"; SqlParameter[] paras = { new SqlParameter("mer_id", mcpd.MerID), new SqlParameter("pd_name", mcpd.PdName), new SqlParameter("pd_price", mcpd.PdPrice), new SqlParameter("pd_memprice", mcpd.PdMemPrice), new SqlParameter("pd_info", mcpd.PdInfo), new SqlParameter("pd_pic", mcpd.PdPic), new SqlParameter("pd_state", mcpd.PdState), new SqlParameter("pd_note", mcpd.PdNote) }; DataSet ds = dbc.GetDataSet(sqlString, paras); return(int.Parse(ds.Tables[0].Rows[0].ItemArray[0].ToString())); }
protected void AddPro_Submit_Click(object sender, EventArgs e) { int mer_id = int.Parse(Session["user_ID"].ToString()); int pageSize = 6; DAL.McManaDAL.MerInfoMaintDAL func = new DAL.McManaDAL.MerInfoMaintDAL(); McPdMaintain mcpd = new McPdMaintain(); mcpd.MerID = mer_id; mcpd.PdName = AddPro_Name.Text; mcpd.PdPrice = float.Parse(AddPro_Price.Text); mcpd.PdMemPrice = float.Parse(AddPro_MemPrice.Text); mcpd.PdInfo = AddPro_Intro.Text; mcpd.PdState = AddPro_State.SelectedValue.Equals("1") == true ? true : false; mcpd.PdNote = AddPro_Note.Text; if (uploadF.Value == null || uploadF.Equals("")) { mcpd.PdPic = ""; } else { string filename = uploadF.PostedFile.FileName; string fileExt = filename.Substring(filename.LastIndexOf('.') + 1); string newName = DateTime.Now.ToString("yyyyMMddHHmmss") + "." + fileExt; string uploadFolder = Server.MapPath("../../") + "/UpFiles" + "/prd_pic/" + newName; uploadF.PostedFile.SaveAs(uploadFolder); string databasePath = "UpFiles/prd_pic/" + newName; mcpd.PdPic = databasePath; } int pro_id = func.AddProduct(mcpd); int pageIndex = (func.ProductCountInMerchant(mer_id) / pageSize) + 1; Response.Redirect("../MerShowInfoMaintain.aspx?mer_id=" + mer_id + "&pro_id=" + pro_id + "&page_index=" + pageIndex); }
/// <summary> /// 根据商品ID获得商品详细信息 /// </summary> /// <param name="pro_id">商品ID</param> /// <returns>商品实体类</returns> public McPdMaintain GetProductInfoByID(int pro_id) { DBConnection dbc = new DBConnection(); String strString = @"SELECT [pd_id] ,[mer_id] ,[pd_name] ,[pd_price] ,[pd_mem_price] ,[pd_info] ,[pd_pic] ,case [pd_state] when 1 then '可用' else '不可用' end as pd_state ,[pd_note] FROM [shuaka].[dbo].[mc_PdMaintain] WHERE [pd_id]=@pro_id"; SqlParameter[] paras = { new SqlParameter("pro_id", pro_id) }; DataSet ds = dbc.GetDataSet(strString, paras); McPdMaintain mcpd = new McPdMaintain(); object[] itemArray = ds.Tables[0].Rows[0].ItemArray; mcpd.PdID = int.Parse(itemArray[0].ToString()); mcpd.MerID = int.Parse(itemArray[1].ToString()); mcpd.PdName = itemArray[2].ToString(); mcpd.PdPrice = float.Parse(itemArray[3].ToString()); mcpd.PdMemPrice = float.Parse(itemArray[4].ToString()); mcpd.PdInfo = itemArray[5].ToString(); mcpd.PdPic = itemArray[6].ToString(); mcpd.PdState = (itemArray[7].ToString().Equals("可用") == true); mcpd.PdNote = itemArray[8].ToString(); return(mcpd); }