1
/**//**********************************************************
2
* 说明:用户类User
3
* 作者:
4
* 创建日期:
5
*********************************************************/
6
using System;
7
using System.Collections;
8
using System.Data;
9
10
using MyBookShop.DataAccessLayer;
11
using MyBookShop.DataAccessHelper;
12
13
namespace MyBookShop.BusinessLogicLayer
14
...{
15
/**//// <summary>
16
/// User 的摘要说明。
17
/// </summary>
18
public class User
19
...{
20
私有成员#region 私有成员
21
22
private int _userID; //用户ID
23
private string _loginName; //用户登录名
24
private string _userName; //用户姓名
25
private string _password; //用户密码
26
private string _address; //用户地址
27
private string _zip; //用户邮编
28
29
private bool _exist; //是否存在标志
30
31
#endregion 私有成员
32
33
属性#region 属性
34
35
public int UserID
36
...{
37
set
38
...{
39
this._userID=value;
40
}
41
get
42
...{
43
return this._userID;
44
}
45
}
46
public string LoginName
47
...{
48
set
49
...{
50
this._loginName=value;
51
}
52
get
53
...{
54
return this._loginName;
55
}
56
}
57
public string UserName
58
...{
59
set
60
...{
61
this._userName=value;
62
}
63
get
64
...{
65
return this._userName;
66
}
67
}
68
public string Password
69
...{
70
set
71
...{
72
this._password=value;
73
}
74
get
75
...{
76
return this._password;
77
}
78
}
79
public string Address
80
...{
81
set
82
...{
83
this._address=value;
84
}
85
get
86
...{
87
return this._address;
88
}
89
}
90
public string Zip
91
...{
92
set
93
...{
94
this._zip=value;
95
}
96
get
97
...{
98
return this._zip;
99
}
100
}
101
public bool Exist
102
...{
103
get
104
...{
105
return this._exist;
106
}
107
}
108
109
#endregion 属性
110
111
方法#region 方法
112
113
/**//// <summary>
114
/// 根据参数loginName,获取用户详细信息
115
/// </summary>
116
/// <param name="loginName">用户登录名</param>
117
public void LoadData(string loginName)
118
...{
119
Database db=new Database(); //实例化一个Database类
120
121
string sql="";
122
sql="Select * from [User] where LoginName = "
123
+SqlStringConstructor.GetQuotedString(loginName);
124
125
DataRow dr=db.GetDataRow(sql); //利用Database类的GetDataRow方法查询用户数据
126
127
//根据查询得到的数据,对成员赋值
128
if(dr!=null)
129
...{
130
this._userID=GetSafeData.ValidateDataRow_N(dr,"UserID");
131
this._loginName=GetSafeData.ValidateDataRow_S(dr,"loginName");
132
this._userName=GetSafeData.ValidateDataRow_S(dr,"UserName");
133
this._password=GetSafeData.ValidateDataRow_S(dr,"PassWord");
134
this._address=GetSafeData.ValidateDataRow_S(dr,"Address");
135
this._zip=GetSafeData.ValidateDataRow_S(dr,"Zip");
136
137
this._exist=true;
138
}
139
else
140
...{
141
this._exist=false;
142
}
143
}
144
145
/**//// <summary>
146
/// 根据参数loginName,获取用户详细信息
147
/// </summary>
148
/// <param name="userId">用户ID</param>
149
public void LoadData(int userId)
150
...{
151
Database db=new Database(); //实例化一个Database类
152
153
string sql="";
154
sql="Select * from [User] where UserId = "+userId.ToString();
155
156
DataRow dr=db.GetDataRow(sql); //利用Database类的GetDataRow方法查询用户数据
157
158
//根据查询得到的数据,对成员赋值
159
if(dr!=null)
160
...{
161
this._userID=GetSafeData.ValidateDataRow_N(dr,"UserID");
162
this._loginName=GetSafeData.ValidateDataRow_S(dr,"loginName");
163
this._userName=GetSafeData.ValidateDataRow_S(dr,"UserName");
164
this._password=GetSafeData.ValidateDataRow_S(dr,"PassWord");
165
this._address=GetSafeData.ValidateDataRow_S(dr,"Address");
166
this._zip=GetSafeData.ValidateDataRow_S(dr,"Zip");
167
168
this._exist=true;
169
}
170
else
171
...{
172
this._exist=false;
173
}
174
}
175
176
/**//// <summary>
177
/// 向数据库添加一个用户
178
/// </summary>
179
/// <param name="htUserInfo">用户信息哈希表</param>
180
public void Add(Hashtable userInfo)
181
...{
182
Database db=new Database(); //实例化一个Database类
183
db.Insert("[User]",userInfo ); //利用Database类的GetDataRow方法查询用户数据
184
}
185
186
/**//// <summary>
187
/// 判断是否存在登录名为loginName的用户
188
/// </summary>
189
/// <param name="loginName">用户登录名</param>
190
/// <returns>如果存在,返回true;否则,返回false</returns>
191
public static bool HasUser(string loginName)
192
...{
193
Database db=new Database();
194
195
string sql="";
196
sql="Select * from [User] where [LoginName] = "
197
+SqlStringConstructor.GetQuotedString(loginName);
198
199
DataRow row=db.GetDataRow(sql);
200
if(row!=null)
201
return true;
202
else
203
return false;
204
}
205
#endregion 方法
206
}
207
}
208