ASP.net 网站开发知识点总结

news/2024/5/20 13:54:47/文章来源:https://blog.csdn.net/dianzhongqu2330/article/details/102050414

一、常用技术概括及介绍

1. SQL server:处理数据库的设计
2. asp.net 
3. html            :前端网页
4. css     :网页的布局设计
5. JavaScript  :能够更好的操作页面
6. jQuery        :
7. ajax    :处理局部刷新请求

二、分层介绍 (类库)
1.bll:业务层、
2.dal:数据层、
3.model:对应数据库的表、
4.common:公共方法
5.webapp:新建的app

6.webapp自带的配置文件

 

创建好之后如下:

三、实现步骤
1. 数据层中两个类,对应封装增删改查语句

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace CZBK.ItcastProject.DAL
{public class SqlHelper{//getdatetable方法获取整个表     //参数1.sql语句  2. 判断是sql语句还是存储过程 3. 传递的参数private static readonly string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;  //读取配置文件中的字符串public static DataTable GetDataTable(string sql,CommandType type,params SqlParameter[]pars){    using (SqlConnection conn = new SqlConnection(connStr)){   using (SqlDataAdapter apter = new SqlDataAdapter(sql, conn)){if (pars != null){apter.SelectCommand.Parameters.AddRange(pars);}apter.SelectCommand.CommandType = type;DataTable da = new DataTable();apter.Fill(da);return da;}}}//获取受影响行数,ExecuteNonQuery 主要用在插入,更新,删除 一般情况用在查询的时候返回的是-1 public static int ExecuteNonquery(string sql, CommandType type, params SqlParameter[] pars){
      
using (SqlConnection conn = new SqlConnection(connStr)){using (SqlCommand cmd = new SqlCommand(sql, conn)){if (pars != null){cmd.Parameters.AddRange(pars);}cmd.CommandType = type;conn.Open();return cmd.ExecuteNonQuery();}}}} }

 

  1 using CZBK.ItcastProject.Model;
  2 using System;
  3 using System.Collections.Generic;
  4 using System.Linq;
  5 using System.Text;
  6 using System.Threading.Tasks;
  7 using System.Data;
  8 using System.Data.SqlClient;
  9 namespace CZBK.ItcastProject.DAL
 10 {
 11     public class UserInfoDal
 12     {
 13         /// <summary>
 14         /// 获取用户列表
 15         /// </summary>
 16         /// <returns></returns>
 17         public List<UserInfo> GetList()
 18         {
 19             string sql = "select * from UserInfo";
 20             DataTable da = SqlHelper.GetDataTable(sql, CommandType.Text);
 21             List<UserInfo> list = null;
 22             if (da.Rows.Count > 0)
 23             {
 24                 list = new List<UserInfo>();
 25                 UserInfo userInfo = null;
 26                 foreach (DataRow row in da.Rows)
 27                 {
 28                     userInfo = new UserInfo();
 29                     LoadEntity(userInfo, row);
 30                     list.Add(userInfo);
 31                 }
 32             }
 33             return list;
 34         }
 35         /// <summary>
 36         /// 添加用户信息
 37         /// </summary>
 38         /// <param name="userInfo"></param>
 39         /// <returns></returns>
 40         public int AddUserInfo(UserInfo userInfo)
 41         {
 42             string sql = "insert into UserInfo(UserName,UserPass,RegTime,Email) values(@UserName,@UserPass,@RegTime,@Email)";
 43             SqlParameter[] pars = { 
 44                                 new SqlParameter("@UserName",SqlDbType.NVarChar,32),
 45                                   new SqlParameter("@UserPass",SqlDbType.NVarChar,32),
 46                                          new SqlParameter("@RegTime",SqlDbType.DateTime),
 47                                     new SqlParameter("@Email",SqlDbType.NVarChar,32)
 48                                 };
 49             pars[0].Value = userInfo.UserName;
 50             pars[1].Value = userInfo.UserPass;
 51             pars[2].Value = userInfo.RegTime;
 52             pars[3].Value = userInfo.Email;
 53             return SqlHelper.ExecuteNonquery(sql, CommandType.Text, pars);
 54         }
 55 
 56         /// <summary>
 57         /// 根据ID删除用户的信息
 58         /// </summary>
 59         /// <param name="id"></param>
 60         /// <returns></returns>
 61         public int DeleteUserInfo(int id)
 62         {
 63             string sql = "delete  from UserInfo where ID=@ID";
 64             SqlParameter[] pars = { 
 65                                   new SqlParameter("@ID",SqlDbType.Int)
 66                                   };
 67             pars[0].Value = id;
 68             return SqlHelper.ExecuteNonquery(sql,CommandType.Text,pars);
 69         }
 70 
 71         /// <summary>
 72         /// 修改用户信息
 73         /// </summary>
 74         /// <param name="userInfo"></param>
 75         /// <returns></returns>
 76         public int EditUserInfo(UserInfo userInfo)
 77         {
 78             string sql = "update UserInfo set UserName=@UserName,UserPass=@UserPass,RegTime=@RegTime,Email=@Email where ID=@ID";
 79             SqlParameter[] pars = { 
 80                                 new SqlParameter("@UserName",SqlDbType.NVarChar,32),
 81                                   new SqlParameter("@UserPass",SqlDbType.NVarChar,32),
 82                                          new SqlParameter("@RegTime",SqlDbType.DateTime),
 83                                     new SqlParameter("@Email",SqlDbType.NVarChar,32),
 84                                     new SqlParameter("@ID",SqlDbType.Int)
 85                                 };
 86             pars[0].Value = userInfo.UserName;
 87             pars[1].Value = userInfo.UserPass;
 88             pars[2].Value = userInfo.RegTime;
 89             pars[3].Value = userInfo.Email;
 90             pars[4].Value = userInfo.Id;
 91             return SqlHelper.ExecuteNonquery(sql, CommandType.Text, pars);
 92         }
 93 
 94         /// <summary>
 95         /// 根据用户的编号,获取用户的信息
 96         /// </summary>
 97         /// <param name="id"></param>
 98         /// <returns></returns>
 99         public UserInfo GetUserInfo(int id)
100         {
101             string sql = "select * from UserInfo where ID=@ID";
102             SqlParameter[] pars = { 
103                                   new SqlParameter("@ID",SqlDbType.Int)
104                                   };
105             pars[0].Value = id;
106             DataTable da=SqlHelper.GetDataTable(sql, CommandType.Text, pars);
107             UserInfo userInfo = null;
108             if (da.Rows.Count > 0)
109             {
110                 userInfo = new UserInfo();
111                 LoadEntity(userInfo, da.Rows[0]);
112             }
113             return userInfo;
114         }
115  
116 
117         private void LoadEntity(UserInfo userInfo, DataRow row)
118         {
119             userInfo.UserName = row["UserName"] != DBNull.Value ? row["UserName"].ToString() : string.Empty;
120             userInfo.UserPass = row["UserPass"] != DBNull.Value ? row["UserPass"].ToString() : string.Empty;
121             userInfo.Email = row["Email"] != DBNull.Value ? row["Email"].ToString() : string.Empty;
122             userInfo.Id = Convert.ToInt32(row["ID"]);
123             userInfo.RegTime = Convert.ToDateTime(row["RegTime"]);
124         }
125     }
126 }
具体增删改查部分

 model层中添加与列相同的表字段。示例代码如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace CZBK.ItcastProject.Model
{public class UserInfo{public int Id { get; set; }public string UserName { get; set; }public string UserPass { get; set; }public DateTime RegTime { get; set; }public string Email { get; set; }}
}

 


2. 业务层中写一个调用对象方法的方法

 1 using CZBK.ItcastProject.Model;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 using CZBK.ItcastProject.DAL;
 8 namespace CZBK.ItcastProject.BLL
 9 {
10    public class UserInfoService
11     {
12       UserInfoDal UserInfoDal = new UserInfoDal();
13        /// <summary>
14        /// 返回数据列表
15        /// </summary>
16        /// <returns></returns>
17        public List<UserInfo> GetList()
18        {
19            return UserInfoDal.GetList();
20        }
21        /// <summary>
22        /// 添加数据
23        /// </summary>
24        /// <param name="userInfo"></param>
25        /// <returns></returns>
26        public bool AddUserInfo(UserInfo userInfo)
27        {
28            return UserInfoDal.AddUserInfo(userInfo)>0;
29        }
30         /// <summary>
31         /// 根据ID删除用户的信息
32         /// </summary>
33         /// <param name="id"></param>
34         /// <returns></returns>
35        public bool DeleteUserInfo(int id)
36        {
37            return UserInfoDal.DeleteUserInfo(id) > 0;
38        }
39        /// <summary>
40        /// 修改用户信息
41        /// </summary>
42        /// <param name="userInfo"></param>
43        /// <returns></returns>
44        public bool EditUserInfo(UserInfo userInfo)
45        {
46            return UserInfoDal.EditUserInfo(userInfo) > 0;
47        }
48        /// <summary>
49         /// 根据用户的编号,获取用户的信息
50         /// </summary>
51         /// <param name="id"></param>
52         /// <returns></returns>
53        public UserInfo GetUserInfo(int id)
54        {
55            return UserInfoDal.GetUserInfo(id);
56        }
57         
58     }
59 }
UserInfoService

 


3. 新建一个html页面,

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title></title><link href="Css/tableStyle.css" rel="stylesheet" /><script src="Js/jquery-1.7.1.js"></script><script type="text/javascript">$(function () {$(".deletes").click(function () {if (!confirm("确定要删除吗?")) {return false;}});});</script>
</head><body><a href="AddUserInfo.html">添加</a><table><tr><th>编号</th><th>用户名</th><th>密码</th><th>邮箱</th><th>时间</th><th>删除</th><th>详细</th><th>编辑</th></tr>@tbody</table>
</body>
</html>
UserInfoList.html

 


4. 新建一个一般处理程序

using CZBK.ItcastProject.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;namespace CZBK.ItcastProject.WebApp
{/// <summary>/// UserInfoList 的摘要说明/// </summary>public class UserInfoList : IHttpHandler{public void ProcessRequest(HttpContext context){context.Response.ContentType = "text/html";//new一个业务层的类库对象BLL.UserInfoService UserInfoService = new BLL.UserInfoService();//调用获取全部列表的方法List<UserInfo> list= UserInfoService.GetList();//快捷操作字符串的方法StringBuilder sb = new StringBuilder();//将遍历到的数据拼接成一个新的字符串foreach (UserInfo userInfo in list){sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td><a href='DeleteUser.ashx?id={0}' class='deletes'>删除</a></td><td><a href='ShowDetail.ashx?uid={0}'>详细</a></td><td><a href='ShowEdit.ashx?id={0}'>编辑</a></td></tr>",userInfo.Id,userInfo.UserName,userInfo.UserPass,userInfo.Email,userInfo.RegTime);}//读取模板文件的路径string filePath = context.Request.MapPath("UserInfoList.html");//读取其中全部的字节string fileCotent = File.ReadAllText(filePath);//替换字符串fileCotent = fileCotent.Replace("@tbody",sb.ToString());context.Response.Write(fileCotent);}public bool IsReusable{get{return false;}}}
}
UserInfoList.ashx

 

转载于:https://www.cnblogs.com/wangjinya/p/10399136.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_903494.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SEO大事件:百度站长平台推出新站加速收录计划!

近日&#xff0c;在百度推出飓风算法&#xff0c;蝶变行动后&#xff0c;百度站长平台又悄然推出了一个小工具&#xff0c;对于中小站长可谓是大大的福音&#xff0c;很多刚刚从事SEO行业的小伙伴&#xff0c;经常发现向百度提交一个全新的网站&#xff0c;站点链接收录特别缓慢…

SEO价值匹配策略

在解释这个策略之前&#xff0c;我们首先要了解&#xff0c;什么是有价值的东西。100元对你也许很有价值&#xff0c;但是对于百万富翁来说&#xff0c;也许根本不值得一提&#xff1b;小米手机对你来说很有价值&#xff0c;但是对于苹果手机爱好者来说&#xff0c;小米要差很多…

SEO营销思维:名利借力策略

大部分人在生活中追求的无非就是名和利&#xff0c;我们在做网站SEO的时候&#xff0c;可以利用这点把自己的网站做得更好。很多人有这样的苦恼&#xff1a; 1、自己有产品&#xff0c;但是产品没有名气&#xff0c;不懂如何在互联网推广。 2、自己有名气&#xff0c;但是没有自…

从零开始学SEO的基础概念

SEO的意思是搜索引擎优化&#xff0c;它一般由两部分组成&#xff1a;站内优化和站外优化。站内优化主要是指通过网站技术、网站内容结构、域名、服务器和代码等操作&#xff0c;促使用户的网站能够在百度搜索引擎当中获得更好的排名&#xff1b;而站外优化可以理解为&#xff…

一个金融行业站SEO优化方案分析

前面写了两篇文章被大家评定为内容过于基础&#xff0c;建议添加一些实战案例。今天深圳seo就把自己的一个金融站的实战案例分享给大家。 网站目的&#xff1a;1、外币兑换业务  2、网站要有一定的流量 3、提升权重以便以后开展其它业务 策略&#xff1a;因为外币兑换与汇率…

抖音seo源码搭建 抖音矩阵系统具体功能展示?

抖音seo源码搭建&#xff0c;抖音矩阵系统&#xff1a; 抖音SEO和百度SEO、360SEO、搜狗SEO 其实就是换汤不换药&#xff0c;很多时候去了解这个SEO的时候&#xff0c;也不要去局限于它只是做抖音还是做小红书或知乎等。 我们不仅仅是去了解这个平台&#xff0c;同时更要去了解…

短视频seo源码账号矩阵程序开发搭建?短视频seo矩阵搜索技术

短视频seo源码账号矩阵程序开发搭建&#xff1f;短视频seo矩阵搜索技术 短视频seo源码账号矩阵程序开发搭建&#xff1f;短视频seo矩阵搜索技术如何部署&#xff1f; 首先什么是短视频搜索短视频SEO&#xff1f; 用户通过短视频平台在搜索框去做搜索的时候输入关键词&#xff…

抖音seo源码二次开发,短视频seo源码二次开发

抖音seo源码二次开发&#xff0c;短视频seo源码二次开发 抖音seo这套系统除了前端搭建&#xff0c;以及视频制作板块&#xff08;视频制作包括智能云剪辑、智能渲染去重&#xff0c;云端数字人&#xff09;&#xff0c;其他的功能板块视频定时发布&#xff0c;视频分发&#x…

抖音seo矩阵系统,抖音矩阵系统源码怎么搭建?

抖音seo矩阵系统&#xff0c;抖音矩阵系统源码怎么搭建&#xff1f; 抖音seo矩阵系统&#xff0c;抖音矩阵系统源码怎么搭建&#xff1f;抖音矩阵系统即是在抖音平台的基础上进行多账号的布局&#xff0c;形成客户不论搜索账号&#xff0c;视频以及关键词视频时&#xff0c;平…

介绍一下关于goodnotes,notability的手帐笔记素材的网站,含有A4大量的打印纸,电子手帐,贴图,便签,字体

官网:http://www.bishua666.com/a4做了ipad等等移动端的适配 1.提供各种A4打印纸模板,可以导出图片,pdf到打印机方便打印,打印纸类型有日程计划,练字书法,清单,财务,音乐,艾宾浩斯,康内尔 2.提供数百款GoodNotes和Notability等笔记类的应用类别手帐笔记模板pdf,pdf模板可以转图…

javascript跨域_您网站的Javascript跨域API

javascript跨域 Javascript cross-domain api for your website Welcome our readers. Today I would like to give a small but very important lesson where we will create our own cross-domain javascript api. I think that many of you have already tried to implement…

如何使用Akismet保护任何网站免受垃圾邮件的侵害

Akismet – spam protection. Today we will continue PHP lessons. And today we will talk about spam protection. I think every one have own website, and every one faced with appearing of unwanted content on the site (spam). What is spam? – this is (usually)…

通过phpstudy搭建简单的网站

1.简单一键构建&#xff1a;下载phpstudy&#xff0c;开启Apache2.4.39和MySQL5.7.26 选择软件管理--网站程序&#xff0c;选择自己想搭建的网站类型&#xff0c;点击一键部署&#xff0c;设置账户密码&#xff0c;搭建成功 2.如果中途报错&#xff0c;或者端口组冲突&#x…

linux宝塔新建站点

网上查了各种资料&#xff0c;绕了一大圈。有的说域名解析有问题&#xff0c;有的说端口问题&#xff0c;说的都是什么鬼东西啊。我特此在此记录下我自己找到的方法&#xff08;做个笔记&#xff09;。 首先新建立站点如图&#xff1a; 准备步骤&#xff1a;不管有没有域名你都…

分享一些省心的PPT模板下载网站资源(附5G优质PPT模板)

分享一些省心的PPT模板下载网站资源&#xff08;附5G优质PPT模板&#xff09; 每次需要做PPT时&#xff0c;总是为找省心的模板二发愁&#xff0c;用搜索引擎搜索“免费PPT模板”时&#xff0c;展示出的大量所谓“免费”的网站。心动的点开一个后&#xff0c;最终却是&#xf…

分享一些省心的PPT模板下载网站资源(附5G优质PPT模板)

每次需要做PPT时&#xff0c;总是为找省心的模板二发愁&#xff0c;用搜索引擎搜索“免费PPT模板”时&#xff0c;展示出的大量所谓“免费”的网站。心动的点开一个后&#xff0c;最终却是&#xff1a;开通会员才免费&#xff0c;满满的套路 现在我们急需那些&#xff0c;省去搜…

免费PPT模板网站

1、51PPT模板 网址&#xff1a;51pptmoban.com/ppt/ 界面&#xff1a; 下载过程&#xff1a; &#xff08;1&#xff09;点击想下载的模板 &#xff08;2&#xff09;页面向下拉&#xff0c;找到“下载地址” &#xff08;3&#xff09;点击“本地下载”&#xff0c;即可。 2…

免费简历模板网站

免费简历模板网站 1.个人简历网 https://www.gerenjianli.com/moban/ 2.超级简历 https://www.wondercv.com/jianlimoban/ 3.菜鸟图库 https://www.sucai999.com/search/word/0_242_0.html?vNTYxMjky

win2003升级到2012 64bitR2后网站报500错误

服务器从win2003升级到2012 64bitR2后网站开始报500错误 由于2012和原来的2003有很大的区别&#xff0c;很多地都不是很熟悉&#xff0c;后来通过在网上搜索加上自己琢磨算是解决了。现在把我的解决方式写一下&#xff0c;说不定能对遇到同样错误的产生帮助。 1、查阅出错原因…

网站第一次打开加载缓慢问题

需要先检测是否页面加载内容过大&#xff0c;再次检测是否数据库连接问题。。如果简单的页面第一次打开仍然较慢&#xff0c;需要检测应用程序池。应用程序池闲置超时默认为20分钟&#xff0c;如果20分钟之内无人点击&#xff0c;则应用程序池将终止&#xff0c;以便在下次访问…