/// <summary> /// 保存按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnsave_Click(object sender, EventArgs e) { int id = hftypeid.Value != null?int.Parse(hftypeid.Value) : 0; string name = txbtypename.Text; int orderby = txborderby.Text.Trim().Length == 0 ? 0 : int.Parse(txborderby.Text.Trim()); Model.Seller_categoryInfo model = new Model.Seller_categoryInfo(); model.id = id; model.name = name; model.parentid = int.Parse(ddlproducttype.SelectedValue); model.orderby = orderby; model.img = Common.Utils.ObjectToStr(Request["txbimg"]); // 图片 int result = 0; string resultMsg = ""; if (id > 0) { result = BLL.Seller_categoryBLL.Update(model); } else { result = BLL.Seller_categoryBLL.Insert(model, ref resultMsg); } if (result > 0) { Response.Redirect("seller_category.aspx"); } else { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MScript", "alert('提交失败!" + resultMsg.Replace("'", "").Replace("\r", "").Replace("\n", "") + "');", true); } }
/// <summary> /// 删除 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "del") { int id = Convert.ToInt32(e.CommandArgument); Model.Seller_categoryInfo info = BLL.Seller_categoryBLL.GetModel(id); if (info == null) { return; } string oldimg = info.img; int b = BLL.Seller_categoryBLL.Delete(id); if (b > 0) { if (oldimg != null && oldimg.Trim().Length > 0) { File.Delete(Server.MapPath(oldimg)); // 删除图片 } Repeater1bind(); } else { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), DateTime.Now.ToString(), "alert('删除失败!');", true); } } }
/// <summary> /// 绑定 /// </summary> private void bind() { ddlproducttypebind(); if (id > 0) { hftypeid.Value = id.ToString(); Model.Seller_categoryInfo info = BLL.Seller_categoryBLL.GetModel(id); txbtypename.Text = info.name; txborderby.Text = info.orderby.ToString(); imgview = info.img != null && info.img.Trim().Length > 0 ? "<img src=\"" + info.img + "\" height=\"100\" />" : ""; img = info.img != null && info.img.Trim().Length > 0 ? info.img : ""; try { ddlproducttype.SelectedValue = info.parentid.ToString(); } catch { } } else { txborderby.Text = "99"; } }