public void Borrar() { AulaTipoUso AulaTipoUso = new AulaTipoUso(); AulaTipoUso.Id = Convert.ToInt32(this.txtId.Text); db.borrarAulaTipoUso(AulaTipoUso); cargarDataGrid(); edicion(false); }
public bool Guardar() { edicion(false); if (this.txtId.Text == "") { /*------------INSERTAR FACULTAD----------------*/ if (this.txtDescripcion.Text != "") { AulaTipoUso AulaTipoUso = new AulaTipoUso(); AulaTipoUso.Descripcion = this.txtDescripcion.Text; insertAulaTipoUso(AulaTipoUso); this.dgAulaTipoUsos.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 != "") { AulaTipoUso AulaTipoUso = new AulaTipoUso(); AulaTipoUso.Id = Convert.ToInt32(this.txtId.Text); AulaTipoUso.Descripcion = this.txtDescripcion.Text; actualizarAulaTipoUso(AulaTipoUso); this.dgAulaTipoUsos.Enabled = true; cargarDataGrid(); return true; } else { MessageBox.Show("Descripción no puede estar vacio","Error",MessageBoxButtons.OK); return false; } /*---------FIN Actualizar FACULTAD----------------*/ } }
public Boolean actualizarAulaTipoUso(AulaTipoUso AulaTipoUso) { 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_uso set descripcion=@descripcion where id_tipo_uso=@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 = AulaTipoUso.Descripcion; this.command.Parameters["@id"].Value = AulaTipoUso.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 insertAulaTipoUso(AulaTipoUso AulaTipoUso) { 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_uso(Descripcion) values(@descripcion);" + "SELECT CAST(scope_identity() AS int)"; this.command.Parameters.Add(new SqlParameter("@descripcion", SqlDbType.NVarChar, 50)); this.command.Parameters["@descripcion"].Value = AulaTipoUso.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 AulaTipos------------------------*/ /*--------------------Catalogo de AulaTipoUsoUsos-------------------------*/ public List<AulaTipoUso> getAulaTipoUso() { SqlDataReader dataReader = null; List<AulaTipoUso> AulaTipoUsoUsos = new List<AulaTipoUso>(); try { string query = "Select * from aula_tipo_uso"; command = new SqlCommand(query, connection); command.Connection.Open(); dataReader = command.ExecuteReader(); while (dataReader.Read()) { AulaTipoUso edi = new AulaTipoUso(); edi.Id = Convert.ToInt32(dataReader["id_tipo_uso"].ToString()); edi.Descripcion = dataReader["descripcion"].ToString(); AulaTipoUsoUsos.Add(edi); } return AulaTipoUsoUsos; } catch (Exception e) { throw new Exception("Error al obtener datos de AulaTipoUso. " + e.Message.ToString()); } finally { command.Connection.Close(); } }
public Boolean borrarAulaTipoUso(AulaTipoUso AulaTipoUso) { 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_uso where id_tipo_uso=@id;"; this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int)); this.command.Parameters["@id"].Value = AulaTipoUso.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 insertAulaTipoUso(AulaTipoUso AulaTipoUso) { try { db.insertAulaTipoUso(AulaTipoUso); } catch (Exception e) { MessageBox.Show(e.Message); } return true; }
private bool actualizarAulaTipoUso(AulaTipoUso AulaTipoUso) { try { db.actualizarAulaTipoUso(AulaTipoUso); } catch (Exception e) { MessageBox.Show(e.Message); } return true; }