void Awake()
    {
        sequencias = new Sequencia[numeroDeSequencias];

        for (int i = 0; i < numeroDeSequencias; i++)
        {
            primeiro   = numerosInicias[Random.Range(0, numerosInicias.Length)];
            incremento = incrementos[Random.Range(0, incrementos.Length)];

            for (int o = 0; o < i; o++)
            {
                if (primeiro == sequencias[o].PrimeiroValor && incremento == sequencias[o].Incremento)
                {
                    primeiro   = numerosInicias[Random.Range(0, numerosInicias.Length)];
                    incremento = incrementos[Random.Range(0, incrementos.Length)];
                }
            }

            sequencias[i] = new Sequencia(numeroDeNumerosDasSequencias, primeiro, incremento);
            Debug.Log("Sequencia: " + i + " Primeiro: " + primeiro + " Incremento: " + incremento);
            for (int n = 0; n < numeroDeNumerosDasSequencias; n++)
            {
                sequencias[i].NumerosDaSequencia[n] = primeiro + incremento * n;
                //Debug.Log(sequencias[i].NumerosDaSequencia[n]);
            }
        }
    }
Esempio n. 2
0
        public int IncrementarProximoNumero(string sigla, string descricao)
        {
            using (_banco = new BancoFB())
            {
                int valor = 0;
                _banco.RetornoReader("SELECT VALOR FROM SEQUENCIA WHERE SIGLA = '" + sigla + "'");
                if (_banco.Read())
                {
                    valor = _banco.CampoInt32("VALOR");
                }
                _banco.CloseReader();

                if (valor > 0)
                {
                    _banco.ExecutaComando("UPDATE SEQUENCIA SET VALOR = VALOR + 1 WHERE SIGLA = '" + sigla + "'");
                }
                else
                {
                    var model = new Sequencia();
                    model.Descricao = descricao;
                    model.Sigla     = sigla;
                    Salvar(model);
                    valor = 1;
                }
                return(valor);
            }
        }
Esempio n. 3
0
        public List <Sequencia> ListarPorTudo(int id = 0)
        {
            using (_banco = new BancoFB())
            {
                var sb = new StringBuilder();
                sb.Append("SELECT ID, SIGLA, DESCRICAO, VALOR FROM SEQUENCIA");
                if (id > 0)
                {
                    sb.Append(" WHERE ID = " + id);
                }
                else
                {
                    sb.Append(" ORDER BY SIGLA");
                }

                _banco.RetornoReader(sb.ToString());

                List <Sequencia> lista = new List <Sequencia>();
                while (_banco.Read())
                {
                    var model = new Sequencia()
                    {
                        Id        = _banco.CampoInt32("Id"),
                        Descricao = _banco.CampoStr("Descricao"),
                        Sigla     = _banco.CampoStr("Sigla"),
                        Valor     = _banco.CampoIntNull("Valor")
                    };
                    lista.Add(model);
                }
                ;
                _banco.CloseReader();

                return(lista);
            }
        }
Esempio n. 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            Sequencia sequencia = db.Sequencias.Find(id);

            db.Sequencias.Remove(sequencia);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
 public ActionResult Edit([Bind(Include = "SequenciaId,Tipo,Descricao")] Sequencia sequencia)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sequencia).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sequencia));
 }
Esempio n. 6
0
 public static Sequencia Salvar(Sequencia sequencia_)
 {
     using (Repositorio ctx = new Repositorio())
     {
         sequencia_.Validar();
         RequisicaoHTTP requisicao = new RequisicaoHTTP();
         ctx.Sequencias.Add(sequencia_);
         ctx.SaveChanges();
         return(sequencia_);
     }
 }
Esempio n. 7
0
        public ActionResult Create([Bind(Include = "SequenciaId,Tipo,Descricao")] Sequencia sequencia)
        {
            if (ModelState.IsValid)
            {
                db.Sequencias.Add(sequencia);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sequencia));
        }
Esempio n. 8
0
        public bool verificaCNPJ(string cnpj)
        {
            if (string.IsNullOrEmpty(cnpj))
            {
                return(false);
            }
            else
            {
                int[]  d = new int[14];
                int[]  v = new int[2];
                int    j, i, soma;
                string Sequencia, SoNumero;

                SoNumero = Regex.Replace(cnpj, "[^0-9]", string.Empty);

                //verificando se todos os numeros são iguais
                if (new string(SoNumero[0], SoNumero.Length) == SoNumero)
                {
                    return(false);
                }
                if (SoNumero.Length == 14)
                {
                    Sequencia = "6543298765432";
                    for (i = 0; i <= 13; i++)
                    {
                        d[i] = Convert.ToInt32(SoNumero.Substring(i, 1));
                    }
                    for (i = 0; i <= 1; i++)
                    {
                        soma = 0;
                        for (j = 0; j <= 11 + i; j++)
                        {
                            soma += d[j] * Convert.ToInt32(Sequencia.Substring(j + 1 - i, 1));
                        }

                        v[i] = (soma * 10) % 11;
                        if (v[i] == 10)
                        {
                            v[i] = 0;
                        }
                    }
                    return(v[0] == d[12] & v[1] == d[13]);
                }
                // CPF ou CNPJ inválido se
                // a quantidade de dígitos numérios for diferente de 11 e 14
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 9
0
        // GET: Sequencias/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Sequencia sequencia = db.Sequencias.Find(id);

            if (sequencia == null)
            {
                return(HttpNotFound());
            }
            return(View(sequencia));
        }
Esempio n. 10
0
        private void Iniciar()
        {
            InitializeComponent();

            tabControl1.TabPages.Remove(tpEditar);
            tabControl1.TabPages.Remove(tpFiltro);

            _session = SessionFactory.Criar();

            Geral.Grade.Config(dgvDados);

            _model = new Sequencia();
            CarregarConsulta();
        }
Esempio n. 11
0
 public void Insert()
 {
     try
     {
         Sequencia seq = new Sequencia();
         seq.Name  = "Produto";
         seq.Value = 1;
         _context.Sequencias.InsertOneAsync(seq);
     }
     catch (Exception ex)
     {
         // log or manage the exception
         throw ex;
     }
 }
Esempio n. 12
0
        public override void Editar()
        {
            if (dgvDados.RowCount == 0)
            {
                return;
            }

            _model = _session.ServiceSequencia.RetornarPorId(int.Parse(dgvDados.CurrentRow.Cells["Id"].Value.ToString()));

            txtSigla.Enabled = false;
            base.Editar();

            VincularDados();
            txtDescricao.Focus();
        }
Esempio n. 13
0
 public Sequencia ObterPorid(int id)
 {
     using (_banco = new BancoFB())
     {
         var model = new Sequencia();
         _banco.RetornoReader("SELECT ID, SIGLA, DESCRICAO, VALOR FROM SEQUENCIA WHERE ID = " + id);
         if (_banco.Read())
         {
             model.Id        = _banco.CampoInt32("Id");
             model.Descricao = _banco.CampoStr("Descricao");
             model.Sigla     = _banco.CampoStr("Sigla");
             model.Valor     = _banco.CampoIntNull("Valor");
         }
         _banco.CloseReader();
         return(model);
     }
 }
Esempio n. 14
0
        public static bool Deletar(int uuid)
        {
            using (Repositorio ctx = new Repositorio())
            {
                Sequencia _sequencia = ctx.Sequencias
                                       .Where(s => s.id == uuid).FirstOrDefault();

                if (_sequencia == null)
                {
                    return(true);
                }

                ctx.Remove(_sequencia);
                ctx.SaveChanges();

                return(true);
            }
        }
Esempio n. 15
0
 public void Salvar(Sequencia model)
 {
     using (_banco = new BancoFB())
     {
         string Instrucao;
         if (model.Id == 0)
         {
             model.Id  = _banco.RetornarId("SEQ_SEQUENCIA");
             Instrucao = string.Format("INSERT INTO SEQUENCIA(DESCRICAO, ID, SIGLA, VALOR) VALUES ('{0}', {1}, '{2}', {3}) returning ID",
                                       model.Descricao, model.Id, model.Sigla, model.Valor);
             model.Id = _banco.ExecutaScalar(Instrucao);
         }
         else
         {
             Instrucao = string.Format("UPDATE SEQUENCIA SET DESCRICAO='{0}', SIGLA='{1}', VALOR='{2}' WHERE ID = {3}",
                                       model.Descricao, model.Sigla, model.Valor, model.Id);
             _banco.ExecutaComando(Instrucao);
         }
     }
 }
        public bool sValidarCpfCnpj(string cpfCnpj)
        {
            cpfCnpj = cpfCnpj.Replace(".", "");
            cpfCnpj = cpfCnpj.Replace("-", "");
            cpfCnpj = cpfCnpj.Replace("/", "");

            if (string.IsNullOrEmpty(cpfCnpj))
            {
                return(false);
            }

            else
            {
                int[] d;
                int[] v = new int[2];

                string Sequencia, soNumero;

                soNumero = Regex.Replace(cpfCnpj, "[^0-9]", string.Empty);

                if (soNumero.Length == 11)
                {
                    d = new int[11];

                    for (int i = 0; i <= 10; i++)
                    {
                        d[i] = Convert.ToInt32(soNumero.Substring(i, 1));
                    }

                    for (int i = 0; i <= 1; i++)
                    {
                        int soma = 0;

                        for (int j = 0; j <= 8 + i; j++)
                        {
                            soma += d[j] * (10 + i - j);
                        }

                        v[i] = (soma) % 11;

                        if (v[i] == 10)
                        {
                            v[i] = 0;
                        }
                    }

                    return(v[0] == d[9] & v[1] == d[10]);
                }

                else if (soNumero.Length == 14)
                {
                    d = new int[14];

                    Sequencia = "6543298765432";
                    for (int i = 0; i <= 13; i++)
                    {
                        d[i] = Convert.ToInt32(soNumero.Substring(i, 1));
                    }
                    for (int i = 0; i <= 1; i++)
                    {
                        int soma = 0;
                        for (int j = 0; j <= 11 + i; j++)
                        {
                            soma += d[j] * Convert.ToInt32(Sequencia.Substring(j + 1 - i, 1));
                        }

                        v[i] = (soma * 10) % 11;
                        if (v[i] == 10)
                        {
                            v[i] = 0;
                        }
                    }
                    return(v[0] == d[12] & v[1] == d[13]);
                }

                else
                {
                    return(false);
                }
            }
        }
Esempio n. 17
0
        public static bool ValidaCPF(string cpf)
        {
            int[]  d = new int[14];
            int[]  v = new int[2];
            int    j, i, soma;
            string Sequencia, SoNumero;

            SoNumero = Regex.Replace(cpf, "[^0-9]", string.Empty);

            if (new string(SoNumero[0], SoNumero.Length) == SoNumero)
            {
                return(false);
            }

            if (SoNumero.Length == 11)
            {
                for (i = 0; i <= 10; i++)
                {
                    d[i] = Convert.ToInt32(SoNumero.Substring(i, 1));
                }
                for (i = 0; i <= 1; i++)
                {
                    soma = 0;
                    for (j = 0; j <= 8 + i; j++)
                    {
                        soma += d[j] * (10 + i - j);
                    }

                    v[i] = (soma * 10) % 11;
                    if (v[i] == 10)
                    {
                        v[i] = 0;
                    }
                }
                return(v[0] == d[9] & v[1] == d[10]);
            }
            else if (SoNumero.Length == 14)
            {
                Sequencia = "6543298765432";
                for (i = 0; i <= 13; i++)
                {
                    d[i] = Convert.ToInt32(SoNumero.Substring(i, 1));
                }
                for (i = 0; i <= 1; i++)
                {
                    soma = 0;
                    for (j = 0; j <= 11 + i; j++)
                    {
                        soma += d[j] * Convert.ToInt32(Sequencia.Substring(j + 1 - i, 1));
                    }

                    v[i] = (soma * 10) % 11;
                    if (v[i] == 10)
                    {
                        v[i] = 0;
                    }
                }
                return(v[0] == d[12] & v[1] == d[13]);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 18
0
        //Verifica se o CPF ou CNPJ digitado é válido
        public static bool ValidarCPFCNPJ()
        {
            if (string.IsNullOrEmpty(_CpfCnpJ))
            {
                return(false);
            }
            else
            {
                int[]  d = new int[14];
                int[]  v = new int[2];
                int    j, i, soma;
                string Sequencia, SoNumero;

                SoNumero = Regex.Replace(_CpfCnpJ, "[^0-9]", string.Empty);

                //verificando se todos os numeros são iguais
                if (new string(SoNumero[0], SoNumero.Length) == SoNumero)
                {
                    return(false);
                }

                // se a quantidade de dígitos numérios for igual a 11
                // iremos verificar como CPF
                if (SoNumero.Length == 11)
                {
                    for (i = 0; i <= 10; i++)
                    {
                        d[i] = Convert.ToInt32(SoNumero.Substring(i, 1));
                    }
                    for (i = 0; i <= 1; i++)
                    {
                        soma = 0;
                        for (j = 0; j <= 8 + i; j++)
                        {
                            soma += d[j] * (10 + i - j);
                        }

                        v[i] = (soma * 10) % 11;
                        if (v[i] == 10)
                        {
                            v[i] = 0;
                        }
                    }
                    return(v[0] == d[9] & v[1] == d[10]);
                }
                // se a quantidade de dígitos numérios for igual a 14
                // iremos verificar como CNPJ
                else if (SoNumero.Length == 14)
                {
                    Sequencia = "6543298765432";
                    for (i = 0; i <= 13; i++)
                    {
                        d[i] = Convert.ToInt32(SoNumero.Substring(i, 1));
                    }
                    for (i = 0; i <= 1; i++)
                    {
                        soma = 0;
                        for (j = 0; j <= 11 + i; j++)
                        {
                            soma += d[j] * Convert.ToInt32(Sequencia.Substring(j + 1 - i, 1));
                        }

                        v[i] = (soma * 10) % 11;
                        if (v[i] == 10)
                        {
                            v[i] = 0;
                        }
                    }
                    return(v[0] == d[12] & v[1] == d[13]);
                }
                // CPF ou CNPJ inválido se
                // a quantidade de dígitos numérios for diferente de 11 e 14
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 19
0
        public ActionResult <SequenciaResponse> Salvar([FromBody] SequenciaRequest funcionarioRequest)
        {
            Sequencia pessoa = _mapperRequest.Map <Sequencia>(funcionarioRequest);

            return(Ok(_mapperResponse.Map <SequenciaResponse>(SequenciaService.Salvar(pessoa))));
        }
 public IActionResult Post([FromBody] Sequencia sequencia)
 {
     _repositorySequencia.Create(sequencia);
     return(Created("api/sequencias", sequencia));
 }
Esempio n. 21
0
        public void CPFnCNPJ(string cpfcnpj)
        {
            if (!string.IsNullOrEmpty(cpfcnpj))
            {
                int[]  d = new int[14];
                int[]  v = new int[2];
                int    j, i, soma;
                string Sequencia, SoNumero;

                SoNumero = Regex.Replace(cpfcnpj, "[^0-9]", string.Empty);

                //verificando se todos os numeros são iguais
                if (new string(SoNumero[0], SoNumero.Length) == SoNumero)
                {
                    throw new Exception("CPF ou CNPJ Invalido");
                }

                // se a quantidade de dígitos numérios for igual a 11
                // iremos verificar como CPF
                if (SoNumero.Length == 11)
                {
                    for (i = 0; i <= 10; i++)
                    {
                        d[i] = Convert.ToInt32(SoNumero.Substring(i, 1));
                    }
                    for (i = 0; i <= 1; i++)
                    {
                        soma = 0;
                        for (j = 0; j <= 8 + i; j++)
                        {
                            soma += d[j] * (10 + i - j);
                        }

                        v[i] = (soma * 10) % 11;
                        if (v[i] == 10)
                        {
                            v[i] = 0;
                        }
                    }
                    if (!(v[0] == d[9] & v[1] == d[10]))
                    {
                        throw new Exception("CPF ou CNPJ Invalido");
                    }
                }
                // se a quantidade de dígitos numérios for igual a 14
                // iremos verificar como CNPJ
                else if (SoNumero.Length == 14)
                {
                    Sequencia = "6543298765432";
                    for (i = 0; i <= 13; i++)
                    {
                        d[i] = Convert.ToInt32(SoNumero.Substring(i, 1));
                    }
                    for (i = 0; i <= 1; i++)
                    {
                        soma = 0;
                        for (j = 0; j <= 11 + i; j++)
                        {
                            soma += d[j] * Convert.ToInt32(Sequencia.Substring(j + 1 - i, 1));
                        }

                        v[i] = (soma * 10) % 11;
                        if (v[i] == 10)
                        {
                            v[i] = 0;
                        }
                    }
                    if (!(v[0] == d[12] & v[1] == d[13]))
                    {
                        throw new Exception("CPF ou CNPJ Invalido");
                    }
                }
                // CPF ou CNPJ inválido se
                // a quantidade de dígitos numérios for diferente de 11 e 14
                else
                {
                    throw new Exception("CPF ou CNPJ Invalido");
                }
            }
            else
            {
                throw new Exception("Digite seu CPF/CNPJ");
            }
        }
Esempio n. 22
0
        public void Validacoes(bool validaSequencia)
        {
            if (string.IsNullOrEmpty(Inicial))
            {
                Erro = "A letra inicial não pode ser vazia.";
                return;
            }

            if (RegrasDeProducao.Count == 0)
            {
                Erro = "Deve existir ao menos uma regra de produção adicionada.";
                return;
            }

            if (Variaveis.Count == 0)
            {
                Erro = "Deve existir ao menos uma variável adicionada.";
                return;
            }

            bool Exists = Variaveis.Exists(x => x == Inicial);

            if (!Exists)
            {
                Erro = "Letra inicial não existe nas variáveis adiciondas.";
                return;
            }

            var regras = RegrasDeProducao.Where(x => x.De == string.Empty).ToList();

            if (regras.Count > 0)
            {
                Erro = "Nenhuma regra de produção pode se iniciar com vazio.";
                return;
            }

            if (validaSequencia == true)
            {
                if (Sequencia.Count == 0)
                {
                    Erro = "Deve existir ao menos uma sequência adicionada.";
                    return;
                }

                var regra = RegrasDeProducao.Where(x => x.Indice == Sequencia.FirstOrDefault()).FirstOrDefault();

                if (regra.De != Inicial)
                {
                    Erro = "A primeira regra de produção da sequencia não é compatível com a palavra inicial.";
                    return;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(Resposta))
                {
                    Erro = "A resposta precisa ser adicionada.";
                    return;
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Método único de validação do CPF e CNPJ, o método recebe o valor a ser validado realizar o replace dos campos não numéricos caso houver.
        /// Em seguida realiza a validação da string passada verificando se atende ao padrão definido pela Receita Federal do Brasil.
        /// </summary>
        /// <param name="cpfcnpj"></param>
        /// <param name="field"></param>
        /// <returns type=string></returns>
        public bool ValidateCPFCNPJ(string cpfcnpj, string field = "")
        {
            if (string.IsNullOrEmpty(cpfcnpj))
            {
                return(false);
            }
            int[]  d = new int[14];
            int[]  v = new int[2];
            int    j, i, soma;
            string Sequencia, numeroDocumento;

            numeroDocumento = Regex.Replace(cpfcnpj, @"[^\d]", string.Empty);

            if (new string(numeroDocumento[0], numeroDocumento.Length) == numeroDocumento)
            {
                return(false);
            }
            switch (numeroDocumento.Length)
            {
            case 11:
                for (i = 0; i <= 10; i++)
                {
                    d[i] = Convert.ToInt32(numeroDocumento.Substring(i, 1));
                }
                for (i = 0; i <= 1; i++)
                {
                    soma = 0;
                    for (j = 0; j <= 8 + i; j++)
                    {
                        soma += d[j] * (10 + i - j);
                    }

                    v[i] = (soma * 10) % 11;
                    if (v[i] == 10)
                    {
                        v[i] = 0;
                    }
                }
                if (v[0] == d[9] || v[1] == d[10])
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
                break;

            case 14:
                //Sequencia de valor para a validacao do CNPJ
                Sequencia = "6543298765432";
                for (i = 0; i <= 13; i++)
                {
                    d[i] = Convert.ToInt32(numeroDocumento.Substring(i, 1));
                }
                for (i = 0; i <= 1; i++)
                {
                    soma = 0;
                    for (j = 0; j <= 11 + i; j++)
                    {
                        soma += d[j] * Convert.ToInt32(Sequencia.Substring(j + 1 - i, 1));
                    }

                    v[i] = (soma * 10) % 11;
                    if (v[i] == 10)
                    {
                        v[i] = 0;
                    }
                }
                if (v[0] == d[12] || v[1] == d[13])
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
                break;

            default:
                return(false);

                break;
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Sequencia sequencia = db.Sequencias.Find(id);

            return(View("Erase", sequencia));
        }