martes, 29 de octubre de 2013

Ejemplo de Ajax con las librerias de microsoft

ejemplo 1
------------------------------------------------------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication5.WebForm3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager runat="server"></asp:ScriptManager>
    <asp:UpdatePanel  runat="server" UpdateMode="Always">
         <ContentTemplate>
                <fieldset>
                <legend>UpdatePanel</legend>
                <asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br />
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
                </fieldset>
            </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

--------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication5
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button1.Click += new EventHandler(Button1_Click);
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = "Refreshed at " +
                DateTime.Now.ToString();
        }
    }
}










Ejemplo2


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication5
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            timer1.Tick += new EventHandler<EventArgs>(timer1_Tick);
        }

        void timer1_Tick(object sender, EventArgs e)
        {
            Label1.Text = "Refreshed at " +
               DateTime.Now.ToString();
        }
    }
}


-------------------------





<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="WebApplication5.WebForm4" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
     <asp:Timer runat="server" ID="timer1" Interval="1000" ></asp:Timer>
    <asp:UpdatePanel ID="UpdatePanel1"  runat="server" UpdateMode="Always">
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="timer1" />
    </Triggers>
         <ContentTemplate>
                <fieldset>
                <legend>UpdatePanel</legend>
                <asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br />
                </fieldset>
            </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

jueves, 17 de octubre de 2013

Ejemplo de Base de datos

static public class AccesoDatos
    {
        static string ConnectionString = "Data Source=LAB4-SERVER;Initial Catalog=Crocitto;User ID=crocitto";
        //static string ConnectionString = "DATA SOURCE=.; INITIAL CATALOG=CARRITO; USER ID = sa; PASSWORD=andres";
        static public SqlConnection cn = new SqlConnection(ConnectionString);

        static public void Conectar()
        {
            if (cn.State == ConnectionState.Closed)
                cn.Open();
        }

        static public void Desconectar()
        {
            if (cn.State == ConnectionState.Open)
                cn.Close();
        }

    }

--------------------------------------------------------------------------------------

public class BDCategorias:Categorias
    {
        private static BDCategorias instance;
        DataTable DTCategorias = new DataTable();
        ArrayList listacategorias = new ArrayList();

        protected BDCategorias()
        {
        }

        public static BDCategorias Instance()
        {
            if (instance == null)
            {
                instance = new BDCategorias();
            }
            return instance;
        }
   
        override public void CargarCategorias()
        {
            SqlCommand cmd = new SqlCommand("select * from Categorias",AccesoDatos.cn);
            SqlDataReader reader;
            AccesoDatos.Conectar();
            reader = cmd.ExecuteReader();
            DTCategorias.Load(reader);
            AccesoDatos.Desconectar();
            DataColumn[] pk = new DataColumn[1];
            pk[0] = DTCategorias.Columns[0];
        }

        override public void Agregar(CATEGORIAS cat)
        {
            SqlCommand cmd = new SqlCommand("insert into Categorias (categoria) values ('" + cat.Nombre + "')", AccesoDatos.cn);
            AccesoDatos.Conectar();
            cmd.ExecuteNonQuery();
            AccesoDatos.Desconectar();           
        }

        override public void Eliminar(int idcateg)
        {
            SqlCommand cmd = new SqlCommand("delete from Categorias where id=" + idcateg, AccesoDatos.cn);
            AccesoDatos.Conectar();
            cmd.ExecuteNonQuery();
            AccesoDatos.Desconectar();
        }

        override public void Modificar(CATEGORIAS cat)
        {
            SqlCommand cmd = new SqlCommand("update Categorias set categoria='" + cat.Nombre + "' where id=" + cat.Id, AccesoDatos.cn);
            AccesoDatos.Conectar();
            cmd.ExecuteNonQuery();
            AccesoDatos.Desconectar();
        }

        override public CATEGORIAS Buscar(int idcat)
        {
            SqlCommand cmd = new SqlCommand("select * from Categorias where id=" + idcat, AccesoDatos.cn);
            SqlDataReader reader;
            AccesoDatos.Conectar();
            reader = cmd.ExecuteReader();
            DataTable dt1 = new DataTable();
            dt1.Load(reader);
            AccesoDatos.Desconectar();
            foreach (DataRow dt in dt1.Rows)
            {
                CATEGORIAS c = new CATEGORIAS();
                c.Id = Convert.ToInt16(dt["id"]);
                c.Nombre = dt["categoria"].ToString();
                return c;
            }
            return null;
        }
}


miércoles, 16 de octubre de 2013

TP

Objetivo

Desarrollo de una aplicación social que permita publicar comentarios e imágenes en un muro

y ver publicaciones de amigos.

Fecha de Entrega: 15/11/2013

Requerimientos funcionales

Para ingresar al sitio el usuario debe loguearse o registrarse en el sistema.

El usuario puede hacer publicaciones en el muro que constan de comentarios o imágenes.

El muro muestra únicamente las publicaciones propias y de sus amigos.

El usuario puede enviar solicitudes de amistad.

El sistema debe mostrar todas las solicitudes que le llegan al usuario y deben poder

confirmarse.

Requerimientos No funcionales

El sitio debe ser desarrollado en Visual Studio 2008 o superior.

La base de datos puede ser a elección.

El sitio debe ser subido a un host.

Investigación

Se debe investigar e implementar, en parte del sitio, algunos de los siguientes temas:

HTML5, CS3, Jquery, Ajax.

Observaciones

La presentación y defensa del TP es individual. La nota de corrección se aplicara como

segundo parcial.

Utilizar todos los conceptos aprendidos en el dictado de la materia, incluir en el TP:

Elementos HTML

Master Page

Themes (CSS/Skins)

Variables de sesión/aplicación

Lista de Objetos

ADO.NET

Autenticacion de Usuarios.

Diseño modular separado en capas.

jueves, 10 de octubre de 2013

miércoles, 2 de octubre de 2013

Codigo ayuda de examen

---------------Eliminar un row de la grilla-------------

-------------aspx
 <asp:GridView runat="server" ID="grdDummy" AutoGenerateColumns="false">
            <Columns>
                <asp:BoundField DataField="columna1" HeaderText="texto1" />
                <asp:CommandField DeleteText="Eliminar" ShowDeleteButton="true" />
            </Columns>
        </asp:GridView>


----------cs

 DataSet data = null;
  protected void Page_Load(object sender, EventArgs e)
  {
    data = new DataSet();
    DataTable table1 = new DataTable();
    table1.Columns.Add("Columna1");
    data.Tables.Add(table1);
    DataRow row1 = table1.NewRow();
    table1.Rows.Add(row1);
    row1[0] = "asdad";
    grdDummy.DataSource = data;
    grdDummy.DataBind();
    grdDummy.RowDeleting += new GridViewDeleteEventHandler(grdDummy_RowDeleting);
  }

  void grdDummy_RowDeleting(object sender, GridViewDeleteEventArgs e)
  {
    data.Tables[0].Rows.RemoveAt(e.RowIndex);
    grdDummy.DataBind();
  }



---------------------Property de un data set instanciado en session------------

DataSet data
  {
    get
    {
      if (Session["data"] == null)
        Session.Add("data", GetCustomDataSet());
      return (DataSet)Session["data"];
    }
  }

De DataRow[] a DataTable

 private DataTable GetDatatable(DataRow[] rows)
        {
            DataTable table1 = new DataTable();
            table1.Columns.Add("Columna1");
            foreach (DataRow row in rows)
            {
                DataRow newRow = table1.NewRow();
                table1.Rows.Add(newRow);
                newRow.ItemArray = row.ItemArray;
            }
            return table1;
        }