public void InsertarSancion(Modelos.Sancion Ms) { try { Con.Conectar(); string sql = "INSERT INTO Sanciones VALUES( @sPres, @sDiS, @sFeI, @sFeF)"; SqlCommand sc = new SqlCommand(sql, Con.Conex()); sc.Parameters.AddWithValue("@sPres", Ms.SanPrestamo); sc.Parameters.AddWithValue("@sDiS", Ms.SanDiaSancion); sc.Parameters.AddWithValue("@sFeI", Ms.SanFechaInicio); sc.Parameters.AddWithValue("@sFeF", Ms.SanFechaFin); int result = sc.ExecuteNonQuery(); if (result == 1) { Console.WriteLine("Sancion insertada"); MessageBox.Show("Sancion insertada"); } else { Console.WriteLine("La sancion no pudo ser insertada"); MessageBox.Show("La sancion no pudo ser insertada"); } } catch (Exception e) { Console.WriteLine(e.Message); MessageBox.Show(e.Message); } finally { Con.Desconectar(); } }
protected void BtnGuardar_Click(object sender, EventArgs e) { Modelos.Sancion Ms = new Modelos.Sancion(); Controladores.DetallePrestamosControlador Cdc = new Controladores.DetallePrestamosControlador(); string[] vect = new string[2]; vect = Cs.ConsultaExistencia(ListaLibros.SelectedValue, ListaUsuarios.SelectedValue); DateTime fecha = Convert.ToDateTime(Fecha.Text); DateTime fechaEn = Convert.ToDateTime(vect[1]); if (fecha > fechaEn) { Cu.ActualizarEstadoUsuario(ListaUsuarios.SelectedValue); Ms.SanDiaSancion = "5"; Ms.SanFechaFin = fecha.AddDays(5).ToString(); Ms.SanFechaInicio = Fecha.Text; Ms.SanPrestamo = vect[0]; Cs.InsertarSancion(Ms); } }