/// <summary> /// carga en una lista todos los elementos del plan contable registrados /// </summary> /// <param name="lista"></param> private void cargarElementoContableRegistrado(List <ElementoPlanContable> lista) { lista.Clear(); conectar(); String consulta = "select * from elementosDelPlanContables where registrado = true ORDER BY numeroIdentificador COLLATE NOCASE ASC"; SqliteCommand command = new SqliteCommand(consulta, Connection); try { SqliteDataReader lector = command.ExecuteReader(); while (lector.Read()) { bool registrado = lector.GetBoolean(0); string id = lector.GetString(1); string nombre = lector.GetString(2); ElementoPlanContable elementoPlanContable = new ElementoPlanContable(registrado, id, nombre); lista.Add(elementoPlanContable); } command.Connection.Close(); lector.Close(); } catch (Exception e) { throw new Exception("Error: " + e); } finally { close(); } }
private void buttonBuscar_Click(object sender, EventArgs e) { string numero = this.textBoxIndex.Text; if (esNumeral(numero)) { this.CodigoBuscado = numero; // hay que verificar si existe ElementoPlanContable elemento = elementosPlanContables.Find(q => q.numeroIdentificador == numero); if (elemento != null) { Conexion conexion = new Conexion(); elemento = conexion.buscarElementoPlanContable(numero); cargarElementoEnCampos(elemento); habilitarAgregar(true); this.groupBox.Enabled = true; this.buttonBorrar.Enabled = true; if (conexion.yaTieneAsiento(CodigoBuscado)) { this.checkBox1.Enabled = false; //no dejo que lo editen } } else { mostrarMensajeError("el indice ingresado no existe"); } } else { mostrarMensajeError("El indice ingresado no es numeral."); } }
public void cargarElementoEnCampos(ElementoPlanContable elemento) { Conexion conexion = new Conexion(); this.textNombre.Text = elemento.nombre; this.comboBoxTipo.SelectedIndex = int.Parse(elemento.numeroIdentificador.ElementAt(0).ToString()) - 1; this.textNumero.Text = elemento.numeroIdentificador.Remove(0, 1); this.checkBox1.Checked = elemento.registrable; }
/// <summary> /// retorna el elemento del plan contable que tenga el index que introducimos /// </summary> /// <param name="index"> indice que queremos buscar </param> /// <returns>retorna un elemento contable que exista en la base de datos</returns> public ElementoPlanContable buscarElementoPlanContable(string numeroIdentificador) { try { conectar(); String consulta = "select * from elementosDelPlanContables where numeroIdentificador = " + numeroIdentificador; SqliteCommand command = new SqliteCommand(consulta, Connection); try { SqliteDataReader lector = command.ExecuteReader(); while (lector.Read()) { bool registrado = lector.GetBoolean(0); string id = lector.GetString(1); string nombre = lector.GetString(2); ElementoPlanContable elementoPlanContable = new ElementoPlanContable(registrado, id, nombre); return(elementoPlanContable); } command.Connection.Close(); lector.Close(); } catch (Exception e) { throw new Exception("Error al ejecutar codigo en la base de datos" + e); } } catch (Exception e) { throw new Exception("no se pudo realizar la coneccion a la base de datos" + e); } finally { close(); } return(null); }