private void tsbBorrar_Click(object sender, EventArgs e) { if (dgvDatos.SelectedRows.Count == 0) { return; } DataGridViewRow r = dgvDatos.SelectedRows[0]; CategoriaListDto categoriaListDto = (CategoriaListDto)r.Tag; DialogResult dr = MessageBox .Show($@"¿Desea borrar el registro seleccionado de la categoría {categoriaListDto.NombreCategoria}?", "Confirmar Baja", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2 ); if (dr == DialogResult.No) { return; } try { //Controlar relaciones _servicio.Borrar(categoriaListDto.CategoriaId); dgvDatos.Rows.Remove(r); MessageBox.Show("Registro borrado", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void tsbEditar_Click(object sender, EventArgs e) { if (dgvDatos.SelectedRows.Count == 0) { return; } DataGridViewRow r = dgvDatos.SelectedRows[0]; CategoriaListDto categoriaDto = (CategoriaListDto)r.Tag; CategoriaListDto categoriaDtoAux = categoriaDto.Clone() as CategoriaListDto; FrmCategoriasAE frm = new FrmCategoriasAE(); CategoriaEditDto categoriaEditDto = _servicio.GetCategoriaPorId(categoriaDto.CategoriaId); frm.Text = "Editar Categoría"; frm.SetCategoria(categoriaEditDto); DialogResult dr = frm.ShowDialog(this); if (dr == DialogResult.Cancel) { return; } try { categoriaEditDto = frm.GetCategoria(); //Controlar repitencia if (!_servicio.Existe(categoriaEditDto)) { _servicio.Guardar(categoriaEditDto); categoriaDto = new CategoriaListDto { CategoriaId = categoriaEditDto.CategoriaId, NombreCategoria = categoriaEditDto.NombreCategoria, }; SetearFila(r, categoriaDto); MessageBox.Show("Registro Agregado", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { SetearFila(r, categoriaDto); MessageBox.Show("Registro ya existente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception exception) { SetearFila(r, categoriaDtoAux); MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
internal static void CargarDatosComboCategorias(ref ComboBox combo) { IServiciosCategorias servicio = new ServiciosCategorias(); var lista = servicio.GetLista(); var defaultCategoria = new CategoriaListDto() { CategoriaId = 0, NombreCategoria = "Seleccione Categoria" }; lista.Insert(0, defaultCategoria); combo.DataSource = lista; combo.ValueMember = "CategoriaId"; combo.DisplayMember = "NombreCategoria"; combo.SelectedIndex = 0; }
public List <CategoriaListDto> GetLista() { List <CategoriaListDto> lista = new List <CategoriaListDto>(); try { string cadenaComando = "SELECT CategoriaId, NombreCategoria FROM Categorias"; SqlCommand comando = new SqlCommand(cadenaComando, _sqlConnection); SqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { CategoriaListDto categoriaDto = ConstruirCategoriaListDto(reader); lista.Add(categoriaDto); } reader.Close(); return(lista); } catch (Exception e) { throw new Exception("Error al intentar leer las categorías"); } }
private void tsbNuevo_Click(object sender, EventArgs e) { FrmCategoriasAE frm = new FrmCategoriasAE(); frm.Text = "Agregar Categoría"; DialogResult dr = frm.ShowDialog(this); if (dr == DialogResult.OK) { try { CategoriaEditDto categoriaEditDto = frm.GetCategoria(); //Controlar repitencia if (!_servicio.Existe(categoriaEditDto)) { _servicio.Guardar(categoriaEditDto); CategoriaListDto categoriaListDto = new CategoriaListDto { CategoriaId = categoriaEditDto.CategoriaId, NombreCategoria = categoriaEditDto.NombreCategoria, }; DataGridViewRow r = ConstruirFila(); SetearFila(r, categoriaListDto); AgregarFila(r); MessageBox.Show("Registro Agregado", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Registro ya existente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public bool Eliminar(CategoriaListDto parametroDto) { throw new NotImplementedException(); }
public CategoriaListDto Crear(CategoriaListDto entidadDto) { throw new NotImplementedException(); }
private void SetearFila(DataGridViewRow r, CategoriaListDto categoriaDto) { r.Cells[cmnNombre.Index].Value = categoriaDto.NombreCategoria; r.Tag = categoriaDto; }