UML:Diagramas de Secuencia , si se hacen efectivos¡¡¡ – Aplicación en 3 Capas

Diagrama de Secuencia

El Otro dia me encargaron hacer un demo y hacer efectivo el analisis (cosa que no siempre se hace) pero Aqui el diagrama y poder hacerlo efectivo

primero nuestra clasica Aplicacíon en 3 capas

image

Nuestra Pantalla:

image

En Nuestro formulario:

PrestamoNegocios prestamoNeg = new PrestamoNegocios();
SocioNegocios socioNeg = new SocioNegocios();
LibroNegocios libroNeg = new LibroNegocios();

     private void btnPrestar_Click(object sender, EventArgs e)
        {
            Prestamo prestamo = new Prestamo();
            Socio socio = new Socio(3, this.txtSocio.Text.Trim());
            Libro libro = new Libro(1,this.txtLibro.Text.Trim());        
            prestamo.LibroID = libro.LibroID;
            prestamo.SocioID = socio.SocioID;           
            prestamo.Fecha = DateTime.Now;           
            libro.Descripcion = this.txtLibro.Text;
            if (socioNeg.verificarSocio(socio))
            {
                if (libroNeg.verificarLibro(libro))
                {
                    if (prestamoNeg.registrarPrestamo(prestamo, libro, socio))
                    {
                        MessageBox.Show(“Se Registro Prestamo”);
                    }
                    else
                    {
                        MessageBox.Show(“No se puede registrar el prestamo”);
                    }
                }
                else
                {
                    MessageBox.Show(“No se puede verificar libro”);
                }               
            }
            else
            {
                MessageBox.Show(“No se puede verificar socio”);
            }
        }

En Nuestra Capa de Negocios:

public class LibroNegocios
{
    public bool verificarLibro(Libro libro)
    {
        return new LibroDatos().verificarLibro(libro);
    }
}

public class PrestamoNegocios
{
    public bool registrarPrestamo(Prestamo prestamo,Libro libro,Socio socio)
    {
        return new PrestamosDatos().registrarPrestamo(prestamo);                    
    }
}

public class SocioNegocios
{
    public bool verificarSocio(Socio socio)
    {
        return new SistemaPrestamos.Datos.SocioDatos().verificarSocio(socio);
    }
}

En Nuestra Capa de Datos:

public class LibroDatos
{
    public bool verificarLibro(Libro libro)
    {
        DataSet ds = new DataSet();
        SqlConnection conexion = new SqlConnection(“Data Source=.;Initial Catalog=Prestamos;Integrated Security=SSPI”);
        SqlCommand comando = new SqlCommand(“verificarLibro”, conexion);
        comando.CommandType = CommandType.StoredProcedure;
        comando.Parameters.Add(“Descripcion”, SqlDbType.VarChar, 50);
        comando.Parameters["Descripcion"].Value = libro.Descripcion;           
        SqlDataAdapter adap = new SqlDataAdapter(comando);
        conexion.Open();
        adap.Fill(ds);           
        conexion.Close();
        conexion.Dispose();
        if(ds.Tables[0].Rows.Count > 0)
        {
            return true;
        }
        return false;
    }
}

public class PrestamosDatos
    {
        public bool registrarPrestamo(Prestamo prestamo)
        {
            SqlConnection conexion = new SqlConnection(“Data Source=.;Initial Catalog=Prestamos;Integrated Security=SSPI”);
            SqlCommand comando = new SqlCommand(“registrarPrestamo”, conexion);
            comando.CommandType = CommandType.StoredProcedure;
            comando.Parameters.Add(“LibroID”, SqlDbType.Int);           
            comando.Parameters.Add(“SocioID”, SqlDbType.Int);
            comando.Parameters.Add(“Fecha”, SqlDbType.DateTime);
            comando.Parameters["LibroID"].Value = prestamo.LibroID;           
            comando.Parameters["SocioID"].Value = prestamo.SocioID;
            comando.Parameters["Fecha"].Value = prestamo.Fecha;
            conexion.Open();
            int resultado = comando.ExecuteNonQuery();
            conexion.Close();
            conexion.Dispose();
            if(resultado>0)
            {
                return true;
            }
            return false;
        }
    }

public class SocioDatos
    {
        public bool verificarSocio(Socio socio)
        {
            DataSet ds = new DataSet();           
            SqlConnection conexion = new SqlConnection(“Data Source=.;Initial Catalog=Prestamos;Integrated Security=SSPI”);
            SqlCommand comando = new SqlCommand(“verificarSocio”, conexion);
            comando.CommandType = CommandType.StoredProcedure;
            comando.Parameters.Add(“Socio”, SqlDbType.Char, 50);
            comando.Parameters["Socio"].Value = “Juan”;//socio.Nombre;
            SqlDataAdapter adap = new SqlDataAdapter(comando);           
            conexion.Open();
            adap.Fill(ds);
            conexion.Close();
            conexion.Dispose();
            if(ds.Tables[0].Rows.Count>0)
            {           
                return true;
            }
            return false;
        }

Nuestras Entidades:

public class Socio
   {
       public Socio(int _SocioID,string _Nombre)
       {
           this._SocioID = _SocioID;
           this._Nombre = _Nombre;
       }

       private int _SocioID;

       public int SocioID
       {
           get { return _SocioID; }
           set { _SocioID = value; }
       }
       private string _Nombre;

       public string Nombre
       {
           get { return _Nombre; }
           set { _Nombre = value; }
       }

   }

public class Prestamo
    {
        private int _PrestamoID;

        public int PrestamoID
        {
            get { return _PrestamoID; }
            set { _PrestamoID = value; }
        }
        private int _LibroID;

        public int LibroID
        {
            get { return _LibroID; }
            set { _LibroID = value; }
        }
        private int _SocioID;

        public int SocioID
        {
            get { return _SocioID; }
            set { _SocioID = value; }
        }
        private DateTime _Fecha;

        public DateTime Fecha
        {
            get { return _Fecha; }
            set { _Fecha = value; }
        }       
    }

public class Libro
    {
        private int _LibroID;

        public int LibroID
        {
            get { return _LibroID; }
            set { _LibroID = value; }
        }
        private string _Descripcion;

        public string Descripcion
        {
            get { return _Descripcion; }
            set { _Descripcion = value; }
        }
        public Libro(int _LibroID, string _Descripcion)
        {
            this._LibroID = _LibroID;
            this._Descripcion = _Descripcion;
        }

Simple y Basico, como dicen coquito , y esta vez si segui el Diagrama de Secuencia.
En el Comprimido esta el Backup de la Base , solo restauren.
DESCARGATE LA DEMO
Muchas Gracias
Jose Fabricio Rojas


About this entry