private void BugReport_load(object sender, EventArgs e) { //to get project titile from database MySqlConnection conn = new MySqlConnection("server = localhost; user id = root; database = bugtracker"); MySqlDataReader myreader; try { //getting data from database using dataadapter MySqlCommand sda = new MySqlCommand("Select ProjectTitle from bug", conn); //Create a Datatable to hold the records from database //Step 5:Open Connection conn.Open(); myreader = sda.ExecuteReader(); while (myreader.Read()) { comboBoxProject.Items.Add(myreader.GetValue(0).ToString()); } conn.Close(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } finally { //Step 8: Close Connection conn.Close(); } // WindowState = FormWindowState.Maximized; BugReport vb = new BugReport(); DataTable dt = vb.Select_bug(); dgv_bug.DataSource = dt; string type = login.loggedIN_utype; if (type == "Admin") { lbl_addBug.Text = "Manage bug"; } else { lbl_addBug.Text = "Enter a new bug"; } }
private void btn_delete_Click(object sender, EventArgs e) { //Checking if the user is admin or user or debugger string type = login.loggedIN_utype; if (type == "Admin") { //connecting to the database MySqlConnection conn = new MySqlConnection("server = localhost; user id = root; database = bugtracker"); MySqlCommand sda = new MySqlCommand("DELETE FROM Bug WHERE id='" + this.txtBox_bugID.Text + "'", conn); conn.Open(); //Step 6: Execute cmd int rows = sda.ExecuteNonQuery(); //if sda is success rows value is greater than 0 if (rows > 0) { MessageBox.Show("Bug Deleted Successfully. Thank You."); //Refresh Data Grid View BugReport vb = new BugReport(); DataTable dt = vb.Select_bug(); dgv_bug.DataSource = dt; //Clear all the Input fields txtBox_bugID.Clear(); comboBoxProject.Text = ""; textBox_bugtitle.Clear(); textBox_bugdescription.Clear(); dateTimePicker_reportdate.Text = ""; lbl_img_path.Text = "[image path]"; cmbBox_status.Text = ""; } else { //Delete Failed Message MessageBox.Show("Failed to delete bug. Please Try Again."); } } else { MessageBox.Show("Sorry! You are not allowed to remove any data.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//for searching private void txt_searchbug_TextChanged(object sender, EventArgs e) { //get keyword from textbox string keyword = txt_searchbug.Text; BugReport vb1 = new BugReport(); //check if keywords have value or not if (keyword != null) { //show user based based on keywords DataTable dt = vb1.Search_bug(keyword); dgv_bug.DataSource = dt; } else { //show all user from database DataTable dt = vb1.Select_bug(); dgv_bug.DataSource = dt; } }
private void btn_updatebug_Click(object sender, EventArgs e) { int BugID = 0; if (txtBox_bugID.Text.Trim() != "") { BugID = int.Parse(txtBox_bugID.Text.Trim()); } string ProjectTitle = comboBoxProject.Text.ToString(); string BugTitle = textBox_bugtitle.Text.Trim(); string BugDescription = textBox_bugdescription.Text.Trim(); string ReportDate = dateTimePicker_reportdate.Text.Trim(); string ImagePath = lbl_img_path.Text.Trim(); string status = cmbBox_status.Text.ToString(); // int addedby = ; ReportDate = DateTime.Now.ToString("yyyy-MM-dd"); //connecting to the database MySqlConnection conn = new MySqlConnection("server = localhost; user id = root; database = bugtracker"); try { MySqlCommand sda = new MySqlCommand("update bug set ProjectTitle='" + this.comboBoxProject.Text + "',BugTitle='" + this.textBox_bugtitle.Text + "',BugDescription='" + this.textBox_bugdescription.Text + "',ReportDate='" + this.dateTimePicker_reportdate.Text + "',image='" + this.lbl_img_path.Text + "',status='" + this.cmbBox_status.Text + "' where bug.id='" + this.txtBox_bugID.Text + "'", conn); //Open Connection conn.Open(); int rows = sda.ExecuteNonQuery(); //if Inserted rows is greater is greater than 0 //Else set isSuccess to false, Save Failed if (rows > 0) { MessageBox.Show("Bug updated. click ok to continue"); //Refresh Data Grid View BugReport vb = new BugReport(); DataTable dt = vb.Select_bug(); dgv_bug.DataSource = dt; //Clear all the Input fields txtBox_bugID.Clear(); comboBoxProject.Text = ""; textBox_bugtitle.Clear(); textBox_bugdescription.Clear(); dateTimePicker_reportdate.Text = ""; lbl_img_path.Text = "[image path]"; } else { MessageBox.Show("Bug failed to update. click ok to continue"); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } finally { //CLose Connection conn.Close(); } }