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 { 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; phoneBox.Text = chel.Phone; innBox.Text = chel.INN; snilsBox.Text = chel.SNILS; pasportBox.Text = chel.Pasport; checkBox1.Checked = chel.Pensia; } } catch (Exception e) { this.ShowError(errorLabel, e.Message); workButton.Enabled = false; } } private void workButton_Click(object sender, EventArgs e) { try { if (maleBox.SelectedIndex == -1) throw new Exception("Пол не указан."); var _chel = new Chel(); _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.Phone = phoneBox.Text; _chel.INN = innBox.Text; _chel.SNILS = snilsBox.Text; _chel.Pasport = pasportBox.Text; _chel.Pensia = checkBox1.Checked; FuncDB.ChelCheckValid(_chel); if (chel == null) FuncDB.ChelAdd(_chel); else { _chel.Id = chel.Id; FuncDB.ChelChange(_chel); } this.Close(); } catch (Exception ex) { this.ShowError(errorLabel, ex.Message); } } private void canceledButton_Click(object sender, EventArgs e) { isCanceled = true; this.Close(); } } }