Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 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. InitializeComponent();
  18. CreateUsers();
  19. }
  20. AdminPanel _AdminPanel;
  21. UserPanel _UserPanel;
  22.  
  23. string[,] userdata = new string[4, 3];
  24.  
  25. private void CreateUsers()
  26. {
  27. userdata[0, 0] = "jan";
  28. userdata[0, 1] = "abc123";
  29. userdata[0, 2] = "0";
  30.  
  31. userdata[1, 0] = "adma";
  32. userdata[1, 1] = "123456";
  33. userdata[1, 2] = "0";
  34.  
  35. userdata[2, 0] = "admin";
  36. userdata[2, 1] = "12345";
  37. userdata[2, 2] = "1";
  38.  
  39. userdata[3, 0] = "admin2";
  40. userdata[3, 1] = "pass";
  41. userdata[3, 2] = "1";
  42. }
  43.  
  44.  
  45. private void LoginButton_Click(object sender, EventArgs e)
  46. {
  47. if(txt_login.Text.Length == 0)
  48. {
  49. txt_login.Focus();
  50. }
  51.  
  52. if(txt_password.Text.Length == 0)
  53. {
  54. txt_password.Focus();
  55. }
  56. auth(txt_login.Text, txt_password.Text);
  57. }
  58.  
  59. private void CloseButton_Click(object sender, EventArgs e)
  60. {
  61. Close();
  62. }
  63.  
  64. private void auth(string user, string password)
  65. {
  66. for(int i = 0; i < userdata.GetLength(0); i++)
  67. {
  68. if(user== userdata[i,0] && password == userdata[i, 1] && userdata[i,2] == "1")
  69. {
  70. if ((_AdminPanel = (AdminPanel)checkifwinopen(typeof(AdminPanel))) == null)
  71. {
  72. _AdminPanel = new AdminPanel();
  73. _AdminPanel.Show();
  74. }
  75. else _AdminPanel.BringToFront();
  76. break;
  77. }
  78.  
  79. if (user == userdata[i, 0] && password == userdata[i, 1] && userdata[i, 2] == "0")
  80. {
  81. if ((_UserPanel = (UserPanel)checkifwinopen(typeof(UserPanel))) == null)
  82. {
  83. _UserPanel = new UserPanel();
  84. _UserPanel.Show();
  85. }
  86. else _UserPanel.BringToFront();
  87. break;
  88. }
  89. }
  90.  
  91. }
  92. private Form checkifwinopen(Type FormType)
  93. {
  94. foreach(Form OpenForm in Application.OpenForms)
  95. {
  96. if (OpenForm.GetType() == FormType) return OpenForm;
  97. }
  98. return null;
  99. }
  100. }
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement