Example #1
0
        protected void rdgArchivos_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            DBConn oConn = new DBConn();

            if (oConn.Open())
            {
                CmsArchivos oArchivos = new CmsArchivos(ref oConn);
                oArchivos.CodContenido = CodContenido.Value;
                rdgArchivos.DataSource = oArchivos.Get();

                oConn.Close();
            }
        }
Example #2
0
        protected void rdgArchivos_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "cmdDelete":
                StringBuilder sPath = new StringBuilder();
                sPath.Append(Server.MapPath("."));
                sPath.Append(@"\rps_onlineservice\");
                sPath.Append(@"\contenido\");
                sPath.Append(@"\contenido_");
                sPath.Append(CodContenido.Value);
                sPath.Append(@"\");
                string pCodArchivo = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["cod_archivo"].ToString();
                DBConn oConn       = new DBConn();
                if (oConn.Open())
                {
                    CmsArchivos oArchivos = new CmsArchivos(ref oConn);
                    oArchivos.CodArchivo = pCodArchivo;
                    DataTable dArchivos = oArchivos.Get();
                    if (dArchivos != null)
                    {
                        if (dArchivos.Rows.Count > 0)
                        {
                            sPath.Append(dArchivos.Rows[0]["nom_archivo"].ToString());
                            File.Delete(sPath.ToString());
                        }
                    }
                    dArchivos = null;

                    oArchivos.Accion = "ELIMINAR";
                    oArchivos.Put();
                    oConn.Close();
                }
                rdgArchivos.Rebind();
                break;
            }
        }
Example #3
0
        public string InsertImage(UploadedFile file, string userID)
        {
            string pCodArchivo = string.Empty;
            DBConn oConn       = new DBConn();

            try
            {
                byte[]        imageData = GetImageBytes(file.InputStream);
                StringBuilder sPath     = new StringBuilder();
                StringBuilder sFile     = new StringBuilder();
                sPath.Append(HttpContext.Current.Server.MapPath("."));
                sPath.Append(@"\rps_onlineservice\");
                sPath.Append(@"\contenido\");
                sPath.Append(@"\contenido_");
                sPath.Append(userID);
                if (!Directory.Exists(sPath.ToString()))
                {
                    Directory.CreateDirectory(sPath.ToString());
                }

                if (oConn.Open())
                {
                    oConn.BeginTransaction();

                    ObjectModel oObjectModel = new ObjectModel(ref oConn);
                    pCodArchivo = oObjectModel.getCodeKey("CMS_ARCHIVOS");

                    sPath.Append(@"\").Append(pCodArchivo).Append(file.GetExtension());
                    sFile.Append(pCodArchivo).Append(file.GetExtension());
                    File.WriteAllBytes(sPath.ToString(), imageData);

                    CmsArchivos oArchivos = new CmsArchivos(ref oConn);
                    oArchivos.CodArchivo   = pCodArchivo;
                    oArchivos.Accion       = "CREAR";
                    oArchivos.CodContenido = userID;
                    oArchivos.DateArchivo  = DateTime.Now.ToString();
                    oArchivos.NomArchivo   = sFile.ToString();
                    oArchivos.ExtArchivo   = file.GetExtension();
                    oArchivos.Put();

                    if (string.IsNullOrEmpty(oArchivos.Error))
                    {
                        oConn.Commit();
                        string cPath           = HttpContext.Current.Server.MapPath(".") + @"\binary\";
                        string sFileUsrArchivo = "ContenidoArchivo_" + userID + ".bin";
                        oArchivos.SerializaTblArchivo(ref oConn, cPath, sFileUsrArchivo);
                    }
                    else
                    {
                        oConn.Rollback();
                    }

                    oConn.Close();
                }
            }
            catch (Exception Ex)
            {
                if (oConn.bIsOpen)
                {
                    oConn.Rollback();
                    oConn.Close();
                }
            }
            return(pCodArchivo);
        }
Example #4
0
        protected void rdContenido_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "cmdEdit":
                string[] cParam = new string[2];
                cParam[0] = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["cod_contenido"].ToString();
                cParam[1] = CodNodo.Value;
                Response.Redirect(String.Format("Contenido.aspx?CodContenido={0}&CodNodo={1}", cParam));
                break;

            case "cmdDelete":
                string pCodContenido = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["cod_contenido"].ToString();
                DBConn oConn         = new DBConn();
                if (oConn.Open())
                {
                    StringBuilder sPath;
                    CmsArchivos   oArchivos = new CmsArchivos(ref oConn);
                    oArchivos.CodContenido = pCodContenido;
                    DataTable dArchivos = oArchivos.Get();
                    if (dArchivos != null)
                    {
                        if (dArchivos.Rows.Count > 0)
                        {
                            foreach (DataRow oRow in dArchivos.Rows)
                            {
                                sPath = new StringBuilder();
                                sPath.Append(Server.MapPath("."));
                                sPath.Append(@"\rps_onlineservice\");
                                sPath.Append(@"\contenido\");
                                sPath.Append(@"\contenido_");
                                sPath.Append(pCodContenido);
                                sPath.Append(@"\");
                                sPath.Append(oRow["nom_archivo"].ToString());
                                if (File.Exists(sPath.ToString()))
                                {
                                    File.Delete(sPath.ToString());
                                    oArchivos            = new CmsArchivos(ref oConn);
                                    oArchivos.CodArchivo = oRow["cod_archivo"].ToString();
                                    oArchivos.Accion     = "ELIMINAR";
                                    oArchivos.Put();
                                }
                            }
                        }
                    }
                    dArchivos = null;

                    sPath = new StringBuilder();
                    sPath.Append(Server.MapPath("."));
                    sPath.Append(@"\binary\Contenido_");
                    sPath.Append(pCodContenido);
                    sPath.Append(".bin");
                    File.Delete(sPath.ToString());

                    CmsContenidos oContenidos = new CmsContenidos(ref oConn);
                    oContenidos.CodContenido = pCodContenido;
                    oContenidos.Accion       = "ELIMINAR";
                    oContenidos.Put();
                    oConn.Close();
                }
                rdContenido.Rebind();
                break;
            }
        }