コード例 #1
0
        public void Test1()
        {
            var scan1 = new Scan();

            scan1.druck_pseudonym = "A15000";
            scan1.lager_fach      = "A01-2-3";
            ScanVariantenChecker checker = new ScanVariantenChecker();

            Assert.True(checker.CheckLine(scan1).Equals(ScanVarianten.ArtikelZuPlatz));

            var scan2 = new Scan();

            scan2.druck_pseudonym = "AA1500";
            scan2.lager_fach      = "A01-2-3";
            Assert.False(checker.CheckLine(scan2).Equals(ScanVarianten.ArtikelZuPlatz));

            var scan3 = new Scan();

            scan3.druck_pseudonym = "BOX2000";
            scan3.lager_fach      = "A01-2-3";
            Assert.True(checker.CheckLine(scan3).Equals(ScanVarianten.BoxZuPlatz));

            var scan4 = new Scan();

            scan4.druck_pseudonym = "C13000";
            scan4.lager_fach      = "A01-2-3";
            Assert.True(checker.CheckLine(scan4).Equals(ScanVarianten.ArtikelZuPlatz));

            var scan5 = new Scan();

            scan5.druck_pseudonym = "C13000";
            scan5.lager_fach      = "BOX2000";
            Assert.True(checker.CheckLine(scan5).Equals(ScanVarianten.ArtikelZuBox));
        }
コード例 #2
0
        public IActionResult Scan(IFormFile file)
        {
            //FileInfo file = new FileInfo();
            StreamReader streamReader = new StreamReader(file.OpenReadStream(), Encoding.UTF8);
            List <Scan>  scanList     = new List <Scan>();
            List <Scan>  successList  = new List <Scan>();
            List <Scan>  failList     = new List <Scan>();

            using (ExcelPackage package = new ExcelPackage(streamReader.BaseStream))
            {
                ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
                int            rowCount  = worksheet.Dimension.Rows;
                int            ColCount  = 2;
                for (int row = 2; row <= rowCount; row++)
                {
                    Scan scan = new Scan();
                    for (int col = 1; col <= ColCount; col++)
                    {
                        if (col == 1)
                        {
                            scan.lager_fach = worksheet.Cells[row, col].Value.ToString();
                        }
                        else
                        {
                            scan.druck_pseudonym = worksheet.Cells[row, col].Value.ToString();
                        }
                    }
                    scanList.Add(scan);
                }
            }
            LagerContext         con     = HttpContext.RequestServices.GetService(typeof(LagerApp.Model.LagerContext)) as LagerContext;
            ScanVariantenChecker checker = new ScanVariantenChecker();

            //Über alle Einträge in Liste iterieren
            foreach (var item in scanList)
            {
                item.druck_pseudonym = item.druck_pseudonym.Trim().ToUpper();
                item.lager_fach      = item.lager_fach.Trim().ToUpper();
                switch (checker.CheckLine(item))
                {
                case ScanVarianten.ArtikelZuBox:
                    LagerBoxDTO dto = new LagerBoxDTO();
                    dto.ArtikelId = item.druck_pseudonym;
                    dto.LagerBox  = item.lager_fach;
                    if (con.saveOrUpdateToBox(dto) > 0)
                    {
                        successList.Add(item);
                    }
                    else
                    {
                        failList.Add(item);
                    }
                    break;

                case ScanVarianten.ArtikelZuPlatz:
                    ArtikelLagerPlatzDTO dto2 = new ArtikelLagerPlatzDTO();
                    dto2.ArtikelId  = item.druck_pseudonym;
                    dto2.LagerPlatz = item.lager_fach;
                    if (con.saveOrUpdateArtikelToPlatz(dto2) > 0)
                    {
                        successList.Add(item);
                    }
                    else
                    {
                        failList.Add(item);
                    }
                    break;

                case ScanVarianten.BoxZuPlatz:
                    LagerPlatzDTO dto3 = new LagerPlatzDTO();
                    dto3.LagerBox   = item.druck_pseudonym;
                    dto3.LagerPlatz = item.lager_fach;
                    if (con.saveOrUpdateBoxToPlatz(dto3) > 0)
                    {
                        successList.Add(item);
                    }
                    else
                    {
                        failList.Add(item);
                    }
                    break;

                default:
                    failList.Add(item);
                    break;
                }
            }
            LoggerXLSX log = new LoggerXLSX();

            log.fail    = failList;
            log.success = successList;
            return(View(log));
        }