Exemple #1
0
 internal async void OnCurrentAsycudaDocumentIDChanged(object sender, NotificationEventArgs <string> e)
 {
     using (AsycudaDocumentRepository ctx = new AsycudaDocumentRepository())
     {
         CurrentAsycudaDocument = await ctx.GetAsycudaDocument(e.Data).ConfigureAwait(continueOnCapturedContext: false);
     }
     NotifyPropertyChanged(m => CurrentAsycudaDocument);
 }
        public async Task SelectAll()
        {
            IEnumerable <AsycudaDocument> lst = null;

            using (var ctx = new AsycudaDocumentRepository())
            {
                lst = await ctx.GetAsycudaDocumentsByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            SelectedAsycudaDocuments = new ObservableCollection <AsycudaDocument>(lst);
        }
        public async Task Send2Excel(string folder, AsycudaDocument doc)
        {
            if (doc != null)
            {
                using (var ctx = new AsycudaDocumentRepository())
                {
                    var doctype = await ctx.GetAsycudaDocument(doc.ASYCUDA_Id.ToString()).ConfigureAwait(false);

                    if (doctype.DocumentType == "IM7")
                    {
                        return;
                    }
                }
            }

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(() =>
                {
                    var s = new ExportToExcel <SaleReportLine, List <SaleReportLine> >();
                    s.StartUp();

                    try
                    {
                        folder   = Path.GetDirectoryName(folder);
                        var data = GetDocumentSalesReport(doc.ASYCUDA_Id).Result;
                        if (data != null)
                        {
                            string path = Path.Combine(folder,
                                                       !string.IsNullOrEmpty(doc.CNumber) ? doc.CNumber : doc.ReferenceNumber + ".xls");

                            s.dataToPrint = data.ToList();
                            s.SaveReport(path);
                        }
                        else
                        {
                            s.dataToPrint = new List <SaleReportLine>();
                            File.Create(Path.Combine(folder, doc.CNumber ?? doc.ReferenceNumber + ".xls"));
                        }
                        StatusModel.StatusUpdate();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    s.ShutDown();
                },
                                            CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
        public IList <AsycudaDocument> LoadRange(int startIndex, int count, SortDescriptionCollection sortDescriptions, out int overallCount)
        {
            try
            {
                if (FilterExpression == null)
                {
                    FilterExpression = "All";
                }
                using (var ctx = new AsycudaDocumentRepository())
                {
                    var r = ctx.LoadRange(startIndex, count, FilterExpression, navExp, IncludesLst);
                    overallCount = r.Result.Item2;

                    return(r.Result.Item1.ToList());
                }
            }
            catch (Exception ex)
            {
                StatusModel.Message(ex.Message);
                overallCount = 0;
                return(new List <AsycudaDocument>());
            }
        }
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <AsycudaDocument> lst = null;

            using (var ctx = new AsycudaDocumentRepository())
            {
                lst = await ctx.GetAsycudaDocumentsByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <AsycudaDocumentExcelLine, List <AsycudaDocumentExcelLine> >
            {
                dataToPrint = lst.Select(x => new AsycudaDocumentExcelLine
                {
                    id = x.id,


                    CNumber = x.CNumber,


                    RegistrationDate = x.RegistrationDate,


                    IsManuallyAssessed = x.IsManuallyAssessed,


                    ReferenceNumber = x.ReferenceNumber,


                    EffectiveRegistrationDate = x.EffectiveRegistrationDate,


                    DoNotAllocate = x.DoNotAllocate,


                    AutoUpdate = x.AutoUpdate,


                    BLNumber = x.BLNumber,


                    Description = x.Description,


                    Type_of_declaration = x.Type_of_declaration,


                    Declaration_gen_procedure_code = x.Declaration_gen_procedure_code,


                    Extended_customs_procedure = x.Extended_customs_procedure,


                    Country_first_destination = x.Country_first_destination,


                    Currency_code = x.Currency_code,


                    Currency_rate = x.Currency_rate,


                    Manifest_reference_number = x.Manifest_reference_number,


                    Customs_clearance_office_code = x.Customs_clearance_office_code,


                    Lines = x.Lines,


                    DocumentType = x.DocumentType,


                    ImportComplete = x.ImportComplete,


                    Cancelled = x.Cancelled,


                    TotalCIF = x.TotalCIF,


                    TotalGrossWeight = x.TotalGrossWeight
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }