using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PayrollSystem
{
    public partial class form_dashboard : Form
    {
        int employeeCount = 0;
        int departmentsCount = 0;

        int totalPayAmount = 0;

        public form_dashboard()
        {
            InitializeComponent();
        }

        private void form_dashboard_Load(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection(Helpers.conString))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("SELECT COUNT(id) FROM Departments", con))
                {
                    departmentsCount = (int)cmd.ExecuteScalar();
                }

                using (SqlCommand cmd = new SqlCommand("SELECT Employees.ID, Departments.Basic as basic, Employees.Allowance as allowance FROM Employees JOIN Departments ON Employees.Department_ID=Departments.ID", con))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read()) {
                            int basic = int.Parse(reader["basic"].ToString());
                            int allowance = int.Parse(reader["allowance"].ToString());

                            totalPayAmount += basic + allowance;
                            employeeCount++;
                        }
                    }
                }
            }

            lbl_pay_amount.Text = totalPayAmount.ToString();
            lbl_employee_count.Text = employeeCount.ToString();
            lbl_departments_count.Text = departmentsCount.ToString();
        }
    }
}
