/// <summary> /// Method for populating the DataDridView /// </summary> public void populateDataGridView() { if (DbConnector.OpenSQLConnection()) // Open connection to the database { // Connection opened DefectDataAccess defect = new DefectDataAccess(); dgvDefect.AutoGenerateColumns = false; // To only show the columns needed if (FormProvider.Dashboard.role == "Tester") { dgvDefect.DataSource = defect.FindDefects(FormProvider.Dashboard.username, "Tester"); } else if (FormProvider.Dashboard.role == "Developer") { dgvDefect.DataSource = defect.FindDefects(FormProvider.Dashboard.username, "Dev"); } else { dgvDefect.DataSource = defect.GetAllDefects(); } txtSearchDefects.Text = ""; Defects_Tab_Child.getInstance().clearDefectText(); } 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> /// Populate the datagridview with search result /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSearchDefects_Click(object sender, EventArgs e) { if (DbConnector.OpenSQLConnection()) // Open connection to the database { // Connection opened DefectDataAccess defect = new DefectDataAccess(); dgvDefect.AutoGenerateColumns = false; // To only show the columns needed if (FormProvider.Dashboard.role == "Tester") { if (txtSearchDefects.Text != "") { dgvDefect.DataSource = defect.SearchDefects(FormProvider.Dashboard.username, txtSearchDefects.Text.Trim(), "Tester"); } else { dgvDefect.DataSource = defect.FindDefects(FormProvider.Dashboard.username, "Tester"); } } else if (FormProvider.Dashboard.role == "Developer") { if (txtSearchDefects.Text != "") { dgvDefect.DataSource = defect.SearchDefects(FormProvider.Dashboard.username, txtSearchDefects.Text.Trim(), "Dev"); } else { dgvDefect.DataSource = defect.FindDefects(FormProvider.Dashboard.username, "Dev"); } } else { dgvDefect.DataSource = defect.SearchDefects(txtSearchDefects.Text.Trim()); } } 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 }