Example #1
0
        public static bool Guardar(CotizarArticulos articulo)
        {
            bool     paso     = false;
            Contexto contexto = new Contexto();

            try
            {
                if (contexto.Cotizar.Add(articulo) != null)
                {
                    foreach (var item in articulo.Detalle)
                    {
                        contexto.Articulos.Find(item.ArticuloId).CantCotizada += item.Cantidad;
                    }

                    contexto.SaveChanges();
                    paso = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                contexto.Dispose();
            }

            return(paso);
        }
Example #2
0
        public static bool Eliminar(int id)
        {
            bool     paso     = false;
            Contexto contexto = new Contexto();

            try
            {
                CotizarArticulos articulo = contexto.Cotizar.Find(id);

                foreach (var item in articulo.Detalle)
                {
                    var cotizar = contexto.Articulos.Find(item.ArticuloId).CantCotizada -= item.Cantidad;
                }

                contexto.Cotizar.Remove(articulo);

                if (contexto.SaveChanges() > 0)
                {
                    paso = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                contexto.Dispose();
            }
            return(paso);
        }
Example #3
0
        public static CotizarArticulos Buscar(int id)
        {
            Contexto         contexto = new Contexto();
            CotizarArticulos articulo = new CotizarArticulos();

            try
            {
                articulo = contexto.Cotizar.Find(id);
                articulo.Detalle.Count();

                foreach (var item in articulo.Detalle)
                {
                    string d = item.Articulo.Descripcion;
                    string n = item.Persona.Nombres;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                contexto.Dispose();
            }
            return(articulo);
        }
Example #4
0
        private void Buscar_button_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Id_numericUpDown.Value);
            CotizarArticulos articulo = BLL.CotizarArticulosBLL.Buscar(id);

            if (articulo != null)
            {
                LlenaCampos(articulo);
            }
            else
            {
                MessageBox.Show("No hay resultados!!", "Busqueda Fallida!!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Example #5
0
        //llenar los campos del registro
        private void LlenaCampos(CotizarArticulos cotizar)
        {
            Id_numericUpDown.Value = cotizar.CotizarId;
            FechaCotizacion_dateTimePicker.Value = cotizar.Fecha;
            Total_numericUpDown.Value            = cotizar.Total;
            Comentarios_textBox.Text             = cotizar.Comentarios;

            DetalleDataGridView.DataSource = cotizar.Detalle;

            DetalleDataGridView.Columns["Id"].Visible         = false;
            DetalleDataGridView.Columns["CotizarId"].Visible  = false;
            DetalleDataGridView.Columns["ArticuloId"].Visible = false;
            DetalleDataGridView.Columns["PersonaId"].Visible  = false;
        }
Example #6
0
        public static bool Modificar(CotizarArticulos articulo)
        {
            bool     paso     = false;
            Contexto contexto = new Contexto();

            try
            {
                var cotizacionAnt = BLL.CotizarArticulosBLL.Buscar(articulo.CotizarId);

                foreach (var item in cotizacionAnt.Detalle)
                {
                    contexto.Articulos.Find(item.ArticuloId).CantCotizada -= item.Cantidad;

                    if (!articulo.Detalle.ToList().Exists(a => a.Id == item.Id))
                    {
                        contexto.Articulos.Find(item.ArticuloId).CantCotizada -= item.Cantidad;
                        item.Articulo = null;
                        contexto.Entry(item).State = EntityState.Deleted;
                    }
                }

                foreach (var item in articulo.Detalle)
                {
                    contexto.Articulos.Find(item.ArticuloId).CantCotizada += item.Cantidad;

                    var estado = item.Id > 0 ? EntityState.Modified : EntityState.Added;
                    contexto.Entry(item).State = estado;
                }

                contexto.Entry(articulo).State = EntityState.Modified;
                if (contexto.SaveChanges() > 0)
                {
                    paso = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                contexto.Dispose();
            }


            return(paso);
        }
Example #7
0
        //llenar la entidad con los datos
        private CotizarArticulos LlenaClase()
        {
            CotizarArticulos cotizar = new CotizarArticulos();

            cotizar.CotizarId   = Convert.ToInt32(Id_numericUpDown.Value);
            cotizar.Fecha       = FechaCotizacion_dateTimePicker.Value.Date;
            cotizar.Total       = Total_numericUpDown.Value;
            cotizar.Comentarios = Comentarios_textBox.Text;

            foreach (DataGridViewRow item in DetalleDataGridView.Rows)
            {
                cotizar.AgregarDetalle(
                    ToInt(item.Cells["Id"].Value),
                    ToInt(item.Cells["CotizarId"].Value),
                    ToInt(item.Cells["ArticuloId"].Value),
                    ToInt(item.Cells["PersonaId"].Value),
                    ToInt(item.Cells["Cantidad"].Value),
                    ToInt(item.Cells["Precio"].Value),
                    ToInt(item.Cells["Importe"].Value)
                    );
            }

            return(cotizar);
        }