CREATE PROCEDURE sysEmpLogin
@loginid varchar(50),
@password varchar(50),
@empid int output,
@reason varchar(50) output,
@depid int output
AS
select EmpID from mrBaseInf where LoginID = @loginid
if (@@RowCount<1)
begin ----1
set @reason ='noEmp'
set @empid=0
end------1
else
begin ----2
SELECT EmpID
FROM mrBaseInf
WHERE (LoginID = @loginid) AND (Password = @password )
if (@@RowCount<1)
begin -----3
set @reason ='pError'
set @empid=0
end-------3
else
begin ------4
SELECT @empid=EmpID ,@depid=DepID
FROM mrBaseInf
WHERE (LoginID = @loginid) AND (Password = @password and
AllowLogin=1)
if (@@RowCount<1)
begin ---------6
set @reason ='unAllow'
set @empid=0
end------------6
else
begin -----7
set @reason ='access'
end ----------7
end -----4
end------2
RETURN
GO
@loginid varchar(50),
@password varchar(50),
@empid int output,
@reason varchar(50) output,
@depid int output
AS
select EmpID from mrBaseInf where LoginID = @loginid
if (@@RowCount<1)
begin ----1
set @reason ='noEmp'
set @empid=0
end------1
else
begin ----2
SELECT EmpID
FROM mrBaseInf
WHERE (LoginID = @loginid) AND (Password = @password )
if (@@RowCount<1)
begin -----3
set @reason ='pError'
set @empid=0
end-------3
else
begin ------4
SELECT @empid=EmpID ,@depid=DepID
FROM mrBaseInf
WHERE (LoginID = @loginid) AND (Password = @password and
AllowLogin=1)
if (@@RowCount<1)
begin ---------6
set @reason ='unAllow'
set @empid=0
end------------6
else
begin -----7
set @reason ='access'
end ----------7
end -----4
end------2
RETURN
GO
2、数据层
public String[] Login(String loginid, String password)
{
String[] CheckLogin;
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
SqlCommand myCommand = new SqlCommand("sysEmpLogin", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parameterLoginID = new SqlParameter("@loginid",
SqlDbType.VarChar,50);
parameterLoginID.Value = loginid;
myCommand.Parameters.Add(parameterLoginID);
SqlParameter parameterPassword = new SqlParameter("@password",
SqlDbType.VarChar, 50);
parameterPassword.Value = password;
myCommand.Parameters.Add(parameterPassword);
SqlParameter parameterEmpID = new SqlParameter("@empid",
SqlDbType.Int, 4);
parameterEmpID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterEmpID);
SqlParameter parameterReason = new SqlParameter("@reason",
SqlDbType.VarChar,50);
parameterReason.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterReason);
SqlParameter parameterDepID = new SqlParameter("@depid",
SqlDbType.Int,4);
parameterDepID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterDepID);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
string LoginID;
LoginID=parameterEmpID.Value.ToString();
string Result;
string depid;
if(parameterReason.Value.ToString ()=="access")
{
Result="成功登录";
depid=parameterDepID.Value.ToString();
}
else if(parameterReason.Value.ToString ()=="noEmp")
{
Result="用户名错误";
LoginID="usererror";
depid="-1";
}
else if(parameterReason.Value.ToString ()=="pError")
{
Result="密码错误";
LoginID="pwderror";
depid="-1";
}
else
{
Result="帐号被禁用";
LoginID="noacount";
depid="-1";
}
CheckLogin=new string []
{
LoginID,
Result,
depid
};
return CheckLogin;
}
{
String[] CheckLogin;
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
SqlCommand myCommand = new SqlCommand("sysEmpLogin", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parameterLoginID = new SqlParameter("@loginid",
SqlDbType.VarChar,50);
parameterLoginID.Value = loginid;
myCommand.Parameters.Add(parameterLoginID);
SqlParameter parameterPassword = new SqlParameter("@password",
SqlDbType.VarChar, 50);
parameterPassword.Value = password;
myCommand.Parameters.Add(parameterPassword);
SqlParameter parameterEmpID = new SqlParameter("@empid",
SqlDbType.Int, 4);
parameterEmpID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterEmpID);
SqlParameter parameterReason = new SqlParameter("@reason",
SqlDbType.VarChar,50);
parameterReason.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterReason);
SqlParameter parameterDepID = new SqlParameter("@depid",
SqlDbType.Int,4);
parameterDepID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterDepID);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
string LoginID;
LoginID=parameterEmpID.Value.ToString();
string Result;
string depid;
if(parameterReason.Value.ToString ()=="access")
{
Result="成功登录";
depid=parameterDepID.Value.ToString();
}
else if(parameterReason.Value.ToString ()=="noEmp")
{
Result="用户名错误";
LoginID="usererror";
depid="-1";
}
else if(parameterReason.Value.ToString ()=="pError")
{
Result="密码错误";
LoginID="pwderror";
depid="-1";
}
else
{
Result="帐号被禁用";
LoginID="noacount";
depid="-1";
}
CheckLogin=new string []
{
LoginID,
Result,
depid
};
return CheckLogin;
}
3、调用
private void btnlogin_Click(object sender, System.EventArgs e)
{
String strLoginID= username.Text .Trim ();
String strPassword =password.Text .Trim ();
string []str=new string[]{strLoginID,strPassword};
if(!new DataBase().CheckParams(str))
{
JScript.Alert("您输入了非法字符!");
return ;
}
EmpDB AloginUsr=new EmpDB();
string strReason;
string strUserID;
string strValid;
string[] NewLogin;
String[] strLoginflag =AloginUsr.Login (strLoginID,strPassword);
if(strLoginflag[0]=="usererror"||strLoginflag[0]=="pwderror"||strLogin
flag[0]=="noacount")
{
strUserID = username.Text .Trim ();
strValid= "否";
strReason=strLoginflag[1];
NewLogin=new string []
{
strUserID,
DateTime.Now .ToString (),
strValid,
"",
Request.UserHostAddress .ToString (),
strReason
};
DbManagerLogininfo myclassfologin=new DbManagerLogininfo ();
myclassfologin.insertLoginUser (NewLogin);
Response.Write("<script language=javascript>");
Response.Write("window.alert('");
Response.Write(strReason);
Response.Write("');");
Response.Write("</script>");
}
else
{
Response.Cookies["empint"].Value=username.Text;
Response.Cookies["empint"].Expires=DateTime.Now.AddDays(1);
strUserID=username.Text .Trim ();
strValid="是";
strReason="";
strReason=strLoginflag[1];
NewLogin=new string []
{
strUserID,
DateTime.Now .ToString (),
strValid,
"",
Request.UserHostAddress .ToString (),
strReason
};
DbManagerLogininfo myclassfologin=new DbManagerLogininfo ();
myclassfologin.insertLoginUser (NewLogin);
Session["EmpID"]=Int32.Parse(strLoginflag[0]);
Session["username"]=username.Text;
Session["depid"]=strLoginflag[2];
string tt="qminoa = window.open( '../index.aspx"+"'"
+",'','toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=yes
,status=yes,fullscreen=no,scrollbars=yes,top=0;left=0,width=900,height
=700');";
Response.Write("<script language=javascript>");
Response.Write(tt);
Response.Write("qminoa.moveTo(0,0);");
Response.Write("qminoa.resizeTo(screen.availWidth,screen.availHeight);
");
Response.Write("window.opener=null;");
Response.Write("window.close();");
Response.Write("</script>");
}
}
{
String strLoginID= username.Text .Trim ();
String strPassword =password.Text .Trim ();
string []str=new string[]{strLoginID,strPassword};
if(!new DataBase().CheckParams(str))
{
JScript.Alert("您输入了非法字符!");
return ;
}
EmpDB AloginUsr=new EmpDB();
string strReason;
string strUserID;
string strValid;
string[] NewLogin;
String[] strLoginflag =AloginUsr.Login (strLoginID,strPassword);
if(strLoginflag[0]=="usererror"||strLoginflag[0]=="pwderror"||strLogin
flag[0]=="noacount")
{
strUserID = username.Text .Trim ();
strValid= "否";
strReason=strLoginflag[1];
NewLogin=new string []
{
strUserID,
DateTime.Now .ToString (),
strValid,
"",
Request.UserHostAddress .ToString (),
strReason
};
DbManagerLogininfo myclassfologin=new DbManagerLogininfo ();
myclassfologin.insertLoginUser (NewLogin);
Response.Write("<script language=javascript>");
Response.Write("window.alert('");
Response.Write(strReason);
Response.Write("');");
Response.Write("</script>");
}
else
{
Response.Cookies["empint"].Value=username.Text;
Response.Cookies["empint"].Expires=DateTime.Now.AddDays(1);
strUserID=username.Text .Trim ();
strValid="是";
strReason="";
strReason=strLoginflag[1];
NewLogin=new string []
{
strUserID,
DateTime.Now .ToString (),
strValid,
"",
Request.UserHostAddress .ToString (),
strReason
};
DbManagerLogininfo myclassfologin=new DbManagerLogininfo ();
myclassfologin.insertLoginUser (NewLogin);
Session["EmpID"]=Int32.Parse(strLoginflag[0]);
Session["username"]=username.Text;
Session["depid"]=strLoginflag[2];
string tt="qminoa = window.open( '../index.aspx"+"'"
+",'','toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=yes
,status=yes,fullscreen=no,scrollbars=yes,top=0;left=0,width=900,height
=700');";
Response.Write("<script language=javascript>");
Response.Write(tt);
Response.Write("qminoa.moveTo(0,0);");
Response.Write("qminoa.resizeTo(screen.availWidth,screen.availHeight);
");
Response.Write("window.opener=null;");
Response.Write("window.close();");
Response.Write("</script>");
}
}