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()
- {
- InitializeComponent();
- CreateUsers();
- }
- AdminPanel _AdminPanel;
- UserPanel _UserPanel;
- string[,] userdata = new string[4, 3];
- private void CreateUsers()
- {
- userdata[0, 0] = "jan";
- userdata[0, 1] = "abc123";
- userdata[0, 2] = "0";
- userdata[1, 0] = "adma";
- userdata[1, 1] = "123456";
- userdata[1, 2] = "0";
- userdata[2, 0] = "admin";
- userdata[2, 1] = "12345";
- userdata[2, 2] = "1";
- userdata[3, 0] = "admin2";
- userdata[3, 1] = "pass";
- userdata[3, 2] = "1";
- }
- 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)
- {
- for(int i = 0; i < userdata.GetLength(0); i++)
- {
- if(user== userdata[i,0] && password == userdata[i, 1] && userdata[i,2] == "1")
- {
- if ((_AdminPanel = (AdminPanel)checkifwinopen(typeof(AdminPanel))) == null)
- {
- _AdminPanel = new AdminPanel();
- _AdminPanel.Show();
- }
- else _AdminPanel.BringToFront();
- break;
- }
- if (user == userdata[i, 0] && password == userdata[i, 1] && userdata[i, 2] == "0")
- {
- 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