コード例 #1
0
ファイル: UserDAO.cs プロジェクト: petre23/Proiect-PAW
        public List<User> GetAllUsers()
        {
            List<User> userList = new List<User>();
            using (_connection)
            {
                _connection.Open();
                string selectString = "SELECT * FROM SYS_USER";
                command.CommandText = selectString;
                var reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        User user = new User();
                        user.Username = reader["Username"].ToString();
                        user.IsAdmin = Convert.ToBoolean(reader["IsAdmin"]);
                        userList.Add(user);
                    }
                    reader.Close();
                }
                _connection.Close();
            }
            return userList;
        }
コード例 #2
0
ファイル: UserDAO.cs プロジェクト: petre23/Proiect-PAW
        public void DeleteUser(User usr)
        {
            using (_connection)
            {
                _connection.Open();
                string deleteString = "DELETE FROM SYS_USER WHERE UserNmae = @Username";
                command.CommandText = deleteString;

                command.Parameters.Add("@Username", usr.Username);

                command.ExecuteNonQuery();

                _connection.Close();
            }
        }
コード例 #3
0
 public LoginFormController(ILoginForm form)
 {
     _form = form;
     user = new User();
     userDAO = new UserDAO();
 }
コード例 #4
0
ファイル: UserDAO.cs プロジェクト: petre23/Proiect-PAW
        public bool InsertUser(User usr)
        {
            try
            {
                using (_connection)
                {
                    _connection.Open();
                    string insertString = "INSERT INTO SYS_USER(Username,Password) VALUES(@Username,@Password)";
                    command.CommandText = insertString;

                    usr.Password = Sha256Encrypt(usr.Password);

                    command.Parameters.Add("@Username", usr.Username);
                    command.Parameters.Add("@Password", usr.Password);

                    command.ExecuteNonQuery();

                    _connection.Close();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
コード例 #5
0
ファイル: UserDAO.cs プロジェクト: petre23/Proiect-PAW
        public void UpdatetUser(User usr)
        {
            using (_connection)
            {
                _connection.Open();
                string updateString = "UPDATE SYS_USER SET UserNmae = @Username,Password = @Password";
                command.CommandText = updateString;

                usr.Password = Sha256Encrypt(usr.Password);

                command.Parameters.Add("@Username", usr.Username);
                command.Parameters.Add("@Password", usr.Password);

                command.ExecuteNonQuery();

                _connection.Close();
            }
        }
コード例 #6
0
ファイル: UserDAO.cs プロジェクト: petre23/Proiect-PAW
        public bool SuccesfullLogin(User usr)
        {
            InitConnection();
            using (_connection)
            {
                _connection.Open();
                string selectString = "SELECT * FROM SYS_USER WHERE Username = @Username AND Password = @Password";
                command.CommandText = selectString;

                usr.Password = Sha256Encrypt(usr.Password);

                command.Parameters.Add("@Username", usr.Username);
                command.Parameters.Add("@Password", usr.Password);

                var reader = command.ExecuteReader();

                if (reader.HasRows)
                    return true;

                reader.Close();
                _connection.Close();
            }
            return false;
        }
コード例 #7
0
 public RegisterFormController(IRegisterForm form)
 {
     _form = form;
     user = new User();
     userDAO = new UserDAO();
 }