为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

修改密码

2018-06-07 6页 doc 19KB 12阅读

用户头像

is_682974

暂无简介

举报
修改密码修改密码 using System; using System.Data.SqlClient; using System.Configuration; namespace SuperMarketMIS.DB { public class DBHelper { private SqlConnection connection = null; public static string ConnectionString { get { return ConfigurationManager.AppSettings[...
修改密码
修改密码 using System; using System.Data.SqlClient; using System.Configuration; namespace SuperMarketMIS.DB { public class DBHelper { private SqlConnection connection = null; public static string ConnectionString { get { return ConfigurationManager.AppSettings["cs"]; } } public SqlConnection Connection { get { if (connection == null) { string cs = ConfigurationManager.AppSettings["cs"]; connection = new SqlConnection(cs); } return connection; } } public void OpenConnection() { if (connection.State == System.Data.ConnectionState.Closed) { connection.Open(); } else if (connection.State == System.Data.ConnectionState.Broken) { connection.Close(); connection.Open(); } } public void CloseConnection() { if (connection.State == System.Data.ConnectionState.Open) { connection.Close(); } } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using SuperMarketMIS.DB; namespace SuperMarketMIS.GUI { public partial class ChangePasswordForm : Form { private string username; private DBHelper helper = null; public ChangePasswordForm(string username) { InitializeComponent(); this.username = username; helper = new DBHelper(); } private void btnReturn_Click(object sender, EventArgs e) { this.Close(); } private void btnModify_Click(object sender, EventArgs e) { if (CheckInput()) { try { SqlConnection con = helper.Connection; helper.OpenConnection(); SqlCommand command = con.CreateCommand(); command.CommandText = "update tb_sysuser set password = '" + txtNewPassword.Text + "' where username='" + username + "'"; int result = command.ExecuteNonQuery(); if (result == 1) { MessageBox.Show("修T改?成??功|", "", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("修T改?失º?ì败ã??"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { helper.CloseConnection(); } } else { MessageBox.Show("原-密??码?错ä?ª误??", "错ä?ª误??", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private bool CheckInput() { if (txtOrginalPassword.Text == "" || txtNewPassword.Text == "" || txtConfirmPassword.Text == "") { MessageBox.Show("输º?入??不?能??为a空?", "错ä?ª误??", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } else if (txtNewPassword.Text != txtConfirmPassword.Text) { MessageBox.Show("两??次ä?密??码?不?一??致?", "错ä?ª误??", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } else { return CheckOriginalPassword(); } } private bool CheckOriginalPassword() { try { SqlConnection con = helper.Connection; helper.OpenConnection(); SqlCommand command = con.CreateCommand(); command.CommandText = "select password from tb_sysuser where username='" + username + "'"; SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { if (reader["password"].ToString() == txtOrginalPassword.Text) { return true; } } } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show("系?Ì统ª3故?º障?", "错ä?ª误??", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { helper.CloseConnection(); } return false; } } }
/
本文档为【修改密码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索