private void Txt_id_produto_KeyPress(object sender, KeyPressEventArgs e) { if (Txt_id_produto.Text != "") { if ((e.KeyChar == Convert.ToChar(Keys.Enter)) || (e.KeyChar == Convert.ToChar(Keys.Tab))) { SqlConnection conexao = new SqlConnection { ConnectionString = Properties.Settings.Default.conexao }; SqlCommand comando = new SqlCommand { CommandType = CommandType.Text, CommandText = "select Produtos.id, Produtos.nome, Produtos.imagem, Estoque.preco_venda from Produtos inner join Estoque on Produtos.id = Estoque.id_produto where Produtos.id = @id" }; comando.Connection = conexao; conexao.Open(); try { comando.Parameters.Add("@id", SqlDbType.Int).Value = Txt_id_produto.Text; SqlDataReader dr; dr = comando.ExecuteReader(); while (dr.Read()) { Txt_nome_produto.Text = Convert.ToString(dr["nome"]); Txt_valor_produto.Text = Convert.ToString(dr["preco_venda"]); MemoryStream mstream = new MemoryStream((byte[])(dr["imagem"])); Pic_imagem_produto.Image = Image.FromStream(mstream); Pic_imagem_produto.Refresh(); } conexao.Close(); Txt_quantidade_compra.Text = "1"; Txt_quantidade_compra.Focus(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void Btn_Adcionar_Click(object sender, EventArgs e) { if (Txt_nome_produto.Text != "") { Dgv_produtos_vendas.Rows.Add(Txt_id_produto.Text, Txt_nome_produto.Text, Txt_quantidade_compra.Text, Txt_valor_produto.Text, Lbl_total.Text); Txt_id_produto.Text = ""; Txt_nome_produto.Text = ""; Txt_quantidade_compra.Text = ""; Txt_valor_produto.Text = ""; Lbl_total.Text = "TOTAL:"; Pic_imagem_produto.Image = null; Pic_imagem_produto.Refresh(); Txt_id_produto.Focus(); TotalCompra(); Txt_valor_pago.Text = Txt_total_pagar.Text; } else { MessageBox.Show("Inválido ! Selecione um Produto !"); } }