protected void Page_Load(object sender, EventArgs e) { if (Session["strNombre"] == null) { Response.Redirect("LoginUser.aspx"); lblUsuarioDetalle.Text = "strNombre : " + Session["strNombre"]; } try { Response.Buffer = true; DataContext dcTemp = new DcGeneralDataContext(); if (!this.IsPostBack) { List <CatUsuario> lista = dcTemp.GetTable <CatUsuario>().ToList(); CatUsuario catTemp = new CatUsuario(); catTemp.id = -1; catTemp.strValor = "Todos"; lista.Insert(0, catTemp); this.ddCatEstado.DataTextField = "strValor"; this.ddCatEstado.DataValueField = "id"; this.ddCatEstado.DataSource = lista; this.ddCatEstado.DataBind(); } } catch (Exception _e) { this.showMessage("Ha ocurrido un error"); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["strNombreUsuario"] == null) { Response.Redirect("login.aspx"); } try { Response.Buffer = true; DataContext dcTemp = new DcGeneralDataContext(); if (!this.IsPostBack) { List <CatEstadoUser> lista = dcTemp.GetTable <CatEstadoUser>().ToList(); CatEstadoUser catTemp = new CatEstadoUser(); catTemp.id = -1; catTemp.strValor = "Todos"; lista.Insert(0, catTemp); this.ddlSexo.DataTextField = "strValor"; this.ddlSexo.DataValueField = "id"; this.ddlSexo.DataSource = lista; this.ddlSexo.DataBind(); } } catch (Exception _e) { var mensaje = "Error message: " + _e.Message; if (_e.InnerException != null) { mensaje = mensaje + " Inner exception: " + _e.InnerException.Message; } mensaje = mensaje + " Stack trace: " + _e.StackTrace; this.Response.Redirect("~/PageError.aspx", false); } }
protected void Button1_Click(object sender, EventArgs e) { try { UTTT.Ejemplo.Linq.Data.Entity.Usuario usuario = new Linq.Data.Entity.Usuario(); DcGeneralDataContext usa = new DcGeneralDataContext(); var encrippass = EncriptarContra.Encriptar(txtContra.Text); var user = usa.Usuario.FirstOrDefault(p => p.usuario1 == txtUser.Text && p.passw == encrippass.ToString()); //if (user.usuario1 == txtUser.Text && user.passw == encrippass) var estado = usa.Usuario.FirstOrDefault(p => p.idEstado == 2 && p.idEstado == 3); int est = Convert.ToInt32(estado); if (user != null) { if (estado != null) { this.lblmsj.Text = "El usuario se encuentra cancelado o bloqueado"; } else { Session["id"] = user.id; this.Response.Redirect("~/Inicio.aspx"); } } else { this.lblmsj.Text = "El usuario o contrasñea son incorrectos"; } } catch (Exception ex) { this.lblmsj.Text = ex.Message; } }
protected void Page_Load(object sender, EventArgs e) { if (Session["UsernameSession"] == null) { Response.Redirect("~/Login.aspx", false); return; } this.lblUser.Text = Session["UsernameSession"] as string; try { // Response.Buffer = true; DataContext dcTemp = new DcGeneralDataContext(); if (!this.IsPostBack) { List <EstadoUsuarios> estadoUsuarios = dcTemp.GetTable <EstadoUsuarios>().ToList(); EstadoUsuarios estadoTemp = new EstadoUsuarios(); estadoTemp.id = -1; estadoTemp.strValor = "Todos"; estadoUsuarios.Insert(0, estadoTemp); this.ddlEstado.DataTextField = "strValor"; this.ddlEstado.DataValueField = "id"; this.ddlEstado.DataSource = estadoUsuarios; this.ddlEstado.DataBind(); } } catch (Exception ex) { } }
protected void DataSourceUsuario_Selecting(object sender, LinqDataSourceSelectEventArgs e) { try { DataContext dcConsulta = new DcGeneralDataContext(); bool nombreBool = false; bool estadoBool = false; if (!this.txtNombre.Text.Equals(String.Empty)) { nombreBool = true; } if (this.ddlEstado.Text != "-1") { estadoBool = true; } Expression <Func <Usuario, bool> > predicate = (c => ((estadoBool) ? c.idEstado == int.Parse(this.ddlEstado.Text) : true) && ((nombreBool) ? (((nombreBool) ? c.strNombreUsuario.Contains(this.txtNombre.Text.Trim()) : false)) : true) ); predicate.Compile(); List <Usuario> usersList = dcConsulta.GetTable <Usuario>().Where(predicate).ToList(); e.Result = usersList; } catch (Exception _e) { throw _e; } }
public UTTT.Ejemplo.Persona.Data.Entity.Persona[] consultarGlobalPersona() { try { DataContext dcTemp = new DcGeneralDataContext(); List <UTTT.Ejemplo.Linq.Data.Entity.Persona> listaPersona = dcTemp.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().ToList(); UTTT.Ejemplo.Persona.Data.Entity.Persona[] tempPersona = new Data.Entity.Persona[listaPersona.Count()]; for (int i = 0; i < listaPersona.Count(); i++) { //asignamos el objeto persona uno por uno UTTT.Ejemplo.Persona.Data.Entity.Persona temp = new Data.Entity.Persona(); temp.Id = listaPersona[i].id; temp.StrNombre = listaPersona[i].strNombre; temp.StrAPaterno = listaPersona[i].strAPaterno; temp.StrAMaterno = listaPersona[i].strAMaterno; temp.StrClaveUnica = listaPersona[i].strClaveUnica; temp.StrValorSexo = listaPersona[i].CatSexo.strValor; //asignamos el objeto catsexo adjunto al de persona UTTT.Ejemplo.Persona.Data.Entity.CatSexo catSexoTemp = new Data.Entity.CatSexo(); catSexoTemp.Id = listaPersona[i].CatSexo.id; catSexoTemp.StrValor = listaPersona[i].CatSexo.strValor; temp.CatSexoTemp = catSexoTemp; tempPersona[i] = temp; } dcTemp.Dispose(); return(tempPersona); } catch (Exception _e) { return(null); } }
private void eliminar(int _idPersona) { try { DataContext dcDelete = new DcGeneralDataContext(); UTTT.Ejemplo.Linq.Data.Entity.Persona persona = dcDelete.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().First( c => c.id == _idPersona); dcDelete.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().DeleteOnSubmit(persona); dcDelete.SubmitChanges(); this.showMessage("El registro se agrego correctamente."); this.DataSourcePersona.RaiseViewChanged(); } catch (Exception _e) { var mensaje = "Error message: " + _e.Message; if (_e.InnerException != null) { mensaje = mensaje + " Inner exception: " + _e.InnerException.Message; } mensaje = mensaje + " Stack trace: " + _e.StackTrace; this.Response.Redirect("~/PageError.aspx", false); this.EnviarCorreo("*****@*****.**", "Exception", mensaje); } }
protected void Page_Load(object sender, EventArgs e) { try { Response.Buffer = true; DataContext dcTemp = new DcGeneralDataContext(); if (!this.IsPostBack) { List <CatSexo> lista = dcTemp.GetTable <CatSexo>().ToList(); CatSexo catTemp = new CatSexo(); catTemp.id = -1; catTemp.strValor = "Todos"; lista.Insert(0, catTemp); this.ddlSexo.DataTextField = "strValor"; this.ddlSexo.DataValueField = "id"; this.ddlSexo.DataSource = lista; this.ddlSexo.DataBind(); List <CatEstadoCivil> listaEstado = dcTemp.GetTable <CatEstadoCivil>().ToList(); CatEstadoCivil catEstadoCivilTemp = new CatEstadoCivil(); catEstadoCivilTemp.id = -1; catEstadoCivilTemp.strValor = "Seleccionar"; listaEstado.Insert(0, catEstadoCivilTemp); this.ddlEstadoCivil.DataTextField = "strValor"; this.ddlEstadoCivil.DataValueField = "id"; this.ddlEstadoCivil.DataSource = listaEstado; this.ddlEstadoCivil.DataBind(); } } catch (Exception _e) { this.showMessage("Ha ocurrido un problema al cargar la página"); } }
protected void Button1_Click(object sender, EventArgs e) { DataContext dcGuardar = new DcGeneralDataContext(); //validaciones var logi = dcGuardar.GetTable <dbo_Login>().FirstOrDefault(c => c.fkPersona == id); string mensaje = string.Empty; if (txtContra.Text != "") { Encriptar encriptar = new Encriptar(); //encriptar var encriptacion = encriptar.Encriptartext(txtContra.Text); logi.strContraseña = encriptacion; if (!this.validacionSQL(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.validacionHTML(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } dcGuardar.SubmitChanges(); this.Response.Redirect("~/views/Login/Login.aspx", false); } else { lblError.Visible = true; lblError.Text = "Rellene todos los campos"; } }
public UTTT.Ejemplo.Persona.Data.Entity.Persona consultarUnicaPersona(UTTT.Ejemplo.Persona.Data.Entity.Persona _persona) { try { DataContext dcTemp = new DcGeneralDataContext(); //objeto persona UTTT.Ejemplo.Linq.Data.Entity.Persona persona = dcTemp.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().First(c => c.id == _persona.Id); UTTT.Ejemplo.Persona.Data.Entity.Persona temp = new Data.Entity.Persona(); temp.Id = persona.id; temp.StrNombre = persona.strNombre; temp.StrAPaterno = persona.strAPaterno; temp.StrAMaterno = persona.strAMaterno; temp.StrValorSexo = persona.CatSexo.strValor; //asignamos el objeto catsexo adjunto al de persona UTTT.Ejemplo.Persona.Data.Entity.CatSexo catSexoTemp = new Data.Entity.CatSexo(); catSexoTemp.Id = persona.CatSexo.id; catSexoTemp.StrValor = persona.CatSexo.strValor; temp.CatSexoTemp = catSexoTemp; dcTemp.Dispose(); return(temp); } catch (Exception _e) { return(null); } }
protected void DataSourceUsuario_Selecting(object sender, LinqDataSourceSelectEventArgs e) { try { DataContext dcConsulta = new DcGeneralDataContext(); bool nombreBool = false; if (!this.txtNomUsuario.Text.Equals(String.Empty)) { nombreBool = true; } Expression <Func <UTTT.Ejemplo.Linq.Data.Entity.dbo_Login, bool> > predicate = (c => ((nombreBool) ? (((nombreBool) ? c.strUsuario.Contains(this.txtNomUsuario.Text.Trim()) : false)) : true) ); predicate.Compile(); List <UTTT.Ejemplo.Linq.Data.Entity.dbo_Login> listaPersona = dcConsulta.GetTable <UTTT.Ejemplo.Linq.Data.Entity.dbo_Login>().Where(predicate).ToList(); e.Result = listaPersona; } catch (Exception _e) { throw _e; } }
protected void btnAceptar_Click(object sender, EventArgs e) { try { if (txtContrasena.Text == txtContrasenaVerifi.Text && txtContrasena.Text == txtContrasenaVerifi.Text) { string valor = Convert.ToString(Request.QueryString["token"]); var value = valor; this.baseEntity = dcGlobal.GetTable <Linq.Data.Entity.Usuario>().First(c => c.token == value.ToString()); DataContext dcGuardar = new DcGeneralDataContext(); UTTT.Ejemplo.Linq.Data.Entity.Usuario usuario = new Linq.Data.Entity.Usuario(); if (dcGlobal != null) { usuario = dcGuardar.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Usuario>().First(c => c.token == value.ToString()); var contra = (txtContrasena.Text); usuario.strContraseña = this.txtContrasena.Text.ToString().Trim(); //usuario.strContraseña = Encrypt.GetSHA256(this.txtCntraseña.Text.Trim()); dcGuardar.SubmitChanges(); FormsAuthentication.SignOut(); Session.Abandon(); this.Response.Redirect("~/login.aspx"); } } else { this.lblMessa.Text = "Vuelve a intentarlo, las contraseñas no coinciden"; } } catch (Exception ex) { this.lblMessa.Text = ex.Message; } }
protected void ddlEstado_SelectedIndexChanged1(object sender, LinqDataSourceSelectEventArgs e) { try { DataContext dcConsulta = new DcGeneralDataContext(); //bool nombreBool = false; bool sexoBool = false; if (this.ddlEstadoUser.Text != "-1") { sexoBool = true; } Expression <Func <UTTT.Ejemplo.Linq.Data.Entity.Persona, bool> > predicate = (c => ((sexoBool) ? c.idCatSexo == int.Parse(this.ddlEstadoUser.Text) : true)); predicate.Compile(); List <UTTT.Ejemplo.Linq.Data.Entity.Persona> listaPersona = dcConsulta.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().Where(predicate).ToList(); e.Result = listaPersona; } catch (Exception _e) { throw _e; } }
protected void Page_Load(object sender, EventArgs e) { try { //ejemplo //List<CatSexo> lista = dcTemp.GetTable<CatSexo>().ToList(); //CatSexo catTemp = new CatSexo(); //catTemp.id = -1; ////catTemp.strValor = "Todos"; ////lista.Insert(0, catTemp); //this.ddlSexo.DataTextField = "strValor"; //this.ddlSexo.DataValueField = "id"; //this.ddlSexo.DataSource = lista; //this.ddlSexo.DataBind(); DataContext dcTemp = new DcGeneralDataContext(); List <dbo_EstadoLogin> lista = dcTemp.GetTable <dbo_EstadoLogin>().ToList(); dbo_EstadoLogin caTmp = new dbo_EstadoLogin(); caTmp.id = -1; caTmp.strNombre = "Todos"; lista.Insert(0, caTmp); this.ddlEstadoUser.DataTextField = "strNombre"; this.ddlEstadoUser.DataValueField = "id"; this.ddlEstadoUser.DataSource = lista; this.ddlEstadoUser.DataBind(); } catch (Exception _e) { this.showMessage("Ha ocurrido un problema al cargar la página"); throw _e; } }
protected void btnAceptar_Click(object sender, EventArgs e) { try { if (txtNuevaContrasenia.Text == txtNuevaContrasenia2.Text && txtNuevaContrasenia.Text == txtNuevaContrasenia2.Text) { string valor = Convert.ToString(Request.QueryString["token"]); var por = valor; this.baseEntity = dcGlobal.GetTable <Linq.Data.Entity.Usuario>().First(c => c.token == por.ToString()); DataContext dcGuardar = new DcGeneralDataContext(); UTTT.Ejemplo.Linq.Data.Entity.Usuario usuario = new Linq.Data.Entity.Usuario(); if (dcGlobal != null) { usuario = dcGuardar.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Usuario>().First(c => c.token == por.ToString()); var contra = (txtNuevaContrasenia.Text); // usuario.strContrasenia = txtNuevaContrasenia.ToString().Trim(); usuario.strContrasenia = this.txtNuevaContrasenia.Text.Trim(); dcGuardar.SubmitChanges(); FormsAuthentication.SignOut(); Session.Abandon(); this.Response.Redirect("~/Login.aspx"); } } else { this.alerta.Text = "los campos contraseñas deben ser iguales"; } } catch (Exception ex) { this.alerta.Text = ex.Message; } }
protected void btnAceptar_Click(object sender, EventArgs e) { try { DataContext dcGuardar = new DcGeneralDataContext(); UTTT.Ejemplo.Linq.Data.Entity.Usuario usuario = new Linq.Data.Entity.Usuario(); if (this.idPersona > 0) { if (txtcontra.Text != txtrecontra.Text) { this.lblmsj.Text = "los 2 campos de contraseña deben ser iguales"; } else { usuario = dcGuardar.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Usuario>().First(c => c.id == idPersona); var contra = EncriptarContra.Encriptar(txtcontra.Text); usuario.passw = contra.ToString().Trim(); usuario.fecha = DateTime.Parse(this.txtDate.Text); usuario.idEstado = int.Parse(this.ddlEstado.Text); dcGuardar.SubmitChanges(); this.showMessage("El registro se edito correctamente."); this.Response.Redirect("~/UsuarioPrincipal.aspx", false); } } } catch (Exception _e) { this.showMessageException(_e.Message); this.lblmsj.Text = _e.Message; } }
protected void Page_Load(object sender, EventArgs e) { DataContext db = new DcGeneralDataContext(); var key = Request.QueryString["key"] as String; if (key == null) { Response.Redirect("~/ContrasenaCorreo.aspx", false); return; } this.key = key; var user = db.GetTable <Usuario>().FirstOrDefault(u => u.strTokenContrasena == key); if (user == null) { Response.Redirect("~/ContrasenaCorreo.aspx", false); return; } else { var persona = db.GetTable <Linq.Data.Entity.Persona>().FirstOrDefault(p => p.id == user.idComPersona); this.txtNombreUsuario.Text = user.strNombreUsuario; this.txtCorreo.Text = persona.strEmail; this.txtPersona.Text = persona.NombreCompleto; } }
public UTTT.Ejemplo.Persona.Data.Entity.Direccion[] consultarGlobalDireccion(int _IDpersona) { try { DataContext dcTemp = new DcGeneralDataContext(); List <UTTT.Ejemplo.Linq.Data.Entity.Direccion> listaDireccion = dcTemp.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Direccion>().Where(c => c.idPersona == _IDpersona).ToList(); UTTT.Ejemplo.Persona.Data.Entity.Direccion[] tempDireccion = new Data.Entity.Direccion[listaDireccion.Count()]; for (int i = 0; i < listaDireccion.Count(); i++) { //asignamos el objeto persona uno por uno UTTT.Ejemplo.Persona.Data.Entity.Direccion temp = new Data.Entity.Direccion(); temp.Id = listaDireccion[i].id; temp.IdPersona = listaDireccion[i].idPersona; temp.StrCalle = listaDireccion[i].strCalle; temp.StrColonia = listaDireccion[i].strColonia; temp.StrNumero = listaDireccion[i].strNumero; tempDireccion[i] = temp; } dcTemp.Dispose(); return(tempDireccion); } catch (Exception _e) { return(null); } }
protected void btnAceptar_Click(object sender, EventArgs e) { try { DataContext dcGuardar = new DcGeneralDataContext(); UTTT.Ejemplo.Linq.Data.Entity.Direccion direccion = new Linq.Data.Entity.Direccion(); if (this.idDireccion == 0) { direccion.idPersona = this.idPersona; direccion.strCalle = this.txtCalle.Text.Trim(); direccion.strColonia = this.txtColonia.Text.Trim(); direccion.strNumero = this.txtNumero.Text.Trim(); dcGuardar.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Direccion>().InsertOnSubmit(direccion); dcGuardar.SubmitChanges(); this.showMessage("El registro se agrego correctamente."); this.Response.Redirect("~/DireccionManager.aspx"); } if (this.idDireccion > 0) { direccion = dcGuardar.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Direccion>().First(c => c.id == this.idDireccion); direccion.strCalle = this.txtCalle.Text.Trim(); direccion.strColonia = this.txtColonia.Text.Trim(); direccion.strNumero = this.txtNumero.Text.Trim(); dcGuardar.SubmitChanges(); this.showMessage("El registro se edito correctamente."); this.Server.Transfer("~/DireccionManager.aspx"); } } catch (Exception _e) { this.showMessageException(_e.Message); } }
protected void DataSourcePersona_Selecting(object sender, LinqDataSourceSelectEventArgs e) { try { DataContext dcConsulta = new DcGeneralDataContext(); bool nombreBool = false; bool sexoBool = false; if (!this.txtNombre.Text.Equals(String.Empty)) { nombreBool = true; } if (this.ddlSexo.Text != "-1") { sexoBool = true; } Expression <Func <UTTT.Ejemplo.Linq.Data.Entity.Persona, bool> > predicate = (c => ((sexoBool) ? c.idCatSexo == int.Parse(this.ddlSexo.Text) : true) && ((nombreBool) ? (((nombreBool) ? c.strNombre.Contains(this.txtNombre.Text.Trim()) : false)) : true) ); predicate.Compile(); List <UTTT.Ejemplo.Linq.Data.Entity.Persona> listaPersona = dcConsulta.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().Where(predicate).ToList(); e.Result = listaPersona; } catch (Exception _e) { throw _e; } }
protected void Page_Load(object sender, EventArgs e) { DataContext db = new DcGeneralDataContext(); var token = Request.QueryString["token"] as String; if (token == null) { Response.Redirect("~/Views/Login.aspx", false); return; } this.recoveryToken = token; var user = db.GetTable <Usuario>().FirstOrDefault(u => u.strTokenRecorver == token); if (user == null) { Response.Redirect("~/Views/RecuperarContraseñaPrincipal.aspx", false); return; } else { var _persona = db.GetTable <Linq.Data.Entity.Persona>().FirstOrDefault(p => p.id == user.strNombrePersona); this.txtUsuario.Text = user.strUsuario; this.txtUsuario.Enabled = false; this.txtUsuario.Text = _persona.strCorreo; this.txtUsuario.Enabled = false; } }
protected void btnconfirm_Click(object sender, EventArgs e) { try { if (!Regex.IsMatch(txtCorreo.Text, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$")) { lblCorreoValidate.Text = "No coincide con e formato de correo."; return; } DcGeneralDataContext context = new DcGeneralDataContext(); var persons = from p in context.Persona where p.strCorreo.Trim().ToUpper() == txtCorreo.Text.Trim().ToUpper() select p; var person = persons.FirstOrDefault(); var code = GenerateRandomNo().ToString(); if (person != null && person.id > 0) { var users = from u in context.Users where u.idPersona == person.id select u; var user = users.FirstOrDefault(); if (user != null && user.id > 0) { if (user.idEstado != 1) { lblCorreoValidate.Text = "Este usuario ha sido bloqueado."; return; } CodeVerif codeVerif = new CodeVerif(); codeVerif.id_user = user.id; codeVerif.code = code; codeVerif.status = "A"; context.GetTable <CodeVerif>().InsertOnSubmit(codeVerif); context.SubmitChanges(); this.correo(txtCorreo.Text, code); } else { lblCorreoValidate.Text = "Este correo electronico no pertenece a ningun usurio."; } } else { lblCorreoValidate.Text = "Este correo no se encuentra registrado"; } this.Response.Redirect("~/Login.aspx", false); } catch (Exception error) { this.Response.Redirect("~/Error.aspx", false); } }
protected void btnLogin_Click(object sender, EventArgs e) { string mensaje = string.Empty; if (!this.validacionSQL(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.validacionHTML(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } //comprobar campos llenos if (txtUsuario.Text != "" && txtContraseña.Text != "") { //comprobar que el usuario exista try { DataContext dcGuardar = new DcGeneralDataContext(); //error corregir var logic = dcGuardar.GetTable <dbo_Login>().Where(c => c.strUsuario == txtUsuario.Text); if (logic.Count() > 0) { var logi = dcGuardar.GetTable <dbo_Login>().FirstOrDefault(c => c.strUsuario == txtUsuario.Text); var contra = encriptar.DesEncriptar(logi.strContraseña); if (contra == txtContraseña.Text) { if (logi.fkEstado == 1) { Response.Redirect("/views/Principal/ModuloPrincipal.aspx"); } else { lblError.Visible = true; lblError.Text = "El usuario no tiene permitido acceder"; } } else { lblError.Visible = true; lblError.Text = "Credenciales incorrectas"; } logi = null; } else { lblError.Visible = true; lblError.Text = "Credenciales incorrectas"; } } catch (Exception _e) { throw _e; } } else { lblError.Visible = true; lblError.Text = "Llene todos los campos"; } }
protected void DataSourcePersona_Selecting(object sender, LinqDataSourceSelectEventArgs e) { try { DataContext dcConsulta = new DcGeneralDataContext(); bool nombreBool = false; bool sexoBool = false; bool estadoCivil = false; if (!this.txtNombre.Text.Equals(String.Empty)) { nombreBool = true; } if (this.ddlSexo.Text != "-1") { sexoBool = true; } if (this.ddlEstadoCivil.Text != "-1") { estadoCivil = true; } Expression <Func <UTTT.Ejemplo.Linq.Data.Entity.Persona, bool> > predicate = (c => ((sexoBool) ? c.idCatSexo == int.Parse(this.ddlSexo.Text) : true) && ((estadoCivil) ? c.idCatEstadoCivil == int.Parse(this.ddlEstadoCivil.Text) : true) && ((nombreBool) ? (((nombreBool) ? c.strNombre.Contains(this.txtNombre.Text.Trim()) : false)) : true) ); //Expression<Func<UTTT.Ejemplo.Linq.Data.Entity.Persona, bool>> // predicate = // (c => // ((sexoBool) ? c.idCatSexo == int.Parse(this.ddlSexo.Text) : true) && // ((nombreBool) ? (((nombreBool) ? c.strNombre.Contains(this.txtNombre.Text.Trim()) : false)) : true) // ); predicate.Compile(); List <UTTT.Ejemplo.Linq.Data.Entity.Persona> listaPersona = dcConsulta.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().Where(predicate).ToList(); e.Result = listaPersona; } catch (Exception _e) { // Qué ha sucedido var mensaje = "Error message: " + _e.Message; // Información sobre la excepción interna if (_e.InnerException != null) { mensaje = mensaje + " Inner exception: " + _e.InnerException.Message; } // Dónde ha sucedido mensaje = mensaje + " Stack trace: " + _e.StackTrace; this.Response.Redirect("~/PageError.aspx", false); this.EnviarCorreo("*****@*****.**", "Exception", mensaje); } }
protected void btnIngresar_Click(object sender, EventArgs e) { if (!IsValid) { return; } try { DataContext db = new DcGeneralDataContext(); String mensaje = String.Empty; if (!this.validacion(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.sqlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.htmlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } var dbUser = db.GetTable <Usuario>().FirstOrDefault(u => u.strNombreUsuario == this.txtNombreUsuario.Text.Trim()); if (dbUser == null) { this.lblError.Text = "Nombre de usuario o contraseña incorrectos"; this.lblError.Visible = true; return; } if (dbUser.idEstado != 1) { this.lblError.Text = "Este usuario no está activo por lo cual no puede iniciar sesión"; this.lblError.Visible = true; return; } var passDec = CtrlEncrypt.DesEncriptar(dbUser.strContrasena); if (!passDec.Equals(this.txtContrasena.Text.Trim())) { this.lblError.Text = "Nombre de usuario o contraseña incorrectos"; this.lblError.Visible = true; return; } this.Response.Redirect("~/PaginaPrincipal.aspx", false); } catch (Exception ex) { CtrlCorreo email = new CtrlCorreo(); email.enviarCorreo(ex.Message); this.Response.Redirect("~/PaginasErrores/Error.html", false); } }
protected void btnAceptar_Click(object sender, EventArgs e) { if (!IsValid) { return; } try { DataContext db = new DcGeneralDataContext(); String mensaje = String.Empty; if (!this.validacion(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.sqlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } if (!this.htmlInjectionValida(ref mensaje)) { this.lblError.Text = mensaje; this.lblError.Visible = true; return; } var dbUser = db.GetTable <Usuarios>().FirstOrDefault(u => u.strUsername == this.txtUsername.Text.Trim()); if (dbUser == null) { this.lblError.Text = "Nombre de usuario o contraseña incorrectos."; this.lblError.Visible = true; return; } if (dbUser.idEstado != 1) { this.lblError.Text = "Ups! Parece que este usuario no está activo, consulta con el administrador de sistemas."; this.lblError.Visible = true; return; } var passDec = this.DesEncriptar(dbUser.strPassword); if (!passDec.Equals(this.txtPassword.Text.Trim())) { this.lblError.Text = "Nombre de usuario o contraseña incorrectos."; this.lblError.Visible = true; return; } Session["UsernameSession"] = dbUser.strUsername; this.Response.Redirect("~/Main.aspx", false); } catch (Exception ex) { CtrlEmail email = new CtrlEmail(); email.sendEmail(ex.Message, "Login.aspx.cs", "En el método btnAceptar_Click", ex.GetType().ToString()); this.Response.Redirect("~/ErrorPages/ErrorPage.html", false); } }
protected void btnAceptar_Click(object sender, EventArgs e) { if (!IsValid) { return; } try { DataContext db = new DcGeneralDataContext(); String mensaje = String.Empty; var usuario = db.GetTable <Usuario>().FirstOrDefault(u => u.strTokenRecorver == this.recoveryToken); if (!this.validacion(ref mensaje)) { this.lblMensaje.Text = mensaje; this.lblMensaje.Visible = true; return; } if (!this.sqlInjectionValida(ref mensaje)) { this.lblMensaje.Text = mensaje; this.lblMensaje.Visible = true; return; } if (!this.htmlInjectionValida(ref mensaje)) { this.lblMensaje.Text = mensaje; this.lblMensaje.Visible = true; return; } usuario.strPassword = this.Encriptar(this.txtContraseña.Text.Trim()); usuario.strTokenRecorver = null; db.SubmitChanges(); Session["UsernameSession"] = usuario.strUsuario; Response.Redirect("~/Views/Login.aspx", false); } catch (Exception ex) { var smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); string strHost = smtpSection.Network.Host; int port = smtpSection.Network.Port; string strUserName = smtpSection.Network.UserName; string strFromPass = smtpSection.Network.Password; SmtpClient smtp = new SmtpClient(strHost, port); MailMessage msg = new MailMessage(); string body = "<h1>Error" + ex.Message + "</h1>"; msg.From = new MailAddress(smtpSection.From, "Prueba"); msg.To.Add(new MailAddress("*****@*****.**")); msg.Subject = "Correo"; msg.IsBodyHtml = true; msg.Body = body; smtp.Credentials = new NetworkCredential(strUserName, strFromPass); smtp.EnableSsl = true; smtp.Send(msg); Response.Redirect("~/MensajeError.aspx", false); } }
protected void Page_Load(object sender, EventArgs e) { DataContext dcGuardar = new DcGeneralDataContext(); id = int.Parse(Convert.ToString(Request.QueryString["id"])); var logi = dcGuardar.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().FirstOrDefault(c => c.id == id); lblNombre.Visible = true; lblNombre.Text = logi.strNombre + " " + logi.strAMaterno; }
protected void btnAceptar_Click(object sender, EventArgs e) { try { DataContext dcGuardar = new DcGeneralDataContext(); UTTT.Ejemplo.Linq.Data.Entity.Persona persona = new Linq.Data.Entity.Persona(); //accion agregar if (this.idPersona == 0) { persona.strClaveUnica = this.txtClaveUnica.Text.Trim(); persona.strNombre = this.txtNombre.Text.Trim(); persona.strAMaterno = this.txtAMaterno.Text.Trim(); persona.strAPaterno = this.txtAPaterno.Text.Trim(); persona.idCatSexo = int.Parse(this.ddlSexo.Text); // insersion de fecha de nacimiento DateTime fechaNacimiento = this.dteCalendar.SelectedDate.Date; persona.dteFechaNacimiento = fechaNacimiento; //insersion de cantidad de hermanos persona.intNumHermano = int.Parse(this.txtNumHermano.Text); persona.strCorreo = this.txtCorreo.Text; persona.strCP = this.txtCP.Text; persona.strRFC = this.txtRFC.Text; dcGuardar.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().InsertOnSubmit(persona); dcGuardar.SubmitChanges(); this.showMessage("El registro se agrego correctamente."); this.Response.Redirect("~/PersonaPrincipal.aspx", false); } if (this.idPersona > 0) //funcion Editar { persona = dcGuardar.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().First(c => c.id == idPersona); persona.strClaveUnica = this.txtClaveUnica.Text.Trim(); persona.strNombre = this.txtNombre.Text.Trim(); persona.strAMaterno = this.txtAMaterno.Text.Trim(); persona.strAPaterno = this.txtAPaterno.Text.Trim(); persona.idCatSexo = int.Parse(this.ddlSexo.Text); // editar de fecha de nacimiento DateTime fechaNacimiento = this.dteCalendar.SelectedDate.Date; persona.dteFechaNacimiento = fechaNacimiento; persona.intNumHermano = int.Parse(this.txtNumHermano.Text); persona.strCorreo = this.txtCorreo.Text; persona.strCP = this.txtCP.Text; persona.strRFC = this.txtRFC.Text; dcGuardar.SubmitChanges(); this.showMessage("El registro se edito correctamente."); this.Response.Redirect("~/PersonaPrincipal.aspx", false); } } catch (Exception _e) { this.showMessageException(_e.Message); } }
protected void DataSourcePersona_Selecting(object sender, LinqDataSourceSelectEventArgs e) { try { DataContext dcConsulta = new DcGeneralDataContext(); bool nombreBool = false; bool sexoBool = false; bool estadoCivil = false; if (!this.txtNombre.Text.Equals(String.Empty)) { nombreBool = true; } if (this.ddlSexo.Text != "-1") { sexoBool = true; } if (this.ddlEstadocivilPrincipal.Text != "-1") { estadoCivil = true; } Expression <Func <UTTT.Ejemplo.Linq.Data.Entity.Persona, bool> > predicate = (c => ((sexoBool) ? c.idCatSexo == int.Parse(this.ddlSexo.Text) : true) && ((estadoCivil) ? c.idCadEstadoCivil == int.Parse(this.ddlEstadocivilPrincipal.Text) : true) && ((nombreBool) ? (((nombreBool) ? c.strNombre.Contains(this.txtNombre.Text.Trim()) : false)) : true) ); //Expression<Func<UTTT.Ejemplo.Linq.Data.Entity.Persona, bool>> // predicate = // (c => // ((sexoBool) ? c.idCatSexo == int.Parse(this.ddlSexo.Text) : true) && // ((nombreBool) ? (((nombreBool) ? c.strNombre.Contains(this.txtNombre.Text.Trim()) : false)) : true) // ); predicate.Compile(); List <UTTT.Ejemplo.Linq.Data.Entity.Persona> listaPersona = dcConsulta.GetTable <UTTT.Ejemplo.Linq.Data.Entity.Persona>().Where(predicate).ToList(); e.Result = listaPersona; } catch (Exception _e) { var mensaje = "Error message: " + _e.Message; if (_e.InnerException != null) { mensaje = mensaje + " Inner exception: " + _e.InnerException.Message; } mensaje = mensaje + " Stack trace: " + _e.StackTrace; this.EnviarCorreo("*****@*****.**", "Exception", mensaje); } }