protected void btnBajar_Click(object sender, EventArgs e)
        {
            ImageButton boton = sender as ImageButton;
            TableCell celda = boton.Parent as TableCell;
            TableRow fila = celda.Parent as TableRow;
            string nombreRegla = fila.Cells[0].Text;
            int indexActual = tblReglas.Rows.GetRowIndex(fila);
            int indexNuevo = indexActual + 1;
            if (indexNuevo != tblReglas.Rows.Count)
            {
                IMetodosAdministrador _metAdministrador = new MetodosAdministrador();
                LinkedList<Regla> _lisReglas = (LinkedList<Regla>)Session["LISTA_REGLAS"];
                Regla _reglaBaja = new Regla();
                Regla _reglaSube = new Regla();

                foreach (Regla _regla in _lisReglas)//-- Obtengo las reglas por modificar
                {
                    if (_regla.Posicion.Equals(indexActual))//-- Aca el nombre sube o baja no tiene sentido
                    {
                        _reglaBaja = _regla;
                    }
                    if (_regla.Posicion.Equals(indexNuevo))
                    {
                        _reglaSube = _regla;
                    }
                }

                _lisReglas.Remove(_reglaSube);//-- Borro reglas de lista
                _lisReglas.Remove(_reglaBaja);

                _reglaSube.Posicion = indexActual;//-- Cambio las posiciones
                _reglaBaja.Posicion = indexNuevo;

                _lisReglas.AddLast(_reglaSube);//-- Agrego a la lista
                _lisReglas.AddLast(_reglaBaja);

                bool _resultado = _metAdministrador.ModificarOrdenReglas(_lisReglas);

                if (_resultado)
                {
                    Page.Response.Redirect(Page.Request.Url.PathAndQuery);
                }
                else
                {
                    lblPopupHeader.Text = "Error";
                    lblPopupBody.Text = "La prioridad de la regla no fue modificada.";
                    Pop_Alerta.Show();
                }

            }
            else
            {
                lblPopupHeader.Text = "Error";
                lblPopupBody.Text = "La regla ya tiene la prioridad mínima.";
                Pop_Alerta.Show();
            }
        }
        /**
         * Agrega una regla al negocio.
         **/
        public bool AgregarRegla(Regla pRegla)
        {
            XmlDocument _xmlEditor = new XmlDocument();
            _xmlEditor.Load("OrdenReglas.xml");

            //XmlElement _xmlElemento = _xmlEditor.CreateElement(_sNODOSXML[0]);

            //XmlAttribute _xmlAtributo = _xmlEditor.CreateAttribute();
            return true;
        }
        /**
         * Agrega una regla al negocio.
         **/
        public bool AgregarRegla(Regla pRegla)
        {
            try
            {
                SIFRegla _sifRegla = new SIFRegla();
                _sifRegla.num_prioridad = pRegla.Posicion;
                _sifRegla.txt_estado = pRegla.Estado;
                _sifRegla.txt_nombre = pRegla.Nombre;
                _sifRegla.txt_script = pRegla.StoredProcedure;

                _objConexionBase = new Inclutec_BDEntities();
                _objConexionBase.AddToSIFReglas(_sifRegla);
                _objConexionBase.SaveChanges();
                _objConexionBase.Connection.Close();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        /// <summary>
        /// Agrega una regla al archivo xml.
        /// </summary>
        /// <param name="pRegla"></param>
        public void AgregarRegla(Regla pRegla)
        {
            XmlElement _xmlElemento = _xmlEditor.CreateElement("regla");

            //Agrega los atributos a los elementos
            XmlAttribute _xmlAtributo = _xmlEditor.CreateAttribute(_sATRIBUTOSREGLA[0]);
            _xmlAtributo.Value = pRegla.Posicion.ToString();
            _xmlElemento.Attributes.Append(_xmlAtributo);

            _xmlAtributo = _xmlEditor.CreateAttribute(_sATRIBUTOSREGLA[1]);
            _xmlAtributo.Value = pRegla.Nombre;
            _xmlElemento.Attributes.Append(_xmlAtributo);

            _xmlAtributo = _xmlEditor.CreateAttribute(_sATRIBUTOSREGLA[2]);
            _xmlAtributo.Value = pRegla.StoredProcedure;
            _xmlElemento.Attributes.Append(_xmlAtributo);

            _xmlAtributo = _xmlEditor.CreateAttribute(_sATRIBUTOSREGLA[3]);
            _xmlAtributo.Value = "habilitada";
            _xmlElemento.Attributes.Append(_xmlAtributo);

            //Agrega los parametros del stored procedure a la regla
            foreach (Parametro _param in pRegla.Parametros)
            {
                XmlElement _xmlParametro= _xmlEditor.CreateElement("param");

                XmlAttribute _xmlAtributoParam = _xmlEditor.CreateAttribute(_sATRIBUTOSPARAMETRO[0]);
                _xmlAtributoParam.Value = _param.Nombre;
                _xmlParametro.Attributes.Append(_xmlAtributoParam);

                _xmlAtributoParam = _xmlEditor.CreateAttribute(_sATRIBUTOSPARAMETRO[1]);
                _xmlAtributoParam.Value = _param.Tipo;
                _xmlParametro.Attributes.Append(_xmlAtributoParam);

                _xmlElemento.AppendChild(_xmlParametro);
            }
            _xmlEditor.DocumentElement.AppendChild(_xmlElemento);
            this.GuardarCambios();
        }
 protected void btnAgregarRegla_Click(object sender, EventArgs e)
 {
     //Intento agregar regla al sistema
     IMetodosAdministrador _metAdministrador = new MetodosAdministrador();
     Regla _reglaNueva = new Regla();
     _reglaNueva.Posicion = tblReglas.Rows.Count-1;
     _reglaNueva.Nombre = txtNombreRegla.Text;
     _reglaNueva.StoredProcedure = txtNombreProcedimiento.Text;
     _reglaNueva.Estado = "habilitada";
     bool _resultado = _metAdministrador.AgregarRegla(_reglaNueva);
     if(_resultado)
     {
         lblPopupHeader.Text = "Regla agregada";
         lblPopupBody.Text = "La regla fue agregada exitosamente al sistema.";
         Pop_Alerta.Show();
     }
     else
     {
         lblPopupHeader.Text = "Error al agregar regla";
         lblPopupBody.Text = "Ocurrió un error al intentar agregar la regla al sistema.";
         Pop_Alerta.Show();
     }
     //Page.Response.Redirect(Request.RawUrl);
 }
        /// <summary>
        /// Retorna la informacion de todas las reglas.
        /// </summary>
        /// <returns></returns>
        public LinkedList<Regla> ObtenerListaReglas()
        {
            try
            {
                XmlNodeList _liNodos = _xmlEditor.SelectNodes(_sNODOSXML[0]);
                LinkedList<Regla> _liReglas = new LinkedList<Regla>();
                foreach (XmlNode _xmlNodo in _liNodos)
                {
                    Regla _regla = new Regla();
                    _regla.Posicion = Int32.Parse(_xmlNodo.Attributes[_sATRIBUTOSREGLA[0]].Value);
                    _regla.Nombre = _xmlNodo.Attributes[_sATRIBUTOSREGLA[1]].Value;
                    _regla.StoredProcedure = _xmlNodo.Attributes[_sATRIBUTOSREGLA[2]].Value;
                    _regla.Estado = _xmlNodo.Attributes[_sATRIBUTOSREGLA[3]].Value;
                    _liReglas.AddLast(_regla);
                }

                return _liReglas;
            }
            catch (Exception)
            {
                return null;
            }
        }
        /// <summary>
        /// Modifica el procedimiento de una regla del negocio.
        /// </summary>
        /// <param name="pRegla"></param>
        /// <param name="pParametros"></param>
        public void ModificarProcedureRegla(Regla pRegla)
        {
            XmlNodeList _liReglas = _xmlEditor.SelectNodes(_sNODOSXML[0]);
            foreach (XmlNode _regla in _liReglas)
            {
                if (_regla.Attributes[_sATRIBUTOSREGLA[1]].Value.Equals(pRegla.Nombre))
                {
                    _regla.Attributes[_sATRIBUTOSREGLA[2]].Value = pRegla.StoredProcedure;
                    //Elimina los parametros anteriores
                    foreach (XmlNode _child in _regla.ChildNodes)
                    {
                        _regla.RemoveChild(_child);
                    }
                    //Agrega los parametros del stored procedure a la regla
                    foreach (Parametro _param in pRegla.Parametros)
                    {
                        XmlElement _xmlParametro = _xmlEditor.CreateElement("param");

                        XmlAttribute _xmlAtributoParam = _xmlEditor.CreateAttribute(_sATRIBUTOSPARAMETRO[0]);
                        _xmlAtributoParam.Value = _param.Nombre;
                        _xmlParametro.Attributes.Append(_xmlAtributoParam);

                        _xmlAtributoParam = _xmlEditor.CreateAttribute(_sATRIBUTOSPARAMETRO[1]);
                        _xmlAtributoParam.Value = _param.Tipo;
                        _xmlParametro.Attributes.Append(_xmlAtributoParam);

                        _regla.AppendChild(_xmlParametro);
                    }
                    break;
                }
            } this.GuardarCambios();
        }
 /// <summary>
 /// Habilita una regla del negocio
 /// </summary>
 /// <param name="regla"></param>
 /// <returns></returns>
 public bool HabilitarRegla(Regla pRegla)
 {
     try
     {
         XmlNodeList _liReglas = _xmlEditor.SelectNodes(_sNODOSXML[0]);
         foreach (XmlNode _regla in _liReglas)
         {
             if (_regla.Attributes[_sATRIBUTOSREGLA[1]].Value.ToString().Equals(pRegla.Nombre))
             {
                 _regla.Attributes["posicion"].Value = pRegla.Posicion.ToString();
                 _regla.Attributes["estado"].Value = _sESTADOSREGLAS[0];
                 break;
             }
         } this.GuardarCambios();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
 /**
  * Elimina una regla del negocio.
  **/
 public bool EliminarRegla(Regla pRegla)
 {
     return true;
 }
 /**
  * Modifica el procedimiento de una regla del negocio.
  **/
 public bool ModificarProcedimientoRegla(Regla pNombreProcedimiento, string pProcedimiento)
 {
     return true;
 }
 /**
  * Retorna la informacion de todas las reglas.
  **/
 public LinkedList<Regla> ObtenerInformacionReglas()
 {
     try
     {
         _objConexionBase = new Inclutec_BDEntities();
         var _Reglas = from _sifReglas in _objConexionBase.SIFReglas
                       select _sifReglas;
         LinkedList<Regla> _liReglas = new LinkedList<Regla>();
         foreach (SIFRegla _sifRegla in _Reglas)
         {
             Regla _regla = new Regla();
             _regla.Nombre = _sifRegla.txt_nombre;
             _regla.Estado = _sifRegla.txt_estado;
             _regla.Posicion = _sifRegla.num_prioridad;
             _regla.StoredProcedure = _sifRegla.txt_script;
             _liReglas.AddLast(_regla);
         }
         return _liReglas;
     }
     catch (Exception)
     {
         return null;
     }
 }
 /**
  * Modifica el procedimiento de una regla del negocio.
  **/
 public bool ModificarProcedimientoRegla(Regla pNombreProcedimiento, string pProcedimiento)
 {
     try
     {
         _objConexionBase = new Inclutec_BDEntities();
         SIFRegla _sifRegla = (from _sifReglas in _objConexionBase.SIFReglas
                               where _sifReglas.txt_nombre == pNombreProcedimiento.Nombre
                               select _sifReglas).First();
         _sifRegla.txt_script = pProcedimiento;
         _objConexionBase.SaveChanges();
         _objConexionBase.Connection.Close();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
 /**
  * Elimina una regla del negocio.
  **/
 public bool DesactivarRegla(Regla pRegla)
 {
     try
     {
         _objConexionBase = new Inclutec_BDEntities();
         SIFRegla _sifRegla = (from _sifReglas in _objConexionBase.SIFReglas
                             where _sifReglas.txt_nombre == pRegla.Nombre
                             select _sifReglas).First();
         _sifRegla.txt_estado = "deshabilitada";
         _objConexionBase.SaveChanges();
         _objConexionBase.Connection.Close();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }