コード例 #1
0
        // 从json字符串中转换出需要的数据
        private List <SpecDataDto> ReadValueFromJsonStr(string jsonStr)
        {
            JToken             specToken    = JToken.Parse(jsonStr);
            List <SpecDataDto> specDataList = new List <SpecDataDto>();

            foreach (var specItem in specToken)
            {
                SpecDataDto       specData = new SpecDataDto();
                List <EleDataDto> eleList  = new List <EleDataDto>();

                var    tempSpec = (Newtonsoft.Json.Linq.JProperty)specItem;
                int    specId   = int.Parse(tempSpec.Name.Substring(3));
                var    eleToken = JToken.Parse(tempSpec.Value.ToString());
                int    i        = 0;
                string signId   = string.Empty;
                string typeId   = string.Empty;
                foreach (var eleItem in eleToken)
                {
                    var tempEle = (JProperty)eleItem;
                    if (i == 0) //签到Id
                    {
                        signId = tempEle.Value.ToString();
                    }
                    else if (i == 1) // 原表Id-typeIn表id
                    {
                        typeId = tempEle.Value.ToString();
                    }
                    else if (i >= 2) // 元素
                    {
                        dynamic    eleData = JToken.Parse(tempEle.Value.ToString());
                        EleDataDto eleObj  = new EleDataDto();


                        // 如果元素值不为空 或者 元素的原Id不为空,则将数据置入数组
                        // 当元素原Id不为空时,代表,数据可能是更新,不管将元素是否有值,因为可能需要将有值的元素更新为无值
                        if (!string.IsNullOrEmpty((string)eleData.eleValue) || !string.IsNullOrEmpty((string)eleData.typeEleId))
                        {
                            int eleId = int.Parse(tempEle.Name.Substring(3));
                            eleObj.SpecId = specId;
                            eleObj.EleId  = eleId;

                            eleObj.OldId      = eleData.TypeEleId;
                            eleObj.EleValue   = eleData.eleValue;
                            eleObj.OperatorId = eleData.operId;
                            eleObj.EleName    = eleData.eleName;

                            eleList.Add(eleObj);
                        }
                    }
                    i++;
                }
                specData.OldId       = typeId;
                specData.SpecId      = specId;
                specData.SignId      = signId;
                specData.EleDataList = eleList;
                specDataList.Add(specData);
            }

            return(specDataList);
        }
コード例 #2
0
        private void UpdateSingleElement(EleDataDto item)
        {
            var tempFindItem = _typeInItemRep.Single(x => x.Id == int.Parse(item.OldId));

            tempFindItem.EleValue   = item.EleValue;
            tempFindItem.OperatorId = item.OperatorId;
            _typeInItemRep.UpdateAsync(tempFindItem);
        }