private void ButtonAdd_Click(object sender, EventArgs e) { try { OrderSet order = new OrderSet(); if (comboBoxOrder.SelectedItem != null) { order.IdClient = Convert.ToInt32(comboBoxOrder.SelectedItem.ToString().Split('.')[0]); } else { throw new Exception("Обязательные данные не заполнены"); } if (comboBoxOrder.SelectedItem != null) { order.IdAutopart = Convert.ToInt32(comboBoxOrder.SelectedItem.ToString().Split('.')[0]); } else { throw new Exception("Обязательные данные не заполнены"); } Program.catalog.OrderSet.Add(order); Program.catalog.SaveChanges(); ShowOrder(); } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void ListViewOrder_SelectedIndexChanged(object sender, EventArgs e) { if (listViewOrder.SelectedItems.Count == 1) { OrderSet orderSet = listViewOrder.SelectedItems[0].Tag as OrderSet; comboBoxOrder.Text = orderSet.IdClient.ToString() + " " + orderSet.ClientSet.LastName + " " + orderSet.ClientSet.FirstName + " " + orderSet.ClientSet.MiddleName + " " + orderSet.ClientSet.IdAutopart.ToString() + " " + orderSet.ClientSet.AutopartSet.NameAutopart; } else { comboBoxOrder.SelectedItem = null; } }
private void ButtonDel_Click(object sender, EventArgs e) { try { if (listViewOrder.SelectedItems.Count == 1) { OrderSet order = listViewOrder.SelectedItems[0].Tag as OrderSet; Program.catalog.OrderSet.Remove(order); Program.catalog.SaveChanges(); ShowOrder(); } comboBoxOrder.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }