private void buttonEditInfo_Click(object sender, EventArgs e) { if (listViewSell.SelectedItems.Count == 1) { SellAction sa = listViewSell.SelectedItems[0].Tag as SellAction; sa.IdUser = Convert.ToInt32(comboBoxNameUser.SelectedItem.ToString().Split('.')[0]); sa.DateSell = Convert.ToString(textBoxDateSell.Text); sa.PriceSell = Convert.ToString(textBoxPriceSell.Text); Program.ADb.SaveChanges(); ShowSell(); } }
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (listViewSell.SelectedItems.Count == 1) { SellAction sa = listViewSell.SelectedItems[0].Tag as SellAction; comboBoxNameUser.SelectedIndex = comboBoxNameUser.FindString(sa.IdUser.ToString()); textBoxDateSell.Text = sa.DateSell.ToString(); textBoxPriceSell.Text = sa.PriceSell.ToString(); } else { comboBoxNameUser.SelectedItem = null; textBoxDateSell.Text = ""; textBoxPriceSell.Text = ""; } }
private void buttonAddInfo_Click(object sender, EventArgs e) { if (comboBoxNameUser.SelectedItem != null) { SellAction sa = new SellAction(); sa.IdUser = Convert.ToInt32(comboBoxNameUser.SelectedItem.ToString().Split('.')[0]); sa.DateSell = Convert.ToString(textBoxDateSell.Text); sa.PriceSell = Convert.ToString(textBoxPriceSell.Text); Program.ADb.SellAction.Add(sa); Program.ADb.SaveChanges(); ShowSell(); } else { MessageBox.Show("Данные не выбраны", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void buttonDelInfo_Click(object sender, EventArgs e) { try { if (listViewSell.SelectedItems.Count == 1) { SellAction sa = listViewSell.SelectedItems[0].Tag as SellAction; Program.ADb.SellAction.Remove(sa); Program.ADb.SaveChanges(); ShowSell(); } comboBoxNameUser.SelectedItem = null; textBoxDateSell.Text = ""; textBoxPriceSell.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }