123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- 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 Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void sing_in_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("SELECT * FROM users WHERE login = @login AND password = @password", conn);
- command.Parameters.AddWithValue("@login", login.Text);
- command.Parameters.AddWithValue("@password", password.Text);
- conn.Open();
- SqlDataReader Reader = null;
- try
- {
- Reader = command.ExecuteReader();
- if (Reader.HasRows)
- {
- Reader.Read();
- int rols = 0;
- if((Reader["admin"].ToString()) == "1" &&(adminCheck.Checked))
- {
- Form2 fr2 = new Form2();
- fr2.Show();
- this.Hide();
- rols = 1;
- }
- if ((Reader["manager"].ToString() == "1")&& (managerCheck.Checked))
- {
- Form3 fr3 = new Form3();
- fr3.Show();
- this.Hide();
- rols = 1;
- }
- if (rols == 0)
- {
- MessageBox.Show("Выбрана неправильная роль", "ошибка авторизации", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- else
- {
- MessageBox.Show("Неправильно введен логин или пароль", "ошибка авторизации", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message.ToString(),"", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void password_TextChanged(object sender, EventArgs 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 = "Введите пароль";
- }
- }
- }
- }
|