private void buttonAdd_Click(object sender, EventArgs e)
        {
            PeredachaOborud po = new PeredachaOborud();

            po.IdFirstSotr      = Convert.ToInt32(comboBoxFirstSotr.SelectedItem.ToString().Split('.')[0]);
            po.IdSecondSotr     = Convert.ToInt32(comboBoxSecondSotr.SelectedItem.ToString().Split('.')[0]);
            po.IdObor           = Convert.ToInt32(comboBoxOborud.SelectedItem.ToString().Split('.')[0]);
            po.PurposePeredacha = textBoxPurposePeredacha.Text;
            Program.KPDB.PeredachaOborud.Add(po);
            Program.KPDB.SaveChanges();
            ShowPeredacha();
        }
 private void buttonEdit_Click(object sender, EventArgs e)
 {
     if (listViewPeredacha.SelectedItems.Count == 1)
     {
         PeredachaOborud po = listViewPeredacha.SelectedItems[0].Tag as PeredachaOborud;
         po.IdFirstSotr      = Convert.ToInt32(comboBoxFirstSotr.SelectedItem.ToString().Split('.')[0]);
         po.IdSecondSotr     = Convert.ToInt32(comboBoxSecondSotr.SelectedItem.ToString().Split('.')[0]);
         po.IdObor           = Convert.ToInt32(comboBoxOborud.SelectedItem.ToString().Split('.')[0]);
         po.PurposePeredacha = textBoxPurposePeredacha.Text;
         Program.KPDB.SaveChanges();
         ShowPeredacha();
     }
 }
 private void listViewPeredacha_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listViewPeredacha.SelectedItems.Count == 1)
     {
         PeredachaOborud po = listViewPeredacha.SelectedItems[0].Tag as PeredachaOborud;
         comboBoxFirstSotr.SelectedIndex  = comboBoxFirstSotr.FindString(po.IdFirstSotr.ToString());
         comboBoxSecondSotr.SelectedIndex = comboBoxSecondSotr.FindString(po.IdSecondSotr.ToString());
         comboBoxOborud.SelectedIndex     = comboBoxOborud.FindString(po.IdObor.ToString());
         textBoxPurposePeredacha.Text     = po.PurposePeredacha;
     }
     else
     {
         comboBoxFirstSotr.SelectedItem  = null;
         comboBoxSecondSotr.SelectedItem = null;
         comboBoxOborud.SelectedItem     = null;
         textBoxPurposePeredacha.Text    = "";
     }
 }
 private void buttonDel_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewPeredacha.SelectedItems.Count == 1)
         {
             PeredachaOborud po = listViewPeredacha.SelectedItems[0].Tag as PeredachaOborud;
             Program.KPDB.PeredachaOborud.Remove(po);
             Program.KPDB.SaveChanges();
             ShowPeredacha();
         }
         comboBoxFirstSotr.SelectedItem  = null;
         comboBoxSecondSotr.SelectedItem = null;
         comboBoxOborud.SelectedItem     = null;
         textBoxPurposePeredacha.Text    = "";
     }
     catch
     {
         MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }