Advertisement
Guest User

Form1

a guest
Mar 26th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  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.  
  11. namespace WindowsFormsApp3
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. CreateUsers();
  18. InitializeComponent();
  19.  
  20. }
  21. AdminPanel _AdminPanel;
  22. UserPanel _UserPanel;
  23.  
  24. List<User> users = new List<User>();
  25.  
  26. private void CreateUsers()
  27. {
  28.  
  29. for (int i =0; i<7; i++)
  30. {
  31. User x = new User();
  32. x.user = "user" + i.ToString();
  33. x.password = "1234";
  34. x.isAdmin = false;
  35. users.Add(x);
  36. }
  37. for (int i = 0; i < 3; i++)
  38. {
  39. User x = new User();
  40. x.user = "admin" + i.ToString();
  41. x.password = "1234";
  42. x.isAdmin = true;
  43. users.Add(x);
  44. }
  45. }
  46.  
  47.  
  48. private void LoginButton_Click(object sender, EventArgs e)
  49. {
  50. if(txt_login.Text.Length == 0)
  51. {
  52. txt_login.Focus();
  53. }
  54.  
  55. if(txt_password.Text.Length == 0)
  56. {
  57. txt_password.Focus();
  58. }
  59. Auth(txt_login.Text, txt_password.Text);
  60. }
  61.  
  62. private void CloseButton_Click(object sender, EventArgs e)
  63. {
  64. Close();
  65. }
  66.  
  67. private void Auth(string user, string password)
  68. {
  69. foreach(User y in users)
  70. {
  71. if(user== y.user && y.passiscorrect(password) == true && y.isAdmin == true)
  72. {
  73. if ((_AdminPanel = (AdminPanel)checkifwinopen(typeof(AdminPanel))) == null)
  74. {
  75. _AdminPanel = new AdminPanel();
  76. _AdminPanel.Show();
  77. }
  78. else _AdminPanel.BringToFront();
  79. break;
  80. }
  81.  
  82. if (user == y.user && y.passiscorrect(password) == true && y.isAdmin == false)
  83. {
  84. if ((_UserPanel = (UserPanel)checkifwinopen(typeof(UserPanel))) == null)
  85. {
  86. _UserPanel = new UserPanel();
  87. _UserPanel.Show();
  88. }
  89. else _UserPanel.BringToFront();
  90. break;
  91. }
  92. }
  93.  
  94. }
  95. private Form checkifwinopen(Type FormType)
  96. {
  97. foreach(Form OpenForm in Application.OpenForms)
  98. {
  99. if (OpenForm.GetType() == FormType) return OpenForm;
  100. }
  101. return null;
  102. }
  103. }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement