예제 #1
0
        private void AtualizarGrid(PedidoItem PedidoItem, bool booExcluir)
        {
            try
            {
                object FiltroExcluir = null;

                if (booExcluir)
                {
                    FiltroExcluir         = (LocalizarFiltroExcluir(dgwColecao) as PedidoItem).GetChavePrimaria();
                    dgwColecao.DataSource = null;
                    pedidoItemCollection.Remove(PedidoItem);
                }
                else
                {
                    if (PedidoItem != null)
                    {
                        var Item = from p in pedidoItemCollection
                                   where p.GetChavePrimaria() == PedidoItem.GetChavePrimaria()
                                   select p;

                        if (Item.Count() == 1)
                        {
                            PedidoItem PedidoItemSelecionado = Item.First();
                            PedidoItemSelecionado = PedidoItem;
                        }
                        else
                        {
                            pedidoItemCollection.Add(PedidoItem);
                        }
                    }
                    else
                    {
                        while (backgroundWorker1.IsBusy)
                        {
                            Application.DoEvents();
                        }
                        object[] args = new object[2];
                        args[0] = "PesquisarItemPedido";
                        args[1] = this.pedido.IDPedido;
                        backgroundWorker1.RunWorkerAsync(args);
                        while (backgroundWorker1.IsBusy)
                        {
                            Application.DoEvents();
                        }
                    }
                }

                dgwColecao.DataSource = null;
                if (pedidoItemCollection.Count() > 0)
                {
                    dgwColecao.DataSource = pedidoItemCollection.ToList <PedidoItem>();
                }

                txtRegistros.Text = dgwColecao.Rows.Count.ToString();

                //if (objPedidoItem != null)
                //    LocalizarIndexLinha(dgwColecao, FiltroExcluir == null ? objPedidoItem.GetChavePrimaria() : FiltroExcluir);

                dgwColecao.Update();
                dgwColecao.Refresh();

                if (dgwColecao.RowCount > 0)
                {
                    dgwColecao.Focus();
                }
            }
            catch (Exception ex)
            {
                Exceptionerro(ex);
            }
        }