private void btnUpdate_Click(object sender, EventArgs e) // Update Button Click event { // Check if the user selected any record to update if (string.IsNullOrWhiteSpace(this.e_userid.Text)) { MessageBox.Show("You did not select any record!", "Error"); } else { // Prompt DialogResult result = MessageBox.Show("Are you sure you want to update this record?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { string connetionString = null; MySqlConnection cnn; connetionString = "server=localhost;database=dcm;uid=root;"; cnn = new MySqlConnection(connetionString); try { if (this.e_lname.Text == "" || this.e_fname.Text == "" || this.e_complainant.Text == "" || this.e_violation.Text == "") { MessageBox.Show("You must fill the required fields!"); } else { cnn.Open(); string query = "Update tblwatchlist set lastname = '" + this.e_lname.Text + "', firstname = '" + this.e_fname.Text + "', othername = '" + this.e_oname.Text + "', bdate = '" + this.e_bday.Value.Date.ToString("yyyy-MM-dd") + "', violation = '" + this.e_violation.Text + "', cmplainant = '" + this.e_complainant.Text + "', middlename = '" + this.e_mname.Text + "', watchstat = '" + e_cmbStatus.Text + "' where userid = '" + this.e_userid.Text + "' "; using (MySqlConnection conn = new MySqlConnection(connetionString)) { MySqlCommand MyCommand2 = new MySqlCommand(query, cnn); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); Homepage f1 = (Homepage)Application.OpenForms["Homepage"]; f1.loaddata(); txtSearch.Text = ""; MessageBox.Show("You successfully updated the record!"); } cnn.Close(); } } catch (Exception ex) { // MessageBox.Show(ex.ToString()); } } else { } } }
private void btnLogin_Click(object sender, EventArgs e) { try { // After success login, show form1 Dialog Homepage f1 = new Homepage(); this.Hide(); f1.ShowDialog(); this.Close(); } catch (Exception eee) { MessageBox.Show(eee.ToString()); } }
private void btnDelete_Click(object sender, EventArgs e) // Delete Button Click event { // For deleting a record (status will be 'FALSE' if (string.IsNullOrWhiteSpace(this.e_userid.Text)) { MessageBox.Show("You did not select any record!", "Error"); } else { DialogResult result = MessageBox.Show("Are you sure you want to delete this record?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { try { cnn.Open(); string query = "Update tblwatchlist set watchstat = 'FALSE' where userid = '" + this.e_userid.Text + "' "; using (MySqlConnection conn = new MySqlConnection(connetionString)) { MySqlCommand MyCommand2 = new MySqlCommand(query, cnn); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); Homepage f1 = (Homepage)Application.OpenForms["Homepage"]; f1.loaddata(); txtSearch.Text = ""; MessageBox.Show("You successfully deleted the record!"); } cnn.Close(); } catch (Exception ex) { //MessageBox.Show(ex.ToString()); } } else if (result == DialogResult.No) { } } }