Esempio n. 1
0
        private async void DoExtractRsns(object obj)
        {
            try
            {
                LoadingRSNs    = true;
                ExtractRsnView = null;
                if (FromBatch != null && FromCategory != null)
                {
                    var result = await RestHub.ExtractRsn(SelectedDeliveryBatch.Id, FromCategory.Value);

                    if (result.HttpCode == System.Net.HttpStatusCode.OK)
                    {
                        List <ExtractRSNDto> dtos = (List <ExtractRSNDto>)result.UserObject;
                        ExtractedRsns = new ObservableCollection <ExtractRsnVM>();
                        int count = 1;
                        Dictionary <string, Dictionary <int, int> > tanWiseRxnIdWiseTotalLengths = new Dictionary <string, Dictionary <int, int> >();
                        var tanNumbers = dtos.Select(dto => dto.TanNumber).Distinct();
                        foreach (var tan in tanNumbers)
                        {
                            tanWiseRxnIdWiseTotalLengths[tan] = dtos
                                                                .Where(d => d.TanNumber == tan)
                                                                .GroupBy(d => d.RXNSno)
                                                                .ToDictionary(d => d.Key, d => d.Select(dto => dto.CVT.SafeLength() + dto.FreeText.SafeLength()).Sum());
                        }
                        foreach (var dto in dtos)
                        {
                            var          rxnIdWiseTotalLengths = tanWiseRxnIdWiseTotalLengths[dto.TanNumber];
                            ExtractRsnVM vm = new ExtractRsnVM
                            {
                                TanNumber     = dto.TanNumber,
                                RXNSno        = dto.RXNSno,
                                ProductNumber = dto.ProductNumber,
                                RxnSeq        = dto.RxnSeq,
                                Stage         = dto.Stage,
                                CVT           = dto.CVT,
                                FreeText      = dto.FreeText,
                                Level         = dto.RSNType,
                                Id            = dto.Id,
                                DisplayOrder  = count++
                            };
                            if (rxnIdWiseTotalLengths != null && rxnIdWiseTotalLengths.ContainsKey(dto.RXNSno))
                            {
                                vm.TotalLength = rxnIdWiseTotalLengths[dto.RXNSno];
                                vm.Comment     = $"Reaction {dto.RXNSno} Info.";
                            }
                            ExtractedRsns.Add(vm);
                        }
                        ExtractRsnView = new ListCollectionView(ExtractedRsns);
                        ExtractRsnView.SortDescriptions.Add(new SortDescription("DisplayOrder", ListSortDirection.Ascending));
                        ExtractRsnView.SortDescriptions.Add(new SortDescription("TanNumber", ListSortDirection.Ascending));
                        ExtractRsnView.SortDescriptions.Add(new SortDescription("Sno", ListSortDirection.Ascending));
                        ExtractRsnView.SortDescriptions.Add(new SortDescription("RxnSeq", ListSortDirection.Ascending));
                        ExtractRsnView.SortDescriptions.Add(new SortDescription("Stage", ListSortDirection.Ascending));
                    }
                    else
                    {
                        AppErrorBox.ShowErrorMessage("Can't Update RSN", result.StatusMessage);
                    }
                }
                else
                {
                    AppInfoBox.ShowInfoMessage("From Batch and Category Are Required");
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
                AppErrorBox.ShowErrorMessage("Error while Extract RSNs", ex.ToString());
            }
            finally
            {
                LoadingRSNs = false;
            }
        }