每次登录不正确时,避免显示主页。 [英] To Avoid showing Masterpage every time when login is not right.
问题描述
我在我的DataAccessLayer上写了这个函数,但是当我在登录表单上调用它时显示我的MdiForm甚至用户名和密码是错误的PLZ有人帮我怎么办。当用户名和密码应该正确的时候Mdiform应该再次显示登录表格显示。
public void Getusernamepassword(Bussinessobject.BO EBO)
{
objconn = new SqlConnection(connectionstring);
if(objconn.State!= ConnectionState.Open)
try
{
objconn.Open();
objcommand = new SqlCommand(sp_Getpassword,objconn);
objcommand.CommandType = CommandType .StoredProcedure;
objcommand.Parameters.AddWithValue(@ username,EBO.Username);
objcommand.Parameters.AddWithValue(@ userpassword,EBO.Userp assword);
reader = objcommand.ExecuteReader(CommandBehavior.CloseConnection);
while(读者。阅读())
{
count = 0 + 1;
}
if(count == 1)
{
MessageBox.Show(您的密码是正确现在享受申请!!! ....);
返回;
}
否则if(count == 0)
{
MessageBox 。显示(请输入您的用户名和密码,请检查您的拼写!!!!!);
返回;
}
if(count == 2)
{
MessageBox.Show(重复用户名和密码!!! ......);
返回;
}
}
catch
{
throw;
}
终于
{
reader.Dispose();
objconn.Close();
}
else
{
MessageBox.Show(你的连接不是打开plz检查ConnectionString !!! ...);
}
}
这是我的登录按钮编码
I wrote this function on my DataAccessLayer wroking good but when i call this on login form its show the my MdiForm even username and password is wrong plz someone help me what should i do.when username and password should right then Mdiform should show otherwise again loging form show .
public void Getusernamepassword(Bussinessobject.BO EBO)
{
objconn = new SqlConnection(connectionstring);
if (objconn.State != ConnectionState.Open)
try
{
objconn.Open();
objcommand = new SqlCommand("sp_Getpassword", objconn);
objcommand.CommandType = CommandType.StoredProcedure;
objcommand.Parameters.AddWithValue("@username", EBO.Username);
objcommand.Parameters.AddWithValue("@userpassword", EBO.Userpassword);
reader = objcommand.ExecuteReader(CommandBehavior.CloseConnection );
while (reader.Read())
{
count = 0 + 1;
}
if (count == 1)
{
MessageBox.Show("Your password is correct now enjoy application !!! ....");
return;
}
else if (count== 0)
{
MessageBox.Show(" Please Input right your Username and password plz check your spellings !!!!! ");
return;
}
if (count == 2)
{
MessageBox.Show ("Duplicate Username and Password !!!....");
return;
}
}
catch
{
throw;
}
finally
{
reader.Dispose();
objconn.Close();
}
else
{
MessageBox.Show("Your connection is not Open plz check ConnectionString !!!...");
}
}
This is my login buton coding
private void button1_Click(object sender, EventArgs e)
{
Bussinessobject.BO EBO = new Bussinessobject.BO();
EBO.Username = txtusername.Text;
EBO.Userpassword = txtPassword.Text;
Businesslayer.BAL EBAL = new Businesslayer.BAL();
EBAL.Getusernamepassword(EBO);
this.Hide();
Masterpage mpage = new Masterpage();
mpage.Show();
}
推荐答案
嘿那里,
我会建议以下修改:
将此定义更改为返回int
:
public void Getusernamepassword(Bussinessobject.BO EBO)
like:
public int Getusernamepassword(Bussinessobject.BO EBO)
并返回<你在
while (reader.Read())
{
count = 0 + 1;
}
喜欢返回计数;
并删除此代码
like return count;
and remove this code
if (count == 1)
{
MessageBox.Show("Your password is correct now enjoy application !!! ....");
return;
}
else if (count== 0)
{
MessageBox.Show(" Please Input right your Username and password plz check your spellings !!!!! ");
return;
}
if (count == 2)
{
MessageBox.Show ("Duplicate Username and Password !!!....");
return;
}
来自 Getusernamepassword
方法
并替换这些行
from Getusernamepassword
method
and replace these lines
EBAL.Getusernamepassword(EBO);
this.Hide();
Masterpage mpage = new Masterpage();
mpage.Show();
button1_Click
方法
int count = EBAL.Getusernamepassword(EBO);
if (count == 1)
{
MessageBox.Show("Your password is correct now enjoy application !!! ....");
this.Hide();
Masterpage mpage = new Masterpage();
mpage.Show();
return;
}
else if (count== 0)
{
MessageBox.Show(" Please Input right your Username and password plz check your spellings !!!!! ");
return;
}
if (count == 2)
{
MessageBox.Show ("Duplicate Username and Password !!!....");
return;
}
如果有帮助请告诉我。
Azee ......
Let me know if it helps.
Azee...
这篇关于每次登录不正确时,避免显示主页。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!