authorizationForm.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. namespace hospital
  12. {
  13. public partial class auth : Form
  14. {
  15. public static string userID = null;
  16. SqlConnection sqlConnection = null;
  17. SqlCommand a = null;
  18. public static string[] data = new string[0];
  19. public auth()
  20. {
  21. InitializeComponent();
  22. }
  23. private void Form1_Load(object sender, EventArgs e)
  24. {
  25. FormCreating.openConnection(ref sqlConnection);
  26. debugAndTrace.onStart();
  27. passwordTB.PasswordChar = '●';
  28. debugAndTrace.writeInFile("Вход в приложение");
  29. }
  30. private void signUpBtn_Click(object sender, EventArgs e)
  31. {
  32. registrationForm reg = new registrationForm();
  33. reg.Show();
  34. this.Hide();
  35. debugAndTrace.writeInFile("Переход на форму регистрации");
  36. reg.FormClosing += (obj, args) =>
  37. {
  38. this.Show();
  39. };
  40. }
  41. private void signInBtn_Click(object sender, EventArgs e)
  42. {
  43. if (loginTB.Text == "admin" && passwordTB.Text == "admin")
  44. {
  45. admin Admin = new admin();
  46. Admin.Show();
  47. this.Hide();
  48. Admin.FormClosing += (obj, args) =>
  49. {
  50. this.Show();
  51. };
  52. }
  53. else
  54. {
  55. 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);
  56. if (a.ExecuteScalar().ToString().Equals("1"))
  57. {
  58. MessageBox.Show("Сначала вам необходимо получить роль!", "Ошабка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  59. }
  60. else
  61. {
  62. mainMenu menu = new mainMenu();
  63. loginTB.Text = loginTB.Text.Trim();
  64. passwordTB.Text = passwordTB.Text.Trim();
  65. a = new SqlCommand($"select count(*) from employees where [login] like N'{loginTB.Text.GetHashCode()}' and [password] like N'{passwordTB.Text.GetHashCode()}'", sqlConnection);
  66. Array.Resize(ref data, 2);
  67. data[0] = "Логин: " + loginTB.Text + "(" + loginTB.Text.GetHashCode() + ")";
  68. data[1] = "Пароль: " + passwordTB.Text + "(" + passwordTB.Text.GetHashCode() + ")";
  69. if (a.ExecuteScalar().ToString() == "1")
  70. {
  71. a = new SqlCommand($"select id_employee from employees where login like N'{loginTB.Text.GetHashCode()}' and password like N'{passwordTB.Text.GetHashCode()}'", sqlConnection);
  72. userID = a.ExecuteScalar().ToString();
  73. debugAndTrace.writeInFile("Авторизация", data);
  74. debugAndTrace.writeInFile("Переход на главную форму");
  75. menu.Show();
  76. this.Hide();
  77. }
  78. else
  79. {
  80. MessageBox.Show("Такого пользователя не существует\nПроверьте правильность введенных данных, либо зарегистрируйте новый аккаунт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  81. debugAndTrace.writeInFile("Ошибка входа", data);
  82. }
  83. }
  84. }
  85. }
  86. private void auth_FormClosed(object sender, FormClosedEventArgs e)
  87. {
  88. Application.Exit();
  89. }
  90. private void button1_Click(object sender, EventArgs e)
  91. {
  92. //mainMenu menu = new mainMenu();
  93. //menu.Show();
  94. //this.Hide();
  95. }
  96. bool passwordChar = false;
  97. private void label1_Click(object sender, EventArgs e)
  98. {
  99. if (passwordChar)
  100. {
  101. passwordTB.PasswordChar = '●';
  102. passwordChar = !passwordChar;
  103. }
  104. else
  105. {
  106. passwordTB.PasswordChar = '\0';
  107. passwordChar = !passwordChar;
  108. }
  109. }
  110. private void label2_Click(object sender, EventArgs e)
  111. {
  112. }
  113. }
  114. }