示例#1
0
        public static Type GetEntityType(string model, string entityMode = "Entity")
        {
            DbContext currentDb = SysContext.GetCurrentDb();
            Assembly  assembly  = GetModelAssembly();
            Type      type      = assembly.GetType("FastDev.Model." + entityMode + "." + model);

            if (type == null)
            {
                type = (from a in assembly.GetTypes()
                        where a.Name.ToLower() == model.ToLower() && a.FullName.ToLower().Contains(entityMode + ".")
                        select a).FirstOrDefault();
            }
            if (type == null)
            {
                Assembly assemblyCore = GetCoreAssembly();
                if (assemblyCore != null)
                {
                    type = assemblyCore.GetType("FastDev.Model.Core." + entityMode + "." + model);
                    if (type == null)
                    {
                        type = (from a in assemblyCore.GetTypes()
                                where a.Name.ToLower() == model.ToLower() && a.FullName.ToLower().Contains(entityMode + ".")
                                select a).FirstOrDefault();
                    }
                }
            }
            return(type);
        }
示例#2
0
        public static string GetSettingValue(string key)
        {
            DbContext currentDb = SysContext.GetCurrentDb();

            return(currentDb.ExecuteScalar <string>("select settingvalue from core_setting where settingkey = @0", new object[1]
            {
                key
            }));
        }
示例#3
0
        static WanJiangAuth()
        {
            ServiceConfig serviceConfig = GetServiceConfig(WANGJIANG_USER_TABLE);

            if (serviceConfig != null && !string.IsNullOrEmpty(serviceConfig.model.dbName))
            {
                //根据数据库连接名称,查询数据,获取连接字符串,生成链接
                dbWanJiang = SysContext.GetOtherDB(serviceConfig.model.dbName);
            }
        }
示例#4
0
        public static bool IsEnabledWorkflow(string model)
        {
            DbContext newDb = SysContext.GetRunDb();

            return(newDb.Exists <core_workflow>("where ModelName = @0 and Enabled = @1", new object[2]
            {
                model,
                1
            }));
        }
示例#5
0
        private static FastDev.DevDB.Model.Config.Model GetModelByName(string modelName)
        {
            DbContext  currentDb  = SysContext.GetCurrentDb();
            core_model core_model = currentDb.FirstOrDefault <core_model>("where ModelName = @0", new object[1]
            {
                modelName
            });

            if (core_model == null)
            {
                return(null);
            }
            core_module core_module = null;

            if (!string.IsNullOrEmpty(core_model.ModuleID))
            {
                core_module = currentDb.FirstOrDefault <core_module>("where ID = @0", new object[1]
                {
                    core_model.ModuleID
                });
            }
            string          textField       = "ID";
            core_modelField core_modelField = currentDb.FirstOrDefault <core_modelField>("where IsTextField = 1 and FieldType = @0", new object[1]
            {
                "string"
            });

            if (core_modelField != null)
            {
                textField = core_modelField.FieldName;
            }
            else
            {
                core_modelField = currentDb.FirstOrDefault <core_modelField>("where FieldType = @0", new object[1]
                {
                    "string"
                });
                if (core_modelField != null)
                {
                    textField = core_modelField.FieldName;
                }
            }
            FastDev.DevDB.Model.Config.Model model = new FastDev.DevDB.Model.Config.Model();
            model.name      = core_model.ModelName;
            model.title     = core_model.ModelTitle;
            model.textField = textField;
            if (core_module != null)
            {
                model.moduleName  = core_module.ModuleName;
                model.moduleTitle = core_module.ModuleTitle;
            }
            return(model);
        }
示例#6
0
 public static void LoadSystemVariable(Dictionary <string, object> userdata)
 {
     try
     {
         DbContext            currentDb = SysContext.GetCurrentDb();
         List <core_variable> list      = currentDb.Fetch <core_variable>("", new object[0]);
         foreach (core_variable item in list)
         {
             if (!string.IsNullOrEmpty(item.VariableName))
             {
                 if (!string.IsNullOrEmpty(item.VariableValue))
                 {
                     userdata[item.VariableName] = item.VariableValue;
                 }
                 else if (!string.IsNullOrEmpty(item.VariableExpression))
                 {
                     try
                     {
                         if (item.VariableExpression.Contains("@0"))
                         {
                             string value = currentDb.ExecuteScalar <string>(item.VariableExpression, new object[1]
                             {
                                 SysContext.WanJiangUserID
                             });
                             userdata[item.VariableName] = value;
                         }
                         else
                         {
                             if (item.VariableExpression.Contains("select"))
                             {
                                 string value = currentDb.ExecuteScalar <string>(item.VariableExpression, new object[0]);
                                 userdata[item.VariableName] = value;
                             }
                             else
                             {
                                 //typeof(object).GetField("").GetValue(userinfo);
                                 //这里应该通过反射获取用户类
                                 userdata[item.VariableName] = SysContext.WanJiangUserID;
                             }
                         }
                     }
                     catch (Exception)
                     {
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }
示例#7
0
        public static object GetUserData(string model, string viewname, string context)
        {
            DbContext newDb = SysContext.GetCurrentDb();// SysContext.GetRunDb();
            Dictionary <string, object> dictionary = new Dictionary <string, object>();
            IService service = GetService(model);

            if (service != null)
            {
                dictionary = service.GetViewContext(viewname, context);
            }
            if (dictionary == null)
            {
                dictionary = new Dictionary <string, object>();
            }
            RightsServer rightsServer = new RightsServer(newDb);

            dictionary["rights"] = rightsServer.GetRunTime(model);
            try
            {
                var wanJianUser = SysContext.GetWanJiangUser();
                dictionary["CurrentUserID"]        = wanJianUser.UserId;
                dictionary["CurrentUserLoginName"] = wanJianUser.AccountId;
                dictionary["CurrentUserRealName"]  = wanJianUser.UserName;
                dictionary["CurrentDepartmentID"]  = WanJiangAuth.GetCurrentDepartmentId(SysContext.WanJiangUserID);
                //dictionary["CurrentDepartmentID"] = newDb.ExecuteScalar<string>("select DepartmentID from core_user where id = @0", new object[1]
                //{
                //    SysContext.WanJiangUserID
                //});
                dictionary["CurrentCompanyID"] = WanJiangAuth.GetCurrentCompanyId(SysContext.WanJiangUserID);
                //dictionary["CurrentCompanyID"] = newDb.ExecuteScalar<string>("select CompanyID from res_department where ID=@0", new object[1]
                //{
                //    dictionary["CurrentDepartmentID"]
                //});
            }
            catch
            {
            }
            LoadSystemVariable(dictionary);
            return(dictionary);
        }
示例#8
0
 public static void Log(Exception error)
 {
     try
     {
         DbContext currentDb = SysContext.GetCurrentDb();
         core_log  core_log  = new core_log();
         core_log.CreateDate   = DateTime.Now;
         core_log.CreateUserID = SysContext.WanJiangUserID;
         core_log.ID           = ObEx.ToStr((object)Guid.NewGuid());
         core_log.Logtime      = DateTime.Now;
         core_log.Title        = "系统异常";
         core_log.Logcontent   = error.Message;
         core_log.Logtype      = "exception";
         core_log.StackTrace   = error.StackTrace;
         core_log.Systempath   = HttpContext.Current.Request.Path.ToString();
         core_log.UserID       = SysContext.WanJiangUserID;
         currentDb.Insert("core_log", "ID", false, (object)core_log);
     }
     catch (Exception)
     {
     }
 }
示例#9
0
 public static void Log(string title, string content)
 {
     try
     {
         DbContext currentDb = SysContext.GetCurrentDb();
         core_log  core_log  = new core_log();
         core_log.CreateDate   = DateTime.Now;
         core_log.CreateUserID = SysContext.WanJiangUserID;
         core_log.ID           = ObEx.ToStr((object)Guid.NewGuid());
         core_log.Logtime      = DateTime.Now;
         core_log.Title        = title;
         core_log.Logcontent   = content;
         core_log.Logtype      = "user";
         core_log.Systempath   = HttpContext.Current.Request.Path.ToString();
         core_log.UserID       = SysContext.WanJiangUserID;
         currentDb.Insert("core_log", "ID", false, (object)core_log);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
示例#10
0
        public static string GetModeEntityText(DbContext db, string model, string id)
        {
            string dbName = ServiceHelper.GetServiceConfig(model)?.model.dbName;

            if (!string.IsNullOrEmpty(dbName))
            {
                db = SysContext.GetOtherDB(dbName);
            }
            string key = model + "_" + id;

            if (dicValues.ContainsKey(key))
            {
                return(dicValues[key]);
            }
            string modeTextField = GetModeTextField(model);

            dicValues[key] = db.ExecuteScalar <string>(string.Format("select {0} from {1} where ID = @0", modeTextField, model), new object[1]
            {
                id
            });
            return(dicValues[key]);
        }
示例#11
0
 public static object GetTreeData(DbContext db, FilterTree tree)
 {
     if (!string.IsNullOrEmpty(tree.sourceModel))
     {
         if (tree.sourceModel2 == tree.sourceModel)
         {
             tree.sourceModel2 = null;
         }
         ServiceConfig serviceConfig = ServiceHelper.GetServiceConfig(tree.sourceModel);
         string        textField     = tree.textField;
         if (string.IsNullOrEmpty(textField))
         {
             textField = serviceConfig.model.textField;
         }
         //lyl update at 2018-12-28
         DbContext db2find = db;
         if (!string.IsNullOrEmpty(serviceConfig.model.dbName))
         {
             db2find = SysContext.GetOtherDB(serviceConfig.model.dbName);
         }
         List <Dictionary <string, object> > dic = GetAllProperty(db2find, tree.filter, tree.sourceModel, tree.parentField, "ID", textField, tree.fields, tree.orderBy);
         IList list = FillTreeChild(db2find, dic, "ID", textField, tree.parentField, null, tree.sourceModel, tree);
         if (!string.IsNullOrEmpty(tree.rootText))
         {
             return(new object[1]
             {
                 new
                 {
                     text = tree.rootText,
                     rootNode = true,
                     children = list
                 }
             });
         }
         return(list);
     }
     return(null);
 }
示例#12
0
 public static ModelsConfig GetModelsConfig()
 {
     if (SysContext.IsDev)
     {
         DbContext     currentDb    = SysContext.GetCurrentDb();
         List <string> list         = currentDb.Fetch <string>("select ModelName from core_model", new object[0]);
         ModelsConfig  modelsConfig = new ModelsConfig();
         foreach (string item in list)
         {
             modelsConfig.models.Add(GetModelByName(item));
         }
         return(modelsConfig);
     }
     else
     {
         string modelsPath = new HttpServerUtility(HttpContext.Current).MapPath("~/Service/models.xml");
         if (EnabledCache)
         {
             ModelsConfig modelsConfig = CacheHelper.GetCache("models.xml") as ModelsConfig;
             if (modelsConfig != null)
             {
                 return(modelsConfig);
             }
         }
         if (!File.Exists(modelsPath))
         {
             return(null);
         }
         string       modelsContent = File.ReadAllText(modelsPath);
         ModelsConfig modelsConfig2 = XmlHelper.XmlDeserialize <ModelsConfig>(modelsContent, Encoding.UTF8);
         if (EnabledCache)
         {
             CacheHelper.SetCache("models.xml", (object)modelsConfig2, new CacheDependency(modelsPath));
         }
         return(modelsConfig2);
     }
 }
示例#13
0
        public string TranslateRule(FilterRule rule)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (rule == null)
            {
                return(" 1=1 ");
            }
            if (rule.op == "equal" && (rule.value == null || string.IsNullOrEmpty(rule.value.ToStr()) || rule.value.ToStr().StartsWith("text:")))
            {
                return(" 1=1 ");
            }
            if (rule.type == "sql")
            {
                string text = rule.field.ToStr();
                if (text.Contains("{0}"))
                {
                    return(string.Format(text, paramPrefixToken + AddRuleParms(rule.value, rule.type)));
                }
                return(text);
            }
            if (rule.value.ToStr() == "{CurrentUserID}")
            {
                rule.value = SysContext.WanJiangUserID;
            }
            else if (new Regex("^{\\w+}$", RegexOptions.IgnoreCase).IsMatch(rule.value.ToStr()))
            {
                string key = rule.value.ToStr().Substring(1, rule.value.ToStr().Length - 2);
                rule.value = SysContext.GetVariableValue(key);
            }
            stringBuilder.Append(leftToken + rule.field + rightToken);
            if (rule.op == null)
            {
                rule.op = "equal";
            }
            stringBuilder.Append(GetOperatorQueryText(rule.op));
            string a = rule.op.ToLower();

            if (a == "contains")
            {
                a = "like";
            }
            if (a == "like" || a == "endwith" || a == "notlike" || a == "notendwith")
            {
                string text2 = rule.value.ToString();
                if (!text2.StartsWith(likeToken.ToString()))
                {
                    text2      = DoWithSens(text2);
                    rule.value = likeToken + text2;
                }
            }
            if (a == "like" || a == "startwith" || a == "notlike" || a == "notstartwith")
            {
                string text2 = rule.value.ToString();
                if (!text2.EndsWith(likeToken.ToString()))
                {
                    text2      = DoWithSens(text2);
                    rule.value = text2 + likeToken;
                }
            }
            if (a == "in" || a == "notin")
            {
                string[] array = rule.value.ToString().Split(';');
                bool     flag  = false;
                stringBuilder.Append("(");
                string[] array2 = array;
                foreach (string text2 in array2)
                {
                    if (flag)
                    {
                        stringBuilder.Append(",");
                    }
                    stringBuilder.Append(paramPrefixToken + AddRuleParms(text2, rule.type));
                    flag = true;
                }
                stringBuilder.Append(")");
            }
            else if (a != "isnull" && a != "isnotnull")
            {
                stringBuilder.Append(paramPrefixToken + AddRuleParms(rule.value, rule.type));
            }
            return(stringBuilder.ToString());
        }
示例#14
0
        public static ServiceConfig GetServiceConfig(string model)
        {
            if (SysContext.IsDev)
            {
                #region 如果是开发过程
                DbContext  currentDb  = SysContext.GetCurrentDb();
                core_model core_model = currentDb.FirstOrDefault <core_model>("where ModelName = @0", new object[1]
                {
                    model
                });
                if (core_model == null)
                {
                    return(null);
                }
                List <core_modelField> list        = GetModelFieldsByModelId(currentDb, core_model.ID);
                core_module            core_module = null;
                if (!string.IsNullOrEmpty(core_model.ModuleID))
                {
                    core_module = currentDb.FirstOrDefault <core_module>("where ID = @0", new object[1]
                    {
                        core_model.ModuleID
                    });
                }
                string          textField       = "ID";
                core_modelField core_modelField = list.Where(f => f.IsTextField == 1).FirstOrDefault();
                if (core_modelField != null)
                {
                    textField = core_modelField.FieldName;
                }
                else
                {
                    core_modelField = list.Where(f => f.FieldType == "string").FirstOrDefault();
                    if (core_modelField != null)
                    {
                        textField = core_modelField.FieldName;
                    }
                }
                ServiceConfig serviceConfig = new ServiceConfig();
                List <string> lstMany2One   = new List <string>();
                List <string> lstMany2Many  = new List <string>();
                List <string> lstOne2Many   = new List <string>();
                serviceConfig.model.name      = core_model.ModelName;
                serviceConfig.model.title     = core_model.ModelTitle;
                serviceConfig.model.textField = textField;
                if (((int?)core_model.NotIncludeSysFields).HasValue && core_model.NotIncludeSysFields.Value == 1)
                {
                    serviceConfig.model.notIncludeSysFields = "Y";
                }
                try
                {
                    serviceConfig.model.dbName = currentDb.ExecuteScalar <string>("select DbName from core_model where ModelName = @0", new object[1]
                    {
                        model
                    });
                }
                catch
                {
                }
                if (core_module != null)
                {
                    serviceConfig.model.moduleName  = core_module.ModuleName;
                    serviceConfig.model.moduleTitle = core_module.ModuleTitle;
                }
                foreach (core_modelField item in list)
                {
                    Field field = new Field();
                    field.name   = item.FieldName;
                    field.title  = item.FieldTitle;
                    field.type   = item.FieldType;
                    field.dbName = item.DbName;
                    try
                    {
                        if (currentDb.ExecuteScalar <string>("select IsPK from core_modelField where id = @0", new object[1]
                        {
                            item.ID
                        }) == "1")
                        {
                            field.isPK = "Y";
                        }
                        else
                        {
                            field.isPK = "N";
                        }
                    }
                    catch
                    {
                    }
                    if (item.FieldLength.HasValue)
                    {
                        field.length = item.FieldLength.Value.ToStr();
                    }
                    field.relationField = item.RelationField;
                    field.relationModel = item.RelationModel;
                    serviceConfig.fields.Add(field);
                    if (item.IsFormField != 1)
                    {
                        if (item.FieldType == "many2one")
                        {
                            lstMany2One.Add(item.FieldName);
                        }
                        if (item.FieldType == "many2many")
                        {
                            lstMany2Many.Add(item.FieldName);
                        }
                        if (item.FieldType == "one2many")
                        {
                            lstOne2Many.Add(item.FieldName);
                        }
                    }
                    if (item.IsSearchField == 1)
                    {
                        field.enabledSearch = "Y";
                    }
                }
                serviceConfig.getlist.many2one       = string.Join(",", lstMany2One);
                serviceConfig.getlist.many2many      = string.Join(",", lstMany2Many);
                serviceConfig.getlist.one2many       = string.Join(",", lstOne2Many);
                serviceConfig.getpageddata.many2one  = string.Join(",", lstMany2One);
                serviceConfig.getpageddata.many2many = string.Join(",", lstMany2Many);
                serviceConfig.getpageddata.one2many  = string.Join(",", lstOne2Many);
                return(serviceConfig);

                #endregion
            }
            else
            {
                #region 如果是运行端
                string serviceFileName = new HttpServerUtility(HttpContext.Current).MapPath(string.Format("~/Service/{0}/service.xml", model));
                if (EnabledCache)
                {
                    ServiceConfig serviceConfig = CacheHelper.GetCache("service." + model) as ServiceConfig;
                    if (serviceConfig != null)
                    {
                        return(serviceConfig);
                    }
                }
                if (!File.Exists(serviceFileName))
                {
                    ModelsConfig modelsConfig = GetModelsConfig();
                    string       text2        = null;
                    if (modelsConfig != null && modelsConfig.models != null)
                    {
                        text2 = (from a in modelsConfig.models
                                 where string.Compare(a.name, model, true) == 0
                                 select a).Select(m => m.moduleName).FirstOrDefault();
                    }
                    if (string.IsNullOrEmpty(text2))
                    {
                        text2 = "others";
                    }
                    serviceFileName = new HttpServerUtility(HttpContext.Current).MapPath(string.Format("~/Service/{0}/service.xml", model));
                    if (!File.Exists(serviceFileName))
                    {
                        serviceFileName = new HttpServerUtility(HttpContext.Current).MapPath(string.Format("~/Service/{0}/{1}/service.xml", text2, model));
                    }
                    if (!File.Exists(serviceFileName))
                    {
                        return(null);
                    }
                }
                string        text3 = File.ReadAllText(serviceFileName);
                ServiceConfig rev   = XmlHelper.XmlDeserialize <ServiceConfig>(text3, Encoding.UTF8);
                if (EnabledCache)
                {
                    CacheHelper.SetCache("service." + model, (object)rev, new CacheDependency(serviceFileName));
                }
                return(rev);

                #endregion
            }
        }
示例#15
0
        public static object GetSearchDataset(string model, string key)
        {
            if (string.IsNullOrEmpty(model))
            {
                return(null);
            }
            DbContext     currentDb                = SysContext.GetCurrentDb();
            ServiceConfig serviceConfig            = GetServiceConfig(model);
            List <object> list                     = new List <object>();
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            dictionary["model"] = new
            {
                serviceConfig.model.name,
                serviceConfig.model.title
            };
            List <object> list2 = new List <object>();
            List <Field>  list3 = serviceConfig.fields.Where(f => f.enabledSearch == "Y").ToList();

            foreach (Field item in list3)
            {
                if (string.IsNullOrEmpty(item.relationModel))
                {
                    list.Add(new
                    {
                        field = item.name,
                        text  = "搜索 " + item.title + ":" + key
                    });
                    list2.Add(new
                    {
                        item.name,
                        item.title,
                        item.type
                    });
                }
                else if (item.type == "many2one")
                {
                    ServiceConfig serviceConfig2 = GetServiceConfig(item.relationModel);

                    if (serviceConfig2 != null)
                    {
                        var    qDB       = string.IsNullOrEmpty(serviceConfig2.model.dbName) ? currentDb : SysContext.GetOtherDB(serviceConfig2.model.dbName);
                        string title     = serviceConfig2.model.title;
                        string textField = serviceConfig2.model.textField;
                        if (textField != null)
                        {
                            string nvSql = string.Format("select ID as 'Value',{0} as 'Text' from {1} where {0} like '%{2}%'", textField, item.relationModel, key);
                            if (string.IsNullOrEmpty(key))
                            {
                                nvSql = string.Format("select ID as 'Value',{0} as 'Text' from {1} where {0}", textField, item.relationModel);
                            }
                            List <SearchResultItem> list4 = qDB.Query <SearchResultItem>(nvSql, new object[0]).ToList();
                            if (list4 != null && list4.Any())
                            {
                                list.Add(new
                                {
                                    text        = title,
                                    isGroupItem = true
                                });
                                foreach (SearchResultItem item2 in list4)
                                {
                                    list.Add(new
                                    {
                                        id             = item2.Value,
                                        field          = item.name,
                                        isRelationItem = true,
                                        text           = item2.Text
                                    });
                                }
                                list2.Add(new
                                {
                                    item.name,
                                    item.title,
                                    item.type
                                });
                            }
                        }
                    }
                }
            }
            dictionary["fields"] = list2;
            return(new
            {
                dataset = dictionary,
                result = list
            });
        }
示例#16
0
        private static Dictionary <string, string> dicValues; //存在字段值

        /// <summary>
        /// FastDev Model 动态生成
        /// </summary>
        /// <returns></returns>
        private static Assembly GetModelAssembly()
        {
            return(SysContext.GetModelAssembly());
        }