private void butLeerEn_Click(object sender, EventArgs e) { try { if (posi == 0) { int posicion = Convert.ToInt32(Microsoft.VisualBasic.Interaction.InputBox("Ingrese la posicion del juego a buscar: ")); JuegoNodo jj = servicioLista.buscarPorPosicion(posicion); posi = posicion; grillaListas.Rows[posi - 1].Selected = true; grillaListas.CurrentCell = grillaListas.Rows[posi - 1].Cells[0]; } else { grillaListas.Rows[posi - 1].Selected = false; grillaListas.CurrentCell = grillaListas.Rows[0].Cells[0]; int posicion = Convert.ToInt32(Microsoft.VisualBasic.Interaction.InputBox("Ingrese la posicion del juego a buscar: ")); JuegoNodo jj = servicioLista.buscarPorPosicion(posicion); posi = posicion; grillaListas.Rows[posi - 1].Selected = true; grillaListas.CurrentCell = grillaListas.Rows[posi - 1].Cells[0]; } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
public void volcar() { try { hayRutaVolcado(); sr = new StreamReader(rutaVolcado); string linea = sr.ReadLine(); while (linea != null) { string[] datos = linea.Split(','); string titulo = datos[0].Trim(); string genero = datos[1].Trim(); int precio = Convert.ToInt32(datos[2].Trim()); DateTime dt = DateTime.Parse(datos[3]); int estado = Convert.ToInt32(datos[4]); if (estado == JuegoNodo.ACTIVO) { JuegoNodo jj = new JuegoNodo(precio, titulo, genero, dt, estado); agregarInicio(jj); } linea = sr.ReadLine(); } sr.Close(); } catch (Exception ee) { sr.Close(); throw ee; } }
public int buscarPorTitulo(string pTitulo) { int contador = 0; int result = -1; if (verificarCabeza() == true) { throw new Exception("No hay ningun juego"); } else if (pTitulo == null || pTitulo == "") { throw new Exception("El titulo no debe estar vacio"); } else { JuegoNodo temp = cabeza; while (temp != null) { contador++; if (temp.darTitulo().ToLower().Equals(pTitulo.ToLower())) { result = contador; break; } temp = temp.getSiguiente(); } if (result == -1) { throw new Exception("No se ha econtrado un juego con el titulo: " + pTitulo); } } return(result); }
public JuegoNodo buscarPorPosicion(int pos) { JuegoNodo jn = null; int contador = 0; if (verificarCabeza()) { throw new Exception("No hay ningun juego"); } else if (pos <= 0) { throw new Exception("La posicion especificada no es valida debe ser mayor a cero"); } else if (pos > numeroRegistros) { throw new Exception("La posicion no existe, existen actualmente: " + numeroRegistros + " Registros"); } else { JuegoNodo temp = cabeza; while (temp != null) { contador++; if (contador == pos) { jn = temp; break; } temp = temp.getSiguiente(); } } return(jn); }
public void recorrer() { JuegoNodo nodo = cabeza; while (nodo != null) { nodo = nodo.getSiguiente(); } }
public void eliminar(int posicion) { int contador = 0; if (verificarCabeza() == true) { throw new Exception("No hay ningun juego"); } else if (posicion <= 0) { throw new Exception("La posicion especificada no es valida debe ser mayor a cero"); } else if (posicion > numeroRegistros) { throw new Exception("La posicion no existe, existen actualmente: " + numeroRegistros + " Registros"); } else if (posicion == 1) { cabeza = cabeza.getSiguiente(); if (cabeza != null) { cabeza.setAnterior(null); } numeroRegistros--; } else { JuegoNodo temp = cabeza; while (temp != null) { contador++; if (contador == posicion) { if (temp.getSiguiente() != null) { temp.getSiguiente().setAnterior(temp.getAnterior()); temp.getAnterior().setSiguiente(temp.getSiguiente()); } else { temp.getAnterior().setSiguiente(null); } numeroRegistros--; break; } temp = temp.getSiguiente(); } } }
public void agregarInicio(JuegoNodo juego) { if (verificarCabeza() == true) { cabeza = juego; numeroRegistros++; } else { cabeza.setAnterior(juego); juego.setSiguiente(cabeza); cabeza = juego; numeroRegistros++; } }
public void modificarPrecio(int precio, int posicion) { try { if (JuegoNodo.verificarPrecio(precio) == false) { throw new Exception("El precio no es valido"); } JuegoNodo juego = buscarPorPosicion(posicion); juego.cambiarPrecio(precio); } catch (Exception ee) { throw ee; } }
public JuegoNodo(int pPrecio, string pTitulo, string pGenero, DateTime pFecha, int pEstado) { if (pPrecio >= 0 && pPrecio <= 999999999) { precio = pPrecio; } else { throw new Exception("El precio debe ser mayor o igual a cero y menor igual a 999999999"); } if (pTitulo != null && pTitulo != "") { titulo = pTitulo; } else { throw new Exception("El juego debe tener un titulo"); } if (pGenero != null && pGenero != "") { genero = pGenero; } else { throw new Exception("El juego debe tener un genero"); } if (pFecha != null && pFecha.CompareTo(DateTime.Today) <= 0) { fecha = pFecha; } else { throw new Exception("La fecha no puede ser posterior al dia actual"); } if (pEstado >= 0 && pEstado <= 1) { estado = pEstado; } else { throw new Exception("Solo hay dos estados 0 y 1"); } siguiente = null; anterior = null; }
private void actualizaGrilla() { grillaListas.Rows.Clear(); JuegoNodo cabeza = servicioLista.getCabeza(); int i = 0; while (cabeza != null) { i++; string[] datos = new string[5]; datos[0] = i.ToString(); datos[1] = cabeza.darTitulo(); datos[2] = cabeza.darGenero(); datos[3] = cabeza.darPrecio().ToString(); datos[4] = cabeza.darFecha().ToShortDateString(); grillaListas.Rows.Add(datos); cabeza = cabeza.getSiguiente(); } }
public void ordenarPorPrecio() { if (verificarCabeza() == true) { throw new Exception("No hay elementos para ordenar"); } else { JuegoNodo puntero1 = cabeza; while (puntero1 != null) { JuegoNodo minimo = puntero1; JuegoNodo puntero2 = puntero1.getSiguiente(); while (puntero2 != null) { if (puntero2.darPrecio() < minimo.darPrecio()) { minimo = puntero2; } puntero2 = puntero2.getSiguiente(); } if (minimo != puntero1) { string tituloMinimo = minimo.darTitulo(); string generoMinimo = minimo.darGenero(); int precioMinimo = minimo.darPrecio(); DateTime fechaMinimo = minimo.darFecha(); minimo.cambiarTitulo(puntero1.darTitulo()); minimo.cambiarGenero(puntero1.darGenero()); minimo.cambiarPrecio(puntero1.darPrecio()); minimo.cambiarFecha(puntero1.darFecha()); puntero1.cambiarTitulo(tituloMinimo); puntero1.cambiarGenero(generoMinimo); puntero1.cambiarPrecio(precioMinimo); puntero1.cambiarFecha(fechaMinimo); } puntero1 = puntero1.getSiguiente(); } } }
private void button1_Click(object sender, EventArgs e) { try { string titulo = txtTitulo.Text; string genero = listBoxGenero.Text; int precio = Convert.ToInt32(txtPrecio.Text); DateTime dt = DateTime.Parse(dateTimePicker1.Text); JuegoNodo juego = new JuegoNodo(precio, titulo, genero, dt, Juego.ACTIVO); servicioLista.agregarInicio(juego); actualizaGrilla(); reiniciarCampos(); } catch (FormatException fe) { MessageBox.Show("En el precio solo se puede ingresar enteros"); } catch (Exception ee) { MessageBox.Show(ee.Message); } }
public void eliminarNNodos(int CantidadaEliminar) { if (verificarCabeza() == true) { throw new Exception("No hay ningun juego"); } else if (CantidadaEliminar <= 0) { throw new Exception("La cantidad especificada no es valida debe ser mayor a cero"); } else if (CantidadaEliminar > numeroRegistros) { throw new Exception("La cantidad a eliminar de ser menor o igual a: " + numeroRegistros); } else { int contador = 0; int posicion = 1; if (numeroRegistros != CantidadaEliminar) { posicion = numeroRegistros - CantidadaEliminar; } JuegoNodo temp = cabeza; while (temp != null) { contador++; if (contador == posicion) { temp.setSiguiente(null); numeroRegistros = numeroRegistros - CantidadaEliminar; break; } temp = temp.getSiguiente(); } } }
public ServicioLista() { cabeza = null; numeroRegistros = 0; }
public void setAnterior(JuegoNodo pAnterior) { anterior = pAnterior; }
public void setSiguiente(JuegoNodo pSiguiente) { siguiente = pSiguiente; }