02Del.ashx(删除班级)
using System; using System.Collections.Generic; using System.Linq; using System.Web; using WebHelper; namespace AspxWebForm { /// <summary> /// 删除班级 /// </summary> public class _02Del : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; //1.获取浏览器get传递过来的要删除的班级id string strId = context.Request.QueryString["id"]; //2.验证id是否是数值 if (CommonHelper.IsNum(strId))//验证通过 { //3.删除对应的班级数据 if (new BLL.Classes().UpdateDel(strId)) { //删除成功 CommonHelper.WriteJs("删除成功~!", "01ClassesList.aspx"); } else { //删除失败 CommonHelper.WriteJs("删除失败~!如果您是美女,请联系管理员~~~qq:111111", "01ClassesList.aspx"); } } else {//4.验证失败 //通过输出js 先让浏览器用户看到错误消息,然后再直接通过js控制浏览器跳转到 列表页面(再次请求服务器的列表页面) context.Response.Write("<script>alert('您的参数有误!您什么意思~~!');window.location='01ClassesList.aspx';</script>"); } } public bool IsReusable { get { return false; } } } }
BLL
using System; using System.Collections.Generic; using System.Text; namespace BLL { /// <summary> /// 作者: liuhaitao /// 描述: 业务层 -- Classes表的业务操作类. /// 时间:2013/2/4 9:35:00 /// </summary> public class Classes { private readonly DAL.Classes dal = new DAL.Classes(); #region 04.软删除+ int UpdateDel(string ids) /// <summary> /// 软删除(将删除标志设置为true) /// </summary> 通常情况下: 0代表false,1代表true /// <param name="ids">要软删除的 id们</param> /// <returns>软删除成功与否</returns> public bool UpdateDel(string ids) { return dal.UpdateDel(ids, true) > 0; } #endregion #region 05.物理删除 +int Del(string ids) /// <summary> /// 物理删除(将删除标志设置为true) /// </summary> /// <param name="ids">要删除的 id们</param> /// <returns>删除成功与否</returns> public bool Del(string ids) { return dal.Del(ids) > 0; } #endregion
}
}
DAL
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; namespace DAL { /// <summary> /// Author: JamesZou /// Description: 数据层 -- Classes的实体类. /// 创建时间:2013/2/4 9:33:40 /// </summary> public class Classes { #region 01.修改软删除标志 /// <summary> /// 修改软删除标志 /// </summary> /// <param name="ids">要修改软删除标志的id号们(1,2,5)</param> /// <param name="isDel">要将删除标志 改成 true/false</param> /// <returns>受影响行数</returns> public int UpdateDel(string ids, bool isDel) { StringBuilder strSql = new StringBuilder(); strSql.Append("exec('update Classes set CIsDel=''" + isDel.ToString() + "'' where CID in ('+@ids+')')"); SqlParameter para = new SqlParameter("@ids", ids); return DbHelperSQL.ExcuteNonQuery(strSql.ToString(), para); } #endregion #region 01.2单个修改软删除标志 /// <summary> /// 单个修改软删除标志 /// </summary> /// <param name="idInt">要修改软删除标志的id号</param> /// <param name="isDel">要将删除标志 改成 true/false</param> /// <returns>受影响行数</returns> public int UpdateDel(int idInt, bool isDel) { string strSql = "update Classes set CIsDel='" + isDel.ToString() + "' where CID = @id"; SqlParameter para = new SqlParameter("@id", idInt); return DbHelperSQL.ExcuteNonQuery(strSql, para); } #endregion #region 02.执行物理删除 +int Del(string ids) /// <summary> /// 执行物理删除 /// </summary> /// <param name="ids">要删除的id号们(1,2,5)</param> /// <returns>受影响行数</returns> public int Del(string ids) { StringBuilder strSql = new StringBuilder(); strSql.Append("exec('delete Classes where CID in ('+@ids+')')"); SqlParameter para = new SqlParameter("@ids", ids); return DbHelperSQL.ExcuteNonQuery(strSql.ToString(), para); } #endregion #region 02.2单个物理删除 /// <summary> /// 单个物理删除 /// </summary> /// <param name="idInt">要删除的id号</param> /// <returns>受影响行数</returns> public int Del(int idInt) { string strSql = "delete Classes where CID = @id"; SqlParameter para = new SqlParameter("@id", idInt); return DbHelperSQL.ExcuteNonQuery(strSql, para); } #endregion
}
}