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); } }
private void btnSubtract_Click(object sender, EventArgs e) { try { if (lblRegId.Text.Trim().Equals("") || txtDiscount.Text.Trim().Equals("")) { throw new Exception("Nothing to update"); } double discount = 0; if (!Double.TryParse(txtDiscount.Text.Trim(), out discount)) { throw new Exception("Invalid discount or subsidy value."); } int discounttype = 0; if (rbSubsidy.Checked) { discounttype = 1; } long id = new Assessment().GetAssessment(Convert.ToInt64(lblRegId.Text.Trim())).Id; double tuition = 0; bool tbool = Double.TryParse(lblTuition.Text.Trim(), out tuition); if (!tbool || tuition == 0) { throw new Exception("Invalid tuition amount"); } bool success = new AssessmentDetail().UpdateTuition(id, tuition - discount, discount, discounttype); if (success) { Assessment asses = new Assessment().GetAssessment(Convert.ToInt64(lblRegId.Text.Trim())); dgvAssessDetail.DataSource = asses.AssessmentDetail; dgvAssessDetail.Columns[0].Width = 75; dgvAssessDetail.Columns[1].Width = 300; dgvAssessDetail.Columns[2].Width = 75; dgvAssessDetail.Columns[3].Visible = false; //feetype dgvAssessDetail.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dgvAssessDetail.Columns[2].DefaultCellStyle.Format = string.Format("N2"); RefreshDetails(); MessageBox.Show("Assessment update successful!"); } else { throw new Exception("Updating this assessment failed, server might be offline or nothing to update."); } } 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) { txtDiscount.Text = string.Empty; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }