private void tslAgregar_Click(object sender, EventArgs e)
        {
            frmTiposDeIngredientesAE frm = new frmTiposDeIngredientesAE(this);
            frm.Text = "Nuevo TipoDeIngrediente";
            DialogResult dr = frm.ShowDialog(this);
            if (dr == DialogResult.OK)
            {
                try
                {
                    TipoDeIngrediente tipoDeIngrediente = frm.GetTipoDeIngrediente();
                    if (!_servicio.Existe(tipoDeIngrediente))
                    {
                        _servicio.Guardar(tipoDeIngrediente);
                        DataGridViewRow r = ConstruirFila();
                        SetearFila(r, tipoDeIngrediente);
                        AñadirFila(r);
                        MessageBox.Show("Registro Agregado");
                    }
                    else
                    {
                        MessageBox.Show("Tipo de ingrediente repetido");
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }

        }
        private void tslBorrar_Click(object sender, EventArgs e)
        {
            if (dgvDatos.SelectedRows.Count > 0)
            {
                DataGridViewRow r = dgvDatos.SelectedRows[0];
                TipoDeIngrediente tipoDeIngrediente = (TipoDeIngrediente)r.Tag;

                DialogResult dr = MessageBox.Show(this, $"¿Desea dar de baja el tipo de ingrediente {tipoDeIngrediente.TipoDeIngredientes}?",
                    "Confirmar Baja",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    if (!_servicio.EstaRelacionado(tipoDeIngrediente))
                    {
                        try
                        {
                            _servicio.Borrar(tipoDeIngrediente.TipoDeIngredienteId);
                            dgvDatos.Rows.Remove(r);
                            MessageBox.Show("Registro borrado");
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(exception.Message);

                        }
                    }
                    else
                    {
                        MessageBox.Show("El registro esta relacionado, no se puede borrar");
                    }
                }
            }
        }
        public void AgregarFila(TipoDeIngrediente tipoDeIngrediente)
        {
            DataGridViewRow r = ConstruirFila();
            SetearFila(r, tipoDeIngrediente);
            AñadirFila(r);

        }
 private void tslEditar_Click(object sender, EventArgs e)
 {
     if (dgvDatos.SelectedRows.Count > 0)
     {
         DataGridViewRow r = dgvDatos.SelectedRows[0];
         TipoDeIngrediente tipoDeIngrediente = (TipoDeIngrediente)r.Tag;
         tipoDeIngrediente = _servicio.GetTipoDeIngredientePorId(tipoDeIngrediente.TipoDeIngredienteId);
         frmTiposDeIngredientesAE frm = new frmTiposDeIngredientesAE();
         frm.Text = "Editar TipoDeIngrediente";
         frm.SetTipoDeIngrediente(tipoDeIngrediente);
         DialogResult dr = frm.ShowDialog(this);
         if (dr == DialogResult.OK)
         {
             try
             {
                 tipoDeIngrediente = frm.GetTipoDeIngrediente();
                 if (!_servicio.Existe(tipoDeIngrediente))
                 {
                     _servicio.Guardar(tipoDeIngrediente);
                     SetearFila(r, tipoDeIngrediente);
                     MessageBox.Show("Registro Editado");
                 }
                 else
                 {
                     MessageBox.Show("Tipo de ingrediente Repetido");
                 }
             }
             catch (Exception exception)
             {
                 MessageBox.Show(exception.Message);
             }
         }
     }
 }
示例#5
0
 public void Guardar(TipoDeIngrediente tipoDeIngrediente)
 {
     if (tipoDeIngrediente.TipoDeIngredienteId == 0)
     {
         try
         {
             string     cadenaComando = "INSERT INTO TiposDeIngredientes VALUES(@nombre)";
             SqlCommand comando       = new SqlCommand(cadenaComando, _sqlConnection);
             comando.Parameters.AddWithValue("@nombre", tipoDeIngrediente.TipoDeIngredientes);
             comando.ExecuteNonQuery();
             cadenaComando = "SELECT @@IDENTITY";
             comando       = new SqlCommand(cadenaComando, _sqlConnection);
             tipoDeIngrediente.TipoDeIngredienteId = (int)(decimal)comando.ExecuteScalar();
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
     else
     {
         try
         {
             string     cadenaComando = "UPDATE TiposDeIngredientes SET TipoDeIngrediente=@nombre WHERE TipoDeIngredienteId=@id";
             SqlCommand comando       = new SqlCommand(cadenaComando, _sqlConnection);
             comando.Parameters.AddWithValue("@nombre", tipoDeIngrediente.TipoDeIngredientes);
             comando.Parameters.AddWithValue("@id", tipoDeIngrediente.TipoDeIngredienteId);
             comando.ExecuteNonQuery();
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
示例#6
0
 public bool Existe(TipoDeIngrediente tipoDeIngrediente)
 {
     try
     {
         SqlCommand comando;
         if (tipoDeIngrediente.TipoDeIngredienteId == 0)
         {
             string cadenaComando = "SELECT TipoDeIngredienteId, TipoDeIngrediente FROM TiposDeIngredientes WHERE TipoDeIngrediente=@nombre";
             comando = new SqlCommand(cadenaComando, _sqlConnection);
             comando.Parameters.AddWithValue("@nombre", tipoDeIngrediente.TipoDeIngredientes);
         }
         else
         {
             string cadenaComando = "SELECT TipoDeIngredienteId, TipoDeIngrediente FROM TiposDeIngredientes WHERE TipoDeIngrediente=@nombre AND TipoDeIngredienteid<>@id";
             comando = new SqlCommand(cadenaComando, _sqlConnection);
             comando.Parameters.AddWithValue("@nombre", tipoDeIngrediente.TipoDeIngredientes);
             comando.Parameters.AddWithValue("@id", tipoDeIngrediente.TipoDeIngredienteId);
         }
         SqlDataReader reader = comando.ExecuteReader();
         return(reader.HasRows);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public void Guardar(TipoDeIngrediente tipoDeIngrediente)
 {
     try
     {
         _conexion    = new ConexionBd();
         _repositorio = new RepositorioTiposDeIngredientes(_conexion.AbrirConexion());
         _repositorio.Guardar(tipoDeIngrediente);
         _conexion.CerrarConexion();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
示例#8
0
 public bool EstaRelacionado(TipoDeIngrediente tipoDeIngrediente)
 {
     try
     {
         var CadenaComando = "SELECT TipoDeIngredienteId FROM Proveedores WHERE TipoDeIngredienteId=@id";
         var Comando       = new SqlCommand(CadenaComando, _sqlConnection);
         Comando.Parameters.AddWithValue("@id", tipoDeIngrediente.TipoDeIngredienteId);
         var reader = Comando.ExecuteReader();
         return(reader.HasRows);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public bool EstaRelacionado(TipoDeIngrediente tipoDeIngrediente)
 {
     try
     {
         _conexion    = new ConexionBd();
         _repositorio = new RepositorioTiposDeIngredientes(_conexion.AbrirConexion());
         var estaRelacionado = _repositorio.EstaRelacionado(tipoDeIngrediente);
         _conexion.CerrarConexion();
         return(estaRelacionado);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
示例#10
0
        public static void CargarComboTiposDeIngredientes(ref ComboBox cbo)
        {
            ServicioTipoDeIngrediente servicioTipoDeIngrediente = new ServicioTipoDeIngrediente();

            cbo.DataSource = null;
            List <TipoDeIngrediente> lista = servicioTipoDeIngrediente.GetLista();
            var defaultTipoDeIngrediente   = new TipoDeIngrediente {
                TipoDeIngredienteId = 0, TipoDeIngredientes = "[Seleccione]"
            };

            lista.Insert(0, defaultTipoDeIngrediente);
            cbo.DataSource    = lista;
            cbo.DisplayMember = "TipoDeIngredientes";
            cbo.ValueMember   = "TipoDeIngredienteId";
            cbo.SelectedIndex = 0;
        }
示例#11
0
        private void btnAceptar_Click(object sender, System.EventArgs e)
        {
            if (ValidarDatos())
            {
                if (tipoDeIngrediente == null)
                {
                    tipoDeIngrediente = new TipoDeIngrediente();
                }

                tipoDeIngrediente.TipoDeIngredientes = txtTipoDeIngrediente.Text;
                if (ValidarObjeto())
                {
                    if (!_esEdicion)
                    {
                        try
                        {
                            _servicio.Guardar(tipoDeIngrediente);
                            if (frm != null)
                            {
                                frm.AgregarFila(tipoDeIngrediente);
                            }
                            MessageBox.Show("Registro Guardado", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            DialogResult dr = MessageBox.Show("¿Desea dar de alta otro registro?", "Confirmar",
                                                              MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dr == DialogResult.No)
                            {
                                DialogResult = DialogResult.Cancel;
                            }
                            else
                            {
                                InicializarControles();
                            }
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(exception.Message);
                        }
                    }
                    else
                    {
                        DialogResult = DialogResult.OK;
                    }
                }
            }
        }
示例#12
0
        public List <TipoDeIngrediente> GetLista()
        {
            List <TipoDeIngrediente> lista = new List <TipoDeIngrediente>();

            try
            {
                string        cadenaComando = "SELECT TipoDeIngredienteId, TipoDeIngrediente FROM TiposDeIngredientes";
                SqlCommand    comando       = new SqlCommand(cadenaComando, _sqlConnection);
                SqlDataReader reader        = comando.ExecuteReader();
                while (reader.Read())
                {
                    TipoDeIngrediente tipoDeIngrediente = ConstruirTipoDeIngrediente(reader);
                    lista.Add(tipoDeIngrediente);
                }
                reader.Close();
                return(lista);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
示例#13
0
        public TipoDeIngrediente GetTipoDeIngredientePorId(int id)
        {
            try
            {
                TipoDeIngrediente tipoDeIngrediente = null;
                string            cadenaComando     = "SELECT TipoDeIngredienteId, TipoDeIngrediente FROM TiposDeIngredientes WHERE TipoDeIngredienteId=@id";
                SqlCommand        comando           = new SqlCommand(cadenaComando, _sqlConnection);
                comando.Parameters.AddWithValue("@id", id);
                SqlDataReader reader = comando.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    tipoDeIngrediente = ConstruirTipoDeIngrediente(reader);
                    reader.Close();
                }

                return(tipoDeIngrediente);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        private void SetearFila(DataGridViewRow r, TipoDeIngrediente tipoDeIngrediente)
        {
            r.Cells[clmTipoDeIngredientes.Index].Value = tipoDeIngrediente.TipoDeIngredientes;

            r.Tag = tipoDeIngrediente;
        }
示例#15
0
 public void SetTipoDeIngrediente(TipoDeIngrediente tipoDeIngrediente)
 {
     this.tipoDeIngrediente = tipoDeIngrediente;
 }
示例#16
0
 private void InicializarControles()
 {
     txtTipoDeIngrediente.Clear();
     txtTipoDeIngrediente.Focus();
     tipoDeIngrediente = null;
 }