Professional Documents
Culture Documents
www.myasp.net.com
3. Hacer clic en en (v) para desplegar las opciones de My Websites y visualizar la configuracin
de la cuenta. Luego, vuelva a enrrollar las opciones de My Websites.
10.
11. Ingresar el Password para conectarse con la base de datos y luego hacer clic en el
botn de comando Connect.
Ing. Javier Alberto Manrique Quionez
6
12.
13.
14. En el Formulario Run Query digitar el script SQL para crear las tablas de base de
datos.
15. Hacer clic en el botn de comando Submit y verificar que los comandos se hayan
ejecutado satisfactoriamente..
16. Verificar que la tabla Evento se haya creado. Haga doble clic en la tabla Evento para
verificar la creacin de su estructura.
17. Verificar que la tabla Evento presente la estructura segn el Script ejecutado. Cierre los
Formularios Web abiertos y termine la Sesin en el MyASP.net. Finalmente cerrar la
Pestaa https://mssql.myasp.net/default.asp del Explotrador Windows.
17.
18.
SolucinGestinDeEventos.
19.
20.
21.
new
SqlConnection(ConfigurationManager.ConnectionStrings["DbEventoConnectionString"].ConnectionString);
try
{ return conexion;
}
catch (SqlException e)
{ return null;
}
}
}
}
22.
23.
Crear una clase denominada EventoDAO.cs y digitar el siguiente cdigo del mtodo
esttico insertarRegistro.
Ing. Javier Alberto Manrique Quionez
15
24.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
namespace WebApplicationGestionDeEventos
{public class EventoDAO
{ public static Boolean insertarRegistro(Evento oEvento)
{ SqlConnection oSqlConnection = new SqlConnection();
try
{ oSqlConnection = AdministradorDeConexion.getConexion();
oSqlConnection.Open();
String sentencia = "INSERT INTO Evento(idEvento, nombreDelEvento,fechaDelEvento) VALUES("
+
oEvento.idEvento + ",'" +
oEvento.nombreDelEvento + "'," +
oEvento.fechaDelEvento + ")";
SqlCommand oSqlCommand = new SqlCommand(sentencia, oSqlConnection);
oSqlCommand.ExecuteNonQuery();
oSqlConnection.Close();
return true;
}
catch (System.Exception e)
{ oSqlConnection.Close();
return false;
}
}
public static Boolean eliminarRegistro(Evento oEvento)
{ SqlConnection oSqlConnection = new SqlConnection();
try
{ oSqlConnection = AdministradorDeConexion.getConexion();
oSqlConnection.Open();
string sentencia = "DELETE FROM Evento WHERE idEvento =" + oEvento.idEvento;
SqlCommand oSqlCommand = new SqlCommand(sentencia, oSqlConnection);
oSqlCommand.ExecuteNonQuery();
oSqlConnection.Close();
return true;
}
catch (System.Exception e)
{
oSqlConnection.Close();
return false;
}
}
catch (System.Exception e)
{ oSqlConnection.Close();
return null;
}
}
public static Boolean modificarRegistro(Evento oEvento)
{ SqlConnection oSqlConnection = new SqlConnection();
try
{ oSqlConnection = AdministradorDeConexion.getConexion();
oSqlConnection.Open();
string sentencia = "UPDATE Evento SET nombreDelEvento
='"+oEvento.nombreDelEvento.Trim() + "'," +
"fechaDelEvento ='"+oEvento.fechaDelEvento.Trim() +
" WHERE idEvento =" + oEvento.idEvento;
SqlCommand oSqlCommand = new SqlCommand(sentencia, oSqlConnection);
oSqlCommand.ExecuteNonQuery();
oSqlConnection.Close();
return true;
}
catch (System.Exception e)
{ oSqlConnection.Close();
return false;
}
}
}
catch (System.Exception e)
{ oSqlConnection.Close();
return -99;
}
}
25.
26.
27.
28.
29.
Hacer clic en la pestaa Diseo para visualizar el diseo del Formulario Web.
31.
32.
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplicationGestionDeEventos
{ public partial class WebFormABCM : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e)
{ if (!Page.IsPostBack)
{ LLenar_Grilla();
}
}
public void LLenar_Grilla()
{ DataTable oDataTable = new DataTable();
oDataTable = EventoDAO.GetEvento();
GridViewEvento.DataSource = oDataTable;
GridViewEvento.DataBind();
}
protected void GridViewEvento_RowEditing(object sender, GridViewEditEventArgs e)
{ try
{ GridViewEvento.EditIndex = e.NewEditIndex;
LLenar_Grilla();
}
catch (Exception)
{ throw;
}
}
protected void GridViewEvento_RowCancelingEdit(object sender,
GridViewCancelEditEventArgs e)
{ try
Ing. Javier Alberto Manrique Quionez
23
{ GridViewEvento.EditIndex = -1;
LLenar_Grilla();
}
catch (Exception)
{
throw;
}
}
protected void GridViewEvento_RowUpdating(object sender, GridViewUpdateEventArgs
e)
{ try
{ Evento oEvento = new Evento();
TextBox oTextBox = new TextBox();
oTextBox =
(TextBox)GridViewEvento.Rows[e.RowIndex].FindControl("TextBoxIdEvento");
oEvento.idEvento = Convert.ToInt32(oTextBox.Text);
oTextBox =
(TextBox)GridViewEvento.Rows[e.RowIndex].FindControl("TextBoxNombreDelEvento");
oEvento.nombreDelEvento = oTextBox.Text;
oTextBox =
(TextBox)GridViewEvento.Rows[e.RowIndex].FindControl("TextBoxFechaDelEvento");
oEvento.fechaDelEvento = oTextBox.Text.Substring(0, 10);
bool resultado = EventoDAO.modificarRegistro(oEvento);
GridViewEvento.EditIndex = -1;
LLenar_Grilla();
}
catch (Exception)
{ throw;
}
}
protected void GridViewEvento_RowDeleting(object sender, GridViewDeleteEventArgs e)
{ Evento oEvento = new Evento();
oEvento.idEvento =
Convert.ToInt32(GridViewEvento.DataKeys[e.RowIndex].Values["idEvento"].ToString());
bool resultado = EventoDAO.eliminarRegistro(oEvento);
GridViewEvento.EditIndex = -1;
LLenar_Grilla();
}
protected void ButtonInsertarRegistro_Click(object sender, EventArgs e)
{
Evento oEvento = new Evento();
oEvento.idEvento = Int32.Parse(TextBoxIdEvento.Text);
oEvento.nombreDelEvento = TextBoxNombreDelEvento.Text;
oEvento.fechaDelEvento = TextBoxFechaDelEvento.Text;
bool resultado = EventoDAO.insertarRegistro(oEvento);
LLenar_Grilla();
}
}
}
Ing. Javier Alberto Manrique Quionez
24
33.
34.
<?xml version="1.0"?>
<!-Para obtener ms informacin sobre cmo configurar la aplicacin de ASP.NET, visite
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name
= "DbEventoConnectionString"
connectionString = "Data Source
= SQL5016.myASP.NET;
Initial Catalog = DB_9CB63E_Evento;
User Id
= DB_9CB63E_Primera_admin;
Password
= jamq12345;"
providerName
= "System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true"/>
</system.web>
38.
39.
40.
42.