domingo, 20 de octubre de 2013

Control ListBox: Método de Burbuja - Visual Basic 2012

Public Class Form1

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        ListBox1.Items.Add(txtNumero.Text)
        txtNumero.Clear()
        txtNumero.Focus()
    End Sub

    Private Sub btnOrdenar_Click(sender As Object, e As EventArgs) Handles btnOrdenar.Click
        Dim Auxiliar As Integer
        For i = 0 To ListBox1.Items.Count - 1
            For j = 0 To ListBox1.Items.Count - 2
                If (ListBox1.Items.Item(j) > ListBox1.Items.Item(i)) Then
                    Auxiliar = ListBox1.Items.Item(j)
                    ListBox1.Items.Item(j) = ListBox1.Items.Item(i)
                    ListBox1.Items.Item(i) = Auxiliar
                End If
            Next
        Next
    End Sub
End Class




Video Tuturial - Método de Burbuja en Visual Basic 2012




jueves, 17 de octubre de 2013

Programación en N Capas

Implementación de la Base de Datos en Sql Server 2012 



Aplicación en N Capas - Visual C# 2012










Espero les guste. Gracias...

Calcular Datos en un DataGridview

Public Class Form1

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Dim i As Integer = DataGridView1.Rows.Count
        DataGridView1.Rows.Add()
        DataGridView1.Rows(i).Cells(0).Value = CInt(txtCodigo.Text)
        DataGridView1.Rows(i).Cells(1).Value = CStr(txtDescripcion.Text)
        DataGridView1.Rows(i).Cells(2).Value = CInt(txtCantidad.Text)
        DataGridView1.Rows(i).Cells(3).Value = CDec(txtPrecio.Text)
        DataGridView1.Rows(i).Cells(4).Value = Math.Round((CInt(txtCantidad.Text) * CDec(txtPrecio.Text)) * 0.2, 2) 'Aplicando descuento el 20%
        DataGridView1.Rows(i).Cells(5).Value = Math.Round((CInt(txtCantidad.Text) * CDec(txtPrecio.Text)) + CDec(DataGridView1.Rows(i).Cells(4).Value), 2)
        DataGridView1.ClearSelection()
        MostrarTotal()
    End Sub

    Private Sub btnEliminar_Click(sender As Object, e As EventArgs) Handles btnEliminar.Click

        If DataGridView1.Rows.Count > 0 Then
            Dim i As Integer = DataGridView1.CurrentRow.Index
            If (DataGridView1.Rows(DataGridView1.CurrentRow.Index).Selected = False) Then
                MsgBox("Seleccione Fila a Eliminar", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                DataGridView1.Rows.RemoveAt(i)
                MostrarTotal()
                MsgBox("Eliminado Correctamente", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Else
            MsgBox("No existen Elementos Ok.", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

    End Sub

    Private Sub MostrarTotal()
        Dim Total As Decimal
        For i = 0 To DataGridView1.Rows.Count - 1
            Total = Total + CDec(DataGridView1.Rows(i).Cells(5).Value)
        Next
        lblTotal.Text = CDec(Total)
    End Sub
End Class