public List <FDomain> Listar()
        {
            List <FDomain> funcionarios = new List <FDomain>();

            using (SqlConnection con = new SqlConnection(StringConexao))
            {
                con.Open();
                string        Query = "Select IdFuncionario, Nome, Sobrenome,DataNascimento FROM Funcionarios";
                SqlDataReader L;

                using (SqlCommand cmd = new SqlCommand(Query, con))
                {
                    L = cmd.ExecuteReader();
                    while (L.Read())
                    {
                        FDomain funcionario = new FDomain
                        {
                            IdFuncionario  = Convert.ToInt32(L["IdFuncionario"]),
                            Nome           = L["Nome"].ToString(),
                            Sobrenome      = L["Sobrenome"].ToString(),
                            DataNascimento = Convert.ToDateTime(L["DataNascimento"])
                        };
                        funcionarios.Add(funcionario);
                    }
                }
            }
            return(funcionarios);
        }
        public FDomain BuscarPorId(int Id)
        {
            string Query = "Select IdFuncionario,Nome,Sobrenome from Funcionarios Where IdFuncionario = @IdFuncionario";

            using (SqlConnection con = new SqlConnection(StringConexao))
            {
                con.Open();
                SqlDataReader L;
                using (SqlCommand cmd = new SqlCommand(Query, con))
                {
                    cmd.Parameters.AddWithValue("@IdFuncionario", Id);
                    L = cmd.ExecuteReader();

                    if (L.HasRows)
                    {
                        while (L.Read())
                        {
                            FDomain funcionario = new FDomain
                            {
                                IdFuncionario  = Convert.ToInt32(L["IdFuncionario"]),
                                Nome           = L["Nome"].ToString(),
                                Sobrenome      = L["Sobrenome"].ToString(),
                                DataNascimento = Convert.ToDateTime(L["DataNascimento"])
                            };
                            return(funcionario);
                        }
                    }
                    return(null);
                }
            }
        }
        public List <FDomain> Ordernar(string ordenacao)
        {
            List <FDomain> funcionarios = new List <FDomain>();

            using (SqlConnection con = new SqlConnection(StringConexao))
            {
                con.Open();
                string        Query = "Select IdFuncionario,Nome,Sobrenome, DataNascimento from Funcionarios order by Funcionarios.Nome @ordenacao";
                SqlDataReader L;

                using (SqlCommand cmd = new SqlCommand(Query, con))
                {
                    cmd.Parameters.AddWithValue("@ordenacao", ordenacao);
                    L = cmd.ExecuteReader();
                    while (L.Read())
                    {
                        FDomain funcionario = new FDomain
                        {
                            IdFuncionario  = Convert.ToInt32(L["IdFuncionario"]),
                            Nome           = L["Nome"].ToString(),
                            Sobrenome      = L["Sobrenome"].ToString(),
                            DataNascimento = Convert.ToDateTime(L["DataNascimento"])
                        };
                        funcionarios.Add(funcionario);
                    }
                }
            }
            return(funcionarios);
        }
Exemple #4
0
        public IActionResult BuscarPorNome(string nome)
        {
            FDomain funcionario = Frepository.BuscarPorNome(nome);

            if (funcionario == null)
            {
                return(NotFound());
            }
            return(Ok(funcionario));
        }
Exemple #5
0
        public IActionResult BuscarPorId(int id)
        {
            FDomain funcionario = Frepository.BuscarPorId(id);

            if (funcionario == null)
            {
                return(NotFound());
            }
            return(Ok(funcionario));
        }
        public void Cadastrar(FDomain funcionario)
        {
            string Query = "INSERT Funcionarios (Nome,Sobrenome) VALUES (@Nome,@Sobrenome)";

            using (SqlConnection con = new SqlConnection(StringConexao))
            {
                SqlCommand cmd = new SqlCommand(Query, con);
                cmd.Parameters.AddWithValue("@Nome", funcionario.Nome);
                cmd.Parameters.AddWithValue("@Sobrenome", funcionario.Sobrenome);
                con.Open();
                cmd.ExecuteNonQuery();
            }
        }
        public void Atualizar(FDomain funcionario)
        {
            string Query = "Update Funcionarios SET Nome = @Nome, Sobrenome = @Sobrenome, DataNascimento = @DataNascimento Where IdFuncionario = @IdFuncionario";

            using (SqlConnection con = new SqlConnection(StringConexao))
            {
                SqlCommand cmd = new SqlCommand(Query, con);
                cmd.Parameters.AddWithValue("@Nome", funcionario.Nome);
                cmd.Parameters.AddWithValue("@Sobrenome", funcionario.Sobrenome);
                cmd.Parameters.AddWithValue("@DataNascimento", funcionario.DataNascimento);
                cmd.Parameters.AddWithValue("@IdFuncionario", funcionario.IdFuncionario);
                con.Open();
                cmd.ExecuteNonQuery();
            }
        }
        public List <NomescompletoVM> NomesCompletos()
        {
            List <NomescompletoVM> funcionarios1 = new List <NomescompletoVM>();
            List <FDomain>         funcionarios  = new List <FDomain>();

            using (SqlConnection con = new SqlConnection(StringConexao))
            {
                con.Open();
                string        Query = "Select distinct IdFuncionario, Nome, Sobrenome,DataNascimento FROM Funcionarios";
                SqlDataReader L;

                using (SqlCommand cmd = new SqlCommand(Query, con))
                {
                    L = cmd.ExecuteReader();
                    while (L.Read())
                    {
                        FDomain funcionario = new FDomain
                        {
                            IdFuncionario  = Convert.ToInt32(L["IdFuncionario"]),
                            Nome           = L["Nome"].ToString(),
                            Sobrenome      = L["Sobrenome"].ToString(),
                            DataNascimento = Convert.ToDateTime(L["DataNascimento"])
                        };
                        funcionarios.Add(funcionario);
                        foreach (var item in funcionarios)
                        {
                            if (funcionario.Nome == funcionario.Nome)
                            {
                                NomescompletoVM nomescompletosvm = new NomescompletoVM();
                                nomescompletosvm.nomecompleto = funcionario.Nome + " " + funcionario.Sobrenome;
                                nomescompletosvm.PessoasId    = funcionario.IdFuncionario;
                                funcionarios1.Add(nomescompletosvm);
                            }
                        }
                    }
                }
            }
            return(funcionarios1);
        }
Exemple #9
0
        // ReSharper disable once IdentifierTypo
        // ReSharper disable once InconsistentNaming
        public void PSMTNPCStatTest()
        {
            var p           = new Problem("NPC stats");
            var str         = new FloatVariable("str", 0, 10);
            var con         = new FloatVariable("con", 0, 10);
            var dex         = new FloatVariable("dex", 0, 10);
            var intel       = new FloatVariable("int", 0, 10);
            var wis         = new FloatVariable("wis", 0, 10);
            var charisma    = new FloatVariable("char", 0, 10);
            var classDomain = new FDomain <string>("character class",
                                                   "fighter", "magic user", "cleric", "thief");
            var cClass = classDomain.Instantiate("class");

            p.Assert(
                (cClass == "fighter") > (str > intel),
                (cClass == "fighter") > (str > 5),
                (cClass == "fighter") > (con > 5),
                (cClass == "fighter") > (intel < 8),
                (cClass == "magic user") > (str < intel),
                (cClass == "magic user") > (intel > 5),
                (cClass == "magic user") > (str < 8),
                (cClass == "cleric") > (wis > 5),
                (cClass == "cleric") > (con < wis),
                (cClass == "thief") > (dex > 5),
                (cClass == "thief") > (charisma > 5),
                (cClass == "thief") > (wis < 5),
                (cClass == "thief") > (dex > str),
                (cClass == "thief") > (charisma > intel)
                );
            for (int i = 0; i < 100; i++)
            {
                var s = p.Solve();
                if (s[(cClass == "fighter")])
                {
                    Assert.IsTrue(str.Value(s) >= intel.Value(s));
                }
                if (s[(cClass == "fighter")])
                {
                    Assert.IsTrue(str.Value(s) >= 5);
                }
                if (s[(cClass == "fighter")])
                {
                    Assert.IsTrue(con.Value(s) >= 5);
                }
                if (s[(cClass == "fighter")])
                {
                    Assert.IsTrue(intel.Value(s) <= 8);
                }

                if (s[(cClass == "magic user")])
                {
                    Assert.IsTrue(str.Value(s) <= intel.Value(s));
                }
                if (s[(cClass == "magic user")])
                {
                    Assert.IsTrue(intel.Value(s) >= 5);
                }
                if (s[(cClass == "magic user")])
                {
                    Assert.IsTrue(str.Value(s) <= 8);
                }

                if (s[(cClass == "cleric")])
                {
                    Assert.IsTrue(wis.Value(s) >= 5);
                }
                if (s[(cClass == "cleric")])
                {
                    Assert.IsTrue(con.Value(s) <= wis.Value(s));
                }

                if (s[(cClass == "thief")])
                {
                    Assert.IsTrue(dex.Value(s) >= 5);
                }
                if (s[(cClass == "thief")])
                {
                    Assert.IsTrue(charisma.Value(s) >= 5);
                }
                if (s[(cClass == "thief")])
                {
                    Assert.IsTrue(wis.Value(s) <= 5);
                }
                if (s[(cClass == "thief")])
                {
                    Assert.IsTrue(dex.Value(s) >= str.Value(s));
                }
                if (s[(cClass == "thief")])
                {
                    Assert.IsTrue(charisma.Value(s) >= intel.Value(s));
                }

                Console.WriteLine(s.Model);
            }
        }
Exemple #10
0
        /// <summary>
        /// Add the information in the PCGToy file to the specified problem.
        /// </summary>
        /// <param name="path">File path</param>
        /// <param name="problem">Problem to add the contents to</param>
        /// <exception cref="FileFormatException">If the file is not a valid PCGToy file.</exception>
        public static void LoadFromFile(string path, Problem problem)
        {
            Dictionary <string, FDomain <object> >    domains   = new Dictionary <string, FDomain <object> >();
            Dictionary <string, FDVariable <object> > variables = new Dictionary <string, FDVariable <object> >();

            var f = System.IO.File.OpenText(path);

            while (f.Peek() >= 0)
            {
                var exp = SExpression.Read(f);
                if (!(exp is List <object> l) || l.Count == 0 || !(l[0] is string tag))
                {
                    throw new FileFormatException($"Unknown declaration {exp}");
                }

                switch (tag)
                {
                case "domain":
                    if (l.Count < 2 || !(l[1] is string domainName))
                    {
                        throw new FileFormatException("Malformed domain declaration");
                    }
                    if (l.Count < 3)
                    {
                        throw new FileFormatException($"Domain {domainName} has no elements");
                    }
                    var elements = l.Skip(2).ToArray();
                    domains[domainName] = new FDomain <object>(domainName, elements);
                    break;

                case "variable":
                    if (l.Count < 3 ||
                        l.Count > 4 ||
                        !(l[1] is string varName) ||
                        !(l[2] is string domain))
                    {
                        throw new FileFormatException("Malformed variable declaration");
                    }
                    if (!domains.ContainsKey(domain))
                    {
                        throw new FileFormatException(
                                  $"Unknown domain name: {domain} in declaration of variable {varName}");
                    }
                    Literal c = null;

                    if (l.Count == 4)
                    {
                        c = ConditionFromSExpression(l[3], variables);
                    }
                    var v = new FDVariable <object>(varName, domains[domain], c);
                    variables[varName] = v;
                    break;

                case "nogood":
                    problem.Inconsistent(l.Skip(1).Select(sexp => ConditionFromSExpression(sexp, variables)).ToArray());
                    break;

                default:
                    throw new FileFormatException($"Unknown declaraction {tag}");
                }
            }
        }
Exemple #11
0
        public void LoadFromFile(string path)
        {
            Domains.Clear();
            Variables.Clear();
            Nogoods.Clear();
            var f = System.IO.File.OpenText(path);

            while (f.Peek() >= 0)
            {
                var exp = SExpression.Read(f);
                if (!(exp is List <object> l) || l.Count == 0 || !(l[0] is string tag))
                {
                    throw new FileFormatException($"Unknown declaration {exp}");
                }
                else
                {
                    switch (tag)
                    {
                    case "domain":
                        if (l.Count < 2 || !(l[1] is string domainName))
                        {
                            throw new FileFormatException("Malformed domain declaration");
                        }
                        if (l.Count < 3)
                        {
                            throw new FileFormatException($"Domain {domainName} has no elements");
                        }
                        var elements = l.Skip(2).ToArray();
                        Domains[domainName] = new FDomain <object>(domainName, elements);
                        break;

                    case "variable":
                        if (l.Count < 3 ||
                            l.Count > 4 ||
                            !(l[1] is string varName) ||
                            !(l[2] is string domain))
                        {
                            throw new FileFormatException("Malformed variable declaration");
                        }
                        if (!Domains.ContainsKey(domain))
                        {
                            throw new FileFormatException(
                                      $"Unknown domain name: {domain} in declaration of variable {varName}");
                        }
                        Condition c = null;

                        if (l.Count == 4)
                        {
                            c = ConditionFromSExpression(l[3]);
                        }
                        Variables[varName] = new Variable(varName, this, domain, c);
                        break;

                    case "nogood":
                        Nogoods.Add(l.Skip(1).Select(ConditionFromSExpression).ToArray());
                        break;

                    default:
                        throw new FileFormatException($"Unknown declaraction {tag}");
                    }
                }
            }
            Changed();
            IsDirty = false;
        }
Exemple #12
0
 public void AddDomain(string domainName)
 {
     Domains[domainName] = new FDomain <object>(domainName);
     Changed();
 }
Exemple #13
0
        public IActionResult Atualizar(FDomain funcionario)
        {
            Frepository.Atualizar(funcionario);

            return(Ok());
        }
Exemple #14
0
        public IActionResult Cadastrar(FDomain funcionario)
        {
            Frepository.Cadastrar(funcionario);

            return(Ok());
        }