Beispiel #1
0
 protected void Page_Init(object sender, EventArgs e)
 {
     // lo primero es cargar el contexto
     ctx = new LainsaSci("LainsaSciCTX"); // (LainsaSciCTX -> web.config)
     // Comprobar si hay un usuario logado
     if (Session["UsuarioExtranetId"] != null)
     {
         int id = (int)Session["UsuarioExtranetId"];
         uex = CntLainsaSci.GetUsuarioExtranet(id, ctx);
         if (uex == null)
         {
             Response.Redirect("Default.aspx");
         }
     }
     else
     {
         Response.Redirect("Default.aspx");
     }
     if (Request.QueryString["DocumentoId"] != null)
     {
         documentoId = int.Parse(Request.QueryString["DocumentoId"]);
         documento   = CntLainsaSci.GetDocumento(documentoId, ctx);
         if (documento != null)
         {
             string newFileName = String.Format("{0:000000000}", documento.DocumentoId) + documento.Extension;
             string repodir     = ConfigurationManager.AppSettings["Repositorio"];
             string origen      = repodir + "\\" + newFileName;
             string destino     = Session["UsuarioDir"] + "\\" + newFileName;
             File.Copy(origen, destino, true);
             SplView.ContentUrl = String.Format("/Docs/A{0:000000}/{1}", uex.UsuarioExtranetId, newFileName);
         }
     }
 }
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        // we only process commands with a datasource (our image buttons)
        if (e.CommandSource == null)
        {
            return;
        }
        string typeOfControl = e.CommandSource.GetType().ToString();

        if (typeOfControl.Equals("System.Web.UI.WebControls.ImageButton"))
        {
            int         id   = 0;
            ImageButton imgb = (ImageButton)e.CommandSource;
            if (imgb.ID != "New" && imgb.ID != "Exit")
            {
                id = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][e.Item.OwnerTableView.DataKeyNames[0]];
            }
            switch (imgb.ID)
            {
            case "Select":
                break;

            case "Edit":
                break;

            case "Delete":
                try
                {
                    Documento documento   = CntLainsaSci.GetDocumento(id, ctx);
                    string    newFileName = String.Format("{0:000000000}.", documento.DocumentoId) + documento.Extension;
                    string    repodir     = ConfigurationManager.AppSettings["Repositorio"];
                    string    origen      = repodir + "\\" + newFileName;

                    if (documento.InformeProgramados != null)
                    {
                        foreach (InformeProgramado ip in documento.InformeProgramados)
                        {
                            ip.Documento = null;
                        }
                    }
                    CntLainsaSci.CTXEliminar(documento, ctx);
                    CntLainsaSci.CTXGuardar(ctx);

                    // Además hay que borrarlo físicamente
                    File.Delete(origen);
                    RefreshGrid(true);
                }
                catch (Exception ex)
                {
                    ControlDeError(ex);
                }
                break;
            }
        }
    }
    protected void Page_Init(object sender, EventArgs e)
    {
        // it gets an appropiate context (LainsaSciCTX -> web.config)
        ctx = new LainsaSci("LainsaSciCTX");
        // verify if a Usuario is logged
        usuario = CntWinWeb.IsSomeoneLogged(this, ctx);
        if (usuario == null)
        {
            Response.Redirect("Default.aspx");
        }
        else
        {
            Session["UsuarioId"] = usuario.UsuarioId;
        }
        //
        // si llega aquí está autorizado
        permiso = CntLainsaSci.GetPermiso(usuario.GrupoUsuario, "repositoriotmpform", ctx);
        if (permiso == null)
        {
            RadNotification1.Text = String.Format("<b>{0}</b><br/>{1}",
                                                  (string)GetGlobalResourceObject("ResourceLainsaSci", "Warning"),
                                                  (string)GetGlobalResourceObject("ResourceLainsaSci", "NoPermissionsAssigned"));
            RadNotification1.Show();
            RadAjaxManager1.ResponseScripts.Add("closeWindow();");
        }
        btnAccept.Visible = permiso.Modificar;
        if (Request.QueryString["InTab"] != null)
        {
            inTab = Request.QueryString["InTab"];
        }
        // Si esto no va antes de DocumentoID tendrás problemas.
        if (Request.QueryString["Caller"] != null)
        {
            caller = Request.QueryString["Caller"];
            caller = caller.Replace("'", "");
        }
        // Mirar si se ha pasado una empresa
        if (Request.QueryString["EmpresaId"] != null)
        {
            empresa = CntLainsaSci.GetEmpresa(int.Parse(Request.QueryString["EmpresaId"]), ctx);
            CargaEmpresa(empresa);
        }
        if (Request.QueryString["InstalacionId"] != null)
        {
            instalacion = CntLainsaSci.GetInstalacion(int.Parse(Request.QueryString["InstalacionId"]), ctx);
            CargaInstalacion(instalacion);
        }
        if (Request.QueryString["TipoDispositivoId"] != null)
        {
            tipo = CntLainsaSci.GetTipoDispositivo(int.Parse(Request.QueryString["TipoDispositivoId"]), ctx);
            CargaTipo(tipo);
        }
        if (Request.QueryString["Nombre"] != null)
        {
            nombre = Request.QueryString["Nombre"];
            nombre.Replace("'", "");
            fileName = nombre;
        }
        // MIrar si se ha pasado una instalacion
        if (Request.QueryString["RevisionId"] != null)
        {
            instalacion = CntLainsaSci.GetInstalacion(int.Parse(Request.QueryString["RevisionId"]), ctx);
            CargaInstalacion(instalacion);
        }

        // Is it a new record or not?
        if (Request.QueryString["DocumentoId"] != null)
        {
            documento = CntLainsaSci.GetDocumento(int.Parse(Request.QueryString["DocumentoId"]), ctx);
            LoadData(documento);
            this.Title = String.Format("Documento: {0}", documento.Nombre);
            newRecord  = false;
        }
        else
        {
            // cunado se crea uno nuevo se cargan todas las categorias
            CargaCategorias();
            txtNombre.Text = fileName;
        }
        if (Request.QueryString["FileName"] != null)
        {
            fileName = Request.QueryString["FileName"];
            //CargaAutomatica(fileName);
        }
        // control de skin
        if (Session["Skin"] != null)
        {
            RadSkinManager1.Skin = Session["Skin"].ToString();
        }
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     // Cargar las propiedades de el FileExplorer.
     //string repodir = ConfigurationManager.AppSettings["Repositorio"];
     if (documentoId == 0)
     {
         SplView.ContentUrl = String.Format("/Repo/{0}", fileName);
         if (empresa == null)
         {
             SplData.ContentUrl = String.Format("DocumentoForm.aspx?Caller=DocumentoView&InTab=S&FileName={0}", fileName);
         }
         else
         {
             if (instalacion == null && tipo == null)
             {
                 SplData.ContentUrl = String.Format("DocumentoForm.aspx?Caller=DocumentoView&InTab=S&FileName={0}&EmpresaId={1}&Nombre={2}",
                                                    fileName,
                                                    empresa.EmpresaId,
                                                    nombre);
             }
             else if (instalacion != null)
             {
                 if (tipo == null)
                 {
                     SplData.ContentUrl = String.Format("DocumentoForm.aspx?Caller=DocumentoView&InTab=S&FileName={0}&Nombre={1}&InstalacionId={2}",
                                                        fileName,
                                                        nombre,
                                                        instalacion.InstalacionId);
                 }
                 else
                 {
                     SplData.ContentUrl = String.Format("DocumentoForm.aspx?Caller=DocumentoView&InTab=S&FileName={0}&Nombre={1}&InstalacionId={2}&TipoDispositivoId={3}",
                                                        fileName,
                                                        nombre,
                                                        instalacion.InstalacionId,
                                                        tipo.TipoId);
                 }
             }
             else
             {
                 SplData.ContentUrl = String.Format("DocumentoForm.aspx?Caller=DosumentoView&InTab=SFileName={0}&Nombre={1}&TipoDispositivoId={2}",
                                                    fileName,
                                                    nombre,
                                                    tipo.TipoId);
             }
         }
     }
     else
     {
         Documento documento = CntLainsaSci.GetDocumento(documentoId, ctx);
         if (documento != null)
         {
             string newFileName = String.Format("{0:000000000}.", documento.DocumentoId) + documento.Extension;
             string repodir     = ConfigurationManager.AppSettings["Repositorio"];
             string origen      = repodir + "\\" + newFileName;
             if (File.Exists(origen))
             {
                 string destino = Session["UsuarioDir"] + "\\" + newFileName;
                 File.Copy(origen, destino, true);
                 SplView.ContentUrl = String.Format("/Docs/A{0:000000}/{1}", usuario.UsuarioId, newFileName);
                 SplData.ContentUrl = String.Format("DocumentoForm.aspx?Caller=DocumentoView&InTab=S&DocumentoId={0}", documento.DocumentoId);
             }
             else
             {
                 RadNotification1.Text = String.Format("<b>{0}</b><br/>{1}",
                                                       (string)GetGlobalResourceObject("ResourceLainsaSci", "Warning"),
                                                       (string)GetGlobalResourceObject("ResourceLainsaSci", "NDocumento"));
                 RadNotification1.Show();
             }
         }
     }
 }