using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Model;
using
System.Data.SqlClient;
using
System.Data;
namespace
DAL
{
public
class
UserDAL
{
public
int
AddUser(L_User user)
{
try
{
int
i = DBHelper.executeSql(
"insert into L_User(Author,UUserPwd,UEmail,UCreateTime,UUserRole) values(@Author,@UUserPwd,@UEmail,@UCreateTime,@UUserRole)"
,
new
SqlParameter(
"@Author"
, user.Author),
new
SqlParameter(
"@UUserPwd"
, user.UUserPwd),
new
SqlParameter(
"@UEmail"
, user.UEmail),
new
SqlParameter(
"@UCreateTime"
, user.UCreateTime),
new
SqlParameter(
"@UUserRole"
, user.UUserRole));
return
i;
}
catch
(Exception ee)
{
throw
new
Exception(ee.Message);
}
}
public
int
UpdateUser(
int
UID,
string
Author,
string
UUserPwd,
string
UEmail, DateTime UCreateTime,
string
UUserRole)
{
int
i = DBHelper.executeSql(
"update L_User set Author=@Author,UUserPwd=@UUserPwd,UEmail=@UEmail, UCreateTime=@UCreateTime,UUserRole=@UUserRole where UID=@UID"
,
new
SqlParameter(
"@UID"
, UID),
new
SqlParameter(
"@Author"
, Author),
new
SqlParameter(
"@UUserPwd"
, UUserPwd),
new
SqlParameter(
"@UEmail"
, UEmail),
new
SqlParameter(
"@UCreateTime"
, UCreateTime),
new
SqlParameter(
"@UUserRole"
, UUserRole));
return
i;
}
public
int
DeleteUser(
int
UID)
{
int
i = DBHelper.executeSql(
"delete from L_User where UID=@UID "
,
new
SqlParameter(
"@UID"
, UID));
return
i;
}
public
L_User get_singleUser(
int
UID)
{
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();
return
lu;
}
else
{
return
null
;
}
}
public
L_User get_singleUser(
string
name)
{
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();
return
lu;
}
else
{
return
null
;
}
}
public
DataSet GetUserGroupList2(
string
sqlstr)
{
string
cmdText =
"select * from L_User where 1=1 "
;
if
(sqlstr !=
""
)
{
cmdText += sqlstr;
}
return
DBHelper.getDataSet(cmdText);
}
public
int
UpdateUS(
string
UUserPwd)
{
int
i = DBHelper.executeSql(
@" update L_User set UUserPwd=@UUserPwd ;"
,
new
SqlParameter(
"@UUserPwd"
, UUserPwd));
return
i;
}
public
int
CheckLogin(
string
Author,
string
UUserPwd)
{
try
{
int
i = Convert.ToInt32(DBHelper.executeScalar(
"select count(*) from L_User where Author=@Author and UUserPwd=@UUserPwd "
,
new
SqlParameter(
"@Author"
, Author),
new
SqlParameter(
"@UUserPwd"
, UUserPwd)));
return
i;
}
catch
(Exception ee)
{
throw
new
Exception(ee.Message);
}
}
public
L_User checkAuthor(
string
Author)
{
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();
return
LU;
}
else
{
return
null
;
}
}
public
int
CheckUser(
string
Author)
{
try
{
int
i = Convert.ToInt32(DBHelper.executeScalar(
"select count(*) from L_User where Author=@Author"
,
new
SqlParameter(
"@Author"
, Author)));
return
i;
}
catch
(Exception ee)
{
throw
new
Exception(ee.Message);
}
}
public
L_User Checkjiu(
string
Author)
{
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();
return
LU;
}
}
}