public void Borrar(IEntidad entidad) { clsNota nota = new clsNota(); try { nota = getCast(entidad); } catch (Exception e) { throw e; } int filas; try { filas = manager.DeleteNota(nota); if (filas == 0) { throw new ArgumentException("La nota no existe"); } } catch (Exception e) { throw e; } }
public List<clsNota> ListarNota() { List<clsNota> res = new List<clsNota>(); DataTable dt; try { dt = dbManager.Consultar("select * from Nota;"); } catch (Exception e) { throw e; } foreach (DataRow item in dt.Rows) { clsNota p = new clsNota(); p.Id = Convert.ToInt32(item["IdNota"]); p.IdAlumno = Convert.ToInt32(item["IdAlumno"]); p.IdCurso = Convert.ToInt32(item["IdCurso"]); p.Nota = Convert.ToDouble(item["Nota"]); p.Fecha = Convert.ToDateTime(item["Fecha"]); p.Estado = Convert.ToInt32(item["Estado"]); res.Add(p); } return res; }
public void Agregar(IEntidad entidad) { clsNota nota = new clsNota(); try { nota = getCast(entidad); } catch (Exception e) { throw e; } clsNota compare = new clsNota(); compare.IdAlumno = nota.IdAlumno; compare.IdCurso = nota.IdCurso; try { if (manager.SelectNota(compare).Count == 0) manager.InsertarNota(nota); else throw new ArgumentException("Esta nota ya fue registrada"); } catch (Exception e) { throw e; } }
public void AgregarRegistro(clsNota obj)//agrega un registro al ultimo { if (EscribirRegistro(nregs, obj)) { nregs++; } }
public bool EscribirRegistro(int i, clsNota obj) { try { if (i >= 0 && i <= nregs) { if (obj.Tamaño + 4 > tamañoReg) { Console.WriteLine("Tamaño de registro excedido."); return(false); } else { bw.BaseStream.Seek(i * tamañoReg, SeekOrigin.Begin); bw.Write(obj.IdNota); bw.Write(obj.Tipo.ToString()); bw.Write(obj.Fecha.ToString()); bw.Write(obj.Monto); return(true); } } else { return(false); } } catch (IOException e) { CerrarFichero(); Console.WriteLine(e.Message); return(false); } }
public int DeleteNota(clsNota entidad) { int filas = 0; string query = "delete Dicta where IdAlumno = '" + entidad.IdAlumno + "', IdCurso = '" + entidad.IdCurso + "';"; return filas; }
protected void Unnamed14_Click(object sender, EventArgs e) //boton { l_notas.AbrirFichero(Server.MapPath(@"~/Archivos/Notas.bin")); clsNota obj = new clsNota(i + 1, Convert.ToString(TipoNota.Text), Convert.ToDouble(Monto.Text), Convert.ToDateTime(Fecha.Text)); l_notas.AgregarRegistro(obj); l_notas.CerrarFichero(); }
public frmModificarNota(clsNotaFormateada Nota) { InitializeComponent(); nota_Original = new clsNota(); nota_Original.Id = Nota.Id; nota_Original.Nota = Nota.Nota; nota_Original.Estado = Nota.Estado; nota_Original.Fecha = nota_Original.Fecha; }
//elimina cheque pasando numero de id public void EliminarNota(int idnota, String fichero) { int regi = 0; int regist = 0; int pos = BuscarNota(idnota); fst = new FileStream("Tempo.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite); bwt = new BinaryWriter(fst); brt = new BinaryReader(fst); while (regi < nregs) { if (regist != pos) { clsNota nota1 = LeerReg(regist); bwt.BaseStream.Seek(regi * tamañoReg, SeekOrigin.Begin); bwt.Write(nota1.IdNota); bwt.Write(nota1.Tipo); bwt.Write(nota1.Fecha.ToString()); bwt.Write(nota1.Monto); regist++; regi++; } else { regist++; clsNota nota1 = LeerReg(regist); bwt.BaseStream.Seek(regi * tamañoReg, SeekOrigin.Begin); bwt.Write(nota1.IdNota); bwt.Write(nota1.Tipo); bwt.Write(nota1.Fecha.ToString()); bwt.Write(nota1.Monto); regist++; regi++; } } nregs--; CerrarFichero(); fst.Close(); bwt.Close(); brt.Close(); File.Delete(fichero); File.Move("Tempo.bin", fichero); AbrirFichero(fichero); }
protected void Unnamed14_Click(object sender, EventArgs e) //boton { l_notas.AbrirFichero(Server.MapPath(@"~/Archivos/Notas.bin")); string tipo; int combo = ComboTipo.Items.IndexOf(ComboTipo.Items.FindByValue(ComboTipo.Text)); if (combo == 0) { tipo = "Credito"; } else { tipo = "Debito"; } double monto = double.Parse(Monto.Text); DateTime fe = Convert.ToDateTime(Fecha.Text); clsNota obj = new clsNota(i + 1, tipo, monto, fe); l_notas.AgregarRegistro(obj); l_notas.CerrarFichero(); }
public int InsertarNota(clsNota entidad) { int filas; //string query = "insert Nota values('" + entidad.IdAlumno + "','" + entidad.IdCurso + "','" + CultureInfo.InvariantCulture, "{0:00.00}", entidad.Nota + "','" + entidad.Fecha + "','" + entidad.Estado + "');"; try { SqlParameter[] param = new SqlParameter[5]; param[0] = new SqlParameter("@idAlumno", entidad.IdAlumno); param[1] = new SqlParameter("@idCurso", entidad.IdCurso); param[2] = new SqlParameter("@nota", String.Format(CultureInfo.InvariantCulture, "{0:00.00}", entidad.Nota)); param[3] = new SqlParameter("@fecha", entidad.Fecha); param[4] = new SqlParameter("@estado", entidad.Estado); filas = dbManager.Ejecutar("insertarNota", param, Tipo.INSERTAR); } catch (Exception e) { throw e; } return filas; }
private void btnContinuar_Click(object sender, EventArgs e) { if (tbCurso.Text == "Sin Seleccionar") { MessageBox.Show("Seleccione un Curso"); } else { try { if (Alumno_nuevo != null) { if (Alumno_nuevo.Id != null) { nota_Original.IdAlumno = Alumno_nuevo.Id; } } if (Curso_Nuevo != null) { if (Curso_Nuevo.Id != null) { nota_Original.IdCurso = Curso_Nuevo.Id; } } if(tbCalificacion.Text != nota_Original.Nota.ToString().Replace('.',',')) { nota_Original.Nota = Convert.ToDouble( tbCalificacion.Text.Replace(',', '.')); } if (chbEstado.Checked) { nota_Original.Estado = '1'; } else { nota_Original.Estado = '0'; } clsNota Nota_nuevo = new clsNota(); Nota_nuevo.Id = nota_Original.Id; Nota_nuevo.Nota = nota_Original.Nota; Nota_nuevo.Estado = nota_Original.Estado; Nota_nuevo.Fecha = nota_Original.Fecha; nota_Consultador.Actualizar(nota_Original); MessageBox.Show("Curso modificado exitosamente", "Exito!"); this.Close(); } catch (Exception a) { MessageBox.Show("Ha ocurrido el siguiente error" + a.Message); } } }
private void btnContinuar_Click(object sender, EventArgs e) { clsNota nueva = new clsNota(); try { if (!string.IsNullOrWhiteSpace(tbNota.Text)) { string expresion1 = "^[,][0-9]{0,4}$"; string valor = tbNota.Text; if (Regex.IsMatch(tbNota.Text.Trim(), expresion1) == false) { nueva.IdAlumno = Alumno.Id; nueva.IdCurso = Curso.Id; nueva.Nota = Convert.ToDouble(valor); nueva.Estado = 1; nueva.Fecha = DateTime.Today; Nota.Agregar(nueva); DialogResult result = MessageBox.Show("Desea Registrar otra nota?", "Nota Registrada exitosamente", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { this.restaurar_inicio(); } else { this.Close(); } } else { MessageBox.Show("El formato de la nota ingresada no es correcto"); } } else { MessageBox.Show("Ingrese una nota"); } } catch (Exception a) { if(a.Message == "Esta nota ya fue registrada") { DialogResult modificar = MessageBox.Show("¿Desea modificar la nota existente?", "Esta nota ya fue registrada", MessageBoxButtons.YesNo); if (modificar == DialogResult.Yes) { try { clsNota tarjet = (clsNota) Nota.ObtenerPorId(nueva.IdAlumno, nueva.IdCurso); // frmModificarNota Modificar_Nota = new frmModificarNota(tarjet); this.Visible = false; // Modificar_Nota.ShowDialog(); this.Visible = true; this.restaurar_inicio(); } catch (Exception b) { MessageBox.Show("Ocurrio el siguiente error:" + b.Message); } } else { this.restaurar_inicio(); } } } }
public List<IEntidad> Lista(IEntidad filtro) { clsNota nota = new clsNota(); List<IEntidad> list = new List<IEntidad>(); try { nota = getCast(filtro); } catch (Exception e) { throw e; } try { list.AddRange(manager.SelectNota(nota)); } catch (Exception e) { throw e; } return list; }
public int UpdateNota(clsNota entidad) { int filas; string query = "update Nota set Nota = '" + entidad.Nota + "', Fecha = '" + entidad.Fecha.Date.ToString() + "', Estado = '" + entidad.Estado + "' where IdAlumno = '" + entidad.IdAlumno + "' and IdCurso = '" + entidad.IdCurso + "';"; try { filas = dbManager.Ejecutar(query, Tipo.ACTUALIZAR); string consulta = "SELECT COUNT(*) as Cantidad FROM Nota WHERE IdCurso = '" + entidad.IdCurso + "' AND IdAlumno = '" + entidad.IdAlumno + "';"; DataTable dt = dbManager.Consultar(consulta); int alumnos = Convert.ToInt32(dt.Rows[0]["Cantidad"]); if (alumnos > 1) { throw new Exception("Esta nota ya fue cargada, acceda al menu de modificacion para cambiarla"); } } catch (Exception e) { throw e; } return filas; }
public List<clsNota> SelectNota(clsNota entidad) { List<clsNota> list = new List<clsNota>(); bool idnota = false, alumno = false, curso = false, nota = false, fecha = false; string query = "select * from Nota where"; if (entidad.Id != -1) { query += " IdNota = '" + entidad.Id + "'"; idnota = true; } if (entidad.IdAlumno != -1) { if (idnota) { query += " and"; } query += " IdAlumno = '" + entidad.IdAlumno + "'"; alumno = true; } if (entidad.IdCurso != -1) { if (idnota | alumno) { query += " and"; } query += " IdCurso = '" + entidad.IdCurso + "'"; curso = true; } if (entidad.Nota != -1) { if (idnota | alumno | curso) { query += " and"; } query += " Nota = '" + entidad.Nota + "'"; nota = true; } DateTime nuevo = new DateTime(0001,01,01,0,00,00); if (DateTime.Compare(entidad.Fecha,nuevo) != 0) { if (idnota | alumno | curso | nota) { query += " and"; } query += " Fecha = '" + entidad.Fecha + "'"; fecha = true; } if (entidad.Estado != -1) { if (idnota | alumno | curso | nota | fecha) { query += " and"; } query += " Estado = '" + entidad.Estado + "'"; } query += ";"; DataTable dt; try { dt = dbManager.Consultar(query); } catch (Exception e) { throw e; } foreach (DataRow item in dt.Rows) { clsNota n = new clsNota(); n.Id = Convert.ToInt32(item["IdNota"]); n.IdAlumno = Convert.ToInt32(item["IdAlumno"]); n.IdCurso = Convert.ToInt32(item["IdCurso"]); n.Nota = Convert.ToDouble(item["Nota"]); n.Fecha = Convert.ToDateTime(item["Fecha"]); n.Estado = Convert.ToInt32(item["Estado"]); list.Add(n); } return list; }
public IEntidad ObtenerPorId(int idAlumno, int idCurso) { clsNota nota = new clsNota(); nota.IdAlumno = idAlumno; nota.IdCurso = idCurso; clsNota nalumno = null; try { nalumno = manager.SelectNota(nota)[0]; if (nalumno == null) { throw new ArgumentException("La nota no existe"); } } catch (Exception e) { throw e; } return nalumno; }