/// <summary> /// 获得所有的库位 /// </summary> /// <returns></returns> public List <LocationEntity> GetList() { List <LocationEntity> listResult = CacheHelper.Get <List <LocationEntity> >(CacheKey.JOOSHOW_LOCATION_CACHE); if (!listResult.IsNullOrEmpty()) { return(listResult); } LocationEntity entity = new LocationEntity(); entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete); entity.IncludeAll(); listResult = this.Location.GetList(entity); if (!listResult.IsNullOrEmpty()) { StorageProvider storageProvider = new StorageProvider(); List <StorageEntity> listStorage = storageProvider.GetList(); listStorage = listStorage.IsNull() ? new List <StorageEntity>() : listStorage; foreach (LocationEntity item in listResult) { StorageEntity storage = listStorage.FirstOrDefault(a => a.StorageNum == item.StorageNum); if (storage != null) { item.StorageName = storage.StorageName; } } CacheHelper.Insert(CacheKey.JOOSHOW_LOCATION_CACHE, listResult, null, DateTime.Now.AddHours(6)); } return(listResult); }
/// <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> /// <param name="storageNum"></param> /// <returns></returns> public LocationEntity GetSingleByNum(string LocalNum) { LocationEntity entity = new LocationEntity(); entity.IncludeAll(); entity.Where(a => a.LocalNum == LocalNum); entity = this.Location.GetSingle(entity); return(entity); }
/// <summary> /// 根据库存编码查询仓库信息 /// </summary> /// <param name="storageNum"></param> /// <returns></returns> public LocationEntity GetSingleByNum(string LocalNum) { LocationEntity entity = new LocationEntity(); entity.IncludeAll(); entity.Where(a => a.LocalNum == LocalNum) .And(a => a.IsDelete == (int)EIsDelete.NotDelete) .And(a => a.CompanyID == this.CompanyID); entity = this.Location.GetSingle(entity); return(entity); }
/// <summary> /// 新增库位 /// 如果设置为默认库位,则其他的库位修改为非默认库位 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int Add(LocationEntity entity) { using (TransactionScope ts = new TransactionScope()) { //设置默认值 if (entity.IsDefault == (int)EBool.Yes) { LocationEntity temp = new LocationEntity(); temp.IsDefault = (int)EBool.No; temp.IncludeIsDefault(true); temp.Where(a => a.LocalNum == entity.LocalNum); this.Location.Update(temp); } //绑定仓库信息 StorageProvider storageProvider = new StorageProvider(); List <StorageEntity> listStorage = storageProvider.GetList(); if (entity.StorageNum.IsEmpty()) { if (!listStorage.IsNullOrEmpty()) { StorageEntity storage = listStorage.FirstOrDefault(a => a.IsDefault == (int)EBool.Yes); if (storage != null) { entity.StorageNum = storage.StorageNum; entity.StorageType = storage.StorageType; } } } else { if (!listStorage.IsNullOrEmpty()) { StorageEntity storage = listStorage.FirstOrDefault(a => a.StorageNum == entity.StorageNum); if (storage != null) { entity.StorageType = storage.StorageType; } } } entity.IncludeAll(); int line = this.Location.Add(entity); if (line > 0) { Clear(); } ts.Complete(); return(line); } }
/// <summary> /// 查询分页 /// </summary> /// <param name="entity"></param> /// <param name="pageInfo"></param> /// <returns></returns> public List <LocationEntity> GetList(LocationEntity entity, ref PageInfo pageInfo) { try { entity.IncludeAll(); entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete); entity.OrderBy(a => a.ID, EOrderBy.DESC); int rowCount = 0; List <LocationEntity> listResult = this.Location.GetList(entity, pageInfo.PageSize, pageInfo.PageIndex, out rowCount); pageInfo.RowCount = rowCount; if (!listResult.IsNullOrEmpty()) { StorageProvider storageProvider = new StorageProvider(); List <StorageEntity> listStorage = storageProvider.GetList(); listStorage = listStorage.IsNull() ? new List <StorageEntity>() : listStorage; foreach (LocationEntity item in listResult) { StorageEntity storage = listStorage.FirstOrDefault(a => a.StorageNum == item.StorageNum); if (storage != null) { item.StorageName = storage.StorageName; } else { item.StorageName = ""; } } } return(listResult); } catch (Exception e) { log.Error(e.Message); } return(null); }
/// <summary> /// 初始化某个仓库的库位 /// </summary> /// <param name="StorageNum"></param> /// <param name="CreateUser"></param> /// <returns></returns> public int Init(string StorageNum, string CreateUser) { string Key = string.Format(CacheKey.JOOSHOW_LOCATION_CACHE, this.CompanyID); int line = 0; LocationEntity entity = new LocationEntity(); entity.Where(item => item.StorageNum == StorageNum) .And(item => item.CompanyID == this.CompanyID) ; if (this.Location.GetCount(entity) == 0) { StorageProvider storageProvider = new StorageProvider(this.CompanyID); StorageEntity storage = storageProvider.GetSingleByNum(StorageNum); if (storage != null) { LocationEntity location = new LocationEntity(); location.LocalNum = ConvertHelper.NewGuid(); location.LocalBarCode = new SequenceProvider(this.CompanyID).GetSequence(typeof(LocationEntity)); location.LocalName = "默认待入库位"; location.LocalType = (int)ELocalType.WaitIn; location.StorageNum = storage.SnNum; location.StorageType = storage.StorageType; location.CreateUser = CreateUser; location.CreateTime = DateTime.Now; location.IsDefault = (int)EBool.Yes; location.IsDelete = (int)EIsDelete.NotDelete; location.IsForbid = (int)EBool.No; location.CompanyID = this.CompanyID; location.IncludeAll(); line += this.Location.Add(location); location = new LocationEntity(); location.LocalNum = ConvertHelper.NewGuid(); location.LocalBarCode = new SequenceProvider(this.CompanyID).GetSequence(typeof(LocationEntity)); location.LocalName = "默认正式库位"; location.LocalType = (int)ELocalType.Normal; location.StorageNum = storage.SnNum; location.StorageType = storage.StorageType; location.CreateUser = CreateUser; location.CreateTime = DateTime.Now; location.IsDefault = (int)EBool.Yes; location.IsDelete = (int)EIsDelete.NotDelete; location.IsForbid = (int)EBool.No; location.CompanyID = this.CompanyID; location.IncludeAll(); line += this.Location.Add(location); location = new LocationEntity(); location.LocalNum = ConvertHelper.NewGuid(); location.LocalBarCode = new SequenceProvider(this.CompanyID).GetSequence(typeof(LocationEntity)); location.LocalName = "默认待检库位"; location.LocalType = (int)ELocalType.WaitCheck; location.StorageNum = storage.SnNum; location.StorageType = storage.StorageType; location.CreateUser = CreateUser; location.CreateTime = DateTime.Now; location.IsDefault = (int)EBool.Yes; location.IsDelete = (int)EIsDelete.NotDelete; location.IsForbid = (int)EBool.No; location.CompanyID = this.CompanyID; location.IncludeAll(); line += this.Location.Add(location); location = new LocationEntity(); location.LocalNum = ConvertHelper.NewGuid(); location.LocalBarCode = new SequenceProvider(this.CompanyID).GetSequence(typeof(LocationEntity)); location.LocalName = "默认待出库位"; location.LocalType = (int)ELocalType.WaitOut; location.StorageNum = storage.SnNum; location.StorageType = storage.StorageType; location.CreateUser = CreateUser; location.CreateTime = DateTime.Now; location.IsDefault = (int)EBool.Yes; location.IsDelete = (int)EIsDelete.NotDelete; location.IsForbid = (int)EBool.No; location.CompanyID = this.CompanyID; location.IncludeAll(); line += this.Location.Add(location); location = new LocationEntity(); location.LocalNum = ConvertHelper.NewGuid(); location.LocalBarCode = new SequenceProvider(this.CompanyID).GetSequence(typeof(LocationEntity)); location.LocalName = "默认报损库位"; location.LocalType = (int)ELocalType.Bad; location.StorageNum = storage.SnNum; location.StorageType = storage.StorageType; location.CreateUser = CreateUser; location.CreateTime = DateTime.Now; location.IsDefault = (int)EBool.Yes; location.IsDelete = (int)EIsDelete.NotDelete; location.IsForbid = (int)EBool.No; location.CompanyID = this.CompanyID; location.IncludeAll(); line += this.Location.Add(location); } } if (line > 0) { CacheHelper.Remove(Key); } return(line); }
/// <summary> /// 新增库位 /// 如果设置为默认库位,则其他的库位修改为非默认库位 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int Add(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.IncludeAll(); int line = this.Location.Add(entity); if (line > 0) { CacheHelper.Remove(Key); } ts.Complete(); return(line); } }