108 lines
2.6 KiB
C#
108 lines
2.6 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 WorkChelForm : 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 Chel chel = null;
|
|
public WorkChelForm(Chel chel = null)
|
|
{
|
|
InitializeComponent();
|
|
maleBox.SelectedIndex = 0;
|
|
birthdayBox.Value = DateTime.Now;
|
|
try
|
|
{
|
|
if (chel != null)
|
|
{
|
|
this.chel = chel;
|
|
workButton.Text = "Изменить";
|
|
fNameBox.Text = chel.FName;
|
|
sNameBox.Text = chel.SName;
|
|
tNameBox.Text = chel.TName;
|
|
maleBox.SelectedIndex = chel.Male ? 0 : 1;
|
|
birthdayBox.Value = chel.Birthday;
|
|
addressBox.Text = chel.Address;
|
|
innBox.Text = chel.INN;
|
|
snilsBox.Text = chel.SNILS;
|
|
pasportBox.Text = chel.Pasport;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
ShowError(e.Message);
|
|
workButton.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private void workButton_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (maleBox.SelectedIndex == -1) throw new Exception("Пол не указан.");
|
|
if (chel == null)
|
|
{
|
|
var s = new Chel()
|
|
{
|
|
FName = fNameBox.Text,
|
|
SName = sNameBox.Text,
|
|
TName = tNameBox.Text,
|
|
Male = maleBox.SelectedIndex == 0,
|
|
Birthday = birthdayBox.Value,
|
|
Address = addressBox.Text,
|
|
INN = innBox.Text,
|
|
SNILS = snilsBox.Text,
|
|
Pasport = pasportBox.Text
|
|
};
|
|
FuncDB.AddChel(s);
|
|
}
|
|
else
|
|
{
|
|
chel.FName = fNameBox.Text;
|
|
chel.SName = sNameBox.Text;
|
|
chel.TName = tNameBox.Text;
|
|
chel.Male = maleBox.SelectedIndex == 0;
|
|
chel.Birthday = birthdayBox.Value;
|
|
chel.Address = addressBox.Text;
|
|
chel.INN = innBox.Text;
|
|
chel.SNILS = snilsBox.Text;
|
|
chel.Pasport = pasportBox.Text;
|
|
FuncDB.ChangeChel(chel);
|
|
}
|
|
this.Close();
|
|
}
|
|
catch (Exception ex) { ShowError(ex.Message); }
|
|
}
|
|
private void canceledButton_Click(object sender, EventArgs e)
|
|
{
|
|
isCanceled = true;
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|