public static CalculatedCondition GetCalculatedCondition(TubeSampleStatus status, TubeSampleType type, double volume, int numberExport) { if (type == TubeSampleType.InStorage) { switch (status) { case TubeSampleStatus.Good: if (numberExport <= 0 && volume > 0) { return(CalculatedCondition.InStorage); } if (volume <= 0) { return(CalculatedCondition.OutOfVolume); // Hết } return(CalculatedCondition.Remove); case TubeSampleStatus.Corrupt: return(CalculatedCondition.Corrupt); case TubeSampleStatus.Remove: return(CalculatedCondition.Remove); case TubeSampleStatus.MoreTime: return(CalculatedCondition.MoreTime); default: return(CalculatedCondition.Remove); } } else if (type == TubeSampleType.InUse) { if (status == TubeSampleStatus.Good) { return(CalculatedCondition.InUse); } else { return(CalculatedCondition.Remove); } } else { return(CalculatedCondition.Remove); } }
private void UpdateTubeProxy(SpecLabEntities _entities, DatabaseCommand <UpdateTubeParams, bool> paramCommand) { var sampleDbItem = (from tube in _entities.TubeSamples where tube.TubeId.Equals( paramCommand.CallingInfo.TubeId, StringComparison.OrdinalIgnoreCase) select tube).FirstOrDefault(); if (sampleDbItem == null) { throw new BusinessException(ErrorCode.TubeIdNotExists); } // kiểm tra chuyển trạng thái trực tiếp TubeSampleType currentType = (TubeSampleType)sampleDbItem.TubeType; TubeSampleStatus currentStatus = (TubeSampleStatus)sampleDbItem.Status; if (paramCommand.CallingInfo.Type == TubeSampleType.InStorage) { if (paramCommand.CallingInfo.Status == TubeSampleStatus.Remove) { if (currentStatus != TubeSampleStatus.Remove) { throw new BusinessException(ErrorCode.TubeUpdateStatusRemove); } } } else if (paramCommand.CallingInfo.Type == TubeSampleType.InUse) { if (currentType != TubeSampleType.InUse) { throw new BusinessException(ErrorCode.TubeUpdateStatusInUse); } } ValidateStorageId(_entities, paramCommand.CallingInfo.StorageId, paramCommand.CallingInfo.LocationNum); // check duplicate location var checkLocationQuery = (from tube in _entities.TubeSamples where tube.StorageId == paramCommand.CallingInfo.StorageId && tube.LocationNum == paramCommand.CallingInfo.LocationNum && tube.Status != (int)TubeSampleStatus.Remove && !tube.TubeId.Equals( paramCommand.CallingInfo.TubeId, StringComparison.OrdinalIgnoreCase) select tube.TubeId); if (checkLocationQuery.Any()) { throw new BusinessException(ErrorCode.StorageLocationUsed, paramCommand.CallingInfo.StorageId, paramCommand.CallingInfo.LocationNum); } // check location storage > maximum storage checkLocationQuery = (from storage in _entities.Storages where storage.StorageId == paramCommand.CallingInfo.StorageId && storage.NumberStorage < paramCommand.CallingInfo.LocationNum select storage.StorageId); if (checkLocationQuery.Any()) { throw new BusinessException(ErrorCode.StorageLocationOutOfBound, paramCommand.CallingInfo.StorageId, paramCommand.CallingInfo.LocationNum); } sampleDbItem.Volume = paramCommand.CallingInfo.Volume; sampleDbItem.StorageId = paramCommand.CallingInfo.StorageId; sampleDbItem.LocationNum = paramCommand.CallingInfo.LocationNum; sampleDbItem.Status = (int)paramCommand.CallingInfo.Status; sampleDbItem.TubeType = (int)paramCommand.CallingInfo.Type; sampleDbItem.UpdateDate = DateTime.Now; sampleDbItem.SampleHistories.Add(new SampleHistory() { HistoryDate = paramCommand.CallingInfo.DateInput, Action = (int)HistoryAction.Update, UserId = paramCommand.CallingInfo.UserInput, Status = (int)paramCommand.CallingInfo.Status, TubeType = (int)paramCommand.CallingInfo.Type, Volume = paramCommand.CallingInfo.Volume, StorageId = paramCommand.CallingInfo.StorageId, LocationNum = paramCommand.CallingInfo.LocationNum, TubeId = paramCommand.CallingInfo.TubeId, Description = "" }); _entities.SaveChanges(); }