app.news.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using SQLData;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Utils;
  9. namespace SiteCore.Handler
  10. {
  11. public partial class app
  12. {
  13. public void get_indexnews()
  14. {
  15. //string session_id = con.Request.Headers["session-id"];
  16. //if (session_id == "")
  17. //{
  18. // conError("请重新登录");
  19. // return;
  20. //}
  21. //object re = RedisHelper.StringGet(session_id);
  22. //if (re == null)
  23. //{
  24. // conError("请重新登录");
  25. // return;
  26. //}
  27. //RedisHelper.StringGet()
  28. DataStruct dStruct = GetPostStruct();
  29. dStruct.PageSize = 3;
  30. List<string> lw = new List<string>();
  31. //lw.Add("state=1");
  32. string order = "";
  33. string key = GetString("key");
  34. if (key.Length > 0) lw.Add(string.Format("title like '%{0}%'", key));
  35. dStruct.Order = "addtime desc";
  36. //lw.Add(" newstypeid=1 ");
  37. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  38. dStruct.Fileds = "id,title,sectitle,coverimage as img,addtime as pubtime";
  39. DataTable dt = WebCache.GetData("s_news", dStruct);
  40. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  41. }
  42. public void get_news()
  43. {
  44. DataStruct dStruct = GetPostStruct();
  45. List<string> lw = new List<string>();
  46. //lw.Add("state=1");
  47. int tid = GetPostInt("tid");
  48. if (tid > 0)
  49. {
  50. lw.Add(string.Format("newstypeid={0}", tid));
  51. }
  52. string key = GetString("key");
  53. if (key.Length > 0) lw.Add(string.Format("title like '%{0}%'", key));
  54. dStruct.Order = "addtime desc";
  55. //lw.Add(" newstypeid=1 ");
  56. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  57. dStruct.Fileds = "id,title,sectitle,coverimage as img,addtime as pubtime";
  58. DataTable dt = WebCache.GetData("s_news", dStruct);
  59. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  60. }
  61. public void get_newstype()
  62. {
  63. string sql = "select id,name from s_newstype order by sort";
  64. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  65. conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  66. }
  67. public void get_news_info()
  68. {
  69. if (UrlPostParmsCheck("nid"))
  70. {
  71. int nid = GetPostInt("nid");
  72. //int nid = 3;
  73. string sql = "select title,sectitle,coverimage as img,addtime as pubtime,summary from s_news where id=" + nid;
  74. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  75. if (dt != null && dt.Rows.Count > 0)
  76. {
  77. //foreach (DataRow dr in dt.Rows)
  78. //{
  79. // dr["summary"] = ReplaceHtmlTag(dr["summary"].ToString());
  80. //}
  81. conGridJson(1, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  82. return;
  83. }
  84. }
  85. conError("找不到该资讯");
  86. }
  87. public static string ReplaceHtmlTag(string html, int length = 0)
  88. {
  89. string strText = System.Text.RegularExpressions.Regex.Replace(html, "<[^>]+>", "");
  90. strText = System.Text.RegularExpressions.Regex.Replace(strText, "&[^;]+;", "");
  91. if (length > 0 && strText.Length > length)
  92. return strText.Substring(0, length);
  93. return strText;
  94. }
  95. }
  96. }