123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace KokursTest2
- {
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- String connstring = "Data Source=DESKTOP-Q8BTJMH;Initial Catalog=konkurs;Integrated Security=True";
- SqlConnection conn = new SqlConnection(connstring);
- conn.Open();
- SqlCommand command = new SqlCommand("Insert INTO users (login,password,admin,manager)VALUES(@login,@password,@admin,@manager)", conn);
- command.Parameters.Add("@login", textBox1.Text);
- command.Parameters.Add("@password", textBox2.Text);
-
-
- if (radioButton1.Checked)
- {
- command.Parameters.Add("@admin", "1");
- }
- else
- {
- command.Parameters.Add("@admin", "0");
- }
- if (radioButton2.Checked)
- {
- command.Parameters.Add("@manager", "1");
- }
- else
- {
- command.Parameters.Add("@manager", "0");
- }
- try
- {
-
- command.ExecuteNonQuery();
- MessageBox.Show("Пользователь успешно добавлен","Успешно",MessageBoxButtons.OK,MessageBoxIcon.Information);
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- }
-
- }
- private void Form2_FormClosing(object sender, FormClosingEventArgs e)
- {
- Application.Exit();
- }
- private void panel1_Paint(object sender, PaintEventArgs e)
- {
- }
- private void textBox2_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox1_Enter(object sender, EventArgs e)
- {
- if (textBox1.Text == "Введите логин")
- {
- textBox1.Text = "";
- }
- }
- private void textBox1_Leave(object sender, EventArgs e)
- {
- if (textBox1.Text == "")
- {
- textBox1.Text = "Введите логин";
- }
- }
- private void textBox2_Enter(object sender, EventArgs e)
- {
- if (textBox2.Text == "Введите пароль")
- {
- textBox2.Text = "";
- }
- }
- private void textBox2_Leave(object sender, EventArgs e)
- {
- if (textBox2.Text == "")
- {
- textBox2.Text = "Введите пароль";
- }
- }
- private void textBox3_TextChanged(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- String connstring = "Data Source=DESKTOP-Q8BTJMH;Initial Catalog=konkurs;Integrated Security=True";
- SqlConnection conn = new SqlConnection(connstring);
- conn.Open();
- SqlCommand command = new SqlCommand("DELETE FROM users WHERE login = @login", conn);
- command.Parameters.Add("@login", textBox3.Text);
- try
- {
- command.ExecuteNonQuery();
- MessageBox.Show("Пользователь успешно удален", "Успешно", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- }
- }
- }
- }
|