មេរៀន VB.Net

    Sale Management System

MenuStip

Properties
+ Name= Sale Management System Or (Form1)
+ WindowState = Maximized
+ Text = Sale Management System
+ isMdiContainer = True
ComboBox

Properties
+ Select on form =>
+ font = kh freehand(unicode khmer)
$$=> For all name text box :
+ =>name= txtCode
name= txtName
name= txtPrice
name= txtStock
name= txtCategory

    Add Module

+ Write Code: in Module1

Module Module1
Public cn As SqlClient.SqlConnection
Sub makeConnection()
cn = New SqlClient.SqlConnection
cn.ConnectionString = “server=.;database=A2Exam;uid=sa;pwd=123”
cn.Open()
End Sub
Sub runSQL(ByVal sql As String)
Dim cmd As New SqlClient.SqlCommand(sql, cn)
cmd.ExecuteNonQuery()
cmd.Dispose()
cmd = Nothing
End Sub
Sub addCombo(ByVal SQL As String, ByVal cb As ComboBox)
Dim Cmd As New SqlClient.SqlCommand(SQL, cn)
Dim dr As SqlClient.SqlDataReader
dr = Cmd.ExecuteReader()
While dr.Read
cb.Items.Add(dr(0).ToString)
End While
dr.Close()
Cmd.Dispose()
Cmd = Nothing
End Sub
Sub addListView1(ByVal SQL As String, ByVal LV As ListView)
Dim Cmd As New SqlClient.SqlCommand(SQL, cn)
Dim dr As SqlClient.SqlDataReader = Cmd.ExecuteReader
LV.Columns.Clear()
LV.Items.Clear()
Dim i As Integer
For i = 0 To dr.FieldCount – 1
LV.Columns.Add(dr.GetName(i), CInt(LV.Width / dr.FieldCount))
Next
While dr.Read
With LV.Items.Add(dr(0).ToString)
For i = 1 To dr.FieldCount – 1
.SubItems.Add(dr(i).ToString)
Next
End With
End While
dr.Close()
Cmd.Dispose()
Cmd = Nothing
LV.View = View.Details
End Sub

Function sqlStr(ByVal s As String) As String
s = s.Replace(“‘”, “””)
Return “N'” & s & “‘”
End Function

Sub ClearForm(ByVal F As Form)
Dim c As Control
For Each c In F.Controls
If TypeOf c Is TextBox Then
c.Text = “”
End If
Next
End Sub
End Module
+ On form frmProductEntry =>(Onកត់ចូល, ចាកចេញ, និង form laod)

Public Class frmProductEntry

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SQL As String
SQL = “Insert Into product Values (” & sqlStr(txtCode.Text) & “,” & sqlStr(txtNAME.Text) & “,” & txtPrice.Text & “,” & txtStock.Text & “,” & sqlStr(txtCategory.Text) & “)”
Dim cmd As New SqlClient.SqlCommand(SQL, cn)
cmd.ExecuteNonQuery()
ClearForm(Me)
txtCode.Focus()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()

End Sub

Private Sub frmProductEntry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
addCombo(“select category from product”, Me.ComboBox1)

End Sub
End Class

+ នៅលើ form Laod = Sale Management System Or (Form1)

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
makeConnection()
End Sub

Private Sub ProductEntryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductEntryToolStripMenuItem.Click
frmProductEntry.Show()
frmProductEntry.MdiParent = Me

End Sub

Private Sub ProductListToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProductListToolStripMenuItem.Click
FrmProductList.Show()
FrmProductList.MdiParent = Me
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
End Class

ListView1

+ Write Code On Form Laod = (FrmProductList_Load) និង (Button ចាកចេញ)

Public Class FrmProductList

Private Sub FrmProductList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
addListView1(“Select * from Product”, Me.ListView1)
ComboBox1.Items.Add(“ALL”)
addCombo(“Select Category from Product Group By Category”, Me.ComboBox1)
ComboBox1.SelectedIndex = 0
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim sql As String = “Select * from Product”
If ComboBox1.SelectedIndex > 0 Then
sql = sql & ” Where Category=” & sqlStr(ComboBox1.Text)
End If
addListView1(sql, ListView1)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()

End Sub
End Class
សូមទាញយក File Word ដើម្បីអនុវត្តន័
SaleManagementSystem

One Response to មេរៀន VB.Net

  1. Pingback: សូមស្វាគមន៍មកកាន់គេហទំព័រខ្មែរឡូយ10

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s