157 lines
4.1 KiB
C#
157 lines
4.1 KiB
C#
using Microsoft.Extensions.Logging;
|
||
|
||
using TaskTrackerContracts.BindingModels;
|
||
using TaskTrackerContracts.BusinessLogicsContracts;
|
||
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 FormMain : Form
|
||
{
|
||
private readonly ITaskLogic _taskLogic;
|
||
public FormMain(ITaskLogic taskLogic)
|
||
{
|
||
InitializeComponent();
|
||
_taskLogic = taskLogic;
|
||
}
|
||
private void FormMain_Load(object sender, EventArgs e)
|
||
{
|
||
LoadData();
|
||
}
|
||
private void LoadData()
|
||
{
|
||
try
|
||
{
|
||
var list = _taskLogic.ReadList(null);
|
||
if (list != null)
|
||
{
|
||
dataGridView.DataSource = list;
|
||
dataGridView.Columns["ProjectId"].Visible = false;
|
||
dataGridView.Columns["projectName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
dataGridView.Columns["UserId"].Visible = false;
|
||
dataGridView.Columns["UserFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service =
|
||
Program.ServiceProvider?.GetService(typeof(FormProjects));
|
||
if (service is FormProjects form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormOrganizations));
|
||
if (service is FormOrganizations form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormUsers));
|
||
if (service is FormUsers form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||
{
|
||
var service =
|
||
Program.ServiceProvider?.GetService(typeof(FormCreateTask));
|
||
if (service is FormCreateTask form)
|
||
{
|
||
form.ShowDialog();
|
||
LoadData();
|
||
}
|
||
}
|
||
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
|
||
{
|
||
if (dataGridView.SelectedRows.Count == 1)
|
||
{
|
||
int id =
|
||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||
try
|
||
{
|
||
var operationResult = _taskLogic.TakeTaskInWork(new TaskBindingModel { Id = id });
|
||
if (!operationResult)
|
||
{
|
||
throw new Exception("Ошибка при сохранении");
|
||
}
|
||
LoadData();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||
MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
}
|
||
private void ButtonOrderReady_Click(object sender, EventArgs e)
|
||
{
|
||
if (dataGridView.SelectedRows.Count == 1)
|
||
{
|
||
int id =
|
||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||
try
|
||
{
|
||
var operationResult = _taskLogic.FinishTask(new
|
||
TaskBindingModel
|
||
{ Id = id });
|
||
if (!operationResult)
|
||
{
|
||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||
}
|
||
LoadData();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
}
|
||
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
|
||
{
|
||
if (dataGridView.SelectedRows.Count == 1)
|
||
{
|
||
int id =
|
||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||
try
|
||
{
|
||
var operationResult = _taskLogic.DeliveryTask(new TaskBindingModel { Id = id });
|
||
if (!operationResult)
|
||
{
|
||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||
}
|
||
LoadData();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||
MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
}
|
||
private void ButtonUpd_Click(object sender, EventArgs e)
|
||
{
|
||
LoadData();
|
||
}
|
||
}
|
||
}
|