private void buttonEdit_Click(object sender, EventArgs e) { if (comboBoxDocument.SelectedItem != null && comboBoxNeed.SelectedItem != null && textBoxDate.Text != "" && textBoxPrice.Text != "") { if (listViewNeedsReview.SelectedItems.Count == 1) { DateTime temp; bool date = DateTime.TryParse(textBoxDate.Text, out temp); if (!date) { MessageBox.Show("Введите дату в формате: ДД.ММ.ГГГГ", "Неверный формат даты", MessageBoxButtons.OK); } else { NeedsReview needsReview = listViewNeedsReview.SelectedItems[0].Tag as NeedsReview; needsReview.id_Need = Convert.ToInt32(comboBoxNeed.SelectedItem.ToString().Split('.')[0]); needsReview.Date = Convert.ToDateTime(textBoxDate.Text); needsReview.Comment = textBoxComment.Text; needsReview.id_Document = Convert.ToInt32(comboBoxDocument.SelectedItem.ToString().Split('.')[0]); Program.csr.SaveChanges(); ShowNeedReviews(); } } } else { MessageBox.Show("Заполните все необходимые поля", "Невозможно внести данные!", MessageBoxButtons.OK); } }
private void listViewNeedsReview_SelectedIndexChanged(object sender, EventArgs e) { if (listViewNeedsReview.SelectedItems.Count == 1) { NeedsReview needsReview = listViewNeedsReview.SelectedItems[0].Tag as NeedsReview; comboBoxNeed.SelectedIndex = comboBoxNeed.FindString(needsReview.id_Need.ToString()); comboBoxDocument.SelectedIndex = comboBoxDocument.FindString(needsReview.id_Document.ToString()); textBoxComment.Text = needsReview.Comment; textBoxDate.Text = needsReview.Date.ToString().Substring(0, needsReview.Date.ToString().Length - 8); textBoxPrice.Text = needsReview.Total_Price.ToString(); } else { comboBoxNeed.SelectedItem = null; comboBoxDocument.SelectedItem = null; textBoxComment.Text = ""; textBoxDate.Text = ""; textBoxPrice.Text = ""; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewNeedsReview.SelectedItems.Count == 1) { NeedsReview needsReview = listViewNeedsReview.SelectedItems[0].Tag as NeedsReview; Program.csr.NeedsReview.Remove(needsReview); Program.csr.SaveChanges(); ShowNeedReviews(); } comboBoxNeed.SelectedItem = null; comboBoxDocument.SelectedItem = null; textBoxComment.Text = ""; textBoxDate.Text = ""; textBoxPrice.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }