private bool AddAlbaran()
        {
            if (_entity.OidSerie == 0)
            {
                PgMng.ShowInfoException(Resources.Messages.NO_SERIE_SELECTED);
                return(false);
            }

            OutputDeliveryList list = null;

            if (!_entity.AlbaranContado)
            {
                if (_entity.OidCliente != 0)
                {
                    list = OutputDeliveryList.GetNoFacturados(true, _entity.OidCliente, _entity.OidSerie, (_entity.Rectificativa ? ETipoFactura.Rectificativa : ETipoFactura.Ordinaria));
                }
                else
                {
                    list = OutputDeliveryList.GetNoFacturados(true, 0, _entity.OidSerie, (_entity.Rectificativa ? ETipoFactura.Rectificativa : ETipoFactura.Ordinaria));
                }
            }
            else
            {
                list = OutputDeliveryList.GetNoFacturadosAgrupados(_entity.OidSerie, true);
            }

            //Quitamos de la lista los ya aƱadidos
            List <OutputDeliveryInfo> lista = new List <OutputDeliveryInfo>();

            foreach (OutputDeliveryInfo item in list)
            {
                if (_entity.AlbaranFacturas.GetItemByAlbaran(item.Oid) == null)
                {
                    lista.Add(item);
                }
            }

            OutputDeliveryList lista_completa = OutputDeliveryList.GetListByCliente(true, _entity.OidCliente);

            //AƱadimos a lista los eliminados
            foreach (AlbaranFactura item in _albaranes_factura)
            {
                if (_entity.AlbaranFacturas.GetItemByAlbaran(item.OidAlbaran) == null)
                {
                    lista.Add(lista_completa.GetItem(item.OidAlbaran));
                }
            }

            DeliverySelectForm form = new DeliverySelectForm(this, ETipoEntidad.Cliente, OutputDeliveryList.GetList(lista));

            form.ShowDialog(this);
            if (form.DialogResult == DialogResult.OK)
            {
                _results = form.Selected as List <OutputDeliveryInfo>;

                if (_entity.Rectificativa && (_results.Count > 1))
                {
                    PgMng.ShowInfoException("No es posible asignar varios albaranes a una factura rectificativa.");
                    return(false);
                }

                foreach (OutputDeliveryInfo item in _results)
                {
                    if (item.OidHolder != _results[0].OidHolder)
                    {
                        PgMng.ShowInfoException("No es posible asignar albaranes de clientes distintos a una misma Factura.");
                        return(false);
                    }
                }

                _back_job = BackJob.AddAlbaran;
                //PgMng.StartBackJob(this);

                DoAddAlbaran(null);

                if (Result == BGResult.OK)
                {
                    Serie_BT.Enabled = false;
                    Datos.ResetBindings(false);
                }
            }

            if ((_entity.AlbaranContado) && (_entity.Conceptos.Count < 0))
            {
                Agrupada_CkB.Enabled = false;
            }

            return(false);
        }
        public override void UpdateList()
        {
            switch (_current_action)
            {
            case molAction.Add:
            case molAction.Copy:
                if (_entity == null)
                {
                    return;
                }
                if (List.GetItem(_entity.Oid) != null)
                {
                    return;
                }
                List.AddItem(_entity.GetInfo(false));
                if (FilterType == IFilterType.Filter)
                {
                    OutputDeliveryList listA = OutputDeliveryList.GetList(_filter_results);
                    listA.AddItem(_entity.GetInfo(false));
                    _filter_results = listA.GetSortedList();
                }
                break;

            case molAction.CustomAction1:
            case molAction.CustomAction2:
            case molAction.Edit:
            case molAction.Lock:
            case molAction.Unlock:

                if (_selected != null)
                {
                    List <OutputDeliveryInfo> entities = (List <OutputDeliveryInfo>)_selected;
                    foreach (OutputDeliveryInfo item in entities)
                    {
                        List.GetItem(item.Oid).CopyFrom(item);
                        if (FilterType == IFilterType.Filter)
                        {
                            OutputDeliveryList list   = OutputDeliveryList.GetList(_filter_results);
                            OutputDeliveryInfo entity = list.GetItem(item.Oid);
                            if (entity != null)
                            {
                                entity.CopyFrom(item);
                            }
                            _filter_results = list.GetSortedList();
                        }
                    }
                }

                if (_entity == null)
                {
                    return;
                }
                ActiveItem.CopyFrom(_entity);

                break;

            case molAction.Delete:
                if (ActiveItem == null)
                {
                    return;
                }
                List.RemoveItem(ActiveOID);
                if (FilterType == IFilterType.Filter)
                {
                    OutputDeliveryList listD = OutputDeliveryList.GetList(_filter_results);
                    listD.RemoveItem(ActiveOID);
                    _filter_results = listD.GetSortedList();
                }
                break;
            }

            RefreshSources();
            if (_entity != null)
            {
                Select(_entity.Oid);
            }
            _entity = null;
        }