不知道为什么 总是无法提示修改密码 总显示原密码错误 不知道问题出哪了
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace SuperMarket
{
public partial class ModificationPassword : Form
{
public ModificationPassword()
{
InitializeComponent();
} /// <summary>
/// 修改事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
if (Modification())
{
if (Chose())
{
MessageBox.Show("修改密码成功!");
}
else
{
MessageBox.Show("密码修改失败!");
}
}
}
public string username;
public string passwrd; /// <summary>
/// 修改密码的方法
/// </summary>
/// <returns></returns>
public bool Modification()
{
if (this.textBox1.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请输入原密码!");
this.textBox1.Focus();
return false;
}
if (this.textBox2.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请输入新密码!");
this.textBox2.Focus();
return false;
}
if (this.textBox3.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请输入确认新密码!");
this.textBox3.Focus();
return false;
}
if (this.textBox2.Text != this.textBox3.Text)
{
MessageBox.Show("新密码输入不一致!");
return false;
}
else
{
return true;
}
} public bool Chose()
{
DBHelper.OpenConnection();
string sql = string.Format("select count(*) from [Users] where UserName='{0}' and PassWord='{1}'",username,this.textBox1.Text.ToString());
SqlCommand com = new SqlCommand(sql, DBHelper.Connection);
try
{
int count = (int)com.ExecuteScalar();
if (count > 0)
{
sql = string.Format("update [Users] set PassWord='{0}' where UserName='{1}'", this.textBox2.Text.ToString(), username);
com.CommandText = sql;
if (com.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
}
}
else
{
MessageBox.Show("原密码错误");
return false;
}
}
catch (Exception)
{ throw;
}
finally
{
DBHelper.CloseConnection();
}
}
/// <summary>
/// 返回事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("你是否要返回商品管理界面?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
if (result==DialogResult.Yes)
{
this.Hide();
SuperMarketManage sp = new SuperMarketManage();
sp.Show();
}
} }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace SuperMarket
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
/// <summary>
/// 登录时间
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
if (ChickMessage())
{
if (ChickLogin())
{
MessageBox.Show("登录成功!");
this.Hide();
SuperMarketManage spu = new SuperMarketManage();
spu.Show();
}
else
{
MessageBox.Show("帐号或者密码错误!请重新输入!");
}
}
} /// <summary>
/// 验证登录的方法
/// </summary>
public bool ChickLogin()
{
bool flag = false;
ModificationPassword mp = new ModificationPassword();
mp.username = this.textBox1.Text.Trim().ToString();
mp.passwrd = this.textBox2.Text.Trim().ToString();
string sql = string.Format("select count(*) from Users where UserName='{0}' and PassWord='{1}'",mp.username,mp.passwrd);
try
{
DBHelper.OpenConnection();
SqlCommand com = new SqlCommand(sql,DBHelper.Connection);
int count = (int)com.ExecuteScalar();
if (count>0)
{
flag = true;
}
}
catch (Exception)
{
throw;
}
finally
{
DBHelper.CloseConnection();
}
return flag;
}
/// <summary>
/// 验证是否有输入
/// </summary>
/// <returns></returns>
public bool ChickMessage()
{
if (this.textBox1.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请输入帐号!");
this.textBox1.Focus();
return false;
}
if (this.textBox2.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请输入密码!");
this.textBox2.Focus();
return false;
}
else
{
return true;
}
} public void Exit()
{
DialogResult result = MessageBox.Show("你是否取消登录并退出!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result==DialogResult.Yes)
{
Application.Exit();
}
} private void button2_Click(object sender, EventArgs e)
{
Exit();
}
}
}
解决方案 »
- (急)C#winform中怎么将excel 2007导入到sqlserver2005【以前没弄过】
- 为何总是提示“使用未赋值的局部变量”呢?我已经赋值了呀?
- 求一坐标点的算法,数学问题,用C#实现谢谢
- 几道经典的面试题大家看看
- 请教关于C#窗体问题
- 如何打印WinForm DataGrid数据
- 该项目不存在目标 GetTargetPath
- 存储过程怎么更新?
- 点击主下拉菜单,比如open,如何触发弹出另一个窗口
- 请教关于程序原代码的安全性!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 把字符串转成整型报错以前从来没有碰到过和datatime扯上了
- 求教C#如何动态地创建多个Windows服务?
在调试过程中,将这句放到查询分析器里看看返回的结果是不是大于0,如果等于0,说明输入的用户名或密码与数据库中的不一致