public static string Parse(string stlElement, XmlNode node, PageInfo pageInfo, ContextInfo contextInfo) { string parsedContent; try { var diggType = EDiggType.All; var goodText = "顶一下"; var badText = "踩一下"; var theme = "style1"; var isNumber = false; var isDynamic = false; var ie = node.Attributes?.GetEnumerator(); if (ie != null) { while (ie.MoveNext()) { var attr = (XmlAttribute)ie.Current; var attributeName = attr.Name.ToLower(); if (attributeName.Equals(AttributeType)) { diggType = EDiggTypeUtils.GetEnumType(attr.Value); } else if (attributeName.Equals(AttributeGoodText)) { goodText = attr.Value; } else if (attributeName.Equals(AttributeBadText)) { badText = attr.Value; } else if (attributeName.Equals(AttributeTheme)) { theme = attr.Value; } else if (attributeName.Equals(AttributeIsNumber)) { isNumber = TranslateUtils.ToBool(attr.Value); } else if (attributeName.Equals(AttributeIsDynamic)) { isDynamic = TranslateUtils.ToBool(attr.Value); } } } pageInfo.AddPageScriptsIfNotExists(PageInfo.Components.Jquery); parsedContent = isDynamic ? StlDynamic.ParseDynamicElement(stlElement, pageInfo, contextInfo) : ParseImpl(pageInfo, contextInfo, diggType, goodText, badText, theme, isNumber); } catch (Exception ex) { parsedContent = StlParserUtility.GetStlErrorMessage(ElementName, ex); } return(parsedContent); }
public static string GetUrl(string apiUrl, int publishmentSystemId, int relatedIdentity, int updaterId, EDiggType diggType, string goodText, string badText, string theme, bool isDigg, bool isGood) { apiUrl = PageUtils.Combine(apiUrl, Route); apiUrl = apiUrl.Replace("{publishmentSystemId}", publishmentSystemId.ToString()); return(PageUtils.AddQueryString(apiUrl, new NameValueCollection { { "relatedIdentity", relatedIdentity.ToString() }, { "updaterId", updaterId.ToString() }, { "diggType", EDiggTypeUtils.GetValue(diggType) }, { "goodText", TranslateUtils.EncryptStringBySecretKey(goodText) }, { "badText", TranslateUtils.EncryptStringBySecretKey(badText) }, { "theme", theme }, { "isDigg", isDigg.ToString() }, { "isGood", isGood.ToString() } })); }
public void Main(int publishmentSystemId) { var queryString = HttpContext.Current.Request.QueryString; var updaterId = int.Parse(queryString["updaterId"]); var relatedIdentity = int.Parse(queryString["relatedIdentity"]); var diggType = EDiggTypeUtils.GetEnumType(queryString["diggType"]); var goodText = TranslateUtils.DecryptStringBySecretKey(queryString["goodText"]); var badText = TranslateUtils.DecryptStringBySecretKey(queryString["badText"]); var theme = queryString["theme"]; var isDigg = TranslateUtils.ToBool(queryString["isDigg"]); var isGood = TranslateUtils.ToBool(queryString["isGood"]); if (isDigg) { BaiRongDataProvider.DiggDao.AddCount(publishmentSystemId, relatedIdentity, isGood); } var counts = BaiRongDataProvider.DiggDao.GetCount(publishmentSystemId, relatedIdentity); var goodNum = counts[0]; var badNum = counts[1]; var goodDisplay = diggType != EDiggType.Bad ? "" : "display: none"; var badDisplay = diggType != EDiggType.Good ? "" : "display: none"; var clickStringOfGood = $"stlDiggSet_{updaterId}(true);return false;"; var clickStringOfBad = $"stlDiggSet_{updaterId}(false);return false;"; decimal goodPercentage; decimal badPercentage; if (goodNum == 0 && badNum == 0) { goodPercentage = 0; badPercentage = 0; } else if (goodNum > 0 && badNum == 0) { goodPercentage = 100; badPercentage = 0; } else if (goodNum == 0 && badNum > 0) { goodPercentage = 0; badPercentage = 100; } else { goodPercentage = Math.Round((Convert.ToDecimal(goodNum) / Convert.ToDecimal(goodNum + badNum)) * Convert.ToDecimal(100)); badPercentage = 100 - goodPercentage; } var retval = string.Empty; if (theme == "style1") { retval = string.Format($@" <div class=""newdigg"" id=""newdigg""> <div class=""diggbox digg_good"" onmousemove=""this.style.backgroundPosition='left bottom';"" onmouseout=""this.style.backgroundPosition='left top';"" onclick=""{clickStringOfGood}"" style=""display:{goodDisplay}""> <div class=""digg_act"">{goodText}</div> <div class=""digg_num"">({goodNum})</div> <div class=""digg_percent""> <div class=""digg_percent_bar""><span style=""width:{goodPercentage}%""></span></div> <div class=""digg_percent_num"">{goodPercentage}%</div> </div> </div> <div class=""diggbox digg_bad"" onmousemove=""this.style.backgroundPosition='right bottom';"" onmouseout=""this.style.backgroundPosition='right top';"" onclick=""{clickStringOfBad}"" style=""{badDisplay}""> <div class=""digg_act"">{badText}</div> <div class=""digg_num"">({badNum})</div> <div class=""digg_percent""> <div class=""digg_percent_bar""><span style=""width:{badPercentage}%""></span></div> <div class=""digg_percent_num"">{badPercentage}%</div> </div> </div> </div>"); } else if (theme == "style2") { retval = string.Format($@" <table border=""0"" cellpadding=""0"" cellspacing=""8"" class=""newdigg""> <tr> <td style=""{goodDisplay}""> <table border=""0"" align=""center"" cellpadding=""0"" cellspacing=""0"" class=""digg""> <tr> <td class=""diggnum"" id=""diggnum""> <strong>{goodNum}</strong> </td> </tr> <tr> <td class=""diggit""> <a href=""javascript:;"" onclick=""{clickStringOfGood}"">{goodText}</a> </td> </tr> </table> </td> <td style=""{badDisplay}""> <table border=""0"" align=""center"" cellpadding=""0"" cellspacing=""0"" class=""digg""> <tr> <td class=""diggnum"" id=""diggnum""> <strong>{badNum}</strong> </td> </tr> <tr> <td class=""diggit""> <a href=""javascript:;"" onclick=""{clickStringOfBad}"">{badText}</a> </td> </tr> </table> </td> </tr> </table> "); } else if (theme == "style3") { retval = string.Format($@" <table> <tr> <td align=""center"" style=""{goodDisplay}""> <a class=""diggLink"" href=""javascript:;"" onclick=""{clickStringOfGood}"">{goodText}</a> <span class=""diggNum"">{goodNum}票</span> </td> <td align=""center"" style=""{badDisplay}""> <a class=""diggLink"" href=""javascript:;"" onclick=""{clickStringOfBad}"">{badText}</a> <span class=""diggNum"">{badNum}票</span> </td> </tr> </table> "); } else if (theme == "style4") { retval = string.Format($@" <div> <div class=""diggArea"" style=""{goodDisplay}""> <div class=""diggNum"">{goodNum}</div> <div class=""diggLink""><a href=""javascript:;"" onclick=""{clickStringOfGood}"">{goodText}</a></div> </div> <div class=""diggArea"" style=""{badDisplay}""> <div class=""diggNum"">{badNum}</div> <div class=""diggLink""><a href=""javascript:;"" onclick=""{clickStringOfBad}"">{badText}</a></div> </div> </div> "); } HttpContext.Current.Response.Write(retval); HttpContext.Current.Response.End(); }