Beispiel #1
0
        public ActionResult AgregarPiloto(int idCategoria, int dni)
        {
            //Verifico que el piloto no este agreagado ya a la categoria
            Categoria_Piloto CatPiloto;

            CatPiloto = db.Categoria_Piloto.Where(cp => cp.dniPiloto == dni && cp.idCategoria == idCategoria).FirstOrDefault();

            if (CatPiloto == null)
            {
                //El piloto no esta agregado
                CatPiloto             = new Categoria_Piloto();
                CatPiloto.idCategoria = idCategoria;
                CatPiloto.dniPiloto   = dni;

                db.Categoria_Piloto.Add(CatPiloto);
                Categoria categoria = db.Categoria.Find(idCategoria);

                db.SaveChanges();
                return(RedirectToAction("GetOne", "Torneo", new { id = categoria.Torneo.idTorneo }));
            }
            else
            {
                //El piloto ya esta agregado
                Piloto    piloto    = db.Piloto.Find(dni);
                Categoria categoria = db.Categoria.Find(idCategoria);
                string    msj       = string.Format("El Piloto {0} {1} ya se encuentra agregado a la categoría {2} ", piloto.nombre, piloto.apellido, categoria.nombre);
                TempData["alert"] = Constante.alertDanger(msj);

                return(RedirectToAction("AgregarPiloto", new { idCategoria = categoria.idTorneo }));
            }
        }
        public ActionResult BuscarPiloto(int idCarrera, int idCategoria, string buscar)
        {
            ViewBag.idCarrera = idCarrera;
            if (Constante.IsNumeric(buscar)) // si es numerico es porque ingreso el dni del piloto
            {
                int dni = int.Parse(buscar);
                List <Categoria_Piloto> catPiloto = db.Categoria_Piloto.Where(ct => ct.idCategoria == idCategoria &&
                                                                              (ct.dniPiloto == dni || ct.Piloto.nombre.Contains(buscar) || ct.Piloto.apellido.Contains(buscar))).ToList();

                ViewBag.CatPiloto = catPiloto;
            }
            else if (string.IsNullOrEmpty(buscar)) // no ingreso ningun datos devuelvo todo los los pilotos
            {
                List <Categoria_Piloto> catPiloto = db.Categoria_Piloto.Where(ct => ct.idCategoria == idCategoria).ToList();

                ViewBag.CatPiloto = catPiloto;
            }
            else // ingreso un texto puede ser el nombre o apellido
            {
                List <Categoria_Piloto> catPiloto = db.Categoria_Piloto.Where(ct => ct.idCategoria == idCategoria &&
                                                                              (ct.Piloto.nombre.Contains(buscar) || ct.Piloto.apellido.Contains(buscar))).ToList();

                ViewBag.CatPiloto = catPiloto;
            }

            return(View("ListPilotoTecnica"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Piloto piloto = db.Piloto.Find(id);
            string msj    = string.Format("El piloto  {0} {1} con DNI: {2} a sido eliminado ", piloto.nombre, piloto.apellido, piloto.dni);

            db.Piloto.Remove(piloto);
            db.SaveChanges();

            //string alert = "<div class=" + quote + "alert alert-danger" + quote + "><a class=" + quote +
            //      "close" + quote + " data-dismiss=" + quote + "alert" + quote + ">×</a><span> "+ msj +" </span></div>";

            TempData["alert"] = Constante.alertDanger(msj);

            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        /// <summary>
        /// Recupera o valor de referência.
        /// </summary>
        /// <param name="referenceValue">Dados da referência do valor.</param>
        /// <returns></returns>
        public double GetValue(ReferenceValue referenceValue)
        {
            if (string.IsNullOrEmpty(referenceValue.Path))
            {
                return(0.0);
            }

            // Quebra o caminho da referencias em partes
            var parts = referenceValue.Path.Split('/');

            if (parts.Length < 3)
            {
                return(0);
            }

            AsseguraInicializacao();

            var fabricante    = parts[0];
            var ferragem      = parts[1];
            var nomeConstante = parts[2];

            Constante constante = null;

            lock (_itens)
            {
                var item = _itens.FirstOrDefault(f =>
                                                 StringComparer.InvariantCultureIgnoreCase.Equals(f.Fabricante, fabricante) &&
                                                 StringComparer.InvariantCultureIgnoreCase.Equals(f.Nome, ferragem));

                if (item != null)
                {
                    constante = item.Constantes.FirstOrDefault(f => StringComparer.InvariantCultureIgnoreCase.Equals(f.Nome, nomeConstante));
                }
            }

            if (constante != null)
            {
                return(constante.Valor);
            }

            return(referenceValue.DefaultValue);
        }
Beispiel #5
0
        Exp factor()
        {
            Exp x = null;

            switch (token.TokenType)
            {
            case TokenType.IPAREN:
                eat(TokenType.IPAREN); x = parseExpression(); eat(TokenType.DPAREN);
                return(x);

            case TokenType.INT:
                x = new Constante(token, Tipo.Int); eat(TokenType.INT); return(x);

            case TokenType.FLOAT:
                x = new Constante(token, Tipo.Float); eat(TokenType.FLOAT); return(x);

            case TokenType.booleanConstant:
                x = Constante.True; eat(TokenType.booleanConstant); return(x);

            case TokenType.FALSE:
                x = Constante.False; eat(TokenType.FALSE); return(x);

            case TokenType.ident:
                Identifier id = entornoActual.Get(token);
                if (id == null)
                {
                    error(token.Lexeme + " no declarado");
                }
                eat(TokenType.ident);
                return(id);

            case TokenType.stringConstant:
                Token tok = token;
                eat(TokenType.stringConstant);
                return(new Exp(tok, Tipo.String));

            default:
                error("error de sintaxis");
                return(x);
            }
        }
Beispiel #6
0
        Expresion factor()
        {
            Expresion x = null;

            switch (token.TokenType)
            {
            case TokenType.IPAREN:
                eat(TokenType.IPAREN); x = parseExpression(); eat(TokenType.DPAREN);
                return(x);

            case TokenType.ENTERO:
                x = new Constante(token, Tipo.Int); eat(TokenType.ENTERO); return(x);

            case TokenType.FLOTANTE:
                x = new Constante(token, Tipo.Float); eat(TokenType.FLOTANTE); return(x);

            case TokenType.TRUE:
                x = Constante.True; eat(TokenType.TRUE); return(x);

            case TokenType.FALSE:
                x = Constante.False; eat(TokenType.FALSE); return(x);

            case TokenType.ID:
                Identifier id = entornoActual.Get(token);
                if (id == null)
                {
                    error(token.Lexeme + " no declarado");
                }
                eat(TokenType.ID);
                return(id);

            case TokenType.CADENA:
                Token tok = token;
                eat(TokenType.CADENA);
                return(new Expresion(tok, Tipo.String));

            default:
                error("error de sintaxis");
                return(x);
            }
        }
        public ActionResult Create([Bind(Include = "nombre,apellido,dni,email")] Piloto piloto)
        {
            if (ModelState.IsValid)
            {
                Piloto otroPiloto = db.Piloto.Find(piloto.dni);
                if (otroPiloto == null)
                {
                    db.Piloto.Add(piloto);
                    db.SaveChanges();
                    ViewBag.alertUsuario = Constante.alertInfo(string.Format("El piloto {0} {1} creado"));
                    return(RedirectToAction("Index"));
                }
                else //Existe otro piloto con el mismo dni
                {
                    TempData["alert"] = Constante.alertWarning(string.Format("Ya existe un piloto creado con ese DNI"));
                    return(RedirectToAction("Index"));
                }
            }

            return(PartialView(piloto));
        }
Beispiel #8
0
        public ActionResult Buscar(string buscar, int idCategoria)
        {
            List <Piloto> listPilotos;

            ViewBag.Categoria = db.Categoria.Find(idCategoria);

            if (Constante.IsNumeric(buscar)) // si es numerico es porque ingreso el dni del piloto
            {
                int dni = int.Parse(buscar);
                listPilotos = db.Piloto.Where(p => p.nombre.Contains(buscar) ||
                                              p.apellido.Contains(buscar) || p.dni == dni).ToList();
            }
            else if (string.IsNullOrEmpty(buscar)) // no infreso ninguno datos devuelvo todolos los pilotos
            {
                listPilotos = db.Piloto.ToList();
            }
            else // ingreso un texto puede ser el nombre o apellido
            {
                listPilotos = db.Piloto.Where(p => p.nombre.Contains(buscar) ||
                                              p.apellido.Contains(buscar)).ToList();
            }
            ViewBag.Pilotos = listPilotos;
            return(View("AgregarPiloto"));
        }
Beispiel #9
0
        public TablaLexica(String[] palabras, int[] lineas, TablaIdentificador tablaI, TablaConstante tablaC)
        {
            this.palabras = new Token[palabras.Length];
            //this.palabras[0].reiniciar();
            Token.sNumero = 1;


            // Creando todos los TOKENS
            for (int x = 0; x < palabras.Length; x++)
            {
                //Regex.IsMatch(palabra, @"\d+")
                if (palabras[x] != null && !Regex.IsMatch(palabras[x], @"((\W|^)\s+(\W|$))"))
                {
                    if (palabras[x] != null && Regex.IsMatch(palabras[x], @regexT1))
                    { // Tipo 1 - Reservadas
                        Reservada apuntador = this.darReservada(palabras[x]);
                        if (apuntador != null)
                        {
                            this.palabras[x] = new Token(lineas[x], palabras[x], 1, apuntador.valor);
                        }
                    }
                    else if (palabras[x] != null && Regex.IsMatch(palabras[x], @regexT6))
                    { // Tipo 6 - Cosntantes
                        Constante apuntador = this.darConstante(palabras[x], tablaC);
                        if (apuntador != null)
                        {
                            this.palabras[x] = new Token(lineas[x], "Constante", 6, apuntador.valor);
                        }
                    }
                    else if (palabras[x] != null && Regex.IsMatch(palabras[x], regexT5))
                    { // Tipo 5 - Delimitadores
                        Delimitador apuntador = this.darDelimitador(palabras[x]);
                        if (apuntador != null)
                        {
                            this.palabras[x] = new Token(lineas[x], palabras[x], 5, apuntador.valor);
                        }
                    }
                    else if (palabras[x] != null && Regex.IsMatch(palabras[x], @regexT4))
                    { // Tipo 4 - Identificador
                        Identificador apuntador = this.darIdentificador(palabras[x], tablaI);
                        if (apuntador != null)
                        {
                            this.palabras[x] = new Token(lineas[x], palabras[x], 4, apuntador.valor);
                        }
                    }
                    else if (palabras[x] != null && Regex.IsMatch(palabras[x], @regexT7))
                    { // Tipo 7 - Operadores
                        Operador apuntador = this.darOperador(palabras[x]);
                        this.palabras[x] = new Token(lineas[x], palabras[x], 7, apuntador.valor);
                    }
                    else if (palabras[x] != null && Regex.IsMatch(palabras[x], @regexT8))
                    { // Tipo 8 - Relacionales
                        Relacional apuntador = this.darRelacional(palabras[x]);
                        this.palabras[x] = new Token(lineas[x], palabras[x], 8, apuntador.valor);
                    }
                    else
                    { // Error
                        this.lError = lineas[x];
                        this.error  = true;
                        this.pError = palabras[x];

                        x = palabras.Length;
                    }
                }
            }
        }
Beispiel #10
0
        public WordsCollection Analiza()
        {
            WordsCollection currentSymbol = new WordsCollection(); //Simbolo Actual obtenido del
            int             x             = 0;                     //Fila
            int             y             = 0;                     //Columna
            int             r             = 0;                     //Resultado (regla, desplazamiento o aceptacion)
            Estado          fila          = new Estado(0);

            int  pops      = 0;     //Cantidad de elementos que produce la regla
            bool error     = false; //Bandera que detiene el ciclo
            bool newSymbol = true;  //Decide si se necesita un nuevo simbolo del Lexico o no

            //Inicializa cola
            ColaSintactica.Push(new Estado(0));
            Node Root = new Node();

            //Ciclo que ejecuta el analisis sintactico
            while (!error)
            {
                if (newSymbol)
                {
                    currentSymbol = ALexico.sigSimbolo();
                }
                //x = (int)pila.Peek();
                x = ((Estado)pila.Peek()).transicion;
                y = currentSymbol.TypeId;

                r = TablaLR[x, y];
                Node nodo = new Node();
                nodo = null;

                if (r > 0)
                {
                    //Desplazamiento
                    //pila.Push(currentSymbol);
                    pila.Push(new Terminal(currentSymbol.Word));
                    //pila.Push(r);
                    pila.Push(new Estado(r));
                    newSymbol = true;
                }
                else if (r < 0)
                {
                    //Regla
                    r = Math.Abs(r) - 1;
                    if (r == 0)
                    {
                        //Cadena Aceptada
                        break;
                    }
                    // Obtencion de la cantidad de POPs a realizar en la cola.

                    switch (r)
                    {
                    //case 1:  //<programa> ::= <Definiciones>
                    //nodo=new  programa(pila);
                    //			break;

                    case 3:                          //<Definiciones> ::= <Definicion> <Definiciones>
                    case 16:                         //<DefLocales> ::= <DefLocal> <DefLocales>
                    case 20:                         //<Sentencias> ::= <Sentencia> <Sentencias>
                    case 32:                         //<Argumentos> ::= <Expresion> <ListaArgumentos>
                        pila.Pop();                  //quita estado
                        Node aux = (Node)pila.Pop(); //quita <definiciones>
                        pila.Pop();                  //quita estado
                        nodo = (Node)pila.Pop();     //quita <definicion>
                        if (nodo != null)
                        {
                            nodo.Siguiente = aux;
                        }
                        break;

                    case 1:
                    case 4:                      //<Definicion> ::= <DefVar>
                    case 5:                      //<Definicion> ::= <DefFunc>
                    case 17:                     //<DefLocal> ::= <DefVar>
                    case 18:                     //<DefLocal> ::= <Sentencia>
                    case 35:                     //<Atomo> ::= <LlamadaFunc>
                    case 39:                     //<SentenciaBloque> ::= <Sentencia>
                    case 40:                     //<SentenciaBloque> ::= <Bloque>
                    case 50:                     //<Expresion> ::= <Atomo>
                        pila.Pop();              //quita estado
                        nodo = (Node)pila.Pop(); //quita defvar
                        break;

                    case 6:    // <DefVar> ::= tipo id <ListaVar> ;
                        nodo = new DefVar(ref pila);

                        break;

                    case 8:                                                                      //<ListaVar> ::= , id <ListaVar>
                        pila.Pop();                                                              //quita estado
                        Node lvar = ((Node)pila.Pop());
                        pila.Pop();                                                              //quita estado
                        nodo           = new Identificador(((Terminal)pila.Pop()).nodo.Simbolo); //quita id
                        nodo.Siguiente = lvar;
                        pila.Pop();                                                              //quita estado
                        pila.Pop();                                                              //quita la coma
                        break;

                    case 9:    //<DefFunc> ::= tipo id ( <Parametros> ) <BloqFunc>
                        nodo = new DefFunc(ref pila);
                        break;

                    case 11:    //<Parametros> ::= tipo id <ListaParam>
                        nodo = new Parametros(ref pila);
                        break;

                    case 13:        //<ListaParam> ::= , tipo id <ListaParam>
                        nodo = new Parametros(ref pila);
                        pila.Pop(); //quita estado;
                        pila.Pop(); //quita la coma
                        break;

                    case 14:                       //<BloqFunc> ::= { <DefLocales> }
                    case 30:                       //<Bloque> ::= { <Sentencias> }
                    case 41:                       //<Expresion> ::= ( <Expresion> )
                        pila.Pop();                //quita estado
                        pila.Pop();                //quita }
                        pila.Pop();                //quita estado
                        nodo = ((Node)pila.Pop()); //quita <deflocales> o <sentencias>
                        pila.Pop();
                        pila.Pop();                //quita la {
                        break;

                    case 21:     //<Sentencia> ::= id = <Expresion> ;
                        nodo = new Asignacion(ref pila);
                        break;

                    case 22:    //<Sentencia> ::= if ( <Expresion> ) <SentenciaBloque> <Otro>
                        nodo = new If(ref pila);
                        break;

                    case 23:    //<Sentencia> ::= while ( <Expresion> ) <Bloque>
                        nodo = new While(ref pila);
                        break;

                    case 24:    //<Sentencia> ::= do <Bloque> while ( <Expresion> ) ;
                        nodo = new DoWhile(ref pila);
                        break;

                    case 25:    //<Sentencia> ::= for id = <Expresion> : <Expresion> : <Expresion> <SentenciaBloque>
                        nodo = new For(ref pila);
                        break;

                    case 26:    //<Sentencia> ::= return <Expresion> ;
                        nodo = new Return(ref pila);
                        break;

                    case 27:                       //<Sentencia> ::= <LlamadaFunc> ;
                        pila.Pop();
                        pila.Pop();                //quita ;
                        pila.Pop();
                        nodo = ((Node)pila.Pop()); //quita llamadafunc
                        break;

                    case 29:                       //<Otro> ::= else <SentenciaBloque>
                        pila.Pop();
                        nodo = ((Node)pila.Pop()); //quita sentencia bloque
                        pila.Pop();
                        pila.Pop();                //quita el else
                        break;

                    case 34:    // <ListaArgumentos> ::= , <Expresion> <ListaArgumentos>

                        pila.Pop();
                        aux = ((Node)pila.Pop());  //quita la lsta de argumentos
                        pila.Pop();
                        nodo = ((Node)pila.Pop()); //quita expresion
                        pila.Pop();
                        pila.Pop();                //quita la ,
                        nodo.Siguiente = aux;
                        break;

                    case 36:
                        pila.Pop();
                        nodo = new Identificador(((Terminal)pila.Pop()).nodo.Simbolo);
                        break;

                    case 37:
                        pila.Pop();
                        nodo = new Constante(((Terminal)pila.Pop()).nodo.Simbolo);
                        break;

                    case 38:
                        nodo = new LlamadaFunc(ref pila);
                        break;

                    //R42 < Expresion > ::= opSuma < Expresion >
                    //R43 < Expresion > ::= opNot < Expresion >
                    case 42:
                    case 43:
                        nodo = new Operacion1(ref pila);
                        break;

                    //R44 < Expresion > ::= < Expresion > opMul < Expresion >
                    //R45 < Expresion > ::= < Expresion > opSuma < Expresion >
                    //R46 < Expresion > ::= < Expresion > opRelac < Expresion >
                    //R47 < Expresion > ::= < Expresion > opIgualdad < Expresion >
                    //R48 < Expresion > ::= < Expresion > opAnd < Expresion >
                    //R49 < Expresion > ::= < Expresion > opOr < Expresion >
                    case 44:
                    case 45:
                    case 46:
                    case 47:
                    case 48:
                    case 49:
                        nodo = new Operacion2(ref pila);
                        break;

                    //aqui cae R2,R7,R10,R12,R15,R19,R28,R31,R33,
                    default:
                        pops = Rules.ElementAt(r).TotalProductions;

                        if (pops > 0)
                        {
                            while (pops > 0)
                            {
                                pila.Pop();
                                pila.Pop();
                                pops--;
                            }
                        }
                        break;
                    }
                    //x = (int)pila.Peek();
                    x = ((Estado)pila.Peek()).transicion; //((Estado)pila.Peek()).numestado;

                    y = rules.ElementAt(r).Id;            //columna= idreglas[regla];
                    NoTerminal nt = new NoTerminal(y);    //NoTerminal NT =new NoTerminal(idreglas[regla]);
                    //nt.nodo = nodo;
                    //pila.Push(rules.ElementAt(r).Id);
                    pila.Push(nodo);

                    r = tablaLR[x, y]; //transicion = tabla[fila][columna];
                    //pila.Push(r);
                    pila.Push(new Estado(r));
                    newSymbol = false;
                    Root      = nodo;
                }
                else
                {
                    //Error
                    error = true;
                }
            }

            Root.validatipos(ASemantico.Simbolos, ASemantico.Errores);
            if (error)
            {
                currentSymbol.ErrorSintactico = true;
            }
            if (ASemantico.Errores.Count > 0)
            {
                currentSymbol.ErrorSemantico = true;
                currentSymbol.Errores        = ASemantico.Errores;
                error = true;
            }


            return(error ? currentSymbol : null);
        }