Example 2: Sale Form VB.NET Code - TOP10

Example 2: Sale Form VB.NET Code

Example 2: Sale Form




Source code 2: Sale form

Imports System
Imports System.Data.SqlClient
Imports System.Data

Public Class Sale
    Dim StringCn As String
    Dim cn As SqlConnection
    Dim cmd As SqlCommand
    Dim da As SqlDataAdapter
    Dim dr As SqlDataReader
    Dim dtSale As DataTable
    Dim rowindex As Int32

    Private Sub ToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ToolStrip1.ItemClicked

    End Sub

    Private Sub Sale_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        getItem_Code()
        SelelectData()
    End Sub
    Private Sub Clear()
        txtitemname.Clear()
        txtdescribe.Clear()
        txtqtysale.Clear()
        txtprice_in.Clear()
        txtsaleprice_us.Clear()
        txtsaleprice_riel.Clear()
        txtdiscount_rate.Clear()
    End Sub
    Private Sub Make_Connection()
        Try
            StringCn = "server=DELL-LV; uid=sa; pwd=Ds2014*;Database=POS_Data"
            cn = New SqlConnection(StringCn)
        Catch ex As Exception
        End Try
    End Sub

    Private Sub getItem_Code()
        Try
            Make_Connection()
            da = New SqlDataAdapter("SELECT Item_Name FROM tblSale_Record ", cn)
            cn.Open()
            dtSale = New DataTable()
            da.Fill(dtSale)
            Me.txtcode.Text = "DS-" & (dtSale.Rows.Count).ToString("0000")
        Catch ex As Exception
        End Try
        cn.Close()
    End Sub
    Private Sub SelelectData()
        Try
            da = New SqlDataAdapter("SELECT * FROM tblSale_Record", cn)
            dtSale = New DataTable()
            da.Fill(dtSale)
            ListView1.Items.Clear()
            For Each row As DataRow In dtSale.Rows
                Dim listItem As ListViewItem
                listItem = ListView1.Items.Add(row(0))
                For i As Int32 = 1 To dtSale.Columns.Count - 1
                    listItem.SubItems.Add(row(i))
                Next
            Next
        Catch exe As Exception
        End Try
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Try
            Make_Connection()
            getItem_Code()
            Dim Stt As Double
            Me.txtcode.Text = "DS-" & (dtSale.Rows.Count + 1).ToString("0000")
            Stt = Double.Parse(txtqtysale.Text) * Double.Parse(txtsaleprice_us.Text) - (Double.Parse(txtqtysale.Text) * Double.Parse(txtsaleprice_us.Text)) * Int32.Parse(txtdiscount_rate.Text) / 100
            cmd = New SqlCommand("INSERT INTO tblSale_Record (Item_Code, Item_Name,Describe, Sale_Quantiy, Price_Buy_In, Sale_Price_Us , Sale_Price_Riel, Discount, SubTotal_Price) VALUES ('" & txtcode.Text & "','" & txtitemname.Text & "','" & txtdescribe.Text & "','" & txtqtysale.Text & "','" & txtprice_in.Text & "','" & txtsaleprice_us.Text & "','" & txtsaleprice_riel.Text & "','" & txtdiscount_rate.Text & "','" & Stt & "')", cn)
            cn.Open()
            cmd.ExecuteNonQuery()
            SelelectData()
            Clear()
        Catch exe As Exception
        End Try
        cn.Close()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Clear()
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Me.Close()
    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        Try
            If ListView1.SelectedItems.Count > 0 Then
                txtcode.Text = ListView1.SelectedItems(0).Text
                txtitemname.Text = ListView1.SelectedItems(0).SubItems(1).Text
                txtdescribe.Text = ListView1.SelectedItems(0).SubItems(2).Text
                txtqtysale.Text = ListView1.SelectedItems(0).SubItems(3).Text
                txtprice_in.Text = ListView1.SelectedItems(0).SubItems(4).Text
                txtsaleprice_us.Text = ListView1.SelectedItems(0).SubItems(5).Text
                txtsaleprice_riel.Text = ListView1.SelectedItems(0).SubItems(6).Text
                txtdiscount_rate.Text = ListView1.SelectedItems(0).SubItems(7).Text
            End If
        Catch exe As Exception
        End Try
    End Sub

    Private Sub txtsaleprice_us_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsaleprice_us.TextChanged
        Try
            txtsaleprice_riel.Text = Double.Parse(txtsaleprice_us.Text) * 4200
        Catch exe As Exception
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Make_Connection()
            cmd = New SqlCommand("DELETE FROM tblSale_Record  WHERE Item_Code='" & txtcode.Text & "'", cn)
            cn.Open()
            cmd.ExecuteNonQuery()
            SelelectData()
            Clear()
        Catch exe As Exception
        End Try
        cn.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim Stt As Double
        Stt = Double.Parse(txtqtysale.Text) * Double.Parse(txtsaleprice_us.Text) - (Double.Parse(txtqtysale.Text) * Double.Parse(txtsaleprice_us.Text)) * Int32.Parse(txtdiscount_rate.Text) / 100
        cmd = New SqlCommand("UPDATE tblSale_Record SET  Item_Name='" & txtitemname.Text & "',Describe='" & txtdescribe.Text & "', Sale_Quantiy='" & txtqtysale.Text & "', Price_Buy_In='" & txtprice_in.Text & "',Sale_Price_Us='" & txtsaleprice_us.Text & "' ,Sale_Price_Riel='" & txtsaleprice_riel.Text & "' , Discount='" & txtdiscount_rate.Text & "', SubTotal_Price='" & Stt & "'  WHERE (Item_Code='" & txtcode.Text & "')", cn)
        cn.Open()
        cmd.ExecuteNonQuery()
        SelelectData()
        Clear()
        cn.Close()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Try
            Make_Connection()
            da = New SqlDataAdapter("SELECT * FROM tblSale_Record WHERE Item_Name LIKE '" & txtSearchItem_Name.Text & "%'", cn)
            cn.Open()
            dtSale = New DataTable()
            da.Fill(dtSale)
            ListView1.Items.Clear()
            For Each row As DataRow In dtSale.Rows
                Dim listItem As ListViewItem
                listItem = ListView1.Items.Add(row(0))
                For i As Int32 = 1 To dtSale.Columns.Count - 1
                    listItem.SubItems.Add(row(i))
                Next
                ListView1.CheckBoxes = True
                ListView1.Focus()
                ListView1.Items(0).Selected = True
                ListView1.Items(0).Checked = True
            Next
        Catch ex As Exception
        End Try
        cn.Close()
    End Sub

    Private Sub ListView1_ItemChecked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles ListView1.ItemChecked
        
    End Sub

    Private Sub ListView1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck
        
    End Sub

    Private Sub ListView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.Click
        
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Dim fr As frmReport
        fr = New frmReport()
        fr.Show()
    End Sub
End Class
Previous
Next Post »