public bool EliminarTipoEstante(Tipo_Estante tipoEstante) { try { if (tipoEstante.Id == 0) { return(true); } if (!this.IsTipoEstanteEliminable(tipoEstante)) { return(false); } _contexto.Tipo_Estantes.Remove(tipoEstante); _contexto.SaveChanges(); return(true); } catch (Exception ex) { _errorMsg = "Ocurrio un error al eliminar el tipo estante. Ver el LogError"; StaticFileManager.LogError(ex); return(false); } }
private void btnEliminar_Click(object sender, EventArgs e) { if (MessageBox.Show("Se eliminara el tipo estante seleccionado.¿Desea continuar?", "Atencion...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } Tipo_Estante estanteSelected = (Tipo_Estante)bsTipoEstante.Current; if (estanteSelected == null) { MessageBox.Show("No se selecciono ningún item para ser eliminado", "Atencion...", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (_estanteriaDAL.EliminarTipoEstante(estanteSelected)) { MessageBox.Show("El tipo estante se elimino exitosamente", "Atencion...", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(_estanteriaDAL._errorMsg, "Atencion...", MessageBoxButtons.OK, MessageBoxIcon.Error); } ResetForm(); }
private void lbxTiposEstantes_SelectedIndexChanged(object sender, EventArgs e) { Tipo_Estante estanteSelected = (Tipo_Estante)lbxTiposEstantes.SelectedItem; if (estanteSelected == null) { return; } bsTipoEstante.DataSource = estanteSelected; }
private void btnGuardar_Click(object sender, EventArgs e) { Tipo_Estante estanteSelected = (Tipo_Estante)bsTipoEstante.Current; if (_estanteriaDAL.GuardarTipoEstante(estanteSelected)) { MessageBox.Show("Los cambios se guardaron exitosamente", "Atencion...", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(_estanteriaDAL._errorMsg, "Atencion...", MessageBoxButtons.OK, MessageBoxIcon.Error); } ResetForm(); }
public bool IsTipoEstanteEliminable(Tipo_Estante tipoEstante) { if (tipoEstante == null) { _errorMsg = "El tipo de estante es null"; return(false); } if (_contexto.Estanterias.Where(a => a.Id_Tipo_Estante == tipoEstante.Id).Count() != 0) { _errorMsg = "Existen estantes de este tipo. No puede ser eliminado"; return(false); } return(true); }
public bool Valid(Tipo_Estante tipoEstante) { if (tipoEstante == null) { _errorMsg = "El tipo de estante es null"; return(false); } if (tipoEstante.Descripcion.Length == 0) { _errorMsg = "La descripcion no puede ser vacia"; return(false); } if (tipoEstante.Descripcion.Length > 50) { _errorMsg = "La descripcion no puede superar los 50 caracteres"; return(false); } return(true); }
public bool GuardarTipoEstante(Tipo_Estante tipoEstante) { try { if (!Valid(tipoEstante)) { return(false); } if (tipoEstante.Id == 0) { this._contexto.Tipo_Estantes.Add(tipoEstante); } this._contexto.SaveChanges(); return(true); } catch (Exception ex) { _errorMsg = "Ocurrio un error al eliminar el tipo estante. Ver el LogError"; StaticFileManager.LogError(ex); return(false); } }