www.pudn.com > FORU(SMS).rar > SMS_editAdmin.cs


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 FORU_SMS_ 
{ 
    public partial class SMS_editAdmin : Form 
    { 
        BaseClass.DataConn Dconn = new FORU_SMS_.BaseClass.DataConn(); 
        BaseClass.DataClass Dclass = new FORU_SMS_.BaseClass.DataClass(); 
        public SMS_editAdmin() 
        { 
            InitializeComponent(); 
            this.txtName.Text = SMS_Login.login.TestValue; 
        } 
 
        private void SMS_editAdmin_Load(object sender, EventArgs e) 
        { 
            this.txtPass.Focus(); 
        } 
 
        private void button1_Click(object sender, EventArgs e) 
        { 
            if (this.txtPass.Text.Trim() == "") 
            { 
                MessageBox.Show("旧密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
            } 
            else if (this.newPass.Text.Trim() == "") 
            { 
                MessageBox.Show("新密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
            } 
            else if (this.newPass.Text.Trim().Length < 6) 
            { 
                MessageBox.Show("新密码长度至少为6位!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
            } 
            else if (this.newPass.Text.Trim() != this.confnewPass.Text.Trim()) 
            { 
                MessageBox.Show("密码不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
            } 
            else 
            { 
                SqlDataReader sqlRead = Dclass.GetRead("select Password from SMS_User where UserName='" + this.txtName.Text.Trim() + "'"); 
                if (sqlRead.Read()) 
                { 
                    if (this.txtPass.Text.Trim() != sqlRead["Password"].ToString().Trim()) 
                    { 
                        MessageBox.Show("旧密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                    } 
                    else 
                    { 
                        SqlCommand sqlcom = new SqlCommand("update SMS_User set Password=@newPass where UserName='" + this.txtName.Text.Trim() + "'",Dconn.OpenConn()); 
                        SqlDataAdapter adpter = new SqlDataAdapter(); 
                        adpter.SelectCommand = sqlcom; 
                        sqlcom.Parameters.Add("@newPass", SqlDbType.VarChar, 20).Value = this.newPass.Text.Trim(); 
                        try 
                        { 
                            sqlcom.ExecuteNonQuery(); 
                            this.Close(); 
                            MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                        } 
                        catch (Exception ex) 
                        { 
                            MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
                        } 
                    } 
                } 
                sqlRead.Close(); 
            } 
        } 
 
        private void button2_Click(object sender, EventArgs e) 
        { 
            this.Close(); 
        } 
    } 
}