コード例 #1
0
        public IHttpActionResult INV3(Guid inventorizationId)
        {
            Report3Generator generator = new Report3Generator(AppDomain.CurrentDomain.BaseDirectory + @"\Templates\Report3.XLSX");

            Business.Model.Inventorization inventorization = inventorizationRepository.GetInventorization(inventorizationId);
            if (inventorization == null)
            {
                return(NotFound());
            }
            List <Rests> rests = inventorizationRepository.GetRests(inventorizationId);
            List <Business.Model.Action> actions = actionRepository.GetActionsByInventorization(inventorizationId);

            string[]           codes = rests.Select(x => x.Code).Union(actions.Select(x => x.BarCode)).Distinct().ToArray();
            IEnumerable <Item> items = companyRepository.GetItems(inventorization.Company).Where(x => x.Source == ItemSource.Import && codes.Any(r => r == x.Code));

            using (MemoryStream stream = generator.Generate(items.ToList(), actions, rests))
            {
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ByteArrayContent(stream.ToArray())
                };
                result.Content.Headers.ContentDisposition =
                    new ContentDispositionHeaderValue("attachment")
                {
                    FileName = "Report3.xlsx"
                };
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel");
                return(ResponseMessage(result));
            }
        }
コード例 #2
0
        public void Report3Builds()
        {
            Report3Generator generator    = new Report3Generator(AppDomain.CurrentDomain.BaseDirectory + @"\Templates\Report3.XLSX");
            Fixture          itemsFixture = new Fixture();
            List <Item>      data         = itemsFixture.CreateMany <Item>(100).ToList();
            List <Inventorization.Business.Model.Action> actions = data.SelectMany(x =>
            {
                var itemActions = itemsFixture.CreateMany <Inventorization.Business.Model.Action>(50).ToList();
                return(itemActions.Select(i => { i.BarCode = x.Code; i.Quantity = 1; return i; }));
            }).ToList();
            Random rnd = new Random();
            IEnumerable <Rests> rests = data.Select(x =>
            {
                var res = new Rests()
                {
                    Code              = x.Code,
                    Count             = rnd.Next(1, 10),
                    InventorizationId = Guid.NewGuid()
                };
                return(res);
            });

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            using (MemoryStream stream = generator.Generate(data, actions, rests.ToList()))
            {
                using (FileStream fs = File.Create(AppDomain.CurrentDomain.BaseDirectory + "\\" + Guid.NewGuid().ToString() + ".xlsx"))
                {
                    fs.Write(stream.ToArray(), 0, (int)stream.Length);
                    fs.Close();
                }
            }

            stopWatch.Stop();
            TimeSpan ts = stopWatch.Elapsed;

            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

            Console.WriteLine("RunTime " + elapsedTime);
        }