Beispiel #1
0
        public static string CadProduto(ProdutoDTO obj)
        {
            if (string.IsNullOrWhiteSpace(obj.CodBarra))
            {
                throw new Exception("Campo, código de barra vazio");
            }
            if (obj.CodBarra.Length != 13)
            {
                throw new Exception("Campo, código de barra precisa conter 13 digito");
            }
            try
            {
                Int64.Parse(obj.CodBarra);
            }
            catch
            {
                throw new Exception("Código de Barra deve ser somente número");
            }
            if (string.IsNullOrWhiteSpace(obj.LoteProd))
            {
                throw new Exception("Campo, lote está vazio");
            }

            /* if (string.IsNullOrWhiteSpace(obj.ValProd))
             * {
             *   throw new Exception("Campo, validade está vazio");
             * }*/
            if (string.IsNullOrWhiteSpace(obj.NomeProd))
            {
                throw new Exception("Campo, produto está vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.DescProd))
            {
                throw new Exception("Campo, descrição está vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.QtdProd))
            {
                throw new Exception("Campo,quantidade está vazio");
            }
            try
            {
                Int64.Parse(obj.QtdProd);
            }
            catch
            {
                throw new Exception("Quantidade deve ser somente número");
            }
            if (string.IsNullOrWhiteSpace(obj.MedProd))
            {
                throw new Exception("Campo, Unidade está vazio");
            }

            if (string.IsNullOrWhiteSpace(obj.PrecoProd))
            {
                throw new Exception("Campo, preço está vazio");
            }
            return(ProdutoDAL.CadProduto(obj));
        }
Beispiel #2
0
        public static string CadProduto(ProdutoDTO 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 (obj.AcaoProd == "cadastro")
            {
                bool retorno = ProdutoDAL.ValidarCodBarras(obj.CodBarras);
                if (retorno == true)
                {
                    throw new Exception("Código de barras já esta em uso!");
                }
            }
            if (string.IsNullOrWhiteSpace(obj.NomeProd))
            {
                throw new Exception("Campo nome vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.DescProd))
            {
                throw new Exception("Campo descrição 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");
            }
            try
            {
                Convert.ToInt32(obj.UnidadeProd);
            }
            catch
            {
                throw new Exception("Estoque deve ser numérico!");
            }
            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(ProdutoDAL.CadProduto(obj));

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

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