Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp3
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- CreateUsers();
- InitializeComponent();
- }
- AdminPanel _AdminPanel;
- UserPanel _UserPanel;
- List<User> users = new List<User>();
- private void CreateUsers()
- {
- for (int i =0; i<7; i++)
- {
- User x = new User();
- x.user = "user" + i.ToString();
- x.password = "1234";
- x.isAdmin = false;
- users.Add(x);
- }
- for (int i = 0; i < 3; i++)
- {
- User x = new User();
- x.user = "admin" + i.ToString();
- x.password = "1234";
- x.isAdmin = true;
- users.Add(x);
- }
- }
- private void LoginButton_Click(object sender, EventArgs e)
- {
- if(txt_login.Text.Length == 0)
- {
- txt_login.Focus();
- }
- if(txt_password.Text.Length == 0)
- {
- txt_password.Focus();
- }
- Auth(txt_login.Text, txt_password.Text);
- }
- private void CloseButton_Click(object sender, EventArgs e)
- {
- Close();
- }
- private void Auth(string user, string password)
- {
- foreach(User y in users)
- {
- if(user== y.user && y.passiscorrect(password) == true && y.isAdmin == true)
- {
- if ((_AdminPanel = (AdminPanel)checkifwinopen(typeof(AdminPanel))) == null)
- {
- _AdminPanel = new AdminPanel();
- _AdminPanel.Show();
- }
- else _AdminPanel.BringToFront();
- break;
- }
- if (user == y.user && y.passiscorrect(password) == true && y.isAdmin == false)
- {
- if ((_UserPanel = (UserPanel)checkifwinopen(typeof(UserPanel))) == null)
- {
- _UserPanel = new UserPanel();
- _UserPanel.Show();
- }
- else _UserPanel.BringToFront();
- break;
- }
- }
- }
- private Form checkifwinopen(Type FormType)
- {
- foreach(Form OpenForm in Application.OpenForms)
- {
- if (OpenForm.GetType() == FormType) return OpenForm;
- }
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement