Exemple #1
0
        private static Boolean AreContractsActive(DataConnector connector, MailingDTO mailing)
        {
            Boolean active;

            ContractDAO     contractDAO     = new ContractDAO(connector.MySqlConnection);
            ContractItemDAO contractItemDAO = new ContractItemDAO(connector.MySqlConnection);

            // Faturamento de um contrato apenas
            if (mailing.codigoContrato != 0)
            {
                ContractDTO contract = contractDAO.GetContract(mailing.codigoContrato);
                active = (contract.status != 3) && (contract.status != 4);
                return(active);
            }

            // Caso contrário é o faturamento de todos os equipamentos do cliente (um ou mais contratos)
            active = false;
            List <ContractItemDTO> itemList = contractItemDAO.GetItems("businessPartnerCode = '" + mailing.businessPartnerCode + "'");

            foreach (ContractItemDTO item in itemList)
            {
                ContractDTO contract = contractDAO.GetContract(item.contrato_id);
                if ((contract.status != 3) && (contract.status != 4))
                {
                    active = true;
                }
            }
            return(active);
        }
Exemple #2
0
        public void SetMailing(MailingDTO mailing)
        {
            String commandText = "UPDATE `addoncontratos`.`mailing` SET" +
                                 "  businessPartnerCode='" + mailing.businessPartnerCode + "'" +
                                 ", businessPartnerName='" + mailing.businessPartnerName + "'" +
                                 ", contrato_id=" + mailing.codigoContrato +
                                 ", subContrato_id=" + mailing.codigoSubContrato +
                                 ", diaFaturamento=" + mailing.diaFaturamento +
                                 ", destinatarios='" + mailing.destinatarios + "'" +
                                 ", enviarDemonstrativo=" + mailing.enviarDemonstrativo +
                                 ", ultimoEnvio=@param1" +
                                 " WHERE id =" + mailing.id;

            if (mailing.id == 0)
            {
                commandText = "INSERT INTO `addoncontratos`.`mailing` VALUES (NULL, '" + mailing.businessPartnerCode + "', " + mailing.codigoContrato + "', " + mailing.diaFaturamento + ", '" + mailing.destinatarios + "', " + mailing.enviarDemonstrativo + ", @param1)";
            }
            MySqlParameter param1 = new MySqlParameter("@param1", MySqlDbType.DateTime);

            param1.Value = mailing.ultimoEnvio;
            MySqlCommand command = new MySqlCommand(commandText, this.mySqlConnection);

            command.Parameters.Add(param1);
            command.ExecuteNonQuery();
        }
Exemple #3
0
        public MailingDTO GetMailing(int id)
        {
            MailingDTO mailing = null;

            String          query      = "SELECT * FROM `addoncontratos`.`mailing` WHERE id=" + id;
            MySqlCommand    command    = new MySqlCommand(query, this.mySqlConnection);
            MySqlDataReader dataReader = command.ExecuteReader();

            if (dataReader.Read())
            {
                mailing    = new MailingDTO();
                mailing.id = (int)dataReader["id"];
                mailing.businessPartnerCode = (String)dataReader["businessPartnerCode"];
                mailing.businessPartnerName = (String)dataReader["businessPartnerName"];
                mailing.codigoContrato      = (int)dataReader["contrato_id"];
                mailing.codigoSubContrato   = (int)dataReader["subContrato_id"];
                mailing.diaFaturamento      = (int)dataReader["diaFaturamento"];
                mailing.destinatarios       = (String)dataReader["destinatarios"];
                mailing.enviarDemonstrativo = (Boolean)dataReader["enviarDemonstrativo"];
                mailing.ultimoEnvio         = (DateTime)dataReader["ultimoEnvio"];
            }
            dataReader.Close();

            return(mailing);
        }
Exemple #4
0
        public List <MailingDTO> GetMailings(String filter)
        {
            List <MailingDTO> mailingList = new List <MailingDTO>();

            if (!String.IsNullOrEmpty(filter))
            {
                filter = " WHERE " + filter;
            }
            String          query      = "SELECT * FROM `addoncontratos`.`mailing`" + filter + ";";
            MySqlCommand    command    = new MySqlCommand(query, this.mySqlConnection);
            MySqlDataReader dataReader = command.ExecuteReader();

            while (dataReader.Read())
            {
                MailingDTO mailing = new MailingDTO();
                mailing.id = (int)dataReader["id"];
                mailing.businessPartnerCode = (String)dataReader["businessPartnerCode"];
                mailing.businessPartnerName = (String)dataReader["businessPartnerName"];
                mailing.codigoContrato      = (int)dataReader["contrato_id"];
                mailing.codigoSubContrato   = (int)dataReader["subContrato_id"];
                mailing.diaFaturamento      = (int)dataReader["diaFaturamento"];
                mailing.destinatarios       = (String)dataReader["destinatarios"];
                mailing.enviarDemonstrativo = (Boolean)dataReader["enviarDemonstrativo"];
                mailing.ultimoEnvio         = (DateTime)dataReader["ultimoEnvio"];

                mailingList.Add(mailing);
            }
            dataReader.Close();

            return(mailingList);
        }
        public List <MailingDTO> getListaMailing()
        {
            //ListaUsuarioEmpresaDTO = null;
            List <MailingDTO> ListaMailingDTO = new List <MailingDTO>();
            string            cnxString       = _appDBContext.Database.GetConnectionString();
            SqlConnection     cnx             = new SqlConnection(cnxString);

            try
            {
                cnx.Open();
                using (SqlCommand Sqlcmd = new SqlCommand())
                {
                    Sqlcmd.Connection  = cnx;
                    Sqlcmd.CommandType = CommandType.StoredProcedure;
                    Sqlcmd.CommandText = "SP_S_CONFIGURACION_CORREO_21";

                    SqlDataReader oDataReader = Sqlcmd.ExecuteReader();
                    while (oDataReader.Read())
                    {
                        MailingDTO MailingDTO = new MailingDTO();
                        MailingDTO.id_mailing        = int.Parse(oDataReader["id_mailing"].ToString());
                        MailingDTO.tipo              = int.Parse(oDataReader["tipo"].ToString());
                        MailingDTO.descripcion       = oDataReader["descripcion"].ToString();
                        MailingDTO.descripcion_tipo  = oDataReader["descripcion_tipo"].ToString();
                        MailingDTO.flag_participante = bool.Parse(oDataReader["flag_participante"].ToString());
                        MailingDTO.flag_responsable  = bool.Parse(oDataReader["flag_responsable"].ToString());
                        MailingDTO.otros             = bool.Parse(oDataReader["otros"].ToString());
                        MailingDTO.activo            = bool.Parse(oDataReader["activo"].ToString());



                        ListaMailingDTO.Add(MailingDTO);
                    }
                }
            }
            catch (SqlException sex)
            {
                eErrorLog mensajeLogError = new eErrorLog(
                    sex.Message, "MailingRepository/ListaMailingDTO(). SQL." + sex, "Error Sql");
                mensajeLogError.RegisterLog();
            }
            catch (Exception ex)
            {
                eErrorLog mensajeLogError = new eErrorLog(ex.Message, "MailingRepository/ListaMailingDTO() EX." + ex, "Error");
                mensajeLogError.RegisterLog();
            }
            finally
            {
                if (cnx.State == System.Data.ConnectionState.Open)
                {
                    cnx.Close();
                }
            }


            return(ListaMailingDTO);
        }
        public async Task <IActionResult> GetMail()
        {
            try
            {
                MailingDTO returnModel = new MailingDTO();

                var mail = _bOBackup.TakeBackup();
                Mapper.Map(mail, returnModel);

                return(Ok(new CustomResponse <MailingDTO> {
                    Message = Global.ResponseMessages.Success, StatusCode = StatusCodes.Status200OK, Result = returnModel
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(Error.LogError(ex)));
            }
        }
Exemple #7
0
        private static void SendMailing(DataConnector connector, MailingDTO mailing, SmtpServerDTO server)
        {
            MailMessage mailMessage = null;

            if (mailing.codigoContrato == 0)
            {
                mailMessage = MountBusinessPartnerBilling(connector, mailing.businessPartnerCode, mailing.enviarDemonstrativo);
            }
            else
            {
                mailMessage = MountContractBilling(connector, mailing.codigoContrato, mailing.codigoSubContrato, mailing.enviarDemonstrativo);
            }

            List <String> reportFiles = null;

            if (mailing.enviarDemonstrativo && mailMessage.Attachments.Count > 0)
            {
                reportFiles = new List <String>();
                foreach (Attachment mailAttachment in mailMessage.Attachments)
                {
                    reportFiles.Add(mailAttachment.Name);
                }
            }

            // TODO:  Consertar o envio através do .NET,  utilizar algum componente que funcione, o SmtpClient
            //        da Microsoft não suporta SSL implicito
            SmtpServer smtpServer = SmtpServer.ImportFromDTO(server);
            MailSender mailSender = new MailSender(smtpServer, new TraceHandler());

            mailSender.SetContents(mailMessage.Body, reportFiles);
            Boolean success = mailSender.SendMail("Faturamento de contrato", server.usuario, mailing.destinatarios);

            if (!success)
            {
                // caso não tenha tido sucesso ao enviar através do SmtpClient do .NET tenta enviar pelo PHP
                String mailerUrl       = "http://" + primaryServer + "/Contratos/AjaxCalls/SendEmail.php";
                String mailerParams    = "subject=Faturamento%20de%20contrato&mailBody=" + mailMessage.Body + "&recipients=" + mailing.destinatarios;
                String aditionalParams = "&fileCount=0";
                if (reportFiles != null)
                {
                    aditionalParams = "&fileCount=" + reportFiles.Count;
                    int fileIndex = 0;
                    foreach (String filename in reportFiles)
                    {
                        aditionalParams += "&filename" + fileIndex + "=" + reportFiles[fileIndex];
                        aditionalParams += "&path" + fileIndex + "=" + Environment.CurrentDirectory + @"\" + reportFiles[fileIndex];
                        fileIndex++;
                    }
                }

                RequestHandler mailerRequest = new RequestHandler(mailerUrl, new TraceHandler());
                mailerRequest.StartRequest(mailerParams + aditionalParams, null);
                String mailerResponse = (String)mailerRequest.ParseResponse(typeof(System.String));

                if (mailerResponse == "Email enviado com sucesso!")
                {
                    success = true;
                }
                if (!success)
                {
                    EventLog.WriteEntry("Billing Mailer", mailerResponse);
                }
            }

            if (success) // e-mail enviado com sucesso, grava no banco de dados a data
            {
                MailingDAO mailingDAO = new MailingDAO(connector.MySqlConnection);
                mailing.ultimoEnvio = DateTime.Now;
                mailingDAO.SetMailing(mailing);
            }
        }