private void Bug_Load(object sender, EventArgs e) { Bug vb = new Bug(); DataTable dt = vb.Select_bug(); dataGridView.DataSource = dt; string type = Form1.usertype; if (type == "admin") { label_header.Text = "Manage bug"; } else { label_header.Text = "Enter a new bug"; } }
private void button_delete_Click(object sender, EventArgs e) { //Checking if the user is admin or user or debugger string type = Form1.usertype; if (type == "admin") { //Database connection MySqlConnection conn = new MySqlConnection("server = localhost; user id = root; database = bugtrack"); MySqlCommand sda = new MySqlCommand("DELETE FROM bugreport WHERE id='" + this.textBox_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 Bug vb = new Bug(); DataTable dt = vb.Select_bug(); dataGridView.DataSource = dt; //Clear all the Input fields textBox_bugid.Clear(); comboBox_project.Text = ""; textBox_bugtitle.Clear(); textBox_bugissue.Clear(); reportDate.Text = ""; lbl_img_path.Text = "path"; combo_bugStatus.Text = ""; } else { //Delete Failed Message MessageBox.Show("Failed to delte bug. Please Try Again."); } } else { //Display message MessageBox.Show("Sorry! You are not allowed to remove any data."); } }
//For searching private void textBox_search_TextChanged(object sender, EventArgs e) { //get keyword from textbox string keyword = textBox_search.Text; Bug vb1 = new Bug(); //check if keywords have value or not if (keyword != null) { //show user based based on keywords DataTable dt = vb1.Search_bug(keyword); dataGridView.DataSource = dt; } else { //show all user from database DataTable dt = vb1.Select_bug(); dataGridView.DataSource = dt; } }
private void button_update_Click(object sender, EventArgs e) { MySqlConnection conn = new MySqlConnection("server = localhost; user id = root; database = bugtrack"); int BugID = 0; if (textBox_bugid.Text.Trim() != "") { BugID = int.Parse(textBox_bugid.Text.Trim()); } string ProjectTitle = comboBox_project.Text.ToString(); string BugTitle = textBox_bugtitle.Text.Trim(); string BugDescription = textBox_bugissue.Text.Trim(); string ReportDate = reportDate.Text.Trim(); string ImagePath = lbl_img_path.Text.Trim(); string status = combo_bugStatus.Text.ToString(); //getting loggedin user in added by field string loggedusertype = Form1.usertype; string reportedby = loggedusertype; ReportDate = DateTime.Now.ToString("yyyy-MM-dd"); try { //Database connection MySqlCommand sda = new MySqlCommand("update bugreport set project='" + this.comboBox_project.Text + "',bugtitle='" + this.textBox_bugtitle.Text + "',bugissue='" + this.textBox_bugissue.Text + "',reportdate='" + this.reportDate.Text + "',status='" + this.combo_bugStatus.Text + "',image='" + this.lbl_img_path.Text + "' where bugreport.id='" + this.textBox_bugid.Text + "'", conn); 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 Bug vb = new Bug(); DataTable dt = vb.Select_bug(); dataGridView.DataSource = dt; //Clear all the Input fields textBox_bugid.Clear(); comboBox_project.Text = ""; textBox_bugtitle.Clear(); textBox_bugissue.Clear(); reportDate.Text = ""; lbl_img_path.Text = "path"; combo_bugStatus.Text = ""; } else { MessageBox.Show("Bug failed to update. click ok to continue"); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } finally { //Step :CLose Connection conn.Close(); } }