Beispiel #1
0
        //
        // GET: /parser/preview

        public ActionResult Preview(string id, OnBalance.ViewModels.Parsers.ParserOptions options)
        {
            string data        = Request["Data"];
            string productType = Request["ProductType"].Trim().ToLower();

            string[]       lines = data.Split("\n".ToCharArray());
            IBalanceParser p     = productType == "gjdress" ? new GjExcelParserDress() : new GjExcelParserShoes();

            p.AllowEmptyPrice = options.AllowEmptyPrice;
            var items = p.ParseFileContent(lines);

            // Pass statistics
            ViewBag.ProcessedNonEmptyLines = p.TotalProcessedNonEmptyLines;
            ViewBag.CategoryLines          = p.TotalCategoryLines;

            if (p.Errors.Count > 0 && options.RedirectToErrors)
            {
                TempData["ParserErrors"] = p.Errors.ToList();
                TempData["TotalProcessedNonEmptyLines"] = p.TotalProcessedNonEmptyLines;
                return(RedirectToAction("errors", new { id = id }));
            }

            var notFound = FindNonExistingCategories(items);

            if (notFound.Count > 0 && options.RedirectToCategories)
            {
                TempData["NotFound"] = notFound;
                return(RedirectToAction("NotFoundCategories"));
            }

            // Just to beautify grid
            ViewBag.SizeNames = ExtractAvailableSizes(items);

            if (options.PrepareInsertSql)
            {
                ViewBag.CategoryNames = items.Select(x => x.CategoryName)
                                        .Distinct()
                                        .ToList();
                PrepareInsertSql(items, 110000);
            }

            if (items.Count > 0)
            {
                items = items.OrderBy(x => x.CategoryName).ToList();
                TempData["ExchangeItems"] = items;

                //StringBuilder sb = new StringBuilder();
                //foreach (var e in p.Errors)
                //{
                //    sb.AppendFormat("#{0}\t{1}", e.LineNr, e.Line);
                //    sb.AppendLine("<br />");
                //    Response.Write(sb.ToString());
                //    Response.End();
                //}
            }

            return(View("Preview", "_LayoutLogin", items));
        }
Beispiel #2
0
        public void Test_Line_Contains_Only_Tabs()
        {
            string[] lines = new string[] {
                "																																																	"
            };


            var pi = _gjExcelParser.ParseFileContent(lines);

            Assert.AreEqual(1, _gjExcelParser.Errors.Count, "Expected 1 parsing error");
            Assert.IsTrue(_gjExcelParser.Errors[0].IsLineEmpty, "Expected parsing error about empty line");
        }