求大神找错
不知道为什么 总是无法提示修改密码 总显示原密码错误 不知道问题出哪了
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(); } }}