예제 #1
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            RecalcMask    pass    = new RecalcMask();
            StringBuilder sqlText = new StringBuilder();

            sqlText.Append("insert into  ");
            sqlText.Append("	tbl_access  ");
            sqlText.Append("		(acc_uname, ");
            sqlText.Append("		acc_upassword, ");
            sqlText.Append("		acc_ulevel, ");
            sqlText.Append("		acc_ustate, ");
            sqlText.Append("		acc_uvalid,acc_uid) ");
            sqlText.Append("values ");
            sqlText.AppendFormat("	('{0}','{1}',{2},0,1,{3}) ", txt_username.Text, pass.CalcMask(txt_mask.Text), cmb_userLevel.Text, maxSerial + 1);
            using (SqlConnection con = new SqlConnection(_connectionString))
            {
                con.Open();
                using (SqlCommand com = new SqlCommand(sqlText.ToString(), con))
                {
                    int i = -1;
                    i = com.ExecuteNonQuery();
                    if (i <= 0)
                    {
                        MessageBox.Show("失败");
                    }
                    else
                    {
                        MessageBox.Show("成功");
                    }
                }
            }
            this.Close();
        }
예제 #2
0
        private void btn_submit_Click(object sender, EventArgs e)
        {
            //校验用户原始密码是否正确
            StringBuilder sqlText = new StringBuilder();
            RecalcMask    pass    = new RecalcMask();

            sqlText.AppendFormat("SELECT " +
                                 "                           isnull(acc_uname,'-1') as acc_uname " +
                                 "                    FROM tbl_access " +
                                 "                    WHERE " +
                                 "acc_uid = {0} " +
                                 "AND acc_uvalid = 1 " +
                                 "AND acc_ustate = 0 " +
                                 "AND acc_upassword = '******' ",
                                 (string.IsNullOrWhiteSpace(txt_userid.Text) ? "(-1)" : txt_userid.Text), pass.CalcMask(txt_password.Text));
            using (SqlConnection conn = new SqlConnection(_connectString))
            {
                object o;

                conn.Open();
                using (SqlCommand com = new SqlCommand(sqlText.ToString(), conn))
                {
                    o = com.ExecuteScalar();
                    if (o == null)
                    {
                        MessageBox.Show("修改失败,请校验ID及密码!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                sqlText.Remove(0, sqlText.Length);
                sqlText.Append("update ");
                sqlText.Append("    tbl_access ");
                sqlText.Append("set ");
                sqlText.AppendFormat("    acc_uname = '{0}', ", (string.IsNullOrWhiteSpace(txt_username.Text) ? _userName : txt_username.Text));
                sqlText.AppendFormat("    acc_upassword = '******' ", pass.CalcMask(txt_newPass.Text));
                sqlText.Append("where ");
                sqlText.AppendFormat("    acc_uid = {0} ", txt_userid.Text);
                using (SqlCommand com = new SqlCommand(sqlText.ToString(), conn))
                {
                    int i = -1;
                    i = com.ExecuteNonQuery();
                    if (i <= 0)
                    {
                        MessageBox.Show("失败");
                    }
                    else
                    {
                        MessageBox.Show("成功");
                    }
                }
            }
            //校验新密码和确认密码是否一致
            //提交数据库变更
        }
예제 #3
0
        private void btn_submit_Click(object sender, EventArgs e)
        {
            StringBuilder queryText = new StringBuilder();
            RecalcMask    password  = new RecalcMask();

            // if(txt_username.Text.Equals(string.IsNullOrWhiteSpace()))
            queryText.AppendFormat("SELECT " +
                                   "                           acc_uname as userName," +
                                   "                           acc_ulevel as userLevel," +
                                   "                           acc_uid as userID," +
                                   "                           acc_uvalid as userValid" +
                                   "                    FROM tbl_access " +
                                   "                    WHERE " +
                                   "acc_uid = {0} " +
                                   "AND acc_uvalid = 1 " +
                                   "AND acc_ustate = 0 " +
                                   "AND acc_upassword = '******' ",
                                   (string.IsNullOrWhiteSpace(txt_username.Text)?"(-1)":txt_username.Text), password.CalcMask(txt_password.Text));
            using (SqlConnection connect = new SqlConnection(_connectString))
            {
                if (connect.State != ConnectionState.Open)
                {
                    try
                    {
                        connect.Open();
                        //}
                        //catch
                        //{
                        //    MessageBox.Show("数据通信错误!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
                        //}

                        using (SqlCommand com = new SqlCommand(queryText.ToString(), connect))
                        {
                            SqlDataReader dReader = com.ExecuteReader();
                            if (dReader.HasRows)
                            {
                                dReader.Read();
                                _userName   = dReader.GetString(dReader.GetOrdinal("userName"));
                                _userLevel  = dReader.GetInt32(dReader.GetOrdinal("userLevel"));
                                _userID     = dReader.GetInt32(dReader.GetOrdinal("userID"));
                                _userValid  = dReader.GetBoolean(dReader.GetOrdinal("userValid"));
                                _loginState = 1;
                                this.Close();
                            }
                            else
                            {
                                _loginState = 0;
                                MessageBox.Show("登录失败,请校验ID及密码!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                connect.Close();
            }
        }