/// <summary> /// 设置为默认 /// </summary> /// <param name="LocalNum"></param> /// <returns></returns> public int SetDefault(string LocalNum) { string Key = string.Format(CacheKey.JOOSHOW_LOCATION_CACHE, this.CompanyID); LocationEntity location = GetSingleByNum(LocalNum); location = new LocationEntity(); location.IsDefault = (int)EBool.No; location.IncludeIsDefault(true); location.And(a => a.CompanyID == this.CompanyID); this.Location.Update(location); LocationEntity entity = new LocationEntity(); entity.IsDefault = (int)EBool.Yes; entity.IncludeIsDefault(true); entity.Where(a => a.LocalNum == LocalNum) .And(a => a.CompanyID == this.CompanyID) ; int line = this.Location.Update(entity); 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()) { //设置默认值 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> /// <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); } }