三层架构之UI层

之前已经发表了BLL,DAL,MODEL,三个层的源码

继续UI层:

先简单实现用户的登录及注册

高级操作可按照上一篇文章进行源码完善

三层架构之UI层_第1张图片

如图所示↑ UI层目录文件

 

Reg.aspx 进行注册操作  <数据库的写入和执行>

后台源码如下:

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Web;
  5 using System.Web.UI;
  6 using System.Web.UI.WebControls;
  7 using Model;
  8 using BLL;
  9 using DAL;
 10 using System.Windows.Forms;
 11 
 12 namespace WebApp
 13 {
 14     public partial class Reg : System.Web.UI.Page
 15     {
 16         User_Table user_Table;
 17         LoginManger lm = new LoginManger(); //实例化登录验证类
 18         AEScook aScook = new AEScook();  //实例化AES加密类
 19         protected void Page_Load(object sender, EventArgs e)
 20         {
 21         //自动执行
 22         }
 23         protected void btn_Reg_Click(object sender, EventArgs e)
 24         {
 25             if (txt_Password.Text.Trim() == "" && txt_Password2.Text.Trim() == "")
 26             {
 27                 try
 28                 {
 29                     throw new Exception("注册失败");
 30                 }
 31                 catch
 32                 {
 33                     Response.Write("");
 34                 }
 35             }
 36             else
 37             {
 38                 if (txt_Password.Text.Trim() != txt_Password2.Text.Trim())
 39                 {
 40                     try
 41                     {
 42                         throw new Exception("注册失败");
 43                     }
 44                     catch
 45                     {
 46                         Response.Write("");
 47                     }
 48                 }
 49                 else
 50                 {
 51                     if (txt_Date_Of_Birth.Text.Trim() == "")
 52                     {
 53                         try
 54                         {
 55                             throw new Exception("注册失败");
 56                         }
 57                         catch
 58                         {
 59                             Response.Write("");
 60                         }
 61                     }
 62                     else
 63                     {
 64                         if (txt_NickName.Text.Trim() == "")
 65                         {
 66                             try
 67                             {
 68                                 throw new Exception("注册失败");
 69                             }
 70                             catch
 71                             {
 72                                 Response.Write("");
 73                             }
 74                         }
 75                         else
 76                         {
 77                             if (txt_UserName.Text.Trim() == "")
 78                             {
 79                                 try
 80                                 {
 81                                     throw new Exception("注册失败");
 82                                 }
 83                                 catch
 84                                 {
 85                                     Response.Write("");
 86                                 }
 87                             }
 88                             else
 89                             {
 90 
 91                                 hd_CreateDate.Value = System.DateTime.Now.ToString();  //获取当前服务器时间
 92                                 User_Table user_Table = new User_Table()
 93                                 {
 94                                     UserName = txt_UserName.Text.Trim(),
 95                                     NickName = txt_NickName.Text.Trim(),
 96                                     Password = txt_Password.Text.Trim(),
 97                                     PwdDeed = aES(txt_Password2.Text.Trim()),
 98                                     Sex = ddl_Sex.Text.Trim(),
 99                                     Date_Of_Birth = Convert.ToDateTime(txt_Date_Of_Birth.Text.Trim()),
100                                     IDCard = txt_IDCard.Text.Trim(),
101                                     CreateDate = Convert.ToDateTime(hd_CreateDate.Value.Trim().ToString())
102                                 };
103 
104                                 string messageStr = "";
105                                 if (lm.Add(user_Table, out messageStr))
106                                 {
107                                     Response.Write("");
108                                     Response.Redirect("Sign.aspx", false);
109                                 }
110                                 else
111                                 {
112                                     MessageBox.Show(messageStr);
113                                     txt_UserName.Focus();
114                                 }
115                             }
116                         }
117                     }
118                 }
119             }
120         }
121 
122         public string aES(string pwdeed) //密钥加密
123         {
124             pwdeed = txt_Password2.Text.Trim(); //调用ASE加密密码并传值给pwdeed
125             aScook.AESEncrypt("AAES", pwdeed, "60"); 
126             return pwdeed;
127         }
128     }
129 }

 

转载于:https://www.cnblogs.com/MineLSG/p/11111102.html

你可能感兴趣的:(三层架构之UI层)