/// <summary>
        /// Method for populating the Charts
        /// </summary>
        public void populateCharts()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                ReportsGenerator      reportGen     = new ReportsGenerator();
                List <StatusAnalysis> statusAnalyis = reportGen.StatusAnalysis();

                barChart.DataSource = statusAnalyis.OrderBy(i => i.Status);
                barChart.Series["Defect Count"].XValueMember  = "Status";
                barChart.Series["Defect Count"].YValueMembers = "Count";
                barChart.Series["Defect Count"].YValueType    = ChartValueType.Int32;

                doughnutChart.DataSource = statusAnalyis.OrderBy(i => i.Status);
                doughnutChart.Series["Count"].XValueMember  = "Status";
                doughnutChart.Series["Count"].YValueMembers = "Count";
                doughnutChart.Series["Count"].YValueType    = ChartValueType.Int32;

                DefectDataAccess defect = new DefectDataAccess();
                var defects             = defect.GetAllDefects();
                drePointChart.DataSource = defect.GetAllDefects();
                drePointChart.Series["DRE"].XValueMember  = "DefectId";
                drePointChart.Series["DRE"].YValueMembers = "DRE";
                drePointChart.Series["DRE"].YValueType    = ChartValueType.Int32;

                List <AgeAnalysis> ageAnalysis = new List <AgeAnalysis>();
                foreach (var d in defects.Zip(reportGen.calculateAge(defects), Tuple.Create))
                {
                    ageAnalysis.Add(new AgeAnalysis
                    {
                        DefectId = d.Item1.DefectId,
                        Age      = d.Item2
                    });
                }
                agePointChart.DataSource = ageAnalysis;
                agePointChart.Series["Age"].XValueMember  = "DefectId";
                agePointChart.Series["Age"].YValueMembers = "Age";
                agePointChart.Series["Age"].YValueType    = ChartValueType.Int32;
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                DefectDataAccess defect = new DefectDataAccess();
                dgvAgeAnalysis.AutoGenerateColumns = false; // To only show the columns needed
                var defects = defect.SearchDefectsAnalysis(txtSearchDefects.Text.Trim());
                dgvAgeAnalysis.DataSource = defects;
                ReportsGenerator reportGen = new ReportsGenerator();
                reportGen.calculateAge(defects);
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        /// <summary>
        /// Method for populating the DataDridViews
        /// </summary>
        public void populateDataGridAgeAnalysis()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                DefectDataAccess defect = new DefectDataAccess();
                var defects             = defect.GetAllDefects();
                dgvAgeAnalysis.AutoGenerateColumns = false; // To only show the columns needed
                dgvAgeAnalysis.DataSource          = defects;
                txtSearchDefects.Text = "";
                for (int i = 0; i < defects.Count; i++)
                {
                    ReportsGenerator reportGen = new ReportsGenerator();
                    dgvAgeAnalysis.Rows[i].Cells[7].Value = reportGen.calculateAge(defects)[i];
                }
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }