//Al apretar el boton abre un openFileDialog para añadirlo a la lista de documentos private void buttonNuevo_Click(object sender, EventArgs e) { try { if (openFileDialogDocumentos.ShowDialog() == DialogResult.OK) { documentos documento = new documentos(); documento.nombre = openFileDialogDocumentos.SafeFileName; documento.documento = Convert.ToBase64String(File.ReadAllBytes(openFileDialogDocumentos.FileName)); documentosLista.Add(documento); bindingSourceDocumentos.DataSource = null; bindingSourceDocumentos.DataSource = documentosLista; } } catch (Exception) { errorDocumento(); } }
//Hacemos click para guardar los datos del evento private void buttonSave_Click(object sender, EventArgs e) { //Comprobamos que todos los campos esten llenos y en formato correcto if (textBoxNombre.Text.Trim().Equals("")) { MessageBox.Show(Strings.errorName, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxDescripcion.Text.Trim().Equals("")) { MessageBox.Show(Strings.errorDescription, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (dateTimePickerFecha.Value < DateTime.Today) { MessageBox.Show(Strings.errorDate, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxUbicacion.Text.Trim().Equals("")) { MessageBox.Show(Strings.errorLocation, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (dateTimePickerFechaLimite.Value < DateTime.Today) { MessageBox.Show(Strings.errorDate, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (listBoxNotificacionesSelec.SelectedItems.Count == 0) { MessageBox.Show(Strings.errorNotification, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (dateTimePickerFechaLimite.Value > dateTimePickerFecha.Value) { MessageBox.Show(Strings.errorDateLimit, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!int.TryParse(textBoxNumeroAsistentes.Text, out int num)) { MessageBox.Show(Strings.errorAsistentes, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //Pasamos los datos rellenados al nuevo evento documentos documento = new documentos(); eventoNew.nombre = textBoxNombre.Text.Trim(); eventoNew.descripcion = textBoxDescripcion.Text.Trim(); //Si creamos el evento la pasamos como base64String if (textBoxImagen.Text != "" && !modificar) { eventoNew.nombreImagen = openFileDialogImagen.SafeFileName; string base64String = Convert.ToBase64String(File.ReadAllBytes(openFileDialogImagen.FileName)); eventoNew.imagen = base64String; } //Si modificamos el evento si es diferente al que hemos cargado le pasamos el nuevo string else if (modificar) { if (!textBoxImagen.Text.Equals(eventoNew.nombreImagen)) { eventoNew.nombreImagen = openFileDialogImagen.SafeFileName; string base64String = Convert.ToBase64String(File.ReadAllBytes(openFileDialogImagen.FileName)); eventoNew.imagen = base64String; } } //En el caso de este vacio lo pasamos como null else { if (evento != null) { evento.imagen = null; evento.nombreImagen = ""; } } eventoNew.fecha = dateTimePickerFecha.Value.Date; eventoNew.ubicacion = textBoxUbicacion.Text.Trim(); //eventoNew.hora = dateTimePickerHora.Value.TimeOfDay; String t = dateTimePickerHora.Value.TimeOfDay.ToString().Substring(0, 8); eventoNew.hora = TimeSpan.Parse(t); eventoNew.fechaLimite = dateTimePickerFechaLimite.Value.Date; eventoNew.documentos = documentosLista; eventoNew.notificaciones = notificacion; if (!textBoxNumeroAsistentes.Text.Trim().Equals("")) { eventoNew.numAsistentes = int.Parse(textBoxNumeroAsistentes.Text.Trim()); } if (comboBoxComunity.SelectedItem != null) { //Apaño pq al cambiar idioma no funcionaba, intentaba guardarlo en otro idioma y petaba foreach (comunidades c in comunidades) { String aux = GestorIdiomas.getComunidad(c.nombre); if (aux.Equals(comboBoxComunity.Text)) { eventoNew.comunidades = c; eventoNew.id_comunidad = c.id; } } } //Si creamos el evento mostramos su mensaje if (!modificar) { if (EventoORM.InsertEvento(eventoNew)) { MessageBox.Show(Strings.eventCreated, Strings.created, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } //Si moficamos el evento mostramos su mensaje else { if (EventoORM.UpdateEvento(eventoNew)) { MessageBox.Show(Strings.eventModified, Strings.modified, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } } }