82 lines
1.9 KiB
C#
82 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_O.DataBase;
|
|||
|
|
|||
|
namespace Diplom_O.SupportForms
|
|||
|
{
|
|||
|
public partial class WorkShtatForm : Form
|
|||
|
{
|
|||
|
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();
|
|||
|
}
|
|||
|
|
|||
|
public bool isCanceled = false;
|
|||
|
private Shtat shtat = null;
|
|||
|
public WorkShtatForm(Shtat shtat = null)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
try
|
|||
|
{
|
|||
|
if (shtat != null)
|
|||
|
{
|
|||
|
this.shtat = shtat;
|
|||
|
workButton.Text = "Изменить";
|
|||
|
doljBox.Text = shtat.Doljnost;
|
|||
|
kolvoBox.Text = shtat.Size.ToString();
|
|||
|
busySizeLabel.Text = "Занято: " + FuncDB.BusySizeShtat(shtat.Id);
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
ShowError(e.Message);
|
|||
|
workButton.Enabled = false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void workButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (!int.TryParse(kolvoBox.Text, out int kolvo)) throw new Exception("Ошибка указания количества.");
|
|||
|
if (shtat == null)
|
|||
|
{
|
|||
|
var s = new Shtat() { Doljnost = doljBox.Text, Size = kolvo };
|
|||
|
FuncDB.AddShtat(s);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
shtat.Doljnost = doljBox.Text;
|
|||
|
shtat.Size = kolvo;
|
|||
|
FuncDB.ChangeShtat(shtat);
|
|||
|
}
|
|||
|
this.Close();
|
|||
|
}
|
|||
|
catch (Exception ex) { ShowError(ex.Message); }
|
|||
|
}
|
|||
|
private void canceledButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
isCanceled = true;
|
|||
|
this.Close();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|