Advertisement
jarufino

Untitled

Jun 8th, 2018
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 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. {
  36. txtnumprod.Clear();
  37. txtquantidade.Clear();
  38. try
  39. {
  40. string txt = "SELECT * FROM produtos WHERE ID='" + txtnumprod + "'";
  41. MySqlCommand cmd = new MySqlCommand(txt, con);
  42. con.Open();
  43. MySqlDataReader r = cmd.ExecuteReader();
  44. while (r.Read())
  45. {
  46. int preco = int.Parse(txtquantidade.Text.ToString()) * int.Parse(r[6].ToString());
  47. precototal = preco;
  48. dataGridView1.Rows.Insert(dataGridView1.RowCount, r[0], r[1], txtquantidade.Text.Trim(), r[6], preco);
  49. }
  50. lbltotalitens.Text = "" + (dataGridView1.RowCount - 1) + "";
  51. lbltotal.Text = "" + precototal + "";
  52. con.Close();
  53. }
  54. catch (Exception ee)
  55. {
  56. MessageBox.Show(ee.Message,"Este É Um Erro Vindo Do Banco de Dados");
  57. }
  58. txtnumprod.Focus();
  59. txtnumprod.Clear();
  60. txtquantidade.Enabled = false;
  61. txtquantidade.Clear();
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement