using Commentbase; 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 FormComment : Form { public int? CommentId { get; set; } private Abstracts db; public FormComment(Abstracts abstracts) { InitializeComponent(); db = abstracts; } private void button1_Click(object sender, EventArgs e) { try { if (CommentId.HasValue) { db.UpdateComment(new() { Id = CommentId.Value, PostDate = dateTimePicker1.Value, Content = textBox1.Text, PhotoId = (comboBoxPhoto.SelectedItem as Photo).Id }); } else { db.CreateComment(new() { PostDate = dateTimePicker1.Value, Content = textBox1.Text, PhotoId = (comboBoxPhoto.SelectedItem as Photo).Id }); } 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 LoadData() { try { var photos = db.GetPhotos(); comboBoxPhoto.DataSource = photos; comboBoxPhoto.DisplayMember = "Title"; comboBoxPhoto.ValueMember = "Id"; } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void FormComment_Load(object sender, EventArgs e) { LoadData(); } } }