/// <summary> /// 通过 request path 获取 scc FunctionId /// </summary> /// <param name="requestPath"></param> /// <returns></returns> public static string GetFunctionId(string requestPath) { return(Wrapper.Cache(() => { DataTable dtMenu = Wrapper.Cache(() => Menus.GetData.GetUserRightDtForFunction(SysCode, CurrentUserId), SysCode, CurrentUserId); if (dtMenu != null && dtMenu.Rows.Count > 0) { foreach (DataRow row in dtMenu.Rows) { var rowPath = row["Exe_Path"].ToString2(); rowPath = rowPath.Split('?')[0]; if (rowPath.IsNullOrEmpty()) { continue; } if (requestPath.ToLower().Contains(rowPath.ToLower())) { return row["Sys_Id"].ToString2(); } } } return ""; }, requestPath, CurrentUserId)); }
/// <summary> /// 从SCC获取用户权限列表 /// </summary> /// <param name="userId">用户ID</param> /// <param name="functionId">功能ID</param> /// <returns></returns> public static List <string> GetRole(string userId, string functionId) { return(Wrapper.Cache(() => { var rst = new List <string>(); // 从SCC获取用户权限 DataTable dtMenu = Menus.GetData.GetUserRightDtForFunction(functionId, userId); if (dtMenu != null && dtMenu.Rows.Count > 0) { var rows = dtMenu.Select(string.Format("Sys_Id='{0}'", functionId)); var a = rows[0]["UserPars"].ToString().Split('~'); if (a != null && a.Length > 0) { foreach (var i in a) { var b = i.Split('='); if (b.Length > 1 && b[1] == "1") { rst.Add(b[0]); } } } } return rst; }, userId, functionId)); }
/// <summary> /// 检查用户是否有权限 /// </summary> /// <param name="role">权限</param> /// <returns></returns> public static bool IsInRole(string role, string functionId) { return(Wrapper.Cache(() => { var a = role.Split(','); var b = SccService.GetRole(SccService.CurrentUserId, functionId); var rst = a.All(t => b.Contains(t)); return rst; }, CurrentUserId, functionId, role)); }
/// <summary> /// 从SCC 获取用户信息 /// </summary> /// <param name="userId">用户ID</param> /// <returns></returns> private static UserInfo GetUserInfoFromSCC(string userId) { return(Wrapper.Cache(() => { using (var conn = new SqlConnection(Menus.MenuSQlHelper._DBConnectionString)) { return conn.Query <UserInfo>("Select * From v_user_master_All Where [mail_id]=@mail_id", new { mail_id = userId } ).FirstOrDefault(); } })); }
/// <summary> /// 获取Company /// </summary> /// <param name="compCode">公司代码</param> /// <returns></returns> public static Company GetCompany(string compCode) { return(Wrapper.Cache(() => { using (var conn = new SqlConnection(Commons.SQlHelper._DBConnectionString)) { var sql = @" SELECT * FROM App_Company WHERE Company_Code=@Company_Code;"; return conn.Query <Company>(sql, new { Company_Code = compCode }).FirstOrDefault(); } }, compCode)); }
/// <summary> /// 查询用户语言信息 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static UserLanguage GetUserLanguageByUserId(string userId) { return(Wrapper.Cache(() => { using (var conn = new SqlConnection(Commons.SQlHelper._DBConnectionString)) { var sql = @" SELECT * FROM App_User_Language WHERE User_ID=@User_ID; "; return conn.Query <UserLanguage>(sql, new { User_ID = userId }).FirstOrDefault(); } })); }
/// <summary> /// 获取DB中的类型的表定义 /// </summary> /// <param name="type"></param> /// <returns></returns> public static DataTable GetSchemaTable <T>() where T : ITable { return(Wrapper.Cache(() => { using (var conn = new DB().Database.Connection) { conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandText = string.Format("select * from [{0}]", typeof(T).Name); var reader = cmd.ExecuteReader(CommandBehavior.KeyInfo); return reader.GetSchemaTable(); } }, typeof(T).Name)); }
public static string GetLanguageXml(string keyword) { return(Wrapper.Cache(() => { var langType = HttpContext.Current != null && HttpContext.Current.Session["LangType"] != null ? HttpContext.Current.Session["LangType"].ToString() : "EN"; String xml = Commons.Language.GetXML(keyword, langType, "", false); return string.IsNullOrWhiteSpace(xml) ? string.Empty : xml.Replace("<Language>", "") .Replace("</Language>", "") .Replace("<?xml version='1.0' encoding='utf-8' ?>", ""); }, keyword)); }
public static string GetLanguageJavascript(string keyword) { return(Wrapper.Cache(() => { var langType = HttpContext.Current != null && HttpContext.Current.Session["LangType"] != null ? HttpContext.Current.Session["LangType"].ToString() : "EN"; String xml = Commons.Language.GetXML(keyword, langType, "", false); if (string.IsNullOrWhiteSpace(xml)) { return string.Empty; } var xDoc = XDocument.Parse(xml); var rows = from r in xDoc.Descendants("Row") select new { k = r.Attribute("ItemID").Value.Replace(keyword + ".", ""), v = r.Attribute("Text").Value }; StringBuilder sb = new StringBuilder(); sb.Append("<script>var PageLangCache = {"); foreach (var r in rows) { sb.Append("\"") .Append(r.k) .Append("\"") .Append(":") .Append("\"") .Append(r.v) .Append("\","); } sb.Remove(sb.Length - 1, 1); sb.Append("};</script>"); return sb.ToString(); }, keyword)); }