Пример #1
0
        private static DA.ValueName ToEntity(string name, DA.ValueNameCategory category, DA.ValueNameType type, DA.OKBDataContext okb)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            var entity = okb.ValueNames.FirstOrDefault(x => (x.Name == name) && (x.Category == category) && (x.Type == type));

            if (entity == null)
            {
                entity = new DA.ValueName()
                {
                    Id = 0, Name = name, Category = category, Type = type
                }
            }
            ;
            return(entity);
        }
Пример #2
0
        private static DA.Value ToEntity(DT.Value source, DA.Run run, DA.ValueNameCategory category, DA.OKBDataContext okb, List <DA.BinaryData> binCache)
        {
            if (source == null)
            {
                return(null);
            }
            var entity = new DA.Value();

            entity.Run      = run;
            entity.DataType = Convert.ToEntity(source.DataType, okb);
            if (source is DT.BoolValue)
            {
                entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Bool, okb);
                entity.BoolValue = ((DT.BoolValue)source).Value;
            }
            else if (source is DT.IntValue)
            {
                entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Int, okb);
                entity.IntValue  = ((DT.IntValue)source).Value;
            }
            else if (source is DT.TimeSpanValue)
            {
                entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.TimeSpan, okb);
                entity.LongValue = ((DT.TimeSpanValue)source).Value;
            }
            else if (source is DT.LongValue)
            {
                entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Long, okb);
                entity.LongValue = ((DT.LongValue)source).Value;
            }
            else if (source is DT.FloatValue)
            {
                entity.ValueName  = Convert.ToEntity(source.Name, category, DA.ValueNameType.Float, okb);
                entity.FloatValue = ((DT.FloatValue)source).Value;
            }
            else if (source is DT.DoubleValue)
            {
                entity.ValueName   = Convert.ToEntity(source.Name, category, DA.ValueNameType.Double, okb);
                entity.DoubleValue = ((DT.DoubleValue)source).Value;
            }
            else if (source is DT.PercentValue)
            {
                entity.ValueName   = Convert.ToEntity(source.Name, category, DA.ValueNameType.Percent, okb);
                entity.DoubleValue = ((DT.PercentValue)source).Value;
            }
            else if (source is DT.StringValue)
            {
                entity.ValueName   = Convert.ToEntity(source.Name, category, DA.ValueNameType.String, okb);
                entity.StringValue = ((DT.StringValue)source).Value;
            }
            else if (source is DT.BinaryValue)
            {
                entity.ValueName  = Convert.ToEntity(source.Name, category, DA.ValueNameType.Binary, okb);
                entity.BinaryData = Convert.ToEntity(((DT.BinaryValue)source).Value, okb, binCache);
            }
            else
            {
                throw new ArgumentException("Unknown value type.", "source");
            }
            return(entity);
        }