123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- 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 konkursTest14
- {
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
- private void Form2_FormClosing(object sender, FormClosingEventArgs e)
- {
- Application.Exit();
- }
- private void addUser_Click(object sender, EventArgs e)
- {
- String connString = "Data Source=CLASS3108;Initial Catalog=konkurstest;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.Add("@login", Login.Text);
- command.Parameters.Add("@password", password.Text);
-
- conn.Open();
- try
- {
- if (AdminButton.Checked)
- {
- command.Parameters.Add("@admin", "1");
- }else
- {
- command.Parameters.Add("@admin", "0");
- }
- if (ManagerButton.Checked)
- {
- command.Parameters.Add("@manager", "1");
- }
- else
- {
- command.Parameters.Add("@manager", "0");
- }
- command.ExecuteNonQuery();
- MessageBox.Show("Пользователь успешно добавлен", "успешно", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- }
- }
- private void panel1_Paint(object sender, PaintEventArgs e)
- {
- }
- private void Login_Enter(object sender, EventArgs e)
- {
- if (Login.Text == "Введите логин")
- {
- Login.Text = "";
- }
- }
- private void Login_Leave(object sender, EventArgs e)
- {
- if (Login.Text == "")
- {
- Login.Text = "Введите логин";
- }
- }
- private void password_Enter(object sender, EventArgs e)
- {
- if (password.Text == "Введите пароль")
- {
- password.Text = "";
- }
- }
- private void password_Leave(object sender, EventArgs e)
- {
- if (password.Text == "")
- {
- password.Text = "Введите пароль";
- }
- }
- private void Delete_Click(object sender, EventArgs e)
- {
- String connString = "Data Source=CLASS3108;Initial Catalog=konkurstest;Integrated Security=True";
- SqlConnection conn = new SqlConnection(connString);
- SqlCommand command = new SqlCommand("DELETE FROM users where login = @login", conn);
- command.Parameters.Add("@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);
- }
- finally
- {
- }
- }
- private void LoginDel_Enter(object sender, EventArgs e)
- {
- if(LoginDel.Text == "Введите логин")
- {
- LoginDel.Text = "";
- }
- }
- private void LoginDel_Leave(object sender, EventArgs e)
- {
- if (LoginDel.Text == "")
- {
- LoginDel.Text = "Введите логин";
- }
- }
- }
- }
|