async void LoadSerieBatch()
        {
            if (batchLoaded)
            {
                return;
            }
            SetBusy();
            var lst = await api.Query <InvSerieBatch>(new InvSerieBatchOpen());

            if (lst == null || lst.Length == 0)
            {
                ClearBusy();
                return;
            }

            var mainList   = (List <InvItemStorageCount>)dgInvStockStatus.ItemsSource;
            var search     = new InvItemStorageCount();
            var sort       = new InvItemStorageLocalSort();
            var cnt        = mainList.Count;
            var extraItems = new List <InvItemStorageCount>(cnt);

            foreach (var rec in lst)
            {
                var itm = rec._Item;
                search._Item = itm;
                var idx = mainList.BinarySearch(search, sort);
                if (idx < 0)
                {
                    idx = ~idx;
                }
                if (idx >= 0 && idx < cnt && mainList[idx]._Item == itm)
                {
                    var r    = new InvItemStorageCount();
                    var item = mainList[idx];
                    StreamingManager.Copy(item, r);
                    r._SerieBatch  = rec._Number;
                    r._Qty         = rec._Qty - rec._QtySold;
                    r._QtyReserved = rec._QtyMarked;
                    r._Warehouse   = rec._Warehouse;
                    r._Location    = rec._Location;
                    r._QtyOrdered  = 0;
                    r._Quantity    = null;
                    extraItems.Add(r);
                }
            }
            extraItems.AddRange(mainList);
            extraItems.Sort(sort);
            dgInvStockStatus.ItemsSource = extraItems;
            SerieBatch.Visible           = true;
            batchLoaded = true;
            ClearBusy();
        }
        public async Task BindGrid(IEnumerable <PropValuePair> propValuePair)
        {
            await dgInvStockStatus.Filter(propValuePair);

            var mainList = (List <InvItemStorageCount>)dgInvStockStatus.ItemsSource;

            if (mainList == null)
            {
                return;
            }

            var search = new InvItemStorageCount();
            var sort   = new InvItemStorageLocalSort();
            var cnt    = mainList.Count;
            var api    = this.api;

            if (this.items == null)
            {
                this.items = await api.LoadCache(typeof(Uniconta.DataModel.InvItem));
            }

            if (propValuePair == null || propValuePair.Count() == 0)
            {
                var lst = new List <InvItemStorageCount>(cnt);
                foreach (var item in (Uniconta.DataModel.InvItem[]) this.items.GetNotNullArray)
                {
                    if (item._ItemType == (byte)ItemType.Service)
                    {
                        continue;
                    }
                    var itm = item._Item;
                    search._Item = itm;
                    var idx = mainList.BinarySearch(search, sort);
                    if (idx < 0)
                    {
                        idx = ~idx;
                    }
                    if (idx >= 0 && idx < cnt && mainList[idx]._Item == itm)
                    {
                        continue;
                    }
                    var r = new InvItemStorageCount();
                    r.SetMaster(item);
                    lst.Add(r);
                }
                if (lst.Count > 0)
                {
                    lst.AddRange(mainList);
                    lst.Sort(sort);
                    mainList = lst;
                }
            }
            if (api.CompanyEntity.ItemVariants && api.CompanyEntity._LoadVariantsInCounting)
            {
                var stds = await api.Query <InvStandardVariantCombi>();

                var newList = AddVariants(mainList, stds);
                if (newList != null)
                {
                    newList.Sort(sort);
                    mainList = newList;
                }
            }
            dgInvStockStatus.ItemsSource = mainList;

            SerieBatch.Visible = false;
            batchLoaded        = false;
        }