viernes, 4 de abril de 2008

Tarifador Telefónico

Este es un simple Tarifador Telefónico, programado en Visual Basic.NET. En realidad no es tan complicado pero sirve para aprender a manejar algunos controles y a practicar el uso del condicional SELECT CASE.

Basicamente lo que hace es ingresar el número de minutos que ha hablado la persona, y mediante el uso del Select Case resolvemos las reglas del negocio sobre los planes tarifarios para llamadas a teléfonos fijos(local, nacional, internacional) o a celulares(puede ser a una MoviStar de Telefónica o a un celular Claro), tambien aplicable un plan tarifario según el ámbito de llamada(local, nacional, internacional).

El diseño quedaría algo así como el de la imagen; donde para mostrar el resultado utilizo un label(lblmonto) y el codigo es el siguiente:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
opttelfijo.Checked = True
cbotiposervicio.Items.Add("MoviStar")
cbotiposervicio.Items.Add("Claro")
cbollamada.Items.Add("Local")
cbollamada.Items.Add("Nacional")
cbollamada.Items.Add("Internacional")
cbotiposervicio.Enabled = False
End Sub

Private Sub opttelfijo_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opttelfijo.CheckedChanged
If opttelfijo.Checked = True Then
cbotiposervicio.Enabled = False
End If
End Sub

Private Sub optcel_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optcel.CheckedChanged
If optcel.Checked = True Then
cbotiposervicio.Enabled = True
End If
End Sub

Private Sub btnCalcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcular.Click
Dim minuto As Integer
Dim tarifa As Decimal
Dim monto As Decimal
minuto = Val(txtminuto.Text)
If opttelfijo.Checked = True Then
Select Case cbollamada.Text
Case "Local"
tarifa = 0.2
Case "Nacional"
tarifa = 0.5
Case "Internacional"
tarifa = 1.5
Case Else
MsgBox("Seleccione por favor el tipo de llamada")
cbollamada.Focus()
Exit Sub
End Select
End If
If optcel.Checked = True Then
Select Case cbotiposervicio.Text
Case "MoviStar"
Select Case cbollamada.Text
Case "Local"
tarifa = 0.6
Case "Nacional"
tarifa = 1.0
Case "Internacional"
tarifa = 2.5
Case Else
MsgBox("Seleccione por favor el tipo de llamada")
cbollamada.Focus()
Exit Sub
End Select
Case "Claro"
Select Case cbollamada.Text
Case "Local"
tarifa = 0.8
Case "Nacional"
tarifa = 1.5
Case "Internacional"
tarifa = 4.5
Case Else
MsgBox("Seleccione por favor el tipo de llamada")
cbollamada.Focus()
Exit Sub
End Select
Case Else
MsgBox("Seleccione por favor el tipo de servicio")
cbotiposervicio.Focus()
End Select
End If
monto = minuto * tarifa
lblmonto.Text = "S/. " & monto.ToString
End Sub

Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
txtminuto.Text = ""
lblmonto.Text = ""
cbotiposervicio.SelectedItem = -1
cbollamada.SelectedItem = -1
opttelfijo.Checked = True
cbotiposervicio.Enabled = False
End Sub
End Class

No hay comentarios: