domingo, 27 de julio de 2014

El Libro del Día: HTML5 in Action

El Libro del Día: 2014-07-27

Titulo: HTML5 in Action
Autor: Rob Crowther, Joe Lennon, Ash Blue, Greg Wanish
Editorial: Manning
Nro Paginas: 466

Capítulos:
PART 1 INTRODUCTION
1 HTML5: from documents to applications
PART 2 BROWSER-BASED APPS
2 Form creation: input widgets, data binding, and data validation
3 File editing and management: rich formatting, file storage, drag and drop
4 Messaging: communicating to and from scripts in HTML5
5 Mobile applications: client storage and offline execution
PART 3 INTERACTIVE GRAPHICS, MEDIA, AND GAMING
6 2D Canvas: low-level, 2D graphics rendering
7 SVG: responsive in-browser graphics
8 Video and audio: playing media in the browser
9 WebGL: 3D application development

Descarga:
HTML5_InAction

sábado, 26 de julio de 2014

El Demo del Día: Plantilla de Datos en el Control Web DataList

Requerimientos

Se desea crear una Aplicación Web que permita listar los datos de los empleados que cumpla con lo siguiente:
- Presente en forma de ficha la información del código, apellido, nombre y fecha de nacimiento del empleado.
- Muestre en la ficha la foto del empleado la cual se encuentra en un carpeta "Empleados" donde el nombre del archivo esta compuesto por el código del empleado y la extensión jpg. Para los archivos que no se encuentren se usará el archivo No.jpg.
- La información debe aparecer solo en una pagina en forma de cuadro con borde distribuida en columnas.
- Las fichas deben tener fondo gris claro, pero al pasar el mouse el estilo de la ficha cambiara a fondo amarillo.

Nota: El principal requerimiento es que la pagina sea rápida y que arroje la menor cantidad de HTML en el cliente. Además el Usuario No quiere Paginado ya que no son demasiados los registros a mostrar.

Solución

Usaremos el control DataList y le quitaremos el ViewState (EnableViewState=false) para reducir el HTML arrojado al cliente y para mejorar la apariencia de la pagina usaremos estilos para las fichas de datos.
Ademas usando Plantilla de Datos en el Control DataList podemos presentar en forma de ficha la información del empleado y mostrarla en varias columnas.

Crear el Procedimiento Almacenado en la Base de Datos de SQL Server

Usaremos la tabla Empleados (Employees) de Northwind:

Create Procedure [dbo].[uspEmployeesListar]
As
Select EmployeeID,LastName,FirstName,
IsNull(BirthDate,'1/1/1900') As BirthDate
From Employees Order By 1

Crear una Librería de Clases con las Entidades del Negocio

Crear un proyecto de tipo Librería de Clases en C# llamado: "Northwind.Librerias.EntidadesNegocio" y modificar el código de la clase como sigue:

using System;
namespace Northwind.Librerias.EntidadesNegocio
{
    public class beEmpleado
    {
        public int IdEmpleado { get; set; }
        public string Apellido { get; set; }
        public string Nombre { get; set; }
        public string NombreCompleto
        {
            get
            {
                return (String.Format("{0} {1}",Nombre,Apellido));
            }
        }
        public DateTime FechaNacimiento { get; set; }
    }
}

Crear una Librería de Acceso a Datos

Crear un proyecto de tipo Librería de Clases en C# llamado: "Northwind.Librerias.AccesoDatos" y modificar el código de la clase como sigue:

using System;
using System.Data; //CommandType
using System.Data.SqlClient; //SqlConnection, SqlCommand, SqlDataReader
using System.Collections.Generic; //List
using Northwind.Librerias.EntidadesNegocio; //beEmpleado
namespace Northwind.Librerias.AccesoDatos
{
    public class daEmpleado
    {
        public List<beEmpleado> listar(SqlConnection con)
        {
            List<beEmpleado> lbeEmpleado = null;
            SqlCommand cmd = new SqlCommand("uspEmployeesListar", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader drd = cmd.ExecuteReader(CommandBehavior.SingleResult);
            if (drd != null)
            {
                lbeEmpleado = new List<beEmpleado>();
                int posIdEmpleado = drd.GetOrdinal("EmployeeID");
                int posApellido = drd.GetOrdinal("LastName");
                int posNombre = drd.GetOrdinal("FirstName");
                int posFechaNacimiento = drd.GetOrdinal("BirthDate");
                beEmpleado obeEmpleado;
                while (drd.Read())
                {
                    obeEmpleado = new beEmpleado();
                    obeEmpleado.IdEmpleado = drd.GetInt32(posIdEmpleado);
                    obeEmpleado.Apellido = drd.GetString(posApellido);
                    obeEmpleado.Nombre = drd.GetString(posNombre);
                    obeEmpleado.FechaNacimiento = drd.GetDateTime(posFechaNacimiento);
                    lbeEmpleado.Add(obeEmpleado);
                }
                drd.Close();
            }
            return (lbeEmpleado);
        }
    }
}

Nota: Hay que hacer una referencia a la Librería de Entidades del Negocio.

Crear una Librería de Reglas del Negocio

Crear un proyecto de tipo Librería de Clases en C# llamado: "Northwind.Librerias.ReglasNegocio" y modificar el código de la clase como sigue:

using System;
using System.Configuration; //ConfigurationManager
namespace Northwind.Librerias.ReglasNegocio
{
    public class brGeneral
    {
        //Propiedad
        public string Conexion { get; set; }

        //Constructor
        public brGeneral()
        {
            Conexion = ConfigurationManager.ConnectionStrings["conNW"].ConnectionString;
        }
    }
}

Nota: Hay que hacer una referencia a la Librería de Entidades del Negocio, a la Librería de Acceso a Datos y a System.Configuration.

Agregar otra clase llamada: "brEmpleado" y escribir el siguiente código:

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Northwind.Librerias.EntidadesNegocio;
using Northwind.Librerias.AccesoDatos;

namespace Northwind.Librerias.ReglasNegocio
{
    public class brEmpleado:brGeneral //Herencia
    {
        public List<beEmpleado> listar()
        {
            List<beEmpleado> lbeEmpleado = null;
            using (SqlConnection con = new SqlConnection(Conexion))
            {
                try
                {
                    con.Open();
                    daEmpleado odaEmpleado = new daEmpleado();
                    lbeEmpleado = odaEmpleado.listar(con);
                }
                catch (SqlException ex)
                {
                    //Capturar el error y grabar un Log
                }
            } //con.Close(); con.Dispose(); con = null;
            return (lbeEmpleado);
        }
    }
}

Nota: La clase "brEmpleado" hereda de la clase "brGeneral" la cadena de conexión para no pasarla como parámetro en cada método de la clase o en el constructor de cada clase se hace una sola vez.

Crear una Librería de Código de Usuario para Web

Crear un proyecto de tipo Librería de Clases en C# llamado: "General.Librerias.CodigoUsuarioWeb" y modificar el código de la clase como sigue:

using System;
using System.Collections.Generic;
using System.IO; //File
using System.Web; //HttpContext

namespace General.Librerias.CodigoUsuarioWeb
{
    public class Imagen
    {
        public static string obtenerUrl(int id, string carpeta)
        {
            string archivo = HttpContext.Current.Server.MapPath
            (String.Format("../Imagenes/{0}/{1}.jpg", carpeta, id));
            string url = String.Format("../Imagenes/{0}/{1}.jpg", carpeta, id);
            if (!File.Exists(archivo)) url = String.Format("../Imagenes/{0}/No.jpg", carpeta);
            return (url);
        }
    }
}

Nota: Como esta librería va a ser usada por paginas web hay que hacer referencia a: "System.Web"

Crear la Aplicación Web en ASP .NET Web Form

Crear un "Nuevo Sitio web vacío de ASP .NET" en C# llamado "Demo12" y crear las siguientes carpetas:
- Estilos: Para el archivo de hoja de estilo (CSS).
- Imagenes. Dentro crear otra carpeta llamada "Empleados" y adjuntar los archivos con las fotos de los empleados: 1.jpg, 2.jpg, 3.jpg, ... y No.jpg.
- Paginas: Para contener la pagina de lista de empleados.

Crear el Archivo de Hoja de Estilo (CSS)

Seleccionar la carpeta "Estilos" y agregar un archivo de hoja de estilos con el nombre de: "ACME.css" y modificar el código como sigue:

.Cuadro {
    position:absolute;
    left:2%;
    top:4%;
    width:96%;
    height:92%;
    background-color: gray;
    border:solid;
    border-color:black;
    border-radius:10px;
    overflow:scroll;
}
.Titulo {
    background-color:black;
    color:white;
    text-transform:uppercase;
    font-size:xx-large;
    font-weight:bold;
}
.Subtitulo {
    background-color:white;
    color:blue;
    text-transform:capitalize;
    font-size:x-large;
    font-weight:bold;
}
.MarcarTabla {
    background-color: lightgray;
    cursor:default;
    border:solid;
    border-color:lightgray;
}
.MarcarTabla:hover {
    background-color: yellow;
    cursor:pointer;
    border:solid;
    border-color:black;
}

Nota: El estilo "Cuadro" será aplicado al div principal de la pagina y el estilo "MarcarTabla" será aplicado a la tabla que muestra la ficha de cada empleado dentro del DataList.

Crear la Pagina ASP .NET como un Formulario Web Form

Seleccionar la carpeta "Paginas" y agregar un Formulario Web Form llamado: "ListaEmpleados.aspx", para empezar a diseñar la pagina hay que hacer referencia a las Librerías de Negocio (que copia todas sus dependencias) y la Librería de Código de Usuario Web.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListaEmpleados.aspx.cs" Inherits="Paginas_ListaEmpleados" %>
<%@ Import Namespace="Northwind.Librerias.EntidadesNegocio" %>
<%@ Import Namespace="General.Librerias.CodigoUsuarioWeb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link href="../Estilos/ACME.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div class="Cuadro">
        <table style="width: 100%">
            <tr>
                <td class="Titulo">Plantilla y Estilos en el Control DataList</td>
            </tr>
            <tr>
                <td class="Subtitulo">Lista de Empleados</td>
            </tr>
            <tr>
                <td>
                    <asp:DataList ID="dlsEmpleado" runat="server" EnableViewState="False" 
                        RepeatColumns="3" CellPadding="20" CellSpacing="20"
                        RepeatDirection="Horizontal">
                        <ItemTemplate>
                            <table class="MarcarTabla">
                                <tr>
                                    <td>
                                        <table>
                                            <tr>
                                                <td style="width:80px">Código :</td>
                                                <td style="width:100px">
                                                    <%#((beEmpleado)Container.DataItem).IdEmpleado%>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="width:80px">Apellido :</td>
                                                <td style="width:100px">
                                                    <%#((beEmpleado)Container.DataItem).Apellido%>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="width:80px">Nombre :</td>
                                                <td style="width:100px">
                                                    <%#((beEmpleado)Container.DataItem).Nombre%>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="width:80px">Fecha Nac :</td>
                                                <td style="width:100px">
                                                    <%#((beEmpleado)Container.DataItem).FechaNacimiento.
                                                           ToShortDateString()%>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                    <td>
                                        <img src='<%#Imagen.obtenerUrl(((beEmpleado)Container.DataItem).
                                           IdEmpleado,"Empleados")%>' width="120" height="80" alt="Foto" 
                                           title="<%#((beEmpleado)Container.DataItem).
                                           NombreCompleto%>"/>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                   </asp:DataList>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

Nota: Se ha configurado las propiedad "RepeatColumns" del Control DataList para distribuir en 3 columnas los datos de los empleados, además la propiedad "RepeatDirection" está en Horizontal y No en Vertical para mostrar la dirección de los registros en filas y no en columnas, de izquierda a derecha y no de arriba hacia abajo. Finalmente, las propiedades CellPadding y CellSpacing permiten dar espaciado a los datos.

El diseño de la pagina se mostrará como en la siguiente figura:


Escribir el siguiente código C# en la página:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Northwind.Librerias.EntidadesNegocio; //beEmpleado
using Northwind.Librerias.ReglasNegocio; //brEmpleado

public partial class Paginas_ListaEmpleados : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            brEmpleado obrEmpleado = new brEmpleado();
            List<beEmpleado> lbeEmpleado = obrEmpleado.listar();
            dlsEmpleado.DataSource = lbeEmpleado;
            dlsEmpleado.DataBind();
        }
    }
}

Modificar el Archivo Web.Config para especificar la cadena de conexión a Northwind

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="conNW" providerName="SQLServer" connectionString="uid=UsuarioNW;pwd=123456;
      data source=DSOFT\Sqlexpress; database=Northwind"/>
  </connectionStrings>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>
</configuration>

Probar la Pagina Web

Guardar el Sitio Web, clic derecho a la Pagina "ListaEmpleados.aspx" y seleccionar "Ver en el explorador".


Observar que el contenido aparece sobre un cuadro con borde negro con esquinas redondeadas y los registros de empleados aparecen en pequeñas fichas distribuidas en 3 columnas. El cuadro tiene una barra de desplazamiento (scroll) para ver los demás registros.

Pasar el mouse por cada ficha de empleado y notar como cambia el estilo de la ficha seleccionada debido al estilo "MarcarTabla" aplicado a la tabla que esta dentro del control DataList.

Clic derecho a la página y seleccionar "Ver código fuente de la pagina", notar que el HTML generado desde el servidor es mínimo ya que se le quito el ViewState al control DataList y se uso Hojas de Estilo para reducir el formato en cada tabla.

Comentario Final

En esta demostración usamos el Control DataList para presentar la información en columnas y usando Estilos lo presentamos en una sola pagina en forma de cuadro con una barra de desplazamiento, esta técnica es útil si no son muchas páginas, de lo contrario es mejor Paginar para No enviar demasiado HTML al cliente, lo cual veremos en un siguiente post.

Descarga:

El Libro del Día: Programming Windows Store Apps with C#

El Libro del Día: 2014-07-26

Titulo: Programming Windows Store Apps with C#
Autor: Matt Baxter-Reynolds, Iris Classon
Editorial: O'Reilly
Nro Paginas: 508

Capítulos:
1. Making the Transition from .NET (Part 1)
2. Making the Transition from .NET (Part 2)
3. Local Persistent Data
4. The App Bar
5. Notifications
6. Working with Files
7. Sharing
8. Searching
9. Settings
10. Location
11. Using the Camera
12. Responsive Design
13. Resources and Localization
14. Background Tasks and App Lifetime
15. Sideloading and Distribution
A. Cryptography and Hashing
B. Unit Testing Basics for Windows Store Apps

Descarga:
Programming_WindowsStore_AppsC#

viernes, 25 de julio de 2014

El Libro del Día: Microsoft SharePoint 2013 Administration Inside Out

El Libro del Día: 2014-07-25

Titulo: Microsoft SharePoint 2013 Administration Inside Out
Autor: Randy Williams, CA Callahan, Chris Givens, John Milan Gross, 
          Brian Alderman, Javier Barrera
Editorial: Microsoft
Nro Paginas: 954

Capítulos:
Chapter 1: What’s new in SharePoint 2013
Chapter 2: Planning and preparing for SharePoint 2013 installation
Chapter 3: Upgrading to SharePoint 2013
Chapter 4: Installing SharePoint 2013
Chapter 5: Managing farms, web applications, and content databases
Chapter 6: Creating and managing service applications
Chapter 7: Creating and managing site collections
Chapter 8: Creating and configuring Search service applications
Chapter 9: Customizing search results and the Search Center site
Chapter 10: Configuring Metadata Management Services
Chapter 11: Configuring User Profile Services
Chapter 12: Understanding and configuring social capabilities
Chapter 13: Configuring Business Connectivity Services
Chapter 14: Configuring records management and eDiscovery
Chapter 15: Understanding and managing SharePoint 2013 apps
Chapter 16: Managing farm and sandboxed solutions
Chapter 17: Installing and configuring business intelligence components
Chapter 18: Monitoring and troubleshooting SharePoint 2013
Chapter 19: Understanding and configuring security
Chapter 20: Scaling and optimizing farms
Chapter 21: Installing and configuring Office Web Apps 2013
Chapter 22: Understanding SharePoint Online, Azure, and hybrid scenarios
Chapter 23: Performing content and disaster recovery

Descarga:
Microsoft_SharePoint2013_Administration_InsideOut

jueves, 24 de julio de 2014

El Libro del Día: Windows Phone 8 In Action

El Libro del Día: 2014-07-24

Titulo: Windows Phone 8 In Action
Autor: Timothy Binkley-Jones, Adam Benoit, Massimo Perga, Michael Sync
Editorial: Manning
Nro Paginas: 497

Capítulos:
PART 1 INTRODUCING WINDOWS PHONE
1 A new phone, a new operating system
2 Creating your first Windows Phone application
PART 2 CORE WINDOWS PHONE
3 Fast application switching and resume
4 Scheduled actions
5 Launching tasks and choosers
6 Contacts and calendars
7 Storing data
8 Working with the camera
9 Integrating with the Photos and Music + Videos Hubs
10 Using sensors
11 Network communication with push notifications
12 Using the Speech API
PART 3 XAML FOR WINDOWS PHONE
13 ApplicationBar and context menus
14 Panorama and pivot controls
15 Building a media player
16 Using Maps 369
17 Building HTML applications
18 Releasing and monetizing apps

Descarga:
WindowsPhone_8_InAction

miércoles, 23 de julio de 2014

El Libro del Día: Exam Ref 70-484

El Libro del Día: 2014-07-23

Titulo: Exam Ref 70-484 Essentials of Developing Windows Store Apps Using C#
Autor: Indrajit Chakrabarty
Editorial: Microsoft
Nro Paginas: 446

Capítulos:
Chapter 1 Design Windows Store apps
Chapter 2 Develop Windows Store apps
Chapter 3 Create the user interface
Chapter 4 Program the user interaction
Chapter 5 Manage security and data

Descarga:
ExamRef_70484_Essentials_Developing_WindowsStore_C#

martes, 22 de julio de 2014

El Libro del Día: Microsoft SQL Server 2012 Internals

El Libro del Día: 2014-07-22

Titulo: Microsoft SQL Server 2012 Internals
Autor: Kalen Delaney, Bob Beauchemin, Conor Cunningham, 
          Jonathan Kehayias, Benjamin Nevarez, Paul S. Randal
Editorial: Microsoft
Nro Paginas: 983

Capítulos:
Chapter 1 SQL Server 2012 architecture and configuration
Chapter 2 The SQLOS
Chapter 3 Databases and database files
Chapter 4 Special databases
Chapter 5 Logging and recovery
Chapter 6 Table storage
Chapter 7 Indexes: internals and management
Chapter 8 Special storage
Chapter 9 Special indexes
Chapter 10 Query execution
Chapter 11 The Query Optimizer
Chapter 12 Plan caching and recompilation
Chapter 13 Transactions and concurrency
Chapter 14 DBCC internals

Descarga:
Microsoft_SQL_Server_2012_Internals