mantenimiento de cuentas ado.net.pdf

Upload: gregoriohdd

Post on 09-Jan-2016

2 views

Category:

Documents


0 download

TRANSCRIPT

  • CURSO: TALLER DE PROGRAMACION DISTRIBUIDA Instituto Cibernet Utcubamba El Amigo del Saber

    Docente del Curso:

    Gregorio Bautista Oblitas (Lic. Matemtica y Computacin, Magister en Educacion, Bachiller en Ingenieria de Sistemas e Informtica)

    HTTP://WWW.ISTPCIBERNET.COM/

    CONTENIDO DEL CURSO PROGRAMACION ORIENTADA A OBJETOS Los Objetos Diagramas de Clases Atributos Metodos

    lenguaje sql CREACION DE BASE DE DATOS CONSULTAS PROCEDIMIENTOS ALMACENADOS

    ADO. NET 4.5 SQLDataAdapter DataSet ConfigurationManager Using SqlComand Mantenimiento de Registros ExecuteScalar ExecuteNonQuery Datatable DataView Transacciones

    Linq to sql TablaAdapter LinQ LINQ to DataSet LINQ to Entities Consultas con LinQ DataContext

    PROGRAMACION EN N-CAPAS Programar en Capas

  • 1. Appp.config

  • 2. Importar System.config

  • 3. Diseo del Formulario para el mantenimiento de la tabla tbcliente

  • 4. Creamos un Mdulo que contendr las funciones a utilizar en el formulario

    5. Cdigo para el Modulo funcionescliente

    Module funcionescliente Function getCodigo() As String Return frmcliente.lblCodigo.Text End Function Function getNombres() As String Return frmcliente.txtNombres.Text End Function Function getApellidos() As String Return frmcliente.txtapellidos.Text End Function Function getSexo() As String Return frmcliente.cbosexo.SelectedText.ToString End Function Function getCelular() As String Return frmcliente.txtcelular.Text End Function

  • Function getDni() As String Return frmcliente.txtdni.Text End Function Function getDireccion() As String Return frmcliente.txtdireccion.Text End Function Sub llenarsexo() frmcliente.cbosexo.Items.Add("M") frmcliente.cbosexo.Items.Add("F") End Sub Function Valida() As String With frmcliente If Len(Trim(.txtNombres.Text)) = 0 Then Return "Nombre del Cliente" ElseIf .cbosexo.SelectedIndex = -1 Then Return "Sexo" ElseIf Len(Trim(.txtcelular.Text)) = 0 Then Return "Telefono del Cliente" ElseIf Len(Trim(.txtdni.Text)) = 0 Then Return "DNI del Cliente" ElseIf Len(Trim(.txtapellidos.Text)) = 0 Then Return "Apellidos del Cliente" ElseIf Len(Trim(.txtapellidos.Text)) = 0 Then Return "Direccion del Cliente"

  • Else Return "" End If End With End Function Sub limpiarControles() Dim misObjetos As Control For Each misObjetos In frmcliente.Controls If TypeOf misObjetos Is System.Windows.Forms.TextBox Then misObjetos.Text = "" End If Next frmcliente.txtNombres.Focus() frmcliente.cbosexo.SelectedIndex = -1 End Sub End Module

    6. Programacin del Formulario frmcliente

    Imports System.Data.SqlClient Imports System.Configuration Imports Microsoft Public Class frmcliente Sub autogeneraCodigo() Using cn As New SqlConnection(ConfigurationManager. ConnectionStrings("cn").ConnectionString) Using cmd As New SqlCommand cmd.Connection = cn

  • cmd.CommandType = CommandType.Text cmd.CommandText = "ultimocliente" cn.Open() lblCodigo.Text = "C" & (VisualBasic. _ Right(cmd.ExecuteScalar, 3) + 1).ToString("000") End Using End Using End Sub Sub registra() Using cn As New SqlConnection(ConfigurationManager. ConnectionStrings("cn").ConnectionString) Using cmd As New SqlCommand() cn.Open() cmd.Connection = cn cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "nuevocliente" With cmd.Parameters .Add("@codcliente", SqlDbType.Char).Value = funcionescliente.getCodigo() .Add("@nombre", SqlDbType.VarChar).Value = funcionescliente.getNombres() .Add("@apellidos", SqlDbType.Char).Value = funcionescliente.getApellidos() .Add("@sexo", SqlDbType.Char).Value = funcionescliente.getSexo() .Add("@dni", SqlDbType.VarChar).Value = funcionescliente.getDni() .Add("@direccion", SqlDbType.VarChar).Value = funcionescliente.getDireccion() .Add("@celular", SqlDbType.VarChar).Value = funcionescliente.getCelular() End With

  • cmd.ExecuteNonQuery() End Using End Using End Sub Private Sub btnRegistrar_Click(sender As Object, e As EventArgs) Handles btnRegistrar.Click Try If funcionescliente.Valida() = "" Then Call registra() Call autogeneraCodigo() MessageBox.Show("Pasajero registrado correctamente", "Mensaje", _ MessageBoxButtons.OK, MessageBoxIcon.Information) funcionescliente.limpiarControles() Else MessageBox.Show("Error en " + funcionescliente.Valida(), "Mensaje", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End If Catch ex As Exception MessageBox.Show("Error en " + ex.Message, "Mensaje", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub frmcliente_Load(sender As Object, e As EventArgs) Handles MyBase.Load funcionescliente.llenarsexo() autogeneraCodigo() End Sub End Class