public void Execute(object parameter)
 {
     if (parameter.Equals("Agregar"))
     {
         this.IsReadOnlyCodigoCategoria = false;
         this.IsReadOnlyCodigoEmpaque   = false;
         this.IsReadOnlyDescripcion     = false;
         this.IsReadOnlyPrecioPorUnidad = false;
         this.IsReadOnlyPrecioPorDocena = false;
         this.IsReadOnlyPrecioPorMayor  = false;
         this.IsReadOnlyExistencia      = false;
     }
     if (parameter.Equals("Guardar"))
     {
         Producto nuevo = new Producto();
         nuevo.CodigoCategoria = Convert.ToInt16(this.CodigoCategoria);
         nuevo.CodigoEmpaque   = Convert.ToInt16(this.CodigoEmpaque);
         nuevo.Descripcion     = this.Descripcion;
         nuevo.PrecioUnitario  = Convert.ToInt16(this.PrecioPorUnidad);
         nuevo.PrecioPorDocena = Convert.ToInt16(this.PrecioPorDocena);
         nuevo.PrecioPorMayor  = Convert.ToInt16(this.PrecioPorMayor);
         nuevo.Existencia      = Convert.ToInt16(this.Existencia);
         db.Productos.Add(nuevo);
         db.SaveChanges();
         this.Productos.Add(nuevo);
         MessageBox.Show("Registro almacenado");
     }
 }
Exemplo n.º 2
0
 public void Execute(object parameter)
 {
     if (parameter.Equals("Agregar"))
     {
         this.IsReadOnlyDescripcion = false;
     }
     if (parameter.Equals("Guardar"))
     {
         TipoEmpaque nuevo = new TipoEmpaque();
         nuevo.Descripcion = this.Descripcion;
         db.TipoEmpaques.Add(nuevo);
         db.SaveChanges();
         this.TipoEmpaques.Add(nuevo);
         MessageBox.Show("Registro Almacenado");
     }
 }
 public void Execute(object parameter)
 {
     if (parameter.Equals("Agregar"))
     {
         this.IsReadOnlyNit               = false;
         this.IsReadOnlyRazonSocial       = false;
         this.IsReadOnlyDireccion         = false;
         this.IsReadOnlyPaginaWeb         = false;
         this.IsReadOnlyContactoPrincipal = false;
     }
     if (parameter.Equals("Guardar"))
     {
         Proveedor nuevo = new Proveedor();
         nuevo.Nit               = this.Nit;
         nuevo.RazonSocial       = this.RazonSocial;
         nuevo.Direccion         = this.Direccion;
         nuevo.PaginaWeb         = this.PaginaWeb;
         nuevo.ContactoPrincipal = this.ContactoPrincipal;
         db.Proveedores.Add(nuevo);
         db.SaveChanges();
         this.Proveedores.Add(nuevo);
         MessageBox.Show("Registro Almacenado");
     }
 }
        public void Execute(object parameter)        //ejecuta evento
        {
            if (parameter.Equals("Agregar"))
            {
                this.IsReadOnlyDescripcion = false;
                this.accion             = ACCION.NUEVO;
                this.IsEnableAgregar    = false;
                this.IsEnableEliminar   = false;
                this.IsEnableActualizar = false;
                this.IsEnableCancelar   = true;
                this.IsEnableGuardar    = true;
            }
            if (parameter.Equals("Guardar"))
            {
                switch (this.accion)
                {
                case ACCION.NUEVO:
                    Categoria nuevo = new Categoria();
                    nuevo.Descripcion = this.Descripcion;
                    db.Categorias.Add(nuevo);
                    db.SaveChanges();
                    this.Categorias.Add(nuevo);
                    MessageBox.Show("Registro Almacenado");
                    break;

                case ACCION.ACTUALIZAR:
                    try
                    {
                        int posicion        = this.Categorias.IndexOf(this.SelectCategoria);
                        var updateCategoria = this.db.Categorias.Find(this.SelectCategoria.CodigoCategoria);
                        updateCategoria.Descripcion          = this.Descripcion;
                        this.db.Entry(updateCategoria).State = EntityState.Modified;
                        this.db.SaveChanges();
                        this.Categorias.RemoveAt(posicion);
                        this.Categorias.Insert(posicion, updateCategoria);
                        MessageBox.Show("Registro Actualizado!!!");
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                    break;
                }
                this.IsEnableAgregar       = true;
                this.IsEnableEliminar      = true;
                this.IsEnableActualizar    = true;
                this.IsEnableCancelar      = false;
                this.IsEnableGuardar       = false;
                this.IsReadOnlyDescripcion = true;
            }

            else if (parameter.Equals("Actualizar"))
            {
                this.accion = ACCION.ACTUALIZAR;
                this.IsReadOnlyDescripcion = false;
                this.IsEnableAgregar       = false;
                this.IsEnableEliminar      = false;
                this.IsEnableActualizar    = false;
                this.IsEnableCancelar      = true;
                this.IsEnableGuardar       = true;
            }
            else if (parameter.Equals("Eliminar"))
            {
                if (this.SelectCategoria != null)
                {
                    var respuesta = MessageBox.Show("Esta seguro de eliminar el registo?", "Eliminar", MessageBoxButton.YesNo);
                    if (respuesta == MessageBoxResult.Yes)
                    {
                        try
                        {
                            db.Categorias.Remove(this.SelectCategoria);
                            db.SaveChanges();
                            this.Categorias.Remove(this.SelectCategoria);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }

                        MessageBox.Show("Registro eliminado correctamente!!");
                    }
                }
                else
                {
                    MessageBox.Show("Debe seleccionar un registro", "Eliminar", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else if (parameter.Equals("Cancelar"))
            {
                this.IsEnableAgregar        = true;
                this.IsEnableEliminar       = true;
                this.IsEnableActualizar     = true;
                this.IsEnableCancelar       = false;
                this.IsEnableGuardar        = false;
                this._IsReadOnlyDescripcion = true;
            }
        }