예제 #1
0
        private string GetEnumString(string connName, string tableName, string fieldCode, string data)
        {
            bool fromMeta = false;

            if (data.StartsWith("[") == false)
            {
                var arr = data.Split(',');
                if (arr.Length == 3) //如果data为ConnName,tableName,fieldCode时
                {
                    connName  = arr[0];
                    tableName = arr[1];
                    fieldCode = arr[2];
                    fromMeta  = true;
                }
                else if (arr.Length == 2)//如果data为tableName,fieldCode时
                {
                    tableName = arr[0];
                    fieldCode = arr[1];
                    fromMeta  = true;
                }
            }

            string result = "";

            if (data.StartsWith("["))
            {
                result = data;
            }
            else if (data == "" || data == "FromMeta" || fromMeta == true)
            {
                var entities = FormulaHelper.GetEntities <BaseEntities>();
                var field    = entities.Set <S_M_Field>().FirstOrDefault(c => c.Code == fieldCode && c.S_M_Table.Code == tableName && c.S_M_Table.ConnName == connName);
                if (field == null || string.IsNullOrEmpty(field.EnumKey))
                {
                    result = string.Format("var enum_{0}_{1} = {2};", tableName, fieldCode, "[]");
                }
                else if (field.EnumKey.Trim().StartsWith("["))
                {
                    result = field.EnumKey;
                }
                else
                {
                    IEnumService enumService = FormulaHelper.GetService <IEnumService>();
                    try
                    {
                        result = JsonHelper.ToJson(enumService.GetEnumTable(field.EnumKey));
                    }
                    catch (Exception) { }
                }
            }
            else
            {
                IEnumService enumService = FormulaHelper.GetService <IEnumService>();
                try
                {
                    result = JsonHelper.ToJson(enumService.GetEnumTable(data));
                }
                catch (Exception) { }
            }

            return(result);
        }
예제 #2
0
        private string GetEnumString(string connName, string tableName, string fieldCode, string data)
        {
            bool fromMeta = false;

            if (data.StartsWith("[") == false)
            {
                var arr = data.Split(',');
                if (arr.Length == 3) //如果data为ConnName,tableName,fieldCode时
                {
                    connName  = arr[0];
                    tableName = arr[1];
                    fieldCode = arr[2];
                    fromMeta  = true;
                }
                else if (arr.Length == 2)//如果data为tableName,fieldCode时
                {
                    tableName = arr[0];
                    fieldCode = arr[1];
                    fromMeta  = true;
                }
            }

            string result = "";

            if (data.StartsWith("["))
            {
                var LGID = FormulaHelper.GetCurrentLGID();
                if (!string.IsNullOrEmpty(LGID))
                {
                    var enums = JsonHelper.ToObject <List <Dictionary <string, object> > >(data);
                    if (enums.Count > 0 && enums.Where(c => c.Keys.Contains("textEN")).Count() > 0)
                    {
                        foreach (var item in enums)
                        {
                            var text = item.GetValue("textEN");
                            item.SetValue("text", text);
                            item.Remove("textEN");
                        }
                        result = JsonHelper.ToJson(enums);
                    }
                    else
                    {
                        result = data;
                    }
                }
                else
                {
                    result = data;
                }
            }
            else if (data == "" || data == "FromMeta" || fromMeta == true)
            {
                var entities = FormulaHelper.GetEntities <BaseEntities>();
                var field    = entities.Set <S_M_Field>().FirstOrDefault(c => c.Code == fieldCode && c.S_M_Table.Code == tableName && c.S_M_Table.ConnName == connName);
                if (field == null || string.IsNullOrEmpty(field.EnumKey))
                {
                    result = string.Format("var enum_{0}_{1} = {2};", tableName, fieldCode, "[]");
                }
                else if (field.EnumKey.Trim().StartsWith("["))
                {
                    result = field.EnumKey;
                }
                else
                {
                    IEnumService enumService = FormulaHelper.GetService <IEnumService>();
                    try
                    {
                        result = JsonHelper.ToJson(enumService.GetEnumTable(field.EnumKey));
                    }
                    catch (Exception) { }
                }
            }
            else
            {
                IEnumService enumService = FormulaHelper.GetService <IEnumService>();
                try
                {
                    result = JsonHelper.ToJson(enumService.GetEnumTable(data));
                }
                catch (Exception) { }
            }

            return(result);
        }