Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace SistemaVendas
- {
- public partial class Caixa : Form
- {
- public Caixa()
- {
- InitializeComponent();
- }
- int precototal = 0;
- MySqlConnection con = new MySqlConnection("server=localhost; database=sistemacsharp; username=root; password=");
- private void txtnumprod_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == 13)
- {
- txtquantidade.Enabled = true;
- txtquantidade.Focus();
- }
- }
- private void txtquantidade_KeyPress(object sender, KeyPressEventArgs e)
- {
- try
- {
- string txt = "SELECT * FROM produtos WHERE ID = @NumProd";
- using (MySqlCommand cmd = new MySqlCommand(txt, con))
- {
- cmd.Parameters.AddWithValue("@NumProd", txtnumprod.Text);
- con.Open();
- using (MySqlDataReader r = cmd.ExecuteReader())
- {
- while (r.Read())
- {
- int preco = int.Parse(txtquantidade.Text.ToString()) * int.Parse(r[6].ToString());
- precototal = preco;
- dataGridView1.Rows.Insert(dataGridView1.RowCount, r[0], r[1], txtquantidade.Text.Trim(), r[6], preco);
- }
- lbltotalitens.Text = "" + (dataGridView1.RowCount - 1) + "";
- lbltotal.Text = "" + precototal + "";
- }
- }
- }
- catch (Exception ee)
- {
- MessageBox.Show(ee.Message, "Este É Um Erro Vindo Do Banco de Dados");
- }
- txtnumprod.Focus();
- txtnumprod.Clear();
- txtquantidade.Enabled = false;
- txtquantidade.Clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement