示例#1
0
        protected void crearUsuario(object sender, EventArgs e)
        {
            try
            {
                List <Usuario> existen = iUs.getByCriterio <Usuario>("", "", txt_username.Text);
                if (existen.Count == 0)
                {
                    if (ddl_perfil.SelectedValue == "0")
                    {
                        String msj = "Seleccione un perfil.";
                        this.Page.Response.Write("<script language='JavaScript'>window.alert('" + msj + "');</script>");
                    }
                    else
                    {
                        usuario       = new Usuario();
                        usuario.login = txt_username.Text.Trim();
                        password      = txt_password.Text.Trim();
                        String hash = Encripta.EncodePassword(string.Concat(usuario.login, password));
                        usuario.contraseña    = hash;
                        usuario.fechaVigencia = DateTime.Now.Date;
                        //verificar el tipo del estado
                        usuario.estado = true;
                        Persona p = iPers.getByCriterio <Persona>("", "", txt_persona.Text).First <Persona>();
                        usuario.codigoPersona = p.codigoPersona;
                        usuario.codigoUsuario = generarCodigoUsuario();
                        usuario.mail          = txt_correo.Text;
                        usuario.recibeAlertas = cheq_alerta.Checked;

                        perf           = iPerf.getPorCriterio <Perfil>(ddl_perfil.SelectedValue.ToString()).First <Perfil>();
                        usuario.perfil = perf.codigoPerfil;

                        iUs.save <Usuario>(usuario);
                        String msj = "El usuario ha sido creado correctamente.";
                        Intermediario.confirmarCambios();
                        this.Page.Response.Write("<script language='JavaScript'>window.alert('" + msj + "');</script>");

                        txt_apellido.Text   = "";
                        txt_codigo.Text     = "";
                        txt_nombre.Text     = "";
                        txt_password.Text   = "";
                        txt_persona.Text    = "";
                        txt_username.Text   = "";
                        txt_correo.Text     = "";
                        cheq_alerta.Checked = false;
                    }
                }
                else
                {
                    String msj = "El nombre de usuario ingresado ya existe. Por favor ingrese otro usuario.";
                    this.Page.Response.Write("<script language='JavaScript'>window.alert('" + msj + "');</script>");
                    txt_username.Text = "";
                    txt_password.Text = "";
                }
            }
            catch (Exception) {
            }
        }
        protected void gvUsuario_Actualizar(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row = gv_Usuarios.Rows[e.RowIndex];

            gv_Usuarios.EditIndex = -1;
            String codigo = row.Cells[1].Text;
            String nombre = row.Cells[2].Text;
            //Encripta la contraseña 123456
            // String cel1 = ((TextBox)(row.Cells[2].Controls[0])).Text;
            String cel2     = ((TextBox)(row.Cells[3].Controls[0])).Text;
            String password = Encripta.EncodePassword(String.Concat(nombre, cel2));   //Encripta.EncodePassword(string.Concat(,"123456"));

            DropDownList comboPerfil = (DropDownList)gv_Usuarios.Rows[e.RowIndex].Cells[5].FindControl("ddl_perfiles");
            String       perfil      = comboPerfil.SelectedValue;

            per = iPerf.getPorCriterio <Perfil>(perfil).First();

            DropDownList comboEstado = (DropDownList)gv_Usuarios.Rows[e.RowIndex].Cells[4].FindControl("ddl_estados");
            String       estado      = comboEstado.SelectedItem.Text;

            String email = ((TextBox)(row.Cells[6].Controls[0])).Text;

            DropDownList comboAlertas = (DropDownList)gv_Usuarios.Rows[e.RowIndex].Cells[7].FindControl("ddl_alertas");
            String       alerta       = comboAlertas.SelectedItem.Text;

            ActualizarUsuarios(nombre, password, estado, per.codigoPerfil, email, alerta);
            llenar(nombre);
        }