123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- 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 hospital
- {
- public partial class auth : Form
- {
- public static string userID = null;
- SqlConnection sqlConnection = null;
- SqlCommand a = null;
- public static string[] data = new string[0];
- public auth()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- FormCreating.openConnection(ref sqlConnection);
- debugAndTrace.onStart();
- passwordTB.PasswordChar = '●';
- debugAndTrace.writeInFile("Вход в приложение");
- }
- private void signUpBtn_Click(object sender, EventArgs e)
- {
- registrationForm reg = new registrationForm();
- reg.Show();
- this.Hide();
- debugAndTrace.writeInFile("Переход на форму регистрации");
- reg.FormClosing += (obj, args) =>
- {
- this.Show();
- };
- }
- public static string signIn(string login, string password)
- {
- SqlConnection sqlConnection = null;
- FormCreating.openConnection(ref sqlConnection);
- SqlCommand a = null;
- if (login == "admin" && password == "admin")
- {
- return "Добро пожаловать, админ!";
- }
- else
- {
- a = new SqlCommand($"select count(*) from employees where login like {login.GetHashCode()} and password like {password.GetHashCode()} and id_post is null", sqlConnection);
- if (a.ExecuteScalar().ToString().Equals("1"))
- {
- return "Сначала вам необходимо получить роль!";
- }
- else
- {
- login = login.Trim();
- password = password.Trim();
- a = new SqlCommand($"select count(*) from employees where [login] like N'{login.GetHashCode()}' and [password] like N'{password.GetHashCode()}'", sqlConnection);
- Array.Resize(ref data, 2);
- data[0] = "Логин: " + login + "(" + login.GetHashCode() + ")";
- data[1] = "Пароль: " + password + "(" + password.GetHashCode() + ")";
- if (a.ExecuteScalar().ToString() == "1")
- {
- a = new SqlCommand($"select id_employee from employees where login like N'{login.GetHashCode()}' and password like N'{password.GetHashCode()}'", sqlConnection);
- userID = a.ExecuteScalar().ToString();
- return "Успешная авторизация!";
- }
- else
- {
- return "Такого пользователя не существует\nПроверьте правильность введенных данных, либо зарегистрируйте новый аккаунт";
- }
- }
- }
- }
- private void signInBtn_Click(object sender, EventArgs e)
- {
- if (loginTB.Text == "admin" && passwordTB.Text == "admin")
- {
- admin Admin = new admin();
- Admin.Show();
- this.Hide();
- Admin.FormClosing += (obj, args) =>
- {
- this.Show();
- };
- }
- else
- {
- a = new SqlCommand($"select count(*) from employees where login like {loginTB.Text.GetHashCode()} and password like {passwordTB.Text.GetHashCode()} and id_post is null", sqlConnection);
- if (a.ExecuteScalar().ToString().Equals("1"))
- {
- MessageBox.Show("Сначала вам необходимо получить роль!", "Ошабка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- mainMenu menu = new mainMenu();
- loginTB.Text = loginTB.Text.Trim();
- passwordTB.Text = passwordTB.Text.Trim();
- a = new SqlCommand($"select count(*) from employees where [login] like N'{loginTB.Text.GetHashCode()}' and [password] like N'{passwordTB.Text.GetHashCode()}'", sqlConnection);
- Array.Resize(ref data, 2);
- data[0] = "Логин: " + loginTB.Text + "(" + loginTB.Text.GetHashCode() + ")";
- data[1] = "Пароль: " + passwordTB.Text + "(" + passwordTB.Text.GetHashCode() + ")";
- if (a.ExecuteScalar().ToString() == "1")
- {
- a = new SqlCommand($"select id_employee from employees where login like N'{loginTB.Text.GetHashCode()}' and password like N'{passwordTB.Text.GetHashCode()}'", sqlConnection);
- userID = a.ExecuteScalar().ToString();
- debugAndTrace.writeInFile("Авторизация", data);
- debugAndTrace.writeInFile("Переход на главную форму");
- menu.Show();
- this.Hide();
- }
- else
- {
- MessageBox.Show("Такого пользователя не существует\nПроверьте правильность введенных данных, либо зарегистрируйте новый аккаунт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- debugAndTrace.writeInFile("Ошибка входа", data);
- }
- }
- }
- }
- private void auth_FormClosed(object sender, FormClosedEventArgs e)
- {
- Application.Exit();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //mainMenu menu = new mainMenu();
- //menu.Show();
- //this.Hide();
- }
- bool passwordChar = false;
- private void label1_Click(object sender, EventArgs e)
- {
- if (passwordChar)
- {
- passwordTB.PasswordChar = '●';
- passwordChar = !passwordChar;
- }
- else
- {
- passwordTB.PasswordChar = '\0';
- passwordChar = !passwordChar;
- }
- }
- private void label2_Click(object sender, EventArgs e)
- {
- }
- }
- }
|