using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
namespace AddToRole
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Server server = new Server(Instance.Text);
            Database database = server.Databases[Database.Text];
            if (!database.Users[User.TabIndex].IsMember(Roles.SelectedItem.ToString()))
            {
                database.Roles[Roles.SelectedItem.ToString()].AddMember(User.Text);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Server server = new Server(Instance.Text);
            Database database = server.Databases[Database.Text];
            Roles.Items.Clear();
            foreach (DatabaseRole role in database.Roles)
            {
                Roles.Items.Add(role.Name);
            }
        }
    }
}