private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewCustoms.SelectedItems.Count == 1) { CustomSet customSet = listViewCustoms.SelectedItems[0].Tag as CustomSet; Program.itDb.CustomSet.Remove(customSet); Program.itDb.SaveChanges(); ShowCustoms(); } comboBoxClients.SelectedItem = null; comboBoxDepartment.SelectedItem = null; comboBoxAttendance.SelectedItem = null; dateTimePickerDead.Value = DateTime.Now; textBoxStatus.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void listViewCustoms_SelectedIndexChanged(object sender, EventArgs e) { if (listViewCustoms.SelectedItems.Count == 1) { CustomSet customSet = listViewCustoms.SelectedItems[0].Tag as CustomSet; comboBoxClients.SelectedIndex = comboBoxClients.FindString(customSet.IdClient.ToString()); comboBoxDepartment.SelectedIndex = comboBoxDepartment.FindString(customSet.IdDepartament.ToString()); comboBoxAttendance.SelectedIndex = comboBoxAttendance.FindString(customSet.IdAttedence.ToString()); dateTimePickerDead.Value = customSet.DeadLine; textBoxStatus.Text = customSet.Status; } else { comboBoxClients.SelectedItem = null; comboBoxDepartment.SelectedItem = null; comboBoxAttendance.SelectedItem = null; dateTimePickerDead.Value = DateTime.Now; textBoxStatus.Text = ""; } }
private void buttonAdd_Click(object sender, EventArgs e) { try { if (comboBoxClients.SelectedItem != null && comboBoxDepartment.SelectedItem != null && comboBoxAttendance.SelectedItem != null && dateTimePickerDead.Value != null && textBoxStatus.Text != "") { CustomSet customSet = new CustomSet(); customSet.IdClient = Convert.ToInt32(comboBoxClients.SelectedItem.ToString().Split('.')[0]); customSet.IdDepartament = Convert.ToInt32(comboBoxDepartment.SelectedItem.ToString().Split('.')[0]); customSet.IdAttedence = Convert.ToInt32(comboBoxAttendance.SelectedItem.ToString().Split('.')[0]); customSet.DeadLine = dateTimePickerDead.Value; customSet.Status = textBoxStatus.Text; Program.itDb.CustomSet.Add(customSet); Program.itDb.SaveChanges(); ShowCustoms(); } else { MessageBox.Show("Поля не заполнены! Проверьте и повторите попытку.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }