private void AuthorToolStripMenuItem_Click(object sender, EventArgs e) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { choose = 1; dataGridView.DataSource = (from author in context.Author select new { Family = author.FamilyAuthor, Name = author.NameAuthor, Patronymic = author.PatronymicAuthor, Gender = author.Gender, YearBirthday = author.DateBirthday }).ToList(); dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; nameFilter.Visible = false; authorFilter.Visible = true; CategoryFilter.Visible = false; StatusFilter.Visible = false; } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void DelButton_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Вы уверены, что хотите удалить достопримечательность? Отменить это дейсвие будет невозможно.", "Подтвердите действие", MessageBoxButtons.YesNo, MessageBoxIcon.Question); try { if (result == DialogResult.Yes) { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { context.Sight.Remove((from sig in context.Sight where sig.ID == sight.ID select sig).FirstOrDefault()); context.SaveChanges(); } this.Close(); } else if (result == DialogResult.No) { return; } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void InitForm() { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { YearNumericUpDown.ValueChanged += YearNumericUpDown_ValueChanged; Image imgsight = Image.FromFile("unnamed.png"); PictureBox.Image = imgsight; PictureBox.SizeMode = PictureBoxSizeMode.StretchImage; StatusComboBox.DataSource = (from status in context.StatusSight select status.NameStatus).ToList(); StatusComboBox.SelectedItem = null; StatusComboBox.TextChanged += StatusComboBox_TextChanged; StopComboBox.DataSource = (from stop in context.TransportStop select stop.NameStop).ToList(); StopComboBox.SelectedItem = null; StopComboBox.TextChanged += StopComboBox_TextChanged; CategoryComboBox.DataSource = (from category in context.Category select category.NameCategory).ToList(); CategoryComboBox.SelectedItem = null; CategoryComboBox.TextChanged += CategoryComboBox_TextChanged; AuthorComboBox.DataSource = (from author in context.Author select author.FamilyAuthor + " " + author.NameAuthor + " " + author.PatronymicAuthor).ToList(); AuthorComboBox.SelectedItem = null; AuthorComboBox.TextChanged += AuthorComboBox_TextChanged; } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void InitDGV() { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { AuthorDataGridView.DataSource = (from sig in context.Sight join aos in context.AuthorOfSight on sig.ID equals aos.SightID join author in context.Author on aos.AuthorID equals author.ID where sig.ID == sight.ID select new { Family = author.FamilyAuthor, Name = author.NameAuthor, Patronymic = author.PatronymicAuthor }).ToList(); AuthorDataGridView.Columns[0].Width = 100; AuthorDataGridView.Columns[0].HeaderText = "Фамилия"; AuthorDataGridView.Columns[1].Width = 100; AuthorDataGridView.Columns[1].HeaderText = "Имя"; AuthorDataGridView.Columns[2].Width = 100; AuthorDataGridView.Columns[2].HeaderText = "Отчество"; } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void CategoryComboBox_TextChanged(object sender, EventArgs e) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { sight.CategoryID = (from category in context.Category where category.NameCategory == CategoryComboBox.Text select category.ID).FirstOrDefault(); } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void StopComboBox_TextChanged(object sender, EventArgs e) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { sight.StopID = (from stop in context.TransportStop where stop.NameStop == StopComboBox.Text select stop.ID).FirstOrDefault(); } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void InitDVG() { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { var result = (from sight in context.Sight join category in context.Category on sight.CategoryID equals category.ID join status in context.StatusSight on sight.StatusID equals status.ID join authorofsight in context.AuthorOfSight on sight.ID equals authorofsight.SightID join author in context.Author on authorofsight.AuthorID equals author.ID select new { NameSight = sight.NameSight, Category = category.NameCategory, Status = status.NameStatus, Family = author.FamilyAuthor, Name = author.NameAuthor, Patronymic = author.PatronymicAuthor }); dataGridView.DataSource = null; dataGridView.DataSource = result.ToList(); dataGridView.Columns[0].Width = 170; } dataGridView.Columns[0].HeaderText = "Название"; dataGridView.Columns[1].Width = 80; dataGridView.Columns[1].HeaderText = "Категория"; dataGridView.Columns[2].Width = 220; dataGridView.Columns[2].HeaderText = "Статус"; dataGridView.Columns[3].Width = 100; dataGridView.Columns[3].HeaderText = "Фамилия"; dataGridView.Columns[4].Width = 100; dataGridView.Columns[4].HeaderText = "Имя"; dataGridView.Columns[5].Width = 100; dataGridView.Columns[5].HeaderText = "Отчество"; nameFilter.Visible = true; authorFilter.Visible = true; CategoryFilter.Visible = true; StatusFilter.Visible = true; } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void YearNumericUpDown_ValueChanged(object sender, EventArgs e) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { List <AuthorOfSight> authorOfSights = (from aos in context.AuthorOfSight where sight.ID == aos.SightID select aos).ToList <AuthorOfSight>(); foreach (AuthorOfSight item in authorOfSights) { item.DateCreate = (short)YearNumericUpDown.Value; } context.SaveChanges(); } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "ERror", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void KindTrToolStripMenuItem_Click(object sender, EventArgs e) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { choose = 5; dataGridView.DataSource = (from kindtr in context.KindOfTransport select new { Name = kindtr.NameKind }).ToList(); dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; nameFilter.Visible = true; authorFilter.Visible = false; CategoryFilter.Visible = false; StatusFilter.Visible = false; } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void AuthorComboBox_TextChanged(object sender, EventArgs e) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { if (AuthorComboBox.SelectedItem != null) { string[] parse = AuthorComboBox.Text.Split(' '); AuthorDGV.Rows.Add(); for (int i = 0; i < AuthorDGV.Columns.Count; i++) { AuthorDGV.Rows[AuthorDGV.Rows.Count - 1].Cells[i].Value = parse[i]; } } } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void CategoryFilterTextBox_TextChanged(object sender, EventArgs e) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { var r = (from sight in context.Sight join category in context.Category on sight.CategoryID equals category.ID join status in context.StatusSight on sight.StatusID equals status.ID join authorofsight in context.AuthorOfSight on sight.ID equals authorofsight.SightID join author in context.Author on authorofsight.AuthorID equals author.ID select new { NameSight = sight.NameSight, Category = category.NameCategory, Status = status.NameStatus, Family = author.FamilyAuthor, Name = author.NameAuthor, Patronymic = author.PatronymicAuthor }); if (dataGridView.DataSource != null) { if (!string.IsNullOrWhiteSpace(CategoryFilterTextBox.Text)) { dataGridView.DataSource = r.Where(c => c.Category.Contains(CategoryFilterTextBox.Text)).ToList(); } else { dataGridView.DataSource = r.ToList(); } } } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void DelAuthButton_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Вы действительно хотите удалить автора? Отменить действие будет невозможно.", "Подтвердите действие", MessageBoxButtons.YesNo, MessageBoxIcon.Question); try { if (result == DialogResult.Yes) { if (AuthorDataGridView.SelectedRows.Count != 0) { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { string s = AuthorDataGridView.SelectedRows[0].Cells[0].Value.ToString(); string s1 = AuthorDataGridView.SelectedRows[0].Cells[1].Value.ToString(); string s2 = AuthorDataGridView.SelectedRows[0].Cells[2].Value.ToString(); context.AuthorOfSight.Remove((from aos in context.AuthorOfSight join author in context.Author on aos.AuthorID equals author.ID where aos.SightID == sight.ID && author.FamilyAuthor == s && author.NameAuthor == s1 && author.PatronymicAuthor == s2 select aos).FirstOrDefault()); context.SaveChanges(); } InitDGV(); } } else if (result == DialogResult.No) { return; } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void SaveButton_Click(object sender, EventArgs e) { try { if (CheckFied()) { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { if (this.Text == "Изменение") { Sight s = context.Sight.Find((from sig in context.Sight where sig.ID == sight.ID select sig.ID).Single()); s.NameSight = sight.NameSight; s.DescriptionSight = sight.DescriptionSight; s.AddresSights = sight.AddresSights; s.Photo = sight.Photo; s.StopID = sight.StopID; s.StatusID = sight.StatusID; s.CategoryID = sight.CategoryID; for (int i = 0; i < AuthorDGV.Rows.Count; i++) { string namea = AuthorDGV.Rows[i].Cells[1].Value.ToString(); string familya = AuthorDGV.Rows[i].Cells[0].Value.ToString(); string patrona = AuthorDGV.Rows[i].Cells[2].Value.ToString(); context.AuthorOfSight.Add(new AuthorOfSight(sight.ID, (from author in context.Author where author.NameAuthor == namea && author.FamilyAuthor == familya && author.PatronymicAuthor == patrona select author.ID).FirstOrDefault(), (short)YearNumericUpDown.Value)); } context.SaveChanges(); } else { context.Sight.Add(new Sight(sight.NameSight, sight.DescriptionSight, sight.Photo, sight.AddresSights, sight.StopID, sight.StatusID, sight.CategoryID)); for (int i = 0; i < AuthorDGV.Rows.Count; i++) { string namea = AuthorDGV.Rows[i].Cells[1].Value.ToString(); string familya = AuthorDGV.Rows[i].Cells[0].Value.ToString(); string patrona = AuthorDGV.Rows[i].Cells[2].Value.ToString(); context.AuthorOfSight.Add(new AuthorOfSight((from sig in context.Sight where sig.NameSight == NameTextBox.Text select sig.ID).FirstOrDefault(), (from author in context.Author where author.NameAuthor == namea && author.FamilyAuthor == familya && author.PatronymicAuthor == patrona select author.ID).FirstOrDefault(), (short)YearNumericUpDown.Value)); } context.SaveChanges(); } } this.Close(); } else { MessageBox.Show("Не все обязательные поля заполнены. Проверьте данные.", "Внимание"); } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void DeleteButton_Click(object sender, EventArgs e) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { if (choose == 1) { DialogResult result = MessageBox.Show("Вы действительно хотите удалить автора? Отменить действие будет невозможно.", "Подтвердите действие", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { context.Author.Remove((from author in context.Author where author.ID == auth.ID select author).FirstOrDefault()); context.SaveChanges(); this.Close(); } else if (result == DialogResult.No) { return; } } if (choose == 2) { DialogResult result = MessageBox.Show("Вы действительно хотите удалить статус? Отменить действие будет невозможно.", "Подтвердите действие", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { context.StatusSight.Remove((from status in context.StatusSight where status.ID == stsi.ID select status).FirstOrDefault()); context.SaveChanges(); this.Close(); } else if (result == DialogResult.No) { return; } } if (choose == 3) { DialogResult result = MessageBox.Show("Вы действительно хотите удалить остановку? Отменить действие будет невозможно.", "Подтвердите действие", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { context.TransportStop.Remove((from stop in context.TransportStop where stop.ID == trst.ID select stop).FirstOrDefault()); context.SaveChanges(); this.Close(); } else if (result == DialogResult.No) { return; } } if (choose == 4) { DialogResult result = MessageBox.Show("Вы действительно хотите удалить категорию? Отменить действие будет невозможно.", "Подтвердите действие", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { context.Category.Remove((from category in context.Category where category.ID == cat.ID select category).FirstOrDefault()); context.SaveChanges(); this.Close(); } else if (result == DialogResult.No) { return; } } if (choose == 5) { DialogResult result = MessageBox.Show("Вы действительно хотите удалить вид транспорта? Отменить действие будет невозможно.", "Подтвердите действие", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { context.KindOfTransport.Remove((from kindtransport in context.KindOfTransport where kindtransport.ID == kintr.ID select kindtransport).FirstOrDefault()); context.SaveChanges(); this.Close(); } else if (result == DialogResult.No) { return; } } } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void dataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { if (choose == 0) { if (e.RowIndex >= 0) { string s = dataGridView.SelectedRows[0].Cells[0].Value.ToString(); Edit edit = new Edit((from sight in context.Sight where s == sight.NameSight select sight).FirstOrDefault(), connectionString); edit.FormClosed += Edit_FormClosed; edit.ShowDialog(); } } else if (choose == 1) { if (e.RowIndex >= 0) { string a = dataGridView.SelectedRows[0].Cells[0].Value.ToString(); string a1 = dataGridView.SelectedRows[0].Cells[1].Value.ToString(); string a2 = dataGridView.SelectedRows[0].Cells[2].Value.ToString(); string a3 = dataGridView.SelectedRows[0].Cells[3].Value.ToString(); string a4 = dataGridView.SelectedRows[0].Cells[4].Value.ToString(); Table table = new Table((from author in context.Author where a == author.FamilyAuthor && a1 == author.NameAuthor && a2 == author.PatronymicAuthor && a3 == author.Gender.ToString() && a4 == author.DateBirthday.ToString() select author).FirstOrDefault(), connectionString); table.FormClosed += Edit_FormClosed; table.ShowDialog(); } } else if (choose == 2) { if (e.RowIndex >= 0) { string ss = dataGridView.SelectedRows[0].Cells[0].Value.ToString(); Table table = new Table((from status in context.StatusSight where ss == status.NameStatus select status).FirstOrDefault(), connectionString); table.FormClosed += Edit_FormClosed; table.ShowDialog(); } } else if (choose == 3) { if (e.RowIndex >= 0) { string ts = dataGridView.SelectedRows[0].Cells[0].Value.ToString(); Table table = new Table((from stop in context.TransportStop where ts == stop.NameStop select stop).FirstOrDefault(), connectionString); table.FormClosed += Edit_FormClosed; table.ShowDialog(); } } else if (choose == 4) { if (e.RowIndex >= 0) { string c = dataGridView.SelectedRows[0].Cells[0].Value.ToString(); Table table = new Table((from category in context.Category where c == category.NameCategory select category).FirstOrDefault(), connectionString); table.FormClosed += Edit_FormClosed; table.ShowDialog(); } } else if (choose == 5) { if (e.RowIndex >= 0) { string kt = dataGridView.SelectedRows[0].Cells[0].Value.ToString(); Table table = new Table((from kind in context.KindOfTransport where kt == kind.NameKind select kind).FirstOrDefault(), connectionString); table.FormClosed += Edit_FormClosed; table.ShowDialog(); } } } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void Edit_FormClosed(object sender, FormClosedEventArgs e) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { if (choose == 0) { InitDVG(); } if (choose == 1) { dataGridView.DataSource = (from author in context.Author select new { Family = author.FamilyAuthor, Name = author.NameAuthor, Patronymic = author.PatronymicAuthor, Gender = author.Gender, YearBirthday = author.DateBirthday }).ToList(); dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; nameFilter.Visible = false; authorFilter.Visible = true; CategoryFilter.Visible = false; StatusFilter.Visible = false; } if (choose == 2) { dataGridView.DataSource = (from status in context.StatusSight select new { Name = status.NameStatus }).ToList(); dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; nameFilter.Visible = true; authorFilter.Visible = false; CategoryFilter.Visible = false; StatusFilter.Visible = false; } if (choose == 3) { dataGridView.DataSource = (from stop in context.TransportStop select new { Name = stop.NameStop }).ToList(); dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; nameFilter.Visible = true; authorFilter.Visible = false; CategoryFilter.Visible = false; StatusFilter.Visible = false; } if (choose == 4) { dataGridView.DataSource = (from category in context.Category select new { Name = category.NameCategory }).ToList(); dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; nameFilter.Visible = true; authorFilter.Visible = false; CategoryFilter.Visible = false; StatusFilter.Visible = false; } if (choose == 5) { dataGridView.DataSource = (from kindtr in context.KindOfTransport select new { Name = kindtr.NameKind }).ToList(); dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; nameFilter.Visible = true; authorFilter.Visible = false; CategoryFilter.Visible = false; StatusFilter.Visible = false; } } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void InitForm(Sight sight) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { NameTextBox.Text = sight.NameSight; DiscriptionTextBox.Text = sight.DescriptionSight; AddressTextBox.Text = sight.AddresSights; YearNumericUpDown.Value = (from sig in context.Sight join aos in context.AuthorOfSight on sig.ID equals aos.SightID where sig.ID == sight.ID select aos.DateCreate).FirstOrDefault(); YearNumericUpDown.ValueChanged += YearNumericUpDown_ValueChanged; if (File.Exists(sight.Photo.Trim())) { Image imgsight = Image.FromFile(sight.Photo.Trim()); PictureBox.Image = imgsight; PictureBox.SizeMode = PictureBoxSizeMode.StretchImage; } else { Image imgsight = Image.FromFile("unnamed.png"); PictureBox.Image = imgsight; PictureBox.SizeMode = PictureBoxSizeMode.StretchImage; } AddPictureButton.Text = "Изменить изображение"; this.Text = "Изменение"; StatusComboBox.DataSource = (from status in context.StatusSight select status.NameStatus).ToList(); StatusComboBox.TextChanged += StatusComboBox_TextChanged; StatusComboBox.Text = (from status in context.StatusSight where status.ID == sight.StatusID select status.NameStatus).FirstOrDefault().ToString(); StopComboBox.DataSource = (from stop in context.TransportStop select stop.NameStop).ToList(); StopComboBox.TextChanged += StopComboBox_TextChanged; StopComboBox.Text = (from sig in context.Sight join stop in context.TransportStop on sig.StopID equals stop.ID where sig.ID == sight.ID select stop.NameStop).Single(); CategoryComboBox.DataSource = (from category in context.Category select category.NameCategory).ToList(); CategoryComboBox.TextChanged += CategoryComboBox_TextChanged; CategoryComboBox.Text = (from sig in context.Sight join category in context.Category on sig.CategoryID equals category.ID where sig.ID == sight.ID select category.NameCategory).Single(); if (this.Text == "Изменение") { AuthorComboBox.DataSource = (from author in context.Author select author.FamilyAuthor + " " + author.NameAuthor + " " + author.PatronymicAuthor).ToList(); AuthorComboBox.SelectedItem = null; AuthorComboBox.TextChanged += AuthorComboBox_TextChanged; } InitDGV(); } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }
private void CreateEditButton_Click(object sender, EventArgs e) { try { using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString)) { if (ChekField()) { if (this.Text == "Изменение") { if (choose == 1) { Author a = context.Author.Find(auth.ID); a.FamilyAuthor = FamilyTextBox.Text; a.NameAuthor = NameTextBox.Text; a.PatronymicAuthor = PatronymicTextBox.Text; if (ManCheckBox.Checked) { a.Gender = true; } else { a.Gender = false; } a.DateBirthday = (short)YearNumericUpDown.Value; context.SaveChanges(); this.Close(); } if (choose == 2) { StatusSight ss = context.StatusSight.Find(stsi.ID); ss.NameStatus = NameTextBox.Text; context.SaveChanges(); this.Close(); } if (choose == 3) { TransportStop ts = context.TransportStop.Find(trst.ID); ts.NameStop = NameTextBox.Text; context.SaveChanges(); this.Close(); } if (choose == 4) { Category c = context.Category.Find(cat.ID); c.NameCategory = NameTextBox.Text; context.SaveChanges(); this.Close(); } if (choose == 5) { KindOfTransport kt = context.KindOfTransport.Find(kintr.ID); kt.NameKind = NameTextBox.Text; context.SaveChanges(); this.Close(); } } else { if (choose == 1) { context.Author.Add(new Author(auth.FamilyAuthor, auth.NameAuthor, auth.PatronymicAuthor, auth.Gender, auth.DateBirthday)); context.SaveChanges(); this.Close(); } if (choose == 2) { context.StatusSight.Add(new StatusSight(stsi.NameStatus)); context.SaveChanges(); this.Close(); } if (choose == 3) { context.TransportStop.Add(new TransportStop(trst.NameStop)); context.SaveChanges(); this.Close(); } if (choose == 4) { context.Category.Add(new Category(cat.NameCategory)); context.SaveChanges(); this.Close(); } if (choose == 5) { context.KindOfTransport.Add(new KindOfTransport(kintr.NameKind)); context.SaveChanges(); this.Close(); } } } else { MessageBox.Show("Не все обязательные поля заполнены. Проверьте данные.", "Внимание"); } } } catch (DbUpdateException) { MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }