public Entidades.Comisiones RecuperarUno(int id) { MySqlConnection oConn = Datos.General.CreateConnection(); using (oConn) { oConn.Open(); MySqlCommand oCmd = new MySqlCommand(); using (oCmd) { oCmd.Connection = oConn; oCmd.CommandType = CommandType.StoredProcedure; oCmd.CommandText = "ComisionesRecuperarUno"; oCmd.Parameters.AddWithValue("@IdComision", id); Entidades.Comisiones oComisiones = new Entidades.Comisiones(); try { MySqlDataReader oReader = oCmd.ExecuteReader(); using (oReader) { while (oReader.Read()) { Entidades.Comision oComision = new Entidades.Comision(); oComision.IdComision = Convert.ToInt32(oReader["IdComision"]); oComision.NroComision = Convert.ToInt32(oReader["NroComision"]); oComision.Turno = Convert.ToString(oReader["Turno"]); oComisiones.Add(oComision); oComision = null; } return oComisiones; } } finally { oComisiones = null; } } } }
private void btnGuardar_Click(object sender, EventArgs e) { Negocio.Comisiones oComisiones = new Negocio.Comisiones(); if (this.esValido()) { try { Entidades.Comision oComision = new Entidades.Comision(); if (tipoOperacion != General.TipoOperacion.Alta) { oComision.IdComision = Convert.ToInt32(this.id_buscado); } oComision.NroComision = Convert.ToInt32(txtNroComision.Text); oComision.Turno = txtTurno.Text; if (this.tipoOperacion == General.TipoOperacion.Modificacion) { oComisiones.Modificar(oComision); MessageBox.Show("Comisión modificada correctamente", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { int id = oComisiones.Agregar(oComision); MessageBox.Show("Comisión agregada correctamente.\nId Comisión Nº: " + id.ToString(), "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); } } finally { oComisiones = null; borrarCampos(); } } }