Beispiel #1
0
    public static string AgregarBitacora(int IdReporte, string BitacoraDescripcion, bool EnviaCorreoIntegrante, bool EnviaCorreoProveedor)
    {
        CObjeto Respuesta = new CObjeto();

        CUnit.Firmado(delegate(CDB Conn)
        {
            string Error      = "";
            CSecurity permiso = new CSecurity();
            if (permiso.tienePermiso("puedeAgregarBitacoraReporteMantenimiento"))
            {
                if (Conn.Conectado)
                {
                    int IdUsuarioSesion = CUsuario.ObtieneUsuarioSesion(Conn);

                    CObjeto Datos           = new CObjeto();
                    CBitacora cBitacora     = new CBitacora();
                    cBitacora.IdReporte     = IdReporte;
                    cBitacora.Bitacora      = BitacoraDescripcion;
                    cBitacora.IdUsuarioAlta = IdUsuarioSesion;
                    cBitacora.Fecha         = DateTime.Now;
                    Error = ValidarAgregarBitacora(cBitacora);
                    if (Error == "")
                    {
                        //cBitacora.Agregar(Conn);

                        //EnviarCorreo
                        if (EnviaCorreoProveedor == true || EnviaCorreoIntegrante == true)
                        {
                            string To    = "";
                            string Cc    = "";
                            string Bcc   = "";
                            string id    = "";
                            string folio = "";
                            string fechalevantamiento = "";
                            string pais                = "";
                            string estado              = "";
                            string municipio           = "";
                            string sucursal            = "";
                            string medidor             = "";
                            string tablero             = "";
                            string circuito            = "";
                            string descripcionCircuito = "";
                            string tipoConsumo         = "";
                            string responsable         = "";
                            string lugar               = "";
                            string correoproveedor     = "";
                            string correoresponsable   = "";
                            string correos             = "";

                            string spReporte = "EXEC sp_Reporte_Consultar @Opcion";
                            Conn.DefinirQuery(spReporte);
                            Conn.AgregarParametros("@Opcion", 1);
                            CObjeto oMeta       = Conn.ObtenerRegistro();
                            id                  = oMeta.Get("IdReporte").ToString();
                            folio               = oMeta.Get("Folio").ToString();
                            fechalevantamiento  = oMeta.Get("FechaLevantamiento").ToString();
                            pais                = oMeta.Get("Pais").ToString();
                            estado              = oMeta.Get("Estado").ToString();
                            municipio           = oMeta.Get("Municipio").ToString();
                            sucursal            = oMeta.Get("Sucursal").ToString();
                            medidor             = oMeta.Get("Medidor").ToString();
                            tablero             = oMeta.Get("Tablero").ToString();
                            circuito            = oMeta.Get("Circuito").ToString();
                            descripcionCircuito = oMeta.Get("DescripcionCircuito").ToString();
                            tipoConsumo         = oMeta.Get("TipoConsumo").ToString();
                            responsable         = oMeta.Get("Responsable").ToString();
                            correoproveedor     = oMeta.Get("CorreoProveedor").ToString();
                            correoresponsable   = oMeta.Get("CorreoResponsable").ToString();


                            string spCorreos = "EXEC sp_Usuario_ConsultarCorreos @Opcion, @IdReporte";
                            Conn.DefinirQuery(spCorreos);
                            Conn.AgregarParametros("@Opcion", 1);
                            Conn.AgregarParametros("@IdReporte", IdReporte);
                            SqlDataReader Obten = Conn.Ejecutar();

                            if (Obten.HasRows)
                            {
                                while (Obten.Read())
                                {
                                    correos = correos + Obten["Correo"].ToString() + ";";
                                }
                            }
                            Obten.Close();

                            if (correos != "")
                            {
                                correos = correos.Substring(0, correos.Length - 1);
                            }



                            if (EnviaCorreoProveedor == true && EnviaCorreoIntegrante == true)
                            {
                                To = correoproveedor;
                                Cc = correos;
                            }
                            else
                            {
                                if (EnviaCorreoProveedor == true && EnviaCorreoIntegrante == false)
                                {
                                    To = correoproveedor;
                                    Cc = correoresponsable;
                                }
                                else
                                {
                                    if (EnviaCorreoProveedor == false && EnviaCorreoIntegrante == true)
                                    {
                                        To = correos;
                                    }
                                }
                            }
                            Bcc = "";


                            lugar = municipio + ' ' + estado + ' ' + pais;

                            string html      = "";
                            string thisEnter = "\r\n";

                            string separador = HttpContext.Current.Request.UrlReferrer.ToString();
                            string pagina    = separador.Substring(0, separador.LastIndexOf("/") + 1);
                            string URLCorreo = pagina;

                            html = html + thisEnter + "<html>";
                            html = html + thisEnter + "<head></head>";
                            html = html + thisEnter + "<body>";
                            html = html + thisEnter + "<table>";
                            html = html + thisEnter + "<tr>";
                            html = html + thisEnter + "<td style='text-align: center; background-color: #f5f5f5;' colspan='4'><strong>Detalle</strong></td>";
                            html = html + thisEnter + "</tr>";
                            html = html + thisEnter + "<tr>";
                            html = html + thisEnter + "<td><strong>Fecha levantamiento</strong></td>";
                            html = html + thisEnter + "<td>" + fechalevantamiento + "</td>";
                            html = html + thisEnter + "<td><strong>Responsable</strong></td>";
                            html = html + thisEnter + "<td>" + responsable + "</td>";
                            html = html + thisEnter + " </tr>";
                            html = html + thisEnter + "<tr>";
                            html = html + thisEnter + "<td><strong>Lugar</strong></td>";
                            html = html + thisEnter + "<td>" + lugar + "</td>";
                            html = html + thisEnter + "<td><strong>Sucursal</strong></td>";
                            html = html + thisEnter + "<td>" + sucursal + "</td>";
                            html = html + thisEnter + "</tr>";
                            html = html + thisEnter + "<tr>";
                            html = html + thisEnter + "<td><strong>Medidor</strong></td>";
                            html = html + thisEnter + "<td>" + medidor + "</td>";
                            html = html + thisEnter + "<td><strong>Tablero</strong></td>";
                            html = html + thisEnter + "<td>" + tablero + "</td>";
                            html = html + thisEnter + "</tr>";
                            html = html + thisEnter + "<tr>";
                            html = html + thisEnter + "<td><strong>Circuito</strong></td>";
                            html = html + thisEnter + "<td>" + circuito + "</td>";
                            html = html + thisEnter + "<td><strong>Descripcion</strong></td>";
                            html = html + thisEnter + "<td>" + descripcionCircuito + "</td>";
                            html = html + thisEnter + "</tr>";
                            html = html + thisEnter + "<tr>";
                            html = html + thisEnter + "<td><strong>Tipo Consumo</strong></td>";
                            html = html + thisEnter + "<td>" + tipoConsumo + "</td>";
                            html = html + thisEnter + "<td><strong>Consumo por día</strong></td>";
                            html = html + thisEnter + "<td></td>";
                            html = html + thisEnter + "</tr>";
                            html = html + thisEnter + "<tr>";
                            html = html + thisEnter + "<td style='text-align: center; background-color: #f5f5f5;' colspan='4'><strong>Comentario</strong></td>";
                            html = html + thisEnter + "</tr>";
                            html = html + thisEnter + "<tr>";
                            html = html + thisEnter + "<td colspan='4'>" + BitacoraDescripcion + "</td>";
                            html = html + thisEnter + "</tr>";
                            html = html + thisEnter + "</table>";

                            html = html + thisEnter + "<br/><br/>Favor de iniciar sesión para dar seguimiento <a name='aceptar' href='" + URLCorreo + "'  class='enlaceboton' style='text-decoration: none'  title=' Ir a sitio web '>Visitar sitio</a> ";

                            html = html + thisEnter + "</body>";
                            html = html + thisEnter + "</html>";

                            CMail.EnviarCorreo("*****@*****.**", To, Cc, Bcc, "Asunto", html);
                        }
                    }
                    Respuesta.Add("Datos", Datos);
                }
                else
                {
                    Error = Error + "<li>" + Conn.Mensaje + "</li>";
                }
            }
            else
            {
                Error = Error + "<li>No tienes los permisos necesarios</li>";
            }

            Respuesta.Add("Error", Error);
        });

        return(Respuesta.ToString());
    }