private void buttonDel_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewAttendance.SelectedItems.Count == 1)
         {
             AttedenceSet attedenceSet = listViewAttendance.SelectedItems[0].Tag as AttedenceSet;
             Program.itDb.AttedenceSet.Remove(attedenceSet);
             Program.itDb.SaveChanges();
             ShowAttendance();
         }
         textBoxName.Text                 = "";
         textBoxPrice.Text                = "";
         textBoxGuarantee.Text            = "";
         comboBoxDepartament.SelectedItem = null;
     }
     catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }
 private void listViewAttendance_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listViewAttendance.SelectedItems.Count == 1)
     {
         AttedenceSet attedenceSet = listViewAttendance.SelectedItems[0].Tag as AttedenceSet;
         textBoxName.Text                  = attedenceSet.Name;
         textBoxPrice.Text                 = attedenceSet.Price.ToString();
         textBoxGuarantee.Text             = attedenceSet.Guarantee;
         comboBoxDepartament.SelectedIndex = comboBoxDepartament.FindString(attedenceSet.IdDepartment.ToString());
     }
     else
     {
         textBoxName.Text                 = "";
         textBoxPrice.Text                = "";
         textBoxGuarantee.Text            = "";
         comboBoxDepartament.SelectedItem = null;
     }
 }
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     try
     {
         if (textBoxName.Text != "" && textBoxPrice.Text != "" && comboBoxDepartament.SelectedItem != null)
         {
             AttedenceSet attedenceSet = new AttedenceSet();
             attedenceSet.Name         = textBoxName.Text;
             attedenceSet.Price        = Convert.ToInt32(textBoxPrice.Text);
             attedenceSet.Guarantee    = textBoxGuarantee.Text;
             attedenceSet.IdDepartment = Convert.ToInt32(comboBoxDepartament.SelectedItem.ToString().Split('.')[0]);
             Program.itDb.AttedenceSet.Add(attedenceSet);
             Program.itDb.SaveChanges();
             ShowAttendance();
         }
         else
         {
             MessageBox.Show("Поля не заполнены! Проверьте и повторите попытку.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }