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 OptForm : Form { public bool isCanceled = false; private int chelId = 0; private Free free = null; public OptForm(Free free = null, int? chelId = null) { InitializeComponent(); if (free == null && chelId == null) throw new Exception("Не выбран сотрудник."); dateBox.Value = DateTime.Now; dateBox2.Value = DateTime.Now; comboBox1.SelectedIndex = 0; try { if (free != null) { this.free = free; this.chelId = free.ChelId; dateBox.Value = free.Start; comboBox1.Text = free.Type; if (free.End.HasValue) { checkBox1.Checked = false; dateBox2.Enabled = true; dateBox2.Value = free.End.Value; } else { checkBox1.Checked = true; dateBox2.Enabled = false; } workButton.Text = "Изменить"; } else { this.chelId = chelId.Value; } } catch (Exception e) { this.ShowError(errorLabel, e.Message); workButton.Enabled = false; } } private void workButton_Click(object sender, EventArgs e) { try { var _free = new Free(); _free.ChelId = chelId; _free.Type = comboBox1.Text; _free.Start = dateBox.Value; if (checkBox1.Checked) _free.End = null; else _free.End = dateBox2.Value; FuncDB.FreeCheckValid(_free); if (free == null) FuncDB.FreeAdd(_free); else { _free.Id = free.Id; FuncDB.FreeChange(_free); } this.Close(); } catch (Exception ex) { this.ShowError(errorLabel, ex.Message); } } private void canceledButton_Click(object sender, EventArgs e) { isCanceled = true; this.Close(); } private void checkBox1_CheckedChanged(object sender, EventArgs e) { dateBox2.Enabled = !checkBox1.Checked; } } }