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); }
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 })); }
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); }
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) { } }
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); }
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) { } }
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); } }
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); } }
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 } }
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 }); }