Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. <%@ WebHandler Language="C#" Class="CheckLogOP" %>
  2.  
  3. using System.Data;
  4. using System.Web;
  5. using System.Web.SessionState;
  6. using System.Collections.Generic;
  7. using Newtonsoft.Json;
  8. using System.Data.SqlClient;
  9. using System.Web.Configuration;
  10.  
  11. public class CheckLogOP : IHttpHandler, IRequiresSessionState
  12. {
  13.  
  14. public void ProcessRequest(HttpContext context)
  15. {
  16. AllowHttpMethod(context.Request.HttpMethod,"POST");
  17.  
  18. string jsonString = HttpContext.Current.Request.Form["o"] ?? "";
  19. var VM = JsonConvert.DeserializeObject<PassLogVM>(QueryStringEncryptToolS.Decrypt(jsonString));
  20. //var VM = JsonConvert.DeserializeObject<PassLogVM>(jsonString);
  21.  
  22. DataTable dt = new DataTable();
  23.  
  24. string SQL = string.Format("select CreateType,ChangeDate,ChangeUserID,ChangeOrgID from {0} where 1=1 ", VM.TableName);
  25.  
  26. if (VM.WhereDict == null)
  27. {
  28. return;
  29. }
  30.  
  31. foreach (var item in VM.WhereDict)
  32. {
  33. SQL = SQL + string.Format(" and {0}='{1}' ",item.Key.Trim('@'),item.Value.ToString());
  34. }
  35.  
  36. using (SqlConnection sc = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnLog"].ToString()))
  37. {
  38. using (SqlCommand cmd = new SqlCommand(SQL, sc))
  39. {
  40. using (SqlDataAdapter da = new SqlDataAdapter(cmd))
  41. {
  42. sc.Open();
  43. da.Fill(dt);
  44. }
  45.  
  46. }
  47. }
  48.  
  49. List<GeneralLogVM> list = new List<GeneralLogVM>();
  50.  
  51. WayneEntity.EntityS.FillModel(list, dt);
  52.  
  53. Dictionary<string, object> dict = new Dictionary<string, object>();
  54.  
  55. if (list.Count > 0)
  56. {
  57. dict["chk"] = 1;
  58. }
  59. else
  60. {
  61. dict["chk"] = 0;
  62. }
  63. var msg1 = list.Find(item => item.CreateType == 1);
  64. dict["msg1"] = msg1;
  65. list.Remove(msg1);
  66. dict["msg2"] = list;
  67.  
  68. context.Response.ContentType = "application/json; charset=utf-8";
  69. context.Response.Write(JsonConvert.SerializeObject(dict));
  70. context.Response.End();
  71.  
  72. }
  73.  
  74. public bool IsReusable
  75. {
  76. get
  77. {
  78. return false;
  79. }
  80. }
  81.  
  82. protected void AllowHttpMethod(string myMethod,params string[] methods)
  83. {
  84. bool HasPower = false;
  85.  
  86. System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(methods);
  87.  
  88. for (int i = 0; i <= methods.Length - 1; i++)
  89. {
  90. if (methods[i].Trim().ToUpper().Equals(myMethod))
  91. {
  92. HasPower = true;
  93. break;
  94. }
  95. }
  96.  
  97.  
  98. if (HasPower == false)
  99. {
  100. throw new HttpException(404, "Not found");
  101. //Response.Redirect("~/html/ErrorPage/NoPower.html");
  102. //string myScript = "<script>alert('您無權操作此頁面');history.go(-1);</script>";
  103. //Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "DisableTop", myScript, false);
  104. }
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement