コード例 #1
0
 private void Guardar(bool NuevoRegistro, string ID, string Title, string Alt, string Descripcion, string FileName, HttpPostedFile PostedImage, bool BandCambioImagen)
 {
     try
     {
         string  BaseDir       = Server.MapPath("");
         string  FileExtension = BandCambioImagen ? Path.GetExtension(FileName) : string.Empty;
         CH_Foto Datos         = new CH_Foto
         {
             NuevoRegistro = NuevoRegistro,
             IDFoto        = ID,
             Title         = Title,
             Alt           = Alt,
             Descripcion   = Descripcion,
             Extension     = FileExtension,
             NombreArchivo = FileName,
             CambioImagen  = BandCambioImagen,
             URLImagen     = BaseDir,
             Conexion      = Comun.Conexion,
             IDUsuario     = User.Identity.Name
         };
         CH_FotoNegocio FN = new CH_FotoNegocio();
         FN.ACFoto(Datos);
         if (Datos.Completado)
         {
             if (BandCambioImagen)
             {
                 if (PostedImage != null && PostedImage.ContentLength > 0)
                 {
                     try
                     {
                         string BaseDirMarca = Server.MapPath("~/Images/MarcaAgua/watermark_final.png");
                         if (File.Exists(BaseDirMarca))
                         {
                             Stream S = PostedImage.InputStream;
                             System.Drawing.Image Img = new System.Drawing.Bitmap(S);
                             Img = UtilImagen.ResizeImageW(Img, 1024);
                             Img = UtilImagen.ResizeImageH(Img, 700);
                             System.Drawing.Image Marca = System.Drawing.Image.FromFile(BaseDirMarca);
                             Img = UtilImagen.SetWaterMark("", Img, Marca);
                             Img.Save(BaseDir + Datos.URLImagen);
                             FN.ImagenSubidaFotoXID(Datos);
                         }
                         else
                         {
                             throw new Exception("No existe la imagen.");
                         }
                     }
                     catch (Exception)
                     {
                         string ScriptError = DialogMessage.Show(TipoMensaje.Error, "Ocurrió un error al guardar la imagen.", "Error", ShowMethod.FadeIn, HideMethod.FadeOut, ToastPosition.TopFullWidth, true);
                         ScriptManager.RegisterStartupScript(this, typeof(Page), "popup", ScriptError, true);
                     }
                 }
             }
             Response.Redirect("frmGaleriaFotos.aspx", false);
         }
         else
         {
             string ScriptError = DialogMessage.Show(TipoMensaje.Error, "Error al guardar los datos.", "Error", ShowMethod.FadeIn, HideMethod.FadeOut, ToastPosition.TopFullWidth, true);
             ScriptManager.RegisterStartupScript(this, typeof(Page), "popup", ScriptError, true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
 private void Guardar(bool NuevoRegistro, string id, string titulo, string tittle, string alt, string descripcion, string FileName, HttpPostedFile PostedImage, bool BandCambioImagen, string textoHtml)
 {
     try
     {
         string  BaseDir       = Server.MapPath("");
         string  FileExtension = BandCambioImagen ? Path.GetExtension(FileName) : string.Empty;
         RR_Blog Datos         = new RR_Blog
         {
             NuevoRegistro = NuevoRegistro,
             IDPublicacion = ID,
             Titulo        = titulo,
             Fecha         = DateTime.Today,
             TextoReducido = textoHtml.Substring(0, 50),
             TextoHtml     = textoHtml,
             UrlImagen     = BaseDir,
             CambioImagen  = BandCambioImagen,
             Alt           = alt,
             Title         = tittle,
             Descripcion   = descripcion,
             TipoArchivo   = FileExtension,
             Conexion      = Comun.Conexion,
             IDUsuario     = Comun.IDUsuario
         };
         RR_AdministradorWebNegocio CN = new RR_AdministradorWebNegocio();
         CN.ACPublicacionesBlog(Datos);
         if (Datos.Completado)
         {
             if (BandCambioImagen)
             {
                 if (PostedImage != null && PostedImage.ContentLength > 0)
                 {
                     try
                     {
                         string BaseDirMarca = Server.MapPath("~/Images/MarcaAgua/watermark_final.png");
                         if (File.Exists(BaseDirMarca))
                         {
                             Stream S = PostedImage.InputStream;
                             System.Drawing.Image Img = new System.Drawing.Bitmap(S);
                             Img = UtilImagen.ResizeImageW(Img, 1024);
                             Img = UtilImagen.ResizeImageH(Img, 700);
                             System.Drawing.Image Marca = System.Drawing.Image.FromFile(BaseDirMarca);
                             Img = UtilImagen.SetWaterMark("", Img, Marca);
                             Img.Save(Datos.UrlImagen);
                         }
                         else
                         {
                             throw new Exception("No existe la imagen.");
                         }
                     }
                     catch (Exception ex)
                     {
                         throw ex;
                         string ScriptError = DialogMessage.Show(TipoMensaje.Error, "Ocurrió un error al guardar la imagen.", "Error", ShowMethod.FadeIn, HideMethod.FadeOut, ToastPosition.TopFullWidth, true);
                         ScriptManager.RegisterStartupScript(this, typeof(Page), "popup", ScriptError, true);
                     }
                 }
             }
             Response.Redirect("frmBlogGrid.aspx", false);
         }
         else
         {
             string ScriptError = DialogMessage.Show(TipoMensaje.Error, "Error al guardar los datos.", "Error",
                                                     ShowMethod.FadeIn, HideMethod.FadeOut, ToastPosition.TopFullWidth, true);
             ScriptManager.RegisterStartupScript(this, typeof(Page), "popup", ScriptError, true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }