public BuscarControl() { InitializeComponent(); try { equipos = new Conexion().getEquipos(); ColumnEquipo.DataSource = equipos; ColumnEquipo.DisplayMember = "Descripcion"; ColumnEquipo.ValueMember = "ID"; comboBoxEquipo.DataSource = equipos; comboBoxEquipo.DisplayMember = "Descripcion"; comboBoxEquipo.ValueMember = "ID"; aulaTipos = new Conexion().getAulaTipos(); AulaTipo aulaTipoCualquiera = new AulaTipo(); aulaTipoCualquiera.Id = 0; aulaTipoCualquiera.Descripcion = "Cualquiera"; aulaTipos.Add(aulaTipoCualquiera); comboBoxTipoAula.DataSource = aulaTipos; comboBoxTipoAula.DisplayMember = "Descripcion"; comboBoxTipoAula.ValueMember = "Id"; comboBoxTipoAula.SelectedValue = 0; dataGridViewResultado.AutoGenerateColumns = false; ColumnEdificio.DataPropertyName = "NombreEdificio"; ColumnAula.DataPropertyName = "Referencia"; ColumnCapacidad.DataPropertyName = "Capacidad"; ColumnAulaTipo.DataPropertyName = "NombreTipo"; dateTimeInputInicio.Value = DateTime.Now; dateTimeInputFin.Value = DateTime.Now.AddHours(2); } catch { } }
public void Borrar() { AulaTipo AulaTipo = new AulaTipo(); AulaTipo.Id = Convert.ToInt32(this.txtId.Text); db.borrarAulaTipo(AulaTipo); cargarDataGrid(); edicion(false); }
public bool Guardar() { edicion(false); if (this.txtId.Text == "") { /*------------INSERTAR FACULTAD----------------*/ if (this.txtDescripcion.Text != "") { AulaTipo AulaTipo = new AulaTipo(); AulaTipo.Descripcion = this.txtDescripcion.Text; insertAulaEstado(AulaTipo); this.dgAulaTipos.Enabled = true; cargarDataGrid(); this.txtId.DataBindings.Add("Text", AulaTiposBindingSource, "Id"); this.txtDescripcion.DataBindings.Add("Text", AulaTiposBindingSource, "Descripcion"); this.AulaTiposBindingSource.MoveLast(); return true; } else { MessageBox.Show("Descripción no puede estar vacio.", "Error", MessageBoxButtons.OK); return false; } /*---------FIN INSERTAR FACULTAD----------------*/ } else { /*------------Actualizar FACULTAD----------------*/ if (this.txtDescripcion.Text != "") { AulaTipo AulaTipo = new AulaTipo(); AulaTipo.Id = Convert.ToInt32(this.txtId.Text); AulaTipo.Descripcion = this.txtDescripcion.Text; actualizarAulaTipo(AulaTipo); this.dgAulaTipos.Enabled = true; cargarDataGrid(); return true; } else { MessageBox.Show("Descripción no puede estar vacio","Error",MessageBoxButtons.OK); return false; } /*---------FIN Actualizar FACULTAD----------------*/ } }
public Boolean actualizarAulaTipo(AulaTipo AulaTipo) { this.connection.Open(); this.command = this.connection.CreateCommand(); this.transaction = this.connection.BeginTransaction(); this.command.Connection = this.connection; this.command.Transaction = this.transaction; try { this.command.CommandText = "Update aula_tipo set descripcion=@descripcion where id_tipo=@id;"; this.command.Parameters.Add(new SqlParameter("@descripcion", SqlDbType.NVarChar, 50)); this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int)); this.command.Parameters["@descripcion"].Value = AulaTipo.Descripcion; this.command.Parameters["@id"].Value = AulaTipo.Id; this.command.ExecuteNonQuery(); this.transaction.Commit(); return true; } catch (Exception e) { try { this.transaction.Rollback(); throw new Exception("Error al Actualizar." + e.Message); return false; } catch (Exception ex) { throw new Exception("Error al rollback accion." + ex.Message); return false; } } finally { this.connection.Close(); } }
public Boolean insertAulaTipo(AulaTipo AulaTipo) { this.connection.Open(); this.command = this.connection.CreateCommand(); this.transaction = this.connection.BeginTransaction(); this.command.Connection = this.connection; this.command.Transaction = this.transaction; try { this.command.CommandText = "insert into aula_tipo(Descripcion) values(@descripcion);" + "SELECT CAST(scope_identity() AS int)"; this.command.Parameters.Add(new SqlParameter("@descripcion", SqlDbType.NVarChar, 50)); this.command.Parameters["@descripcion"].Value = AulaTipo.Descripcion; this.lastUpdated = this.command.ExecuteScalar().ToString(); this.transaction.Commit(); return true; } catch (Exception e) { try { transaction.Rollback(); throw new Exception("Error al insertar registro. " + e.Message); return false; } catch (Exception ex) { throw new Exception("Error al roolback accion. " + ex.Message); } } finally { this.connection.Close(); } }
/*--------------------FIN CATALOGO Grupos------------------------*/ /*--------------------Catalogo de AulaTipos-------------------------*/ public List<AulaTipo> getAulaTipos() { SqlDataReader dataReader = null; List<AulaTipo> AulaTipos = new List<AulaTipo>(); try { string query = "Select * from aula_tipo"; command = new SqlCommand(query, connection); command.Connection.Open(); dataReader = command.ExecuteReader(); while (dataReader.Read()) { AulaTipo edi = new AulaTipo(); edi.Id = Convert.ToInt32(dataReader["id_tipo"].ToString()); edi.Descripcion = dataReader["descripcion"].ToString(); AulaTipos.Add(edi); } return AulaTipos; } catch (Exception e) { throw new Exception("Error al obtener datos de AulaTipo. " + e.Message.ToString()); } finally { command.Connection.Close(); } }
public Boolean borrarAulaTipo(AulaTipo AulaTipo) { this.connection.Open(); this.command = this.connection.CreateCommand(); this.transaction = this.connection.BeginTransaction(); this.command.Connection = this.connection; this.command.Transaction = this.transaction; try { this.command.CommandText = "delete from aula_tipo where id_tipo=@id;"; this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int)); this.command.Parameters["@id"].Value = AulaTipo.Id; this.command.ExecuteNonQuery(); this.transaction.Commit(); return true; } catch (Exception e) { try { this.transaction.Rollback(); throw new Exception("Error al borrar registro. " + e.Message); return false; } catch (Exception ex) { throw new Exception("Error al rollback acción. " + ex.Message); return false; } } finally { this.connection.Close(); } }
private bool insertAulaEstado(AulaTipo AulaEstado) { try { db.insertAulaTipo(AulaEstado); } catch (Exception e) { MessageBox.Show(e.Message); } return true; }
private bool actualizarAulaTipo(AulaTipo AulaTipo) { try { db.actualizarAulaTipo(AulaTipo); } catch (Exception e) { MessageBox.Show(e.Message); } return true; }