Ashx增删改查_动软

1.首先展示列表 ashx 讲究的是个替换 这些就是属于ashx麻烦的地方

 1   public void ProcessRequest(HttpContext context)
 2         {
 3             context.Response.ContentType = "text/html";
 4             BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
 5            List<UserInfo>list= UserInfoService.GetEntityList();
 6            // List<UserInfo>list=UserInfoService.GetEntityList();
 7             StringBuilder sb = new StringBuilder();
 8             foreach (UserInfo userInfo in list)
 9             {
10                 sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td><a href=‘ShowDetail.ashx?id={5}‘>详细</a></td><td>删除</td><td><a href=‘Edit.ashx?id={5}‘>修改</a></td></tr>", userInfo.ID, userInfo.UserName, userInfo.UserPass, userInfo.RegTime.ToShortDateString(), userInfo.Email, userInfo.ID);
11             }
12             string filePath = context.Request.MapPath("UserInfoList.html");
13             string fileContent = File.ReadAllText(filePath);
14            fileContent= fileContent.Replace("$tbody",sb.ToString());
15            context.Response.Write(fileContent);
16         }

修改

 1  public void ProcessRequest(HttpContext context)
 2         {
 3             context.Response.ContentType = "text/html";
 4             int id;
 5             if (int.TryParse(context.Request.QueryString["id"], out id))
 6             {
 7                 //1从Bll 里面获取数据
 8                 BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
 9
10                 UserInfo userInfo =UserInfoService.GetModel(id);
11                 //2创建文件名和文件路径
12                 string filePath = context.Request.MapPath("Edit.html");
13                 string fileContent = File.ReadAllText(filePath);
14                //3 再替换
15                fileContent= fileContent.Replace("$txtName",userInfo.UserName).Replace("$txtPwd",userInfo.UserPass).Replace("$txtEmail",userInfo.Email).Replace("$txtRegTime",userInfo.RegTime.ToString()).Replace("$txtId",userInfo.ID.ToString());
16                context.Response.Write(fileContent);
17             }
18         }

Edit.html类
1  <form method="post" action="ProcessEdit.ashx">
 2       <input type="hidden" name="txtId" value="$txtId" />
 3     <table>
 4         <tr><td>用户名</td><td><input type="text" name="txtName" value="$txtName" /></td></tr>
 5           <tr><td>密码</td><td><input type="text" name="txtPwd" value="$txtPwd" /></td></tr>
 6        <!--   <tr><td>邮箱</td><td><input type="text" name="txtEmail"  value="$txtEmail"/></td></tr>
 7            <tr><td>日期时间</td><td><input type="text" name="txtRegTime"  value="$txtRegTime"/></td></tr>-->
 8         <tr><td colspan="4"><input type="submit" value="修改用户" /></td></tr>
 9     </table>
10         </form>
ProcessEdit.ashx类

public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
          //  UserInfo userInfo = new UserInfo();
            //userInfo.UserName=context.Request.Form["txtName"];
            //userInfo.UserPass=context.Request.Form["txtPwd"];
            //userInfo.RegTime = Convert.ToDateTime(context.Request.Form["txtRegTime"]);
            //userInfo.Email=context.Request.Form["txtEmail"];
            int id=Convert.ToInt32(context.Request.Form["txtId"]);
            BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
            UserInfo userInfo=UserInfoService.GetModel(id);//查询一下,然后再修改,
            userInfo.UserName = context.Request.Form["txtName"];
            userInfo.UserPass = context.Request.Form["txtPwd"];
            if (UserInfoService.UpdateEntity(userInfo))
            {
                context.Response.Redirect("UserInfoList.ashx");
            }
            else
            {
                context.Response.Write("修改失败");
            }

        }

展示

 1   public void ProcessRequest(HttpContext context)
 2         {
 3             context.Response.ContentType = "text/html";
 4             int id;
 5             if (int.TryParse(context.Request.QueryString["id"], out id))
 6             {
 7                 BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
 8                 UserInfo userInfo=UserInfoService.GetModel(id);
 9                 string filePath = context.Request.MapPath("ShowDetail.html");
10                 string fileContent = File.ReadAllText(filePath);
11                 fileContent = fileContent.Replace("$name", userInfo.UserName).Replace("$pwd",userInfo.UserPass);
12                 context.Response.Write(fileContent);
13             }
14         }
<table>
        <tr><td>用户名</td><td>$name</td></tr>
            <tr><td>密码</td><td>$pwd</td></tr>
    </table>
时间: 2024-08-04 07:46:35

Ashx增删改查_动软的相关文章

赵雅智_使用SQLiteDatabase提供的增删改查方法及事务

知识点详解:http://blog.csdn.net/zhaoyazhi2129/article/details/9026093 MainActivity.java,User.java,BaseDao.java,UserDao.java同上篇 http://blog.csdn.net/zhaoyazhi2129/article/details/28640195 UserDaoImple.java package com.example.android_sqlite.dao.impl; impor

网络公开课_我理解的Oracle增删改查与你不同

您好, Beijing Shennao 邀请您出席使用 WebEx 的网络研讨会. 主题:网络公开课_我理解的Oracle增删改查与你不同 主持人:Beijing Shennao 日期与时间: 2014年7月18日 19:30, 中国时间(北京,GMT+08:00) 活动密码:321321 ------------------------------------------------------- 要加入该在线活动 ---------------------------------------

链表的基本操作之_增删改查

<span style="font-size:32px;"><strong style="background-color: rgb(51, 255, 51);">链表的基本操作之_增删改查</strong></span> #include<stdio.h> #include<string.h> #include<stdlib.h> typedef struct Node { int

论坛模块_版块管理_增删改查&amp;实现上下移动

论坛模块_版块管理1_增删改查 设计实体Forum.java public class Forum { private Long id; private String name; private String Description; private int position; //排序用的位置号 public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getNam

Hibernate入门_增删改查

一.Hibernate入门案例剖析:  ①创建实体类Student 并重写toString方法 public class Student { private Integer sid; private Integer age; private String name; public Integer getSid() { return sid; } public void setSid(Integer sid) { this.sid = sid; } public Integer getAge()

通用DAO之MyBatis封装,封装通用的增删改查(二)

曾经发过一篇文章,大概写的就是阿海多么多么厉害,见到某位同事在Hibernate的基础上封装了一下,就以一己之力开发什么什么框架,最后写了个超大的一坨的事. 那么,后续篇来了.阿海不是自负之人,当之前的CRUD框架并没有达到理想的结果时,阿海转向了Mybatis封装.别问我为什么不是Hibernate.我本来就不喜欢Hibernate,即使在之前的一家公司一直被强制性的约束使用Hibernate时,也没有对Hibernate产生什么真正的好感,反而屡次发现了Hibernate的一些问题. 或许是

Python 模拟SQL对文件进行增删改查

1 #!/usr/bin/env python 2 # _*_ coding:UTF-8 _*_ 3 # __auth__: Dalhhin 4 # Python 3.5.2,Pycharm 2016.3.2 5 # 2017/05/15 6 7 import sys,os 8 9 def where(dbfile,where_list): #条件是一个list 10 11 def and_or_where(sub_where_list): 12 '''获取and或同时含有and.or关键字的条

javascript生成表格增删改查 JavaScript动态改变表格单元格内容 动态生成表格 JS获取表格任意单元格 javascript如何动态删除表格某一行

jsp页面表格布局Html代码 <body > <center> <input type="text" value="111" id="mytext"> <table border="1" width="60%" id="mytable"> <tr> <td id="td1">第一行第一列<

beego增删改查代码实现

记录下使用beego的增删改查实现,数据库使用mysql,完整代码如下: package main import ( _ "crud_beego/routers" //自动注册路由 "fmt" "github.com/astaxie/beego" "github.com/astaxie/beego/orm" _ "github.com/go-sql-driver/mysql" ) const ( DRIVE