private void AddRecordFile(Campeonato campeonato) { StreamWriter escribir = new StreamWriter(path, true); escribir.WriteLine(campeonato.ToString()); escribir.Close(); }
private void pictureBox1_Click(object sender, EventArgs e) { string msg = ""; if (textNombre.Text.Length < 3 || textNombre.Text.Length > 50) { msg += "El nombre debe de estar comprendido entre 3 y 50 caracteres\n"; } DateTime fechaInicio = new DateTime(dateInicio.Value.Year, dateInicio.Value.Month, dateInicio.Value.Day, 0, 0, 0); DateTime fechaFinal = new DateTime(dateFin.Value.Year, dateFin.Value.Month, dateFin.Value.Day, 0, 0, 0); if (DateTime.Compare(fechaInicio, fechaFinal) >= 0) { msg = "\nLa fecha de inicio debe de ser menor a la fecha final"; } if (msg.Length > 0) { MessageBox.Show(msg, "Mensaje de error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Campeonato campeonato = new Campeonato(); campeonato.Id = new Random().Next(1, 1000); campeonato.Nombre = textNombre.Text; campeonato.FechaInicio = dateInicio.Value; campeonato.FechaTermino = dateInicio.Value; string[] array = campeonato.ToString().Split(new char[] { '|' }); datos.Rows.Add(array); datos.Rows.Add(array); AddRecordFile(campeonato); msg = "Registro agregado exitosamente"; MessageBox.Show(msg, "Agrega un campeonato", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void add_Click(object sender, EventArgs e) { string msg = ""; if (textBox2.Text.Length < 3 || textBox2.Text.Length > 50) { msg += "El nombre debe estar comprendido entre 3 y 50 caracteres"; } DateTime dateTimePicker1 = new DateTime(dateInicio.Value.Year, dateInicio.Value.Month, dateInicio.Value.Day, 0, 0, 0); DateTime dateTimePicker2 = new DateTime(dateFin.Value.Year, dateFin.Value.Month, dateFin.Value.Day, 0, 0, 0); if (DateTime.Compare(dateTimePicker1, dateTimePicker2) >= 0) { msg += "La fecha Inicio debe ser menor a la fecha final"; } if (msg.Length > 0) { MessageBox.Show(msg, "Mensaje de error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //Crea un objeto de tipo campeonato Campeonato campeonato = new Campeonato(); campeonato.ID = new Random().Next(1, 1000); //Se genera un Id Aleatorio campeonato.Nombre = textBox2.Text; //Caja de texto campeonato.FechaInicio = dateInicio.Value; //Inicio campeonato.FechaFin = dateFin.Value; //Fin string[] array = campeonato.ToString().Split(new char[] { '|' }); datos.Rows.Add(array); AddRecordFile(campeonato);//Lo agrega al archivo un objeto msg = "Registro agregado exitosamente"; MessageBox.Show(msg, "Agrega un campeonato", MessageBoxButtons.OK, MessageBoxIcon.Information); } }