Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 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 System.Data.SqlClient;
  11.  
  12. namespace POS_BUPO
  13. {
  14. public partial class frm_addproduct : Form
  15. {
  16. public frm_addproduct()
  17. {
  18. InitializeComponent();
  19. }
  20. Main viewmain = new Main();
  21. SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\SnowPrince\Desktop\POS_BUPO\POS_BUPO\Product.mdf;Integrated Security=True;Connect Timeout=30");
  22. private void btn_back1_Click(object sender, EventArgs e)
  23. {
  24. this.Close();
  25. viewmain.Show();
  26. }
  27.  
  28. private void button1_Click(object sender, EventArgs e)
  29. {
  30.  
  31.  
  32. if (txtAddCode.Text == "")
  33. {
  34. label5.Visible = true;
  35. }
  36. if(txtAddName.Text == "")
  37. {
  38. label6.Visible = true;
  39. }
  40. if(txtAddDes.Text == "")
  41. {
  42. label7.Visible = true;
  43. }
  44. if(txtAddPrice.Text == "")
  45. {
  46. label8.Visible = true;
  47. }
  48. else
  49. {
  50.  
  51.  
  52. conn.Open();
  53. SqlCommand cmd = new SqlCommand("INSERT INTO PData (ProductCode , ProductName , Description , Price) " +
  54. "VALUES (@ProductCode , @ProductName , @Description , @Price ) ", conn);
  55.  
  56. cmd.Parameters.AddWithValue("@ProductCode ", txtAddCode.Text);
  57. cmd.Parameters.AddWithValue("@ProductName ", txtAddName.Text);
  58. cmd.Parameters.AddWithValue("@Description ", txtAddDes.Text);
  59. cmd.Parameters.AddWithValue("@Price ", txtAddPrice.Text);
  60. cmd.ExecuteNonQuery();
  61.  
  62. conn.Close();
  63. MessageBox.Show("ทำการเก็บข้อมูลเสร็จสิ้น","Save Data",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
  64. txtAddCode.Clear();
  65. txtAddDes.Clear();
  66. txtAddName.Clear();
  67. txtAddPrice.Clear();
  68. conn.Close();
  69.  
  70. }
  71.  
  72. }
  73. private void button2_Click(object sender, EventArgs e)
  74. {
  75. txtAddCode.Clear();
  76. txtAddDes.Clear();
  77. txtAddName.Clear();
  78. txtAddPrice.Clear();
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement