Example #1
0
        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));
                }
            }
        }