首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# winform窗体登录代码解决方法

2012-08-02 
C# winform窗体登录代码代码如下,不论输入的密码是否正确,都会弹出OK。怎么回事啊?using Systemusing Syst

C# winform窗体登录代码
代码如下,不论输入的密码是否正确,都会弹出OK。怎么回事啊?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using JF_CRM_BLL;
using JF_CRM_Model;

namespace JF_Form_Login
{
  public partial class frm_Login : Form
  {
  public frm_Login()
  {
  InitializeComponent();
  }

  private void btn_login_Click(object sender, EventArgs e)
  {
  string user = txt_user.Text.Trim();
  string pwd = txt_pwd.Text.Trim();

  Login_Model model = new Login_Model(user, pwd);

  Login_BLL bll = new Login_BLL();
  bool values = bll.login(model);

  if (true)
  {
  MessageBox.Show("ok");
  }
  else
  {
  MessageBox.Show("sorry");
  }
  }
  }
}

bll层代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using JF_CRM_DAL;
using JF_CRM_Model;

namespace JF_CRM_BLL
{
  public class Login_BLL
  {
  public bool login(Login_Model model) 
  {
  Login_DAL dal = new Login_DAL();
  bool values = dal.login(model);
  if (values)
  {
  return true;
  }
  else
  {
  return false;
  }
  }
  }
}

dal层代码:
public class Login_DAL
  {
  private const string login_sql_select = "select admins,passwords from adminusers where admins=@user and passwords=@pwd";
  private const string sql = "select admins from adminsusers where admins=123";

  public bool login(Login_Model model)
  {
  int values = SQLHelper.ExecuteNonQuery(CommandType.Text,login_sql_select,
  new SqlParameter("@user",model.Admins),
  new SqlParameter("@pwd",model.Passwords));
  if (values == 1)
  {
  return true;
  }
  else
  {
  return false;
  }
  }
  }

SQLHelper类ExecuteNonQuery()方法代码
public static int ExecuteNonQuery(CommandType type, string text, params SqlParameter[] para) 
  {
  using (SqlConnection conn = new SqlConnection(SQLConnectionString))
  {
  SqlCommand comm = new SqlCommand();
  PrepareCommand(comm, conn, type, text, para);
  int values = comm.ExecuteNonQuery();
  comm.Parameters.Clear();
  return values;
  }
  }

[解决办法]
大哥if(true)怎么输入都正确啦!

还有你dal返回的已经是bool类型了,你biz还判断什么?直接返回啦!!
[解决办法]
一时半会很难看明白
------解决方案--------------------


if语句括号中判断的是BOOL型,是TRUE则执行if结构里面的语句;否则执行else。你的if后边跟的是TRUE,当然执行Mssage.show(OK)了。

[解决办法]
你的if应该是要 values吧?为什么是true?
[解决办法]
Login_BLL bll = new Login_BLL();
bool values = bll.login(model);

if (true)//这错了,逻辑错误,把true 换成 values
{
MessageBox.Show("ok");
}



[解决办法]
传一个 MOdel的 user 就可以了 还传个Pwd 干啥。。
[解决办法]
if (true)
{
MessageBox.Show("ok");
}
[解决办法]
呵呵if(ture)请问楼主是想判断什么是真勒,
if(login=ture)or false
[解决办法]

探讨
Login_BLL bll = new Login_BLL();
bool values = bll.login(model);

if (true)//这错了,逻辑错误,把true 换成 values
{
MessageBox.Show("ok");
}

[解决办法]
bool values = bll.login(model);

if (values)
{
MessageBox.Show("ok");
}
else
{
MessageBox.Show("sorry");
}
[解决办法]
if(true) 不是永远为真么 。那不就永远弹出OK了。 if(values==true)
[解决办法]
探讨

Login_BLL bll = new Login_BLL();
bool values = bll.login(model);

if (true)//这错了,逻辑错误,把true 换成 values
{
MessageBox.Show("ok");
}

[解决办法]
C# code
private const string login_sql_select = "select admins,passwords from adminusers where admins=@user and passwords=@pwd";int values = SQLHelper.ExecuteNonQuery(CommandType.Text,login_sql_select,  new SqlParameter("@user",model.Admins),  new SqlParameter("@pwd",model.Passwords));
[解决办法]
探讨

引用:
C# code

private const string login_sql_select = "select admins,passwords from adminusers where admins=@user and passwords=@pwd";
int values = SQLHelper.ExecuteNonQuery(Com……

[解决办法]
在if的前面插入断点,看看values 值到底是什么。
[解决办法]
还是自己下断点调试吧
[解决办法]
探讨

引用:
Login_BLL bll = new Login_BLL();
bool values = bll.login(model);

if (true)//这错了,逻辑错误,把true 换成 values
{
MessageBox.Show("ok");
}



热点排行