Exemplo n.º 1
0
        // Rutinas el programador
        void DeleteDocumento(Int32 DocumentoId)
        {
            ENTDocumento oENTDocumento = new ENTDocumento();
            ENTResponse oENTResponse = new ENTResponse();

            BPDocumento oBPDocumento = new BPDocumento();

            try
            {

                // Formulario
                oENTDocumento.DocumentoId = DocumentoId;

                // Consultar información del archivo
                oENTResponse = oBPDocumento.SelectDocumento_Path(oENTDocumento);

                // Errores y Warnings
                if (oENTResponse.GeneratesException) { throw (new Exception(oENTResponse.sErrorMessage)); }
                if (oENTResponse.sMessage != "") { throw (new Exception(oENTResponse.sMessage)); }

                // Eliminar físicamente el archivo
                if (File.Exists(oENTResponse.dsResponse.Tables[1].Rows[0]["Ruta"].ToString())) { File.Delete(oENTResponse.dsResponse.Tables[1].Rows[0]["Ruta"].ToString()); }

                // Eliminar la referencia del archivo en la base de datos
                oENTResponse = oBPDocumento.DeleteDocumento(oENTDocumento);

                // Errores y Warnings
                if (oENTResponse.GeneratesException) { throw (new Exception(oENTResponse.sErrorMessage)); }
                if (oENTResponse.sMessage != "") { throw (new Exception(oENTResponse.sMessage)); }

                // Estado inicial del formulario
                this.ckeDescripcion.Text = "";

                // Refrescar el formulario
                SelectSolicitud();

                // Foco
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Convert.ToString(Guid.NewGuid()), "function pageLoad(){ focusControl('" + this.fupArchivo.ClientID + "'); }", true);

            }catch ( IOException ioEx){

                throw (ioEx);
            }catch (Exception ex){

                throw (ex);
            }
        }
Exemplo n.º 2
0
        void InsertDocumento()
        {
            ENTDocumento oENTDocumento = new ENTDocumento();
            ENTResponse oENTResponse = new ENTResponse();
            ENTSession oENTSession;

            BPDocumento oBPDocumento = new BPDocumento();

            try
            {

                // Validaciones
                if (this.fupArchivo.PostedFile == null) { throw (new Exception("Es necesario seleccionar un Documento")); }
                if (!this.fupArchivo.HasFile) { throw (new Exception("Es necesario seleccionar un Documento")); }
                if (this.fupArchivo.PostedFile.ContentLength == 0) { throw (new Exception("Es necesario seleccionar un Documento")); }

                // Obtener Sesion
                oENTSession = (ENTSession)this.Session["oENTSession"];

                // Formulario
                oENTDocumento.SolicitudId = Int32.Parse(this.hddSolicitudId.Value);
                oENTDocumento.ExpedienteId = 0;
                oENTDocumento.ModuloId = 2; // Quejas
                oENTDocumento.idUsuarioInsert = oENTSession.idUsuario;
                oENTDocumento.Extension = Path.GetExtension(this.fupArchivo.PostedFile.FileName);
                oENTDocumento.Nombre = this.fupArchivo.FileName;
                oENTDocumento.Descripcion = this.ckeDescripcion.Text.Trim();
                oENTDocumento.Ruta = oBPDocumento.UploadFile(this.fupArchivo.PostedFile, this.hddSolicitudId.Value, BPDocumento.RepositoryTypes.Solicitud );

                // Transacción
                oENTResponse = oBPDocumento.InsertDocumento(oENTDocumento);

                // Errores y Warnings
                if (oENTResponse.GeneratesException) { throw (new Exception(oENTResponse.sErrorMessage)); }
                if (oENTResponse.sMessage != "") { throw (new Exception(oENTResponse.sMessage)); }

                // Estado inicial del formulario
                this.ckeDescripcion.Text = "";

                // Refrescar el formulario
                SelectSolicitud();

                // Foco
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Convert.ToString(Guid.NewGuid()), "function pageLoad(){ focusControl('" + this.fupArchivo.ClientID + "'); }", true);

            }catch (Exception ex){
                throw (ex);
            }
        }
Exemplo n.º 3
0
        // Eventos
        public void ProcessRequest(HttpContext httpContext)
        {
            ENTDocumento oENTDocumento = new ENTDocumento();
            ENTResponse oENTResponse = new ENTResponse();
            BPDocumento oBPDocumento = new BPDocumento();

            MemoryStream msFile;
            FileStream fsFile;
            Byte[] byteFile;

            Int32 DocumentoId;

            try
            {

                // Validaciones de llamada
                if (httpContext.Request.QueryString["key"] == null) { httpContext.Response.Redirect("~/Application/WebApp/Private/SysApp/saNotificacion.aspx", false); return; }

                // Obtener el id del documento
                DocumentoId = Int32.Parse(gcEncryption.DecryptString(httpContext.Request.QueryString["key"], true));

                // Consultar la ruta del archivo
                oENTDocumento.DocumentoId = DocumentoId;
                oENTResponse = oBPDocumento.SelectDocumento_Path(oENTDocumento);

                // Errores y Warnings
                if (oENTResponse.GeneratesException) { throw (new Exception(oENTResponse.sErrorMessage)); }
                if (oENTResponse.sMessage != "") { throw (new Exception(oENTResponse.sMessage)); }

                // Obtener el archivo
                fsFile = new System.IO.FileStream(oENTResponse.dsResponse.Tables[1].Rows[0]["Ruta"].ToString(), System.IO.FileMode.Open, System.IO.FileAccess.Read);

                byteFile = new Byte[fsFile.Length];
                fsFile.Read(byteFile, 0, (int)fsFile.Length);
                fsFile.Close();

                // Validación
                if (byteFile == null) { throw (new Exception("No se encontró el archivo")); }

                // Cambiar los contet de la página
                httpContext.Response.ContentType = "application/x-unknown/octet-stream";
                httpContext.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + oENTResponse.dsResponse.Tables[1].Rows[0]["Nombre"].ToString() + "\"");

                // Descargar el archivo
                msFile = new MemoryStream(byteFile, true);
                msFile.Write(byteFile, 0, byteFile.Length);
                httpContext.Response.BinaryWrite(byteFile);
                httpContext.Response.Flush();

            }catch (IOException ioEx){

                httpContext.Response.Write(ioEx.Message);

             }catch (Exception ex){

                httpContext.Response.Write(ex.Message);

            }finally{

                httpContext.Response.End();

            }
        }