Beispiel #1
0
 public static void BuscProduto(Cad_Produto_DTO obj)
 {
     try
     {
         string     sql = "SELECT * FROM tb_produto where nome = @nome and marca = @marca";
         SqlCommand cmd = new SqlCommand(sql, Conexao.Login());
         cmd.Parameters.AddWithValue("@nome", obj.NomeProduto);
         cmd.Parameters.AddWithValue("@marca", obj.Marca);
         SqlDataReader data = cmd.ExecuteReader();
         while (data.Read())
         {
             if (data.HasRows)
             {
                 obj.NomeProduto  = data["nome"].ToString();
                 obj.Descricao    = data["descricao"].ToString();
                 obj.Categoria    = data["categoria"].ToString();
                 obj.SubCategoria = data["subcategoria"].ToString();
                 obj.Marca        = data["marca"].ToString();
                 obj.Qtd          = data["qtd"].ToString();
             }
         }
     }
     catch
     {
         throw new Exception("Erro ao buscar o produto");
     }
     finally
     {
         if (Conexao.Login().State != ConnectionState.Closed)
         {
             Conexao.Login().Close();
         }
     }
 }
Beispiel #2
0
 public static string CadProduto(Cad_Produto_DTO obj)
 {
     try
     {
         string sql = "INSERT INTO tb_produto(nome,descricao,categoria,subcategoria,qtd,marca)" +
                      " VALUES (@nome,@descricao,@categoria,@subcategoria,@qtd,@marca)";
         SqlCommand cmd = new SqlCommand(sql, Conexao.Login());
         cmd.Parameters.AddWithValue("@nome", obj.NomeProduto);
         cmd.Parameters.AddWithValue("@descricao", obj.Descricao);
         cmd.Parameters.AddWithValue("@categoria", obj.Categoria);
         cmd.Parameters.AddWithValue("@subcategoria", obj.SubCategoria);
         cmd.Parameters.AddWithValue("@qtd", obj.Qtd);
         cmd.Parameters.AddWithValue("@marca", obj.Marca);
         cmd.ExecuteNonQuery();
         return("Produto Cadastrado com sucesso");
     }
     catch
     {
         throw new Exception("Erro ao cadastrar produto");
     }
     finally
     {
         if (Conexao.Login().State != ConnectionState.Closed)
         {
             Conexao.Login().Close();
         }
     }
 }
Beispiel #3
0
 public static string alterProduto(Cad_Produto_DTO obj, string nome, string marca)
 {
     try
     {
         string     sql = "update tb_produto set nome = @nome, descricao = @descricao,categoria = @categoria,subcategoria = @subcategoria, qtd = 10,marca = @marca where nome = @nome1 and marca = @marca1";
         SqlCommand cmd = new SqlCommand(sql, Conexao.Login());
         cmd.Parameters.AddWithValue("@nome", obj.NomeProduto);
         cmd.Parameters.AddWithValue("@descricao", obj.Descricao);
         cmd.Parameters.AddWithValue("@categoria", obj.Categoria);
         cmd.Parameters.AddWithValue("@subcategoria", obj.SubCategoria);
         cmd.Parameters.AddWithValue("@marca", obj.Marca);
         cmd.Parameters.AddWithValue("@qtd", obj.Qtd);
         cmd.Parameters.AddWithValue("@nome1", nome);
         cmd.Parameters.AddWithValue("@marca1", marca);
         cmd.ExecuteNonQuery();
         return("Produto alterado com sucesso");
     }
     catch
     {
         throw new Exception("Erro ao alterar dados do produto");
     }
     finally
     {
         if (Conexao.Login().State != ConnectionState.Closed)
         {
             Conexao.Login().Close();
         }
     }
 }
Beispiel #4
0
        public static string AlterProduto(Cad_Produto_DTO obj, string nome, string marca)
        {
            if (string.IsNullOrWhiteSpace(obj.NomeProduto))
            {
                throw new Exception("Campo nome vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.Descricao))
            {
                throw new Exception("Campo descrição vazio");
            }
            bool regEx = Regex.IsMatch(obj.Qtd, @"^\d");

            if (!regEx)
            {
                throw new Exception("Campo quantidade deve conter apenas números");
            }
            if (string.IsNullOrWhiteSpace(obj.Categoria))
            {
                throw new Exception("Campo categoria vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.SubCategoria))
            {
                throw new Exception("Campo sub-categoria vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.Marca))
            {
                throw new Exception("Campo marca vazio");
            }
            string msg = Cad_Produto_DAL.alterProduto(obj, nome, marca);

            return(msg);
        }
Beispiel #5
0
 public static void bucProduto(Cad_Produto_DTO obj)
 {
     if (string.IsNullOrWhiteSpace(obj.NomeProduto))
     {
         throw new Exception("Para buscar preencha o nome do produto!!");
     }
     if (string.IsNullOrWhiteSpace(obj.Marca))
     {
         throw new Exception("Para buscar preencha a marca do produto!!");
     }
     Cad_Produto_DAL.BuscProduto(obj);
 }
Beispiel #6
0
 private void btnCadProduto_Click(object sender, EventArgs e)
 {
     try
     {
         Cad_Produto_DTO obj = new Cad_Produto_DTO();
         obj.NomeProduto  = txtNomeProduto.Text.ToUpper();
         obj.Descricao    = txtDescricao.Text.ToUpper();
         obj.Categoria    = cbCategoria.SelectedItem.ToString();
         obj.Qtd          = txtQtd.Text;
         obj.SubCategoria = cbSubCategoria.SelectedItem.ToString();
         obj.Marca        = txtMarca.Text.ToUpper();
         string msg = Cad_Produto_BLL.CadProduto(obj);
         MessageBox.Show(msg, "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         limpar();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Beispiel #7
0
        public static string CadProduto(Cad_Produto_DTO obj)
        {
            if (string.IsNullOrWhiteSpace(obj.NomeProduto))
            {
                throw new Exception("Campo nome vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.Descricao))
            {
                throw new Exception("Campo descrição vazio");
            }
            bool regEx = Regex.IsMatch(obj.Qtd, @"^\d");

            if (!regEx)
            {
                throw new Exception("Campo quantidade deve conter apenas números");
            }
            if (string.IsNullOrWhiteSpace(obj.Categoria))
            {
                throw new Exception("Campo categoria vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.SubCategoria))
            {
                throw new Exception("Campo sub-categoria vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.Marca))
            {
                throw new Exception("Campo marca vazio");
            }
            bool result = Cad_Produto_DAL.VerifProduto(obj.NomeProduto, obj.Marca);

            if (result)
            {
                throw new Exception("Nome do produto e marca ja cadastrados\n se deseja altera-lo selecione na lista acima");
            }
            string msg = Cad_Produto_DAL.CadProduto(obj);

            return(msg);
        }
Beispiel #8
0
        private void panel3_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                Cad_Produto_DTO obj = new Cad_Produto_DTO();
                obj.NomeProduto = txtBuscNome.Text.ToUpper();
                obj.Marca       = txtBuscMarca.Text.ToUpper();
                Cad_Produto_BLL.bucProduto(obj);

                txtNomeProduto.Text = obj.NomeProduto;
                txtMarca.Text       = obj.Marca;
                int selectCat = 0;
                switch (obj.Categoria)
                {
                case "Bebida":
                    selectCat = 0;
                    break;

                case "Perecível":
                    selectCat = 1;
                    break;

                case "Não perecível":
                    selectCat = 2;
                    break;
                }
                cbCategoria.SelectedIndex = selectCat;
                int selectsubCat = 0;
                switch (obj.SubCategoria)
                {
                case "Bebida alcoolica":
                    selectsubCat = 0;
                    break;

                case "Bebida não alcoolica":
                    selectsubCat = 1;
                    break;

                case "Ingrediente":
                    selectsubCat = 2;
                    break;

                case "Carnes":
                    selectsubCat = 3;
                    break;

                case "Aperitivo":
                    selectsubCat = 4;
                    break;

                case "Sobremesa":
                    selectsubCat = 5;
                    break;

                case "Tempero":
                    selectsubCat = 6;
                    break;

                case "Pão":
                    selectsubCat = 7;
                    break;

                case "Frutos do mar":
                    selectsubCat = 8;
                    break;
                }
                cbSubCategoria.SelectedIndex = selectsubCat;
                txtDescricao.Text            = obj.Descricao;
                txtQtd.Text = obj.Qtd;
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }