/// <summary> /// 获得所有的库位 /// </summary> /// <returns></returns> public List <LocationEntity> GetList() { string Key = string.Format(CacheKey.JOOSHOW_LOCATION_CACHE, this.CompanyID); List <LocationEntity> listResult = CacheHelper.Get <List <LocationEntity> >(Key); if (!listResult.IsNullOrEmpty()) { return(listResult); } LocationEntity entity = new LocationEntity(); entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete) .And(a => a.CompanyID == this.CompanyID); entity.IncludeAll(); entity.OrderBy(a => a.ID, EOrderBy.DESC); listResult = this.Location.GetList(entity); if (!listResult.IsNullOrEmpty()) { StorageProvider storageProvider = new StorageProvider(this.CompanyID); List <StorageEntity> listStorage = storageProvider.GetList(); listStorage = listStorage.IsNull() ? new List <StorageEntity>() : listStorage; foreach (LocationEntity item in listResult) { StorageEntity storage = listStorage.FirstOrDefault(a => a.SnNum == item.StorageNum); if (storage != null) { item.StorageName = storage.StorageName; } } CacheHelper.Insert(Key, listResult); } return(listResult); }
/// <summary> /// 获得产品的缓存数据 /// </summary> /// <returns></returns> public List <ProductEntity> GetList() { string Key = string.Format(CacheKey.JOOSHOW_PRODUCT_CACHE, this.CompanyID); List <ProductEntity> list = CacheHelper.Get(Key) as List <ProductEntity>; if (!list.IsNullOrEmpty()) { return(list); } ProductEntity entity = new ProductEntity(); entity.IncludeAll(); entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete) .And(a => a.CompanyID == this.CompanyID); entity.OrderBy(a => a.ID, EOrderBy.DESC); list = this.Product.GetList(entity); if (!list.IsNullOrEmpty()) { StorageProvider storageProvider = new StorageProvider(this.CompanyID); List <StorageEntity> listStorage = storageProvider.GetList(); listStorage = listStorage.IsNull() ? new List <StorageEntity>() : listStorage; LocationProvider locationProvider = new LocationProvider(this.CompanyID); List <LocationEntity> listLocation = locationProvider.GetList(); listLocation = listLocation.IsNull() ? new List <LocationEntity>() : listLocation; foreach (ProductEntity item in list) { if (!item.StorageNum.IsEmpty()) { StorageEntity storage = listStorage.FirstOrDefault(a => a.SnNum == item.StorageNum); item.StorageName = storage.IsNull() ? string.Empty : storage.StorageName; } if (!item.DefaultLocal.IsEmpty()) { LocationEntity location = listLocation.FirstOrDefault(a => a.LocalNum == item.DefaultLocal); item.LocalName = location.IsNull() ? string.Empty : location.LocalName; } } } if (!list.IsNullOrEmpty()) { CacheHelper.Insert(Key, list); } return(list); }
/// <summary> /// 修改 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int Update(LocationEntity entity) { using (TransactionScope ts = new TransactionScope()) { string Key = string.Format(CacheKey.JOOSHOW_LOCATION_CACHE, this.CompanyID); if (entity.IsDefault == (int)EBool.Yes) { LocationEntity location = new LocationEntity(); location.IsDefault = (int)EBool.No; location.IncludeIsDefault(true); location.Where(a => a.LocalType == entity.LocalType) .And(a => a.CompanyID == this.CompanyID) ; this.Location.Update(location); LocationEntity temp = new LocationEntity(); temp.IsDefault = (int)EBool.No; temp.IncludeIsDefault(true); temp.Where(a => a.CompanyID == this.CompanyID); this.Location.Update(temp); } //绑定仓库信息 StorageProvider storageProvider = new StorageProvider(this.CompanyID); List <StorageEntity> listStorage = storageProvider.GetList(); listStorage = listStorage.IsNull() ? new List <StorageEntity>() : listStorage; if (entity.StorageNum.IsEmpty()) { StorageEntity storage = listStorage.FirstOrDefault(a => a.IsDefault == (int)EBool.Yes); if (storage != null) { entity.StorageNum = storage.StorageNum; entity.StorageType = storage.StorageType; } } else { StorageEntity storage = listStorage.FirstOrDefault(a => a.StorageNum == entity.StorageNum); if (storage != null) { entity.StorageType = storage.StorageType; } } if (entity.UnitName.IsEmpty() && !entity.UnitNum.IsEmpty()) { MeasureProvider provider = new MeasureProvider(this.CompanyID); List <MeasureEntity> listMeasure = provider.GetList(); listMeasure = listMeasure.IsNull() ? new List <MeasureEntity>() : listMeasure; MeasureEntity measureEntity = listMeasure.FirstOrDefault(a => a.SN == entity.UnitNum); entity.UnitName = measureEntity != null ? measureEntity.MeasureName : entity.UnitName; } entity.UnitNum = entity.UnitNum.IsEmpty() ? "" : entity.UnitNum; entity.UnitName = entity.UnitName.IsEmpty() ? "" : entity.UnitName; entity.Include(a => new { a.LocalBarCode, a.LocalName, a.StorageNum, a.StorageType, a.LocalType, a.Rack, a.Length, a.Width, a.Height, a.X, a.Y, a.Z, a.UnitNum, a.UnitName, a.Remark, a.IsForbid, a.IsDefault }); entity.Where(a => a.LocalNum == entity.LocalNum) .And(a => a.CompanyID == this.CompanyID) ; int line = this.Location.Update(entity); if (line > 0) { CacheHelper.Remove(Key); } ts.Complete(); return(line); } }