Example #1
0
        private void _UserBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this._UserBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.dataSet1);
            MDIParent1 my = Application.OpenForms.OfType <MDIParent1>().Single();

            my.UserRegistered();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text != null && textBox2.Text != null && textBox3.Text != null && comboBox1.SelectedIndex != -1)
                {
                    int    role = comboBox1.SelectedIndex;
                    string str  = "";

                    switch (role)
                    {
                    case 0:
                        str = "db_owner";
                        break;

                    case 1:
                        str = "DecanatRole";
                        break;

                    case 2:
                        str = "TeacherRole";
                        break;

                    case 3:
                        str = "StarostaRole";
                        break;

                    case 4:
                        str = "StudentRole";
                        break;
                    }
                    role++;

                    String     quertString = @"insert into _User (login, password, id_role) values ('" + textBox2.Text + "','" + textBox3.Text + "','" + role.ToString() + "');";
                    SqlCommand insert      = new SqlCommand(quertString, con);
                    con.Open();
                    insert.ExecuteNonQuery();
                    con.Close();

                    //СОЗДАНИЕ
                    String     quertString2 = @"EXEC sp_addlogin " + textBox2.Text + "," + textBox3.Text + ",UniverConnect";
                    SqlCommand create2      = new SqlCommand(quertString2, con);
                    con.Open();
                    create2.ExecuteNonQuery();
                    con.Close();
                    String     quertString3 = @"EXEC sp_adduser " + textBox2.Text + "," + textBox1.Text + "";
                    SqlCommand create3      = new SqlCommand(quertString3, con);
                    con.Open();
                    create3.ExecuteNonQuery();
                    con.Close();
                    String     quertString4 = @"EXEC sp_addrolemember " + str + "," + textBox1.Text + " ";
                    SqlCommand create4      = new SqlCommand(quertString4, con);
                    con.Open();
                    create4.ExecuteNonQuery();
                    con.Close();
                    MDIParent1 my = Application.OpenForms.OfType <MDIParent1>().Single();
                    my.UserRegistered();
                }
                else
                {
                    MessageBox.Show("Заполнены не все поля", "Ошибка");
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "У вас недостаточно прав!");
            }
        }