public static Produto BuscaProduto(int codProduto)
        {
            using (SqlConnection sqlConn =
                        new SqlConnection(ConnString))
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Parameters.AddWithValue("Id", codProduto);
                    sqlCommand.CommandText = "select * from produtos where Id = @Id";
                    sqlCommand.Connection = sqlConn;
                    sqlConn.Open();
                    SqlDataReader dataReader;
                    dataReader = sqlCommand.ExecuteReader();

                    if (dataReader.Read())
                    {
                        Produto prod = new Produto(int.Parse(dataReader[0].ToString()),
                                                dataReader[1].ToString(),
                                                dataReader[2].ToString(),
                                                dataReader[3].ToString(),
                                                int.Parse(dataReader[4].ToString()),
                                                float.Parse(dataReader[5].ToString()),
                                                float.Parse(dataReader[6].ToString()),
                                                dataReader[7].ToString());
                        return prod;
                    }
                    return null;
                }
            }
        }
        public static Produto AlterarProduto(int id, string nome, string fornecedor, float p1, float p2, string desc,int qtd)
        {
            using (SqlConnection sqlConn =
                        new SqlConnection(ConnString))
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.CommandText = "update produtos set NomeProduto = '" +nome+ "',"
                                                                + " Fornecedor = '" +fornecedor+ "',"
                                                                + " PrecoCompra = " +p1+ ","
                                                                + " PrecoVenda = " +p2+ ","
                                                                + " QtdEstoque = " + qtd + ","
                                                                + " Descricao = '" +desc+ "'"
                                                                + " where Id = " +id;
                    sqlCommand.Connection = sqlConn;
                    sqlConn.Open();

                    if (sqlCommand.ExecuteNonQuery() > 0)
                    {
                        sqlCommand.Parameters.AddWithValue("Id", id);
                        sqlCommand.CommandText = "select * from produtos where Id = @Id";
                        SqlDataReader dataReader;
                        dataReader = sqlCommand.ExecuteReader();
                        if (dataReader.Read())
                        {
                            Produto prod = new Produto(int.Parse(dataReader[0].ToString()),
                                                    dataReader[1].ToString(),
                                                    dataReader[2].ToString(),
                                                    dataReader[3].ToString(),
                                                    int.Parse(dataReader[4].ToString()),
                                                    float.Parse(dataReader[5].ToString()),
                                                    float.Parse(dataReader[6].ToString()),
                                                    dataReader[7].ToString());
                            sqlConn.Close();
                            return prod;
                        }
                    }
                    sqlConn.Close();
                    return null;
                }
            }
        }
 public ItenVenda(Produto p, int qtd)
 {
     Produto = p;
     Qtd = qtd;
 }
        public static Produto InserirProduto(string nome, string fornecedor, float p1, float p2, string desc,int qtd, string val)
        {
            using (SqlConnection sqlConn =
                        new SqlConnection(ConnString))
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Parameters.AddWithValue("nome", nome);
                    sqlCommand.Parameters.AddWithValue("fornecedor", fornecedor);
                    sqlCommand.Parameters.AddWithValue("precoCompra", p1);
                    sqlCommand.Parameters.AddWithValue("precoVenda", p1);
                    sqlCommand.Parameters.AddWithValue("desc", desc);
                    sqlCommand.Parameters.AddWithValue("qtd", qtd);
                    sqlCommand.Parameters.AddWithValue("val", val);
                    sqlCommand.CommandText = "insert into produtos values (@desc,@fornecedor,@val,@qtd,@precoCompra,@precoVenda,@nome)";
                    sqlCommand.Connection = sqlConn;
                    sqlConn.Open();

                    if (sqlCommand.ExecuteNonQuery() > 0)
                    {
                        sqlCommand.CommandText = "select * from produtos order by Id desc";
                        SqlDataReader dataReader;
                        dataReader = sqlCommand.ExecuteReader();
                        if (dataReader.Read())
                        {
                            Produto prod = new Produto(int.Parse(dataReader[0].ToString()),
                                                dataReader[1].ToString(),
                                                dataReader[2].ToString(),
                                                dataReader[3].ToString(),
                                                int.Parse(dataReader[4].ToString()),
                                                float.Parse(dataReader[5].ToString()),
                                                float.Parse(dataReader[6].ToString()),
                                                dataReader[7].ToString());
                            sqlConn.Close();
                            return prod;
                        }
                    }
                    sqlConn.Close();
                    return null;
                }
            }
        }
        public static Produto RemoverProduto(Produto prod)
        {
            using (SqlConnection sqlConn =
                        new SqlConnection(ConnString))
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Parameters.AddWithValue("id", prod.Cod);
                    sqlCommand.CommandText = "delete from produtos where Id = @id";
                    sqlCommand.Connection = sqlConn;
                    sqlConn.Open();

                    if (sqlCommand.ExecuteNonQuery() > 0)
                    {
                        return prod;
                    }
                    sqlConn.Close();
                    return null;
                }
            }
        }