Advertisement
jarufino

Untitled

Jun 3rd, 2018
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MySql.Data.MySqlClient;
  11.  
  12. namespace SistemaVendas
  13. {
  14. public partial class Caixa : Form
  15. {
  16. public Caixa()
  17. {
  18. InitializeComponent();
  19. }
  20. int precototal = 0;
  21. MySqlConnection con = new MySqlConnection("server=localhost; database=sistemacsharp; username=root; password=;");
  22.  
  23.  
  24. private void txtnumprod_KeyPress(object sender, KeyPressEventArgs e)
  25. {
  26. if(e.KeyChar==13)
  27. {
  28. txtquantidade.Enabled = true;
  29. txtquantidade.Focus();
  30. }
  31. }
  32.  
  33. private void txtquantidade_KeyPress(object sender, KeyPressEventArgs e)
  34. {
  35. try
  36. {
  37. string txt = "select *from produtos where id='" + txtnumprod.Text + "'";
  38. MySqlCommand cmd = new MySqlCommand(txtnumprod.Text, con);
  39. con.Open();
  40. MySqlDataReader r = cmd.ExecuteReader();
  41. while (r.Read())
  42. {
  43. int preco = int.Parse(txtquantidade.Text.ToString()) * int.Parse(r[4].ToString());
  44. precototal = preco;
  45. dataGridView1.Rows.Add(dataGridView1.RowCount, r[0], r[1], txtquantidade.Text.Trim(), r[4], preco);
  46. }
  47. lbltotalitens.Text = "" + (dataGridView1.RowCount - 1) + "";
  48. lbltotal.Text = "" + precototal + "";
  49. con.Close();
  50. }
  51. catch (Exception ee)
  52. {
  53. MessageBox.Show(ee.Message,"Este É Um Erro Vindo Do Banco de Dados");
  54. }
  55. txtnumprod.Focus();
  56. txtnumprod.Clear();
  57. txtquantidade.Enabled = false;
  58. txtquantidade.Clear();
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement