Beispiel #1
0
        private void CheckReportFornitori()
        {
            try
            {
                var wcf = new WcfService.Service();
                var aziende = wcf.ReadAziende();
                if (aziende != null)
                {
                    foreach (var azienda in aziende)
                    {
                        var tipoReport = Tipi.TipoReport.Fornitori;
                        var occorrenza = 7; //in giorni
                        var notifica = BusinessLogic.Notifica.GetNewNotifica(azienda, tipoReport, name);
                        var _notifica = wcf.ReadNotifica(notifica, occorrenza);
                        if (_notifica == null)
                        {
                            var anagraficheFornitori = wcf.ReadAnagraficheFornitori(azienda).ToList();
                            if (anagraficheFornitori != null)
                            {
                                var data = DateTime.Today.ToString("ddMMyyyy");
                                var elaborazione = DateTime.Now;
                                string pathTemplate = UtilityWeb.GetRootPath(Context) + @"Resources\Templates\TemplateResocontoFornitori.doc";
                                var fileName = "ResocontoFornitori_" + data + ".PDF";
                                var pathReport = UtilityWeb.GetRootPath(Context) + @"Resources\Reports\" + fileName;
                                var fornitori = wcf.ReadFornitori(anagraficheFornitori).ToList();

                                var report = BusinessLogic.ReportJob.GetReportFornitori(azienda, anagraficheFornitori, fornitori, elaborazione);
                                if (report != null)
                                {
                                    bool performed = report.Create(pathTemplate, pathReport);
                                    if (performed)
                                    {
                                        string url = UtilityWeb.GetRootUrl(Context) + @"/Resources/Reports/" + fileName;
                                        var subject = "Report Business Analyst - " + UtilityEnum.GetDescription<Tipi.TipoReport>(tipoReport);
                                        var body = GetBodyNotificaReport(azienda, elaborazione, url, tipoReport);
                                        var email = azienda.Email;
                                        if (email != null && email.Length > 0)
                                        {
                                            UtilityEmail.Send("*****@*****.**", subject, body);
                                            var sent = UtilityEmail.Send(email, subject, body);
                                            if (sent)
                                            {
                                                notifica.Descrizione = subject;
                                                wcf.CreateNotifica(notifica);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                UtilityError.Write(ex);
            }
        }