using Microsoft.Extensions.Logging; /*using TaskTrackerBusinessLogic.BusinessLogics;*/ using TaskTrackerContracts.BindingModels; using TaskTrackerContracts.BusinessLogicsContracts; using TaskTrackerContracts.SearchModels; 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 TaskTrackerView { public partial class FormCreateTask : Form { private readonly IProjectLogic _logicR; private readonly ITaskLogic _logicO; private readonly IUserLogic _logicC; public FormCreateTask(IProjectLogic logicR, ITaskLogic logicO, IUserLogic logicC) { InitializeComponent(); _logicR = logicR; _logicO = logicO; _logicC = logicC; } private void FormCreateOrder_Load(object sender, EventArgs e) { try { var projectList = _logicR.ReadList(null); if (projectList != null) { comboBoxReinforced.DisplayMember = "ProjectName"; comboBoxReinforced.ValueMember = "Id"; comboBoxReinforced.DataSource = projectList; comboBoxReinforced.SelectedItem = null; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } try { var userList = _logicC.ReadList(null); if (userList != null) { comboBoxClient.DisplayMember = "UserFIO"; comboBoxClient.ValueMember = "Id"; comboBoxClient.DataSource = userList; comboBoxClient.SelectedItem = null; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void ButtonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxCount.Text)) { MessageBox.Show("Заполните поле", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBoxReinforced.SelectedValue == null) { MessageBox.Show("Выберите проект", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBoxClient.SelectedValue == null) { MessageBox.Show("Выберите сотрудника", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var operationResult = _logicO.CreateTask(new TaskBindingModel { ProjectId = Convert.ToInt32(comboBoxReinforced.SelectedValue), UserId = Convert.ToInt32(comboBoxClient.SelectedValue), Title = textBoxCount.Text, Description = textBoxSum.Text }); if (!operationResult) { throw new Exception("Ошибка при создании задачи.Дополнительная информация в логах."); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void ButtonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } } }