2023-09-06 22:02:39 +04:00
|
|
|
|
using BlogBusinessLogic;
|
|
|
|
|
using BlogContracts.BindingModels;
|
|
|
|
|
using BlogContracts.BusinessLogicContracts;
|
2023-09-06 21:16:28 +04:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2023-09-06 22:02:39 +04:00
|
|
|
|
namespace Blog
|
2023-09-06 21:16:28 +04:00
|
|
|
|
{
|
|
|
|
|
public partial class FormMain : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly IMessageLogic _messageLogic;
|
|
|
|
|
public FormMain(IMessageLogic messageLogic)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_messageLogic = messageLogic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormRoles));
|
|
|
|
|
|
|
|
|
|
if (service is FormRoles form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormUsers));
|
|
|
|
|
|
|
|
|
|
if (service is FormUsers form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormCategories));
|
|
|
|
|
|
|
|
|
|
if (service is FormCategories form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateMessage));
|
|
|
|
|
|
|
|
|
|
if (service is FormCreateMessage form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormMain_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _messageLogic.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
dataGridView.DataSource = list;
|
|
|
|
|
dataGridView.Columns["Id"].Visible = false;
|
|
|
|
|
dataGridView.Columns["UserId"].Visible = false;
|
|
|
|
|
dataGridView.Columns["TopicId"].Visible = false;
|
|
|
|
|
dataGridView.Columns["Username"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
|
|
|
dataGridView.Columns["TopicName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
|
|
|
dataGridView.Columns["Text"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
|
|
|
dataGridView.Columns["Date"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
if (MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!_messageLogic.Delete(new MessageBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonUpdate_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonChange_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateMessage));
|
|
|
|
|
|
|
|
|
|
if (service is FormCreateMessage form)
|
|
|
|
|
{
|
|
|
|
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
|
|
|
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormTests));
|
|
|
|
|
|
|
|
|
|
if (service is FormTests form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|