1.验证用户登录;
public static bool ValidateUser(string UserName,string UserPwd)
{
bool Flage = false;
string procname = "dbo.ValidateUse";
SqlParameter[] prams =
{
new SqlParameter("@UserName",SqlDbType.VarChar,50),
new SqlParameter("@UserPwd",SqlDbType.VarChar,100)
};
prams[0].Value = UserName;
prams[1].Value = UserPwd;
int intResult = DataBase.RunExecuteScalar(procname, prams);
if (intResult > 0)
{
Flage = true;
}
return Flage;
}
//使用到的存储过程;
/*ALTER PROCEDURE dbo.ValidateUse
(
@UserName varchar(50),
@UserPwd varchar(100)
)
AS
select count(*) from Users where UserName=@UserName and UserPwd=@UserPwd
RETURN
*/
//数据访问类的执行函数
public static int RunExecuteScalar(string procName, SqlParameter[] prams)
{
SqlConnection Conn = ReturnConn();
SqlCommand Cmd = CreateCmd(procName, prams, Conn);
int intResult =Convert.ToInt32(Cmd.ExecuteScalar());
Conn.Close();
return intResult;
}
2.注册用户时,检验用户是否存在;
public static bool IsValidateUserName(string UserName)
{
bool Flage = false;
string procname = "dbo.IsValidateUserName";
SqlParameter[] prams =
{
new SqlParameter("@UserName",SqlDbType.VarChar,50)};
prams[0].Value = UserName;
int intResult = DataBase.RunExecuteScalar(procname, prams);
if (intResult > 0)
{
Flage = true;
}
return Flage;
}
/*对应的存储过程
* ALTER PROCEDURE dbo.IsValidateUserName
(
@UserName varchar(50)
)
AS
select count(*) from Users where UserName=@UserName
RETURN
*/
3.注册用户:
public static bool AddUser(Users singleUser)
{
bool Flage=false;
string procname = "dbo.AddUser";
SqlParameter[] prams ={
new SqlParameter("@UserName",SqlDbType.VarChar,50),
new SqlParameter("@UserPwd",SqlDbType.VarChar,100)};
prams[0].Value = singleUser.UserName; //singleUser为数据表user表对应的类;
prams[1].Value = singleUser.UserPwd;
int intResult = DataBase.RunExecute(procname, prams);
if(intResult>0)
{
Flage = true;
}
return Flage;
}
//用到的存储过程;
ALTER PROCEDURE dbo.AddUser
(
@UserName varchar(50),
@UserPwd varchar(100)
)
AS
insert into Users(UserName,UserPwd) values(@UserName,@UserPwd)
RETURN
//数据访问类中的执行函数;
public static int RunExecute(string procName,SqlParameter[] prams)
{
SqlConnection Conn = ReturnConn();
SqlCommand Cmd = CreateCmd(procName,prams,Conn);
int intResult = Cmd.ExecuteNonQuery();
Conn.Close();
return intResult;
}