Example #1
0
        public List <Entity.Praca> ConsultarPraca()
        {
            List <Entity.Praca> response = null;

            using (SqlHelper msh = new SqlHelper())
            {
                var sqlCommand = new SQLiteCommand("SELECT * FROM Praca");

                using (SQLiteDataReader dr = msh.ExecuteReader(sqlCommand))
                {
                    if (dr.HasRows)
                    {
                        response = new List <Entity.Praca>();
                        while (dr.Read())
                        {
                            Entity.Praca item = new Entity.Praca()
                            {
                                Id   = SqlDataTypes.DBInt32(dr["Id"]),
                                Nome = SqlDataTypes.DBString(dr["Nome"])
                            };

                            response.Add(item);
                        }
                    }
                }
            }
            return(response);
        }
Example #2
0
        public List <Entity.Operador> ConsultarOperadores(decimal?percentual, string nome)
        {
            List <Entity.Operador> response = null;

            using (SqlHelper msh = new SqlHelper())
            {
                var queryBase = "SELECT * FROM Operator" +
                                "inner join Praca pr" +
                                "on pr.ID = Praca" +
                                "WHERE 1 = 1";
                var clausulaPercentual = string.Empty;
                var clausulaNome       = string.Empty;

                var sqlCommand = new SQLiteCommand();

                if (percentual.HasValue)
                {
                    sqlCommand.Parameters.AddWithValue("percentual", percentual);
                    clausulaPercentual = " AND Percentual = @percentual";
                }

                if (!string.IsNullOrEmpty(nome))
                {
                    sqlCommand.Parameters.AddWithValue("percentual", percentual);
                    clausulaNome = " AND Nome LIKE @nome";
                }

                sqlCommand.CommandText = string.Concat(queryBase, clausulaPercentual, clausulaNome);

                using (SQLiteDataReader dr = msh.ExecuteReader(sqlCommand))
                {
                    if (dr.HasRows)
                    {
                        response = new List <Entity.Operador>();
                        while (dr.Read())
                        {
                            Entity.Operador item = new Entity.Operador()
                            {
                                Id         = SqlDataTypes.DBInt32(dr["Id"]),
                                Nome       = SqlDataTypes.DBString(dr["Nome"]),
                                Ativo      = SqlDataTypes.DBBoolean(dr["Ativo"]),
                                Limite     = SqlDataTypes.DBDecimal(dr["Limite"]),
                                Percentual = SqlDataTypes.DBDecimal(dr["Percentual"])
                            };

                            item.Praca = SqlDataTypes.DBString(dr["pr.Nome"]);

                            response.Add(item);
                        }
                    }
                }
            }

            return(response);
        }