private void printNotasForAccount(BatchExecutionResults results, int accountId, ReportExecutionWrapper reportExecutionWrapper, string pdfOnlineReportsFolder, string pdfPostReportsFolder, bool showLogo) { using (IDalSession session = NHSessionFactory.CreateSession()) { try { List<INota> notas = NotaMapper.GetUnprintedNotasByAccount(session, accountId, NotaType); if (notas.Count > 0) { ICustomerAccount account = notas[0].Account; foreach (INota[] notaGroup in ReportGrouping.GetGroups(notas)) { try { DataSet ds = buildDataSet(session, notaGroup); string pdfFileName = string.Format(@"{0}_{1:d4}_{2}_{3}.pdf", account.Number, account.AccountHolders.PrimaryAccountHolder.Contact.Key, notaGroup[0].NotaNumber, GetFileSuffix(notaGroup)); string pdfOnlineFullPath = string.Format(@"{0}\{1}", pdfOnlineReportsFolder, pdfFileName), pdfPostFullPath = string.Format(@"{0}\{1}", pdfPostReportsFolder, pdfFileName); List<string> paramValues = new List<string>(); GenerateParamValues(paramValues, showLogo, notaGroup); List<string> paramValuesWithShowLogo = copyParamValuesWithShowLogo(paramValues, reportExecutionWrapper.ExtraParamNames); reportExecutionWrapper.Run(ds, pdfOnlineFullPath, paramValuesWithShowLogo.ToArray()); bool needsSendByPost = account.NeedsSendByPost(SendableDocumentCategories.NotasAndQuarterlyReports); if (needsSendByPost) { if (showLogo) File.Copy(pdfOnlineFullPath, pdfPostFullPath, true); else reportExecutionWrapper.Run(ds, pdfPostFullPath, paramValues.ToArray()); } registerNotaPrinting(session, notaGroup, pdfFileName, pdfOnlineReportsFolder, needsSendByPost); results.MarkSuccess(notaGroup.Length); } catch (Exception ex) { results.MarkError(new ApplicationException( string.Format("Error printing nota's ({0}) for account {1} ({2}), in PDF file containing nota number {3}.", NotaType.ToString(), account.DisplayNumberWithName, accountId, notaGroup[0].NotaNumber), ex)); } } } } catch (Exception ex) { ICustomerAccount errAccount = AccountMapper.GetAccount(session, accountId) as ICustomerAccount; string accountNumberWithName = (errAccount != null ? errAccount.DisplayNumberWithName : ""); results.MarkError(new ApplicationException(string.Format("Error retrieving nota's ({0}) for account {1} ({2}).", NotaType.ToString(), accountNumberWithName, accountId), ex)); } } }
public void PrintNotas(BatchExecutionResults results, int managementCompanyId) { string companyDesc = managementCompanyId.ToString(); try { ReportExecutionWrapper reportExecutionWrapper = new ReportExecutionWrapper(); string pdfOnlineReportsFolder = null, pdfPostReportsFolder = null; bool showLogo; using (IDalSession session1 = NHSessionFactory.CreateSession()) { IManagementCompany managementCompany = ManagementCompanyMapper.GetManagementCompany(session1, managementCompanyId); if (managementCompany == null) { results.MarkError( new ApplicationException(string.Format("Management Company with ID '{0}' could not be found.", managementCompanyId))); return; } companyDesc = managementCompany.CompanyName; IReportTemplate reportTemplate = ReportTemplateMapper.GetReportTemplate(session1, managementCompany, ReportName, true); reportExecutionWrapper.SetReportName(reportTemplate.ReportTemplateName); List<string> paramNames = new List<string>(); GenerateParamNames(paramNames); reportExecutionWrapper.AddParameters(paramNames.ToArray()); showLogo = managementCompany.ShowLogoByDefault; pdfOnlineReportsFolder = getPdfReportsFolder(managementCompany, "Online", null); pdfPostReportsFolder = getPdfReportsFolder(managementCompany, "Post", showLogo); } int[] accountIdsWithUnprintedNotas = null; using (IDalSession session2 = NHSessionFactory.CreateSession()) { accountIdsWithUnprintedNotas = NotaMapper.GetAccountsIdsWithUnprintedNotas(session2, managementCompanyId, NotaType); } foreach (int accountid in accountIdsWithUnprintedNotas) printNotasForAccount(results, accountid, reportExecutionWrapper, pdfOnlineReportsFolder, pdfPostReportsFolder, showLogo); } catch (Exception ex) { results.MarkError( new ApplicationException(string.Format("Error while preparing printing of nota's ({0}) for company '{1}'.", NotaType.ToString(), companyDesc), ex)); } }