public ActionResult ExcelBatchStrageCheck() { var _key = "sess_excel_inpor_instorage_11"; var dat = SessionAccess.Get(_key) as List <List <string> >; Dictionary <string, string> dic = new Dictionary <string, string>(); if (dat != null && dat.Any()) { foreach (var li in dat) { var te = li[0]; Guid guid = Guid.NewGuid(); var key = guid.ToString(); dic.Add(key, te); } } BatchInputStorageCheck(dic, true); 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>; OperationResult resul = new OperationResult(OperationResultType.Success); resul.Other = new { validCoun = validModels.Count, inValidCoun = inValidModels.Count }; SessionAccess.Remove(_key); return(Json(resul)); }
/// <summary> /// 批量导入页面分页获取excel的数据 /// </summary> /// <returns></returns> public ActionResult GetBatchImportExcelData() { GridRequest gr = new GridRequest(Request); var _key = "sess_excel_inpor_instorage_11"; var dat = SessionAccess.Get(_key) as List <List <string> >; GridData <object> da = new GridData <object>(new List <object>(), 0, Request); if (dat != null) { var te = dat.Select(c => new { Barcode = c[0], RowInd = Convert.ToInt32(c[1]), }).ToList(); var li = te.OrderBy(c => c.RowInd).Skip(gr.PageCondition.PageIndex).Take(gr.PageCondition.PageSize).Select(c => new { ProductBarcode = c.Barcode, c.RowInd } ).ToList(); da = new GridData <object>(li, dat.Count, Request); } return(Json(da)); }
public ActionResult GetValidDataList() { string _validSessionKey = "1102_validsessionkey_09"; string _invaliSessionKey = "1102_invalidsessionkey_03"; var validData = SessionAccess.Get(_validSessionKey) as List <DiscountValidSession>; var invalidData = SessionAccess.Get(_invaliSessionKey) as List <DiscountValidSession>; return(Json(new { validDa = validData, invaliDa = invalidData })); }
/// <summary> /// 获取数据 /// </summary> /// <returns></returns> public ActionResult VaildViewList(string uid) { GridRequest request = new GridRequest(Request); int count = 0; int pageIndex = request.PageCondition.PageIndex; int pageSize = request.PageCondition.PageSize; var validListFromCache = (List <Product_Model>)SessionAccess.Get(SESSION_KEY_VALID_LIST + uid) ?? new List <Product_Model>(); count = validListFromCache.Count; var index = 1; var resData = validListFromCache.Skip(pageIndex).Take(pageSize).Select(p => new { Id = index++, ProductBarcode = p.ProductBarcode }).ToList(); var data = new GridData <object>(resData, count, request.RequestInfo); return(Json(data, JsonRequestBehavior.AllowGet)); }
public JsonResult BathcProductCreate(int?[] ids, ProductDiscountDto dto) { OperationResult resul = new OperationResult(OperationResultType.Error); #region 添加前校验 if (!string.IsNullOrEmpty(dto.DiscountName)) { bool exis = _productDiscountContract.ProductDiscounts.Any( c => c.DiscountName == dto.DiscountName && !c.IsDeleted && c.IsEnabled); if (exis) { resul.Message = "已存在同名的折扣方案"; return(Json(resul)); } } #endregion string _validSessionKey = "1102_validsessionkey_09"; string _invaliSessionKey = "1102_invalidsessionkey_03"; if (ids.Any(c => c != null)) { if (dto.DiscountType == 1) { dto.BigNumbers = string.Join(",", ids); } resul = _productDiscountContract.Insert(dto); } else { var discountvalids = SessionAccess.Get(_validSessionKey) as List <DiscountValidSession>; if (discountvalids != null) { resul = _productDiscountContract.Insert(dto); } else { resul = new OperationResult(OperationResultType.ValidError); } } if (resul.ResultType == OperationResultType.Success) { SessionAccess.Remove(_validSessionKey); SessionAccess.Remove(_invaliSessionKey); } return(Json(resul)); }
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)); }
public ActionResult GetInputStorageCheckData() { GridRequest gr = new GridRequest(Request); var exp = FilterHelper.GetExpression <Product_Model>(gr.FilterGroup); var scanValidKey = "ScanValid"; List <Product_Model> validModels = SessionAccess.Get(scanValidKey) as List <Product_Model>; if (validModels == null) { validModels = new List <Product_Model>(); } List <object> da = new List <object>(); if (validModels.Any()) { var codes = validModels.OrderBy(c => c.Id).Skip(gr.PageCondition.PageIndex).Take(gr.PageCondition.PageSize).Select(c => c.ProductBarcode); da = _productBarcodeDetailContract.productBarcodeDetails.Where(c => codes.Contains(c.ProductNumber + c.OnlyFlag)).Select(c => new { c.Product.Id, c.ProductNumber, Barcode = c.ProductNumber + c.OnlyFlag, ThumbnailPath = c.Product.ThumbnailPath ?? c.Product.ProductOriginNumber.ThumbnailPath, c.Product.ProductOriginNumber.Brand.BrandName, c.Product.ProductOriginNumber.Category.CategoryName, c.Product.Size.SizeName }).ToList().Select(c => new { c.Id, Pind = (validModels.FirstOrDefault(g => g.ProductBarcode == c.Barcode)) == null ? 0 : validModels.FirstOrDefault(g => g.ProductBarcode == c.Barcode).Id, c.ProductNumber, c.Barcode, c.ThumbnailPath, c.BrandName, c.CategoryName, c.SizeName, }).OrderBy(c => c.Pind).ToList <object>(); } GridData <object> resda = new GridData <object>(da, validModels.Count, Request); return(Json(resda)); }
/// <summary> /// 入库校验 /// </summary> /// <param name="uuid"></param> /// <param name="number"></param> /// <returns></returns> public ActionResult InputStorageCheck(string uuid, string number) { Dictionary <string, string> dicpre = new Dictionary <string, string>(); dicpre.Add(uuid, number); BatchInputStorageCheck(dicpre); 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>; OperationResult resul = new OperationResult(OperationResultType.Success); resul.Other = new { uuid, validCoun = validModels.Count, inValidCoun = inValidModels.Count }; return(Json(resul)); }
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)); }
/// <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)); }
public ActionResult ExceptionDataExportToExcel() { OperationResult result = 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>; List <List <string> > validDa = new List <List <string> >(); List <List <string> > inValidDa = new List <List <string> >(); if (validModels != null && validModels.Any()) { foreach (var valda in validModels) { validDa.Add(new List <string>() { valda.Id.ToString(), valda.ProductBarcode }); } } if (inValidModels != null && inValidModels.Any()) { foreach (var valda in inValidModels) { inValidDa.Add(new List <string>() { valda.Id.ToString(), valda.ProductBarcode, valda.Notes }); } } List <List <List <string> > > li = new List <List <List <string> > >(); li.Add(validDa); li.Add(inValidDa); YxkSabri.ExcelUtility excel = new ExcelUtility(); var name = DateTime.Now.ToString("yyyyMMddHHff") + ".xls"; string basedir = Server.MapPath(@"\Content\UploadFiles\Excels\ExportDa\"); if (Directory.Exists(basedir)) { Directory.Delete(basedir, true); } Directory.CreateDirectory(basedir); string path = basedir + name; var rsul = excel.ExportMulitExcelSheet(li, path, new string[] { "有效", "无效" }); if (rsul) { result = new OperationResult(OperationResultType.Success); } return(File(path, "application/ms-excel", "导出数据.xls")); //// string path = "D:/test/销售月报表.xlsx"; // FileStream fs = new FileStream(path, FileMode.Open); // byte[] buffer = new byte[fs.Length]; // fs.Read(buffer, 0, buffer.Length); // fs.Close(); //System.IO.File.Delete(path); // Response.ContentType = "application/ms-excel"; // Response.Charset = "GB2312"; // Response.ContentEncoding = System.Text.Encoding.UTF8; // Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode("销售月报表.xlsx")); // Response.OutputStream.Write(buffer, 0, buffer.Length); // Response.Flush(); // Response.End(); // return Json(result); }
/// <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); }