public List <ProjectModel> GetAllProjects(int pageNumber, string searchTerm, int numberOfRecords, bool showHiddenProjects, string userID)
        {
            ProjectDataAccess obj = new ProjectDataAccess();
            var result            = obj.GetAllProjects(pageNumber, searchTerm, numberOfRecords, showHiddenProjects, userID);

            return(ConvertProjectDataTableToList(result));
        }
        /// <summary>
        /// Method for populating the DataDridView
        /// </summary>
        public void populateDataGridView()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                ProjectDataAccess project = new ProjectDataAccess();
                dgvProject.AutoGenerateColumns = false; // To only show the columns needed
                dgvProject.DataSource          = project.GetAllProjects();
                txtSearchProjects.Text         = "";
                Projects_Tab_Child.getInstance().clearProjectText();
            }
            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>
        /// Changing the view for insert or update
        /// </summary>
        /// <param name="viewType"></param>
        public void changeView(Defect defect)
        {
            #region Populating the comboBoxProject
            List <Project> projects = new List <Project>();

            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                ProjectDataAccess project = new ProjectDataAccess();
                projects = project.GetAllProjects();
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (projects != null)
            {
                // Populate comboBoxes with data
                foreach (Project p in projects)
                {
                    comboBoxProject.Items.Add(p.ProjectName);
                }
            }
            #endregion

            if (defect == null)
            {
                // Button Add New clicked
                labelTitle.Text         = "Add New Defect";
                btnDefectSave.Text      = "Save";
                panelAssignedTo.Enabled = false;
                comboBoxStatus.Items.Add("New");
                txtRaisedBy.Text = FormProvider.Dashboard.username;
                if (FormProvider.Dashboard.role == "Manager" || FormProvider.Dashboard.role == "Developer")
                {
                    Enabled = false;
                }
            }
            else
            {
                // Button Update clicked
                #region Populating comboBoxAssignedTo
                List <User> developers = new List <User>();

                if (DbConnector.OpenSQLConnection()) // Open connection to the database
                {
                    // Connection opened
                    UserDataAccess user = new UserDataAccess();
                    developers = user.GetActiveDevelopers();
                }
                else
                {
                    // Connection could not be opened
                    MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (developers != null)
                {
                    comboBoxAssignedTo.Items.Clear();

                    // Populate comboBoxes with data
                    foreach (User u in developers)
                    {
                        comboBoxAssignedTo.Items.Add(u.Username);
                    }
                }
                #endregion

                #region Change the view depending on the Action, User and Defect Status
                labelTitle.Text    = "Update Module";
                btnDefectSave.Text = "Update";
                Enabled            = true;
                if (FormProvider.Dashboard.role == "Manager")
                {
                    panelProjectName.Enabled = false;
                    panelModuleName.Enabled  = false;
                    panelDescription.Enabled = false;
                    panelSteps.Enabled       = false;
                    panelRaisedBy.Enabled    = false;
                    panelAssignedTo.Enabled  = true;
                    panelPriority.Enabled    = true;
                }
                else if (FormProvider.Dashboard.role == "Developer")
                {
                    panelProjectName.Enabled = false;
                    panelModuleName.Enabled  = false;
                    panelDescription.Enabled = false;
                    panelSteps.Enabled       = false;
                    panelRaisedBy.Enabled    = false;
                    panelAssignedTo.Enabled  = false;
                    panelPriority.Enabled    = false;
                }
                else if (FormProvider.Dashboard.role == "Tester")
                {
                    panelAssignedTo.Enabled  = false;
                    panelProjectName.Enabled = true;
                    panelModuleName.Enabled  = true;
                    panelDescription.Enabled = true;
                    panelSteps.Enabled       = true;
                    panelRaisedBy.Enabled    = true;
                    panelPriority.Enabled    = true;
                }
                else
                {
                    panelProjectName.Enabled = true;
                    panelModuleName.Enabled  = true;
                    panelDescription.Enabled = true;
                    panelSteps.Enabled       = true;
                    panelRaisedBy.Enabled    = true;
                    panelAssignedTo.Enabled  = true;
                    panelPriority.Enabled    = true;
                }
                defectId             = defect.DefectId;
                comboBoxProject.Text = defect.ProjectName;
                comboBoxModule.Text  = defect.ModuleName;
                txtDescription.Text  = defect.Description;
                txtSteps.Text        = defect.StepsToRepeat;
                txtRaisedBy.Text     = defect.RaisedBy;
                defectStatus         = defect.Status;
                if (defect.Priority == "Low")
                {
                    RadioButtonPriorityLow.Checked = true;
                }
                else if (defect.Priority == "Medium")
                {
                    RadioButtonPriorityMed.Checked = true;
                }
                else
                {
                    RadioButtonPriorityHigh.Checked = true;
                }
                drr = defect.DRR;
                dre = defect.DRE;

                if (defect.AssignedTo != null)
                {
                    comboBoxAssignedTo.Items.Add(defect.AssignedTo);
                }
                comboBoxAssignedTo.Text = currentAssigned = defect.AssignedTo;

                if (defect.Status == "New")
                {
                    comboBoxStatus.Items.Clear();
                    comboBoxStatus.Items.Add("New");
                    if (FormProvider.Dashboard.role != "Tester")
                    {
                        comboBoxStatus.Items.Add("Open");
                        comboBoxStatus.Items.Add("Rejected");
                        comboBoxStatus.Items.Add("Duplicate");
                    }
                    comboBoxStatus.Text = defect.Status;
                }
                else if (defect.Status == "Open")
                {
                    comboBoxStatus.Items.Clear();
                    comboBoxStatus.Items.Add("Open");
                    comboBoxStatus.Text = defect.Status;
                    if (FormProvider.Dashboard.role != "Tester")
                    {
                        comboBoxStatus.Items.Add("Rejected");
                        comboBoxStatus.Items.Add("Duplicate");
                    }
                }
                else if (defect.Status == "Assigned")
                {
                    comboBoxStatus.Items.Clear();
                    comboBoxStatus.Items.Add("Assigned");
                    comboBoxStatus.Text = defect.Status;
                    if (FormProvider.Dashboard.role != "Developer" && FormProvider.Dashboard.role != "Tester")
                    {
                        comboBoxStatus.Items.Add("Rejected");
                        comboBoxStatus.Items.Add("Duplicate");
                        comboBoxStatus.Items.Add("Postponed");
                    }
                    if (FormProvider.Dashboard.role != "Manager" && FormProvider.Dashboard.role != "Tester")
                    {
                        comboBoxStatus.Items.Add("Not Reproducible");
                        comboBoxStatus.Items.Add("Need More Information");
                        comboBoxStatus.Items.Add("Known Defect");
                        comboBoxStatus.Items.Add("Fixed");
                        comboBoxStatus.Items.Add("Ready for Retest");
                    }
                }
                else if (defect.Status == "Rejected")
                {
                    comboBoxStatus.Items.Clear();
                    comboBoxStatus.Items.Add("Rejected");
                    comboBoxStatus.Text = defect.Status;
                    if (FormProvider.Dashboard.role != "Developer")
                    {
                        comboBoxStatus.Items.Add("Closed");
                        comboBoxStatus.Items.Add("Re-Opened");
                    }
                }
                else if (defect.Status == "Duplicate")
                {
                    comboBoxStatus.Items.Clear();
                    comboBoxStatus.Items.Add("Duplicate");
                    comboBoxStatus.Text = defect.Status;
                    if (FormProvider.Dashboard.role != "Developer")
                    {
                        comboBoxStatus.Items.Add("Closed");
                        comboBoxStatus.Items.Add("Re-Opened");
                    }
                }
                else if (defect.Status == "Closed")
                {
                    comboBoxStatus.Items.Clear();
                    comboBoxStatus.Items.Add("Closed");
                    comboBoxStatus.Text = defect.Status;
                }
                else if (defect.Status == "Re-Opened")
                {
                    comboBoxStatus.Items.Clear();
                    comboBoxStatus.Items.Add("Re-Opened");
                    comboBoxStatus.Text = defect.Status;
                    if (FormProvider.Dashboard.role != "Developer" && FormProvider.Dashboard.role != "Tester")
                    {
                        if (comboBoxAssignedTo.Text != "")
                        {
                            comboBoxStatus.Items.Add("Assigned");
                        }
                        comboBoxStatus.Items.Add("Rejected");
                        comboBoxStatus.Items.Add("Duplicate");
                    }
                }
                else if (defect.Status == "Postponed")
                {
                    comboBoxStatus.Items.Clear();
                    comboBoxStatus.Items.Add("Postponed");
                    comboBoxStatus.Text = defect.Status;
                    if (FormProvider.Dashboard.role != "Manager" && FormProvider.Dashboard.role != "Tester")
                    {
                        comboBoxStatus.Items.Add("Not Reproducible");
                        comboBoxStatus.Items.Add("Need More Information");
                        comboBoxStatus.Items.Add("Known Defect");
                        comboBoxStatus.Items.Add("Fixed");
                        comboBoxStatus.Items.Add("Ready for Retest");
                    }
                    if (FormProvider.Dashboard.role != "Developer")
                    {
                        if (FormProvider.Dashboard.role != "Tester")
                        {
                            comboBoxStatus.Items.Add("Rejected");
                            comboBoxStatus.Items.Add("Duplicate");
                        }
                        comboBoxStatus.Items.Add("Closed");
                    }
                }
                else if (defect.Status == "Ready for Retest")
                {
                    comboBoxStatus.Items.Clear();
                    comboBoxStatus.Items.Add("Ready for Retest");
                    comboBoxStatus.Text = defect.Status;
                    if (FormProvider.Dashboard.role != "Developer")
                    {
                        comboBoxStatus.Items.Add("Closed");
                        comboBoxStatus.Items.Add("Re-Opened");
                    }
                }
                else
                {
                    comboBoxStatus.Items.Clear();
                    if (FormProvider.Dashboard.role != "Manager" && FormProvider.Dashboard.role != "Tester")
                    {
                        comboBoxStatus.Items.Add("Not Reproducible");
                        comboBoxStatus.Items.Add("Need More Information");
                        comboBoxStatus.Items.Add("Known Defect");
                        comboBoxStatus.Items.Add("Fixed");
                        comboBoxStatus.Items.Add("Ready for Retest");
                    }
                    if (FormProvider.Dashboard.role != "Developer")
                    {
                        comboBoxStatus.Items.Add("Closed");
                        comboBoxStatus.Items.Add("Re-Opened");
                    }
                    comboBoxStatus.Text = defect.Status;
                }
                #endregion

                if (comboBoxStatus.Text == "Closed")
                {
                    panelDefectAdd.Enabled = false;
                }
                else
                {
                    panelDefectAdd.Enabled = true;
                }
            }
        }