public static Dictionary <string, string> GetPortalType() { Dictionary <string, string> lists = new Dictionary <string, string>(); foreach (var item in Enum.GetNames(typeof(PortalType))) { lists.Add(item, PortalHelper.GetEnumDescription((PortalType)Enum.Parse(typeof(PortalType), item))); } return(lists); }
public static string CreatePortal(string templetID, string portalID, bool isNew, string json) { try { var entities = FormulaHelper.GetEntities <BaseEntities>(); var templet = entities.Set <S_A_PortalTemplet>().SingleOrDefault(c => c.ID == templetID); if (templet != null) { var html = templet.Items; Dictionary <string, object> list = JsonHelper.ToObject(json); string type = list.GetValue("Type"); if (type != PortalType.Now.ToString()) { if (isNew) { string linkUrl = list.GetValue("LinkUrl"); string moreUrl = list.GetValue("MoreUrl"); S_A_Portal portal = new S_A_Portal(); portalID = FormulaHelper.CreateGuid(); portal.ID = portalID; portal.Title = list.GetValue("Title"); portal.Type = type; if (string.IsNullOrEmpty(linkUrl)) { portal.LinkUrl = "/Base/UI/Portal/Views?ID={ID}&portalID=" + portalID; } else { portal.LinkUrl = list.GetValue("LinkUrl"); } if (string.IsNullOrEmpty(moreUrl)) { portal.MoreUrl = "/Base/UI/Portal/ListView?portalID=" + portalID; } else { portal.MoreUrl = list.GetValue("MoreUrl"); } portal.Height = list.GetValue("Height").Trim(); portal.DisplayType = list.GetValue("DisplayType").Trim(); portal.ConnName = list.GetValue("ConnName"); portal.SQL = list.GetValue("SQL"); entities.Set <S_A_Portal>().Add(portal); } else { if (!string.IsNullOrEmpty(portalID)) { var portal = entities.Set <S_A_Portal>().SingleOrDefault(c => c.ID == portalID); if (portal != null) { portal.ID = portalID; portal.Title = list.GetValue("Title"); portal.Type = type; portal.ConnName = list.GetValue("ConnName"); portal.SQL = list.GetValue("SQL"); portal.LinkUrl = list.GetValue("LinkUrl"); portal.MoreUrl = list.GetValue("MoreUrl"); portal.Height = list.GetValue("Height").Trim(); portal.DisplayType = list.GetValue("DisplayType").Trim(); } } } } else { Regex preg = new Regex(@"\{PORTALS}(.+?){/PORTALS}"); SQLHelper sqlHelper = SQLHelper.CreateSqlHelper(ConnEnum.Base); List <string> portalIDs = new List <string>(); foreach (Match m in preg.Matches(templet.Items)) { string portals = m.Value; string result = Regex.Match(portals, "(?<={PORTALS}).*?(?={/PORTALS})").Value; if (!string.IsNullOrEmpty(result)) { portalIDs.Add(result); } } List <string> nowPortal = new List <string>(); portalID = list.GetValue("Portal"); foreach (string item in portalID.Split(',')) { if (portalIDs.Count > 0) { var query = sqlHelper.ExecuteScalar(string.Format("select 1 from S_A_Portal where ID In ({0}) and LinkUrl like '%{1}.cshtml%'", PortalHelper.SplitCondition(string.Join(",", portalIDs.ToArray())), item)); if (Convert.ToInt32(query) > 0) { throw new Exception("不能添加重复的块,请点击块后进行修改!"); } } var nowID = FormulaHelper.CreateGuid(); if (!html.Contains(nowID)) { entities.Set <S_A_Portal>().Add(new S_A_Portal() { ID = nowID, Title = EnumBaseHelper.GetEnumDescription(typeof(Base.Logic.DefaultPortal), item), Type = PortalType.Link.ToString(), LinkUrl = string.Format("/PortalLTE/Views/Main/{0}.cshtml", item) }); nowPortal.Add(nowID); } } portalID = string.Join(",", nowPortal.ToArray()); } int indexOf = html.IndexOf("</section>"); string reg = "(?<={PORTALS}).*?(?={/PORTALS})"; string firstHtml = html.Substring(0, indexOf); string lastHtml = html.Substring(indexOf, html.Length - indexOf); string MatchValue = Regex.Match(firstHtml, reg).Value; if (string.IsNullOrEmpty(MatchValue)) { if (!lastHtml.Contains(portalID)) { templet.Items = firstHtml + ("{PORTALS}" + portalID + "{/PORTALS}") + lastHtml; } } else { List <string> values = new List <string>(); foreach (Match m in Regex.Matches(firstHtml, reg)) { values.Add(m.Value); } var target = string.Join(",", values.ToArray()); if (!firstHtml.Contains(portalID) && !lastHtml.Contains(portalID)) { values.Add(portalID); } firstHtml = firstHtml.Replace(target, string.Join(",", values.ToArray())); templet.Items = firstHtml + lastHtml; } entities.SaveChanges(); } } catch (Exception e) { } return(portalID); }
public static void CreatePortalTemplet(string id, string json, bool isLoad) { var entities = FormulaHelper.GetEntities <BaseEntities>(); var templet = entities.Set <S_A_PortalTemplet>().SingleOrDefault(c => c.ID == id); if (templet != null) { string rows = "1", cols = "3", colWidth = "4,4,4"; if (string.IsNullOrEmpty(templet.Items)) { templet.Rows = rows; templet.Cols = cols; templet.ColsWidth = colWidth; templet.Items = CalcTemplet(rows, cols, colWidth); } else { if (!isLoad) { Regex reg = new Regex(@"\{PORTALS}(.+?){/PORTALS}"); SQLHelper sqlHelper = SQLHelper.CreateSqlHelper(ConnEnum.Base); List <string> portalIDs = new List <string>(); foreach (Match m in reg.Matches(templet.Items)) { string portals = m.Value; string result = Regex.Match(portals, "(?<={PORTALS}).*?(?={/PORTALS})").Value; if (!string.IsNullOrEmpty(result)) { portalIDs.Add(result); } } if (portalIDs.Count > 0) { sqlHelper.ExecuteNonQuery(string.Format("delete from S_A_Portal where ID In ({0})", PortalHelper.SplitCondition(string.Join(",", portalIDs.ToArray())))); } } if (!string.IsNullOrEmpty(json) && !json.Equals("{}")) { Dictionary <string, object> list = JsonHelper.ToObject(json); var templetType = list.GetValue("TempletType"); if (!string.IsNullOrEmpty(templetType)) { colWidth = list.GetValue("ColsWidth"); if (templetType.Trim() == "1r2c") { cols = "2"; } else if (templetType.Trim() == "custom") { rows = list.GetValue("Rows"); cols = list.GetValue("Cols"); } templet.Rows = rows; templet.Cols = cols; templet.ColsWidth = colWidth; templet.Items = CalcTemplet(rows, cols, colWidth); } } } entities.SaveChanges(); } }
public static string GetIndexHTML(string url, string templateID = "") { StringBuilder sb = new StringBuilder(); try { var entities = FormulaHelper.GetEntities <BaseEntities>(); SQLHelper sqlHelper = SQLHelper.CreateSqlHelper(ConnEnum.Base); System.Random Random = new System.Random(); var userInfo = entities.Set <S_A_User>().SingleOrDefault(c => c.ID == FormulaHelper.UserID); if (userInfo != null) { List <string> roles = new List <string>(); bool isPortalMain = url.IndexOf("/UI/Portal/Portal") >= 0; string linkTemplate = PortalHelper.GetPageHtml(HomePageTemplet + "linkUrl.js"); var portalTemplet = sqlHelper.ExecuteDataTable("select ID as TempletID,Items from S_A_PortalTemplet"); DataRow dataRow = null; if (!string.IsNullOrEmpty(templateID)) { dataRow = portalTemplet.Select(string.Format(" TempletID='{0}'", templateID))[0]; } else { portalTemplet = GetUserRoleTemplets(FormulaHelper.UserID); if (portalTemplet.Rows.Count > 0) { dataRow = portalTemplet.Rows[0]; } } if (portalTemplet.Rows.Count > 0 && dataRow != null) { var items = dataRow["Items"].ToString(); if (!string.IsNullOrEmpty(userInfo.PortalSettings) && !isPortalMain) { if (string.IsNullOrEmpty(templateID) || (!string.IsNullOrEmpty(templateID) && userInfo.PortalSettings.Split(':')[0] == templateID)) { items = userInfo.PortalSettings.Split(':')[1]; } } templateID = dataRow["TempletID"].ToString(); sb.Append(items); Regex reg = new Regex(@"\{PORTALS}(.+?){/PORTALS}"); foreach (Match m in reg.Matches(items)) { string portals = m.Value; string result = Regex.Match(portals, "(?<={PORTALS}).*?(?={/PORTALS})").Value; if (string.IsNullOrEmpty(result)) { sb.Replace(portals, ""); } else { StringBuilder sbPortal = new StringBuilder(); string condition = PortalHelper.SplitCondition(result); string orderBy = string.Format("charindex(','+rtrim(cast(ID as varchar(100)))+',',',{0},')", result); if (Config.Constant.IsOracleDb) { orderBy = string.Format("'{0}',ID)", result); } var portal = sqlHelper.ExecuteDataTable(string.Format("select * from S_A_Portal where ID In ({0}) order by {1}", condition, orderBy)); if (portal.Rows.Count > 0) { foreach (DataRow dr in portal.Rows) { string id = dr["ID"].ToString(); string title = dr["Title"].ToString(); string linkUrl = Convert.ToString(dr["LinkUrl"]); string moreUrl = Convert.ToString(dr["MoreUrl"]); string height = Convert.ToString(dr["Height"]).Trim(); bool IsList = Convert.ToString(dr["DisplayType"]) == DisplayType.List.ToString() || string.IsNullOrEmpty(Convert.ToString(dr["DisplayType"])); int bottom = !string.IsNullOrEmpty(height) ? 32 : 0; height = string.IsNullOrEmpty(height) ? "100%" : height.ToLower().Contains("px") ? height : height + "px"; var portalType = (PortalType)Enum.Parse(typeof(PortalType), dr["Type"].ToString()); var randomID = Random.Next(0, 99999999).ToString(); switch (portalType) { case PortalType.Link: if (linkUrl.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) || linkUrl.IndexOf(".cshtml") <= 0) { if (linkTemplate.Length > 0) { var rurl = System.Web.HttpContext.Current.Request.Url.Host; var rport = System.Web.HttpContext.Current.Request.Url.Port; var domain = linkUrl.Split('/'); //以“/”进行分割 var returnurl = ""; if (linkUrl.StartsWith("http") && domain.Length >= 2 && domain[2] != null) { returnurl = domain[0] + "//" + domain[2]; } else { returnurl = ""; //如果url不正确就取空 } var urlflag = false; if (returnurl.IndexOf(":") >= 0) { if (returnurl.IndexOf(rurl + ":" + rport) < 0) { urlflag = true; } } else if (returnurl != "") { if (rport.ToString() != "80" || returnurl.IndexOf(rurl) < 0) { urlflag = true; } } if (urlflag) { var token = GetToken(); var tokenKey = String.IsNullOrEmpty(ConfigurationManager.AppSettings["TokenKey"]) ? String.Empty : ConfigurationManager.AppSettings["TokenKey"]; if (!string.IsNullOrEmpty(tokenKey) && !string.IsNullOrEmpty(token)) { if (linkUrl.IndexOf("?") >= 0) { linkUrl = linkUrl + "&" + tokenKey + "=" + token; } else { linkUrl = linkUrl + "?" + tokenKey + "=" + token; } } } linkTemplate = PortalHelper.SplitOnClick(linkTemplate, templateID, (isPortalMain ? id : "")); sbPortal.Append(linkTemplate.Replace(enumID, id).Replace(enumTitle, title).Replace(enumLinkUrl, linkUrl).Replace(enumHeight, height).Replace(enumPaddingBottom, bottom.ToString()).Replace(enumIsList, IsList ? "true" : "false").Replace(enumIsOldPortal, !IsUseNewPortal ? "true" : "false")); } } else { string temp = PortalHelper.GetPageHtml(linkUrl); temp = PortalHelper.SplitOnClick(temp, templateID, (isPortalMain ? id : "")); sbPortal.Append(temp.Replace(enumID, id).Replace(enumTitle, title).Replace(enumLinkList, randomID).Replace(enumMoreID, randomID).Replace(enumMoreUrl, moreUrl).Replace(enumLinkUrl, linkUrl).Replace(enumHeight, height).Replace(enumPaddingBottom, bottom.ToString()).Replace(enumIsList, IsList ? "true" : "false").Replace(enumIsOldPortal, !IsUseNewPortal ? "true" : "false")); } break; case PortalType.Default: string defaultPath = HomePageTemplet + "default.js"; string defaultTemplet = PortalHelper.GetPageHtml(defaultPath); defaultTemplet = PortalHelper.SplitOnClick(defaultTemplet, templateID, (isPortalMain ? id : "")); sbPortal.Append(defaultTemplet.Replace(enumID, id).Replace(enumTitle, title).Replace(enumLinkList, randomID).Replace(enumMoreID, randomID).Replace(enumMoreUrl, moreUrl).Replace(enumLinkUrl, linkUrl).Replace(enumHeight, height).Replace(enumPaddingBottom, bottom.ToString()).Replace(enumIsList, IsList ? "true" : "false").Replace(enumIsOldPortal, !IsUseNewPortal ? "true" : "false")); break; } } } sb.Replace(portals, sbPortal.ToString()); } } } } } catch (Exception exp) { throw new Exception("门户配置有误,请联系管理员!"); } return(sb.ToString()); }
public static List <Dictionary <string, string> > GetPortalIndexHTML(string systemName) { List <Dictionary <string, string> > portals = new List <Dictionary <string, string> >(); try { Dictionary <string, string> explainDic = new Dictionary <string, string>(); explainDic.SetValue("ID", FormulaHelper.CreateGuid()); explainDic.SetValue("Key", "explain"); explainDic.SetValue("Title", "首页"); explainDic.SetValue("Count", "1"); explainDic.SetValue("Html", "<img class='nologin_home_ad' src='/PortalLTE/Images/ad.png'>"); portals.Add(explainDic); SQLHelper sqlHelper = SQLHelper.CreateSqlHelper(ConnEnum.Base); var portalTemplet = GetUserRoleTemplets(!string.IsNullOrEmpty(systemName) ? FormulaHelper.UserID : ""); if (portalTemplet.Rows.Count > 0) { var items = JsonHelper.ToObject <List <Dictionary <string, object> > >(portalTemplet.Rows[0]["Items"].ToString()).OrderBy(c => c.GetValue("SortIndex")).ToList(); for (var i = 0; i < items.Count; i++) { StringBuilder sbPortal = new StringBuilder(); var type = items[i].GetValue("Type"); if (type == NewPortalType.Image.ToString()) //图片新闻 { var randomID = (new Random().Next(0, 99999999) + i).ToString(); string normalPath = HomePageTemplet + "image.js"; string normalTemplet = PortalHelper.GetPageHtml(normalPath); sbPortal.Append(normalTemplet.Replace(enumLinkList, randomID)); } else { List <S_I_PublicInformCatalog> tabList = new List <S_I_PublicInformCatalog>(); var catalogs = sqlHelper.ExecuteDataTable("select * from S_I_PublicInformCatalog"); var keys = items[i].GetValue("Keys").Split(','); foreach (var key in keys) { var dr = catalogs.Select(string.Format(" CatalogKey='{0}'", key)); if (dr != null && dr.Count() > 0) { tabList.Add(new S_I_PublicInformCatalog() { ID = dr[0]["ID"].ToString(), CatalogKey = dr[0]["CatalogKey"].ToString(), CatalogName = dr[0]["CatalogName"].ToString() }); } } foreach (var key in keys) { var dr = catalogs.Select(string.Format(" CatalogKey='{0}'", key)); if (dr != null && dr.Count() > 0) { var randomID = (new Random().Next(0, 99999999) + i).ToString(); string normalPath = HomePageTemplet + "normal.js"; string normalTemplet = PortalHelper.GetPageHtml(normalPath); sbPortal.Append(normalTemplet.Replace(enumID, key).Replace(enumLinkList, randomID).Replace(enumTabListData, JsonHelper.ToJson(tabList)).Replace(enumBackgroundColor, "")); break; } } } if (!string.IsNullOrEmpty(sbPortal.ToString())) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.SetValue("ID", FormulaHelper.CreateGuid()); dic.SetValue("Key", items[i].GetValue("Keys")); dic.SetValue("Title", items[i].GetValue("Title")); if (items[i].ContainsKey("Count")) { dic.SetValue("Count", items[i].GetValue("Count")); } dic.SetValue("Html", sbPortal.ToString()); portals.Add(dic); } } } } catch (Exception exp) { throw new Exception("门户配置有误,请联系管理员!"); } return(portals); }