Created
April 30, 2017 18:27
-
-
Save IsabelPerez26/625559d4abc9c8d22f876e9fa8664702 to your computer and use it in GitHub Desktop.
Default conexion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Collections.Concurrent; | |
using System.Linq; | |
using System.Web; | |
using Microsoft.VisualBasic; | |
using System.Collections; | |
using System.Data; | |
using System.Diagnostics; | |
using System.Data.SqlClient; | |
using System.Configuration; | |
namespace WebApplication3 | |
{ | |
// public class Concexion | |
// { | |
// } | |
//} | |
/// <summary> | |
/// Clase que maneja la conexion con sql server | |
/// </summary> | |
/// <remarks></remarks> | |
public class Conexion | |
{ | |
private string conexion = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; | |
/// <summary> | |
/// Obtener la un SqlConection con la cadena de conexion | |
/// </summary> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public SqlConnection conex() | |
{ | |
string connectionString = conexion; | |
return new System.Data.SqlClient.SqlConnection(connectionString); | |
} | |
/// <summary> | |
/// Obtener la Cadena de Conexion | |
/// </summary> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public string conex_string() | |
{ | |
return conexion; | |
} | |
} | |
/// <summary> | |
/// Clase que maneja el llamado a los procedimientos almacenados | |
/// </summary> | |
/// <remarks></remarks> | |
public class StoredProcedure | |
{ | |
private Conexion obj = new Conexion(); | |
/// <summary> | |
/// Constructor que solo recibe el nombre del procedimiento e inicializa la colección. | |
/// </summary> | |
/// <param name="nNombre">Nombre del procedimiento almacenado</param> | |
/// <remarks></remarks> | |
public StoredProcedure(string nNombre) | |
{ | |
try | |
{ | |
Nombre = nNombre; | |
Parametros = new Collection(); | |
} | |
catch (Exception ex) | |
{ | |
throw ex; | |
} | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks></remarks> | |
public StoredProcedure() | |
{ | |
Nombre = ""; | |
Parametros = new Collection(); | |
} | |
/// <summary> | |
/// declaracion de variables para el nombre de procedimiento y los parametros de los procedimientos | |
/// </summary> | |
/// <remarks></remarks> | |
private string mNombreProcedimiento; | |
private Collection mParametros; | |
/// <summary> | |
/// Propiedad de la clase para asignar y obtener el nombre del procedimiento | |
/// </summary> | |
/// <value></value> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public string Nombre | |
{ | |
get { return mNombreProcedimiento; } | |
set { mNombreProcedimiento = value; } | |
} | |
/// <summary> | |
/// Propiedad para obtener y asignar los parametros de los procediemientos almacenados | |
/// </summary> | |
/// <value></value> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public Collection Parametros | |
{ | |
get { return mParametros; } | |
set { mParametros = value; } | |
} | |
/// <summary> | |
/// Agrega los parametros del procedimiento y su respectivo valor. | |
/// </summary> | |
/// <param name="pVariable"></param> | |
/// <param name="pValor"></param> | |
/// <remarks></remarks> | |
public void AgregarParametro(string pVariable, object pValor) | |
{ | |
try | |
{ | |
StoredProcedureParameter iParametro = new StoredProcedureParameter((pVariable[0].ToString().Trim() == "@" ? pVariable : "@" + pVariable), pValor); | |
this.Parametros.Add(iParametro); | |
} | |
catch (Exception ex) | |
{ | |
throw ex; | |
} | |
} | |
/// <summary> | |
/// Ejecutar Vista | |
/// </summary> | |
/// <param name="nombre">Modificacion del nombre a ejecutar, default el nombre inicializado en la instancia</param> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public DataSet EjecutarVista2(string nombre = "") | |
{ | |
try | |
{ | |
string _nombre = (string.IsNullOrEmpty(nombre.Trim()) ? this.Nombre : nombre); | |
Conexion Conn = new Conexion(); | |
string sql = "SELECT * FROM " + _nombre; | |
SqlCommand sqlCmd = new SqlCommand(this.Nombre, obj.conex()); | |
sqlCmd.CommandType = CommandType.Text; | |
sqlCmd.CommandText = sql; | |
sqlCmd.Connection = obj.conex(); | |
SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); | |
DataSet ds = new DataSet(); | |
sda.Fill(ds); | |
obj.conex().Close(); | |
return ds; | |
} | |
catch (Exception ex) | |
{ | |
throw ex; | |
} | |
} | |
/// <summary> | |
/// Ejecutar Vista | |
/// </summary> | |
/// <param name="nombre">Modificacion del nombre a ejecutar, default el nombre inicializado en la instancia</param> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public DataTable EjecutarVista(string nombre) | |
{ | |
try | |
{ | |
Conexion Conn = new Conexion(); | |
string sql = "SELECT * FROM " + nombre; | |
SqlCommand sqlCmd = new SqlCommand(this.Nombre, obj.conex()); | |
sqlCmd.CommandType = CommandType.Text; | |
sqlCmd.CommandText = sql; | |
sqlCmd.Connection = obj.conex(); | |
SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); | |
DataTable ds = new DataTable(); | |
sda.Fill(ds); | |
obj.conex().Close(); | |
return ds; | |
} | |
catch (Exception ex) | |
{ | |
throw ex; | |
} | |
} | |
/// <summary> | |
/// Ejecutar una funcion SQL | |
/// </summary> | |
/// <param name="nombre"></param> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public DataTable EjecutarFuncion(string nombre) | |
{ | |
try | |
{ | |
Conexion Conn = new Conexion(); | |
string sql = "SELECT " + nombre.Trim(); | |
SqlCommand sqlCmd = new SqlCommand(this.Nombre, obj.conex()); | |
sqlCmd.CommandType = CommandType.Text; | |
sqlCmd.CommandText = sql; | |
sqlCmd.Connection = obj.conex(); | |
SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); | |
DataTable ds = new DataTable(); | |
sda.Fill(ds); | |
obj.conex().Close(); | |
return ds; | |
} | |
catch (Exception ex) | |
{ | |
throw ex; | |
} | |
} | |
/// <summary> | |
/// Ejecuta el procedimiento almacenado. | |
/// </summary> | |
/// <param name="nombre">Modificacion del nombre a ejecutar, default el nombre inicializado en la instancia</param>> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public DataSet EjecutarProcedimiento(string nombre = "") | |
{ | |
try | |
{ | |
string _nombre = (string.IsNullOrEmpty(nombre.Trim()) ? this.Nombre : nombre); | |
Conexion Conn = new Conexion(); | |
//colocacion de la varialbe de conexion | |
SqlCommand sqlCmd = new SqlCommand(_nombre, obj.conex()); | |
sqlCmd.CommandType = CommandType.StoredProcedure; | |
sqlCmd.CommandTimeout = 120; | |
StoredProcedureParameter mParametro = null; | |
//Agrega las variables al procedimiento almacenado | |
foreach (StoredProcedureParameter mParametro_loopVariable in this.Parametros) | |
{ | |
mParametro = mParametro_loopVariable; | |
SqlParameter pParam = new SqlParameter(mParametro.Variable, mParametro.GetTypeProperty); | |
pParam.Direction = ParameterDirection.Input; | |
pParam.Value = mParametro.Valor; | |
sqlCmd.Parameters.Add(pParam); | |
} | |
//SqlAdapter utiliza el SqlCommand para llenar el Dataset | |
SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); | |
DataSet ds = new DataSet(); | |
sda.Fill(ds); | |
obj.conex().Close(); | |
return ds; | |
} | |
catch (Exception ex) | |
{ | |
throw ex; | |
} | |
} | |
/// <summary> | |
/// Ejecutar un query de texto en SQL | |
/// </summary> | |
/// <param name="query">consulta tipo texto</param> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public DataSet EjecutarQueryString(string query) | |
{ | |
try | |
{ | |
Conexion Conn = new Conexion(); | |
//colocacion de la varialbe de conexion | |
SqlCommand sqlCmd = new SqlCommand(query.Trim(), obj.conex()); | |
var _with1 = sqlCmd; | |
_with1.CommandType = CommandType.Text; | |
_with1.CommandTimeout = 120; | |
//SqlAdapter utiliza el SqlCommand para llenar el Dataset | |
SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); | |
DataSet ds = new DataSet(); | |
sda.Fill(ds); | |
obj.conex().Close(); | |
return ds; | |
} | |
catch (Exception ex) | |
{ | |
throw ex; | |
} | |
} | |
/// <summary> | |
/// EjecutarVistaOrdenada | |
/// </summary> | |
/// <param name="SqlOrden">Consulta del order by</param> | |
/// <param name="nombreVista">Modificacion del nombre a ejecutar, default el nombre inicializado en la instancia</param> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public DataSet EjecutarVistaOrdenada(string nombreVista, string SqlOrden) | |
{ | |
try | |
{ | |
Conexion Conn = new Conexion(); | |
string sql = null; | |
//colocacion de la varialbe de conexion | |
sql = "SELECT * FROM " + nombreVista + " ORDER BY " + SqlOrden; | |
SqlCommand sqlCmd = new SqlCommand(this.Nombre, obj.conex()); | |
sqlCmd.CommandType = CommandType.Text; | |
sqlCmd.CommandText = sql; | |
sqlCmd.Connection = obj.conex(); | |
SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); | |
//Se llena el dataset | |
DataSet ds = new DataSet(); | |
sda.Fill(ds); | |
obj.conex().Close(); | |
return ds; | |
} | |
catch (Exception ex) | |
{ | |
throw ex; | |
} | |
} | |
/// <summary> | |
/// Convercion de Serializacion de DataTable a Json | |
/// </summary> | |
/// <param name="dt">DataTable a convertir</param> | |
/// <returns>String con formato JSON</returns> | |
/// <remarks></remarks> | |
public string ConvertDataTableToJSON(DataTable dt) | |
{ | |
try | |
{ | |
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); | |
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); | |
Dictionary<string, object> row = default(Dictionary<string, object>); | |
foreach (DataRow dr in dt.Rows) | |
{ | |
row = new Dictionary<string, object>(); | |
foreach (DataColumn col in dt.Columns) | |
{ | |
row.Add(col.ColumnName, dr[col]); | |
} | |
rows.Add(row); | |
} | |
return serializer.Serialize(rows); | |
} | |
catch (Exception ex) | |
{ | |
throw ex; | |
} | |
} | |
} | |
/// <summary> | |
/// Clase que maneja las variables y su respectivo valor | |
/// </summary> | |
/// <remarks></remarks> | |
public class StoredProcedureParameter | |
{ | |
private string mVariable; | |
private object mValor; | |
/// <summary> | |
/// Nombre de la variable, debe ser igual a la declarada en el procedimiento almacenado | |
/// </summary> | |
/// <value></value> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public string Variable | |
{ | |
get { return mVariable; } | |
set { mVariable = value; } | |
} | |
/// <summary> | |
/// Valor de la variable, puede ser de cualquier tipo de dato. preferible que coincida con las variables declaradas en GetTypeProperty | |
/// </summary> | |
/// <value></value> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public object Valor | |
{ | |
get { return mValor; } | |
set { mValor = value; } | |
} | |
/// <summary> | |
/// Se definen los posibles tipos de datos que se le van a enviar al procedimiento almacenado | |
/// Esta lista podria aumentar conforme se usen otro tipo de variable. | |
/// </summary> | |
/// <value></value> | |
/// <returns></returns> | |
/// <remarks></remarks> | |
public SqlDbType GetTypeProperty | |
{ | |
get | |
{ | |
if (mValor.GetType().FullName == "System.String;") | |
{ | |
return SqlDbType.NVarChar; | |
} | |
else if (mValor.GetType().FullName == "System.Int16;") | |
{ | |
return SqlDbType.Int; | |
} | |
else if (mValor.GetType().FullName == "System.Int32;") | |
{ | |
return SqlDbType.Int; | |
} | |
else if (mValor.GetType().FullName == "System.Int64;") | |
{ | |
return SqlDbType.BigInt; | |
} | |
else if (mValor.GetType().FullName == "System.Integer;") | |
{ | |
return SqlDbType.Int; | |
} | |
else if (mValor.GetType().FullName == "System.Decimal;") | |
{ | |
return SqlDbType.Decimal; | |
} | |
else if (mValor.GetType().FullName == "System.Double;") | |
{ | |
return SqlDbType.Float; | |
} | |
else if (mValor.GetType().FullName == "System.DateTime;") | |
{ | |
return SqlDbType.DateTime; | |
} | |
else if (mValor.GetType().FullName == "System.Byte;") | |
{ | |
return SqlDbType.Image; | |
} | |
return SqlDbType.NVarChar; | |
} | |
} | |
/// <summary> | |
/// Constructor para la inicializacion de la variable. | |
/// </summary> | |
/// <param name="pVariable"></param> | |
/// <param name="pValor"></param> | |
/// <remarks></remarks> | |
public StoredProcedureParameter(string pVariable, object pValor) | |
{ | |
try | |
{ | |
this.Variable = pVariable; | |
this.Valor = pValor; | |
} | |
catch (Exception ex) | |
{ | |
throw new Exception("Error en la creacion del Parametro \n " + ex.Message); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication3._Default" %> | |
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> | |
<script src="Scripts/ie10-viewport-bug-workaround.js"></script> | |
<link href="Scripts/ie10-viewport-bug-workaround.css" rel="stylesheet" /> | |
<script src="Scripts/ie-emulation-modes-warning.js"></script> | |
<link href="Scripts/carousel.css" rel="stylesheet" /> | |
<!-- Carousel | |
================================================== --> | |
<div id="myCarousel" class="carousel slide" data-ride="carousel"> | |
<!-- Indicators --> | |
<ol class="carousel-indicators"> | |
<li data-target="#myCarousel" data-slide-to="0" class=""></li> | |
<li data-target="#myCarousel" data-slide-to="1" class=""></li> | |
<li data-target="#myCarousel" data-slide-to="2" class="active"></li> | |
</ol> | |
<div class="carousel-inner" role="listbox"> | |
<div class="item"> | |
<img class="first-slide" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="First slide"> | |
<img src="Imagenes/18217639_1419538388068967_987194638_n.png" />" /> | |
<div class="container"> | |
<div class="carousel-caption"> | |
<h1> Utiliza energía amigable para el medio ambiente</h1> | |
<p>.</p> | |
<p><a class="btn btn-lg btn-primary" href="#" role="button">Unete al mundo solar</a></p> | |
</div> | |
</div> | |
</div> | |
<div class="item"> | |
<img class="second-slide" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Second slide"> | |
<img src="Imagenes/casafotovoltaico2.jpg" />" /> | |
</div> | |
defa<div class="item active"> | |
<img class="third-slide" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Third slide"> | |
<img src="Imagenes/esquema_aislada.jpg" />" /> | |
<div class="container"> | |
<div class="carousel-caption"> | |
<h1></h1> | |
<p></p> | |
<p><a class="btn btn-lg btn-primary" href="#" role="button">Energía Solar </a></p> | |
</div> | |
</div> | |
</div> | |
</div> | |
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"> | |
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> | |
<span class="sr-only">Previous</span> | |
</a> | |
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"> | |
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> | |
<span class="sr-only">Next</span> | |
</a> | |
</div><!-- /.carousel --> | |
<div class="jumbotron"> | |
<h1>Energía Inteligente</h1> | |
<p class="lead">Tiene la visión de despertar el aprovechamiento de la energia solar en "Cuando","Como" y "Donde" </p> | |
<p><a href="http://www.asp.net" class="btn btn-primary btn-lg">Informese más »</a></p> | |
</div> | |
<div class="row"> | |
<div class="col-md-4"> | |
<h2> </h2> | |
<p> | |
</p> | |
<p> | |
</p> | |
</div> | |
<div class="col-md-4"> | |
<h2> </h2> | |
<p> | |
| |
</p> | |
</div> | |
<div class="col-md-4"> | |
<p> | |
</p> | |
</div> | |
</div> | |
</asp:Content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------ | |
// <generado automáticamente> | |
// Este código fue generado por una herramienta. | |
// | |
// Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si | |
// se vuelve a generar el código. | |
// </generado automáticamente> | |
//------------------------------------------------------------------------------ | |
namespace WebApplication3 { | |
public partial class SiteMaster { | |
/// <summary> | |
/// Control MainContent. | |
/// </summary> | |
/// <remarks> | |
/// Campo generado automáticamente. | |
/// Para modificarlo, mueva la declaración del campo del archivo del diseñador al archivo de código subyacente. | |
/// </remarks> | |
protected global::System.Web.UI.WebControls.ContentPlaceHolder MainContent; | |
/// <summary> | |
/// Control ASPxPivotGrid1. | |
/// </summary> | |
/// <remarks> | |
/// Campo generado automáticamente. | |
/// Para modificarlo, mueva la declaración del campo del archivo del diseñador al archivo de código subyacente. | |
/// </remarks> | |
protected global::DevExpress.Web.ASPxPivotGrid.ASPxPivotGrid ASPxPivotGrid1; | |
/// <summary> | |
/// Control SqlDataSource1. | |
/// </summary> | |
/// <remarks> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------ | |
// <generado automáticamente> | |
// Este código fue generado por una herramienta. | |
// | |
// Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si | |
// se vuelve a generar el código. | |
// </generado automáticamente> | |
//------------------------------------------------------------------------------ | |
namespace WebApplication3 { | |
public partial class AhorroEnergia { | |
/// <summary> | |
/// Control ASPxGridView1. | |
/// </summary> | |
/// <remarks> | |
/// Campo generado automáticamente. | |
/// Para modificarlo, mueva la declaración del campo del archivo del diseñador al archivo de código subyacente. | |
/// </remarks> | |
protected global::DevExpress.Web.ASPxGridView ASPxGridView1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Security.Claims; | |
using System.Security.Principal; | |
using System.Web; | |
using System.Web.Security; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
using Microsoft.AspNet.Identity; | |
namespace WebApplication3 | |
{ | |
public partial class SiteMaster : MasterPage | |
{ | |
private const string AntiXsrfTokenKey = "__AntiXsrfToken"; | |
private const string AntiXsrfUserNameKey = "__AntiXsrfUserName"; | |
private string _antiXsrfTokenValue; | |
protected void Page_Init(object sender, EventArgs e) | |
{ | |
// The code below helps to protect against XSRF attacks | |
var requestCookie = Request.Cookies[AntiXsrfTokenKey]; | |
Guid requestCookieGuidValue; | |
if (requestCookie != null && Guid.TryParse(requestCookie.Value, out requestCookieGuidValue)) | |
{ | |
// Use the Anti-XSRF token from the cookie | |
_antiXsrfTokenValue = requestCookie.Value; | |
Page.ViewStateUserKey = _antiXsrfTokenValue; | |
} | |
else | |
{ | |
// Generate a new Anti-XSRF token and save to the cookie | |
_antiXsrfTokenValue = Guid.NewGuid().ToString("N"); | |
Page.ViewStateUserKey = _antiXsrfTokenValue; | |
var responseCookie = new HttpCookie(AntiXsrfTokenKey) | |
{ | |
HttpOnly = true, | |
Value = _antiXsrfTokenValue | |
}; | |
if (FormsAuthentication.RequireSSL && Request.IsSecureConnection) | |
{ | |
responseCookie.Secure = true; | |
} | |
Response.Cookies.Set(responseCookie); | |
} | |
Page.PreLoad += master_Page_PreLoad; | |
} | |
protected void master_Page_PreLoad(object sender, EventArgs e) | |
{ | |
if (!IsPostBack) | |
{ | |
// Set Anti-XSRF token | |
ViewState[AntiXsrfTokenKey] = Page.ViewStateUserKey; | |
ViewState[AntiXsrfUserNameKey] = Context.User.Identity.Name ?? String.Empty; | |
} | |
else | |
{ | |
// Validate the Anti-XSRF token | |
if ((string)ViewState[AntiXsrfTokenKey] != _antiXsrfTokenValue | |
|| (string)ViewState[AntiXsrfUserNameKey] != (Context.User.Identity.Name ?? String.Empty)) | |
{ | |
throw new InvalidOperationException("Validation of Anti-XSRF token failed."); | |
} | |
} | |
} | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
} | |
protected void Unnamed_LoggingOut(object sender, LoginCancelEventArgs e) | |
{ | |
Context.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment