示例#1
0
        /// <summary>
        /// Create Invoice For Closure Charge and Auction Invoicing
        /// </summary>
        private void CreateInvoice(string type)
        {
            var tasks   = new List <Task <ResultDTO> >();
            var results = new List <string>();

            //try {
            LogService.WriteInfo("Begin Mass Billing " + type);
            DraftService lObjDraftService = new DraftService();

            lObjDraftService.DeleteDrafts(type);

            foreach (var doc in pendingInvoices)
            {
                //  tasks.Add(Task.Run(() => {

                try {
                    LogService.WriteInfo("Begin Creating Invoice for Cient: " + doc.Code);
                    var invoice = new DocumentDTO();
                    invoice.Document          = doc;
                    invoice.FloorServiceLines = massInvoicingDAO.GetFloorServiceLines(doc.Code, user.WhsCode, type);
                    invoice.DeliveryLines     = massInvoicingDAO.GetDeliveryLines(doc.Code, user.WhsCode);
                    //invoice.FloorServiceLines = massInvoicingDAO.GetFloorServiceLines(doc.Code, "CRHE", type);
                    //invoice.DeliveryLines = massInvoicingDAO.GetDeliveryLines(doc.Code, "CRHE");

                    if (invoice.FloorServiceLines.Count == 0 && invoice.DeliveryLines.Count == 0)
                    {
                        results.Add("Sin servicio de piso ni entregas de alimento");
                    }
                    else
                    {
                        results.Add(InvoiceDI.CreateInvoice(invoice, user, floorServiceItem, type).Message);
                    }
                    LogService.WriteInfo("Successfully Creating Invoice for Cient: " + doc.Code);
                    //  }));
                    //Thread.Sleep(130);
                }
                catch (Exception ex) {
                    HandleException(ex, "[Exception] Invoice for Client " + doc.Code);
                }
                //Task.WaitAll(tasks.ToArray());
            }

            //catch(AggregateException ae) {
            //    ae.Handle(e => {
            //        HandleException(e, "(Closure)");
            //        return true;
            //    });
            //}
            //catch(Exception ex) {
            //    HandleException(ex, "(Closure)");
            //}

            Task.Factory.StartNew(() => {
                // BindResultColumn(tasks.Select(t => t.Result.Message).AsParallel().AsOrdered().ToList(), type);
                BindResultColumn(results, type);
                LogService.WriteInfo("Done Mass Billing " + type);
            });

            UIApplication.ShowMessageBox("Revisar la Columna de Resultados");
        }