Example #1
0
 public ItemDimensionAdjustmentSearchViewModel()
 {
     WarehouseClient.GetItemDimensionsQuantitiesByDateCompleted += (s, e) =>
     {
         if (e.Result.Count <= 0)
         {
             MessageBox.Show(strings.NoDataFound);
         }
         foreach (var iR in e.Result)
         {
             if (iR.ColorFrom == null)
             {
                 iR.ColorFrom = new TblColor()
                 {
                     Iserial = iR.ColorFromId,
                     Code    = iR.ColorFromCode
                 };
             }
             // هشوف لو موجود مش هحطه
             if (!SearchResultList.Any(sr => sr.ItemDimFromIserial == iR.ItemDimFromIserial))
             {
                 var qtemp = iR.AvailableQuantity;
                 iR.AvailableQuantity = 0;
                 iR.CountedQuantity   = 0;
                 iR.AvailableQuantity = qtemp;
                 SearchResultList.Add(iR);
             }
         }
         Loading   = false;
         FullCount = e.fullCount;
     };
     WarehouseClient.GetItemDimensionsOrCreateCompleted += (s, e) =>
     {
         SelectedSearchResultList.Clear();
         foreach (var item in e.Result)
         {
             SelectedSearchResultList.Add(item);
         }
         IsWorking = false;
     };
     WarehouseClient.GetAccWarehouseRowsCompleted += (s, e) =>
     {
         //اخر حاجة راجع بيند الكميات وبحث التسوية مش بيحسب الكميات غالبا بيند
         if (e.Result.Count <= 0)
         {
             MessageBox.Show(strings.NoDataFound);
         }
         foreach (var iR in e.Result)
         {
             // هشوف لو موجود مش هحطه
             if (!SearchResultList.Any(sr => sr.ItemDimFromIserial == iR.ItemDimFromIserial))
             {
                 var qtemp = iR.AvailableQuantity;
                 iR.AvailableQuantity = 0;
                 iR.CountedQuantity   = 0;
                 iR.AvailableQuantity = qtemp;
                 SearchResultList.Add(iR);
             }
         }
         Loading = false;
     };
     ApplyCommand = new RelayCommand((o) =>
     {
         var view = (o as ItemDimensionAdjustmentSearchChildWindow);
         if (view != null)
         {
             //هنا هاخد الى مختاره فى الجريد للشاشة الاصلية
             ApplySelectedItem(view);
         }
     });
     OkCommand = new RelayCommand((o) =>
     {
         var view = (o as ItemDimensionAdjustmentSearchChildWindow);
         if (view != null)
         {
             //هنا هاخد الى مختاره فى الجريد للشاشة الاصلية لو مكانش راح
             //وهقفل الشاشة فى الاخر
             ApplySelectedItem(view);
             view.DialogResult = true;
             view.Close();
         }
     });
 }
        public ItemDimensionSearchViewModel()
        {
            Client.AccWithConfigAndSizeCompleted += (s, sv) =>
            {
                bool isSearchItem    = false;
                var  itemSearchModel = SearchResultList.FirstOrDefault(i => i.ItemId == sv.Result.Iserial && i.ItemType == sv.Result.ItemGroup);
                CRUDManagerService.ItemsDto item;
                if (itemSearchModel != null)
                {
                    item         = itemSearchModel.ItemPerRow ?? (itemSearchModel.ItemPerRow = new CRUDManagerService.ItemsDto());
                    isSearchItem = true;
                }
                else
                {
                    item = ItemPerRow;
                }

                item.AccConfigList   = sv.Result.AccConfigList;
                item.SizesList       = new ObservableCollection <string>();
                item.CombinationList = sv.Result.CombinationList;

                var tblAccessoryAttributesDetails = sv.Result.CombinationList.FirstOrDefault();
                if (tblAccessoryAttributesDetails != null)
                {
                    item.SizesList.Add(tblAccessoryAttributesDetails.Size);
                }
                if (item.CombinationList != null)
                {
                    item.SizesList = new ObservableCollection <string>();
                }
                if (isSearchItem)
                {
                    if (item.AccConfigList == null)
                    {
                        item.AccConfigList = new ObservableCollection <CRUDManagerService.TblColor>();
                    }
                    itemSearchModel.ColorPerRow = item.AccConfigList.FirstOrDefault(c => c.Iserial == itemSearchModel.ColorToId);
                }
            };
            Client.InspectionRouteCompleted += (o, e) =>
            {
                foreach (var batchNo in e.Result.Select(x => x.RollBatch))
                {
                    if (!BatchNoList.Contains(batchNo))
                    {
                        BatchNoList.Add(batchNo);
                    }
                }
            };
            // Client.SearchF
            WarehouseClient.GetAccWarehouseRowsCompleted += (s, e) =>
            {
                if (e.Result.Count <= 0)
                {
                    MessageBox.Show(strings.NoDataFound);
                }
                foreach (var iR in e.Result)
                {
                    // هشوف لو موجود مش هحطه
                    if (!SearchResultList.Any(sr => sr.ItemDimFromIserial == iR.ItemDimFromIserial))
                    {
                        var qtemp = iR.AvailableQuantity;
                        iR.AvailableQuantity = 0;
                        // iR.CountedQuantity = 0;
                        iR.AvailableQuantity = qtemp;
                        if (iR.PendingQuantity > 0)
                        {
                            iR.TransferredQuantity = iR.AvailableQuantity;
                        }
                        else
                        {
                            iR.TransferredQuantity = iR.AvailableQuantity + iR.PendingQuantity;
                        }
                        ItemDimensionSearchModel item = new ItemDimensionSearchModel();
                        item.InjectFrom(iR);
                        if (item.ItemPerRow == null)
                        {
                            item.ItemPerRow = new CRUDManagerService.ItemsDto();
                        }
                        if (ItemPerRow.Iserial > 0)
                        {
                            item.ItemPerRow.InjectFrom(ItemPerRow);
                        }
                        //else
                        //    Client.AccWithConfigAndSizeAsync(new CRUDManagerService.ItemsDto()
                        //    {
                        //        Iserial = item.ItemId,
                        //        ItemGroup = item.ItemType,
                        //        Code=item.ItemCode,
                        //    });
                        if (item.ItemPerRow.AccConfigList == null)
                        {
                            item.ItemPerRow.AccConfigList = new ObservableCollection <CRUDManagerService.TblColor>();
                        }
                        var colorRow = item.ItemPerRow.AccConfigList.FirstOrDefault(c => c.Iserial == iR.ColorPerRow.Iserial);
                        if (colorRow == null)
                        {
                            colorRow = new CRUDManagerService.TblColor()
                            {
                                Iserial = item.ColorFromId,
                                Code    = item.ColorFromCode
                            };
                        }
                        item.ColorPerRow = colorRow;

                        SearchResultList.Add(item);
                    }
                }
                Loading = false;
            };
            WarehouseClient.GetItemDimensionsOrCreteForTransferCompleted += (s, e) =>
            {
                SelectedSearchResultList.Clear();
                foreach (var item in e.Result)
                {
                    ItemDimensionSearchModel temp = new ItemDimensionSearchModel();
                    temp.InjectFrom(item);
                    temp.ItemPerRow = ItemPerRow;
                    temp.ColorPerRow.InjectFrom(item.ColorPerRow);
                    SelectedSearchResultList.Add(temp);
                }
                IsWorking = false;
            };
            CancelCommand = new RelayCommand((o) => // هقفل وارجع فولس يعرف انه كنسل
            {
                var view = (o as ChildWindowsOverride);
                if (view != null)
                {
                    view.DialogResult = false;
                    view.Close();
                }
            });
            ApplyCommand = new RelayCommand((o) =>
            {
                var view = (o as ItemDimensionSearchChildWindow);
                if (view != null)
                {
                    //هنا هاخد الى مختاره فى الجريد للشاشة الاصلية
                    ApplySelectedItem(view);
                }
            });
            OkCommand = new RelayCommand((o) =>
            {
                var view = (o as ItemDimensionSearchChildWindow);
                if (view != null)
                {
                    //هنا هاخد الى مختاره فى الجريد للشاشة الاصلية لو مكانش راح
                    //وهقفل الشاشة فى الاخر
                    ApplySelectedItem(view);
                    view.DialogResult = true;
                    view.Close();
                }
            });
            LoadingRow = new GalaSoft.MvvmLight.Command.RelayCommand <object>((o) =>
            {
                var e = o as System.Windows.Controls.DataGridRowEventArgs;
                if (SearchResultList.Count < PageSize)
                {
                    return;
                }
                if (SearchResultList.Count - 2 < e.Row.GetIndex() && !Loading)
                {
                    GetInspectionWarehouseRows();
                }
            });
            DetailSelectionChanged = new GalaSoft.MvvmLight.Command.RelayCommand <object>(
                (o) => {
                var e    = o as System.Windows.Controls.SelectionChangedEventArgs;
                var temp = new Web.DataLayer.ItemDimensionSearchModel();
                if (e.AddedItems != null && e.AddedItems.Count > 0)
                {
                    temp.InjectFrom(e.AddedItems[0]);
                    WarehouseClient.GetItemToQuantitiesAsync(temp, WarehouseToCode);
                }
            });
            WarehouseClient.GetItemToQuantitiesCompleted += (s, e) =>
            {
                var item = SearchResultList.FirstOrDefault(rl =>
                                                           rl.ItemId == e.Result.ItemId && rl.ItemType == e.Result.ItemType &&
                                                           rl.ItemDimFromIserial == e.Result.ItemDimFromIserial &&
                                                           rl.ColorFromId == e.Result.ColorFromId &&
                                                           rl.SizeFrom == e.Result.SizeFrom && rl.BatchNoFrom == e.Result.BatchNoFrom &&
                                                           rl.ColorToId == e.Result.ColorToId && rl.SizeTo == e.Result.SizeTo &&
                                                           rl.BatchNoTo == e.Result.BatchNoTo);
                if (item != null)
                {
                    item.ItemDimToIserial    = e.Result.ItemDimToIserial;
                    item.AvailableToQuantity = e.Result.AvailableToQuantity;
                    item.PendingToQuantity   = e.Result.PendingToQuantity;
                }
                else
                {
                    //item.AvailableToQuantity = 0;
                    //item.PendingToQuantity = 0;
                }
            };

            WarehouseClient.GetItemGroupCompleted += (s, e) =>
            {
                foreach (var item in e.Result)
                {
                    ItemTypes.Add(item);
                }
            };
            WarehouseClient.GetItemGroupAsync();
        }