示例#1
0
        private void EditUser()
        {
            int curRowIdx = dgvUser.CurrentRow.Index;

            DataRow editRow = dataTableUser.Rows[curRowIdx];

            editRow["FullName"] = txtFullName.Text;
            editRow["UserName"] = txtUserName.Text;
            editRow["PassWord"] = MyUtils.MD5Hash(txtPassWord.Text);

            sqlHelper.Update(dataTableUser);
        }
示例#2
0
        private void AddUser()
        {
            DataRow newRow = dataTableUser.NewRow();

            newRow["FullName"] = txtFullName.Text;
            newRow["UserName"] = txtUserName.Text;
            newRow["PassWord"] = MyUtils.MD5Hash(txtPassWord.Text);

            dataTableUser.Rows.Add(newRow);
            sqlHelper.Update(dataTableUser);
            GetDataGridView();
        }
示例#3
0
        /// <summary>
        /// Cập nhật thông tin người dùng
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="fullName"></param>
        /// <param name="passWord"></param>
        /// <returns>
        /// Return true nếu thành công
        /// </returns>
        public static bool UpdateUser(int userID, string fullName, string passWord)
        {
            string cmd = "dbo.UpdateUser";

            int res = SqlHelper.ExecuteNonQuery(
                SqlHelper.defaultConnStr,
                cmd,
                CommandType.StoredProcedure,
                UserIDParam(userID),
                FullNameParam(fullName),
                PassWordParam(MyUtils.MD5Hash(passWord))
                );

            return(res == 1);
        }
示例#4
0
        /// <summary>
        /// Đăng nhập
        /// </summary>
        /// <param name="userName">Tên tài khoản</param>
        /// <param name="passWord">Mật khẩu</param>
        /// <returns>
        /// Trả về UserID nếu thành công, ngược lại trả về -1
        /// </returns>
        public static int Login(string userName, string passWord)
        {
            string cmd = "dbo.Login";

            SqlDataReader reader = SqlHelper.ExecuteReader(
                SqlHelper.defaultConnStr,
                cmd,
                CommandType.StoredProcedure,
                UserNameParam(userName), PassWordParam(MyUtils.MD5Hash(passWord))
                );

            if (reader.HasRows)
            {
                reader.Read();
                return(Convert.ToInt32(reader["UserID"].ToString()));
            }

            return(-1);
        }