Example #1
0
        private void SetTenantPreference()
        {
            Preference tenantPreference1 = new Preference();

            tenantPreference1.tenantId = tenant.id;
            tenantPreference1.name     = "sysSender";
            tenantPreference1.value    = "*****@*****.**";
            tenantPreference1.type     = "System.String";

            Preference tenantPreference2 = new Preference();

            tenantPreference2.tenantId = tenant.id;
            tenantPreference2.name     = "exportFormat";
            tenantPreference2.value    = "0"; // Por default exporta para PDF
            tenantPreference2.type     = "System.Int32";

            Preference tenantPreference3 = new Preference();

            tenantPreference3.tenantId = tenant.id;
            tenantPreference3.name     = "periodEndDate";
            tenantPreference3.value    = "1"; // Por default considera o periodo terminando no dia 1 as zero horas (na virada do mês)
            tenantPreference3.type     = "System.Int32";

            PreferenceDAO preferenceDAO = new PreferenceDAO(sqlConnection);

            preferenceDAO.SetTenantPreference(tenantPreference1);
            preferenceDAO.SetTenantPreference(tenantPreference2);
            preferenceDAO.SetTenantPreference(tenantPreference3);
        }
Example #2
0
        public void Execute()
        {
            // Verifica se as dependências foram instanciadas (se o método InitializeTaskState foi chamado)
            if (taskParams == null)
            {
                return;
            }
            if (dataAccess == null)
            {
                return;
            }
            if (notifications == null)
            {
                return;
            }
            if (fileLogger == null)
            {
                return;
            }

            dataAccess.OpenConnection();

            TenantDAO     tenantDAO     = new TenantDAO(dataAccess.GetConnection());
            PreferenceDAO preferenceDAO = new PreferenceDAO(dataAccess.GetConnection());
            MailingDAO    mailingDAO    = new MailingDAO(dataAccess.GetConnection());

            List <Object> tenantList = tenantDAO.GetAllTenants();

            foreach (Tenant tenant in tenantList)
            {
                currentTenant = tenant.id;
                Preference senderPreference = preferenceDAO.GetTenantPreference(currentTenant, "sysSender");
                currentSysSender = senderPreference.value;
                Preference exportPreference = preferenceDAO.GetTenantPreference(currentTenant, "exportFormat");
                int        exportFormat     = 0; // o default é eportar para PDF
                if (exportPreference != null)
                {
                    exportFormat = int.Parse(exportPreference.value);
                }
                currentFormatExtension = GetFormatExtension(exportFormat);
                Preference endDatePreference = preferenceDAO.GetTenantPreference(currentTenant, "periodEndDate");
                currentPeriodEndDate = 1; // o default é o periodo entre o dia 1 deste mês e o dia 1 do mês passado
                if (endDatePreference != null)
                {
                    currentPeriodEndDate = int.Parse(endDatePreference.value);
                }
                currentReportBuilder = GetReportBuilder(exportFormat);

                List <Object> mailingList = mailingDAO.GetAllMailings(currentTenant);
                foreach (Mailing mailing in mailingList)
                {
                    ProcessMailing(mailingDAO, mailing);
                }
            }

            dataAccess.CloseConnection();
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            accountingMasterPage = (AccountingMasterPage)Page.Master;
            accountingMasterPage.InitializeMasterPageComponents();
            dataAccess = accountingMasterPage.dataAccess;

            if (!Authorization.AuthorizedAsAdministrator(Session))
            {
                // Remove todos os controles da página
                configurationArea.Controls.Clear();
                controlArea.Controls.Clear();

                // Mostra aviso de falta de autorização
                WarningMessage.Show(controlArea, Authorization.GetWarning());
                return;
            }

            Tenant        tenant      = (Tenant)Session["tenant"];
            SettingsInput tenantInput = new SettingsInput(pnlTenant, null);

            tenantInput.Add("txtTenantAlias", "Nome amigável", tenant.alias);

            preferenceDAO = new PreferenceDAO(dataAccess.GetConnection());
            Preference sysSender    = preferenceDAO.GetTenantPreference(tenant.id, "sysSender");
            Preference exportFormat = preferenceDAO.GetTenantPreference(tenant.id, "exportFormat");

            if (exportFormat == null)
            {
                // Se não existe no banco cria a entrada
                exportFormat       = new Preference();
                exportFormat.id    = 0;
                exportFormat.value = "0";
            }
            Preference periodEndDate = preferenceDAO.GetTenantPreference(tenant.id, "periodEndDate");

            if (periodEndDate == null)
            {
                // Se não existe no banco cria a entrada
                periodEndDate       = new Preference();
                periodEndDate.id    = 0;
                periodEndDate.value = "1";
            }

            SettingsInput tenantPreferencesInput = new SettingsInput(pnlTenantPreferences, null);

            tenantPreferencesInput.AddHidden("txtSysSenderId", sysSender.id.ToString());
            tenantPreferencesInput.Add("txtSysSenderValue", "Remetente e-mails do sistema", sysSender.value);
            tenantPreferencesInput.AddHidden("txtExportFormatId", exportFormat.id.ToString());
            tenantPreferencesInput.AddDropDownList("cmbExportFormatValue", "Formato de exportação", int.Parse(exportFormat.value), typeof(ExportFormatEnum));
            tenantPreferencesInput.AddHidden("txtPeriodEndDateId", periodEndDate.id.ToString());
            tenantPreferencesInput.AddDropDownList("cmbPeriodEndDateValue", "Fechamento de período", int.Parse(periodEndDate.value), typeof(PeriodDelimiterEnum));
        }
Example #4
0
        public static Dictionary <String, Object> GetExportOptions(int tenantId, SqlConnection sqlConnection)
        {
            ExportFormatEnum currentFormat = ExportFormatEnum.PDF;

            PreferenceDAO preferenceDAO = new PreferenceDAO(sqlConnection);
            Preference    exportFormat  = preferenceDAO.GetTenantPreference(tenantId, "exportFormat");

            // A conversão abaixo seria propensa a estouros de exceção visto que não esão sendo feitas
            // verificações de tipo, faixa de inteiro, etc. Estas verificações são um pouco redundantes
            // pois os valores gravados no banco tem garantia de corretude
            if (exportFormat != null)
            {
                currentFormat = (ExportFormatEnum)int.Parse(exportFormat.value);
            }

            return(GetExportOptions(currentFormat));
        }
Example #5
0
        private static ExportFormatEnum GetCurrentFormat(HttpSessionState Session)
        {
            // Obtem os dados da sessão e servidor web
            Tenant            tenant = (Tenant)Session["tenant"];
            HttpServerUtility server = HttpContext.Current.Server;

            // Abre a conexão com o banco
            DataAccess dataAccess = DataAccess.Instance;

            dataAccess.MountConnection(FileResource.MapWebResource(server, "DataAccess.xml"), DatabaseEnum.PrintAccounting);
            dataAccess.OpenConnection();

            // Busca no banco o formato configurado para exportação
            PreferenceDAO preferenceDAO = new PreferenceDAO(dataAccess.GetConnection());
            Preference    exportFormat  = preferenceDAO.GetTenantPreference(tenant.id, "exportFormat");

            if (exportFormat == null)
            {
                return(ExportFormatEnum.PDF); // não esta configurado, retorna default
            }
            // Fecha a conexão com o banco
            dataAccess.CloseConnection();
            dataAccess = null;

            // Verifica se é um inteiro
            int     storedFormat;
            Boolean retrieved = int.TryParse(exportFormat.value, out storedFormat);

            if (!retrieved)
            {
                return(ExportFormatEnum.PDF); // dado incorreto configurado no BD, retorna default
            }
            // Verifica se está na faixa de valores aceitos
            if ((storedFormat < 0) || (storedFormat > 2)) // PDF = 0, XLS = 1, CSV = 2
            {
                return(ExportFormatEnum.PDF);             // fora de faixa, retorna default
            }
            return((ExportFormatEnum)storedFormat);
        }