/// <summary> /// 获取任务类型列表 /// </summary> /// <returns></returns> public ActionResult GetJobTypeList() { string jobTypeDll = WebConfigHelper.GetAppSettingValue("QuartzJob"); List <Type> types = Globals.GetAssemblyTypes(jobTypeDll); if (types == null) { types = new List <Type>(); } List <Type> jobTypes = new List <Type>(); foreach (Type tempType in types) { if (tempType.GetInterface("IJob") != null) { jobTypes.Add(tempType); } } List <Type> frameTypes = Globals.GetAssemblyTypes("Rookey.Frame.QuartzClient").Where(x => x.Namespace == "Rookey.Frame.QuartzClient.FrameJob" && x.GetInterface("IJob") != null).ToList(); var frameResult = frameTypes.Select(x => new { id = string.Format("{0},Rookey.Frame.QuartzClient", x.FullName), text = x.FullName }).ToList(); var result = jobTypes.Select(x => new { id = string.Format("{0},{1}", x.FullName, jobTypeDll), text = x.FullName }).ToList(); result.AddRange(frameResult); if (result.Count == 0) { return(Json(null)); } return(Json(result)); }
/// <summary> /// 获取临时实体类型集合 /// </summary> /// <returns></returns> public static List <Type> GetTempModelTypes() { try { string tempModelPath = WebConfigHelper.GetAppSettingValue("TempModelPath"); if (string.IsNullOrEmpty(tempModelPath)) { tempModelPath = "TempModel"; } string dllPath = string.Format(@"{0}{1}", Globals.GetBinPath(), tempModelPath); if (!Directory.Exists(dllPath)) //临时实体dll目录不存在 { return(new List <Type>()); } List <Type> list = new List <Type>(); foreach (string dll in Directory.GetFiles(dllPath, "*.dll")) { //非程序集类型的关联load时会报错 try { var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(dll); list.AddRange(assembly.DefinedTypes.Select(x => x.AsType()).Where(x => x.Namespace == "Rookey.FrameCore.TempModel")); } catch { } } return(list); } catch { } return(new List <Type>()); }
public ActionResult Login() { if (!ToolOperate.IsNeedInit()) //不需要初始化时 { if (WebConfigHelper.GetAppSettingValue("NeedRepairTable") == "true") //需要修复数据表 { string tables = WebConfigHelper.GetAppSettingValue("RepairTables"); //要修复的数据表 List <string> token = new List <string>(); if (!string.IsNullOrEmpty(tables)) { token = tables.Split(",".ToCharArray()).ToList(); } if (token.Count > 0) { ToolOperate.RepairTables(token); } } } else //需要初始化 { return(RedirectToAction("Init", "Page")); } ViewBag.IsShowValidateCode = (Session[LOGINERROR].ObjToInt() >= 2).ToString().ToLower(); return(View()); }
/// <summary> /// 下载附件 /// </summary> /// <param name="attachId">附件Id</param> /// <returns></returns> public ActionResult DownloadAttachment(Guid attachId) { if (_Request == null) { _Request = Request; } string errMsg = string.Empty; Sys_Attachment attachment = CommonOperate.GetEntityById <Sys_Attachment>(attachId, out errMsg); if (attachment != null) { try { string tempFile = string.Format("{0}{1}", Globals.GetWebDir(), attachment.FileUrl.ObjToStr().Replace(Globals.GetBaseUrl(), string.Empty)); if (WebConfigHelper.GetAppSettingValue("IsLinux") != "true") { tempFile = tempFile.Replace("/", "\\"); } string ext = FileOperateHelper.GetFileExt(tempFile); var fs = new System.IO.FileStream(tempFile, FileMode.Open); if (fs != null) { return(File(fs, FileOperateHelper.GetHttpMIMEContentType(ext), Url.Encode(attachment.FileName))); } } catch (Exception ex) { return(Content("<script>alert('异常:" + ex.Message + "');</script>")); } } return(Content("<script>alert('找不到此文件!');</script>")); }
/// <summary> /// 构造函数 /// </summary> private QuartzDataHandler() { if (_scheduler == null) { string quartzServer = WebConfigHelper.GetAppSettingValue("QuartzServer"); if (string.IsNullOrEmpty(quartzServer)) { quartzServer = "tcp://127.0.0.1:7005"; } NameValueCollection properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "RemoteQuartzClient"; properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "5"; properties["quartz.threadPool.threadPriority"] = "Normal"; //远程调度配置 properties["quartz.scheduler.proxy"] = "true"; properties["quartz.scheduler.proxy.address"] = string.Format("{0}/QuartzScheduler", quartzServer); try { ISchedulerFactory schedulerFactory = new StdSchedulerFactory(properties); IScheduler scheduler = schedulerFactory.GetScheduler(); if (scheduler != null) { _scheduler = new DefaultScheduler(scheduler); _scheduler.StartScheduler(); _data = _scheduler.Data; } } catch (Exception ex) { } } }
/// <summary> /// 获取数据模型类型对应的数据层类型 /// </summary> /// <param name="modelType"></param> /// <returns></returns> private static Type GetCustomeDALType(Type modelType) { string dalDll = "Rookey.Frame.DAL"; //默认数据层DLL //取自定义数据层类型 string customerDAL = WebConfigHelper.GetAppSettingValue("DAL"); if (!string.IsNullOrEmpty(customerDAL)) { dalDll += string.Format(",{0}", customerDAL); } List <Type> tempTypes = new List <Type>(); if (!string.IsNullOrEmpty(dalDll)) { string[] token = dalDll.Split(",".ToCharArray()); foreach (string dllName in token) { var assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(dllName)); tempTypes = assembly.DefinedTypes.Select(x => x.AsType()).ToList(); } } List <Type> dalTypeList = new List <Type>(); //过滤 foreach (Type type in tempTypes) { if ((type.IsGenericType && type.Name.Contains("BaseDAL")) || (type.BaseType != null && type.BaseType.Name.Contains("BaseDAL"))) { dalTypeList.Add(type); } } return(dalTypeList.Where(x => x.Name == string.Format("{0}DAL", modelType.Name)).FirstOrDefault()); }
public ActionResult FileUp(HttpPostedFileBase upfile) { if (_Request == null) { _Request = Request; } string path = string.Empty; string fileName = upfile.FileName; string pathFlag = "\\"; if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true") { pathFlag = "/"; } int s = fileName.LastIndexOf(pathFlag); if (s >= 0) { fileName = fileName.Substring(s + 1); } string fileType = Path.GetExtension(upfile.FileName); try { UploadFileManager.httpContext = _Request.RequestContext.HttpContext; path = UploadFile(upfile, "UEFile", "File"); } catch (Exception ex) { return(Json(new { state = ex.Message })); } return(Json(new { state = "SUCCESS", url = path, fileType = fileType, original = fileName })); }
/// <summary> /// 缓存用户Cookie数据 /// </summary> /// <param name="userInfo">用户信息</param> /// <returns></returns> private void CacheUserData(UserInfo userInfo) { //客户端浏览器参数 int w = _Request.QueryEx("w").ObjToInt(); int h = _Request.QueryEx("h").ObjToInt(); if (w > 0) { userInfo.ClientBrowserWidth = w; } if (h > 0) { userInfo.ClientBrowserHeight = h; } //获取客户端IP userInfo.ClientIP = WebHelper.GetClientIP(_Request); //缓存用户扩展信息 UserInfo.CacheUserExtendInfo(userInfo.UserName, userInfo.ExtendUserObject); //用户票据保存 int acount_expire_time = UserInfo.ACCOUNT_EXPIRATION_TIME; acount_expire_time = WebConfigHelper.GetAppSettingValue("ACCOUNT_EXPIRATION_TIME").ObjToInt(); if (acount_expire_time <= 0) { acount_expire_time = UserInfo.ACCOUNT_EXPIRATION_TIME; } FormsPrincipal.Login(userInfo.UserName, userInfo, acount_expire_time, GetHttpContext(_Request)); }
/// <summary> /// 获取所有数据层接口类型 /// </summary> /// <returns></returns> public static List <Type> GetAllDALInterfaceTypes() { List <Type> dalInterfaceTypeList = new List <Type>(); if (cacheFactory != null && cacheFactory.Exists(cache_idalType)) { dalInterfaceTypeList = cacheFactory.Get <List <Type> >(cache_idalType); if (dalInterfaceTypeList == null) { dalInterfaceTypeList = new List <Type>(); } return(dalInterfaceTypeList); } string idalDll = DEFAULT_IDAL_DLL; //默认数据层接口DLL //取自定义数据层接口类型 string customerIDAL = WebConfigHelper.GetAppSettingValue("IDAL"); if (!string.IsNullOrEmpty(customerIDAL)) { idalDll += string.Format(",{0}", customerIDAL); } List <Type> tempTypes = new List <Type>(); if (!string.IsNullOrEmpty(idalDll)) { string[] token = idalDll.Split(",".ToCharArray()); foreach (string dllName in token) { string nameSpace = dllName == DEFAULT_IDAL_DLL ? "Rookey.Frame.IDAL" : null; tempTypes.AddRange(GetTypesByDLL(dllName, nameSpace)); } } //过滤 foreach (Type type in tempTypes) { Type[] types = type.GetInterfaces(); if (type.Name == "IBaseDAL`1") { dalInterfaceTypeList.Add(type); continue; } if (types == null || types.Length == 0) { continue; } List <string> typeNames = types.Select(x => x.Name).ToList(); if (typeNames.Contains("IBaseDAL")) { dalInterfaceTypeList.Add(type); } } if (dalInterfaceTypeList.Count > 0 && cacheFactory != null) { cacheFactory.Set <List <Type> >(cache_idalType, dalInterfaceTypeList); } return(dalInterfaceTypeList); }
/// <summary> /// 获取所有的模块类型集合 /// </summary> /// <returns></returns> public static List <Type> GetAllModelTypes() { List <Type> tempTypes = new List <Type>(); if (cacheFactory != null && cacheFactory.Exists(cache_modelType)) { tempTypes = cacheFactory.Get <List <Type> >(cache_modelType); if (tempTypes == null) { tempTypes = new List <Type>(); } return(tempTypes); } string modelDll = DEFAULT_MODEL_DLL; //默认实体层dll //取自定义数据模型类型 string customerModelBLL = WebConfigHelper.GetAppSettingValue("Model"); if (!string.IsNullOrEmpty(customerModelBLL)) { modelDll += string.Format(",{0}", customerModelBLL); } NotNullCheck.NotEmpty(modelDll, "Web.config->appSettings中实体层程序集名称"); List <Type> types = new List <Type>(); if (!string.IsNullOrEmpty(modelDll)) { string[] token = modelDll.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string dllName in token) { types.AddRange(GetTypesByDLL(dllName)); } } //添加临时实体类型集合 List <Type> tempModelTypes = GetTempModelTypes(); types.AddRange(tempModelTypes); //取模块类型集合 foreach (Type type in types) { ModuleConfigAttribute moduleConfig = ((ModuleConfigAttribute)(Attribute.GetCustomAttribute(type, typeof(ModuleConfigAttribute)))); NoModuleAttribute noModuleAttr = ((NoModuleAttribute)(Attribute.GetCustomAttribute(type, typeof(NoModuleAttribute)))); if (moduleConfig == null && noModuleAttr == null) { continue; } tempTypes.Add(type); } if (tempTypes.Count > 0 && cacheFactory != null) { cacheFactory.Set <List <Type> >(cache_modelType, tempTypes); } return(tempTypes); }
/// <summary> /// 释放分布式锁(基于DB方式) /// </summary> /// <param name="moduleFlag">模块标识,模块表名/类名</param> /// <param name="method_Flag">方法名标识</param> /// <returns></returns> public static string ReleaseDistDbLock(string moduleFlag, string method_Flag) { if (WebConfigHelper.GetAppSettingValue("EnabledDistributeLock") != "true") //未启用分布式锁 { return(string.Empty); } lock (tempObjDistriLock) { string errMsg = string.Empty; CommonOperate.DeleteRecordsByExpression <Other_DistributedLock>(x => x.ModuleFlag == moduleFlag && x.Method_Flag == method_Flag, out errMsg); return(string.Empty); } }
/// <summary> /// 获取重置密码邮件内容 /// </summary> /// <param name="user">用户</param> /// <returns></returns> private string GetForgetPwdSendContent(Sys_User user) { StringBuilder sb = new StringBuilder(); string webServer = WebConfigHelper.GetAppSettingValue("WebServer"); //跳转服务器 string webIndex = WebConfigHelper.GetAppSettingValue("WebIndex"); //跳转首页地址 string webName = WebConfigHelper.GetCurrWebName(); sb.Append("<div style=\"font-size: 13px;padding:40px;background-color: #F7F7F7;font-family:Arial, Helvetica, sans-serif; color:#333;\">"); sb.Append("<div class=\"mailcontentbox\" style=\"min-width: 500px;max-width: 750px;\">"); sb.Append("<div style=\"background-color: gray;\">"); sb.AppendFormat("<a href=\"{0}{1}\" target=\"_blank\">", webServer, webIndex); string logoPath = WebConfigHelper.GetCurrWebLogo(); if (!string.IsNullOrEmpty(logoPath)) { logoPath = logoPath.Substring(1, logoPath.Length - 1); logoPath = webServer + logoPath; } sb.AppendFormat("<img style=\"margin:5px 0px 5px 10px;\" src=\"{0}\" border=\"0\">", logoPath); sb.Append("</a>"); sb.Append("</div>"); sb.Append("<div style=\"border-width:0px 1px 2px 1px;border-style:solid;border-color:#D7D7D7;border-bottom-color:#333;padding:20px;background:#fff;\">"); sb.Append("<p style=\"line-height:20px;padding-bottom:5px;\">"); sb.AppendFormat(" 您好 {0},", string.IsNullOrEmpty(user.AliasName) ? user.UserName : user.AliasName); sb.Append("</p>"); sb.Append("<p style=\"line-height:20px;padding-bottom:5px;\">"); sb.AppendFormat("您发送了重置{0}密码的申请。 </p>", webName); sb.Append("<p style=\"line-height:20px;padding-bottom:5px;\">"); sb.Append("请点击下边的链接进行确认,之后您将可以设置一个新密码。 </p>"); sb.Append("<p style=\"line-height:20px;padding-bottom:5px;\">"); string resetPwdUrl = string.Format("{0}User/ResetPwd.html?uid={1}", webServer, user.Id); sb.AppendFormat(" <a href=\"{0}\" target=\"_blank\" style=\"color:#36C;\">{0}</a>", resetPwdUrl); sb.Append("</p>"); sb.Append("<p style=\"line-height:13px; margin: 40px 0px 10px\">"); sb.AppendFormat("感谢您使用{0} </p>", webName); sb.Append("<p style=\"padding-bottom:5px; padding-top:0px; margin-top:0px\">"); sb.AppendFormat(" {0} Team", webName); sb.Append("</p>"); sb.Append("</div>"); sb.Append("<div style=\"color:#777;padding: 15px;\">"); sb.AppendFormat(" ©{0} {1} Team.", DateTime.Now.Year, webName); sb.Append("</div>"); sb.Append("</div>"); sb.Append("</div>"); return(sb.ToString()); }
/// <summary> /// 获取当前所有业务类型集合 /// </summary> /// <returns></returns> public static List <Type> GetAllBLLTypes() { List <Type> bllTypeList = new List <Type>(); if (cacheFactory != null && cacheFactory.Exists(cache_bllType)) { bllTypeList = cacheFactory.Get <List <Type> >(cache_bllType); if (bllTypeList == null) { bllTypeList = new List <Type>(); } return(bllTypeList); } string bllDll = DEFAULT_BLL_DLL; //默认业务层DLL //取自定义业务层类型 string customerBLL = WebConfigHelper.GetAppSettingValue("BLL"); if (!string.IsNullOrEmpty(customerBLL)) { bllDll += string.Format(",{0}", customerBLL); } List <Type> tempTypes = new List <Type>(); if (!string.IsNullOrEmpty(bllDll)) { string[] token = bllDll.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string dllName in token) { string nameSpace = dllName == DEFAULT_BLL_DLL ? "Rookey.Frame.BLL" : null; tempTypes.AddRange(GetTypesByDLL(dllName, nameSpace)); } } //过滤 foreach (Type type in tempTypes) { if ((type.IsGenericType && type.Name.Contains("BaseBLL")) || (type.BaseType != null && type.BaseType.Name.Contains("BaseBLL"))) { bllTypeList.Add(type); } } if (bllTypeList.Count > 0 && cacheFactory != null) { cacheFactory.Set <List <Type> >(cache_bllType, bllTypeList); } return(bllTypeList); }
/// <summary> /// 获取所有数据层类型 /// </summary> /// <returns></returns> public static List <Type> GetAllDALTypes() { List <Type> dalTypeList = new List <Type>(); if (cacheFactory != null && cacheFactory.Exists(cache_dalType)) { dalTypeList = cacheFactory.Get <List <Type> >(cache_dalType); if (dalTypeList == null) { dalTypeList = new List <Type>(); } return(dalTypeList); } string dalDll = DEFAULT_DAL_DLL; //默认数据层DLL //取自定义数据层类型 string customerDAL = WebConfigHelper.GetAppSettingValue("DAL"); if (!string.IsNullOrEmpty(customerDAL)) { dalDll += string.Format(",{0}", customerDAL); } List <Type> tempTypes = new List <Type>(); if (!string.IsNullOrEmpty(dalDll)) { string[] token = dalDll.Split(",".ToCharArray()); foreach (string dllName in token) { string nameSpace = dllName == DEFAULT_DAL_DLL ? "Rookey.Frame.DAL" : null; tempTypes.AddRange(GetTypesByDLL(dllName, nameSpace)); } } //过滤 foreach (Type type in tempTypes) { if ((type.IsGenericType && type.Name.Contains("BaseDAL")) || (type.BaseType != null && type.BaseType.Name.Contains("BaseDAL"))) { dalTypeList.Add(type); } } if (dalTypeList.Count > 0 && cacheFactory != null) { cacheFactory.Set <List <Type> >(cache_dalType, dalTypeList); } return(dalTypeList); }
/// <summary> /// 获取当前所有业务接口类型集合 /// </summary> /// <returns></returns> public static List <Type> GetAllBLLInterfaceTypes() { List <Type> bllInterfaceTypeList = new List <Type>(); if (cacheFactory != null && cacheFactory.Exists(cache_ibllType)) { bllInterfaceTypeList = cacheFactory.Get <List <Type> >(cache_ibllType); if (bllInterfaceTypeList == null) { bllInterfaceTypeList = new List <Type>(); } return(bllInterfaceTypeList); } string ibllDll = DEFAULT_IBLL_DLL; //默认业务层接口dll //取自定义业务层接口类型 string customerIBLL = WebConfigHelper.GetAppSettingValue("IBLL"); if (!string.IsNullOrEmpty(customerIBLL)) { ibllDll += string.Format(",{0}", customerIBLL); } List <Type> tempTypes = new List <Type>(); if (!string.IsNullOrEmpty(ibllDll)) { string[] token = ibllDll.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string dllName in token) { tempTypes.AddRange(GetTypesByDLL(dllName)); } } //过滤 foreach (Type type in tempTypes) { if (type.IsInterface) { bllInterfaceTypeList.Add(type); } } if (bllInterfaceTypeList.Count > 0 && bllInterfaceTypeList != null) { cacheFactory.Set <List <Type> >(cache_ibllType, bllInterfaceTypeList); } return(bllInterfaceTypeList); }
/// <summary> /// 获取所有的验证模块类型集合 /// </summary> /// <returns></returns> public static List <Type> GetAllFluentValidationModelTypes() { List <Type> tempTypes = new List <Type>(); if (cacheFactory != null && cacheFactory.Exists(cache_modelValidateType)) { tempTypes = cacheFactory.Get <List <Type> >(cache_modelValidateType); if (tempTypes == null) { tempTypes = new List <Type>(); } return(tempTypes); } string modelDll = DEFAULT_MODEL_VALIDATOR_DLL; //默认实体验证层dll //取自定义数据模型类型 string customerModelBLL = WebConfigHelper.GetAppSettingValue("ModelValidator"); if (!string.IsNullOrEmpty(customerModelBLL)) { modelDll += string.Format(",{0}", customerModelBLL); } if (string.IsNullOrEmpty(modelDll)) { return(new List <Type>()); } List <Type> types = new List <Type>(); if (!string.IsNullOrEmpty(modelDll)) { string[] token = modelDll.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string dllName in token) { types.AddRange(GetTypesByDLL(dllName)); } } tempTypes = types.Where(x => x.BaseType.Name.Contains("AbstractValidator")).ToList(); if (tempTypes.Count > 0 && cacheFactory != null) { cacheFactory.Set <List <Type> >(cache_modelValidateType, tempTypes); } return(tempTypes); }
/// <summary> /// 上传员工照片,照片路径/Upload/ /// </summary> /// <returns></returns> public ActionResult UploadEmpPhoto() { Guid id = Request["id"].ObjToGuid(); string filePath = Request["filePath"].ObjToStr(); string errMsg = string.Empty; if (id != Guid.Empty && !string.IsNullOrWhiteSpace(filePath)) { string pathFlag = "\\"; if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true") { pathFlag = "/"; } else { filePath = filePath.Replace("/", "\\"); } if (filePath.StartsWith(pathFlag)) { filePath = filePath.Substring(pathFlag.Length, filePath.Length - pathFlag.Length); } filePath = Globals.GetWebDir() + filePath; string dir = Globals.GetWebDir() + "Upload" + pathFlag + "Image" + pathFlag + "Emp"; try { if (!System.IO.Directory.Exists(dir)) { System.IO.Directory.CreateDirectory(dir); } string newFile = dir + pathFlag + id.ToString() + System.IO.Path.GetExtension(filePath); System.IO.File.Copy(filePath, newFile, true); } catch (Exception ex) { errMsg = ex.Message; } } return(Json(new ReturnResult() { Success = string.IsNullOrEmpty(errMsg), Message = errMsg })); }
public ActionResult ImageManager(string action) { string[] paths = { "Image", "Other" }; //需要遍历的目录列表,最好使用缩略图地址,否则当网速慢时可能会造成严重的延时 string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" }; String str = String.Empty; if (_Request == null) { _Request = Request; } if (action == "get") { UploadFileManager.httpContext = _Request.RequestContext.HttpContext; foreach (string path in paths) { var cfg = UploadFileManager.GetUploadConfig("UEImage"); string basePath = _Request.RequestContext.HttpContext.Server.MapPath("~/") + cfg.Folder + "/" + path; if (WebConfigHelper.GetAppSettingValue("IsLinux") != "true") { basePath = basePath.Replace("/", "\\"); } DirectoryInfo info = new DirectoryInfo(basePath); //目录验证 if (info.Exists) { DirectoryInfo[] infoArr = info.GetDirectories(); foreach (DirectoryInfo tmpInfo in infoArr) { foreach (FileInfo fi in tmpInfo.GetFiles()) { if (Array.IndexOf(filetype, fi.Extension) != -1) { str += cfg.Folder + "/" + path + "/" + tmpInfo.Name + "/" + fi.Name + "ue_separate_ue"; } } } } } } return(Content(str)); }
/// <summary> /// 获取自定义操作处理类型 /// </summary> /// <returns></returns> public static List <Type> GetCustomerOperateHandleTypes() { List <Type> list = new List <Type>(); if (cacheFactory != null && cacheFactory.Exists(cache_operateHandleType)) { list = cacheFactory.Get <List <Type> >(cache_operateHandleType); if (list == null) { list = new List <Type>(); } return(list); } string operateDll = DEFAULT_OPERATE_DLL; //默认操作层dll //取自定义操作类类型 string customerOperateDll = WebConfigHelper.GetAppSettingValue("Operate"); if (!string.IsNullOrEmpty(customerOperateDll)) { operateDll += string.Format(",{0}", customerOperateDll); } string[] token = operateDll.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (token.Length > 0) { foreach (string str in token) { string nameSpace = str == DEFAULT_OPERATE_DLL ? "Rookey.Frame.Operate.Base.OperateHandle.Implement" : null; list.AddRange(BridgeObject.GetTypesByDLL(str, nameSpace)); } } list = list.Where(x => x.Name.EndsWith("OperateHandle") || x.Name.StartsWith("OperateHandleFactory") || (x.BaseType != null && x.BaseType.Name == "InitFactory")).ToList(); if (list == null) { list = new List <Type>(); } if (list.Count > 0 && cacheFactory != null) { cacheFactory.Set <List <Type> >(cache_operateHandleType, list); } return(list); }
/// <summary> /// 注册路由 /// </summary> /// <param name="routes">路由集合</param> public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{resource}.aspx/{*pathInfo}"); // 忽略对 IM 路径的路由 routes.IgnoreRoute("FileManage/{webform}"); routes.IgnoreRoute("IM/{webform}"); string defaultController = WebConfigHelper.GetAppSettingValue("DefaultController"); string defaultAction = WebConfigHelper.GetAppSettingValue("DefaultAction"); if (string.IsNullOrEmpty(defaultController)) { defaultController = "Page"; } if (string.IsNullOrEmpty(defaultAction)) { defaultAction = "Main"; } routes.MapRoute( "index", // Route name "", // URL with parameters new { controller = defaultController, action = defaultAction, id = UrlParameter.Optional } // Parameter defaults , namespaces: new[] { NAMESPACE } ); routes.MapRoute( "Default1", "{controller}/{action}.html", new { controller = defaultController, action = defaultAction } , namespaces: new[] { NAMESPACE } ); routes.MapRoute( "Default2", // Route name "{controller}/{action}/{id}.html", // URL with parameters new { controller = defaultController, action = defaultAction, id = UrlParameter.Optional } // Parameter defaults , namespaces: new[] { NAMESPACE } ); }
public IEnumerable <string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable <string> viewLocations) { List <string> viewFormats = new List <string>() { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", "~/Views/Page/{0}.cshtml", //自定义View规则 "~/Views/Page/Common/{0}.cshtml", //自定义View规则 "~/Views/Page/System/{0}.cshtml", //自定义View规则 "~/Views/Page/Permission/{0}.cshtml", //自定义View规则 "~/Views/Page/Desktop/{0}.cshtml", //自定义View规则 "~/Views/Page/Email/{0}.cshtml" //自定义View规则 }; string otherViewConfigs = WebConfigHelper.GetAppSettingValue("ViewConfig"); if (!string.IsNullOrEmpty(otherViewConfigs)) //其他视图配置 { List <string> token = otherViewConfigs.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); viewFormats.AddRange(token); } return(viewFormats); }
/// <summary> /// 注册路由 /// </summary> /// <param name="routes">路由集合</param> /// <param name="service"></param> public static void RegisterRoutes(IRouteBuilder routes, IServiceProvider service) { string defaultController = WebConfigHelper.GetAppSettingValue("DefaultController"); string defaultAction = WebConfigHelper.GetAppSettingValue("DefaultAction"); if (string.IsNullOrEmpty(defaultController)) { defaultController = "Page"; } if (string.IsNullOrEmpty(defaultAction)) { defaultAction = "Main"; } //自定义路由 routes.Routes.Add(new LegacyRoute(service, defaultController, defaultAction, new string[] { "/" })); //默认路由 routes.MapRoute( name: "default", template: "{controller}/{action}.html", defaults: new { controller = defaultController, action = defaultAction } ); }
/// <summary> /// 取分布式锁(基于DB方式) /// </summary> /// <param name="moduleFlag">模块标识,模块表名/类名</param> /// <param name="method_Flag">方法名标识</param> /// <param name="expirtime">自定义过期时间(秒)</param> /// <param name="des">锁描述</param> /// <returns></returns> public static string DistributeDbLock(string moduleFlag, string method_Flag, double?expirtime = null, string des = null) { try { if (WebConfigHelper.GetAppSettingValue("EnabledDistributeLock") != "true") //未启用分布式锁 { return(string.Empty); } string hostname = System.Net.Dns.GetHostName(); //当前服务器 string processId = ApplicationObject.GetCurrentProcessId(); //当前进程 string threadId = ApplicationObject.GetCurrentThreadId(); //当前线程 lock (tempObjDistriLock) { string errMsg = string.Empty; int timeout = 30; //30秒超时 DateTime initTime = DateTime.Now; DatabaseType dbType = DatabaseType.MsSqlServer; string connStr = ModelConfigHelper.GetModelConnStr(typeof(Other_DistributedLock), out dbType, false); while ((DateTime.Now - initTime).TotalSeconds <= timeout) { double updateTimesamp = Globals.GetTimestamp(DateTime.Now); //当前时间戳 double invalidTimesamp = expirtime.HasValue && expirtime.Value > 0 ? updateTimesamp + expirtime.Value : updateTimesamp + 20; //过期时间戳 Other_DistributedLock methodLock = CommonOperate.GetEntity <Other_DistributedLock>(x => x.ModuleFlag == moduleFlag && x.Method_Flag == method_Flag && x.Invalid_Timesamp > updateTimesamp, null, out errMsg); //锁存在,继续循环再取 if (methodLock != null) { Thread.Sleep(10); continue; } //锁不存在,取得锁成功,插入锁标识 methodLock = new Other_DistributedLock() { ModuleFlag = moduleFlag, Method_Flag = method_Flag, Update_Timesamp = updateTimesamp, Invalid_Timesamp = invalidTimesamp, Maching = hostname, ProcessId = processId, ThreadId = threadId, Des = des }; TransactionTask tranAction = (conn) => { CommonOperate.DeleteRecordsByExpression <Other_DistributedLock>(x => x.ModuleFlag == moduleFlag && x.Method_Flag == method_Flag, out errMsg, false, connStr, dbType, conn); if (!string.IsNullOrEmpty(errMsg)) { throw new Exception(errMsg); } CommonOperate.OperateRecord <Other_DistributedLock>(methodLock, ModelRecordOperateType.Add, out errMsg, null, false, false, connStr, dbType, conn); if (!string.IsNullOrEmpty(errMsg)) { throw new Exception(errMsg); } }; CommonOperate.TransactionHandle(tranAction, out errMsg, connStr, dbType); //取锁成功 if (string.IsNullOrEmpty(errMsg)) { return(string.Empty); } else { WritLockLog(moduleFlag, method_Flag, errMsg); } //取锁失败,继续循环取 Thread.Sleep(10); } return("获取分布式锁超时"); //取锁失败 } } catch { return(string.Empty); } }
/// <summary> /// 保存表单附件 /// </summary> /// <param name="moduleId">模块Id</param> /// <param name="id">记录Id</param> /// <param name="fileMsg">文件信息</param> /// <param name="isAdd">是否只是添加</param> /// <returns></returns> public ActionResult SaveFormAttach(Guid moduleId, Guid id, string fileMsg, bool isAdd = false) { if (string.IsNullOrEmpty(fileMsg)) { return(Json(new ReturnResult { Success = true, Message = string.Empty })); } if (_Request == null) { _Request = Request; } SetRequest(_Request); string errMsg = string.Empty; List <AttachFileInfo> addAttachs = null; try { string pathFlag = "\\"; if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true") { pathFlag = "/"; } UserInfo currUser = GetCurrentUser(_Request); Guid? userId = currUser != null ? currUser.UserId : (Guid?)null; string userName = currUser != null ? currUser.UserName : string.Empty; Sys_Module module = SystemOperate.GetModuleById(moduleId); List <AttachFileInfo> attachInfo = JsonHelper.Deserialize <List <AttachFileInfo> >(HttpUtility.UrlDecode(fileMsg, Encoding.UTF8)); #region 除已经移除的附件 if (!isAdd) //非新增状态 { List <Guid> existIds = new List <Guid>(); if (attachInfo != null && attachInfo.Count > 0) { existIds = attachInfo.Select(x => x.Id.ObjToGuid()).Where(x => x != Guid.Empty).ToList(); } //对已删除的附件进行处理 List <Sys_Attachment> tempAttachments = CommonOperate.GetEntities <Sys_Attachment>(out errMsg, x => x.Sys_ModuleId == moduleId && x.RecordId == id, null, false); if (tempAttachments != null) { tempAttachments = tempAttachments.Where(x => !existIds.Contains(x.Id)).ToList(); } SystemOperate.DeleteAttachment(tempAttachments); } #endregion #region 添加附件 if (attachInfo != null && attachInfo.Count > 0) { addAttachs = new List <AttachFileInfo>(); //日期文件夹 string dateFolder = DateTime.Now.ToString("yyyyMM", DateTimeFormatInfo.InvariantInfo); //记录对应的titleKey值 string titleKeyValue = CommonOperate.GetModelTitleKeyValue(moduleId, id); List <Sys_Attachment> list = new List <Sys_Attachment>(); foreach (AttachFileInfo info in attachInfo) { if (string.IsNullOrEmpty(info.AttachFile)) { continue; } if (info.Id.ObjToGuid() != Guid.Empty) { continue; //原来的附件 } string oldAttchFile = _Request.RequestContext.HttpContext.Server.MapPath(info.AttachFile); //临时附件 string dir = string.Format("{0}Upload{3}Attachment{3}{1}{3}{2}", Globals.GetWebDir(), module.TableName, dateFolder, pathFlag); if (!Directory.Exists(dir)) //目录不存在则创建 { Directory.CreateDirectory(dir); } string newAttachFile = string.Format("{0}{4}{1}_{2}{3}", dir, Path.GetFileNameWithoutExtension(info.FileName), id, Path.GetExtension(info.FileName), pathFlag); try { System.IO.File.Copy(oldAttchFile, newAttachFile, true); //复制文件 } catch (Exception ex) { return(Json(new ReturnResult { Success = false, Message = ex.Message }, "text/plain")); } //文件复制完成后删除临时文件 try { System.IO.File.Delete(oldAttchFile); } catch { } string newPdfFile = string.Empty; //pdf文件 string newSwfFile = string.Empty; //swf文件 //可以转换成swf的进行转换 if (info.FileType.Equals(".doc") || info.FileType.Equals(".docx") || info.FileType.Equals(".xls") || info.FileType.Equals(".xlsx") || info.FileType.Equals(".ppt") || info.FileType.Equals(".pptx") || info.FileType.Equals(".pdf")) { newPdfFile = string.Format("{0}{2}{1}.pdf", dir, Path.GetFileNameWithoutExtension(newAttachFile), pathFlag); newSwfFile = string.Format("{0}{2}{1}.swf", dir, Path.GetFileNameWithoutExtension(newAttachFile), pathFlag); string exePath = _Request.RequestContext.HttpContext.Server.MapPath("~/bin/SWFTools/pdf2swf.exe"); string binPath = _Request.RequestContext.HttpContext.Server.MapPath("~/bin/"); string[] obj = new string[] { info.FileType, newAttachFile, newPdfFile, newSwfFile, exePath, binPath }; CreateSwfFile(obj); } //构造文件URL,保存为相对URL地址 string fileUrl = string.Format("Upload/Attachment/{0}/{1}/{2}", module.TableName, dateFolder, Path.GetFileName(newAttachFile)); string pdfUrl = string.IsNullOrEmpty(newPdfFile) ? string.Empty : newPdfFile.Replace(Globals.GetWebDir(), string.Empty).Replace("\\", "/"); string swfUrl = string.IsNullOrEmpty(newSwfFile) ? string.Empty : newSwfFile.Replace(Globals.GetWebDir(), string.Empty).Replace("\\", "/"); Guid attachiId = Guid.NewGuid(); info.Id = attachiId.ToString(); list.Add(new Sys_Attachment() { Id = attachiId, Sys_ModuleId = moduleId, Sys_ModuleName = module.Name, RecordId = id, RecordTitleKeyValue = titleKeyValue, FileName = info.FileName, FileType = info.FileType, FileSize = info.FileSize, FileUrl = fileUrl, PdfUrl = pdfUrl, SwfUrl = swfUrl, AttachType = info.AttachType, CreateDate = DateTime.Now, CreateUserId = userId, CreateUserName = userName, ModifyDate = DateTime.Now, ModifyUserId = userId, ModifyUserName = userName }); string tempUrl = "/" + fileUrl; if (!string.IsNullOrEmpty(swfUrl)) { tempUrl = string.Format("/Page/DocView.html?fn={0}&swfUrl={1}", HttpUtility.UrlEncode(info.FileName).Replace("+", "%20"), HttpUtility.UrlEncode(swfUrl).Replace("+", "%20")); } info.AttachFile = tempUrl; info.PdfFile = pdfUrl; info.SwfFile = swfUrl; addAttachs.Add(info); } if (list.Count > 0) { Guid attachModuleId = SystemOperate.GetModuleIdByName("附件信息"); bool rs = CommonOperate.OperateRecords(attachModuleId, list, ModelRecordOperateType.Add, out errMsg, false); if (!rs) { addAttachs = null; } } } #endregion } catch (Exception ex) { errMsg = ex.Message; } return(Json(new { Success = string.IsNullOrEmpty(errMsg), Message = errMsg, AddAttachs = addAttachs }, "text/plain")); }
public ActionResult UploadAttachment(HttpPostedFileBase[] file, Guid?moduleId, Guid?id, bool isCreateSwf = false) { if (file == null || file.Where(o => o == null).Count() > 0) { return(Json(new ReturnResult { Success = false, Message = "请选择上传文件!" })); } if (_Request == null) { _Request = Request; } SetRequest(_Request); string attachType = _Request["attachType"].ObjToStr(); UploadFileManager.httpContext = _Request.RequestContext.HttpContext; string message = string.Empty; StringBuilder msg = new StringBuilder(); List <AttachFileInfo> fileMsg = new List <AttachFileInfo>(); foreach (var item in file) { try { string fileSize = FileOperateHelper.FileSize(item.ContentLength); string fileType = Path.GetExtension(item.FileName); string fileName = item.FileName; string pathFlag = "\\"; if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true") { pathFlag = "/"; } int s = fileName.LastIndexOf(pathFlag); if (s >= 0) { fileName = fileName.Substring(s + 1); } //保存文件 string filePath = string.Empty; if (moduleId.HasValue) //表单附件 { filePath = UploadFileManager.SaveAs(item, "Attachment", "Temp"); } else { filePath = UploadFileManager.SaveAs(item, string.Empty); } filePath = filePath.StartsWith("~/") ? filePath : filePath.StartsWith("/") ? "~" + filePath : "~/" + filePath; //swf保存路径 string swfPath = string.Empty; //pdf保存路径 string pdfPath = string.Empty; if (isCreateSwf && !moduleId.HasValue) { //exe路径 string exePath = _Request.RequestContext.HttpContext.Server.MapPath("~/bin/SWFTools/pdf2swf.exe"); //bin路径 string binPath = _Request.RequestContext.HttpContext.Server.MapPath("~/bin/"); if (fileType.Equals(".doc") || fileType.Equals(".docx") || fileType.Equals(".xls") || fileType.Equals(".xlsx") || fileType.Equals(".ppt") || fileType.Equals(".pptx") || fileType.Equals(".pdf")) { //取pdf和swf路径 GetFilePath(out pdfPath, out swfPath); //参数 string[] obj = new string[] { fileType, _Request.RequestContext.HttpContext.Server.MapPath(filePath), _Request.RequestContext.HttpContext.Server.MapPath(pdfPath), _Request.RequestContext.HttpContext.Server.MapPath(swfPath), exePath, binPath }; CreateSwfFile(obj); } } fileMsg.Add(new AttachFileInfo() { AttachFile = filePath, PdfFile = pdfPath, SwfFile = swfPath, FileName = fileName, FileType = fileType, FileSize = fileSize, AttachType = attachType }); } catch (Exception ex) { msg.AppendLine(item.FileName + "上传失败:" + ex.Message); break; } } if (moduleId.HasValue && id.HasValue) //查看页面,直接保存附件 { return(SaveFormAttach(moduleId.Value, id.Value, JsonHelper.Serialize(fileMsg), true)); } return(Json(new { Success = string.IsNullOrEmpty(msg.ToString()), Message = string.IsNullOrEmpty(msg.ToString()) ? "上传成功" : msg.ToString(), FileMsg = fileMsg.Count > 0 ? JsonHelper.Serialize(fileMsg) : string.Empty }, "text/plain")); }
public ActionResult ScrawlUp(HttpPostedFileBase upfile, string content) { if (_Request == null) { _Request = Request; } UploadFileManager.httpContext = _Request.RequestContext.HttpContext; var cfg = UploadFileManager.GetUploadConfig("UEImage"); if (upfile != null) { string path = string.Empty; string state = "SUCCESS"; //上传图片 try { path = UploadFile(upfile, "UEImage", "Temp"); } catch (Exception ex) { return(Json(new { state = ex.Message })); } return(Content("<script>parent.ue_callback('" + path + "','" + state + "')</script>"));//回调函数 } else { //上传图片 string url = string.Empty; string state = "SUCCESS"; FileStream fs = null; string pathFlag = "\\"; if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true") { pathFlag = "/"; } try { string dir = _Request.RequestContext.HttpContext.Server.MapPath("~/") + cfg.Folder + "/Other"; string path = DateTime.Now.ToString("yyyyMM"); dir = dir + "/" + path; if (pathFlag == "\\") { dir = dir.Replace("/", "\\"); } if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string filename = System.Guid.NewGuid() + ".png"; fs = System.IO.File.Create(dir + pathFlag + filename); byte[] bytes = Convert.FromBase64String(content); fs.Write(bytes, 0, bytes.Length); url = cfg.Folder + "/Other/" + path + "/" + filename; } catch (Exception e) { state = "未知错误:" + e.Message; url = ""; } finally { fs.Close(); string tempDir = _Request.RequestContext.HttpContext.Server.MapPath("~/") + cfg.Folder + "/Temp"; if (pathFlag == "\\") { tempDir = tempDir.Replace("/", "\\"); } DirectoryInfo info = new DirectoryInfo(tempDir); if (info.Exists) { DirectoryInfo[] infoArr = info.GetDirectories(); foreach (var item in infoArr) { string str = tempDir + pathFlag + item.Name; Directory.Delete(str, true); } } } return(Json(new { url = url, state = state })); } }
/// <summary> /// 添加后台系统任务 /// </summary> /// <param name="obj"></param> /// <param name="e"></param> public static void SysBackgroundTaskAdd(object obj, EventArgs e) { if (WebConfigHelper.GetAppSettingValue("IsRunBgTask") == "true") { try { #region 重建索引 //重建索引任务 BackgroundTask reBuildIndexTask = new BackgroundTask((args) => { if (DateTime.Now.Hour == 4 && DateTime.Now.Minute == 0) { SystemOperate.RebuildAllTableIndex(); } return(true); }, null, false, 45, false); AutoProcessTask.AddTask(reBuildIndexTask); #endregion #region 迁移历史审批数据 //审批完成后的数据迁移到待办历史数据表中,针对审批是迁移失败的处理 BackgroundTask todoStatusHandleTask = new BackgroundTask((args) => { if ((DateTime.Now.Hour == 3 && DateTime.Now.Minute == 0) || (DateTime.Now.Hour == 12 && DateTime.Now.Minute == 40)) { //审批完成数据迁移异常处理 try { string errMsg = string.Empty; int refuseStatus = (int)WorkFlowStatusEnum.Refused; int overStatus = (int)WorkFlowStatusEnum.Over; int obsoStatus = (int)WorkFlowStatusEnum.Obsoleted; List <Bpm_WorkFlowInstance> flowInsts = CommonOperate.GetEntities <Bpm_WorkFlowInstance>(out errMsg, x => x.Status == refuseStatus || x.Status == overStatus || x.Status == obsoStatus, null, false); if (flowInsts != null && flowInsts.Count > 0) { foreach (Bpm_WorkFlowInstance flowInst in flowInsts) { BpmOperate.TransferWorkToDoHistory(flowInst, null); } } } catch { } } return(true); }, null, false, 45, false); AutoProcessTask.AddTask(todoStatusHandleTask); #endregion #region 附件在线预览生成 BackgroundTask attachOnlineViewHandleTask = new BackgroundTask((args) => { if (DateTime.Now.Hour == 4 && DateTime.Now.Minute == 0) { string attachWeb = WebConfigHelper.GetAppSettingValue("AttachmentWeb"); if (!string.IsNullOrEmpty(attachWeb)) { if (!attachWeb.EndsWith("/")) { attachWeb += "/"; } string apiUrl = attachWeb + "api/AnnexApi/ExecCreateSwfTask.html"; DataMutual dataMutal = new DataMutual(apiUrl); dataMutal.Start(null); } } return(true); }, null, false, 45, false); AutoProcessTask.AddTask(attachOnlineViewHandleTask); #endregion #region 基于DB的失效分布式锁释放 BackgroundTask dbLockReleaseHandleTask = new BackgroundTask((args) => { if (WebConfigHelper.GetAppSettingValue("EnabledDistributeLock") == "true") //启用分布式锁 { string errMsg = string.Empty; double nowTimesamp = Globals.GetTimestamp(DateTime.Now);//当前时间戳 CommonOperate.DeleteRecordsByExpression <Other_DistributedLock>(x => x.Invalid_Timesamp < nowTimesamp, out errMsg); } return(true); }, null, false, 60, false); AutoProcessTask.AddTask(dbLockReleaseHandleTask); #endregion } catch { } } try { InitFactory factory = InitFactory.GetInstance(); if (factory != null) { factory.AddBackgroundTask(); } } catch { } }
/// <summary> /// 根据Email类型创建SmtpClient /// </summary> /// <param name="type">Email类型</param> /// <param name="enableSsl">端口号会根据是否支持ssl而不同</param> private void EmailTypeConfig(EmailType type, bool enableSsl) { switch (type) { case EmailType.Customer: { // 自定义邮箱 string host = string.Empty; int port = 25; try { string emailConfig = WebConfigHelper.GetAppSettingValue("EmailServer"); if (!string.IsNullOrEmpty(emailConfig)) { string[] token = emailConfig.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (token.Length > 0) { host = token[0]; if (token.Length > 1) { int.TryParse(token[1], out port); } } } } catch { } if (host == string.Empty) { throw new Exception(MailValidatorHelper.EMAIL_SMTP_TYPE_ERROR); } SmtpClient = new SmtpClient(host, port); SmtpClient.EnableSsl = enableSsl; } break; case EmailType.Gmail: { // Gmail的SMTP要求使用安全连接(SSL) SmtpClient = new SmtpClient("smtp.gmail.com", 587); SmtpClient.EnableSsl = true; } break; case EmailType.HotMail: { // HotMail的SMTP要求使用安全连接(SSL) SmtpClient = new SmtpClient("smtp.live.com", 25); SmtpClient.EnableSsl = true; } break; case EmailType.QQ_FoxMail: { SmtpClient = new SmtpClient("smtp.qq.com", 25); SmtpClient.EnableSsl = false; } break; case EmailType.Mail_126: { SmtpClient = new SmtpClient("smtp.126.com", 25); SmtpClient.EnableSsl = false; } break; case EmailType.Mail_163: { SmtpClient = new SmtpClient("smtp.163.com", enableSsl ? 994 : 25); SmtpClient.EnableSsl = enableSsl; } break; case EmailType.Sina: { SmtpClient = new SmtpClient("smtp.sina.com", 25); SmtpClient.EnableSsl = false; } break; case EmailType.Tom: { SmtpClient = new SmtpClient("smtp.tom.com", 25); SmtpClient.EnableSsl = false; } break; case EmailType.SoHu: { SmtpClient = new SmtpClient("smtp.sohu.com", 25); SmtpClient.EnableSsl = false; } break; case EmailType.Yahoo: { SmtpClient = new SmtpClient("smtp.mail.yahoo.com", 25); SmtpClient.EnableSsl = false; } break; case EmailType.None: default: { throw new Exception(MailValidatorHelper.EMAIL_SMTP_TYPE_ERROR); } } }
/// <summary> /// 从xml配置文件中获取模块缓存配置 /// </summary> /// <param name="tableName">模块表名或类名</param> /// <param name="moduleName">模块名称</param> /// <param name="moduleId">模块ID</param> /// <returns></returns> private Sys_DbConfig GetModuleCacheConfig(string tableName, string moduleName = null, Guid?moduleId = null) { //将未添加到模块表中的模块也加进来 List <Type> modelTypes = GetAllModelTypes(); Type modelType = modelTypes.Where(x => x.Name == tableName).FirstOrDefault(); Guid id = Guid.Empty; if (!moduleId.HasValue) { if (!tableIdDic.ContainsKey(tableName)) { Guid tempId = Guid.NewGuid(); tableIdDic.Add(tableName, tempId); id = tempId; } else { id = tableIdDic[tableName]; } } else { id = moduleId.Value; } Sys_DbConfig dbConfig = new Sys_DbConfig() { Id = id, ModuleName = string.IsNullOrEmpty(moduleName) ? tableName : moduleName }; if (modelType == null) { return(dbConfig); } string dbTypeStr = WebConfigHelper.GetAppSettingValue("DbType"); if (string.IsNullOrEmpty(dbTypeStr)) { dbTypeStr = "0"; } TempDatabaseType dbType = (TempDatabaseType)Enum.Parse(typeof(TempDatabaseType), dbTypeStr); string tempDbTypeStr = string.Empty; string readConnStr = ModelConfigHelper.GetModelConnString(modelType, out tempDbTypeStr); string writeConnStr = ModelConfigHelper.GetModelConnString(modelType, out tempDbTypeStr, false); if (tempDbTypeStr != string.Empty) //实体配置了数据库类型 { try { dbType = (TempDatabaseType)Enum.Parse(typeof(DatabaseType), tempDbTypeStr); } catch { } } dbConfig.DbTypeOfEnum = dbType; dbConfig.ReadConnString = readConnStr; dbConfig.WriteConnString = writeConnStr; string modelConfigPath = ModelConfigHelper.GetModelConfigXml(); string node = string.Format("/Root/{0}", tableName); bool nodeIsExists = XmlHelper.NodeIsExists(modelConfigPath, node); if (!nodeIsExists) //不存在实体节点配置信息,找对应基类的节点配置信息 { //取实体基类 Type baseType = modelType.BaseType; if (baseType != null) //存在基类 { node = string.Format("/Root/{0}", baseType.Name); //基类节点 nodeIsExists = XmlHelper.NodeIsExists(modelConfigPath, node); } } if (!nodeIsExists) { return(dbConfig); } string autoReCreateIndex = XmlHelper.Read(modelConfigPath, node, "AutoReCreateIndex"); //是否自动重建索引 string createIndexPageDensity = XmlHelper.Read(modelConfigPath, node, "CreateIndexPageDensity"); //重建索引页密度 string automaticPartition = XmlHelper.Read(modelConfigPath, node, "AutomaticPartition"); //是否自动分区 string partitionInterval = XmlHelper.Read(modelConfigPath, node, "PartitionInterval"); //分区间隔记录数 dbConfig.AutoReCreateIndex = autoReCreateIndex.ObjToInt() == 1; dbConfig.CreateIndexPageDensity = createIndexPageDensity.ObjToInt(); dbConfig.AutomaticPartition = automaticPartition.ObjToInt() == 1; dbConfig.PartitionInterval = partitionInterval.ObjToInt(); return(dbConfig); }
/// <summary> /// 员工操作完成 /// </summary> /// <param name="operateType">操作类型</param> /// <param name="t">员工对象</param> /// <param name="result">操作结果</param> /// <param name="currUser">当前用户</param> /// <param name="otherParams"></param> public void OperateCompeletedHandle(ModelRecordOperateType operateType, OrgM_Emp t, bool result, UserInfo currUser, object[] otherParams = null) { if (result) { string errMsg = string.Empty; string username = OrgMOperate.GetUserNameByEmp(t); string userInitPwd = WebConfigHelper.GetAppSettingValue("UserInitPwd"); if (string.IsNullOrEmpty(userInitPwd)) { userInitPwd = "123456"; } if (operateType == ModelRecordOperateType.Add) { if (!string.IsNullOrEmpty(username)) { UserOperate.AddUser(out errMsg, username, userInitPwd, null, t.Name); } } else if (operateType == ModelRecordOperateType.Edit) { if (!string.IsNullOrEmpty(username)) { Sys_User user = UserOperate.GetUser(username); if (user != null) //用户已存在 { UserOperate.UpdateUserAliasName(username, t.Name); } else //用户不存在 { UserOperate.AddUser(out errMsg, username, userInitPwd, null, t.Name); } } } else if (operateType == ModelRecordOperateType.Del) { if (!string.IsNullOrEmpty(username)) { UserOperate.DelUser(username); //删除账号 } //删除员工同时删除员工岗位 CommonOperate.DeleteRecordsByExpression <OrgM_EmpDeptDuty>(x => x.OrgM_EmpId == t.Id, out errMsg, t.IsDeleted); } if (operateType == ModelRecordOperateType.Add || operateType == ModelRecordOperateType.Edit) { //新增编辑时同时设置员工主职岗位 if (t.DeptId.HasValue && t.DeptId.Value != Guid.Empty && t.DutyId.HasValue && t.DutyId.Value != Guid.Empty) { OrgM_EmpDeptDuty empPosition = null; if (operateType == ModelRecordOperateType.Edit) { empPosition = CommonOperate.GetEntity <OrgM_EmpDeptDuty>(x => x.OrgM_EmpId == t.Id && x.IsMainDuty == true, null, out errMsg); if (empPosition != null) { empPosition.OrgM_DeptId = t.DeptId.Value; empPosition.OrgM_DutyId = t.DutyId.Value; empPosition.IsValid = true; empPosition.ModifyDate = DateTime.Now; empPosition.ModifyUserId = currUser.UserId; empPosition.ModifyUserName = currUser.EmpName; CommonOperate.OperateRecord <OrgM_EmpDeptDuty>(empPosition, ModelRecordOperateType.Edit, out errMsg, null, false); return; } } Guid moduleId = SystemOperate.GetModuleIdByModelType(typeof(OrgM_EmpDeptDuty)); string code = SystemOperate.GetBillCode(moduleId); empPosition = new OrgM_EmpDeptDuty() { Code = code, OrgM_DeptId = t.DeptId.Value, OrgM_DutyId = t.DutyId.Value, OrgM_EmpId = t.Id, IsMainDuty = true, IsValid = true, EffectiveDate = DateTime.Now, CreateDate = DateTime.Now, CreateUserId = currUser.UserId, CreateUserName = currUser.EmpName, ModifyDate = DateTime.Now, ModifyUserId = currUser.UserId, ModifyUserName = currUser.EmpName }; Guid rs = CommonOperate.OperateRecord <OrgM_EmpDeptDuty>(empPosition, ModelRecordOperateType.Add, out errMsg, null, false); if (rs != Guid.Empty) { SystemOperate.UpdateBillCode(moduleId, code); } } } } }