Advertisement
karnnarock

formmain

Nov 14th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class FormMain
  2.  
  3.  
  4.     Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles BTN_ADD.Click
  5.  
  6.         If productid.Text = "" Then
  7.             MsgBox("กรุณากรอกรหัสสินค้า", MsgBoxStyle.Critical)
  8.             Exit Sub
  9.         End If
  10.         If productname.Text = "" Then
  11.             MsgBox("กรุณากรอกชื่อสินค้า", MsgBoxStyle.Critical)
  12.             Exit Sub
  13.         End If
  14.         If productprice.Text = "" Then
  15.             MsgBox("กรุณากรอกราคาสินค้า", MsgBoxStyle.Critical)
  16.             Exit Sub
  17.         End If
  18.         If productqty.Text = "" Then
  19.             MsgBox("กรุณากรอกจำนวนคงเหลือสินค้า", MsgBoxStyle.Critical)
  20.             Exit Sub
  21.         End If
  22.         If producttype.Text = "" Then
  23.             MsgBox("กรุณากรอกหมวดสินค้า", MsgBoxStyle.Critical)
  24.             Exit Sub
  25.         End If
  26.         If productunit.Text = "" Then
  27.             MsgBox("กรุณากรอกหน่วยนับสินค้า", MsgBoxStyle.Critical)
  28.             Exit Sub
  29.         End If
  30.  
  31.         Dim Checkdata As DataTable = executesql("SELECT Product_ID FROM TBL where Product_ID= '" & productid.Text & "'")
  32.         If checkdata.rows.count > 0 Then
  33.             MsgBox("มีรหัสสินค้าซ้ำ", MsgBoxStyle.Critical)
  34.             Exit Sub
  35.         End If
  36.  
  37.         executesql("INSERT INTO TBL(Product_ID,Product_Name,Product_Price,Product_Qty,Product_Type,Product_Unit)VALUES ('" & productid.Text & "','" & productname.Text & "','" & productprice.Text & "','" & productqty.Text & "','" & producttype.Text & "','" & productunit.Text & "')")
  38.         MsgBox("บันทึกข้อมูลเรียบร้อยแล้วจ้า", MsgBoxStyle.Information)
  39.         productid.Clear()
  40.         productname.Clear()
  41.         productprice.Clear()
  42.         productqty.Clear()
  43.         producttype.Clear()
  44.         productunit.Clear()
  45.  
  46.         loaddatatable()
  47.  
  48.     End Sub
  49.  
  50.     Sub loaddatatable()
  51.         Dim LOADDATA As DataTable = executesql("SELECT * FROM TBL")
  52.         DataGridView1.DataSource = LOADDATA
  53.         DataGridView1.Columns(0).HeaderText = "รหัสสินค้า"
  54.         DataGridView1.Columns(1).HeaderText = "ชื่อสินค้า"
  55.         DataGridView1.Columns(2).HeaderText = "ราคาสินค้า"
  56.         DataGridView1.Columns(3).HeaderText = "คงเหลือสินค้า"
  57.         DataGridView1.Columns(4).HeaderText = "หมวดสินค้า"
  58.         DataGridView1.Columns(5).HeaderText = "หน่วยนับสินค้า"
  59.     End Sub
  60.  
  61.     Private Sub productid_KeyPress(sender As Object, e As KeyPressEventArgs) Handles productid.KeyPress
  62.         Select Case Asc(e.KeyChar)
  63.             Case 48 To 57 ' key โค๊ด ของตัวเลขจะอยู่ระหว่าง48-57ครับ 48คือเลข0 57คือเลข9ตามลำดับ
  64.                e.Handled = False
  65.             Case 8, 13, 46 ' ปุ่ม Backspace = 8,ปุ่ม Enter = 13, ปุ่มDelete = 46
  66.                e.Handled = False
  67.  
  68.             Case Else
  69.                 e.Handled = True
  70.                 MessageBox.Show("ใส่ตัวเลขเท่านั้น !!")
  71.         End Select
  72.     End Sub
  73.  
  74.  
  75.     Private Sub productid_TextChanged(sender As Object, e As EventArgs) Handles productid.TextChanged
  76.  
  77.     End Sub
  78.  
  79.     Private Sub productprice_KeyPress(sender As Object, e As KeyPressEventArgs) Handles productprice.KeyPress
  80.         Select Case Asc(e.KeyChar)
  81.             Case 48 To 57 ' key โค๊ด ของตัวเลขจะอยู่ระหว่าง48-57ครับ 48คือเลข0 57คือเลข9ตามลำดับ
  82.                e.Handled = False
  83.             Case 8, 13, 46 ' ปุ่ม Backspace = 8,ปุ่ม Enter = 13, ปุ่มDelete = 46
  84.                e.Handled = False
  85.  
  86.             Case Else
  87.                 e.Handled = True
  88.                 MessageBox.Show("ใส่ตัวเลขเท่านั้น !!")
  89.         End Select
  90.     End Sub
  91.  
  92.     Private Sub productprice_TextChanged(sender As Object, e As EventArgs) Handles productprice.TextChanged
  93.  
  94.     End Sub
  95.  
  96.     Private Sub productqty_KeyPress(sender As Object, e As KeyPressEventArgs) Handles productqty.KeyPress
  97.         Select Case Asc(e.KeyChar)
  98.             Case 48 To 57 ' key โค๊ด ของตัวเลขจะอยู่ระหว่าง48-57ครับ 48คือเลข0 57คือเลข9ตามลำดับ
  99.                e.Handled = False
  100.             Case 8, 13, 46 ' ปุ่ม Backspace = 8,ปุ่ม Enter = 13, ปุ่มDelete = 46
  101.                e.Handled = False
  102.  
  103.             Case Else
  104.                 e.Handled = True
  105.                 MessageBox.Show("ใส่ตัวเลขเท่านั้น !!")
  106.         End Select
  107.     End Sub
  108.  
  109.     Private Sub productqty_TextChanged(sender As Object, e As EventArgs) Handles productqty.TextChanged
  110.  
  111.     End Sub
  112.  
  113.     Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter
  114.  
  115.     End Sub
  116.  
  117.     Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  118.         loaddatatable()
  119.         DataGridView1.Columns(2).DefaultCellStyle.Format = "N2"
  120.  
  121.     End Sub
  122.  
  123.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  124.         executesql("DELETE FROM TBL WHERE PRODUCT_ID='" & DataGridView1.CurrentRow.Cells(0).Value & "'")
  125.         MsgBox("ลบข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
  126.         loaddatatable()
  127.  
  128.     End Sub
  129.  
  130.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  131.         If productid.Text = "" Then
  132.             MsgBox("กรุณากรอกรหัสสินค้า", MsgBoxStyle.Critical)
  133.             Exit Sub
  134.         End If
  135.         If productname.Text = "" Then
  136.             MsgBox("กรุณากรอกชื่อสินค้า", MsgBoxStyle.Critical)
  137.             Exit Sub
  138.         End If
  139.         If productprice.Text = "" Then
  140.             MsgBox("กรุณากรอกราคาสินค้า", MsgBoxStyle.Critical)
  141.             Exit Sub
  142.         End If
  143.         If productqty.Text = "" Then
  144.             MsgBox("กรุณากรอกจำนวนคงเหลือสินค้า", MsgBoxStyle.Critical)
  145.             Exit Sub
  146.         End If
  147.         If producttype.Text = "" Then
  148.             MsgBox("กรุณากรอกหมวดสินค้า", MsgBoxStyle.Critical)
  149.             Exit Sub
  150.         End If
  151.         If productunit.Text = "" Then
  152.             MsgBox("กรุณากรอกหน่วยนับสินค้า", MsgBoxStyle.Critical)
  153.             Exit Sub
  154.         End If
  155.  
  156.         executesql("UPDATE TBL SET PRODUCT_NAME ='" & productname.Text & "',PRODUCT_PRICE ='" & productprice.Text & "',PRODUCT_QTY ='" & productqty.Text & "',PRODUCT_TYPE ='" & producttype.Text & "',PRODUCT_UNIT='" & productunit.Text & "'WHERE PRODUCT_ID ='" & productid.Text & "'")
  157.  
  158.         productid.Clear()
  159.         productname.Clear()
  160.         productprice.Clear()
  161.         productqty.Clear()
  162.         producttype.Clear()
  163.         productunit.Clear()
  164.         MsgBox("แก้ไขข้อมูลเรียบร้อย", MsgBoxStyle.Information)
  165.  
  166.         loaddatatable()
  167.     End Sub
  168.  
  169.     Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  170.         productid.Text = DataGridView1.CurrentRow.Cells(0).Value
  171.         productname.Text = DataGridView1.CurrentRow.Cells(1).Value
  172.         productprice.Text = DataGridView1.CurrentRow.Cells(2).Value
  173.  
  174.         productprice.Text = CDbl(productprice.Text).ToString("##,##0.00")
  175.  
  176.         productqty.Text = DataGridView1.CurrentRow.Cells(3).Value
  177.         producttype.Text = DataGridView1.CurrentRow.Cells(4).Value
  178.         productunit.Text = DataGridView1.CurrentRow.Cells(5).Value
  179.     End Sub
  180.  
  181.     Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
  182.        
  183.     End Sub
  184.  
  185.     Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  186.         productid.Clear()
  187.         productname.Clear()
  188.         productprice.Clear()
  189.         productqty.Clear()
  190.         producttype.Clear()
  191.         productunit.Clear()
  192.         MsgBox("เคีลยร์", MsgBoxStyle.Information)
  193.     End Sub
  194.  
  195.     Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  196.         Form3.ShowDialog()
  197.  
  198.     End Sub
  199. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement