예제 #1
0
        private void WriteLazada(string outputPath)
        {
            var results = new List <Item>();

            foreach (var topsell in _topSell)
            {
                var matched = MatchingHelper.MatchSku(topsell, _basePrice);

                var addedCost = MatchingHelper.Match(matched, _cost);

                results.Add(new Item()
                {
                    SKU           = matched.SKU,
                    Price         = matched.Price,
                    SalePrice     = matched.SalePrice,
                    SaleStartDate = matched.SaleStartDate,
                    SaleEndDate   = matched.SaleEndDate,
                    Name          = matched.Name,
                    Cost          = addedCost.Price,
                    Matched       = addedCost.Matched,
                });
            }

            using (FileStream stream = new FileStream(outputPath, FileMode.CreateNew, FileAccess.Write))
            {
                var workbook = new XSSFWorkbook();
                var sheet    = workbook.CreateSheet("sheet1");
                var row      = 0;

                var headerRow = sheet.CreateRow(row);
                headerRow.CreateCell(0).SetCellValue("SKU");
                headerRow.CreateCell(1).SetCellValue("Price");
                headerRow.CreateCell(2).SetCellValue("SalePrice");
                headerRow.CreateCell(3).SetCellValue("SaleStartDate");
                headerRow.CreateCell(4).SetCellValue("SaleEndDate");
                headerRow.CreateCell(5).SetCellValue("Name");
                headerRow.CreateCell(6).SetCellValue("Cost");
                headerRow.CreateCell(7).SetCellValue("Matched");

                foreach (var result in results)
                {
                    var rowtemp = sheet.CreateRow(++row);
                    rowtemp.CreateCell(0).SetCellValue(result.SKU);
                    rowtemp.CreateCell(1).SetCellValue(result.Price.ToString(CultureInfo.InvariantCulture));
                    rowtemp.CreateCell(2).SetCellValue(result.SalePrice.ToString(CultureInfo.InvariantCulture));
                    rowtemp.CreateCell(3).SetCellValue(result.SaleStartDate);
                    rowtemp.CreateCell(4).SetCellValue(result.SaleEndDate);
                    rowtemp.CreateCell(5).SetCellValue(result.Name);
                    rowtemp.CreateCell(6).SetCellValue(result.Cost.ToString(CultureInfo.InvariantCulture));
                    rowtemp.CreateCell(7).SetCellValue(!result.Matched ? "NO" : string.Empty);
                }

                workbook.Write(stream);
            }
        }
예제 #2
0
        private void WriteShopee(string outputPath)
        {
            var results = new List <Item>();

            foreach (var tergetStock in _targetStock)
            {
                var matched = MatchingHelper.Match(tergetStock, _baseStock);

                var result = new Item()
                {
                    Name         = tergetStock.Name,
                    Model        = tergetStock.Model + " : " + tergetStock.Price,
                    MatchedModel = matched.Matched && !string.IsNullOrEmpty(matched.Model) ? matched.Model + " : " + matched.Price : string.Empty,
                    Price        = matched.Matched ? MatchingHelper.IsPriceSoDifferance(matched.Price, tergetStock.Price) ? tergetStock.Price : matched.Price : tergetStock.Price,
                    Matched      = matched.Matched,
                    MultiPrices  = matched.MultiPrices,
                    Description  = matched.Matched ? MatchingHelper.IsPriceSoDifferance(matched.Price, tergetStock.Price) ? "Price So Differance": string.Empty : string.Empty,
                };

                results.Add(result);
            }

            using (FileStream stream = new FileStream(outputPath, FileMode.CreateNew, FileAccess.Write))
            {
                var workbook = new XSSFWorkbook();
                var sheet    = workbook.CreateSheet("sheet1");
                var row      = 0;

                var headerRow = sheet.CreateRow(row);
                headerRow.CreateCell(0).SetCellValue("Name");
                headerRow.CreateCell(1).SetCellValue("Model");
                headerRow.CreateCell(2).SetCellValue("MatchedModel");
                headerRow.CreateCell(3).SetCellValue("Price");
                headerRow.CreateCell(4).SetCellValue("Matched");
                headerRow.CreateCell(5).SetCellValue("MultiPrices");
                headerRow.CreateCell(6).SetCellValue("Price So Differance");

                foreach (var result in results)
                {
                    var rowtemp = sheet.CreateRow(++row);
                    rowtemp.CreateCell(0).SetCellValue(result.Name);
                    rowtemp.CreateCell(1).SetCellValue(result.Model);
                    rowtemp.CreateCell(2).SetCellValue(result.MatchedModel);
                    rowtemp.CreateCell(3).SetCellValue(result.Price.ToString(CultureInfo.InvariantCulture));
                    rowtemp.CreateCell(4).SetCellValue(result.Matched);
                    rowtemp.CreateCell(5).SetCellValue(result.MultiPrices);
                    headerRow.CreateCell(6).SetCellValue(result.Description);
                }

                workbook.Write(stream);
            }
        }