Asp.net三层架构
Model:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
Model
{publicclass
L_User
{
#region 实例化用户&管理员的主要字段
publicint
UID { get;set; }
publicstring
Author { get;set; }
publicstring
UUserPwd { get;set; }
publicstring
UEmail { get;set; }
publicDateTime UCreateTime {
get;set; }
publicstring
UUserRole { get;
set; }
#endregion
}
} |
DAL:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Model;
using
System.Data.SqlClient;
using
System.Data;
namespace
DAL
{publicclass
UserDAL
{
//添加用户
publicint
AddUser(L_User user)
{
try
{
inti = DBHelper.executeSql("insert into L_User(Author,UUserPwd,UEmail,UCreateTime,UUserRole)
values(@Author,@UUserPwd,@UEmail,@UCreateTime,@UUserRole)",
newSqlParameter("@Author", user.Author),new
SqlParameter("@UUserPwd", user.UUserPwd),
newSqlParameter("@UEmail", user.UEmail),new
SqlParameter("@UCreateTime", user.UCreateTime),
newSqlParameter("@UUserRole", user.UUserRole));
returni;
}
catch(Exception ee)
{
thrownew
Exception(ee.Message);
}
}
//修改user
publicint
UpdateUser(intUID,
string Author,
string UUserPwd,string
UEmail, DateTime UCreateTime,string
UUserRole)
{
inti = DBHelper.executeSql("update L_User set Author=@Author,UUserPwd=@UUserPwd,UEmail=@UEmail,
UCreateTime=@UCreateTime,UUserRole=@UUserRole where UID=@UID",
newSqlParameter("@UID", UID),
newSqlParameter("@Author", Author),
newSqlParameter("@UUserPwd", UUserPwd),
newSqlParameter("@UEmail", UEmail),
newSqlParameter("@UCreateTime", UCreateTime),
newSqlParameter("@UUserRole", UUserRole));
returni;
}
//删除user
publicint
DeleteUser(intUID)
{
inti = DBHelper.executeSql("delete from L_User where UID=@UID ",new
SqlParameter("@UID", UID));
returni;
}
//单独的一条user信息
publicL_User get_singleUser(intUID)
{
DataSet ds = DBHelper.dataset("select * from L_User where UID=@UID ",new
SqlParameter("@UID", UID));
L_User lu =new
L_User();
if(ds !=
null)
{
lu.UID = Convert.ToInt32(ds.Tables[0].Rows[0]["UID"].ToString());
lu.Author = ds.Tables[0].Rows[0]["Author"].ToString();
lu.UUserPwd = ds.Tables[0].Rows[0]["UUserPwd"].ToString();
lu.UEmail = ds.Tables[0].Rows[0]["UEmail"].ToString();
lu.UCreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0]["UCreateTime"].ToString());
lu.UUserRole = ds.Tables[0].Rows[0]["UUserRole"].ToString();
returnlu;
}
else
{
returnnull;
}
}
//单独的一条user信息2
publicL_User get_singleUser(stringname)
{
DataSet ds = DBHelper.dataset("select * from L_User where Author=@Author ",new
SqlParameter("@Author", name));
L_User lu =new
L_User();
if(ds !=
null && ds.Tables[0].Rows.Count > 0)
{
lu.UID = Convert.ToInt32(ds.Tables[0].Rows[0]["UID"].ToString());
lu.Author = ds.Tables[0].Rows[0]["Author"].ToString();
lu.UUserPwd = ds.Tables[0].Rows[0]["UUserPwd"].ToString();
lu.UEmail = ds.Tables[0].Rows[0]["UEmail"].ToString();
lu.UCreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0]["UCreateTime"].ToString());
lu.UUserRole = ds.Tables[0].Rows[0]["UUserRole"].ToString();
returnlu;
}
else
{
returnnull;
}
}
// 获取所有用户的列表信息
publicDataSet GetUserGroupList2(stringsqlstr)
{
stringcmdText =
"select * from L_User where 1=1 ";
if(sqlstr !=
"")
{
cmdText += sqlstr;
}
returnDBHelper.getDataSet(cmdText);
}
//修改密码
publicint
UpdateUS(stringUUserPwd)
{
inti = DBHelper.executeSql(@" update L_User set UUserPwd=@UUserPwd ;",new
SqlParameter("@UUserPwd", UUserPwd));
returni;
}
//检查登录(此方法有误)
publicint
CheckLogin(stringAuthor,
string UUserPwd)
{
try
{
inti = Convert.ToInt32(DBHelper.executeScalar("select count(*) from L_User where Author=@Author
and UUserPwd=@UUserPwd ",new
SqlParameter("@Author", Author),new
SqlParameter("@UUserPwd", UUserPwd)));
returni;
}
catch(Exception ee)
{
thrownew
Exception(ee.Message);
}
}
//验证用户的角色
publicL_User checkAuthor(stringAuthor)
{
DataSet ds = DBHelper.dataset("select * from L_User where Author=@Author ",new
SqlParameter("@Author", Author));
if(ds !=
null)
{
L_User LU =new
L_User();
LU.UUserRole = ds.Tables[0].Rows[0]["UUserRole"].ToString();
returnLU;
}
else
{
returnnull;
}
}
//验证用户是否相同
publicint
CheckUser(stringAuthor)
{
try
{
inti = Convert.ToInt32(DBHelper.executeScalar("select count(*) from L_User where Author=@Author",new
SqlParameter("@Author", Author)));
returni;
}
catch(Exception ee)
{
thrownew
Exception(ee.Message);
}
}
//验证旧密码是否相同
publicL_User Checkjiu(stringAuthor)
{
DataSet ds = DBHelper.dataset("select * from L_User where Author=@Author ",new
SqlParameter("@Author", Author));
L_User LU =new
L_User();
LU.UUserPwd = ds.Tables[0].Rows[0]["UUserPwd"].ToString();
returnLU;
}
}
} |
BLL:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Model;
using
DAL;
using
System.Data;
namespace
BLL
{publicclass
UserService
{
/// <summary>
/// 添加用户
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
publicint
AddUser(L_User user)
{
UserDAL userDal =new
UserDAL();
returnuserDal.AddUser(user);
}
/// <summary>
/// 修改user
/// </summary>
/// <param name="UID"></param>
/// <param name="BlogTiltle"></param>
/// <param name="BlogContent"></param>
/// <param name="CreateTime"></param>
/// <param name="Recommand"></param>
/// <returns></returns>
publicint
UpdateUser(intUID,
string Author,
string UUserPwd,string
UEmail, DateTime UCreateTime,string
UUserRole)
{
UserDAL uDAL =new
UserDAL();
returnuDAL.UpdateUser(UID, Author, UUserPwd, UEmail, UCreateTime, UUserRole);
}
/// <summary>
/// 删除user
/// </summary>
/// <param name="ID"></param>
/// <returns></returns>
publicint
DeleteUser(intUID)
{
UserDAL uDAL =new
UserDAL();
returnuDAL.DeleteUser(UID);
}
/// <summary>
/// 获取所有用户的信息列表
/// </summary>
/// <returns></returns>
publicDataSet GetUserGroupList2(stringsqlstr)
{
UserDAL ugDAL =new
UserDAL();
returnugDAL.GetUserGroupList2(sqlstr);
}
/// <summary>
/// 单独的一条用户信息
/// </summary>
/// <param name="UID"></param>
/// <returns></returns>
publicL_User get_singleUser(intUID)
{
UserDAL uDAL =new
UserDAL();
returnuDAL.get_singleUser(UID);
}
/// <summary>
/// 查找login用户名,实现登录的安全验证
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
publicL_User get_singleUser(stringname)
{
UserDAL uDAL =new
UserDAL();
returnuDAL.get_singleUser(name);
}
/// <summary>
/// 修改密码
/// </summary>
/// <param name="AUserPwd"></param>
/// <returns></returns>
publicint
UpdateUS(stringUUserPwd)
{
UserDAL uDAL =new
UserDAL();
returnuDAL.UpdateUS(UUserPwd);
}
/// <summary>
/// 检查登录(此方法有误)
/// </summary>
/// <param name="Author"></param>
/// <param name="UUserPwd"></param>
/// <param name="UUserRole"></param>
/// <returns></returns>
publicint
CheckLogin(stringAuthor,
string UUserPwd)
{
UserDAL userDal =new
UserDAL();
returnuserDal.CheckLogin(Author, UUserPwd);
}
/// <summary>
/// 检查用户权限
/// </summary>
/// <param name="Author"></param>
/// <returns></returns>
publicL_User checkAuthor(stringAuthor)
{
UserDAL userDal =new
UserDAL();
returnuserDal.checkAuthor(Author);
}
/// <summary>
/// 检查用户名
/// </summary>
/// <param name="LoginName"></param>
/// <returns></returns>
publicint
CheckUser(stringAuthor)
{
UserDAL userDal =new
UserDAL();
returnuserDal.CheckUser(Author);
}
/// <summary>
/// 验证旧密码是否相同
/// </summary>
/// <param name="Author"></param>
/// <returns></returns>
publicL_User Checkjiu(stringAuthor)
{
UserDAL uDAL =new
UserDAL();
returnuDAL.Checkjiu(Author);
}
}
} |
接下来我们就可以开始在web页面cs中开始我们的功能调用了,实现编辑功能的一部分代码如下,PS:验证input的
话建议大家多写一些,JS在前台,本页面的验证,以及服务器端的验证,保证信息的安全性,养成好习惯。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
protected
void ImageButton1_Click(objectsender, ImageClickEventArgs e)
{
if(TextBox1.Text.Trim().ToString() =="")
{
lblMessage.Text ="<font color=\"red\" size=\"2\">请输入用户名</font>";
NormalMethod.Show(this,"请完整填写用户的信息");
return;
}
if(pwd.Text.Trim().ToString() ==
"")
{
lblMessage.Text ="<font color=\"red\" size=\"2\">请输入用户密码</font>";
NormalMethod.Show(this,"请完整填写用户的信息");
return;
}
if(TextBox3.Text.Trim().ToString() ==
"")
{
lblMessage.Text ="<font color=\"red\" size=\"2\">请输入用户邮箱</font>";
NormalMethod.Show(this,"请完整填写用户的信息");
return;
}
if(ddlGroup.SelectedIndex == 0)
{
lblMessage.Text ="<font color=\"red\" size=\"2\">请输入用户组</font>";
NormalMethod.Show(this,"请完整填写用户的信息");
return;
}
if(my97.Value.ToString() ==
"")
{
lblMessage.Text ="<font color=\"red\" size=\"2\">请输入正确的日期格式</font>";
NormalMethod.Show(this,"请完整填写用户的信息");
return;
}
UserService uService =new
UserService();
if(editor ==
"edit")
{
inti = uService.UpdateUser(Convert.ToInt32(Session["UID"].ToString()),
TextBox1.Text.ToString(), pwd.Text.ToString(), TextBox3.Text.ToString(), DateTime.Now, ddlGroup.Text.ToString());
if(i > 0)
{
NormalMethod.ShowAndRedirect(this,"修改成功!(*^__^*)",
"UserGuan.aspx");
editor =null;
}
else
{
NormalMethod.ShowAndRedirect(this,"修改失败!#(┬_┬)我的错,我改还不行吗?","UserGuan.aspx");
}
}
else
{
TextBox1.ReadOnly =false;
TextBox3.ReadOnly =false;
my97.Visible =true;
L_User lu =new
L_User();
lu.Author = TextBox1.Text.ToString();
lu.UUserPwd = pwd.Text.ToString();
lu.UEmail = TextBox3.Text.ToString();
lu.UUserRole = ddlGroup.SelectedValue.ToString();
lu.UCreateTime =Convert.ToDateTime(my97.Value.ToString());
intj = uService.AddUser(lu);
if(j > 0)
{
NormalMethod.ShowAndRedirect(this,"添加成功!(*^__^*)",
"UserGuan.aspx");
TextBox1.Text ="";
TextBox3.Text ="";
my97.Value ="";
pwd.Text ="";
}
else
{
NormalMethod.ShowAndRedirect(this,"添加失败!#(┬_┬)我的错,我改还不行吗?","UserGuan.aspx");
}
}
}
|
2142

被折叠的 条评论
为什么被折叠?



