private void dgvAssessDetail_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (dgvAssessDetail.SelectedRows.Count == 0) { throw new Exception("No data is selected"); } DialogResult dlg = MessageBox.Show("Are you sure to delete this fee?", "Delete Fee", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dlg == DialogResult.Yes) { if (lblStatus.Text.Equals("ENROLLED")) { dlg = MessageBox.Show("Student is officially enrolled, delete may cause inconsistency of record associations to payment. Are you sure?", "Delete Fee", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dlg == DialogResult.No) { return; } } Cursor.Current = Cursors.WaitCursor; string code = dgvAssessDetail.SelectedRows[0].Cells["CODE"].Value.ToString(); long idass = Convert.ToInt64(lblRegId.Tag); AssessmentDetail assdetail = new AssessmentDetail(); bool deletesuccess = assdetail.DeleteAssessmentDetail(idass, code); dgvAssessDetail.DataSource = assdetail.GetAssessmentDetail(idass); RefreshDetails(); Cursor.Current = Cursors.Default; if (deletesuccess) { MessageBox.Show("Delete successful"); } } } catch (MySqlException ex) { if (ex.Number == 1042) { MessageBox.Show("Database server is offline. Contact administrator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(ex.Number + ": " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void dgvFees_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (dgvFees.SelectedRows.Count == 0 || string.IsNullOrEmpty(lblRegId.Text)) { throw new Exception("No data is selected"); } string code = dgvFees.SelectedRows[0].Cells["CODE"].Value.ToString(); string name = dgvFees.SelectedRows[0].Cells["FEE"].Value.ToString(); long idass = Convert.ToInt64(lblRegId.Tag); double amount = Convert.ToDouble(Microsoft.VisualBasic.Interaction.InputBox("Enter amount for " + name, "Input Amount", "0")); Cursor.Current = Cursors.WaitCursor; AssessmentDetail assdetail = new AssessmentDetail(); bool success = assdetail.AddAssessmentDetail(idass, code, amount); if (!success) { throw new Exception("Duplicate fee in assessment"); } else { dgvAssessDetail.DataSource = assdetail.GetAssessmentDetail(idass); RefreshDetails(); MessageBox.Show("Add successful"); } Cursor.Current = Cursors.Default; } catch (MySqlException ex) { if (ex.Number == 1042) { MessageBox.Show("Database server is offline. Contact administrator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(ex.Number + ": " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }