ASP.Net实现姓名添加查询(三层架构)

目录

演示功能:

点击启动生成页面

 点击搜索模糊查询

点击添加跳转新界面

点击Button添加姓名

步骤:

1、建文件

2、添加引用关系

3、根据数据库中的列写Models下的XueshengModels类

4、DAL下的DBHelper(对数据库进行操作)

5、DAL数据访问层下的service文件

6、BLL业务逻辑层下调用DAL的文件

7、ui表现层主界面前端部分

8、ui表现层主界面后端部分

9、ui表现层添加界面前端部分

10、ui表现层添加界面后端部分


演示功能:

点击启动生成页面

 点击搜索模糊查询

点击添加跳转新界面

点击Button添加姓名

步骤:

1、建文件

下图是三层架构列表,Models里面有模拟数据库中列的类,DAL中有DBHelper和service,BLL中有BllManager文件用于ui界面直接调用

2、添加引用关系

DAL引用Models文件,BLL引用DAL和Models文件,主文件WebApplication1引用Bll和Models

3、根据数据库中的列写Models下的XueshengModels类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace Models
{public   class XueshengModels{private string id;public string Id{get { return id; }set { id = value; }}private string name;public string Name{get { return name; }set { name = value; }}private string date;public string Date{get { return date; }set { date = value; }}}
}

4、DAL下的DBHelper(对数据库进行操作)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace DAL
{public    class DBHelper{public static string connstr = "server=.;database=Xuesheng;uid=sa;pwd=123123";public static SqlConnection conn = null;public static void Connect() {if (conn==null){conn = new SqlConnection(connstr);}conn.Close();conn.Open();}public static bool NoQuery(string sql) {Connect();SqlCommand cmd = new SqlCommand(sql,conn);int temp=   cmd.ExecuteNonQuery();return temp > 0;}public static SqlDataReader Reader(string sql){Connect();SqlCommand cmd = new SqlCommand(sql, conn);return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);}}
}

5、DAL数据访问层下的service文件


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace DAL
{public  class service{public static List<Models.XueshengModels> Cha() {List<Models.XueshengModels> list = new List<Models.XueshengModels>();string sql = "select * from Xuesheng";SqlDataReader read=   DBHelper.Reader(sql);while (read.Read()){Models.XueshengModels model=new Models.XueshengModels();model.Id = read["Id"].ToString();model.Name = read["Name"].ToString();model.Date = read["Date"].ToString();list.Add(model);}return list;}public static bool jia(string name) {string chuan = string.Format("insert xuesheng values('{0}',GETDATE())",name);if (DBHelper.NoQuery(chuan)){return true;}else{return false;}}public static List<Models.XueshengModels> sou(string soutext){List<Models.XueshengModels> list = new List<Models.XueshengModels>();string sql = string.Format("select * from xuesheng where Name like '%{0}%'",soutext);SqlDataReader read = DBHelper.Reader(sql);while (read.Read()){Models.XueshengModels model = new Models.XueshengModels();model.Id = read["Id"].ToString();model.Name = read["Name"].ToString();model.Date = read["Date"].ToString();list.Add(model);}return list;}}
}

6、BLL业务逻辑层下调用DAL的文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace BLL
{public   class BllManager{public static List<Models.XueshengModels> Cha() {return DAL.service.Cha();}public static bool jia(string name) {return DAL.service.jia(name);}public static List<Models.XueshengModels> sou(string soutext) {return DAL.service.sou(soutext);}}
}

7、ui表现层主界面前端部分

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title></title>
</head>
<body><form id="form1" runat="server"><div><a href="Tianjia.aspx"> 添加</a><br /><asp:Label ID="Label1" runat="server" Text=a"搜索"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="确定" />
<hr /><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"><Columns><asp:BoundField DataField="Id" FooterText="id" HeaderText="id" /><asp:BoundField DataField="Name" FooterText="name" HeaderText="name" /><asp:BoundField DataField="Date" FooterText="date" HeaderText="date" /></Columns></asp:GridView></div></form>
</body>
</html>

8、ui表现层主界面后端部分

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace WebApplication1
{public partial class WebForm1 : System.Web.UI.Page{public void Page_Load(object sender, EventArgs e){List<Models.XueshengModels> list=   BLL.BllManager.Cha();GridView1.DataSource = list;GridView1.DataBind();}protected void Button1_Click(object sender, EventArgs e){string soutex = TextBox1.Text;List<Models.XueshengModels> list = BLL.BllManager.sou(soutex);GridView1.DataSource = list;GridView1.DataBind();}}
}

9、ui表现层添加界面前端部分

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Tianjia.aspx.cs" Inherits="WebApplication1.Tianjia" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title></title>
</head>
<body><form id="form1" runat="server"><div><a href="WebForm1.aspx">添加</a><br /><asp:Label ID="Label1" runat="server" Text="添加"></asp:Label> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" style="height: 21px" /></div></form>
</body>
</html>

10、ui表现层添加界面后端部分

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace WebApplication1
{public partial class Tianjia : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void Button1_Click(object sender, EventArgs e){string text = TextBox1.Text.ToString();bool pd=BLL.BllManager.jia(text);if (pd){ClientScript.RegisterStartupScript(this.GetType(), "success", "alert('成功了!'),location.href='WebForm1.aspx'", true);}else{ClientScript.RegisterStartupScript(this.GetType(), "success", "alert('失败了!')", true);}}}
}

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

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

相关文章

深入理解 Union 和 Union All 的区别及优化技巧

嗨&#xff0c;大家好&#xff0c;欢迎来到程序猿漠然公众号&#xff0c;我是漠然。 今天&#xff0c;我将和大家一起深入探讨数据库查询中的两个常用操作&#xff1a;Union 和 Union All。这两个操作虽然看起来相似&#xff0c;但在使用时却有一些需要注意的地方。希望通过我…

python pyinstaller打包exe 踩的坑

1.包的引用要用相对路径。 例&#xff1a; 我的项目架构是 G: └── PPP └── pythonProject ├── main.py └── res └── load_file.py └── calculation_function.py └── keywords_config.json 原…

现代 CPU 技术发展

介绍 这篇文章主要是介绍CPU技术的发展&#xff0c;包括最近几十年CPU性能提升和半导体工艺发展&#xff0c;当前技术发展方向。希望可以帮助软件开发者理解CPU指令集和组成运行原理、CPU性能提升的现状和瓶颈、CPU技术发展方向会如何影响软件开发/设计的框架和编程思想。 提示…

Java开发相关的技术框架,前端框架,数据库

本人详解 作者:王文峰,参加过 CSDN 2020年度博客之星,《Java王大师王天师》 公众号:JAVA开发王大师,专注于天道酬勤的 Java 开发问题中国国学、传统文化和代码爱好者的程序人生,期待你的关注和支持!本人外号:神秘小峯 山峯 转载说明:务必注明来源(注明:作者:王文峰…

AI大模型 | llama2微调手册查看ing

提示词说明 <s>[INST] <<SYS>> {{ system_prompt }} <</SYS>>{{ user_message }} [/INST]其中&#xff0c; <s> &#xff0c;<\s>&#xff0c;<<SYS>>&#xff0c;<</SYS>>&#xff0c;[INST]&#xff0c…

为什么使用手持式定向天线套装

平时基站建设的时候信号干扰排查&#xff0c;干扰定位都是常规项目。当时这些都离不开定向天线。定向天线对比全向天线对于信号的测向更加准确。当时定向天线没有频率范围特别广的&#xff0c;这时候就体现出套装的重要性了。 天线套装组成 W3系列手持定向天线手柄&#xff1…

HTML---盒子模型

文章目录 前言一、pandas是什么&#xff1f;二、使用步骤 1.引入库2.读入数据总结 一.盒子模型概述 HTML中的盒子模型是一种用于描述和布局元素的概念。每个 HTML 元素都可以被表示为一个矩形的盒子&#xff0c;这个盒子包括四个部分&#xff1a;内容区域、内边距、边框和外边距…

《2023全球IPv6支持度白皮书》近日发布

近日&#xff0c;全球IPv6论坛联合中国的下一代互联网国家工程中心面向全球发布《2023全球IPv6支持度白皮书》。白皮书显示&#xff0c;在过去一年&#xff0c;全球IPv6支持度大幅提升&#xff0c;部署应用成效显著。全球IPv6部署率超过40%的国家数量同比增长了30%&#xff0c;…

【计算机系统结构实验】实验5 多核编程(OpenMP编程)

5.1 实验目的 加深对多核处理器架构的理解&#xff1b; 掌握使用OpenMP进行多线程编程的基本方法&#xff1b; 学习Windows和OpenEuler环境下多核编程的过程和time命令&#xff1b; 5.2 实验平台 需要多核处理器的计算机和微软编程工具Visual Studio 2012。Taishan服务器&…

互联网加竞赛 python图像检索系统设计与实现

0 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 &#x1f6a9; python图像检索系统设计与实现 &#x1f947;学长这里给一个题目综合评分(每项满分5分) 难度系数&#xff1a;3分工作量&#xff1a;3分创新点&#xff1a;4分 该项目较为新颖&#xff0c…

【WebRTC---源码篇】(十一:一)采集编码发送期间使用时间戳的详细解读

一、时间戳定义 1、 NTP时间 NtpTime RealTimeClock::CurrentNtpTime() //获取从1900-01-01 00:00.00到当前时刻经过的时间 int64_t RealTimeClock::CurrentNtpInMilliseconds() //获取从1900-01-01 00:00.00到当前时刻经过的毫秒数,ms int64_t rtc::TimeUTCMicros() //获取…

JDBC学习,从入门到入土

JDBC引入 JDBC概念&#xff1a; JDBC是使用Java语言操作关系型数据库的一套API。全称&#xff1a;&#xff08;Java DataBase Connectivity&#xff09;Java数据库连接 JDBC的本质&#xff1a; 官方定义的一套操作所有关系型数据库的规则&#xff0c;即接口。 各个数据库厂…

C# WPF上位机开发(业务主流程才是核心)

【 声明&#xff1a;版权所有&#xff0c;欢迎转载&#xff0c;请勿用于商业用途。 联系信箱&#xff1a;feixiaoxing 163.com】 前面我们说了很多的c# wpf编程技术&#xff0c;里面有控件&#xff0c;有绘图&#xff0c;有数据库&#xff0c;有多线程等技术。但是他们都属于实…

数据结构之进阶二叉树(二叉搜索树和AVL树、红黑树的实现)超详细解析,附实操图和搜索二叉树的实现过程图

绪论​ “生命有如铁砧&#xff0c;愈被敲打&#xff0c;愈能发出火花。——伽利略”&#xff1b;本章主要是数据结构 二叉树的进阶知识&#xff0c;若之前没学过二叉树建议看看这篇文章一篇掌握二叉树&#xff0c;本章的知识从浅到深的对搜索二叉树的使用进行了介绍和对其底层…

数据结构 | 查漏补缺

目录 数据的基本单位 冒泡排序 DFS和BFS中文 Prim 比较 中序线索二叉树 顺序栈 链栈 时间复杂度 循环队列 求第K个结点的值 数据的基本单位 数据元素 循环队列sq中&#xff0c;用数组elem[0‥25]存放数据元素&#xff0c;设当前sq->front为20&#xff0c;sq-&g…

MySQL——内置函数

目录 一.日期函数 1.current_date() 2.current_time() 3.current_stamp() 4.date_add() 5.date_sub() 6.datediff 7.date 8.now 二.字符串函数 1.charset() 2.concat() 3.length() 4.replace 5.substring(str,postion,length) 6.instr&#xff08;string,substr…

零代码助力服装行业数字化转型

内容来自演讲&#xff1a;涂岳俊 | 广州市衣湛国际信息科技有限公司 | CEO 摘要 这篇文章讨论了为什么选择明道云零代码平台&#xff0c;以及它如何帮助服装企业解决各种问题。作者分享了自己的经验&#xff0c;并列举了一些成功的案例来证明零代码平台的优势。文章还提到了在…

[Unity错误解决]There are 2 audio listeners in the scene.

There are 2 audio listeners in the scene. Please ensure there is always exactly one audio listener in the scene. 从组件中找出包含 Audio Listener 的&#xff0c;只激活一个&#xff0c;其他的关掉

【Amazon 实验①】使用Amazon WAF做基础 Web Service 防护

文章目录 一、实验介绍二、实验环境准备三、验证实验环境四、Web ACLs 配置 & AWS 托管规则4.1 Web ACLs 介绍4.2 Managed Rules 托管规则4.3 防护常见威胁类型&#xff08;sql注入&#xff0c;XSS&#xff09;4.4 实验步骤4.4.1 创建Web ACL4.4.2 测试用例4.4.3 测试结果4…

融资项目——vue之路由实现

通俗来说&#xff0c;路由就是锚点<a>的升级版。下面举一个例子来了解&#xff1a; <!DOCTYPE html> <html><head><meta charset"utf-8"><title></title></head><body><div id"list"><h1…