Ejemplo n.º 1
0
        /// <summary>
        /// BuildReportFromList in ListPrintHelper
        /// </summary>
        /// <param name="options"></param>
        /// <param name="listId"></param>
        /// <param name="userContext"></param>
        /// <param name="userProfile"></param>
        /// <param name="_listLogic"></param>
        /// <param name="_profileLogic"></param>
        /// <param name="_elRepo"></param>
        /// <returns></returns>
        public static Stream BuildReportFromList(PrintListModel options, ListType type, long listId, UserSelectedContext userContext,
                                                 UserProfile userProfile, IListService listService, IUserProfileLogic _profileLogic, IEventLogRepository _elRepo)
        {
            if (!string.IsNullOrEmpty(options.Paging.Terms))
            {
                //Build filter
                options.Paging.Filter = new FilterInfo()
                {
                    Field      = "ItemNumber",
                    FilterType = "contains",
                    Value      = options.Paging.Terms,
                    Condition  = "||",
                    Filters    = new List <FilterInfo>()
                    {
                        new FilterInfo()
                        {
                            Condition = "||", Field = "Label", Value = options.Paging.Terms, FilterType = "contains"
                        },
                        new FilterInfo()
                        {
                            Condition = "||", Field = "Name", Value = options.Paging.Terms, FilterType = "contains"
                        }
                    }
                };
            }

            options.Paging.Size = int.MaxValue;
            options.Paging.From = 0;

            if (options.Paging.Sort.Count == 1 && options.Paging.Sort[0].Field == null)
            {
                options.Paging.Sort = new List <SortInfo>();
            }

            ListModel list = listService.ReadList(userProfile, userContext, type, listId, options.ShowPrices);

            var NotesHash = listService.GetNotesHash(userContext);

            foreach (var item in list.Items)
            {
                if (NotesHash.ContainsKey(item.ItemNumber))
                {
                    item.Notes = NotesHash[item.ItemNumber].Notes;
                }
            }

            if (list == null)
            {
                return(null);
            }

            ListModel printlist = list.Clone();

            printlist.ListId = 0;

            if (options.Filter != null)
            {
                printlist.Items = printlist.Items.AsQueryable()
                                  .Filter(options.Filter, null)
                                  .ToList();
            }

            StringBuilder sortinfo = new StringBuilder();

            foreach (SortInfo si in options.Paging.Sort)
            {
                if (sortinfo.Length > 0)
                {
                    sortinfo.Append(";");
                }
                sortinfo.Append(si.Field);
                sortinfo.Append(",");
                sortinfo.Append(si.Order);
            }
            printlist.Items = SortOrderItems(sortinfo.ToString(), printlist.Items);
            int ind = 1;

            foreach (ListItemModel item in printlist.Items)
            {
                item.Position = ind++;
            }

            ListReportModel printModel = printlist.ToReportModel();

            Customer customer = _profileLogic.GetCustomerByCustomerNumber(userContext.CustomerId, userContext.BranchId);

            ReportViewer rv = new ReportViewer();

            rv.ProcessingMode = ProcessingMode.Local;


            Assembly assembly = Assembly.Load("Keithlink.Svc.Impl");

            string rptName    = ChooseReportFromOptions(options, userContext, customer);
            Stream rdlcStream = assembly.GetManifestResourceStream(rptName);

            rv.LocalReport.LoadReportDefinition(rdlcStream);

            rv.LocalReport.SetParameters
                (MakeReportOptionsForPrintListReport(options, printModel.Name, userContext, customer));
            GatherInfoAboutItems(type, listId, options, printModel, userContext, userProfile, customer, listService);

            rv.LocalReport.DataSources.Add(new ReportDataSource("ListItems", printModel.Items));

            string deviceInfo = (options.Landscape) ? KeithLink.Svc.Core.Constants.SET_REPORT_SIZE_LANDSCAPE
                                                    : KeithLink.Svc.Core.Constants.SET_REPORT_SIZE_PORTRAIT;

            byte[] bytes = rv.LocalReport.Render("PDF", deviceInfo);

            Stream stream = new MemoryStream(bytes);

            return(stream);
        }
Ejemplo n.º 2
0
        private static void GatherInfoAboutItems(ListType type, long listId, PrintListModel options, ListReportModel printModel, UserSelectedContext userContext,
                                                 UserProfile userProfile, Customer customer, IListService listService)
        {
            ListModel            listModel = listService.ReadList(userProfile, userContext, type, listId, true);
            List <ListItemModel> itemHash  = listModel.Items.ToList();

            string[]      itemkeys      = itemHash.Select(i => i.ItemNumber).ToArray();
            ItemHistory[] itemHistories = listService.GetItemsHistoryList(userContext, itemkeys);
            foreach (ListItemReportModel item in printModel.Items)
            {
                var itemInfo = itemHash.Where(i => i.ItemNumber == item.ItemNumber).FirstOrDefault();
                if ((customer != null) && (options.ShowPrices))
                {
                    StringBuilder priceInfo = new StringBuilder();
                    if (itemInfo != null)
                    {
                        if ((itemInfo.PackagePrice != null) && (itemInfo.PackagePrice.Equals("0.00") == false))
                        {
                            priceInfo.Append("$");
                            priceInfo.Append(itemInfo.PackagePrice);
                            priceInfo.Append("/Pack");
                            item.Price = priceInfo.ToString();
                            priceInfo.Append(" - ");
                        }
                        if (itemInfo.CasePrice != null)
                        {
                            priceInfo.Append("$");
                            priceInfo.Append(itemInfo.CasePrice);
                            priceInfo.Append("/Case");
                            item.Price = priceInfo.ToString();
                        }
                    }
                }
                //        // to make the option not to sort by label not reorder the items we null the label
                if ((options.Paging != null) && (options.Paging.Sort != null) && (options.Paging.Sort.Count > 0) &&
                    (options.Paging.Sort[0].Field.Equals("label", StringComparison.CurrentCultureIgnoreCase)))
                {
                    item.Label = itemInfo.Label;
                }
                else
                {
                    item.Label = null;
                }
                ItemHistory itemStats = itemHistories.Where(f => f.ItemNumber == item.ItemNumber).FirstOrDefault();
                if (itemStats != null)
                {
                    StringBuilder AVG8WK = new StringBuilder();
                    AVG8WK.Append(itemStats.AverageUse);
                    if (itemStats.UnitOfMeasure.Equals(KeithLink.Svc.Core.Constants.ITEMHISTORY_AVERAGEUSE_PACKAGE))
                    {
                        AVG8WK.Append(" Pack");
                    }
                    else if (itemStats.UnitOfMeasure.Equals(KeithLink.Svc.Core.Constants.ITEMHISTORY_AVERAGEUSE_CASE))
                    {
                        AVG8WK.Append(" Case");
                    }
                    if ((itemStats.AverageUse > 1) | (itemStats.AverageUse == 0))
                    {
                        AVG8WK.Append("s");
                    }
                    item.AvgUse = AVG8WK.ToString();
                }
                else
                {
                    item.AvgUse = "0 Cases";
                }
            }
        }