// // 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)); }
public void Init() { _gjExcelParser = new GjExcelParserShoes(new ObLog4NetLogger(typeof(ParseLineTest).Name)); }