Пример #1
0
        private void pbBackTo_Click(object sender, EventArgs e)
        {
            this.Visible       = false;
            this.ShowInTaskbar = false;
            Glavnoe view = new Glavnoe();

            view.ShowDialog();
        }
Пример #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtLogin.Text != "" && txtPassword.Text != "" && txtName.Text != "" && txtRole.Text != "")
            {
                using (SqlConnection conn = new SqlConnection(@"Data Source = .\SQLEXPRESS; Initial Catalog = I001CRUD; Persist Security Info=True; User ID = student; Password = passw0rd"))
                {
                    try
                    {
                        conn.Open();
                        SqlCommand cmd = conn.CreateCommand();
                        cmd.CommandText = "UPDATE [Users] SET Name='" + txtName.Text + "', Login='******', Password='******',  IsAdmin='" + txtRole.Text + "' Where [Users].ID =" + Id;
                        cmd.ExecuteScalar();
                        conn.Close();

                        Glavnoe view = new Glavnoe();
                        view.Visible       = true;
                        view.ShowInTaskbar = true;
                        this.Close();
                        GC.Collect();
                    }
                    catch (Exception ex)
                    {
                        if ("-2146232060" == Convert.ToString(ex.HResult))
                        {
                            MessageBox.Show("Логин занят");
                        }
                        else
                        {
                            MessageBox.Show(Convert.ToString(ex));
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Введите данные!");
            }
        }
Пример #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtLogin.Text != "" && txtPassword.Text != "" && txtName.Text != "" && txtRole.Text != "")
            {
                using (SqlConnection con = new SqlConnection(@"Data Source = .\SQLEXPRESS; Initial Catalog = I001CRUD; Persist Security Info=True; User ID = student; Password = passw0rd"))
                {
                    try
                    {
                        con.Open();
                        SqlCommand cmd = con.CreateCommand();
                        cmd.CommandText = "INSERT Users (Name, Login, Password, IsAdmin) VALUES ('" + txtName.Text + "','" + txtLogin.Text + "','" + txtPassword.Text + "','" + txtRole.Text + "')";
                        cmd.ExecuteScalar();
                        con.Close();

                        this.Hide();
                        Glavnoe info = new Glavnoe();
                        info.Visible       = true;
                        info.ShowInTaskbar = true;
                    }
                    catch (Exception ex)
                    {
                        if ("-2146232060" == Convert.ToString(ex.HResult))
                        {
                            MessageBox.Show("Логин занят");
                        }
                        else
                        {
                            MessageBox.Show(Convert.ToString(ex));
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Заполните все поля");
            }
        }