private void tsbSave_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; try { if (txtPurpose.Text.Equals("")) { throw new Exception("Please indicate purpose of disbursement"); } double total = 0; List <PaymentDetail> disburseDetail = new List <PaymentDetail>(); foreach (DataGridViewRow row in dgvSource.Rows) { string rowvalue = (string)row.Cells["colDisburse"].Value; if (!string.IsNullOrWhiteSpace(rowvalue)) { double val = 0; bool isGood = Double.TryParse(row.Cells["colDisburse"].Value.ToString(), out val); if (isGood) { total += val; PaymentDetail pd = new PaymentDetail(); pd.Code = row.Cells["CODE"].Value.ToString(); pd.Amount = val; disburseDetail.Add(pd); } else { throw new Exception("Please check entered amount."); } } } if (total == 0 || disburseDetail.Count == 0) { throw new Exception("Please allocate some amount for disbursement"); } if (new Disbursement().SaveDisbursement(txtPurpose.Text.Trim(), total, disburseDetail)) { MessageBox.Show("Disbursement saved."); tsbClear.PerformClick(); } else { throw new Exception("Error occurs in disbursement"); } } 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) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } Cursor.Current = Cursors.Default; }
public MonthlyDetailReport(ReportViewer rv, string report, DateTime dateTime, int paytype, MonthlyReportType monthlyReportType) : base(rv, report) { List <LedgerItem> ledgerItems = new List <LedgerItem>(); DataTable fees; if (paytype == 1) { fees = new Fee().GetAllStandardFees(); } else if (paytype == 2) { fees = new MonthlyDetail().GetAllNonStandardFees(); } else { fees = new MonthlyDetail().GetAllOtherFees(); } DataTable payments = new MonthlyDetail().GetAllPaymentsInMonth(dateTime, paytype, monthlyReportType); DataTable payDetails = new DataTable(); List <LedgerItem> ledger = new List <LedgerItem>(); foreach (DataRow prow in payments.Rows) { long id = Convert.ToInt64(prow["ID"]); payDetails = new MonthlyDetail().GetPaymentDetailById(id); List <PaymentDetail> paylist = new List <PaymentDetail>(); foreach (DataRow plist in payDetails.Rows) { PaymentDetail pd = new PaymentDetail(); pd.Code = plist["CODE"].ToString(); pd.Amount = Convert.ToDouble(plist["AMOUNT"]); paylist.Add(pd); } //check if item is present in pay type, this is good for fees that have categories transfered foreach (PaymentDetail pitem in paylist) { bool present = false; foreach (DataRow row in fees.Rows) { if (row["CODE"].ToString().Equals(pitem.Code)) { present = true; break; } } if (!present) { DataRow dr = fees.NewRow(); DataTable dt = new DataTable(); dt = new Fee().GetFeeByCode(pitem.Code); foreach (DataRow drow in dt.Rows) { dr[0] = drow["feecode"].ToString(); dr[1] = drow["feename"].ToString(); dr[2] = drow["shortname"].ToString(); dr[3] = Convert.ToInt16(drow["feetype"]); } fees.Rows.Add(dr); } } foreach (DataRow row in fees.Rows) { LedgerItem ledgerItem = new LedgerItem(); ledgerItem.FeeCode = row["CODE"].ToString(); ledgerItem.FeeName = row["SHORT NAME"].ToString(); ledgerItem.OrNumber = prow["OR"].ToString(); ledgerItem.PaymentDate = Convert.ToDateTime(prow["DATE"]); //ledgerItem.AssessmentAmount = Convert.ToDouble(row["AMOUNT"]); //ledgerItem.AssessmentTotal = Assess.Total; foreach (PaymentDetail det in paylist) { if (ledgerItem.FeeCode.Equals(det.Code)) { ledgerItem.PaidAmount = det.Amount; break; } else { ledgerItem.PaidAmount = 0; } } ledger.Add(ledgerItem); } } MonthlyReportTitle title; if (monthlyReportType == MonthlyReportType.HSStandard) { title = new MonthlyReportTitle("STANDARD SCHOOL FEES: JHS, Elem, Pre-school"); } else if (monthlyReportType == MonthlyReportType.HSNonStandard) { title = new MonthlyReportTitle("NON-STANDARD SCHOOL FEES: JHS, Elem, Pre-school"); } else if (monthlyReportType == MonthlyReportType.SHSStandard) { title = new MonthlyReportTitle("STANDARD SCHOOL FEES: Senior High School"); } else if (monthlyReportType == MonthlyReportType.SHSNonStandard) { title = new MonthlyReportTitle("NON-STANDARD SCHOOL FEES: Senior High School"); } else if (monthlyReportType == MonthlyReportType.AllStandard) { title = new MonthlyReportTitle("STANDARD SCHOOL FEES: All Department"); } else if (monthlyReportType == MonthlyReportType.AllNonStandard) { title = new MonthlyReportTitle("NON-STANDARD SCHOOL FEES: All Department"); } else if (monthlyReportType == MonthlyReportType.HSOtherType) { title = new MonthlyReportTitle("OTHER SCHOOL FEES: JHS, Elem, Pre-school"); } else if (monthlyReportType == MonthlyReportType.SHSOtherType) { title = new MonthlyReportTitle("OTHER SCHOOL FEES: Senior High School"); } else { title = new MonthlyReportTitle("OTHER SCHOOL FEES: All Department"); } List <MonthlyReportTitle> titles = new List <MonthlyReportTitle>(); titles.Add(title); ReportDataSource dsReport = new ReportDataSource(); dsReport.Name = "dsPayment"; dsReport.Value = ledger; RViewer.LocalReport.DataSources.Add(dsReport); ReportDataSource dsTitle = new ReportDataSource(); dsTitle.Name = "dsTitle"; dsTitle.Value = titles; RViewer.LocalReport.DataSources.Add(dsTitle); }
private void tsbSave_Click(object sender, EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; if (txtOR.Text.Trim().Equals("") || txtCash.Text.Trim().Equals("") || !Double.TryParse(txtCash.Text.Trim(), out double res)) { throw new Exception("Please fill important fields."); } List <PaymentDetail> paymentItems = new List <PaymentDetail>(); foreach (DataGridViewRow row in dgvBalance.Rows) { string value = (string)row.Cells["txtPayment"].Value; if (!string.IsNullOrWhiteSpace(value)) { if (!Double.TryParse(value, out double val)) { dgvBalance.CurrentCell = row.Cells["txtPayment"]; dgvBalance.BeginEdit(true); throw new Exception("Invalid amount."); } if (Convert.ToDouble(row.Cells["txtPayment"].Value) > Convert.ToDouble(row.Cells["BALANCE"].Value)) { dgvBalance.CurrentCell = row.Cells["txtPayment"]; dgvBalance.BeginEdit(true); throw new Exception("Amount entered is higher than the balance."); } if (Convert.ToDouble(row.Cells["txtPayment"].Value) > 0) { PaymentDetail feeObj = new PaymentDetail(); feeObj.Code = row.Cells["CODE"].Value.ToString(); feeObj.Amount = Convert.ToDouble(row.Cells["txtPayment"].Value); paymentItems.Add(feeObj); } } } double paymentTotal = 0; if (paymentItems.Count > 0 && Double.TryParse(lblTotal.Text.Trim(), out paymentTotal) && paymentTotal > 0) { int paymenttype = 0; if (cmbPaymentType.SelectedIndex == 0) { paymenttype = 1; } else if (cmbPaymentType.SelectedIndex == 1) { paymenttype = 2; } else if (cmbPaymentType.SelectedIndex == 2) { paymenttype = 3; } else if (cmbPaymentType.SelectedIndex == 3) { paymenttype = 4; } Payment payment = new Payment(id_assessment, txtOR.Text.Trim(), Convert.ToDouble(lblTotal.Text.Trim()), (MdiParent as frmMDI).LoginUser.Username, paymenttype); payment.PaymentDetail = paymentItems; if (payment.SavePayment()) { DialogResult dlg = MessageBox.Show("Payment save successful.\nPlease insert Official Receipt(OR) for printing", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Question); if (dlg == DialogResult.OK) { frmReport frReport; if (cmbPaymentType.SelectedIndex == 0) { frReport = new frmReport(ReportTypes.OR); } else if (cmbPaymentType.SelectedIndex == 1 || cmbPaymentType.SelectedIndex == 3) { frReport = new frmReport(ReportTypes.OFOR); } else { frReport = new frmReport(ReportTypes.PTAOR); } frReport.Payer = Payer; frReport.ORNumber = txtOR.Text.Trim(); frReport.MdiParent = MdiParent; frReport.Show(); } tsbClear.PerformClick(); } else { throw new Exception("Error in saving this payment."); } } 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) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public LedgerReport(ReportViewer rv, string report, Student student) : base(rv, report) { Registration Reg = new Registration().GetRegistration(student.Id); Assessment Assess = new Assessment().GetAssessment(Reg.Id); DataTable payments = new Ledger().GetAllPaymentPerAccount(Assess.Id); DataTable payDetail = new DataTable(); List <LedgerItem> ledger = new List <LedgerItem>(); foreach (DataRow prow in payments.Rows) { long id = Convert.ToInt64(prow["ID"]); payDetail = new Ledger().GetPaymentDetailById(id); List <PaymentDetail> paylist = new List <PaymentDetail>(); foreach (DataRow plist in payDetail.Rows) { PaymentDetail pd = new PaymentDetail(); pd.Code = plist["CODE"].ToString(); pd.Amount = Convert.ToDouble(plist["AMOUNT"]); paylist.Add(pd); } foreach (DataRow row in Assess.AssessmentDetail.Rows) { LedgerItem ledgerItem = new LedgerItem(); ledgerItem.FeeCode = row["CODE"].ToString(); ledgerItem.FeeName = row["FEE"].ToString(); ledgerItem.OrNumber = prow["OR"].ToString(); ledgerItem.PaymentDate = Convert.ToDateTime(prow["PAYMENT DATE"]); ledgerItem.AssessmentAmount = Convert.ToDouble(row["AMOUNT"]); ledgerItem.AssessmentTotal = Assess.Total; foreach (PaymentDetail det in paylist) { if (ledgerItem.FeeCode.Equals(det.Code)) { ledgerItem.PaidAmount = det.Amount; break; } else { ledgerItem.PaidAmount = 0; } } ledger.Add(ledgerItem); } } List <PaymentDetail> assList = new List <PaymentDetail>(); foreach (DataRow row in Assess.AssessmentDetail.Rows) { PaymentDetail pd = new PaymentDetail(); pd.Code = row["CODE"].ToString(); pd.Name = row["FEE"].ToString(); pd.Amount = Convert.ToDouble(row["AMOUNT"]); assList.Add(pd); } List <Student> studList = new List <Student>(); studList.Add(student); ReportDataSource dsStud = new ReportDataSource(); dsStud.Name = "dsStudent"; dsStud.Value = studList; RViewer.LocalReport.DataSources.Add(dsStud); ReportDataSource dsLedger = new ReportDataSource(); dsLedger.Name = "dsPayment"; dsLedger.Value = ledger; RViewer.LocalReport.DataSources.Add(dsLedger); }