Example #1
0
        public ExistsOffer Find(NewOffer offer)
        {
            var key = GetKey(offer);

            if (!_searchHash.ContainsKey(key))
            {
                return(null);
            }
            return(((List <Offer>)_searchHash[key]).Cast <ExistsOffer>().FirstOrDefault(c => c.NewOffer == null));
        }
        /// <summary>
        /// Производится вставка данных в таблицу Core
        /// </summary>
        public void InsertToCore(FormalizationPosition position, Cost[] costs)
        {
            var quantity = GetFieldValueObject(PriceFields.Quantity);
            var core     = new NewOffer {
                Code             = GetFieldValue(PriceFields.Code),
                CodeCr           = GetFieldValue(PriceFields.CodeCr),
                Unit             = GetFieldValue(PriceFields.Unit),
                Volume           = GetFieldValue(PriceFields.Volume),
                Quantity         = quantity is DBNull ? null : quantity.ToString(),
                Note             = GetFieldValue(PriceFields.Note),
                Doc              = (string)GetFieldValueObject(PriceFields.Doc),
                Junk             = (bool)GetFieldValueObject(PriceFields.Junk),
                Await            = (bool)GetFieldValueObject(PriceFields.Await),
                VitallyImportant = (bool)GetFieldValueObject(PriceFields.VitallyImportant),
                MinBoundCost     = GetDecimalValue(PriceFields.MinBoundCost),
                MaxBoundCost     = GetDecimalValue(PriceFields.MaxBoundCost),
                OrderCost        = GetDecimalValue(PriceFields.OrderCost),
                MinOrderCount    = GetUintOrDefault(PriceFields.MinOrderCount),
                RequestRatio     = GetUintOrDefault(PriceFields.RequestRatio),
                RegistryCost     = GetDecimalValue(PriceFields.RegistryCost),
                Nds              = GetUintOrDefault(PriceFields.Nds),
                CodeOKP          = GetUintOrDefault(PriceFields.CodeOKP),
                EAN13            = SafeConvert.ToUInt64(GetFieldValue(PriceFields.EAN13)),
                Series           = GetFieldValue(PriceFields.Series),
                ProducerCost     = GetDecimalValue(PriceFields.ProducerCost),
                OptimizationSkip = (bool)GetFieldValueObject(PriceFields.OptimizationSkip)
            };

            if (quantity is int)
            {
                core.QuantityAsInt = (int)quantity;
            }

            var    rawPeriodValue = GetFieldValueObject(PriceFields.Period);
            string periodValue;

            //если получилось преобразовать в дату, то сохраняем в формате даты
            if (rawPeriodValue is DateTime)
            {
                periodValue = ((DateTime)rawPeriodValue).ToString("dd'.'MM'.'yyyy");
            }
            else
            {
                //Если не получилось преобразовать, то смотрим на "сырое" значение поле, если оно не пусто, то пишем в базу
                periodValue = GetFieldRawValue(PriceFields.Period);
                if (String.IsNullOrEmpty(periodValue))
                {
                    periodValue = null;
                }
            }
            core.Period    = periodValue;
            core.Costs     = costs;
            position.Offer = core;
        }