Пример #1
0
        private static List <KeyValuePair <WhereType, IConditionalModel> > GetConditionalList(JToken item)
        {
            List <KeyValuePair <WhereType, IConditionalModel> > result = new List <KeyValuePair <WhereType, IConditionalModel> >();
            var values = item.Values().First();

            foreach (var jToken in values)
            {
                WhereType         type             = (WhereType)Convert.ToInt32(jToken["Key"].Value <int>());
                IConditionalModel conditionalModel = null;
                var value = jToken["Value"];
                if (value.ToString().Contains("ConditionalList"))
                {
                    conditionalModel = new ConditionalTree()
                    {
                        ConditionalList = GetConditionalList(value)
                    };
                }
                else
                {
                    conditionalModel = new ConditionalModel()
                    {
                        ConditionalType = (ConditionalType)Convert.ToInt32(value["ConditionalType"].Value <int>()),
                        FieldName       = value["FieldName"] + "",
                        FieldValue      = value["FieldValue"].Value <string>() == null ? null : value["FieldValue"].ToString()
                    };
                }
                result.Add(new KeyValuePair <WhereType, IConditionalModel>(type, conditionalModel));
            }
            return(result);
        }
Пример #2
0
        public List <IConditionalModel> JsonToConditionalModels(string json)
        {
            List <IConditionalModel> conditionalModels = new List <IConditionalModel>();
            var jarray = this.Context.Utilities.DeserializeObject <JArray>(json);

            foreach (var item in jarray)
            {
                if (item.Count() > 0)
                {
                    if (item.ToString().Contains("ConditionalList"))
                    {
                        IConditionalModel model = new ConditionalTree()
                        {
                            ConditionalList = GetConditionalList(item)
                        };
                        conditionalModels.Add(model);
                    }
                    else
                    {
                        IConditionalModel conditionalModel = new ConditionalModel()
                        {
                            ConditionalType = (ConditionalType)Convert.ToInt32(item["ConditionalType"].Value <int>()),
                            FieldName       = item["FieldName"] + "",
                            FieldValue      = item["FieldValue"].Value <string>() == null?null: item["FieldValue"].ToString()
                        };
                        conditionalModels.Add(conditionalModel);
                    }
                }
            }
            return(conditionalModels);
        }
Пример #3
0
 private static object GetFieldValue(ConditionalModel item)
 {
     if (item.FieldValueConvertFunc != null)
     {
         return(item.FieldValueConvertFunc(item.FieldValue));
     }
     else
     {
         return(item.FieldValue);
     }
 }
Пример #4
0
 private static object GetFieldValue(ConditionalModel item)
 {
     if (item.FieldValueConvertFunc != null)
     {
         return(item.FieldValueConvertFunc(item.FieldValue));
     }
     else if (item.CSharpTypeName.HasValue())
     {
         return(UtilMethods.ConvertDataByTypeName(item.CSharpTypeName, item.FieldValue));
     }
     else
     {
         return(item.FieldValue);
     }
 }
Пример #5
0
        private ConditionalCollections ToConditionalCollections(ConditionalTree item, ref int indexTree, List <SugarParameter> parameters)
        {
            List <KeyValuePair <WhereType, ConditionalModel> > list = new List <KeyValuePair <WhereType, ConditionalModel> >();
            var index = 0;

            foreach (var it in item.ConditionalList)
            {
                ConditionalModel model = new ConditionalModel();
                if (it.Value is ConditionalModel)
                {
                    model = (ConditionalModel)it.Value;
                }
                else
                {
                    var tree   = it.Value as ConditionalTree;
                    var con    = ToConditionalCollections(tree, ref indexTree, parameters);
                    var sqlobj = ConditionalModelToSql(new List <IConditionalModel> {
                        con
                    }, index);
                    var sql = sqlobj.Key;
                    if (sql.StartsWith(" NULL "))
                    {
                        sql = Regex.Replace(sql, "^ NULL ", it.Key.ToString().ToUpper());
                    }
                    RepairReplicationParameters(ref sql, sqlobj.Value, indexTree);
                    model = new ConditionalModel()
                    {
                        FieldName  = $"[value=sql{UtilConstants.ReplaceKey}]",
                        FieldValue = sql
                    };
                    parameters.AddRange(sqlobj.Value);
                    indexTree++;
                }
                list.Add(new KeyValuePair <WhereType, ConditionalModel>(it.Key, model));
                index++;
            }
            var result = new ConditionalCollections()
            {
                ConditionalList = list
            };

            return(result);
        }
Пример #6
0
        public static object ConvertDataByTypeName(string ctypename, string value)
        {
            var item = new ConditionalModel()
            {
                CSharpTypeName = ctypename,
                FieldValue     = value
            };

            if (item.CSharpTypeName.EqualCase(UtilConstants.DecType.Name))
            {
                return(Convert.ToDecimal(item.FieldValue));
            }
            else if (item.CSharpTypeName.EqualCase(UtilConstants.DobType.Name))
            {
                return(Convert.ToDouble(item.FieldValue));
            }
            else if (item.CSharpTypeName.EqualCase(UtilConstants.DateType.Name))
            {
                return(Convert.ToDateTime(item.FieldValue));
            }
            else if (item.CSharpTypeName.EqualCase(UtilConstants.IntType.Name))
            {
                return(Convert.ToInt32(item.FieldValue));
            }
            else if (item.CSharpTypeName.EqualCase(UtilConstants.LongType.Name))
            {
                return(Convert.ToInt64(item.FieldValue));
            }
            else if (item.CSharpTypeName.EqualCase(UtilConstants.ShortType.Name))
            {
                return(Convert.ToInt16(item.FieldValue));
            }
            else if (item.CSharpTypeName.EqualCase(UtilConstants.DateTimeOffsetType.Name))
            {
                return(UtilMethods.GetDateTimeOffsetByDateTime(Convert.ToDateTime(item.FieldValue)));
            }
            else
            {
                return(item.FieldValue);
            }
        }
Пример #7
0
        public static bool IsNumber(string ctypename)
        {
            if (ctypename.IsNullOrEmpty())
            {
                return(false);
            }
            var item = new ConditionalModel()
            {
                CSharpTypeName = ctypename,
            };

            if (item.CSharpTypeName.EqualCase(UtilConstants.DecType.Name))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase(UtilConstants.DobType.Name))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase(UtilConstants.IntType.Name))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase(UtilConstants.LongType.Name))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase(UtilConstants.ShortType.Name))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase("int"))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase("long"))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase("short"))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase("byte"))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase("uint"))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase("ulong"))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase("ushort"))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase("uint32"))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase("uint64"))
            {
                return(true);
            }
            else if (item.CSharpTypeName.EqualCase("uint16"))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }