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 ChildForm : Form { private int? rod1Id = null; private void linkRod1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { var form = new ChelForm(true); form.ShowDialog(); if (form.isCanceled) rod1Id = null; else rod1Id = form.formResult.Id; linkRod1_changeName(); } private void linkRod1_changeName() { linkRod1.Text = rod1Id.HasValue ? FuncDB.ChelGetFIOShortById(rod1Id.Value) : "Выбрать человека..."; } private int? rod2Id = null; private void linkRod2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { var form = new ChelForm(true); form.ShowDialog(); if (form.isCanceled) rod2Id = null; else rod2Id = form.formResult.Id; linkRod2_changeName(); } private void linkRod2_changeName() { linkRod2.Text = rod2Id.HasValue ? FuncDB.ChelGetFIOShortById(rod2Id.Value) : "Выбрать человека..."; } public bool isCanceled = false; private Child child = null; public ChildForm(Child child = null) { InitializeComponent(); maleBox.SelectedIndex = 0; birthdayBox.Value = DateTime.Now; try { if (child != null) { this.child = child; workButton.Text = "Изменить"; fNameBox.Text = child.FName; sNameBox.Text = child.SName; tNameBox.Text = child.TName; maleBox.SelectedIndex = child.Male ? 0 : 1; birthdayBox.Value = child.Birthday; rod1Id = child.Parent1Id; rod2Id = child.Parent2Id; linkRod1_changeName(); linkRod2_changeName(); } } 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 _child = new Child(); _child.FName = fNameBox.Text; _child.SName = sNameBox.Text; _child.TName = tNameBox.Text; _child.Male = maleBox.SelectedIndex == 0; _child.Birthday = birthdayBox.Value; _child.Parent1Id = rod1Id; _child.Parent2Id = rod2Id; FuncDB.ChildCheckValid(_child); if (child == null) FuncDB.ChildAdd(_child); else { _child.Id = child.Id; FuncDB.ChildChange(_child); } this.Close(); } catch (Exception ex) { this.ShowError(errorLabel, ex.Message); } } private void canceledButton_Click(object sender, EventArgs e) { isCanceled = true; this.Close(); } } }