private void OnShowFilter(KafelekFiltr _kafelekfiltr)
        {
            kafelekfiltr = _kafelekfiltr;

            if (kafelekfiltr.TypFiltra == 1)
            {
                UpdateMagView();
                return;
            }

            if (bgWorkerFiltr.IsBusy)
            {
                return;
            }
            else if (bgWorker.IsBusy)
            {
                return;
            }
            else
            {
                bgWorkerFiltr.RunWorkerAsync();
            }
        }
        private void LoadZamowieniaFlitr(KafelekFiltr kafelekfiltr)
        {
            try
            {
                if (kafelekfiltr.TypFiltra == 2)
                {
                    List <IHP_NAGLDOK> n = new List <IHP_NAGLDOK>();
                    //var IHP_NAGLDOK = PredicateBuilder.True<IHP_NAGLDOK>();
                    ////if (kafelekfiltr.IdKontrah > 0)
                    ////      n = Nagls.Where((x => x.ID_KONTRAH == kafelekfiltr.IdKontrah &&  x.DATADOK>kafelekfiltr.DataOd  && x.DATADOK < kafelekfiltr.DataDo)).ToList();
                    ////else
                    ////      n = Nagls.Where((x =>x.DATADOK > kafelekfiltr.DataOd && x.DATADOK < kafelekfiltr.DataDo)).ToList();

                    //if (kafelekfiltr.IdKontrah > 0)
                    //{
                    //    predicate = predicate.And(x => x.ID_KONTRAH == kafelekfiltr.IdKontrah);
                    //}


                    //predicate = predicate.And(x => x.DATADOK >= kafelekfiltr.DataOd);
                    //predicate = predicate.And(x => x.DATADOK <= kafelekfiltr.DataDo);

                    //n = context.NAGL.Where(predicate).ToList();

                    Items.Clear();
                    foreach (IHP_NAGLDOK item in n.OrderByDescending(x => x.ID_IHP_NAGLDOK))
                    {
                        ItemKafelek   ik           = new ItemKafelek();
                        StringBuilder captlocal    = new StringBuilder();
                        string        sumalosc     = string.Empty;
                        string        termin       = string.Empty;
                        decimal       sumadec      = 0;
                        int           linia        = 1;
                        string        nazwakontrah = string.Empty;
                        if (!string.IsNullOrEmpty(item.IHP_KONTRAHENT_ARCH.NAZWA))
                        {
                            nazwakontrah = item.IHP_KONTRAHENT_ARCH.NAZWA;
                        }

                        ik.IdKontrah = item.ID_IHP_KONTRAHENT_ARCH;
                        ik.IdNagl    = item.ID_IHP_NAGLDOK;
                        // ik.StatusZam = item.IHP_STATUSZAM;
                        ik.Kontrah = nazwakontrah;

                        foreach (IHP_POZDOK itempoz in item.IHP_POZDOK.Where(x => x.ID_IHP_KARTOTEKA == 4))
                        {
                            // captlocal.Append(itempoz.KARTOTEKA.NAZWASKR + "(" + itempoz.WYMIARX.ToString() + "X" + itempoz.WYMIARY.ToString() + ") " + System.Environment.NewLine);
                            // sumadec += itempoz.ILOSCRAZEM ;
                            linia++;
                            if (linia >= 4)
                            {
                                captlocal.Append("...");
                                break;
                            }
                        }
                        //uzupelnij puste
                        for (int i = 0; i < 4 - linia; i++)
                        {
                            captlocal.AppendLine("");
                        }
                        sumadec    = Math.Round(sumadec, 2);
                        ik.NrZam   = item.NRDOKWEW;
                        termin     = "ter.: " + item.TERMINREALIZ.Value.ToShortDateString();
                        ik.Termin  = termin;
                        ik.Caption = captlocal.ToString();
                        Items.Add(ik);
                        Thread.Sleep(100);
                    }
                }
                Thread.Sleep(500);
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }