Zametki.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ---------------------------------------------------------------------------------------------------------------------------------------------------------
  2. //Резерв C# команд (Win Forms)
  3. //Авторизация через базу данных:
  4. using (var db = new LeTest5Entities())
  5. {
  6. var Users1 = db.Users1.AsNoTracking().FirstOrDefault(u => u.login == textBox1.Text && u.pass == textBox2.Text);
  7. if (Users1 == null)
  8. {
  9. label4.Text = "Неверный логин/пароль";
  10. return;
  11. }
  12. switch (Users1.status)
  13. {
  14. case "admin":
  15. {
  16. admin123 sf = new admin123();
  17. sf.Owner = this;
  18. sf.Show();
  19. this.Hide();
  20. MessageBox.Show("Добро пожаловать админ!");
  21. break;
  22. }
  23. case "operator":
  24. {
  25. Products sf = new Products();
  26. sf.Owner = this;
  27. sf.Show();
  28. this.Hide();
  29. MessageBox.Show("Добро пожаловать оператор!");
  30. break;
  31. }
  32. }
  33. }
  34. ---------------------------------------------------------------------------------------------------------------------------------------------------------
  35. //Регистрация в базе данных:
  36. using (var db = new LeTest5Entities())
  37. {
  38. if (string.IsNullOrEmpty(textBox1.Text) | string.IsNullOrEmpty(textBox2.Text) | string.IsNullOrEmpty(textBox3.Text))
  39. {
  40. }
  41. else
  42. {
  43. bool registr = db.Users1.Any(u => u.login == textBox1.Text|u.pass == textBox2.Text);
  44. if (!registr)
  45. {
  46. db.Database.ExecuteSqlCommand($"INSERT INTO Users1 (login, pass, status)\nVALUES('{textBox1.Text}','{textBox2.Text}','{textBox3.Text}');");
  47. }
  48. else
  49. {
  50. }
  51. }
  52. }
  53. ---------------------------------------------------------------------------------------------------------------------------------------------------------