private void buttonAdd_Click(object sender, EventArgs e)
 {
     if (comboBoxMaterials.SelectedItem != null && comboBoxStaff.SelectedItem != null && comboBoxClients.SelectedItem != null && textBoxDate.Text != "")
     {
         OrdersSet orders = new OrdersSet();
         orders.IdNameMaterial = Convert.ToInt32(comboBoxMaterials.SelectedItem.ToString().Split('.')[0]);
         orders.IdClient       = Convert.ToInt32(comboBoxClients.SelectedItem.ToString().Split('.')[0]);
         orders.IdStaff        = Convert.ToInt32(comboBoxStaff.SelectedItem.ToString().Split('.')[0]);
         orders.Date           = textBoxDate.Text;
         Program.Spartak_Project.OrdersSet.Add(orders);
         Program.Spartak_Project.SaveChanges();
         ShowOrders();
     }
     else
     {
         MessageBox.Show("Данные не выбраны", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 private void listViewOrders_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listViewOrders.SelectedItems.Count == 1)
     {
         OrdersSet orders = listViewOrders.SelectedItems[0].Tag as OrdersSet;
         comboBoxMaterials.SelectedIndex = comboBoxMaterials.FindString(orders.IdNameMaterial.ToString());
         comboBoxClients.SelectedIndex   = comboBoxClients.FindString(orders.IdClient.ToString());
         comboBoxStaff.SelectedIndex     = comboBoxStaff.FindString(orders.IdStaff.ToString());
         textBoxDate.Text = orders.Date;
     }
     else
     {
         comboBoxMaterials.SelectedItem = null;
         comboBoxClients.SelectedItem   = null;
         comboBoxStaff.SelectedItem     = null;
         textBoxDate.Text = "";
     }
 }
 private void buttonDel_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewOrders.SelectedItems.Count == 1)
         {
             OrdersSet orders = listViewOrders.SelectedItems[0].Tag as OrdersSet;
             Program.Spartak_Project.OrdersSet.Remove(orders);
             Program.Spartak_Project.SaveChanges();
             ShowOrders();
         }
         comboBoxMaterials.SelectedItem = null;
         comboBoxClients.SelectedItem   = null;
         comboBoxStaff.SelectedItem     = null;
         textBoxDate.Text = "";
     }
     catch
     {
         MessageBox.Show("Невозможно удалить, эта запись используется", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }