using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {

        protected readonly ZkContext context;
        protected readonly IemployeeService iemployeeService;


        public Form1(ZkContext context,
            IemployeeService iemployeeService)
        {
            this.context = context;
            this.iemployeeService = iemployeeService;

            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {

        }



        private void button1_Click(object sender, EventArgs e)
        {

            

            List<ResponEmployee> emp = iemployeeService.GetAllEmp();

            dataGridView1.DataSource = emp;
        }



        private async Task ShowEmployeeView(string id)
        {
            
                Employees employee = await context.Employees
                    .Where(x => x.id == id) 
                    .SingleAsync();

                var viewForm = Program.ServiceProvider.GetRequiredService<EmployeeViewForm>();
                viewForm.SetEmployee(employee);
                viewForm.Show();
            
           
        }


        private async void empGrid_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string id = dataGridView1.Rows[e.RowIndex].Cells["id"].Value.ToString();
            await ShowEmployeeView(id);
        }


        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            var form = Program.ServiceProvider.GetRequiredService<EmployeeForm>();
            if (form.ShowDialog() == DialogResult.OK)
            {

            }
            
        }
    }
}
