using ProjectItCompany.Repositories;
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;
using Unity;

namespace ProjectItCompany.Forms
{
    public partial class FormWages : Form
    {
        private readonly IUnityContainer _container;
        private readonly IWageRepository _wageRepository;

        public FormWages(IUnityContainer container, IWageRepository wageRepository)
        {
            InitializeComponent();
            _container = container ?? throw new ArgumentNullException(nameof(container));
            _wageRepository = wageRepository ?? throw new ArgumentNullException(nameof(wageRepository));

        }

        private void FormWages_Load(object sender, EventArgs e)
        {
            try
            {
                LoadList();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка при загрузке",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void ButtonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                _container.Resolve<FormWage>().ShowDialog();
                LoadList();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка при добавлении",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void LoadList() => dataGridViewData.DataSource = _wageRepository.ReadWage();
    }
}
