public JsonResult RegistrarNuevoUsuario() { string res = "false"; try { OperacionesUsuarios opUsers = new OperacionesUsuarios(); string username = Request["nombreUsuario"]; string pass = Request["password"]; string pnom = Request["pnombre"]; string snom = Request["snombre"]; string apellidoPat = Request["apat"]; string apmat = Request["amat"]; DateTime fecha = DateTime.Now; int tipo = 2; string email = Request["email"]; opUsers.Guardar(username, pass, pnom, snom, apellidoPat, apmat, fecha, tipo, email); res = "true"; } catch (Exception ex) { res = ex.Message; } return(Json(res)); }
private void btnModificar_Click(object sender, EventArgs e) { if (txtID.Text != "" && txtUsuario.Text != "" && txtContrasenia.Text != "" && txtApellidoNombre.Text != "" && cbxRol.Text != "" && cbxEstado.Text != "") { if (idUsuarioExistente == 0 || idUsuarioExistente.ToString() == txtID.Text) { Usuario oUsuario = new Usuario(); //CAPTURO LOS DATOS DEL FORMULARIO oUsuario.Usu_id = int.Parse(txtID.Text); oUsuario.Usu_nombreUsuario = txtUsuario.Text; oUsuario.Usu_contraseña = txtContrasenia.Text; oUsuario.Usu_apellidoNombre = txtApellidoNombre.Text; oUsuario.Rol_codigo = (string)cbxRol.SelectedValue; oUsuario.Usu_estado = cbxEstado.Text; OperacionesUsuarios.ModificarUsuario(oUsuario); CargarGrilla(); } else { MessageBox.Show("El nombre de usuario ingresado se encuentra en uso en el UserID: " + idUsuarioExistente.ToString() + "\n\nPor favor ingrese otro diferente.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); //txtUsuario.Focus(); } } else { MessageBox.Show("Debe completar todos los datos", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnIngresar_Click(object sender, EventArgs e) { Usuario oUsuario = new Usuario(); string usuario = txtUsuario.Text; string contraseña = txtContrasenia.Text; oUsuario = OperacionesUsuarios.TraerUsuario(usuario, contraseña); if (oUsuario != null) { if (oUsuario.Usu_estado == "ACTIVO") { MessageBox.Show("Bienvenido al Sistema: " + oUsuario.Usu_apellidoNombre, "Bienvenida", MessageBoxButtons.OK, MessageBoxIcon.Information); FrmPrincipal oFrmPrincipal = new FrmPrincipal(oUsuario); //me da acceso al principal this.Visible = false; oFrmPrincipal.Show(); } else { MessageBox.Show("NO PUEDE INGRESAR AL SISTEMA \n\n EL USUARIO SE ENCUENTRA INACTIVO!", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("EL USUARIO O CONTRASEÑA ES INCORRECTO!", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);//muestra un mnj } }
private void CargarGrilla() { cbxRol.DataSource = OperacionesUsuarios.TraerRoles(); cbxRol.DisplayMember = "ROL_Descripcion"; cbxRol.ValueMember = "ROL_Codigo"; dgvUsuarios.DataSource = OperacionesUsuarios.TraerUsuarios(); }
private void txtUsuario_Leave(object sender, EventArgs e) { idUsuarioExistente = OperacionesUsuarios.TraerIdUsuarioSegunNombreUsuario(txtUsuario.Text); if (idUsuarioExistente != 0) { MessageBox.Show("El nombre de usuario ingresado se encuentra en uso en el UserID: " + idUsuarioExistente.ToString() + "\n\nPor favor ingrese otro diferente.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public JsonResult validarLogin() { string res = "false"; OperacionesUsuarios opUsers = new OperacionesUsuarios(); string username = Request["username"]; string password = Request["password"]; int id = 0; int tipo = 0; foreach (Usuarios user in opUsers.TraerTodo()) { if (user.nombreUsuario.Equals(username) && user.password.Equals(password)) { id = user.idUsuario; tipo = user.tipoUsuario.Value; res = "true"; } } if (res.Equals("true")) { string identity = string.Empty; FormsAuthentication.SetAuthCookie(username, false); if (tipo == 1) { identity = "admin"; if (!Roles.RoleExists(identity)) { Roles.CreateRole(identity); } if (!Roles.IsUserInRole(username, identity)) { Roles.AddUserToRole(username, identity); } } else if (tipo == 2) { identity = "cliente"; if (!Roles.RoleExists("cliente")) { Roles.CreateRole(identity); } if (!Roles.IsUserInRole(username, identity)) { Roles.AddUserToRole(username, identity); } } Session["validUser"] = true; Session["idUsuario"] = id; res = "true" + tipo; } return(Json(res)); }
public JsonResult ExisteUsuario(string username, string password) { string res = "false"; OperacionesUsuarios opusu = new OperacionesUsuarios(); foreach (Usuarios user in opusu.TraerTodo()) { if (username == user.nombreUsuario && password == user.password) { return(Json("true")); } } return(Json(res)); }
public string Borrar(int id, string bd) { string res = "false"; try { if (bd == "Mensajes") { OperacionesMensajes opmen = new OperacionesMensajes(); opmen.Borrar(id); } else if (bd == "Noticias") { OperacionesNoticias opnot = new OperacionesNoticias(); opnot.Borrar(id); } else if (bd == "Productos") { OperacionesProductos oprod = new OperacionesProductos(); oprod.Borrar(id); } else if (bd == "Usuarios") { OperacionesUsuarios opusu = new OperacionesUsuarios(); opusu.Borrar(id); } else if (bd == "Ventas") { OperacionesVentas opven = new OperacionesVentas(); opven.Borrar(1); } else { res = "no hay ningun valor"; } res = "true"; } catch (Exception e) { } return(res); }
private void btnEliminar_Click(object sender, EventArgs e) { if (dgvUsuarios.CurrentRow != null) { //Valida si está en uso - En este caso solo avisa pero deja seguir int nroVenta = OperacionesVentas.TraerNROVentaSegunParametro(txtID.Text, "USUARIO"); if (nroVenta != 0) { MessageBox.Show("El usuario seleccionado se encuentra en uso en la Venta N°: " + nroVenta , "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } var respuesta = MessageBox.Show("¿Desea ELIMINAR el usuario seleccionado?\n(Baja Logica - Estado:INACTIVO)", "Confirmacion", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (respuesta.ToString() == "Yes") { int id = int.Parse(txtID.Text); OperacionesUsuarios.EliminarUsuario(id); CargarGrilla(); } } }
private void btnFiltrar_Click(object sender, EventArgs e) { dgvUsuarios.DataSource = OperacionesUsuarios.TraerUsuarios(txtFiltrar.Text); }
public JsonResult Guardar() { string res = "false"; try { string bd = Request["bd"]; if (bd == "Mensajes") { string texto = texto = Request["textoMensaje"]; string date = DateTime.Now.ToString(); string emailR = Request["emailRemitente"]; OperacionesMensajes opmen = new OperacionesMensajes(); opmen.Guardar(texto, date, emailR); } else if (bd == "Productos") { string nom = Request["nombreProducto"]; int precio = int.Parse(Request["precio"]); int stock = int.Parse(Request["stock"]); OperacionesProductos opprod = new OperacionesProductos(); opprod.Guardar(nom, precio, stock); } else if (bd == "Noticias") { DateTime fecha = DateTime.Now; string texto = Request["textoNoticia"]; int idAutor = int.Parse(Request["idAutor"]); OperacionesNoticias opnot = new OperacionesNoticias(); opnot.Guardar(fecha, texto, idAutor); } else if (bd == "Usuarios") { string nomusu = Request["nombreUsuario"]; string password = Request["password"]; string pnombre = Request["pnombre"]; string snombre = Request["snombre"]; string apat = Request["apat"]; string apmat = Request["apmat"]; DateTime fecha = DateTime.Now; int tipo = 0; if (Request["tipo"].ToString() == "Administrador") { tipo = 1; } else if (Request["tipo"].ToString() == "Cliente") { tipo = 2; } else { throw new Exception("tipo de usuario no valido"); } string email = Request["email"]; OperacionesUsuarios opusu = new OperacionesUsuarios(); opusu.Guardar(nomusu, password, pnombre, snombre, apat, apmat, fecha, tipo, email); } else if (bd == "Ventas") { OperacionesVentas opven = new OperacionesVentas(); int iduser = int.Parse(Request["idUsuario"]); int producto = int.Parse(Request["idProducto"]); if (!opven.Guardar(iduser, producto, DateTime.Now)) { throw new Exception("no se guardo"); } } res = "true"; } catch (Exception e) { res = e.Message; } return(Json(res)); }
public JsonResult Actualizar() { string res = "false"; try { string bd = Request["bd"]; if (bd == "Mensajes") { int id = int.Parse(Request["idMensaje"]); string texto = Request["textoMensaje"]; string fecha = Request["fecha"].ToString(); string email = Request["emailRemitente"].ToString();; OperacionesMensajes opmen = new OperacionesMensajes(); opmen.Modificar(id, texto, fecha, email); } else if (bd == "Noticias") { int id = int.Parse(Request["idNoticia"]); string texto = Request["textoNoticia"].ToString(); DateTime fecha = DateTime.Parse(Request["FechaNoticia"].ToString()); int idAut = int.Parse(Request["idAutor"]); OperacionesNoticias opnot = new OperacionesNoticias(); if (!opnot.Modificar(id, fecha, texto, idAut)) { throw new Exception("Error al actualizar"); } } else if (bd == "Productos") { int id = int.Parse(Request["idProducto"]); string nom = Request["nombreProducto"]; int precio = int.Parse(Request["precio"]); int stock = int.Parse(Request["stock"]); OperacionesProductos oprod = new OperacionesProductos(); oprod.Modificar(id, nom, precio, stock); } else if (bd == "Usuarios") { int id = int.Parse(Request["idUsuario"]); string nom = Request["nombreUsuario"].ToString(); string password = Request["password"].ToString(); string pnombre = Request["pnombre"].ToString(); string snombre = Request["snombre"].ToString(); string apat = Request["apat"].ToString(); string amat = Request["amat"].ToString(); DateTime fechaRegistro = DateTime.Parse(Request["fecha"].ToString()); int tipoUsuario = int.Parse(Request["tipoUsuario"]); string email = Request["email"].ToString(); OperacionesUsuarios opusu = new OperacionesUsuarios(); opusu.Modificar(id, nom, password, pnombre, snombre, apat, amat, fechaRegistro, tipoUsuario, email); } else if (bd == "Ventas") { int id = int.Parse(Request["idVenta"]); int idUsuario = int.Parse(Request["idUsuario"]); int idProd = int.Parse(Request["idProducto"]); DateTime dt = DateTime.Parse(Request["fecha"].ToString()); OperacionesVentas opven = new OperacionesVentas(); if (!opven.Modificar(id, idUsuario, idProd, dt)) { throw new Exception("problema en modificar"); } } else { res = "no hay ningun valor"; } res = "true"; } catch (Exception ex) { res = ex.Message; } return(Json(res)); }