12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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 testkonkurs1
- {
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
- private void AddUser_Click(object sender, EventArgs e)
- {
- string connString = "Data Source=DESKTOP-Q8BTJMH;Initial Catalog=Testkonkurs;Integrated Security=True";
- SqlConnection conn = new SqlConnection(connString);
- SqlCommand command = new SqlCommand("INSERT INTO users(login,password,admin,manager)VALUES(@login,@password,@admin,@manager)", conn);
- command.Parameters.AddWithValue("@login", login.Text);
- command.Parameters.AddWithValue("@password", password.Text);
- if (admin.Checked)
- {
- command.Parameters.AddWithValue("@admin", "1");
- }
- else
- {
- command.Parameters.AddWithValue("@admin", "0");
- }
- if (manager.Checked)
- {
- command.Parameters.AddWithValue("@manager", "1");
- }
- else
- {
- command.Parameters.AddWithValue("@manager", "0");
- }
- conn.Open();
- try
- {
- command.ExecuteNonQuery();
- MessageBox.Show("пользователь успешно добавлен", "Успешно", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void Form2_FormClosing(object sender, FormClosingEventArgs e)
- {
- Application.Exit();
- }
- private void Delete_Click(object sender, EventArgs e)
- {
- string connString = "Data Source=DESKTOP-Q8BTJMH;Initial Catalog=Testkonkurs;Integrated Security=True";
- SqlConnection conn = new SqlConnection(connString);
- SqlCommand command = new SqlCommand("DELETE FROM users WHERE login = @login", conn);
- command.Parameters.AddWithValue("@login", LoginDel.Text);
- conn.Open();
- try
- {
- command.ExecuteNonQuery();
- MessageBox.Show("Пользователь успешно удален", "Успешно", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
|