84 lines
1.9 KiB
C#
84 lines
1.9 KiB
C#
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;
|
|
using Diplom_B.DB;
|
|
|
|
namespace Diplom_B
|
|
{
|
|
public partial class LoginForm : Form
|
|
{
|
|
public LoginForm()
|
|
{
|
|
InitializeComponent();
|
|
Init();
|
|
}
|
|
|
|
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)
|
|
{
|
|
errorLabel.Text = "";
|
|
var usr = new User(nameBox.Text, passBox.Text);
|
|
if (!usr.CheckUser())
|
|
{
|
|
ShowError("Пользователя нет");
|
|
return;
|
|
}
|
|
if (!usr.Login())
|
|
{
|
|
ShowError("Неверный пароль");
|
|
return;
|
|
}
|
|
|
|
Program.user = usr;
|
|
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();
|
|
|
|
this.Hide();
|
|
((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());
|
|
}
|
|
}
|
|
}
|