Diplom_B/LoginForm.cs

84 lines
1.9 KiB
C#
Raw Normal View History

2021-07-15 12:21:22 +05:00
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;
2021-07-17 22:32:53 +05:00
using Diplom_B.DB;
2021-07-15 12:21:22 +05:00
namespace Diplom_B
{
2021-07-16 16:43:55 +05:00
public partial class LoginForm : Form
2021-07-15 12:21:22 +05:00
{
2021-07-16 16:43:55 +05:00
public LoginForm()
2021-07-15 12:21:22 +05:00
{
InitializeComponent();
2021-07-17 22:32:53 +05:00
Init();
2021-07-15 12:21:22 +05:00
}
2021-07-17 22:32:53 +05:00
public void Init()
{
nameBox.Items.AddRange(WorkDB.GetUserList());
}
private Task errDrop;
private void ShowError(string msg = null)
{
errorLabel.Text = string.IsNullOrEmpty(msg) ? "Неизвестная ошибка." : msg;
errorLabel.Visible = true;
errDrop = new Task(() =>
{
var fd = errDrop.Id;
Task.Delay(5000).Wait();
if (errDrop.Id == fd)
if (InvokeRequired) Invoke((Action)(() => { errorLabel.Visible = false; }));
else errorLabel.Visible = false;
});
errDrop.Start();
}
private void loginButton_Click(object sender, EventArgs e)
2021-07-15 12:21:22 +05:00
{
2021-07-17 22:32:53 +05:00
errorLabel.Text = "";
var usr = new User(nameBox.Text, passBox.Text);
2021-07-15 12:21:22 +05:00
if (!usr.CheckUser())
{
2021-07-17 22:32:53 +05:00
ShowError("Пользователя нет");
2021-07-15 12:21:22 +05:00
return;
}
if (!usr.Login())
{
2021-07-17 22:32:53 +05:00
ShowError("Неверный пароль");
2021-07-15 12:21:22 +05:00
return;
}
2021-07-17 09:33:09 +05:00
Program.user = usr;
2021-07-17 22:32:53 +05:00
object form = null;
switch(usr.Usr.Default)
{
case 0: form = new DogForm(); break;
case 1: form = new DocForm(); break;
case 2: form = new IzvForm(); break;
case 3: form = new PostForm(); break;
case 4: form = new IzdForm(); break;
case 5: form = new ZakForm(); break;
case 6: form = new SetForm(); break;
}
if (form == null) this.Close();
2021-07-17 09:33:09 +05:00
2021-07-15 16:58:51 +05:00
this.Hide();
2021-07-17 22:32:53 +05:00
((Form)form).Closed += (s, args) => this.Close();
((Form)form).Show();
}
private void keyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
loginButton_Click(this, new EventArgs());
2021-07-15 12:21:22 +05:00
}
2021-07-17 22:32:53 +05:00
}
2021-07-15 12:21:22 +05:00
}