Newer
Older
GHFX_REFACTOR / Forms / FrmEditUser.cs
wxn on 2 Nov 2016 2 KB 提交
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Data.SqlClient;

namespace PipeLine.Forms
{
    public partial class FrmEditUser : Office2007Form
    {
        private SqlConnection sqlConnection = null;
        private string currentUser;
        public FrmEditUser(string username)
        {
            InitializeComponent();
            currentUser = username;
            this.sqlConnection = new SqlConnection("Data Source=" + Utility.DBServer + ";Initial Catalog=" + Utility.dbdatabase + ";Persist Security Info=True;User ID=" + Utility.userID + ";pwd=" + Utility.DBPassword + "");
        }

        private void FrmEditUser_Load(object sender, EventArgs e)
        {
            txtUser.Text = currentUser;
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtUser.Text.Trim() == "" || txtPass.Text == "" || txtPsd.Text == "" || txtPsdConfirm.Text == "")
                {
                    MessageBox.Show("请输入完整信息!", "提示!");

                }
                else
                {
                    sqlConnection.Open();
                    SqlCommand cmd = new SqlCommand("", sqlConnection);
                    string sql = "select * from users where username = '" + txtUser.Text.Trim() + "'and password='" + txtPass.Text + "'";
                    cmd.CommandText = sql;
                    if (null != cmd.ExecuteScalar())
                    {
                        if (txtPsd.Text != txtPsdConfirm.Text)
                        {
                            MessageBox.Show("俩次密码输入不一致,请重新输入!", "警告!");
                        }
                        else
                        {
                            sql = "update users set password='" + txtPsdConfirm.Text + "' where username='" + txtUser.Text + "'";
                            cmd.CommandText = sql;
                            cmd.ExecuteNonQuery();
                            MessageBox.Show("修改密码成功!", "提示");
                            this.Close();
                        }
                    }
                    else
                        MessageBox.Show("旧密码输入错误,请重新输入!", "警告!");
                    sqlConnection.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LogError.PublishError(ex);
            }
        }
        private void btnReset_Click(object sender, EventArgs e)
        {
            txtPass.Text = "";
            txtPsd.Text = "";
            txtPsdConfirm.Text = "";
        }
    }
}