Advertisement
Guest User

Untitled

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