Esempio n. 1
0
        protected override void Execute(NativeActivityContext context)
        {
            // получим все параметры
            var teCode = TeCode.Get(context);

            // переведем код ТЕ в верхний регистр
            if (!string.IsNullOrEmpty(teCode))
            {
                teCode = teCode.ToUpper();
            }
            var placeCode  = PlaceCode.Get(context);
            var isPack     = IsPack.Get(context);
            var length     = Length.Get(context);
            var width      = Width.Get(context);
            var height     = Height.Get(context);
            var tareWeight = TareWeight.Get(context);
            var weight     = Weight.Get(context);
            var mandants   = Mandants.Get(context);
            var teTypeCode = TeTypeCode.Get(context);
            var autoTeType = AutoTeType.Get(context);
            var extFilter  = Filter.Get(context);

            _fontSize = FontSize.Get(context);
            var suspendNotifyCollectionChanged = SuspendNotifyCollectionChanged.Get(context);

            var teManager = IoC.Instance.Resolve <IBaseManager <TE> >();

            try
            {
                if (suspendNotifyCollectionChanged)
                {
                    teManager.SuspendNotifications();
                }

                // если поле тип ТЕ пустое и не стоит признак пытаться определить тип ТЕ автоматически
                if (string.IsNullOrEmpty(teTypeCode) && !autoTeType)
                {
                    throw new OperationException("Не указан тип ТЕ");
                }

                // если поле тип ТЕ заполнено и установлен признак получения автоматически
                if (!string.IsNullOrEmpty(teTypeCode) && autoTeType)
                {
                    throw new OperationException("Неверные настройки получения типа ТЕ");
                }

                var uw = BeginTransactionActivity.GetUnitOfWork(context);
                if (uw != null)
                {
                    throw new OperationException("Действие в транзакции запрещено");
                }

                // проверим существование ТЕ
                if (!string.IsNullOrEmpty(teCode))
                {
                    var bpManager = IoC.Instance.Resolve <IBPProcessManager>();
                    var existTe   = bpManager.CheckInstanceEntity("TE", teCode);
                    if (existTe == 1)
                    {
                        var existTeObj = teManager.Get(teCode);
                        if (existTeObj == null)
                        {
                            throw new OperationException("Нет прав на ТЕ с кодом {0}", teCode);
                        }
                        ExceptionResult.Set(context, null);
                        TeCode.Set(context, teCode);
                        OutTe.Set(context, existTeObj);
                        Exist.Set(context, true);
                        Result.Set(context, true);
                        return;
                    }
                }

                // фильтр на тип ТЕ
                var filter = string.Empty;
                // фильтр по мандантам
                if (!string.IsNullOrEmpty(mandants))
                {
                    filter = string.Format(
                        "tetypecode in (select tt2m.tetypecode_r from wmstetype2mandant tt2m where tt2m.partnerid_r in ({0}))",
                        mandants);
                }

                // фильтр по упаковкам
                if (isPack)
                {
                    filter =
                        string.Format(
                            "{0}tetypecode in (select CUSTOMPARAMVAL.cpvkey from wmscustomparamvalue CUSTOMPARAMVAL  where CUSTOMPARAMVAL.CPV2ENTITY = 'TETYPE' and CUSTOMPARAMVAL.CUSTOMPARAMCODE_R = 'TETypeIsPackingL2' and CUSTOMPARAMVAL.CPVVALUE is not null and CUSTOMPARAMVAL.CPVVALUE != '0')",
                            string.IsNullOrEmpty(filter) ? string.Empty : filter + " and ");
                }

                // дополнительный фильтр по типам ТЕ
                if (!string.IsNullOrEmpty(extFilter))
                {
                    filter =
                        string.Format(
                            "{0}{1}",
                            string.IsNullOrEmpty(filter) ? string.Empty : filter + " and ", extFilter);
                }

                // если надо определить тип ТЕ автоматически
                if (autoTeType)
                {
                    teTypeCode = BPH.DetermineTeTypeCodeByTeCode(teCode, filter);
                }

                var teTypeObj = GetTeType(teTypeCode, filter);

                // если не выбрали тип ТЕ
                if (teTypeObj == null)
                {
                    ExceptionResult.Set(context, null);
                    TeCode.Set(context, teCode);
                    OutTe.Set(context, null);
                    Exist.Set(context, false);
                    Result.Set(context, false);
                    return;
                }

                var teObj = new TE();
                teObj.SetKey(teCode);
                teObj.SetProperty(TE.TETypeCodePropertyName, teTypeObj.GetKey());
                teObj.SetProperty(TE.CreatePlacePropertyName, placeCode);
                teObj.SetProperty(TE.CurrentPlacePropertyName, placeCode);
                teObj.SetProperty(TE.StatusCodePropertyName, TEStates.TE_FREE.ToString());
                teObj.SetProperty(TE.TEPackStatusPropertyName,
                                  isPack ? TEPackStatus.TE_PKG_CREATED.ToString() : TEPackStatus.TE_PKG_NONE.ToString());

                teObj.SetProperty(TE.TELengthPropertyName, length ?? teTypeObj.GetProperty(TEType.LengthPropertyName));
                teObj.SetProperty(TE.TEWidthPropertyName, width ?? teTypeObj.GetProperty(TEType.WidthPropertyName));
                teObj.SetProperty(TE.TEHeightPropertyName, height ?? teTypeObj.GetProperty(TEType.HeightPropertyName));
                teObj.SetProperty(TE.TETareWeightPropertyName,
                                  tareWeight ?? teTypeObj.GetProperty(TEType.TareWeightPropertyName));
                teObj.SetProperty(TE.TEMaxWeightPropertyName,
                                  tareWeight ?? teTypeObj.GetProperty(TEType.MaxWeightPropertyName));
                teObj.SetProperty(TE.TEWeightPropertyName,
                                  weight ?? teTypeObj.GetProperty(TEType.TareWeightPropertyName));

                ((ISecurityAccess)teManager).SuspendRightChecking();
                teManager.Insert(ref teObj);

                ExceptionResult.Set(context, null);
                TeCode.Set(context, teCode);
                OutTe.Set(context, teObj);
                Exist.Set(context, false);
                Result.Set(context, true);
            }
            catch (Exception ex)
            {
                TeCode.Set(context, teCode);
                ExceptionResult.Set(context, ex);
                OutTe.Set(context, null);
                Exist.Set(context, false);
                Result.Set(context, false);
            }
            finally
            {
                if (suspendNotifyCollectionChanged)
                {
                    teManager.ResumeNotifications();
                }
                ((ISecurityAccess)teManager).ResumeRightChecking();
            }
        }
Esempio n. 2
0
        protected override void Execute(NativeActivityContext context)
        {
            var placeCode = PlaceCode.Get(context);

            _fontSize = FontSize.Get(context);
            try
            {
                if (string.IsNullOrEmpty(placeCode))
                {
                    throw new NullReferenceException("Не указан код места");
                }
                using (var mgr = IoC.Instance.Resolve <IBaseManager <Place2Blocking> >())
                {
                    var blocking = mgr.GetFiltered(string.Format("{0}='{1}'",
                                                                 SourceNameHelper.Instance.GetPropertySourceName(typeof(Place2Blocking), Place2Blocking.Place2BlockingPlaceCodePropertyName),
                                                                 placeCode)).ToArray();
                    if (blocking.Length > 0)
                    {
                        Place2Blocking[] actualBlocks;
                        switch (Operation)
                        {
                        case PlaceOperationEnum.IN:
                            actualBlocks =
                                blocking.Where(
                                    i => Equals(i.Place2BlockingBlockingCode, PlaceBlockingEnum.PLACE_BAN.ToString()) || Equals(i.Place2BlockingBlockingCode, PlaceBlockingEnum.PLACE_BAN_IN.ToString()))
                                .ToArray();
                            break;

                        case PlaceOperationEnum.OUT:
                            actualBlocks =
                                blocking.Where(
                                    i => Equals(i.Place2BlockingBlockingCode, PlaceBlockingEnum.PLACE_BAN.ToString()))
                                .ToArray();
                            break;

                        default:
                            actualBlocks = blocking;
                            break;
                        }
                        if (actualBlocks.Length == 0)
                        {
                            Result.Set(context, false);
                        }
                        else
                        {
                            Result.Set(context, true);
                            if (ShowDialog)
                            {
                                var placeName = actualBlocks[0].GetProperty(Place2Blocking.VPLACENAMEPropertyName);
                                var message   = new StringBuilder();
                                message.AppendFormat("Место '{0}' заблокировано!", placeName);
                                foreach (var b in actualBlocks)
                                {
                                    message.AppendFormat("{0}{1}: {2}", System.Environment.NewLine, b.GetProperty(Place2Blocking.VBLOCKINGNAMEPropertyName), b.Place2BlockingDesc);
                                }
                                ShowWarningMessage("Предупреждение", message.ToString());
                            }
                        }
                    }
                    else
                    {
                        Result.Set(context, false);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ShowDialog)
                {
                    ShowErrorMessage(ex);
                }
                Result.Set(context, false);
            }
        }
Esempio n. 3
0
        private void ProcessCreateProduct(NativeActivityContext context)
        {
            #region  .  Checks&Ini  .

            if (_items == null || _items.Count == 0)
            {
                return;
            }

            var iwbId         = IWBId.Get(context);
            var placeCode     = PlaceCode.Get(context);
            var operationCode = OperationCode.Get(context);
            var isMigration   = IsMigration.Get(context) ? 1 : 0;
            var timeOut       = TimeOut.Get(context);
            var wfUow         = BeginTransactionActivity.GetUnitOfWork(context);

            // получаем менеджер приемки
            Min min = null;
            using (var mgr = IoC.Instance.Resolve <IBPProcessManager>())
            {
                if (wfUow != null)
                {
                    mgr.SetUnitOfWork(wfUow);
                }

                var minId = mgr.GetDefaultMIN(iwbId);
                if (minId.HasValue)
                {
                    using (var mgrIn = IoC.Instance.Resolve <IBaseManager <Min> >())
                    {
                        if (wfUow != null)
                        {
                            mgr.SetUnitOfWork(wfUow);
                        }

                        min = mgrIn.Get(minId);
                    }
                }
            }

            // определяем параметры приемки
            var isMinCpvExist     = min != null && min.CustomParamVal != null && min.CustomParamVal.Count != 0;
            var isNeedControlOver = isMinCpvExist &&
                                    min.CustomParamVal.Any(
                i => i.CustomParamCode == MinCpv.MINOverEnableCpvName && i.CPVValue == "1");
            var isNeedConfirmOver = isNeedControlOver &&
                                    min.CustomParamVal.Any(
                i =>
                i.CustomParamCode == MinCpv.MINOverEnableNeedConfirmCpvName &&
                i.CPVValue == "1");
            var isMinLimit     = isMinCpvExist && min.CustomParamVal.Any(i => i.VCustomParamParent == MinCpv.MinLimitL2CpvName);
            var itemsToProcess = new List <IWBPosInput>();

            #endregion

            #region  .  BatchCode&OverCount  .

            foreach (var item in _items)
            {
                var itemKey = item.GetKey();
                if (!item.IsSelected || itemKey == null)
                {
                    _failedItems.Enqueue(item);
                    continue;
                }

                item.ManageFlag = null;

                //Ошибки при распознавании batch-кода
                if (!item.NotCriticalBatchcodeError && !item.IsBpBatchcodeCompleted)
                {
                    var message = string.IsNullOrEmpty(item.BatchcodeErrorMessage)
                        ? "Ошибка не определена."
                        : item.BatchcodeErrorMessage;
                    SkipItem(item, message);
                    continue;
                }

                if (item.RequiredSKUCount < 1)
                {
                    SkipItem(item, "Некорректно введено 'Количество по факту'");
                    continue;
                }

                // если пытаемся принять с избытком
                if (isNeedControlOver)
                {
                    var count     = item.ProductCountSKU + (double)item.RequiredSKUCount;
                    var overCount = count - item.IWBPosCount;
                    if (overCount > 0 && isNeedConfirmOver)
                    {
                        var questionMessage = string.Format(
                            "Позиция '{0}' ед.уч. '{1}'.{4}Фактическое кол-во = '{2}'.{4}Излишек составит '{3}'.{4}Принять излишек?",
                            itemKey, item.SKUNAME, count, overCount, Environment.NewLine);

                        var dr = _viewService.ShowDialog(
                            GetDefaultMessageBoxCaption(iwbId),
                            questionMessage,
                            MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes, 14);

                        if (dr == MessageBoxResult.Yes)
                        {
                            item.ManageFlag += (!string.IsNullOrEmpty(item.ManageFlag) ? "," : string.Empty) +
                                               "OVERASK_OK";
                        }
                        else
                        {
                            var message = string.Format("Пользователь отказался принимать излишек по позиции '{0}'",
                                                        itemKey, item.SKUNAME);
                            SkipItem(item, message);
                            continue;
                        }
                    }
                }

                itemsToProcess.Add(item);
            }

            #endregion

            // группируем по артикулу
            var groupItems = itemsToProcess.GroupBy(i => i.ArtCode).ToArray();

            //обработка сроков годности
            if (isMinLimit)
            {
                var ret = ProccesExpireDate(itemsToProcess, min, groupItems, wfUow, iwbId);
                if (!ret)
                {
                    return;
                }
            }

            var ask = new ConcurrentQueue <IWBPosInput>();

            while (true)
            {
                RunCreateProduct(itemsToProcess, ref ask, timeOut, wfUow, operationCode, iwbId, isMigration, placeCode,
                                 isNeedControlOver);
                if (ask == null || ask.Count <= 0)
                {
                    break;
                }

                itemsToProcess.Clear();
                foreach (var item in ask)
                {
                    var message = string.Format("Принять излишек по позиции '{0}' ед.уч. '{1}' ?", item.GetKey(),
                                                item.SKUNAME);
                    var res = _viewService.ShowDialog(GetDefaultMessageBoxCaption(iwbId), message,
                                                      MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes, 14);

                    if (res != MessageBoxResult.Yes)
                    {
                        SkipItem(item,
                                 string.Format("Пользователь отказался принимать излишек по позиции '{0}'", item.GetKey()));
                        continue;
                    }
                    itemsToProcess.Add(item);
                }

                while (!ask.IsEmpty)
                {
                    IWBPosInput someItem;
                    ask.TryDequeue(out someItem);
                }
            }
        }