private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewTrade.SelectedItems.Count == 1) { TradeInSet tradeset = listViewTrade.SelectedItems[0].Tag as TradeInSet; Program.dbmotor.TradeInSet.Remove(tradeset); Program.dbmotor.SaveChanges(); ShowTrade(); } comboBoxClient.SelectedItem = null; textBoxMark.Text = ""; textBoxModel.Text = ""; textBoxYear.Text = ""; textBoxSerNomer.Text = ""; textBoxPredvPrice.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonEdit_Click(object sender, EventArgs e) { if (listViewTrade.SelectedItems.Count == 1) { TradeInSet tradeset = listViewTrade.SelectedItems[0].Tag as TradeInSet; tradeset.Mark = textBoxMark.Text; tradeset.Model = textBoxModel.Text; tradeset.Year = textBoxYear.Text; tradeset.SerNumber = textBoxSerNomer.Text; tradeset.PrePrice = textBoxPredvPrice.Text; Program.dbmotor.SaveChanges(); ShowTrade(); } }
private void buttonAdd_Click(object sender, EventArgs e) { if (comboBoxClient.SelectedItem != null && textBoxMark.Text != "" && textBoxModel.Text != "" && textBoxYear.Text != "" && textBoxSerNomer.Text != "" && textBoxPredvPrice.Text != "") { TradeInSet tradeSet = new TradeInSet(); tradeSet.IdClient = Convert.ToInt32(comboBoxClient.SelectedItem.ToString().Split('.')[0]); tradeSet.Mark = (textBoxMark.Text); tradeSet.Model = textBoxModel.Text; tradeSet.Year = textBoxYear.Text; tradeSet.SerNumber = textBoxSerNomer.Text; tradeSet.PrePrice = textBoxPredvPrice.Text; Program.dbmotor.TradeInSet.Add(tradeSet); Program.dbmotor.SaveChanges(); ShowTrade(); } else { MessageBox.Show("Данные не выбраны", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void listViewClient_SelectedIndexChanged(object sender, EventArgs e) { if (listViewTrade.SelectedItems.Count == 1) { TradeInSet tradeSet = listViewTrade.SelectedItems[0].Tag as TradeInSet; comboBoxClient.SelectedIndex = comboBoxClient.FindString(tradeSet.IdClient.ToString()); textBoxMark.Text = tradeSet.Mark.ToString(); textBoxModel.Text = tradeSet.Model.ToString(); textBoxYear.Text = tradeSet.Year.ToString(); textBoxSerNomer.Text = tradeSet.SerNumber.ToString(); textBoxPredvPrice.Text = tradeSet.PrePrice.ToString(); } else { comboBoxClient.SelectedItem = null; textBoxMark.Text = ""; textBoxModel.Text = ""; textBoxYear.Text = ""; textBoxSerNomer.Text = ""; textBoxPredvPrice.Text = ""; } }