PosleVHODA.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Data.SqlClient;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace proba
  12. {
  13. public partial class PosleVHODA : Form
  14. {
  15. DataBase dataBase = new DataBase();
  16. public static string login;
  17. public PosleVHODA()
  18. {
  19. InitializeComponent();
  20. }
  21. private void PosleVHODA_Load(object sender, EventArgs e)
  22. {
  23. this.Size = new Size(500, 300);
  24. this.MaximumSize = new Size(500, 300);
  25. this.MinimumSize = new Size(500, 300);
  26. }
  27. private void buttonlogin(object sender, EventArgs e)
  28. {
  29. Shifr.phraze = polePassword.Text;
  30. Shifr myTeloInfo = new Shifr();
  31. myTeloInfo.ShifrCode();
  32. string password = "";
  33. for (int i = 0; i < Shifr.codePhraze.Length; i++)
  34. {
  35. password = password + Shifr.codePhraze[i];
  36. }
  37. if (polelogina.Text.Replace(" ", "") == "") MessageBox.Show("Поле логин не может быть пустым");
  38. else if (polePassword.Text.Replace(" ", "") == "") MessageBox.Show("Поле пароль не может быть пустым");
  39. else
  40. {
  41. dataBase.openConnection();
  42. string admin = "Select * from Employee where login = '" + polelogina.Text.Trim() + "' and password = '" + password + "' and id_role = 1";
  43. SqlDataAdapter sda1 = new SqlDataAdapter(admin, dataBase.GetConnection());
  44. DataTable dtbl1 = new DataTable();
  45. sda1.Fill(dtbl1);
  46. if (dtbl1.Rows.Count == 1)
  47. {
  48. login = polelogina.Text.Trim();
  49. this.Hide();
  50. MainMenu mainmenu = new MainMenu();
  51. mainmenu.ShowDialog();
  52. }
  53. else
  54. {
  55. string query = "Select * from Employee where login = '" + polelogina.Text.Trim() + "' and password = '" + password + "' and id_role = 2";
  56. SqlDataAdapter sda = new SqlDataAdapter(query, dataBase.GetConnection());
  57. DataTable dtbl = new DataTable();
  58. sda.Fill(dtbl);
  59. if (dtbl.Rows.Count == 1)
  60. {
  61. login = polelogina.Text.Trim();
  62. this.Hide();
  63. MainMenu mainmenu = new MainMenu();
  64. mainmenu.ShowDialog();
  65. }
  66. else
  67. {
  68. MessageBox.Show("Неверный логин и/или пароль");
  69. }
  70. }
  71. }
  72. }
  73. private void button_back_Click(object sender, EventArgs e)
  74. {
  75. this.Hide();
  76. Autorization autorization = new Autorization();
  77. autorization.ShowDialog();
  78. }
  79. public void global_FormClosed(object sender, EventArgs e)
  80. {
  81. Application.Exit();
  82. }
  83. private void polelogina_KeyPress(object sender, KeyPressEventArgs e)
  84. {
  85. if (e.KeyChar == (int)Keys.Space)
  86. e.KeyChar = '\0';
  87. }
  88. private void polePassword_KeyPress(object sender, KeyPressEventArgs e)
  89. {
  90. if (e.KeyChar == (int)Keys.Space)
  91. e.KeyChar = '\0';
  92. }
  93. }
  94. }