private void buttonEdit_Click(object sender, EventArgs e) { try { if (listViewSeminar.SelectedItems.Count == 1) { if (comboBoxTypeSeminar.SelectedItem != null && textBoxAddress_City.Text != "" && textBoxAddress_Street.Text != "" && textBoxAddress_House.Text != "" && dateTimePickerSeminar.Value != null) { SeminarsSet seminarsSet = listViewSeminar.SelectedItems[0].Tag as SeminarsSet; seminarsSet.Address_City = textBoxAddress_City.Text; seminarsSet.Address_Street = textBoxAddress_Street.Text; seminarsSet.Address_House = textBoxAddress_House.Text; seminarsSet.Date = dateTimePickerSeminar.Value; seminarsSet.Name = comboBoxTypeSeminar.SelectedItem.ToString(); Program.itDb.SaveChanges(); ShowSeminar(); } else { MessageBox.Show("Поля не заполнены! Проверьте и повторите попытку.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewSeminar.SelectedItems.Count == 1) { SeminarsSet seminarsSet = listViewSeminar.SelectedItems[0].Tag as SeminarsSet; Program.itDb.SeminarsSet.Remove(seminarsSet); Program.itDb.SaveChanges(); ShowSeminar(); } textBoxAddress_City.Text = ""; textBoxAddress_Street.Text = ""; textBoxAddress_House.Text = ""; dateTimePickerSeminar.Value = DateTime.Now; comboBoxTypeSeminar.SelectedItem = null; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void listViewSeminar_SelectedIndexChanged(object sender, EventArgs e) { if (listViewSeminar.SelectedItems.Count == 1) { SeminarsSet seminarsSet = listViewSeminar.SelectedItems[0].Tag as SeminarsSet; textBoxAddress_City.Text = seminarsSet.Address_City; textBoxAddress_Street.Text = seminarsSet.Address_Street; textBoxAddress_House.Text = seminarsSet.Address_House; dateTimePickerSeminar.Value = seminarsSet.Date; comboBoxTypeSeminar.SelectedIndex = comboBoxTypeSeminar.FindString(seminarsSet.Name); } else { textBoxAddress_City.Text = ""; textBoxAddress_Street.Text = ""; textBoxAddress_House.Text = ""; dateTimePickerSeminar.Value = DateTime.Now; comboBoxTypeSeminar.SelectedItem = null; } }