private void generatebtn_Click(object sender, RoutedEventArgs e) { if (SystemClass.CheckConnection()) { if (fundcb.SelectedValue == null) { MessageBox.Show("Please select fund"); } else if (String.IsNullOrEmpty(startdatedp.Text) || String.IsNullOrEmpty(enddatedp.Text)) { MessageBox.Show("Please select start date and end date"); } else { DateTime dateToday = DateTime.Now; string year = dateToday.Year.ToString().Substring(dateToday.Year.ToString().Length - 2); string month = dateToday.Month.ToString().PadLeft(2, '0'); int accountId = (int)fundcb.SelectedValue; ImusCityHallEntities db = new ImusCityHallEntities(); CDSSignatory signatories = db.CDSSignatories.FirstOrDefault(); FundBank account = db.FundBanks.Find(accountId); List <CheckIssuedModel> list = new List <CheckIssuedModel>(); if (db.GetCheckIssued(startdatedp.SelectedDate, enddatedp.SelectedDate, accountId).Count() <= 0) { MessageBox.Show("There are no record in this selection"); return; } var result = db.GetCheckIssued(startdatedp.SelectedDate, enddatedp.SelectedDate, accountId); string adviceNo = account.AdviceNo.HasValue ? account.AdviceNo.ToString() : null; foreach (var checkIssued in result) { var check = new CheckIssuedModel { StartDate = startdatedp.SelectedDate.Value, EndDate = enddatedp.SelectedDate.Value, BankName = checkIssued.BankName, AccoutNumber = checkIssued.AccountNumber, ReportNumber = string.Join("-", checkIssued.FundPrefix, year, month, adviceNo), DateCreated = checkIssued.DateCreated.Value, CheckNo = checkIssued.CheckNo, VoucherNo = checkIssued.VoucherNo, Center = "", CompanyName = checkIssued.CompanyName, PaymentNature = checkIssued.PaymentNature, Amount = checkIssued.Amount.Value, DisbursingOfficer = SystemClass.GetSignatory(signatories.DisbursingOfficer), CanDelBy = checkIssued.CAN_DELETE_EMP, CanDelDate = checkIssued.CAN_DELETE_DATE, Status = checkIssued.Status, StatusID = checkIssued.StatusID.Value }; list.Add(check); } ReportDataSet ds = new ReportDataSet(); ds.Locale = CultureInfo.InvariantCulture; // FillDataSet(ds); DataTable chIss = ds.Tables["CheckIssuedDataTable"]; foreach (CheckIssuedModel ci in list) { DataRow dr = chIss.Rows.Add(); dr.SetField("AccountNumber", ci.AccoutNumber); dr.SetField("Amount", ci.Amount); dr.SetField("BankName", ci.BankName); dr.SetField("CanDelBy", ci.CanDelBy); dr.SetField("CanDelDate", ci.CanDelDate); dr.SetField("Center", ci.Center); dr.SetField("CheckNo", ci.CheckNo); dr.SetField("CompanyName", ci.CompanyName); dr.SetField("DateCreated", ci.DateCreated); dr.SetField("DisbursingOfficer", ci.DisbursingOfficer); dr.SetField("EndDate", ci.EndDate); dr.SetField("PaymentNature", ci.PaymentNature); dr.SetField("ReportNumber", ci.ReportNumber); dr.SetField("StartDate", ci.StartDate); dr.SetField("Status", ci.Status); dr.SetField("StatusID", ci.StatusID); dr.SetField("VoucherNo", ci.VoucherNo); } ReportDocument report; report = new CheckDisbursement.Report.CheckIssuedReport(); report.SetDataSource(chIss); report.SetParameterValue("employee", "Generated By: " + SystemClass.Employee(App.EmployeeID)); reportviewer.ViewerCore.ReportSource = report; } } else { MessageBox.Show(SystemClass.DBConnectionErrorMessage); } }
private void generatebtn_Click(object sender, RoutedEventArgs e) { if (SystemClass.CheckConnection()) { if (fundcb.SelectedValue == null) { MessageBox.Show("Please select fund"); } else if (String.IsNullOrEmpty(startdatedp.Text) || String.IsNullOrEmpty(enddatedp.Text)) { MessageBox.Show("Please select start date and end date"); } else { int accountId = (int)fundcb.SelectedValue; ImusCityHallEntities db = new ImusCityHallEntities(); CDSSignatory signatories = db.CDSSignatories.FirstOrDefault(); FundBank account = db.FundBanks.Find(accountId); if (db.GetCheckRegister(startdatedp.SelectedDate, enddatedp.SelectedDate, accountId).Count() <= 0) { MessageBox.Show("There are no record in this selection"); return; } var result = db.GetCheckRegister(startdatedp.SelectedDate, enddatedp.SelectedDate, accountId).Where(m => m.Status == "Created" || m.Status == "Cancelled" || m.Status == "Damaged"); CurrencyToWords convert = new CurrencyToWords(); double totalAmount = Convert.ToDouble(db.GetCheckRegister(startdatedp.SelectedDate, enddatedp.SelectedDate, accountId).Sum(m => m.Amount).Value); string amountInWords = convert.NumberToWords(totalAmount).ToUpper(); ReportDataSet ds = new ReportDataSet(); ds.Locale = CultureInfo.InvariantCulture; DataTable checkRegisterList = ds.Tables["CheckRegisterDataTable"]; foreach (var checkregister in result) { DataRow dr = checkRegisterList.Rows.Add(); dr.SetField("FundName", checkregister.FundName); dr.SetField("Branch", checkregister.Branch); dr.SetField("AccountNumber", checkregister.AccountNumber); dr.SetField("BankName", checkregister.BankName); dr.SetField("DateCreated", checkregister.DateCreated); dr.SetField("CheckNo", checkregister.CheckNo); dr.SetField("CompanyName", checkregister.CompanyName); dr.SetField("Amount", checkregister.Amount); dr.SetField("AmountInWords", amountInWords); dr.SetField("Status", checkregister.Status); } ReportDocument report; report = new CheckDisbursement.Report.AccountantCheckDisbursementReport(); report.SetDataSource(checkRegisterList); report.SetParameterValue("Signatory1", SystemClass.GetSignatory(signatories.CityAccountant)); report.SetParameterValue("Signatory2", SystemClass.GetSignatory(signatories.AccountantRepresentative)); report.SetParameterValue("AdviceNo", account.AdviceNo.HasValue ? account.AdviceNo.ToString() : ""); report.SetParameterValue("employee", "Generated By: " + SystemClass.Employee(App.EmployeeID)); reportviewer.ViewerCore.ReportSource = report; } } else { MessageBox.Show(SystemClass.DBConnectionErrorMessage); } }