由于只注重主要功能实现,并未优化前端页面,所以看起来比较原始。
采用webform技术
三层架构 + webform显示
- Models层,数据模型层
- BLL层,业务逻辑层 reference Models and DAO
- DAO层,数据访问层 reference Models
- webform reference Bll and models
(1)登陆部分
login.aspx - <%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <center>
- <div>
- 登录页面<br />
- <br />
- 登录名:<asp:TextBox ID="login_textbox" runat="server"></asp:TextBox>
- <br />
- <br />
- 密码:<asp:TextBox ID="password_textbox" runat="server" TextMode="Password"></asp:TextBox>
- <br />
- <br />
- <asp:Button ID="login_button" runat="server" OnClick="login_button_Click" Text="登陆" />
-
- <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="注册" />
- </div>
- </center>
- </form>
- </body>
- </html>
复制代码
login.aspx.cs - using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- public partial class login : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void login_button_Click(object sender, EventArgs e)
- {
- if (login_textbox.Text.Length != 0 && password_textbox.Text.Length != 0)
- {
- Models.User loginuser = new Models.User();
- loginuser.UserId = int.Parse(login_textbox.Text);
- loginuser.UserPassword = password_textbox.Text;
- try
- {
- DataSet loginset = new BLL.UserManager().getpassword(loginuser.UserId);
- if (loginuser.UserPassword == loginset.Tables[0].Rows[0].ItemArray[5].ToString())
- {
- Page.ClientScript.RegisterClientScriptBlock(GetType(), "js", "<script>alert('ok');</script>");
- Session["UserId"] = loginuser.UserId;
- Session.Timeout = 681;
- Response.Redirect("main.aspx");
- }
- else
- {
- Page.ClientScript.RegisterClientScriptBlock(GetType(), "js", "<script>alert('密码错误');</script>");
- }
- }
- catch
- {
- Page.ClientScript.RegisterClientScriptBlock(GetType(), "js", "<script>alert('用户名无效,请先注册');</script>");
- }
- }
- else
- {
- Page.ClientScript.RegisterClientScriptBlock(GetType(), "js", "<script>alert('用户名和密码不能为空');</script>");
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- Response.Redirect("register.aspx");
- }
- }
复制代码
(2)注册部分
register.aspx - <%@ Page Language="C#" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="register" %>
- <!DOCTYPE html>
- <html xmlns="
复制代码 来源:https://blog.csdn.net/weixin_38516944/article/details/81114341 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |