Exemplo n.º 1
0
        public Boolean enviarNotificacionesObjetosContrato()
        {
            tools _tools = new tools();

            Boolean correcto = true;

            Conexion conexion = new Conexion(Empresa);

            conexion.IniciarTransaccion();

            try
            {
                DataTable tablaContratosPorNotificar = ObtenerContratosQueNecesitanNotificacionEmail(conexion);

                String  correos    = "";
                Decimal ID_EMPRESA = 0;
                String  mensajeMail;

                String  RAZ_SOCIAL;
                String  NUMERO_CONTRATO;
                String  FECHA;
                String  FCH_VENCE;
                Decimal REGISTRO;

                foreach (DataRow filaContrato in tablaContratosPorNotificar.Rows)
                {
                    try
                    {
                        ID_EMPRESA = Convert.ToDecimal(filaContrato["ID_EMPRESA"]);
                    }
                    catch
                    {
                        ID_EMPRESA = 0;
                    }

                    DataTable tablaUsuarios = ObtenerDatosUsuarioPorEmpreUnidadNegocio(ID_EMPRESA, "REP. COMERCIAL", conexion);
                    DataRow   filaUsuario;

                    correos = String.Empty;

                    for (int i = 0; i < tablaUsuarios.Rows.Count; i++)
                    {
                        filaUsuario = tablaUsuarios.Rows[i];

                        if (filaUsuario["USU_MAIL"] != DBNull.Value)
                        {
                            if (i == 0)
                            {
                                correos = filaUsuario["USU_MAIL"].ToString().Trim();
                            }
                            else
                            {
                                correos += ";" + filaUsuario["USU_MAIL"].ToString().Trim();
                            }
                        }
                    }

                    if (String.IsNullOrEmpty(correos) == false)
                    {
                        RAZ_SOCIAL      = filaContrato["RAZ_SOCIAL"].ToString().Trim().ToUpper();
                        NUMERO_CONTRATO = filaContrato["NUMERO_CONTRATO"].ToString();
                        REGISTRO        = Convert.ToDecimal(filaContrato["REGISTRO"]);

                        try
                        {
                            FECHA = Convert.ToDateTime(filaContrato["FECHA"]).ToLongDateString();
                        }
                        catch
                        {
                            FECHA = "DESCONOCIDA";
                        }
                        try
                        {
                            FCH_VENCE = Convert.ToDateTime(filaContrato["FCH_VENCE"]).ToLongDateString();
                        }
                        catch
                        {
                            FCH_VENCE = "DESCONOCIDA";
                        }

                        mensajeMail = String.Format("<div style=\"text-align:center\"><b>AVISO -CONTRATO/OFERTA MERCANTIL- POR VENCER</b></div><br /><div style=\"text-align:justify\">Señor(a) Representante comercial de <b>{0}</b> el contrato/Oferta mercantil Numero: <b>{1}</b> esta por vencer.<br /><br /><br /><b>Numero Contrato/Oferta Mercantil:</b> {0}.<br /><b>Fecha Inicio:</b> {2}.<br /><b>Fecha Vencimiento:</b> {3}.</div>", RAZ_SOCIAL, NUMERO_CONTRATO, FECHA, FCH_VENCE);

                        if (_tools.enviarCorreoConCuerpoHtml(correos, "CONTRATO/OFERTA MERCANTIL POR VENCER", mensajeMail) == true)
                        {
                            if (ActualizarFechaAvisoNenRContratos(REGISTRO, conexion) == false)
                            {
                                correcto = false;
                                conexion.DeshacerTransaccion();
                                break;
                            }
                        }
                    }
                }

                if (correcto == true)
                {
                    conexion.AceptarTransaccion();
                }
            }
            catch
            {
                conexion.DeshacerTransaccion();
                correcto = false;
            }
            finally
            {
                conexion.Desconectar();
            }

            return(correcto);
        }