Пример #1
0
        private void TransferCorralsToAuction()
        {
            MassInvoicingDAO massInvoicingDAO = new MassInvoicingDAO();
            DistributionDAO  distributionDAO  = new DistributionDAO();

            LogService.WriteInfo("Begin Transfer Corrals to Actions");
            var results = new ConcurrentDictionary <string, ResultDTO>();

            livestockInCorals.Select(l => l.Code).Distinct().AsParallel().ForAll(client => {
                var transferLivestock = livestockInCorals.Where(l => l.Code == client && l.Quantity > 0).AsParallel().ToList();
                var batches           = massInvoicingDAO.GetBatches(client, user.WhsCode, "N");
                results.TryAdd(client, LivestockTransfer.CreateStockTransfer(transferLivestock, batches, user.Series));
            });

            //another implemetation with same result

            /*var results = livestockInCorals.Select(l => l.Code).Distinct().AsParallel().Select(client => {
             *  var transferLivestock = livestockInCorals.Where(l => l.Code == client && l.Quantity > 0).AsParallel().ToList();
             *  var batches = massInvoicingDAO.GetBatches(client, user.WhsCode, "N");
             *  return new KeyValuePair<string, ResultDTO>(client, LivestockTransfer.CreateStockTransfer(transferLivestock, batches, user.Series));
             * }).ToDictionary(t => t.Key, t => t.Value);*/

            Task.Factory.StartNew(() => {
                BindResultColumn(results);
                LogService.WriteInfo("Begin Transfer Corrals to Actions");
            });
        }
Пример #2
0
        /// <summary>
        /// Fill Livestock Matrix Data By Parallel Loopps
        /// </summary>
        /// <param name="tableID"></param>
        /// <param name="dataTable"></param>
        /// <param name="client"></param>
        /// <param name="type"></param>
        private void FillMatrix1(string tableID, SAPbouiCOM.DataTable dataTable, string client, string type)
        {
            try {
                dataTable.Rows.Clear();
                livestock = massInvoicingDAO.GetDistributedLiveStock(client, type);

                var columns = new List <string>(columnsExit.Keys);

                if (livestock.Count > 0)
                {
                    Parallel.For(0, livestock.Count, row => {
                        dataTable.Rows.Add();
                    });

                    Task.Factory.StartNew(() => {
                        Parallel.For(0, livestock.Count, row => {
                            dataTable.SetValue("C_#", row, row + 1);
                        });
                    });

                    Parallel.ForEach(Partitioner.Create(0, livestock.Count), (range, state) => {
                        for (int i = range.Item1; i < range.Item2; i++)
                        {
                            Parallel.ForEach(columns.Skip(1), column => {
                                dataTable.SetValue(column, i, livestock[i].GetType().GetProperty(column.Replace("C_", String.Empty)).GetValue(livestock[i], null));
                            });
                        }
                    });

                    BindDataMatrix(mtx1, tableID, columns);

                    if (type.Equals("N"))
                    {
                        Task.Factory.StartNew(() => {
                            batches           = massInvoicingDAO.GetBatches(client, user.WhsCode, type);
                            floorServiceLines = massInvoicingDAO.GetFloorServiceLines(client, user.WhsCode, type);
                        });
                    }
                }
                else
                {
                    ClearMtx(mtx1);
                }
            }
            catch (AggregateException ae) {
                ae.Handle(e => {
                    HandleException(e, "(AE)");
                    return(true);
                });
            }
            catch (Exception ex) {
                HandleException(ex, "(FillMatrix2)");
            }
        }