//amonestaciones public void guardarAmonestacion(Amonestacion amonestacion) { SqlConnection connection = ConexionSingleton.obtenerConexion(); connection.Open(); SqlTransaction tx = connection.BeginTransaction(); StringBuilder sb = new StringBuilder(); sb.Append(" insert into amonestacion "); sb.Append(" (amon_alumno_id,amon_fecha,amon_motivo,amon_dvh) "); sb.Append(" values(@alu,@fecha,@motivo,@dvh) "); String dvh = new DAOSeguridad().recalcularDigitoHorizontal(new String[] { amonestacion.alumno.legajo.ToString(), amonestacion.fecha.ToString("yyyy-MM-dd") }); SqlCommand cmd = new SqlCommand(sb.ToString(), connection, tx); cmd.Parameters.Add(new SqlParameter("@alu", SqlDbType.BigInt)).Value = amonestacion.alumno.legajo; cmd.Parameters.Add(new SqlParameter("@fecha", SqlDbType.Date)).Value = amonestacion.fecha; cmd.Parameters.Add(new SqlParameter("@motivo", SqlDbType.Text)).Value = SeguridadUtiles.encriptarAES(amonestacion.motivo); cmd.Parameters.Add(new SqlParameter("@dvh", SqlDbType.VarChar)).Value = dvh; try { String check = " Select count(*) from amonestacion where amon_alumno_id = @alu and amon_fecha = @fecha"; cmd.CommandText = check; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int count = (int)reader.GetValue(0); if (count > 0) { reader.Close(); throw new Exception("FECHA"); } } reader.Close(); cmd.CommandText = sb.ToString(); cmd.ExecuteNonQuery(); tx.Commit(); connection.Close(); Usuario usu = new Usuario(); usu.id = TrabajoDeCampo.Properties.Settings.Default.SessionUser; new DAOSeguridad().grabarBitacora(usu, "Se registro una amonestación", CriticidadEnum.MEDIA); } catch (Exception) { tx.Rollback(); connection.Close(); throw; } }
private void button1_Click(object sender, EventArgs e) { if (!editando) { editando = true; this.registrar.Text = traducciones["com.td.guardar"]; this.groupBox1.Enabled = true; } else { if (String.IsNullOrEmpty(this.richTextBox1.Text)) { MessageBox.Show(traducciones["com.td.complete.campos"]); return; } editando = false; this.registrar.Text = "Registrar"; this.groupBox1.Enabled = false; // logica del save Amonestacion amonestacion = new Amonestacion(); amonestacion.motivo = this.richTextBox1.Text; amonestacion.fecha = this.dateTimePicker1.Value; amonestacion.alumno = alumno; this.richTextBox1.Text = ""; this.dateTimePicker1.Value = this.dateTimePicker1.MaxDate; try { DialogResult result = MessageBox.Show(traducciones["com.td.seguro"], "", MessageBoxButtons.OKCancel); if (!result.Equals(DialogResult.OK)) { return; } this.servicioAlumnos.guardarAmonestacion(amonestacion); } catch (Exception ex) { if (ex.Message == "FECHA") { MessageBox.Show(traducciones["com.td.fecha.ocupada"]); } else { MessageBox.Show(ex.Message); } } listar(); } }
public List <Amonestacion> listarAmonestaciones(String filtro, String valor, String orden) { SqlDataReader reader = null; SqlConnection connection = ConexionSingleton.obtenerConexion(); List <Amonestacion> amonestaciones = new List <Amonestacion>(); connection.Open(); SqlTransaction tx = connection.BeginTransaction(); SqlCommand cmd = new SqlCommand("SELECT * FROM AMONESTACION WHERE AMON_ALUMNO_ID = @ID ", connection, tx); cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.BigInt)).Value = long.Parse(valor); try { reader = cmd.ExecuteReader(); while (reader.Read()) { Amonestacion amonestacion = new Amonestacion(); amonestacion.fecha = DateTime.Parse(reader.GetValue(1).ToString()); amonestacion.motivo = SeguridadUtiles.desencriptarAES(reader.GetValue(2).ToString()); amonestaciones.Add(amonestacion); } reader.Close(); tx.Commit(); connection.Close(); new DAOSeguridad().recalcularDigitoVertical("AMONESTACION"); } catch (Exception) { if (reader != null) { reader.Close(); } tx.Rollback(); connection.Close(); throw; } return(amonestaciones); }
//amonestaciones public void guardarAmonestacion(Amonestacion amonestacion) { this.daoAlumnos.guardarAmonestacion(amonestacion); }