private void RefrescarDatos() { List <comunidades> comunidades = ComunidadORM.SelectAllComunidades(); List <comunidades> comunidadesOriginal; comunidadesOriginal = (from c in comunidades let a = new comunidades() { id = c.id, nombre = GestorIdiomas.getComunidad(c.nombre) } select a).ToList(); socios = SocioORM.SelectAllSocios(); bindingSourceComunidades.DataSource = comunidadesOriginal; if (socios == null) { DialogResult result = MessageBox.Show(Strings.errorBD, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (result == DialogResult.OK || result == DialogResult.Abort) { Application.Exit(); } } else if ((bool)FormLogin.socioLogin.estatal) { bindingSourceSocios.DataSource = socios; } else { List <socios> sociosComunidad = SocioORM.SelectAllSociosByComunidad((int)FormLogin.socioLogin.id_comunidad); bindingSourceSocios.DataSource = sociosComunidad; labelFilterComunidad.Visible = false; comboBoxFilterComunidad.Visible = false; buttonClean.Visible = false; } }
//Modificamos el idioma para que salga el seleccionado private void dataGridViewEventos_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { eventos _evento; if (e.ColumnIndex == 7) { _evento = (eventos)dataGridViewEventos.Rows[e.RowIndex].DataBoundItem; e.Value = GestorIdiomas.getComunidad(_evento.comunidades.nombre); } }
private void dataGridViewSocios_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { socios _socio; if (e.ColumnIndex == 12) { _socio = (socios)dataGridViewSocios.Rows[e.RowIndex].DataBoundItem; if (_socio.comunidades != null) { e.Value = GestorIdiomas.getComunidad(_socio.comunidades.nombre); } } }
//Cuando cargamos el formulario cargamos los datos de notificaciones y de las comundades private void FormEvento_Load(object sender, EventArgs e) { bindingSourceNotificaciones.DataSource = null; bindingSourceNotificaciones.DataSource = NotificacionORM.SelectAllNotificaciones(); comunidades = ComunidadORM.SelectAllComunidades(); comunidadesOriginal = (from c in comunidades let a = new comunidades() { id = c.id, nombre = GestorIdiomas.getComunidad(c.nombre) } select a).ToList(); cambiarIdioma(); bindingSourceComunidades.DataSource = comunidadesOriginal; dateTimePickerHora.CustomFormat = "HH:mm"; if (!modificar) { dateTimePickerFecha.Value = DateTime.Today; dateTimePickerFechaLimite.Value = DateTime.Today; } else { //comboBoxComunity.SelectedValue = evento.id_comunidad; foreach (notificaciones n in evento.notificaciones) { bindingSourceNotificaciones.Remove(n); } } if (!(bool)FormLogin.socioLogin.estatal) { comboBoxComunity.Enabled = false; comboBoxComunity.SelectedValue = FormLogin.socioLogin.id_comunidad; } if (evento != null) { cargarDatos(evento); } }
private void FormSocio_Load(object sender, EventArgs e) { comunidades = ComunidadORM.SelectAllComunidades(); //Creo una copia que no tenga ninguna relacion con la base de datos, con los nombres en el idioma ya //cambiado para usar este porque si usaba el que tiene relacion con la bd, magicamente se cambiaba //en la base de datos comunidadesOriginal = (from c in comunidades let a = new comunidades() { id = c.id, nombre = GestorIdiomas.getComunidad(c.nombre) } select a).ToList(); cambiarIdioma(); bindingSourceComunidades.DataSource = comunidadesOriginal; //buttonSave.Location = new System.Drawing.Point(97, 224); if (!(bool)FormLogin.socioLogin.estatal) { checkBoxState.Enabled = false; checkBoxState.Visible = false; comboBoxComunity.Enabled = false; checkBoxState.Visible = false; comboBoxComunity.SelectedValue = FormLogin.socioLogin.id_comunidad; } if (socio != null) { textBoxDni.Text = socio.dni; textBoxPhone.Text = socio.telefono; textBoxName.Text = socio.nombre; textBoxLastName.Text = socio.apellidos; textBoxEmail.Text = socio.mail; textBoxPassword.Text = socio.password; textBoxPassword2.Text = socio.password; checkBoxActive.Checked = socio.activo; checkBoxAdministrator.Checked = socio.administrador; checkBoxState.Checked = (bool)socio.estatal; comboBoxComunity.SelectedValue = socio.id_comunidad; } }
//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(); } } } }