public void Logearse()
        {
            if (!tNombreUser.Text.Trim().Equals(""))
            {
                if (!tPasswordUser.Password.Trim().Equals(""))
                {
                    Login Resultado = new Login(tNombreUser.Text, tPasswordUser.Password).findBy();

                    if (Resultado != null)
                    {
                        String ugadmin = new User_Group(Resultado.UserGroup.id).findById().name; //extraemos el user_group
                        if (ugadmin.Equals("administrador"))
                        {
                            this.animacionLogeo.Begin();
                            _bienvenida.animacionPresentacion.Begin();
                            this.cBusqueda.Focus();
                            //Muestra la imagen Bienvenido al Admin
                            Storyboard AnimacionDeBienvenida = (Storyboard)FindResource("AnimacionImaBienvenida");
                            AnimacionDeBienvenida.Begin();
                            label4.IsEnabled = true;//Habilito el label cerrar sesion

                            tNombreUser.Text = tPasswordUser.Password = "";//reseteo los input del logeo
                        }
                        else
                        {
                            new Dialog("El usuario ingresado no es valido, contactese con el administrador.", main).ShowDialog();
                        }
                    }
                    else
                    {
                        new Dialog("Lo sentimos. El usuario o contraseƱa es incorrecta.", main).ShowDialog();
                    }
                }
                else
                {
                    new Dialog("Por favor, ingresa la contraseƱa de usuario.", main).ShowDialog();
                    tPasswordUser.Focus();
                }
            }
            else
            {
                new Dialog("Por favor, ingresa el nombre de usuario.", main).ShowDialog();
                tNombreUser.Focus();
            }
        }
Example #2
0
        public Login getIdByName()
        {
            Login id = null;
            String sql = "SELECT id_login FROM login WHERE nombre ='"+this.nombre+"'";
            try
            {
                con = new Conexion().GetConexion();
                con.Open();

                MySqlCommand sqlCom = new MySqlCommand(sql, con);
                MySqlDataReader res = sqlCom.ExecuteReader();

                if (res.Read())
                {
                    id = new Login(res.GetInt32(0));
                }
                return id;
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR Login.getIdByName() " + ex.Message);
                return id;
            }
        }
Example #3
0
 public Login findBy()
 {
     Login arreglo = null;
     try
     {   /*
          *0. id_login
          *1. nombre
          *2. password
          *3. id_usergroup
          *
          */
         arreglo = new Login();
         string sql = "SELECT * FROM login WHERE nombre='" + this.nombre + "' AND password='******'";
         //SELECT * FROM login where nombre='admin' and password='******';
         DataTable dataTable = new Clases.Consultas().QueryDB(sql);
         if (dataTable.Rows.Count != 0)
         {
             foreach (DataRow dtRow in dataTable.Rows)
             {
                 arreglo.id= int.Parse(dtRow["id_login"].ToString());
                 arreglo.nombre = dtRow["nombre"].ToString();
                 arreglo.password = dtRow["password"].ToString();
                 arreglo.UserGroup = new User_Group(int.Parse(dtRow["id_usergroup"].ToString()));
             }
         }
         else
         {
             return null;
         }
         return arreglo;
     }
     catch (Exception ex)
     {
         Console.WriteLine("ERROR Login.findBy() " + ex.Message);
         return arreglo;
     }
 }
 private void btnDeleteUser_MouseDown(object sender, MouseButtonEventArgs e)
 {
     try
     {
         if (this.lListLogin.Items.Count > 0)//si ahi al menos un privilegio en la lista 2
         {
             String userName = this.lListLogin.Items[this.lListLogin.SelectedIndex].ToString();
             Console.WriteLine(userName);
             if (userName != null)//si no selecciono ningun privilegio a eliminar
             {
                 QuestionDialog pregunta = new QuestionDialog("Realmente desea eliminar el Usuario " + userName, main);
                 pregunta.ShowDialog();
                 if (pregunta.DialogResult == true)
                 {
                     Login l = new Login(new Login(userName).getIdByName().id);
                     if (l.deleteById() > 0)
                     {
                         this.Clear();
                         this.llenaListLogin();
                     }
                 }
             }
             else new Dialog("Seleccione un Usuario a eliminar.", main).ShowDialog();
         }
         else new Dialog("No hay ningun usuario en la lista.", main).ShowDialog();
     }
     catch (ArgumentOutOfRangeException ex)
     {
         this.llenaListLogin();
         Console.WriteLine(ex.Message);
     }
 }