日期:2014-05-17  浏览次数:20976 次

求大神找错

不知道为什么 总是无法提示修改密码 总显示原密码错误 不知道问题出哪了
C# code
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)
            {