using Database; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace View { public partial class DescriptionForm : Form { public int id; private bool flag = false; private Abstracts db; public DescriptionForm(Abstracts abstracts) { InitializeComponent(); db = abstracts; } private void button1_Click(object sender, EventArgs e) { try { if (!flag) { db.CreateDescription(new() { Id = id, descript = textBoxDesc.Text, place = textBoxPlace.Text, title = textBoxTitle.Text }); } else { db.UpdateDescription(new() { Id = id, descript = textBoxDesc.Text, place = textBoxPlace.Text, title = textBoxTitle.Text }); } DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void button2_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } private void DescriptionForm_Load(object sender, EventArgs e) { LoadData(); } private void LoadData() { try { var item = db.GetDescription(id); if (item != null) { textBoxTitle.Text = item.title; textBoxDesc.Text = item.descript; textBoxPlace.Text = item.place; flag = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }