private void tsbBorrar_Click(object sender, EventArgs e)
 {
     if (dgvDatos.SelectedRows.Count > 0)
     {
         DataGridViewRow r       = dgvDatos.SelectedRows[0];
         TipoDeMascota   tipomas = (TipoDeMascota)r.Tag;
         DialogResult    dr      = MessageBox.Show($"¿Desea borrar de la lista a {tipomas.Descripcion}?",
                                                   "Confirmar Baja",
                                                   MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Question);
         if (dr == DialogResult.Yes)
         {
             try
             {
                 if (!servicio.EstaRelacionado(tipomas))
                 {
                     servicio.Borrar(tipomas);
                     dgvDatos.Rows.Remove(r);
                     MessageBox.Show("Tipo de mascota Borrado", "Mensaje",
                                     MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
                 else
                 {
                     MessageBox.Show("Tipo de mascota con registros asociados \nBaja Denegada", "Error",
                                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             catch (Exception exception)
             {
                 MessageBox.Show(exception.Message, "Error",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
        private void tsbNuevo_Click(object sender, EventArgs e)
        {
            frmTipoDeMascotaAE frm = new frmTipoDeMascotaAE();

            frm.Text = "Agregar Tipo De Mascota";
            DialogResult dr = frm.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                try
                {
                    TipoDeMascota tipoDeMascota = frm.GetTipoDeMascota();
                    if (!servicio.Existe(tipoDeMascota))
                    {
                        servicio.Agregar(tipoDeMascota);
                        var r = ConstruirFila();
                        SetearFila(r, tipoDeMascota);
                        AgregarFila(r);
                        MessageBox.Show("Tipo de mascota agregado", "Mensaje",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Tipo de mascota repetida... Alta denegada", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #3
0
 public bool Existe(TipoDeMascota tipomascota)
 {
     if (tipomascota.TipoDeMascotaId == 0)
     {
         return(_context.TiposDeMascotas.Any(tp => tp.Descripcion == tipomascota.Descripcion));
     }
     return(_context.TiposDeMascotas.Any(tp => tp.Descripcion == tipomascota.Descripcion &&
                                         tp.TipoDeMascotaId == tipomascota.TipoDeMascotaId));
 }
Exemple #4
0
 public bool EstaRelacionado(TipoDeMascota tipoDeMascota)
 {
     try
     {
         return(_context.Razas.Any(r => r.TipoDeMascotaId == tipoDeMascota.TipoDeMascotaId));
     }
     catch (Exception)
     {
         throw new Exception("Error al verificar si està relacionado con una Raza");
     }
 }
Exemple #5
0
 public bool Existe(TipoDeMascotaEditDto tipomascotaEditDto)
 {
     try
     {
         TipoDeMascota tipo = mapper.Map <TipoDeMascota>(tipomascotaEditDto);
         return(_repositorio.Existe(tipo));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Exemple #6
0
 public bool EstaRelacionado(TipoDeMascotaEditDto tipoMasDto)
 {
     try
     {
         TipoDeMascota tipoDeMascota = _mapper.Map <TipoDeMascota>(tipoMasDto);
         return(_repositorio.EstaRelacionado(tipoDeMascota));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
        private void Okbtn_Click(object sender, EventArgs e)
        {
            if (ValidarDatos())
            {
                if (tipomas == null)
                {
                    tipomas = new TipoDeMascota();
                }

                tipomas.Descripcion = TipoDeMascotaTextBox.Text.Trim();
                DialogResult        = DialogResult.OK;
            }
        }
Exemple #8
0
 public void Guardar(TipoDeMascota tipomas)
 {
     try
     {
         conexion    = new ConexionBd();
         repositorio = new RepositorioTipoDeMascota(conexion.AbrirConexion());
         repositorio.Guardar(tipomas);
         conexion.CerrarConexion();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public void Borrar(TipoDeMascota tipomas)
 {
     try
     {
         string     cadenaComando = "DELETE FROM TipoDeMascota WHERE TipoDeMascotaID=@id";
         SqlCommand comando       = new SqlCommand(cadenaComando, cn);
         comando.Parameters.AddWithValue("@id", tipomas.TipoDeMascotaId);
         comando.ExecuteNonQuery();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Exemple #10
0
 public void Guardar(TipoDeMascotaEditDto tipomascotaEditDto)
 {
     try
     {
         TipoDeMascota tipo = mapper.Map <TipoDeMascota>(tipomascotaEditDto);
         _repositorio.Guardar(tipo);
         _unitOfWork.Save();
         tipo.TipoDeMascotaId = tipomascotaEditDto.TipoDeMascotaId;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Exemple #11
0
 public bool Existe(TipoDeMascota tipomas)
 {
     try
     {
         conexion    = new ConexionBd();
         repositorio = new RepositorioTipoDeMascota(conexion.AbrirConexion());
         var existe = repositorio.Existe(tipomas);
         conexion.CerrarConexion();
         return(existe);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Exemple #12
0
 public bool EstaRelacionado(TipoDeMascota tipomas)
 {
     try
     {
         conexion    = new ConexionBd();
         repositorio = new RepositorioTipoDeMascota(conexion.AbrirConexion());
         var relacionado = repositorio.EstaRelacionado(tipomas);
         conexion.CerrarConexion();
         return(relacionado);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
        public bool Existe(TipoDeMascota tipomas)
        {
            try
            {
                var cadenaComando = "SELECT TipoDeMascotaID, Descripcion FROM TipoDeMascota WHERE Descripcion=@nombre";
                var comando       = new SqlCommand(cadenaComando, cn);
                comando.Parameters.AddWithValue("@nombre", tipomas.Descripcion);
                var reader = comando.ExecuteReader();
                return(reader.HasRows);
            }

            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Exemple #14
0
        public bool Existe(TipoDeMascota tipoDeMascota)
        {
            try
            {
                if (tipoDeMascota.TipoDeMascotaId == 0)
                {
                    return(_context.TipoDeMascotas.Any(tm => tm.Descripcion == tipoDeMascota.Descripcion));
                }

                return(_context.TipoDeMascotas.Any(tm => tm.Descripcion == tipoDeMascota.Descripcion && tm.TipoDeMascotaId == tipoDeMascota.TipoDeMascotaId));
            }
            catch (Exception)
            {
                throw new Exception("Error al verificar si existe un Tipo de Mascota");
            }
        }
 public void Agregar(TipoDeMascota tipomas)
 {
     try
     {
         string     cadenaComando = "INSERT INTO TipoDeMascota VALUES (@tipodemascota)";
         SqlCommand comando       = new SqlCommand(cadenaComando, cn);
         comando.Parameters.AddWithValue("@tipodemascota", tipomas.Descripcion);
         comando.ExecuteNonQuery();
         cadenaComando = "SELECT @@Identity";
         comando       = new SqlCommand(cadenaComando, cn);
         int id = (int)(decimal)comando.ExecuteScalar();
         tipomas.TipoDeMascotaId = id;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public bool EstaRelacionado(TipoDeMascota tipomas)
 {
     try
     {
         var cadenaComando = "SELECT COUNT(*) FROM Mascotas WHERE TipoDeMascotaId=@id";
         var comando       = new SqlCommand(cadenaComando, cn);
         comando.Parameters.AddWithValue("@id", tipomas.TipoDeMascotaId);
         int cantidadRegistros = (int)comando.ExecuteScalar();
         if (cantidadRegistros > 0)
         {
             return(true);
         }
         return(false);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public List <TipoDeMascota> GetLista()
 {
     try
     {
         List <TipoDeMascota> lista = new List <TipoDeMascota>();
         string cadenaComando       = "SELECT TipoDeMascotaID, Descripcion FROM TipoDeMascota";
         var    comando             = new SqlCommand(cadenaComando, cn);
         var    reader = comando.ExecuteReader();
         while (reader.Read())
         {
             TipoDeMascota tipomas = ConstruirTipoMas(reader);
             lista.Add(tipomas);
         }
         reader.Close();
         return(lista);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Exemple #18
0
 public string Comunicarse()
 {
     if (TipoDeMascota.ToLower() == "perro")
     {
         return("Guau Guau !!");
     }
     else if (TipoDeMascota.ToLower() == "gato")
     {
         return("Miau Miua");
     }
     else if (TipoDeMascota.ToLower() == "pajaro")
     {
         return(" Pio Pio");
     }
     else
     {
         Console.Write($"¿Que dice el {TipoDeMascota} ? ");
         string sonido = Console.ReadLine();
         return(sonido);
     }
 }
Exemple #19
0
        public void Guardar(TipoDeMascota tipomascota)
        {
            try
            {
                if (tipomascota.TipoDeMascotaId == 0)
                {
                    _context.TiposDeMascotas.Add(tipomascota);
                }
                else
                {
                    var tipoDb = _context.TiposDeMascotas.SingleOrDefault(tp => tp.TipoDeMascotaId == tipomascota.TipoDeMascotaId);
                    tipoDb.Descripcion = tipomascota.Descripcion;

                    _context.Entry(tipoDb).State = EntityState.Modified;
                }
            }
            catch (Exception)
            {
                throw new Exception("Error al Guardar/Editar el Tipo De Mascota");
            }
        }
Exemple #20
0
        public void Guardar(TipoDeMascota tipoDeMascota)
        {
            try
            {
                if (tipoDeMascota.TipoDeMascotaId == 0)
                {
                    _context.TipoDeMascotas.Add(tipoDeMascota);
                }
                else
                {
                    var mascotaInDb = _context.TipoDeMascotas.Find(tipoDeMascota.TipoDeMascotaId);
                    mascotaInDb.Descripcion           = tipoDeMascota.Descripcion;
                    _context.Entry(mascotaInDb).State = EntityState.Modified;
                }

                //_context.SaveChanges();
            }
            catch (Exception)
            {
                throw new Exception("Error al intentar Agregar/Editar un Tipo De Mascota");
            }
        }
        private void tsbEditar_Click(object sender, EventArgs e)
        {
            if (dgvDatos.SelectedRows.Count > 0)
            {
                DataGridViewRow r       = dgvDatos.SelectedRows[0];
                TipoDeMascota   tipomas = (TipoDeMascota)r.Tag;

                frmTipoDeMascotaAE frm = new frmTipoDeMascotaAE();
                frm.Text = "Editar Tipo De Mascota";
                frm.SetTipoDeMascota(tipomas);
                DialogResult dr = frm.ShowDialog(this);
                if (dr == DialogResult.OK)
                {
                    try
                    {
                        tipomas = frm.GetTipoDeMascota();
                        if (!servicio.Existe(tipomas))
                        {
                            servicio.Guardar(tipomas);
                            SetearFila(r, tipomas);
                            MessageBox.Show("Tipo de mascota Editada", "Mensaje",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Tipo de mascota Duplicada... Alta denegada", "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message, "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }
            }
        }
 public TipoDeMascota GetTipoDeMascotaPorId(int id)
 {
     try
     {
         TipoDeMascota tipomas       = null;
         string        cadenaComando = "SELECT TipoDeMascotaID, Descripcion FROM TipoDeMascota WHERE TipoDeMascotaID=@id";
         SqlCommand    comando       = new SqlCommand(cadenaComando, cn);
         comando.Parameters.AddWithValue("id", id);
         SqlDataReader reader = comando.ExecuteReader();
         if (reader.HasRows)
         {
             reader.Read();
             tipomas = ConstruirTipoMas(reader);
         }
         reader.Close();
         return(tipomas);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public void Guardar(TipoDeMascota tipomas)
 {
     if (tipomas.TipoDeMascotaId == 0)
     {
         try
         {
             string     cadenaComando = "INSERT INTO TipoDeMascota VALUES (@desc)";
             SqlCommand comando       = new SqlCommand(cadenaComando, cn);
             comando.Parameters.AddWithValue("@desc", tipomas.Descripcion);
             comando.ExecuteNonQuery();
             cadenaComando = "SELECT @@IDENTITY";
             comando       = new SqlCommand(cadenaComando, cn);
             int id = (int)(decimal)comando.ExecuteScalar();
             tipomas.TipoDeMascotaId = id;
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
     else
     {
         try
         {
             string     cadenaComando = "UPDATE TipoDeMascota SET Descripcion=@desc WHERE TipoDeMascotaID=@id";
             SqlCommand comando       = new SqlCommand(cadenaComando, cn);
             comando.Parameters.AddWithValue("@desc", tipomas.Descripcion);
             comando.Parameters.AddWithValue("@id", tipomas.TipoDeMascotaId);
             comando.ExecuteNonQuery();
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
 private void SetearFila(DataGridViewRow r, TipoDeMascota tipomas)
 {
     r.Cells[cmnTipoDeMascota.Index].Value = tipomas.Descripcion;
     r.Tag = tipomas;
 }
 public void SetTipoDeMascota(TipoDeMascota tipomas)
 {
     this.tipomas = tipomas;
 }
Exemple #26
0
 public bool EstaRelacionado(TipoDeMascota tipomascota)
 {
     throw new NotImplementedException();
 }