internal bool UpdateIngrediente(Ingredientes ingredientes)
        {
            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(sqlitecon))
                {
                    connection.Open();

                    string query = string.Format("UPDATE INGREDIENTES SET NOME = @NOME, CUSTO = @CUSTO, QUANTIDADE = @QUANTIDADE, GRANDEZA = @GRANDEZA WHERE ID = @ID");

                    using (SQLiteCommand cmd = new SQLiteCommand(query, connection))
                    {
                        cmd.Parameters.AddWithValue("@NOME", ingredientes.Nome);
                        cmd.Parameters.AddWithValue("@CUSTO", ingredientes.Custo);
                        cmd.Parameters.AddWithValue("@QUANTIDADE", ingredientes.Quantidade);
                        cmd.Parameters.AddWithValue("@GRANDEZA", ingredientes.Grandeza);
                        cmd.Parameters.AddWithValue("@ID", ingredientes.Id);

                        return(cmd.ExecuteNonQuery() > 0 ? true : false);
                    }
                }
            }
            catch (SQLiteException e)
            {
                throw;
            }
        }
        internal bool InsertIngrediente(Ingredientes ingredientes)
        {
            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(sqlitecon))
                {
                    connection.Open();

                    string query = string.Format("INSERT INTO INGREDIENTES (nome, custo, quantidade, grandeza) VALUES(@NOME, @CUSTO, @QUANTIDADE, @GRANDEZA)");

                    using (SQLiteCommand cmd = new SQLiteCommand(query, connection))
                    {
                        cmd.Parameters.AddWithValue("@NOME", ingredientes.Nome);
                        cmd.Parameters.AddWithValue("@CUSTO", ingredientes.Custo);
                        cmd.Parameters.AddWithValue("@QUANTIDADE", ingredientes.Quantidade);
                        cmd.Parameters.AddWithValue("@GRANDEZA", ingredientes.Grandeza);

                        return(cmd.ExecuteNonQuery() > 0 ? true : false);
                    }
                }
            }
            catch (SQLiteException e)
            {
                throw;
            }
        }
        internal string GetGrandezaIngrediente(Ingredientes ingredientes)
        {
            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(sqlitecon))
                {
                    connection.Open();

                    string query = string.Format("SELECT GRANDEZA FROM INGREDIENTES WHERE ID = @ID");

                    string retorno = null;

                    using (SQLiteCommand cmd = new SQLiteCommand(query, connection))
                    {
                        cmd.Parameters.AddWithValue("@ID", ingredientes.Id);

                        SQLiteDataReader dr = cmd.ExecuteReader();

                        while (dr.Read())
                        {
                            retorno = dr["GRANDEZA"].ToString();
                        }

                        return(retorno != null ? retorno : null);
                    }
                }
            }
            catch (SQLiteException e)
            {
                throw;
            }
        }
Exemplo n.º 4
0
 public string RetornaGrandezaIngrediente(Ingredientes ingredientes)
 {
     try
     {
         return(repositorioIngredientes.GetGrandezaIngrediente(ingredientes));
     }
     catch (Exception e)
     {
         throw;
     }
 }
Exemplo n.º 5
0
 public List <Ingredientes> ListarIngredientesId(Ingredientes ingredientes)
 {
     try
     {
         return(repositorioIngredientes.SelectIdIngredientes(ingredientes));
     }
     catch (Exception e)
     {
         throw;
     }
 }
Exemplo n.º 6
0
        public bool DeletarIngredientes(Ingredientes ingredientes)
        {
            try
            {
                bool retorno = false;

                if (repositorioIngredientes.GetIdIngrediente(ingredientes))
                {
                    retorno = repositorioIngredientes.DeleteIngrediente(ingredientes);
                }

                return(retorno);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Exemplo n.º 7
0
        public bool InserirIngrediente(Ingredientes ingredientes)
        {
            try
            {
                bool retorno = false;

                if (ValidaIngrediente(ingredientes))
                {
                    retorno = repositorioIngredientes.InsertIngrediente(ingredientes);
                }

                return(retorno);
            }
            catch (Exception e)
            {
                throw;
            }
        }
        internal List <Ingredientes> SelectIdIngredientes(Ingredientes ingredientes)
        {
            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(sqlitecon))
                {
                    connection.Open();

                    string query = string.Format("SELECT * FROM INGREDIENTES WHERE ID = @ID");

                    List <Ingredientes> retorno = new List <Ingredientes>();

                    using (SQLiteCommand cmd = new SQLiteCommand(query, connection))
                    {
                        cmd.Parameters.AddWithValue("@ID", ingredientes.Id);

                        SQLiteDataReader dr = cmd.ExecuteReader();

                        while (dr.Read())
                        {
                            Ingredientes aux = new Ingredientes()
                            {
                                Id         = Convert.ToInt32(dr["ID"]),
                                Nome       = dr["NOME"].ToString(),
                                Quantidade = Convert.ToDouble(dr["QUANTIDADE"]),
                                Grandeza   = dr["GRANDEZA"].ToString(),
                                Custo      = Convert.ToDouble(dr["CUSTO"])
                            };

                            retorno.Add(aux);
                        }

                        return(retorno.Count > 0 ? retorno : null);
                    }
                }
            }
            catch (SQLiteException e)
            {
                throw;
            }
        }
        internal bool GetIdIngrediente(Ingredientes ingredientes)
        {
            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(sqlitecon))
                {
                    connection.Open();

                    string query = string.Format("SELECT * FROM INGREDIENTES WHERE ID = @ID");

                    using (SQLiteCommand cmd = new SQLiteCommand(query, connection))
                    {
                        cmd.Parameters.AddWithValue("@ID", ingredientes.Id);

                        return(cmd.ExecuteNonQuery() > 0 ? true : false);
                    }
                }
            }
            catch (SQLiteException e)
            {
                throw;
            }
        }
Exemplo n.º 10
0
 private bool ValidaIngrediente(Ingredientes ingredientes)
 {
     if (ingredientes.Nome == null || ingredientes.Nome.Length > 255)
     {
         return(false);
     }
     else if (ingredientes.Custo <= 0)
     {
         return(false);
     }
     else if (ingredientes.Quantidade < 0)
     {
         return(false);
     }
     else if (ingredientes.Grandeza == null || ingredientes.Grandeza.Length > 255)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
        internal List <Ingredientes> GetIngredientes()
        {
            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(sqlitecon))
                {
                    connection.Open();

                    string query = string.Format("SELECT ID, NOME FROM INGREDIENTES");

                    List <Ingredientes> retorno = new List <Ingredientes>();

                    using (SQLiteCommand cmd = new SQLiteCommand(query, connection))
                    {
                        SQLiteDataReader dr = cmd.ExecuteReader();

                        while (dr.Read())
                        {
                            Ingredientes aux = new Ingredientes()
                            {
                                Id   = Convert.ToInt32(dr["ID"]),
                                Nome = dr["NOME"].ToString()
                            };

                            retorno.Add(aux);
                        }

                        return(retorno.Count > 0 ? retorno : null);
                    }
                }
            }
            catch (SQLiteException e)
            {
                throw;
            }
        }