Created
June 5, 2016 23:27
-
-
Save MacoChave/bfe1969414b43a28c1cac6b04e380dda to your computer and use it in GitHub Desktop.
Conexion db C# - SQL SERVER
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
namespace GestorHoteles.Datos | |
{ | |
public class Conexion | |
{ | |
//@"Data Source=[ACCESO A DB];Initial Catalog=[NOMBRE DB];Integrated Security=True" | |
string cadenaConexion = @"Data Source=TOTTO\PCTOTTO;Initial Catalog=dbHOTELES;Integrated Security=True"; | |
SqlConnection conVerificar; | |
SqlCommand cmdVerificar; | |
SqlParameter pmVerificar; | |
SqlDataAdapter daVerificar; | |
public string getCadenaConexion() | |
{ | |
return cadenaConexion; | |
} | |
} |
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
use GestorVentas | |
create table Clientes ( | |
cod_cliente int identity, | |
nombre varchar(30) null, | |
apellido varchar(30) null, | |
nit int null, | |
telefono int null, | |
ciudad varchar(50) null, | |
edad int null, | |
sexo varchar(10) null, | |
cod_tarjeta int null, | |
usuario varchar(30) null, | |
pass varchar(30) null, | |
estado varchar(30)) | |
create table Bancos ( | |
cod_banco int identity, | |
nombre varchar(30) null) | |
create table Tarjetas ( | |
cod_tarjeta int identity, | |
cod_banco int null, | |
saldo smallmoney null, | |
cod_cliente int null, | |
moneda char(4) null, | |
tipo_cambio smallmoney null) | |
create table Productos ( | |
cod_producto int not null, | |
nombre varchar(30) null, | |
costo smallmoney null, | |
precio smallmoney null, | |
cantidad int null, | |
edad int null, | |
sexo varchar(30) null) | |
create table Relaciones ( | |
cod_producto int null, | |
cod_pdsimilar int null, | |
cod_pdcomp int null) | |
create table Pedidos ( | |
cod_pedido int identity, | |
cod_cliente int null, | |
cod_producto int null, | |
cantidad int null, | |
estado varchar(20) null) | |
create table Empleados ( | |
cod_empleado int not null, | |
nombre varchar (30), | |
apellido varchar(30), | |
email varchar(30), | |
usuario varchar(30), | |
pass varchar(30), | |
rol varchar(30)) | |
create table Permisos ( | |
cod_empleado int not null, | |
modulo varchar(50), | |
consultar varchar(2), | |
agregar varchar(2), | |
modificar varchar(2), | |
eliminar varchar(2)) | |
go | |
alter table Clientes add primary key (cod_cliente) | |
alter table Bancos add primary key (cod_banco) | |
alter table Tarjetas add primary key (cod_tarjeta) | |
alter table Productos add primary key (cod_producto) | |
alter table Empleados add primary key (cod_empleado) | |
alter table Tarjetas add foreign key (cod_cliente) references Clientes(cod_cliente) | |
alter table Tarjetas add foreign key (cod_banco) references Bancos(cod_banco) | |
alter table Relaciones add foreign key (cod_producto) references Productos(cod_producto) | |
alter table Relaciones add foreign key (cod_pdsimilar) references Productos(cod_producto) | |
alter table Relaciones add foreign key (cod_pdcomp) references Productos(cod_producto) | |
alter table Pedidos add foreign key (cod_producto) references Productos(cod_producto) | |
alter table Pedidos add foreign key (cod_cliente) references Clientes(cod_cliente) | |
alter table Permisos add foreign key (cod_empleado) references Empleados(cod_empleado) | |
go |
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.Linq; | |
using System.Web; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
using System.Data; | |
using System.Data.SqlClient; | |
public partial class Login : System.Web.UI.Page | |
{ | |
SqlConnection conexion = new SqlConnection("Data Source=PC\\SQLEXPRESS;Initial Catalog=GestorVentas;Integrated Security=True"); | |
SqlCommand cmd = new SqlCommand(); | |
SqlDataReader dr; | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
} | |
protected void btningresar_Click1(object sender, ImageClickEventArgs e) | |
{ | |
if (rbtnempleado.Checked) | |
{ | |
conexion.Open(); | |
cmd.Connection = conexion; | |
cmd.CommandText = "select * from Empleados where usuario = '" + txtusuario.Text + "' and pass = '" + txtpassword.Text + "'"; | |
dr = cmd.ExecuteReader(); | |
dr.Read(); | |
if (dr.HasRows) | |
{ | |
Session["usuario"] = txtusuario.Text; | |
Response.Redirect("Empleado.aspx"); | |
} | |
else | |
{ | |
Response.Write("¡¡Usuario incorrecto!!"); | |
} | |
} | |
else | |
{ | |
conexion.Open(); | |
cmd.Connection = conexion; | |
cmd.CommandText = "select * from Clientes where usuario = '" + txtusuario.Text + "' and pass = '" + txtpassword.Text + "' and estado = 'aprobado'"; | |
dr = cmd.ExecuteReader(); | |
dr.Read(); | |
if (dr.HasRows) | |
{ | |
Session["usuario"] = txtusuario.Text; | |
Response.Redirect("Usuario.aspx"); | |
} | |
else | |
{ | |
Response.Write("¡¡Usuario incorrecto!!"); | |
} | |
} | |
conexion.Close(); | |
} | |
protected void btnregistrar_Click1(object sender, ImageClickEventArgs e) | |
{ | |
Serviciowebcliente.WebServiceSoapClient misw = new Serviciowebcliente.WebServiceSoapClient(); | |
misw.insertarRegistros(txtnombre.Text,txtapellido.Text,Convert.ToInt32(txtnit.Text),Convert.ToInt32(txttelefono.Text),txtciudad.Text,Convert.ToInt32(txtedad.Text),txtsexo.Text,txtnewusuario.Text,txtpass.Text); | |
Response.Redirect("Principal.aspx"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment