private void buttonEdit_Click(object sender, EventArgs e) { try { if (listViewOrders.SelectedItems.Count == 1) { OrdersSet ordersSet = listViewOrders.SelectedItems[0].Tag as OrdersSet; if (comboBoxOrder.SelectedItem != null) { ordersSet.IdClients = Convert.ToInt32(comboBoxOrder.SelectedItem.ToString().Split('.')[0]); } else { throw new Exception("Обязательные данные не заполнены"); } if (comboBoxStatus.SelectedItem != null) { ordersSet.OrderStatus = comboBoxStatus.SelectedItem.ToString(); } else { ordersSet.OrderStatus = null; } Program.lab.SaveChanges(); ShowOrders(); } } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void listViewOrders_SelectedIndexChanged(object sender, EventArgs e) { if (listViewOrders.SelectedItems.Count == 1) { OrdersSet ordersSet = listViewOrders.SelectedItems[0].Tag as OrdersSet; comboBoxStatus.Text = ordersSet.OrderStatus; comboBoxOrder.Text = ordersSet.IdClients.ToString() + ". " + ordersSet.ClientsSet.LastName + " " + ordersSet.ClientsSet.FirstName + " - " + ordersSet.ClientsSet.IdBooks.ToString() + ". " + ordersSet.ClientsSet.BooksSet.Name; } else { comboBoxStatus.SelectedItem = null; comboBoxOrder.SelectedItem = null; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewOrders.SelectedItems.Count == 1) { OrdersSet ordersSet = listViewOrders.SelectedItems[0].Tag as OrdersSet; Program.lab.OrdersSet.Remove(ordersSet); Program.lab.SaveChanges(); ShowOrders(); } comboBoxStatus.Text = ""; comboBoxOrder.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);; } }