Создание веб-приложения, сочетающего в себе проектирование и создание баз данных, работу со сторонними форматами данных, программирование в NET и веб-разработку, страница 65

                            id_role_user = Convert.ToInt32(reader[0].ToString());

                        }

                        reader.Close();

                        if (id_role == id_role_user)

                        {

                            conn.Close();

                            return true;

                        }

                        else

                        {

                            conn.Close();

                            return false;

                        }

                    }

                }

            }

            catch (MySqlException exp)

            {

                conn.Close();

                return false;

            }

            catch (ProviderException exp)

            {

                conn.Close();

                return false;

            }

        }

        //У i-го юзера удаляется i-я роль.

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)

        {

            MySqlConnection conn = null;

            try

            {

                if (roleNames.Length < 1 || usernames.Length < 1) throw new ProviderException();

                else if (roleNames == null || roleNames[0] == "" || usernames == null || usernames[0] == "" || roleNames.Length != usernames.Length ) throw new ProviderException();

                else

                {

                    //ОБЪЯВЛЕНИЕ

                    MySqlCommand comm;

                    conn = new MySqlConnection(connectionString);

                    conn.Open();

                    int []id_role = null;

                    string start_role = "user";

                    int id_start_role;

                    string sql = "SELECT id FROM roles WHERE name = '" + start_role + "';";

                    MySqlDataAdapter adapter;

                    DataSet data = new DataSet();

                    MySqlDataReader reader = null;

                    //ВЫТАСКИВАЕМ ID НИЗШЕЙ РОЛИ

                    adapter = new MySqlDataAdapter(sql, conn);

                    adapter.Fill(data);

                    if (data.Tables[0].Rows.Count != 1) throw new ProviderException();

                    else id_start_role = Convert.ToInt32(data.Tables[0].Rows[0]["id"].ToString());

                    //ВЫТАСКИВАЕМ ID РОЛЕЙ

                    id_role = new int[roleNames.Length];

                    for (int i = 0; i < roleNames.Length; i++)

                    {

                        sql = "SELECT id FROM roles WHERE name = '"+roleNames[i]+"';";

                        comm = new MySqlCommand(sql, conn);

                        reader = comm.ExecuteReader();

                        while (reader.Read())

                        {

                            id_role[i] = Convert.ToInt32(reader[0].ToString());

                        }

                        reader.Close();

                    }

                    //УДАЛЯЕМ ЮЗЕРОВ С РОЛЕЙ

                    for (int i = 0; i < usernames.Length; i++)

                    {

                        if (usernames[i] == null || usernames[i] == "" || roleNames[i] == null || roleNames[i] == "") throw new ProviderException();

                        else

                        {

                            sql = "SELECT role FROM auth_user WHERE name = '" + usernames[i] + "';";

                            adapter = new MySqlDataAdapter(sql, conn);

                            data = new DataSet();

                            adapter.Fill(data);

                            if (data.Tables[0].Rows.Count != 1) throw new ProviderException();

                            else if (id_role[i] == Convert.ToInt32(data.Tables[0].Rows[i]["role"].ToString()))

                            {