Beispiel #1
0
        private void btnEditar_Click(object sender, EventArgs e)
        {
            if (dgvEstados.SelectedRows.Count > 0)
            {
                DataGridViewRow r         = dgvEstados.SelectedRows[0];
                Estado          estado    = (Estado)r.Tag;
                Estado          estadoAux = (Estado)estado.Clone();
                FrmEstadosAE    frm       = new FrmEstadosAE();
                frm.Text = "Editar Estado";
                frm.SetEstado(estado);
                DialogResult dr = frm.ShowDialog(this);
                if (dr == DialogResult.OK)
                {
                    try
                    {
                        estado = frm.GetEstado();
                        if (!_Servicio.Existe(estado))
                        {
                            _Servicio.Guardar(estado);
                            SetearFila(r, estado);
                            MessageBox.Show($"Registro {estado.Descripcion} Editado");
                        }

                        else
                        {
                            SetearFila(r, estadoAux);
                            MessageBox.Show($"Registro {estado.Descripcion} Ya existe!");
                        }
                    }
                    catch (Exception exepcion)
                    {
                        SetearFila(r, estadoAux);
                        MessageBox.Show(this, exepcion.Message, "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }
            }
        }
Beispiel #2
0
        private void btnNuevo_Click(object sender, EventArgs e)
        {
            FrmEstadosAE frm = new FrmEstadosAE();

            frm.Text = "Agregar Estado";
            DialogResult dr = frm.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                try
                {
                    Estado estado = frm.GetEstado();
                    if (!_Servicio.Existe(estado))
                    {
                        _Servicio.Guardar(estado);
                        DataGridViewRow r = ConstruirFila();
                        SetearFila(r, estado);
                        AgregarFila(r);
                        MessageBox.Show(this, $"Registro {estado.Descripcion} Agregado",
                                        "Mensaje",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Registro Existente", "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }
                catch (Exception excepcion)
                {
                    MessageBox.Show(this, excepcion.Message, "Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
        }