asp_增删查改(4)

来源:互联网 发布:2016中超网络直播权 编辑:程序博客网 时间:2024/05/24 11:14

Add.ashx:

 public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string title = context.Request["txttitle"];
            string people=context.Request["txtPeople"];


            try
            {
                BLL.HKSJ_Main mainServer = new BLL.HKSJ_Main();
                Model.HKSJ_Main main = new Model.HKSJ_Main();
                main.content = string.Empty;
                main.Date = DateTime.Now;
                main.picUrl = string.Empty;
                main.people = people;
                main.title = title;
                main.type = string.Empty;
                mainServer.Add(main);
                context.Response.Write("OK");
            }
            catch(Exception ex)
            {
                context.Response.Write("后台变态了。。。。");
            }
        }


Delete.ashx:

 public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int id = int.Parse(context.Request["id"]??"0");
            try
            {
                BLL.HKSJ_Main mainServer = new BLL.HKSJ_Main();
                mainServer.Delete(id);
                context.Response.Write("ok");
            }
            catch (Exception ex)
            {
                context.Response.Write("删除失败");
            }
        }


Edit.ashx:

 public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int id = int.Parse(context.Request["hidId"] ?? "0");
            string title = context.Request["txtEditTitle"];
            string people = context.Request["txtEditPeople"];
            try
            {
                BLL.HKSJ_Main mainServer = new BLL.HKSJ_Main();
                var editMain = mainServer.GetModel(id);
                editMain.people = people;
                editMain.title = title;
                if (mainServer.Update(editMain))
                {
                    context.Response.Write("OK");
                }
                else
                {
                    context.Response.Write("修改失败");
                }
            }
            catch (Exception ex)
            {
                context.Response.Write("异常");
            }
           
        }

原创粉丝点击