private void listViewServises_SelectedIndexChanged(object sender, EventArgs e) { if (listViewServises.SelectedItems.Count == 1) { ServicesSet services = listViewServises.SelectedItems[0].Tag as ServicesSet; textBoxName.Text = services.Name; textBoxPrice.Text = services.Price.ToString(); comboBoxDepartment.SelectedIndex = comboBoxDepartment.FindString(services.Id_Department.ToString()); } else { textBoxName.Text = ""; textBoxPrice.Text = ""; comboBoxDepartment.SelectedItem = null; } }
private void buttonDelete_Click(object sender, EventArgs e) { try { if (listViewServises.SelectedItems.Count == 1) { ServicesSet services = listViewServises.SelectedItems[0].Tag as ServicesSet; Program.RBS_Project.ServicesSet.Remove(services); Program.RBS_Project.SaveChanges(); ShowServices(); } textBoxName.Text = ""; textBoxPrice.Text = ""; comboBoxDepartment.SelectedItem = null; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonAdd_Click(object sender, EventArgs e) { if (textBoxName.Text != "" && textBoxPrice.Text != "" && comboBoxDepartment.SelectedItem != null) { ServicesSet servicesSet = new ServicesSet(); servicesSet.Name = textBoxName.Text; servicesSet.Price = Convert.ToInt32(textBoxPrice.Text); servicesSet.Id_Department = Convert.ToInt32(comboBoxDepartment.SelectedItem.ToString().Split('.')[0]); Program.RBS_Project.ServicesSet.Add(servicesSet); Program.RBS_Project.SaveChanges(); ShowServices(); } else { MessageBox.Show("Заполнены не все поля!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }