private List <List <String> > ExcelToJson(string fileName)
 {
     if (System.IO.File.Exists(fileName))
     {
         var da = new List <List <String> >();
         if (Path.GetExtension(fileName) == ".txt")
         {
             string st    = System.IO.File.ReadAllText(fileName);
             var    retda = st.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
             var    li    = new List <List <string> >();
             retda.Each(c =>
             {
                 var t = new List <string>()
                 {
                     c
                 };
                 li.Add(t);
             });
             da = li;
         }
         else
         {
             YxkSabri.ExcelUtility excel = new YxkSabri.ExcelUtility();
             da = excel.ExcelToArray(fileName, 0, 0);
             var _key = "sess_excel_inpor_instorage_11";
             SessionAccess.Set(_key, da, true);
         }
         return(da);
     }
     return(null);
 }
示例#2
0
        public ActionResult RemoveInstoraggeByCach(string[] barcodes)
        {
            OperationResult resul = new OperationResult(OperationResultType.Error);

            var scanValidKey   = "ScanValid";
            var scanInvalidKey = "ScanInvalid";
            List <Product_Model> validModels   = SessionAccess.Get(scanValidKey) as List <Product_Model>;
            List <Product_Model> inValidModels = SessionAccess.Get(scanInvalidKey) as List <Product_Model>;

            if (validModels != null && validModels.Any())
            {
                var ts = validModels.Where(c => barcodes.Contains(c.ProductBarcode)).ToList();
                for (int i = 0; i < ts.Count(); i++)
                {
                    validModels.Remove(ts[i]);
                }

                SessionAccess.Set(scanValidKey, validModels, true);


                //从错误列表中也移除该货号
                if (inValidModels != null && inValidModels.Any())
                {
                    var list = inValidModels.Where(c => barcodes.Contains(c.ProductBarcode)).ToList();
                    for (int i = 0; i < list.Count(); i++)
                    {
                        inValidModels.Remove(list[i]);
                    }

                    SessionAccess.Set(scanInvalidKey, inValidModels, true);
                }

                resul = new OperationResult(OperationResultType.Success);

                resul.Other = new {
                    validCoun   = validModels.Count,
                    inValidCoun = inValidModels.Count
                };
            }



            return(Json(resul));
        }
示例#3
0
        public ActionResult AddToScan(string uuid, string number, bool isbigNumb)
        {
            OperationResult     resul             = new OperationResult(OperationResultType.Success);
            string              _validSessionKey  = "1102_validsessionkey_09";
            string              _invaliSessionKey = "1102_invalidsessionkey_03";
            Product             product           = null;
            ProductOriginNumber orignum           = null;

            List <DiscountValidSession> discouvalidssion =
                (SessionAccess.Get(_validSessionKey) as List <DiscountValidSession>) ?? new List <DiscountValidSession>();

            List <DiscountValidSession> discouInvalidSession =
                (SessionAccess.Get(_invaliSessionKey) as List <DiscountValidSession>) ?? new List <DiscountValidSession>();

            if (discouvalidssion.Any() && discouvalidssion.FirstOrDefault(c => c.Uuid == uuid) != null)
            {
                discouvalidssion.FirstOrDefault(c => c.Uuid == uuid).Count += 1;
            }
            else
            {
                if (discouInvalidSession.Any() && discouInvalidSession.FirstOrDefault(c => c.Uuid == uuid) != null)
                {
                    discouInvalidSession.FirstOrDefault(c => c.Uuid == uuid).Count += 1;
                }
                else
                {
                    DiscountValidSession dis = new DiscountValidSession()
                    {
                        Uuid   = uuid,
                        Number = number,
                        Count  = 1
                    };
                    if (isbigNumb)
                    {//传入的是大款号
                        orignum  = ProductOrigNumberValid(number);
                        dis.Type = 1;
                        if (orignum != null)
                        {
                            dis.Id     = orignum.Id;
                            dis.Number = orignum.BigProdNum;
                            discouvalidssion.Add(dis);
                        }
                        else
                        {
                            discouInvalidSession.Add(dis);
                            resul.ResultType = OperationResultType.Error;
                            resul.Message    = "商品货号不存在";
                        }
                    }
                    else
                    {//传入的是商品货号
                        product  = ProductValid(number);
                        dis.Type = 0;
                        if (product != null)
                        {
                            dis.Id     = product.Id;
                            dis.Number = product.ProductNumber;
                            discouvalidssion.Add(dis);
                        }
                        else
                        {
                            discouInvalidSession.Add(dis);
                            resul.ResultType = OperationResultType.Error;
                            resul.Message    = "商品货号不存在";
                        }
                    }
                }
            }
            try
            {
                SessionAccess.Set(_validSessionKey, discouvalidssion, true);
                SessionAccess.Set(_invaliSessionKey, discouInvalidSession, true);
            }
            catch (Exception)
            {
                throw;
            }
            resul.Data = new {
                uuid       = uuid,
                validCou   = discouvalidssion.GroupBy(c => c.Number).Count(),
                invalidCou = discouInvalidSession.GroupBy(c => c.Number).Count()
            };
            if (isbigNumb)
            {
                orignum = orignum ?? ProductOrigNumberValid(number);
                if (orignum == null)
                {
                    resul.ResultType = OperationResultType.Error;
                    resul.Message    = "商品款号不存在";
                }
                else
                {
                    Product prod = _productContract.Products.FirstOrDefault(c => c.OriginNumber == orignum.OriginNumber);
                    resul.Other = new {
                        Id            = orignum.Id,
                        ProductNumber = orignum.BigProdNum,
                        Brand         = prod.ProductOriginNumber.Brand.BrandName,
                        Category      = prod.ProductOriginNumber.Category.CategoryName,
                        Size          = "",
                        Thumbnail     = prod.ThumbnailPath,
                    };
                }
            }
            else
            {
                product = product ?? ProductValid(number);
                if (product != null)
                {
                    resul.Other = new {
                        Id            = product.Id,
                        ProductNumber = product.ProductNumber,
                        Brand         = product.ProductOriginNumber.Brand.BrandName,
                        Category      = product.ProductOriginNumber.Category.CategoryName,
                        Size          = product.Size.SizeName,
                        Thumbnail     = product.ThumbnailPath,
                    }
                }
                ;
                else
                {
                    resul.ResultType = OperationResultType.Error;
                    resul.Message    = "商品编号不存在";
                }
            }
            return(Json(resul));
        }
示例#4
0
        /// <summary>
        /// 批量导入校验
        /// </summary>
        public ActionResult MultitudeVaild(string nums, string uid)
        {
            var dat = nums.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            int storeCollocationId   = _storeProductCollocationContract.StoreProductCollocations.Where(o => o.Guid == uid).Select(x => x.Id).FirstOrDefault();
            var result               = new OperationResult(OperationResultType.Error, "");
            var validListFromCache   = (List <Product_Model>)SessionAccess.Get(SESSION_KEY_VALID_LIST + uid) ?? new List <Product_Model>();
            var invalidlistFromCache = (List <Product_Model>)SessionAccess.Get(SESSION_KEY_INVALID_LIST + uid) ?? new List <Product_Model>();
            var storeCollocation     = _storeProductCollocationContract.StoreProductCollocations.Where(o => !o.IsDeleted && o.IsEnabled)
                                       .Where(o => o.Id == storeCollocationId)
                                       .Include(o => o.StoreCollocationInfoItems)
                                       .FirstOrDefault();


            string strMessage = string.Empty;

            var modelList = dat.Select(barcode => new Product_Model {
                ProductBarcode = barcode, UUID = Guid.NewGuid().ToString()
            }).ToList();


            var checkRes = CheckCollcationEntity(storeCollocation);

            if (!checkRes.Item1)
            {
                invalidlistFromCache.Add(new Product_Model {
                    ProductBarcode = string.Empty
                });
            }
            else //批量校验
            {
                var tmpValidModels = new List <Product_Model>();
                //var allValid = true;
                var orderblankItemsFromDb = storeCollocation.StoreCollocationInfoItems.ToList();
                foreach (var modelToCheck in modelList)
                {
                    var res = CheckBarcode(modelToCheck, validListFromCache, invalidlistFromCache, orderblankItemsFromDb, storeCollocationId);
                    if (!res.Item1)
                    {
                        //allValid = false;
                        modelToCheck.Notes = res.Item2;
                        invalidlistFromCache.Add(modelToCheck);
                    }
                    else
                    {
                        tmpValidModels.Add(modelToCheck);
                        validListFromCache.Add(modelToCheck);
                    }
                }
                if (tmpValidModels.Count > 0)
                {
                    var optRes = BatchAddCollocationItem(storeCollocation, orderblankItemsFromDb, tmpValidModels.ToArray());
                    if (optRes.ResultType != OperationResultType.Success)
                    {
                        invalidlistFromCache.Add(new Product_Model {
                            ProductBarcode = string.Empty, Notes = optRes.Message
                        });
                    }
                }
            }

            SessionAccess.Set(SESSION_KEY_VALID_LIST + uid, validListFromCache);
            SessionAccess.Set(SESSION_KEY_INVALID_LIST + uid, invalidlistFromCache);
            result.Data       = new { validCount = validListFromCache.Count, invalidCount = invalidlistFromCache.Count };
            result.ResultType = OperationResultType.Success;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        //da= [{ProduId:22,StorCou:120,StoreId:12,StorageId:2},{ProduId:22,StorCou:120,StoreId:12,StorageId:2}]
        //yxk
        public JsonResult AddInventory(string[] prCodes, int storageId, string notes, string recordOrderNumber, DateTime?CreatedTime)
        {
            if (!CreatedTime.HasValue)
            {
                CreatedTime = DateTime.Now;
            }
            OperationResult  optresul = new OperationResult(OperationResultType.Error, "入库失败");
            List <Inventory> inves    = new List <Inventory>();

            if (prCodes == null)
            {
                prCodes = new string[0];
            }
            string key = "ScanValid";
            var    productsModeList = Session[key] as List <Product_Model>;
            int    err = 0;

            if (productsModeList == null || productsModeList.Count == 0)
            {
                optresul.Message = "在服务器中未查到相关的入库操作,可能是操作超时";
            }
            else
            {
                var instorageCode = prCodes.Any() ? productsModeList.Where(c => prCodes.Contains(c.ProductBarcode)).Select(c => c.ProductBarcode).ToList()
                                                  : productsModeList.Select(c => c.ProductBarcode).Distinct().ToList();
                //检查是否有已经入库的条码
                if (_inventoryContract.Inventorys.Any(i => instorageCode.Contains(i.ProductBarcode)))
                {
                    return(Json(OperationResult.Error("检测到有已经入过库的流水号")));
                }
                int adminid = (int)AuthorityHelper.OperatorId;

                var storage = CacheAccess.GetManagedStorage(_storageContract, _administratorContract).FirstOrDefault(f => f.Id == storageId);

                if (storage.IsNull())
                {
                    optresul.Message = "当前用户无权限操作该仓库,ID:" + storageId;
                }
                else
                {
                    var barcodesFromDb = _productBarcodeDetailContract.productBarcodeDetails
                                         .Where(c => instorageCode.Contains(c.ProductNumber + c.OnlyFlag))
                                         .ToList();
                    var distinceBarcodes = new List <ProductBarcodeDetail>();
                    foreach (var code in barcodesFromDb)
                    {
                        if (distinceBarcodes.Any(i => i.ProductNumber == code.ProductNumber && i.OnlyFlag == code.OnlyFlag))
                        {
                            continue;
                        }
                        else
                        {
                            distinceBarcodes.Add(code);
                        }
                    }
                    var productNumbersFromBarcode = distinceBarcodes.Select(c => c.ProductNumber).ToList();
                    var products = _productContract.Products.Where(c => productNumbersFromBarcode.Contains(c.ProductNumber))
                                   .Select(c => new
                    {
                        c.ProductNumber,
                        c.Id,
                        c.ProductOriginNumber.TagPrice,
                        c.ProductOriginNumber.WholesalePrice,
                        c.ProductOriginNumber.PurchasePrice
                    })
                                   .ToList();
                    var           productNumbersFromProduct = products.Select(c => c.ProductNumber).ToList();
                    var           errproduct = distinceBarcodes.Where(c => !productNumbersFromProduct.Contains(c.ProductNumber));
                    List <string> errbarcode = new List <string>();
                    if (errproduct.Any())
                    {
                        //与该商品相关的商品档案不存在
                        //写日志 待完善

                        errbarcode = errproduct.Select(c => c.ProductNumber + c.OnlyFlag).ToList();
                        //inves = new List<Inventory>(); //清空需要入库的数据
                        var errst = "";
                        if (errbarcode.Count > 4)
                        {
                            errst = string.Join(",", errbarcode.Take(4).ToArray());
                        }
                        else
                        {
                            errst = string.Join(",", errbarcode);
                        }
                        _logContract.Insert(new LogDto()
                        {
                            Description = string.Join(",", errbarcode) + "未查找到商品档案",
                        });
                        optresul.Message = "部分商品未查找到商品档案:" + errst + "……,详情请查看日志";
                    }
                    else
                    {
                        inves = distinceBarcodes.Select(c => new Inventory()
                        {
                            ProductNumber  = c.ProductNumber,
                            OnlyFlag       = c.OnlyFlag,
                            ProductLogFlag = Guid.NewGuid().ToString().Replace("-", ""),
                            ProductBarcode = c.ProductNumber + c.OnlyFlag,
                            StoreId        = storage.StoreId,
                            StorageId      = storageId,
                            ProductId      = products.FirstOrDefault(g => g.ProductNumber == c.ProductNumber).Id,
                            Description    = notes,
                        }).ToList();
                    }
                    if (inves.Any())
                    {
                        // 计算本次入库总吊牌价
                        float totalTagPrice = 0;
                        foreach (var inventory in inves)
                        {
                            totalTagPrice += products.First(p => p.Id == inventory.ProductId).TagPrice;
                        }
                        // 根据生成的库存信息,插入入库记录
                        var record = new InventoryRecord()
                        {
                            Quantity          = inves.Count,
                            OperatorId        = adminid,
                            StorageId         = storageId,
                            StoreId           = storage.StoreId,
                            TagPrice          = totalTagPrice,
                            RecordOrderNumber = recordOrderNumber,
                            CreatedTime       = CreatedTime.Value
                        };

                        using (var tran = _inventoryContract.GetTransaction())
                        {
                            var res = _inventoryRecordContract.Insert(record);
                            if (res.ResultType != OperationResultType.Success)
                            {
                                tran.Rollback();
                                return(Json(OperationResult.Error("库存记录插入失败")));
                            }

                            // 将库存信息与入库记录进行关联
                            inves.Each(i => i.InventoryRecordId = record.Id);
                            // 保存库存信息
                            optresul = _inventoryContract.BulkInsert(inves);
                            if (optresul.ResultType != OperationResultType.Success)
                            {
                                tran.Rollback();
                                return(Json(OperationResult.Error("保存库存信息失败")));
                            }
                            List <ProductTrack> listpt = new List <ProductTrack>();
                            foreach (var item in inves)
                            {
                                #region 商品追踪
                                ProductTrack pt = new ProductTrack();
                                pt.ProductNumber  = item.ProductNumber;
                                pt.ProductBarcode = item.ProductNumber + item.OnlyFlag;
                                pt.Describe       = String.Format(ProductOptDescTemplate.ON_PRODUCT_INVENTORY, storage.StorageName);

                                listpt.Add(pt);
                                #endregion
                            }
                            var resPT = _productTrackContract.BulkInsert(listpt);
                            if (resPT.ResultType != OperationResultType.Success)
                            {
                                tran.Rollback();
                                return(Json(OperationResult.Error("商品追踪插入失败")));
                            }
                            List <string> proCodes = inves.Select(c => c.ProductBarcode).ToList();
                            var           details  = _productBarcodeDetailContract.productBarcodeDetails.Where(c => proCodes.Contains(c.ProductNumber + c.OnlyFlag));
                            details.Each(c => c.Status = 1);

                            var resPBD = _productBarcodeDetailContract.BulkUpdate(details);
                            if (resPBD.ResultType != OperationResultType.Success)
                            {
                                tran.Rollback();
                                return(Json(OperationResult.Error("商品条码信息更新失败")));
                            }
                            productsModeList.RemoveAll(c => proCodes.Contains(c.ProductBarcode));
                            SessionAccess.Set(key, productsModeList);

                            tran.Commit();
                        }
                    }
                }
            }
            return(Json(optresul, JsonRequestBehavior.AllowGet));
        }
示例#6
0
        /// <summary>
        /// 入库数据批量校验
        /// </summary>
        /// <param name="pre"></param>
        private void BatchInputStorageCheck(Dictionary <string, string> pre, bool isclear = false)
        {
            var           scanValidKey   = "ScanValid";
            var           scanInvalidKey = "ScanInvalid";
            List <string> errli          = new List <string>();

            List <Product_Model> validModels   = new List <Product_Model>();
            List <Product_Model> inValidModels = new List <Product_Model>();

            if (!isclear)
            {
                validModels   = SessionAccess.Get(scanValidKey) as List <Product_Model>;
                inValidModels = SessionAccess.Get(scanInvalidKey) as List <Product_Model>;
                if (validModels == null)
                {
                    validModels = new List <Product_Model>();
                }
                if (inValidModels == null)
                {
                    inValidModels = new List <Product_Model>();
                }
            }

            List <string> numbs  = pre.Select(c => c.Value).ToList();
            List <string> valied = new List <string>();

            //是否与已校验通过的结果重复
            var exisVali = validModels.Where(c => numbs.Contains(c.ProductBarcode)).ToList();
            //是否与校验不通过的结果重复
            var exisInvali = inValidModels.Where(c => numbs.Contains(c.ProductBarcode)).ToList();
            int cuind      = inValidModels.Count + validModels.Count + 1;

            if (exisVali.Any())
            {
                valied.AddRange(exisVali.Select(c => c.ProductBarcode));
                for (int i = 0; i < exisVali.Count(); i++)
                {
                    var ite = exisVali[0];
                    var t   = CacheAccess.Clone <Product_Model>(ite);
                    t.Id    = cuind;
                    t.Notes = "已进入缓存队列";
                    inValidModels.Add(t);
                }
                var exiscodes = exisVali.Select(c => c.ProductBarcode).ToList();
                numbs.RemoveAll(c => exiscodes.Contains(c));
            }
            else if (exisInvali.Any())
            {
                valied.AddRange(exisInvali.Select(c => c.ProductBarcode));
                for (int i = 0; i < exisInvali.Count(); i++)
                {
                    var ite = exisInvali[i];
                    var t   = CacheAccess.Clone <Product_Model>(ite);
                    t.Id     = cuind;
                    t.Notes += ",且已经重复";
                    inValidModels.Add(t);
                }

                var exiscodes = exisVali.Select(c => c.ProductBarcode).ToList();
                numbs.RemoveAll(c => exiscodes.Contains(c));
            }

            var plbarcode = numbs.Where(c => !valied.Contains(c)).ToList();//没有经过校验的条码

            if (plbarcode.Any())
            {
                //商品的打印记录
                var vadali = _productBarcodeDetailContract.productBarcodeDetails.Where(c => plbarcode.Contains(c.ProductNumber + c.OnlyFlag));
                //根据条码得到编号
                var pnums = numbs.Where(c => c.Length == 14).Select(c => c.Substring(0, 11)).ToList();
                //存在商品檔案的库存
                var exisnum = _productContract.Products.Where(c => pnums.Contains(c.ProductNumber))
                              .Select(c => c.ProductNumber)
                              .ToList();
                //入库校验
                foreach (var inda in plbarcode)
                {
                    //序列号
                    var ind = inValidModels.Count + validModels.Count + 1;
                    if (validModels.Any(c => c.ProductBarcode == inda))
                    {
                        var exc = validModels.FirstOrDefault(c => c.ProductBarcode == inda);
                        if (exc != null)
                        {
                            var t = CacheAccess.Clone <Product_Model>(exc);
                            t.Id    = ind;
                            t.Notes = "已进入缓存队列";
                            inValidModels.Add(t);
                        }
                    }
                    else if (inValidModels.Any(c => c.ProductBarcode == inda))
                    {
                        var exc = inValidModels.FirstOrDefault(c => c.ProductBarcode == inda);
                        if (exc != null)
                        {
                            var te = CacheAccess.Clone <Product_Model>(exc);
                            te.Id     = ind;
                            te.Notes += ",且已经重复";
                            inValidModels.Add(te);
                        }
                        var exiscodes = exisVali.Select(c => c.ProductBarcode).ToList();
                        numbs.RemoveAll(c => exiscodes.Contains(c));
                    }
                    else
                    {
                        //带校验对象
                        var di = pre.FirstOrDefault(c => c.Value == inda);
                        if (inda.Length == 14)
                        {
                            var prnum = inda.Substring(0, 11);
                            //打印记录
                            var barcode = vadali.FirstOrDefault(c => c.ProductNumber + c.OnlyFlag == inda);
                            //商品档案
                            var detai = exisnum.FirstOrDefault(c => c == prnum);

                            if (detai != null)
                            {
                                if (barcode != null)
                                {
                                    if (barcode.IsDeleted)
                                    {
                                        inValidModels.Add(new Product_Model
                                        {
                                            Id             = ind,
                                            UUID           = di.Key,
                                            ProductBarcode = di.Value,
                                            Notes          = "商品档案存在,且有打印记录,但已经被移除到回收站"
                                        });
                                    }
                                    else
                                    {
                                        if (barcode.Status == 0)
                                        {
                                            validModels.Add(new Product_Model
                                            {
                                                Id             = ind,
                                                UUID           = di.Key,
                                                ProductBarcode = di.Value,
                                                Notes          = "商品档案存在,且有打印记录,可以入库"
                                            });
                                        }
                                        else
                                        {
                                            string err = barcode.Status == 1 ? "已入库" : "已删除或禁用";
                                            inValidModels.Add(new Product_Model
                                            {
                                                Id             = ind,
                                                UUID           = di.Key,
                                                ProductBarcode = di.Value,
                                                Notes          = err
                                            });
                                        }
                                    }
                                }
                                else
                                {
                                    inValidModels.Add(new Product_Model
                                    {
                                        Id             = ind,
                                        UUID           = di.Key,
                                        ProductBarcode = di.Value,
                                        Notes          = "商品档案存在,但是没有打印记录"
                                    });
                                }
                            }
                            else
                            {
                                inValidModels.Add(new Product_Model
                                {
                                    Id             = ind,
                                    UUID           = di.Key,
                                    ProductBarcode = di.Value,
                                    Notes          = "商品档案不存在"
                                });
                            }
                        }
                        else
                        {
                            inValidModels.Add(new Product_Model
                            {
                                Id             = ind,
                                UUID           = di.Key,
                                ProductBarcode = di.Value,
                                Notes          = "录入的条码不符合14位数"
                            });
                        }
                    }
                }
            }

            SessionAccess.Set(scanValidKey, validModels, true);
            SessionAccess.Set(scanInvalidKey, inValidModels, true);
        }