private void buttonEdit_Click(object sender, EventArgs e) { if (listViewOrder.SelectedItems.Count == 1) { OrderSet order = listViewOrder.SelectedItems[0].Tag as OrderSet; order.IdAgent = Convert.ToInt32(comboBoxAgent.SelectedItem.ToString().Split('.')[0]); order.IdClient = Convert.ToInt32(comboBoxClient.SelectedItem.ToString().Split('.')[0]); order.IdTovar = Convert.ToInt32(comboBoxTovar.SelectedItem.ToString().Split('.')[0]); Program.lazur.SaveChanges(); ShowOrder(); } }
private void listViewOrder_SelectedIndexChanged(object sender, EventArgs e) { if (listViewOrder.SelectedItems.Count == 1) { OrderSet order = listViewOrder.SelectedItems[0].Tag as OrderSet; comboBoxAgent.SelectedIndex = comboBoxAgent.FindString(order.IdAgent.ToString()); comboBoxClient.SelectedIndex = comboBoxClient.FindString(order.IdClient.ToString()); comboBoxTovar.SelectedIndex = comboBoxTovar.FindString(order.IdTovar.ToString()); } else { comboBoxAgent.SelectedItem = null; comboBoxClient.SelectedItem = null; comboBoxTovar.SelectedItem = null; } }
private void buttonAdd_Click(object sender, EventArgs e) { if (comboBoxAgent.SelectedItem != null && comboBoxClient.SelectedItem != null && comboBoxTovar.SelectedItem != null) { OrderSet order = new OrderSet(); order.IdAgent = Convert.ToInt32(comboBoxAgent.SelectedItem.ToString().Split('.')[0]); order.IdClient = Convert.ToInt32(comboBoxClient.SelectedItem.ToString().Split('.')[0]); order.IdTovar = Convert.ToInt32(comboBoxTovar.SelectedItem.ToString().Split('.')[0]); Program.lazur.OrderSet.Add(order); Program.lazur.SaveChanges(); ShowOrder(); } else { MessageBox.Show("Данные не выбраны", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewOrder.SelectedItems.Count == 1) { OrderSet order = listViewOrder.SelectedItems[0].Tag as OrderSet; Program.lazur.OrderSet.Remove(order); Program.lazur.SaveChanges(); ShowOrder(); } comboBoxAgent.SelectedItem = null; comboBoxClient.SelectedItem = null; comboBoxTovar.SelectedItem = null; } catch { MessageBox.Show("Невозможно удалить, эта запись используется", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }