public static DTO_Produtos BuscarProdutos(string codBarras)
 {
     if (string.IsNullOrWhiteSpace(codBarras))
     {
         throw new Exception("Digite o código de barras do produto!");
     }
     try
     {
         Convert.ToInt64(codBarras);
     }
     catch
     {
         throw new Exception("Código de barras deve ser numérico!");
     }
     if (codBarras.Length != 13)
     {
         throw new Exception("Código de barras deve ter 13 digitos!");
     }
     return(DAL_Produtos.BuscarProdutos(codBarras));
 }
示例#2
0
        public static string ValidarProdutos(DTO_Produtos ObjProduto)
        {
            try
            {
                double result;
                int    resultint;
                if (string.IsNullOrWhiteSpace(ObjProduto.codBarras))
                {
                    throw new Exception("Codigo Vazio");
                }
                else if (ObjProduto.codBarras.Length != 13 || !Int64.TryParse(ObjProduto.codBarras, out Int64 resultint64))
                {
                    throw new Exception("Codigo Invalido");
                }
                if (DAL_ValidarProduto.BuscarProduto(ObjProduto.codBarras))
                {
                    throw new Exception("Codigo já cadastrado");
                }
                if (string.IsNullOrWhiteSpace(ObjProduto.nome))
                {
                    throw new Exception("Nome Vazio");
                }

                if (string.IsNullOrWhiteSpace(ObjProduto.preco))
                {
                    throw new Exception("Preço Vazio");
                }
                if (!double.TryParse(ObjProduto.preco, out result))
                {
                    throw new Exception("Preço Invalido");
                }
                if (string.IsNullOrWhiteSpace(ObjProduto.estoque))
                {
                    throw new Exception("Estoque Vazio");
                }
                if (!int.TryParse(ObjProduto.estoque, out resultint))
                {
                    throw new Exception("Estoque Invalido");
                }
                if (string.IsNullOrWhiteSpace(ObjProduto.unidade))
                {
                    throw new Exception("Unidade Vazia");
                }
                if (!double.TryParse(ObjProduto.unidade, out result))
                {
                    throw new Exception("Unidade Invalida");
                }
                if (string.IsNullOrWhiteSpace(ObjProduto.tipo))
                {
                    throw new Exception("Tipo Vazio");
                }
                if (ObjProduto.valor)
                {
                    throw new Exception("Ativo Vazio");
                }

                if (string.IsNullOrWhiteSpace(ObjProduto.Imagem))
                {
                    throw new Exception("Adicione uma Imagem");
                }

                if (DAL_Produtos.CadastrarProduto(ObjProduto))
                {
                    return("Cadastro Realizado");
                }
                else
                {
                    return("Erro ao Cadastrar");
                }
            }
            catch (Exception ex) {
                return(ex.Message);
            }
        }
        public static string ValidarProdutos(DTO_Produtos obj)
        {
            if (string.IsNullOrWhiteSpace(obj.CodBarras))
            {
                throw new Exception("Campo código de barras vazio");
            }
            try
            {
                Convert.ToInt64(obj.CodBarras);
            }
            catch
            {
                throw new Exception("Código de barras deve ser numérico!");
            }
            if (obj.CodBarras.Length != 13)
            {
                throw new Exception("Código de barras deve ter 13 digitos!");
            }
            if (string.IsNullOrWhiteSpace(obj.NomeProd))
            {
                throw new Exception("Campo nome vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.PrecoProd))
            {
                throw new Exception("Campo preço vazio");
            }
            try
            {
                Convert.ToDouble(obj.PrecoProd);
            }
            catch
            {
                throw new Exception("Preço deve ser numérico!");
            }
            if (string.IsNullOrWhiteSpace(obj.EstoqueProd))
            {
                throw new Exception("Campo estoque vazio");
            }
            try
            {
                Convert.ToInt32(obj.EstoqueProd);
            }
            catch
            {
                throw new Exception("Estoque deve ser numérico!");
            }
            if (string.IsNullOrWhiteSpace(obj.UnidadeProd))
            {
                throw new Exception("Campo unidade vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.TipoUnidProd))
            {
                throw new Exception("Campo tipo vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.AtivoProd))
            {
                throw new Exception("Selecione se o produto está ativo ou inativo!");
            }
            switch (obj.AcaoProd)
            {
            case "cadastro":
                return(DAL_Produtos.CADProdutos(obj));

            //break;
            case "alteracao":
                return(DAL_Produtos.AlterarProduto(obj));

            default:
                throw new Exception("algo errado aconteceu!");
            }
        }