private void ButtonEdit_Click(object sender, EventArgs e) { if (listViewDealSet.SelectedItems.Count == 1) { DealSet deal = listViewDealSet.SelectedItems[0].Tag as DealSet; deal.IdSupply = Convert.ToInt32(comboBoxSupply.SelectedItem.ToString().Split('.')[0]); deal.IdDemand = Convert.ToInt32(comboBoxDemand.SelectedItem.ToString().Split('.')[0]); Program.wftDb.SaveChanges(); ShowDealSet(); } }
private void ListViewDealSet_SelectedIndexChanged(object sender, EventArgs e) { if (listViewDealSet.SelectedItems.Count == 1) { DealSet deal = listViewDealSet.SelectedItems[0].Tag as DealSet; comboBoxSupply.SelectedIndex = comboBoxSupply.FindString(deal.IdSupply.ToString()); comboBoxDemand.SelectedIndex = comboBoxDemand.FindString(deal.IdDemand.ToString()); } else { comboBoxSupply.SelectedItem = null; comboBoxDemand.SelectedItem = null; } }
private void ButtonAdd_Click(object sender, EventArgs e) { if (comboBoxDemand.SelectedItem != null && comboBoxSupply.SelectedItem != null) { DealSet deal = new DealSet(); deal.IdSupply = Convert.ToInt32(comboBoxSupply.SelectedItem.ToString().Split('.')[0]); deal.IdDemand = Convert.ToInt32(comboBoxDemand.SelectedItem.ToString().Split('.')[0]); Program.wftDb.DealSet.Add(deal); Program.wftDb.SaveChanges(); ShowDealSet(); } else { MessageBox.Show("Данные не выбраны", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void ButtonDel_Click(object sender, EventArgs e) { try { if (listViewDealSet.SelectedItems.Count == 1) { DealSet deal = listViewDealSet.SelectedItems[0].Tag as DealSet; Program.wftDb.DealSet.Remove(deal); Program.wftDb.SaveChanges(); ShowDealSet(); } comboBoxSupply.SelectedItem = null; comboBoxDemand.SelectedItem = null; } catch { MessageBox.Show("Невозможно удалить, эта запись используется", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }