Diplom_O/SupportForms/WorkChelForm.cs

108 lines
2.6 KiB
C#
Raw Normal View History

2021-07-23 16:44:42 +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;
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();
2021-07-25 09:43:21 +05:00
maleBox.SelectedIndex = 0;
birthdayBox.Value = DateTime.Now;
2021-07-23 16:44:42 +05:00
try
{
2021-07-25 09:43:21 +05:00
if (chel != null)
2021-07-23 16:44:42 +05:00
{
2021-07-25 09:43:21 +05:00
this.chel = chel;
2021-07-23 16:44:42 +05:00
workButton.Text = "Изменить";
2021-07-25 09:43:21 +05:00
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;
2021-07-23 16:44:42 +05:00
}
}
catch (Exception e)
{
ShowError(e.Message);
workButton.Enabled = false;
}
}
private void workButton_Click(object sender, EventArgs e)
{
try
{
2021-07-25 09:43:21 +05:00
if (maleBox.SelectedIndex == -1) throw new Exception("Пол не указан.");
if (chel == null)
2021-07-23 16:44:42 +05:00
{
2021-07-25 09:43:21 +05:00
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);
2021-07-23 16:44:42 +05:00
}
else
{
2021-07-25 09:43:21 +05:00
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);
2021-07-23 16:44:42 +05:00
}
this.Close();
}
catch (Exception ex) { ShowError(ex.Message); }
}
private void canceledButton_Click(object sender, EventArgs e)
{
isCanceled = true;
this.Close();
}
}
}