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

            OutputDeliveryList list = null;

            list = OutputDeliveryList.GetNoTicketList(_entity.OidSerie, true);

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

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

            OutputDeliveryList lista_completa = OutputDeliveryList.GetList(false, ETipoEntidad.Cliente);

            //Añadimos a lista los eliminados
            foreach (AlbaranTicket item in _albaranes_factura)
            {
                if (_entity.AlbaranTickets.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.ETipoFactura == ETipoFactura.Rectificativa) && (_results.Count > 1))
                {
                    PgMng.ShowInfoException("No es posible asignar varios albaranes a un ticket rectificativo.");
                    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 mismo Ticket.");
                        return(false);
                    }
                }

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

                DoAddAlbaran(null);

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

            return(false);
        }