Пример #1
0
        protected override IBarcode Create(Type objectType, JObject jObject)
        {
            var      barcodeType = (BarcodeType)jObject["BarcodeType"].ToObject(typeof(BarcodeType));
            IBarcode barcode;

            switch (barcodeType)
            {
            case BarcodeType.BundlingBarcode:
                barcode = new BundlingBarcode();
                break;

            case BarcodeType.CustomBarcode:
                barcode = new CustomBarcode();
                break;

            case BarcodeType.StandardBarcode:
                barcode = new StandardBarcode();
                break;

            case BarcodeType.WeighBarcode:
                barcode = new WeighBarcode();
                break;

            default:
                barcode = new StandardBarcode();
                break;
            }
            return(barcode);
        }
        public void Import(string filename)
        {
            var lines = File.ReadAllLines(filename);

            using (var db = _dbFactory.GetRWDb())
            {
                var existBarcodes = db.CustomBarcodes.GetAllAsDto().ToList();

                var index      = 0;
                var existIndex = 0;
                foreach (var line in lines)
                {
                    if (String.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    var barcode = line.Trim();
                    var exist   = existBarcodes.FirstOrDefault(b => b.Barcode == barcode);
                    if (exist == null)
                    {
                        var newBarcode = new CustomBarcode()
                        {
                            Barcode    = barcode,
                            CreateDate = _time.GetUtcTime()
                        };

                        db.CustomBarcodes.Add(newBarcode);

                        existBarcodes.Add(new CustomBarcodeDTO()
                        {
                            Barcode = barcode
                        });

                        index++;
                        _log.Info("Added: " + index);
                    }
                    else
                    {
                        existIndex++;
                        _log.Info("Exist: " + existIndex);
                    }

                    if (index % 200 == 0)
                    {
                        db.Commit();
                    }
                }
            }
        }