Exemple #1
0
        //
        // GET: /Problema/Edit/

        public ActionResult Edit(string omi, int dia, int numero, TipoOlimpiada tipo = TipoOlimpiada.OMI)
        {
            if (!estaLoggeado())
            {
                guardarParams(Pagina.LOGIN, Pagina.PROBLEMA, omi + ":" + dia + ":" + numero);
                return(RedirectTo(Pagina.LOGIN));
            }

            if (!esAdmin())
            {
                return(RedirectTo(Pagina.ERROR, 401));
            }

            Olimpiada o = Olimpiada.obtenerOlimpiadaConClave(omi, tipo);

            if (o == null)
            {
                return(RedirectTo(Pagina.ERROR, 401));
            }

            if (dia < 0 || dia > 2)
            {
                return(RedirectTo(Pagina.ERROR, 401));
            }

            if (numero < 0 || numero > 4)
            {
                return(RedirectTo(Pagina.ERROR, 401));
            }

            Problema p = Problema.obtenerProblema(omi, tipo, dia, numero);

            return(View(p));
        }
Exemple #2
0
        public void Expande()
        {
            var pai = borda.OrderBy(n => problema.ValorHeuristica(n.Estado)).First();

            borda.Remove(pai);

            var acoes = Problema.Acoes(pai.Estado).Where(a => !Borda.Any(n => a.Resultado.Equals(n.Estado)));

            foreach (var acao in acoes)
            {
                var no = new No <T>
                {
                    Estado = acao.Resultado,
                    Pai    = pai,
                };

                borda.Add(no);

                if (Problema.TestaObjetivo(no.Estado))
                {
                    Objetivo = no;
                    return;
                }
            }
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            int      id          = Convert.ToInt32(cboTipo.SelectedValue.ToString());
            String   descricao   = txtDescricao.Text;
            int      idNivel     = Convert.ToInt32(cboNivel.SelectedValue.ToString());
            DateTime dataCriacao = Convert.ToDateTime(txtDataCriacao.Text);


            Problema problema = new Problema()
            {
                Descricao   = descricao,
                DataCriacao = dataCriacao,
                Tipo        = new Tipo()
                {
                    Id = id
                },

                NivelDificuldade = new Nivel()
                {
                    Id = idNivel
                },
            };

            if (new ProblemaDB().insert(problema))
            {
                MessageBox.Show("Registro inserido!");
            }
            else
            {
                MessageBox.Show("Erro ao inserir registro");
            }
        }
Exemple #4
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            Problema prob = new Problema();

            prob.Descricao   = txtDescricao.Text;
            prob.DataCriacao = Convert.ToDateTime(txtData.Text);
            prob.Tipo        = new Tipo()
            {
                Id = Convert.ToInt32(cboTipo.SelectedValue)
            };                                                                      // Descricao = cboTipo.SelectedItem.ToString()
            prob.NivelDificuldade = new Nivel()
            {
                Id = Convert.ToInt32(cboNivel.SelectedValue)
            };                                                                                    // Descricao = cboNivel.SelectedItem.ToString()



            if (new ProblemaDB().insert(prob))
            {
                MessageBox.Show("Registro inserido!");
                txtDescricao.Text     = "";
                txtData.Text          = "";
                cboTipo.SelectedItem  = 0;
                cboNivel.SelectedItem = 0;
                CarregarGrid();
            }
            else
            {
                MessageBox.Show("Erro ao inserir registro!");
            }
        }
        public static void Validate(this Problema problema)
        {
            problema.ClearBrokenRules();

            if (string.IsNullOrEmpty(problema.NomeMapa) && string.IsNullOrEmpty(problema.Id))
            {
                problema.BrokenRules.Add("NomeMapa", Resources.ProblemSpecification_AttributeName_NomeMapa);//Um mapa deve ser especificado.
            }
            if (string.IsNullOrEmpty(problema.Origem))
            {
                problema.BrokenRules.Add("Origem", Resources.ProblemSpecification_AttributeName_Origem);//A origem deve ser especificada.
            }
            if (string.IsNullOrEmpty(problema.Destino))
            {
                problema.BrokenRules.Add("Destino", Resources.ProblemSpecification_AttributeName_Destino);//O destino deve ser especificado.
            }
            if (problema.AutonomiaVeiculo == 0.00m)
            {
                problema.BrokenRules.Add("AutonomiaVeiculo", Resources.ProblemSpecification_AttributeName_AutonomiaVeiculo);//A autonomia do veículo não pode ser zero.
            }
            if (problema.ValorCombustivel == 0.00m)
            {
                problema.BrokenRules.Add("ValorCombustivel", Resources.ProblemSpecification_AttributeName_ValorCombustivel);//O valor do combustivel não pode ser zero.
            }
            //TODO: declare more specifications if needed
        }
        public async Task <IActionResult> Edit(int id, Problema problema)
        {
            if (id != problema.IdProblema)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    bd.Update(problema);
                    await bd.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProblemaExists(problema))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(problema));
        }
        public int NuevoProblema(Problema problema)
        {
            Cn = ObjCn.getConecta();
            Cn.Open();

            using (SqlTransaction tr = Cn.BeginTransaction(IsolationLevel.Serializable))
            {
                SqlCommand cmd = new SqlCommand("SP_NUEVOPROBLEMA", Cn, tr);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@DES", SqlDbType.VarChar).Value = problema.Descripcion;
                cmd.Parameters.Add("@TIP", SqlDbType.VarChar).Value = problema.Tipo;

                try
                {
                    int n = cmd.ExecuteNonQuery();
                    tr.Commit();
                    return(n);
                }
                catch (Exception e)
                {
                    tr.Rollback();
                    Console.WriteLine(e);
                    throw;
                }
            }
        }
Exemple #8
0
 public void AddProblemaInInception(Inceptions inception, Problema problema)
 {
     inception.Problemas.Add(problema);
     inception.DataAtualizacao = DateTime.Now;
     _inceptionRepository.Update(inception);
     _inceptionRepository.Save();
 }
Exemple #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UsuarioOnline"] == null)
        {
            Response.Redirect("~/Views/Login.aspx");
        }
        else
        {
            Usuario user = (Usuario)Session["UsuarioOnline"];
            if (user.Tipo_Usuario != 1)
            {
                Response.Redirect("~/Views/Logout.aspx");
            }
        }

        if (!Page.IsPostBack)
        {
            List <Problema> problemas = Problema.carregarProblemas();
            foreach (Problema problema in problemas)
            {
                selProblema.Items.Add(new ListItem(problema.TituloProblema, problema.IdProblema.ToString()));
            }
        }

        if (selProblema.SelectedIndex > -1)
        {
            carregarQuestoes(int.Parse(selProblema.SelectedValue));
        }
    }
Exemple #10
0
        private List <Problema> TransformaSQLReaderEmList(SqlDataReader retorno)
        {
            var listProblema = new List <Problema>();

            while (retorno.Read())
            {
                var item = new Problema()
                {
                    Id          = Convert.ToInt32(retorno["id"]),
                    Descricao   = retorno["descricao"].ToString(),
                    DataCriacao = Convert.ToDateTime(retorno["datacriacao"].ToString()),
                    Tipo        = new Tipo()
                    {
                        Id = Convert.ToInt32(retorno["id"].ToString())
                    },
                    NivelDificuldade = new Nivel()
                    {
                        Id = Convert.ToInt32(retorno["id"].ToString())
                    },
                };

                listProblema.Add(item);
            }
            return(listProblema);
        }
Exemple #11
0
        public override void Expande()
        {
            var no = borda.Dequeue();

            Explorado.Add(no.Estado);

            var resultados = Problema.Acoes(no.Estado)
                             .Where(e => !Explorado.Contains(e.Resultado) && !borda.Any(b => b.Estado.Equals(e.Resultado)))
                             .Select(a => a.Resultado);

            foreach (var resultado in resultados)
            {
                var filho = new No <T>
                {
                    Pai          = no,
                    Estado       = resultado,
                    Profundidade = no.Profundidade + 1
                };
                borda.Enqueue(filho);

                if (Problema.TestaObjetivo(resultado))
                {
                    Objetivo = filho;
                    return;
                }
            }
        }
Exemple #12
0
        private List <Problema> DataToEntity(DataTable data)
        {
            if (data != null)
            {
                if (data.Rows.Count > 0)
                {
                    List <Problema> P = new List <Problema>();
                    try
                    {
                        foreach (DataRow linha in data.Rows)
                        {
                            Problema p = new Problema();
                            try { p.Id = Convert.ToInt32(linha.ItemArray[0]); } catch { }
                            try { p.DataInsert = (DateTime)linha.ItemArray[1]; } catch { }
                            try { p.Resolvido = Convert.ToInt32(linha.ItemArray[2]); } catch { }
                            try { p.CheckList = linha.ItemArray[3].ToString(); } catch { }
                            try { p.Placa = linha.ItemArray[4].ToString(); } catch { }
                            try { p.Descricao = linha.ItemArray[5].ToString(); } catch { }
                            try { p.UsuarioResolveu = linha.ItemArray[6].ToString(); } catch { }
                            try { p.DataResolveu = (DateTime)linha.ItemArray[7]; } catch { }
                            try { p.Manutencao = linha.ItemArray[8].ToString(); } catch { }
                            try { p.Comentario = linha.ItemArray[9].ToString(); } catch { }
                            try { p.Usuario = linha.ItemArray[10].ToString(); } catch { }


                            P.Add(p);
                        }
                    }
                    catch (Exception) { return(null); }

                    return(P);
                }
            }
            return(null);
        }
Exemple #13
0
        public ActionResult Create(Problema problema)
        {
            MProblema mProblema = new MProblema();

            TempData["Message"] = mProblema.Add(problema) ? "Problema Cadastrado" : "Ação não realizada";
            return(RedirectToAction("Create"));
        }
        public List <Model.Problema> search <T>(string campo, T valor)
        {
            ConnectionFactory cf    = new ConnectionFactory();
            MySqlConnection   conex = cf.database();
            MySqlCommand      sql   = new MySqlCommand("select * from problema where " + campo + " = @value", conex);

            sql.Parameters.AddWithValue("@value", valor);
            DataTable        data = new DataTable();
            MySqlDataAdapter dta  = new MySqlDataAdapter(sql);

            dta.Fill(data);
            List <Problema> problemas = new List <Problema>();

            for (int x = 0; x < data.Rows.Count; x++)
            {
                string id        = data.Rows[x]["id"].ToString();
                string nome      = data.Rows[x]["nome"].ToString();
                bool   stt       = Convert.ToBoolean(data.Rows[x]["stt"]);
                string detalhes  = data.Rows[x]["detalhes"].ToString();
                string descricao = data.Rows[x]["descricao"].ToString();

                Problema problema = new Problema(id, nome, stt, detalhes, descricao);
                problemas.Add(problema);
            }
            return(problemas);
        }
        public IActionResult Create(Problema p)
        {
            context.Problemas.Add(p);
            context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemple #16
0
        public void Expande()
        {
            var no = borda.Pop();

            if (no.Estado.Equals(Objetivo))
            {
                Objetivo = no;
                return;
            }
            if (no.Profundidade >= limite)
            {
                return;
            }

            var resultados = Problema.Acoes(no.Estado)
                             .Where(a => !borda.Any(b => b.Estado.Equals(a.Resultado)))
                             .Select(a => a.Resultado);

            foreach (var resultado in resultados)
            {
                var filho = new No <T>
                {
                    Pai          = no,
                    Estado       = resultado,
                    Profundidade = no.Profundidade + 1
                };
                borda.Push(filho);

                if (Problema.TestaObjetivo(resultado))
                {
                    Objetivo = filho;
                    return;
                }
            }
        }
Exemple #17
0
        //
        // GET: /Olimpiada/

        public ActionResult Index(string clave, TipoOlimpiada tipo = TipoOlimpiada.OMI)
        {
            if (clave == Olimpiada.TEMP_CLAVE)
            {
                return(RedirectTo(Pagina.EDIT_OLIMPIADA, clave + ":" + tipo.ToString()));
            }

            Olimpiada o = Olimpiada.obtenerOlimpiadaConClave(clave, tipo);

            if (o == null)
            {
                return(RedirectTo(Pagina.ERROR, 404));
            }

            limpiarErroresViewBag();
            ViewBag.clave = clave;

            ViewBag.dia1 = Problema.obtenerProblemasDeOMI(clave, tipo, 1);
            ViewBag.dia2 = Problema.obtenerProblemasDeOMI(clave, tipo, 2);

            ViewBag.metadata = Problema.obetnerMetaDatadeOMI(clave, tipo);

            // Mientras las OMIS y OMIPS sean en el mismo evento que la OMI, no tienen su propia vista
            ViewBag.olimpiadas = Olimpiada.obtenerOlimpiadas(TipoOlimpiada.OMI);

            ViewBag.fotos = Album.obtenerAlbumsDeOlimpiada(clave, tipo).Count > 0;

            return(View(o));
        }
Exemple #18
0
        //Falta implementar o CarrageComboNivel

        private void btnsalvar_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(cbotipo.SelectedValue.ToString());

            MessageBox.Show("Id: " + id);
            string descricao = txtdescricao.Text;
            //Receber as demais informações

            Problema problema = new Problema()
            {
                Descricao = descricao,
                Tipo      = new Tipo()
                {
                    Id = id
                },
                //Complementar
            };

            if (new ProblemaDB().Insert(problema))
            {
                MessageBox.Show("Registro inserido!");
            }
            else
            {
                MessageBox.Show("Erro ao inserir registro");
            }
        }
Exemple #19
0
        public void Handle(ProblemaIntegrationEvent @event)
        {
            var inception = _inceptionsRepository.GetInceptionsByIdWithList(@event.IdInceptions);
            var problema  = new Problema(@event.Descricao, inception, @event.Abreviacao);

            _inceptionsService.AddProblemaInInception(inception, problema);
        }
Exemple #20
0
    public int Utes(Allapot a, Problema p)
    {
        var operatorok  = p.operatorok;
        var returnValue = 500;

        foreach (var o in operatorok)
        {
            if (o.babu == 1)
            {
                if (o.alkalmazhato(a))
                {
                    Allapot ujHuszarAllapot = o.lepes(a);
                    if (ujHuszarAllapot.huszar.SequenceEqual(a.kiraly))
                    {
                        returnValue = 0;
                    }
                }
            }
            else if (o.babu == 0)
            {
                if (o.alkalmazhato(a))
                {
                    Allapot ujKiralyAllapot = o.lepes(a);
                    if (ujKiralyAllapot.kiraly.SequenceEqual(a.huszar))
                    {
                        returnValue = 1;
                    }
                }
            }
        }
        return(returnValue);
    }
        public bool delete(string id)
        {
            Problema tmp = new Problema();

            tmp.id = id;
            return(daoProblema.delete(tmp));
        }
        /// <summary>
        /// Divide el problema K-esimo en un problema K-esimo de menor tamaño
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public override Problema[] Divide(Problema p)
        {
            PKesimo m = (PKesimo)p;
            T       piv = a[m.i];//optimizable con la pseudoMediana
            PosPiv  suv = pivotar(piv, m.i, m.j);
            int     u = suv.u, v = suv.v;

            PKesimo[] subp = new PKesimo[1];
            if ((m.i + m.k - 1) < u)
            {
                subp[0] = new PKesimo(m.i, u - 1, m.i + m.k - 1, false);
            }
            else
            {
                if ((v - m.i + 1) < m.k)
                {
                    subp[0] = new PKesimo(v + 1, m.j, m.k - v + m.i - 1, false);
                }
                else
                {
                    subp[0] = new PKesimo(m.i, m.j, m.k, true);
                }
            }
            return(subp);
        }
Exemple #23
0
    protected void btPesquisa_Click(object sender, EventArgs e)
    {
        Problema problema = new Problema();

        problema.TituloProblema = txtPesquisa.Text;
        grdDados.DataSource     = problema.Localiza();
        grdDados.DataBind();
    }
Exemple #24
0
        public ActionResult Delete(int id)
        {
            MProblema mProblema = new MProblema();
            Problema  problema  = mProblema.BringOne(c => c.idProblema == id);

            TempData["Message"] = mProblema.Delete(problema) ? "Problema deletado com sucesso" : "Ação não foi realizada";
            return(RedirectToAction("Index"));
        }
Exemple #25
0
 public RegSolucion()
 {
     InitializeComponent();
     ObjProb            = new Problema();
     solucionNE         = new SolucionNE();
     problemaNE         = new ProblemaNE();
     ObjProb.IdProblema = -1;
 }
Exemple #26
0
        protected override void Roda()
        {
            int stagCount = 0;

            for (int i = 0; i < Iteracoes; i++)
            {
                List <int> indexes = SolucaoAleatoria();

                var    menor         = indexes;
                var    custoOriginal = Problema.Custo(indexes);
                var    custo         = custoOriginal;
                double?novoCusto     = null;

                while (!(novoCusto < custo))
                {
                    for (int p = 0; p < indexes.Count; p++)
                    {
                        for (int q = 0; q < indexes.Count; q++)
                        {
                            var copia = indexes.ToList();
                            var n     = copia[q];
                            copia.RemoveAt(q);
                            copia.Insert(p, n);

                            novoCusto = Problema.Custo(copia);
                            if (novoCusto < custo)
                            {
                                indexes = copia;
                                custo   = novoCusto.Value;
                                break;
                            }
                        }
                        if (novoCusto < custo)
                        {
                            break;
                        }
                    }

                    Solucao = Problema.Solucao(indexes);
                    if (novoCusto >= custo)
                    {
                        break;
                    }
                }
                if (custo < custoOriginal)
                {
                    menor     = indexes;
                    stagCount = 0;
                }
                else
                {
                    if (++stagCount > Stagnacao)
                    {
                        break;
                    }
                }
            }
        }
Exemple #27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Usuario user = (Usuario)Session["UsuarioOnline"];

        if (user == null)
        {
            Response.Redirect("~/Views/Login.aspx");
        }
        else
        if (user.Tipo_Usuario != 2)
        {
            Response.Redirect("~/Views/Logout.aspx");
        }

        //recupera codigo do problema
        int codigo = 0;

        if (Request["codigo"] != null)
        {
            try { codigo = int.Parse(Request["codigo"]); }
            catch { codigo = -1; }
        }

        //se chegou até aqui e não é postback, então carrega o problema
        if (codigo > 0)
        {
            Problema problema = new Problema();
            if (problema.Carregar(codigo))
            {
                //mostra os detalhes do problema
                titulo.InnerText    = problema.TituloProblema;
                descricao.InnerHtml = problema.DescricaoProblema.Replace(Environment.NewLine, "<br />");
                if (problema.DataHoraAtualizacao.Year != 1)
                {
                    atualizacao.InnerText = problema.DataHoraAtualizacao.ToShortDateString() + " " + problema.DataHoraAtualizacao.ToShortTimeString();
                    sectionAtualizacao.Attributes["class"] = "col-md-12";
                }
                else
                {
                    sectionAtualizacao.Attributes.CssStyle["display"] = "none";
                }

                linha.Attributes["class"] = "row";

                carregarSolucoes(codigo);
                carregarQuestoes(codigo);
                carregarFeedbacks(codigo);
            }
            else
            {
                Alerta(problema.message);
            }
        }
        else
        {
            Alerta("Código Inválido");
        }
    }
Exemple #28
0
    private void carregarProblemas()
    {
        //carregar problemas
        panelProblemas.Controls.Clear();
        Table table = new Table();

        table.CssClass = "superFancyTable";
        TableHeaderRow  hr  = new TableHeaderRow();
        TableHeaderCell hc1 = new TableHeaderCell();
        TableHeaderCell hc2 = new TableHeaderCell();
        TableHeaderCell hc3 = new TableHeaderCell();

        hc1.Text = "Problema";
        hc2.Text = "Descrição";
        hr.Controls.Add(hc1);
        hr.Controls.Add(hc2);
        hr.Controls.Add(hc3);
        table.Controls.Add(hr);
        List <Problema> problemas = Problema.carregarProblemas();

        foreach (Problema problema in problemas)
        {
            TableRow  row           = new TableRow();
            TableCell cellNome      = new TableCell();
            TableCell cellDescricao = new TableCell();
            TableCell cellToolbar   = new TableCell();

            //prepara toolbar
            //prepara toolbar
            HyperLink          linkApagar = new HyperLink();
            HyperLink          linkEditar = new HyperLink();
            HtmlGenericControl editar     = new HtmlGenericControl("span");
            HtmlGenericControl apagar     = new HtmlGenericControl("span");
            linkApagar.NavigateUrl     = "javascript:apagarProblema(" + problema.IdProblema + ");";
            linkEditar.NavigateUrl     = "javascript:editarProblema(" + problema.IdProblema + ");";
            editar.Attributes["class"] = "glyphicon glyphicon-pencil ";
            apagar.Attributes["class"] = "glyphicon glyphicon-trash";
            linkApagar.Controls.Add(apagar);
            linkEditar.Controls.Add(editar);
            linkEditar.Attributes.CssStyle.Add("margin-right", "10px;");
            cellToolbar.Attributes["class"] = "text-center";
            cellToolbar.Controls.Add(linkEditar);
            cellToolbar.Controls.Add(linkApagar);

            cellNome.Text      = problema.TituloProblema;
            cellNome.ID        = "titulo" + problema.IdProblema;
            cellDescricao.Text = problema.DescricaoProblema;
            cellDescricao.ID   = "descricao" + problema.IdProblema;

            row.Controls.Add(cellNome);
            row.Controls.Add(cellDescricao);
            row.Controls.Add(cellToolbar);

            table.Controls.Add(row);
        }
        panelProblemas.Controls.Add(table);
    }
Exemple #29
0
        public void ValidacaoProblema_CamposObrigatoriosNaoPreenchidos_Invalido()
        {
            var problema           = new Problema {
            };
            var resultadoValidacao = validadorProblema.Validate(problema);

            Assert.False(resultadoValidacao.IsValid);
            Assert.Equal(4, resultadoValidacao.Errors.Count);
        }
Exemple #30
0
    protected void btnGravarProblema_Click(object sender, EventArgs e)
    {
        String titulo    = txtTitulo.Value;
        String descricao = txtDescricao.Value;
        bool   liberado  = true;

        if (txtTitulo.Value.Equals(""))
        {
            formTitulo.Attributes["class"] = "form-group has-error";
            helpBlockTitulo.InnerText      = "Título é preenchimento obrigatório";
            liberado = false;
        }


        if (txtDescricao.Value.Equals(""))
        {
            formDescricao.Attributes["class"] = "form-group has-error";
            helpBlockDescricao.InnerText      = "Descrição é preenchimento obrigatório";
            liberado = false;
        }

        if (liberado)
        {
            Problema problema = new Problema();

            problema.TituloProblema      = txtTitulo.Value;
            problema.DescricaoProblema   = txtDescricao.Value;
            problema.id_usuario_problema = ((Usuario)Session["UsuarioOnline"]).IdUsuario;

            //decide se vai gravar novo problema ou alterar problema já existent
            if (txtCodigoProblema.Value.Equals(""))
            {
                if (problema.Inserir())
                {
                    alerta.Attributes["class"] = "alert alert-success bottom20"; alerta.InnerText = "Problema Cadastrado com Sucesso."; txtTitulo.Value = ""; txtDescricao.Value = ""; txtCodigoProblema.Value = "";
                }
                else
                {
                    alerta.Attributes["class"] = "alert alert-danger bottom20"; alerta.InnerText = problema.message;
                }
            }
            else
            {
                problema.IdProblema = int.Parse(txtCodigoProblema.Value);
                if (problema.Alterar())
                {
                    alerta.Attributes["class"] = "alert alert-success bottom20"; alerta.InnerText = "Problema Alterado com Sucesso."; txtTitulo.Value = ""; txtDescricao.Value = ""; txtCodigoProblema.Value = "";
                }
                else
                {
                    alerta.Attributes["class"] = "alert alert-danger bottom20"; alerta.InnerText = problema.message;
                }
            }

            carregarProblemas();
        }
    }