登陆页面



登陆页面的页面结构比较简单,没有写样式。

image标签的作用是用来显示验证码。



一般处理程序代码展示

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.SessionState; namespace EF_lainxi.BLL
{
/// <summary>
/// Handler1 的摘要说明
/// </summary>
public class Handler1 : IHttpHandler, IRequiresSessionState
{ public void ProcessRequest(HttpContext context)
{
//颜色的集合
Color[] colors = { Color.White };
Image img = new Bitmap(100, 30);
Graphics graphics = Graphics.FromImage(img);
Random random = new Random(DateTime.Now.Millisecond);
int charNum1 = random.Next(97, 122);
int charNum2 = random.Next(97, 122);
int charNum3 = random.Next(97, 122);
int charNum4 = random.Next(97, 122);
string validCode = string.Format($"{(char)charNum1}{(char)charNum2}{(char)charNum3}{(char)charNum4}");
context.Session["yzm"] = validCode;
Font font = new Font("宋体", 24);
Brush brush1 = new SolidBrush(colors[random.Next(0, colors.Length - 1)]);
graphics.DrawString(((char)charNum1).ToString(), font, brush1, 7, -3);
Brush brush2 = new SolidBrush(colors[random.Next(0, colors.Length - 1)]);
graphics.DrawString(((char)charNum2).ToString(), font, brush2, 26, -9);
Brush brush3 = new SolidBrush(colors[random.Next(0, colors.Length - 1)]);
graphics.DrawString(((char)charNum3).ToString(), font, brush3, 50, 0);
Brush brush4 = new SolidBrush(colors[random.Next(0, colors.Length - 1)]);
graphics.DrawString(((char)charNum4).ToString(), font, brush4, 70, -7);
context.Response.ContentType = "image/jpeg";
img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
graphics.Dispose();
img.Dispose();
} public bool IsReusable
{
get
{
return false;
}
}
}
}

一般处理程序中用来创建一个验证码的图片显示到页面的image里。

页面成品展示



登陆页面代码展示

using EF_lainxi.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace EF_lainxi
{
public partial class DeptDetail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{
string yzm= Session["yzm"].ToString();
if (yzm==TextBox3.Text)
{
if (TextBox1.Text!=null&&TextBox1.Text!=""&&TextBox2.Text!=null&&TextBox2.Text!="")
{
//数据库的名字
using (Model2 db=new Model2())
{
var name = db.Users.FirstOrDefault(s => s.Name == TextBox1.Text);
if (name.Pwd==TextBox2.Text)
{
//跳转到显示界面
Response.Redirect("xians.aspx");
}
else
{
string strUrl = "<script>alert('账号或密码错误');</script>";
Response.Write(strUrl);
}
} }
else
{
string strUrl = "<script>alert('账号或密码不能为空');</script>";
Response.Write(strUrl);
}
}
else
{
string strUrl = "<script>alert('验证码不正确');</script>";
Response.Write(strUrl);
}
}
}
}

主要作用是进行了验证码的判断、账号密码的正确与否,成功跳转显示界面,错误进行提示。

显示页面页面代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="xians.aspx.cs" Inherits="EF_lainxi.xians" %>

<!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>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> </head>
<body>
<form id="form1" runat="server">
<div>
<div>
图书名称: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" Text="查询" CssClass="btn btn-link" OnClick="Button1_Click" /></div>
<div>
<table class="table">
<thead>
<tr>
<th scope="col">图书编号</th>
<th scope="col">图书名称</th>
<th scope="col">图书价格</th>
<th scope="col">作者</th>
<th scope="col">类型</th>
<th scope="col">图片</th>
<th scope="col">上架时间</th>
<th scope="col">操作</th>
</tr>
</thead>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<tbody>
<tr>
<th scope="row"><%# Eval("BookId") %></th>
<td><%# Eval("BookName") %></td>
<td><%# Eval("Price") %></td>
<td><%# Eval("BookAuthor") %></td>
<td><%# Eval("TypeId.TyoeName") %></td>
<td>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "~/images/"+ Eval("Img") %>' Width="60" Height="60" /></td>
<td><%# Eval("Addtime") %></td>
<td>
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("BookId") %>' CommandName="delete" OnClientClick="return confirm('确定删除吗?')">删除</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandArgument='<%# Eval("BookId") %>' CommandName="xainq">详情</asp:LinkButton> </td>
</tr>
</tbody>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
</div> </form>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> </body>
</html>

显示页面后台代码

using EF_lainxi.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace EF_lainxi
{
public partial class xians : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
select();
}
} private void select()
{
using (Model2 db = new Model2())
{
var list = db.BookInfos.ToList();
Repeater1.DataSource = list;
Repeater1.DataBind();
}
} protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
string pand= e.CommandName;
int id = Convert.ToInt32(e.CommandArgument);
if (pand== "delete")
{
using (Model2 db = new Model2())
{
var sc= db.BookInfos.FirstOrDefault(s => s.BookId == id);
db.BookInfos.Remove(sc);
db.SaveChanges();
select();
}
} } protected void Button1_Click(object sender, EventArgs e)
{
using (Model2 db = new Model2())
{
Repeater1.DataSource = db.BookInfos.Where(p => p.BookName.Contains(TextBox1.Text)).ToList();
Repeater1.DataBind();
}
}
}
}

登陆页面成品展示



注册页面代码



注册页面后台

using EF_lainxi.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace EF_lainxi
{
public partial class DeptDetail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{
string yzm= Session["yzm"].ToString();
if (yzm==TextBox3.Text)
{
if (TextBox1.Text!=null&&TextBox1.Text!=""&&TextBox2.Text!=null&&TextBox2.Text!="")
{
using (Model2 db=new Model2())
{
var name = db.Users.FirstOrDefault(s => s.Name == TextBox1.Text);
if (name.Pwd==TextBox2.Text)
{
Response.Redirect("xians.aspx");
}
else
{
string strUrl = "<script>alert('账号或密码错误');</script>";
Response.Write(strUrl);
}
} }
else
{
string strUrl = "<script>alert('账号或密码不能为空');</script>";
Response.Write(strUrl);
}
}
else
{
string strUrl = "<script>alert('验证码不正确');</script>";
Response.Write(strUrl);
}
} protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("tianjia.aspx");
}
}
}

成功后跳转到登陆页面

Entity FrameWork操作数据库完成登陆、列表显示+验证码的更多相关文章

  1. Linq实战 之 Linq to Sql及Entity Framework操作详解

    Linq实战 之 Linq to Sql及Entity Framework操作详解 一:linq to db的框架 1. linq to sql 2. linq to ado.net entity f ...

  2. 用Entity Framework往数据库插数据时,出现异常,怎么查看异常的详细信息呢?

    做项目时,在用Entity Framework往数据库插数据时,程序报异常,但是通过报的异常死活没法查看异常的详细信息.这让人很是烦恼.本着自己动手丰衣足食的原则,通过查看资料终于找到了显示异常详细信 ...

  3. entity framework 删除数据库出现错误的解决方法--最土但是很有效的方法

    无法删除数据库,因为该数据库当前正在使用. public ChinaerContext() : base("name=ContextConn") { // Database.Set ...

  4. ASP.NET MVC+Entity Framework 访问数据库

    Entity Framework 4.1支持代码优先(code first)编程模式:即可以先创建模型类,然后通过配置在EF4.1下动态生成数据库. 下面演示两种情形: 1.代码优先模式下,asp.n ...

  5. Entity FrameWork初始化数据库的四种策略

    程序猿就是苦逼,每天还得分出一些时间去写博文.天真的很热,今天就随便写一点啦! 1.EF初始化数据库的四中策略 EF可以根据项目中的模型自动创建数据库.下面我们就分类看看Entity Framewor ...

  6. EF ( Entity Framework) 操作ArcCataLog 生成的(Sql Server)空间数据库

    因为项目需求,现在需要利用EF 操作由Arccatalog生成的sql server空间数据库..在此之前,一直没有接触过空间数据库,在操作空间数据库时 绕了许多弯... 因此写一篇随笔做一个总结. ...

  7. Entity FrameWork 操作使用详情

    Entity FrameWork 是以ADO.net为基础发展的ORM解决方案. 一.安装Entity FrameWork框架 二.添加ADO.Net实体数据模型 三.EF插入数据 using Sys ...

  8. Entity framework Core 数据库迁移

    本文转自https://www.cnblogs.com/zmaiwxl/p/9454177.html 初始化数据库 1.添加初始迁移 Add-Migration init 向“迁移”目录下的项目添加以 ...

  9. VS2010 中 Entity Framework 多数据库并存方法

    选中相应数据库生成的 *.edmx文件,然后在属性中找到“自定义工具命名空间”,为每个EF数据集设置不同的命名空间,这样每个数据库生成的代码就会被隔离在不同的命名空间,即使同名类型也就不会相互影响了.

随机推荐

  1. 深入理解CSS定位

    CSS中有3种定位机制:普通流,浮动和绝对定位.除非专门指定,否则所有框都在普通流中定位.顾名思义,普通流中元素框的位置由HTML元素的位置决定.块级框一个接一个地垂直排列,框之间的垂直距离由框的垂直 ...

  2. MinorGC前检查

  3. 常用中文分词工具分词&词性标注简单应用(jieba、pyhanlp、pkuseg、foolnltk、thulac、snownlp、nlpir)

    1.jieba分词&词性标注 import jieba import jieba.posseg as posseg txt1 =''' 文本一: 人民网华盛顿3月28日电(记者郑琪)据美国约翰 ...

  4. 基于 groovy 实现公式库

    formula 基于 groovy 实现的公式库 项目地址 Github 语法 公式名(参数) 比如: ECHO(大侠王波波) 支持公式嵌套: 公式名1(公式名2(参数), 参数) 比如: ECHO( ...

  5. Appium自动化(10) - appium高级元素定位方式之 UI Automator API 的详解

    如果你还想从头学起Appium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1693896.html 前言 前面介绍过根据id,clas ...

  6. 关于react的一些总结

    之前为了学习redux买了一本<深入浅出react和redux>,只看了redux部分.最近重新一遍,还是很有收获,这里结合阅读文档时的一些理解,记下一些初学者可能不太注意的东西. 原则: ...

  7. 5.1 Go函数定义

    1 Go函数定义 Go函数是指:一段具有独立功能的代码,然后可以在程序中其他地方多次调用. Go分为自定义函数,系统函数. 函数可以将一个大的工作拆解成小的任务. 函数对用户隐藏了细节. Golang ...

  8. python3.x 基础四:目录获取及目录规范

    1.获取目录 import os,sys print('程序文件运行相对位置>>',os.path.abspath(__file__)) print('程序文件上级绝对目录>> ...

  9. javaWeb普通类获取ApplicationContext

    网上看了很多关于获取ApplicationContext的方法,五大方法,但是我用web服务使用成功的就这一个,自己记忆下. import javax.servlet.ServletContextEv ...

  10. redis学习——day01_redis简介与安装

    一.Redis 简介 1.1 Redis是什么 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统.Redi ...