using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Runtime.Serialization.Json; using System.Web.SessionState; using Dapper; using Dapper.Contrib.Extensions; using System.Data.SqlClient; using System.IO.Compression; namespace abbott_2024_event.BackEnd.api { /// /// clearAllData 的摘要描述 /// public class clearAllData : IHttpHandler { SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString")); public authToken authToken; public void ProcessRequest(HttpContext context) { result objRet = new result(); DataContractJsonSerializer json = new DataContractJsonSerializer(objRet.GetType()); context.Response.ContentType = "application/json;charset=utf-8"; context.Response.AddHeader("Access-Control-Allow-Origin", "*"); string acceptEncoding = context.Request.Headers["Accept-Encoding"].ToString().ToUpperInvariant(); if (!String.IsNullOrEmpty(acceptEncoding)) { if (acceptEncoding.Contains("GZIP")) { //输出流头部GZIP压缩 context.Response.AppendHeader("Content-encoding", "gzip"); context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress); } else if (acceptEncoding.Contains("DEFLATE")) { //输出流头部DEFLATE压缩 context.Response.AppendHeader("Content-encoding", "deflate"); context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress); } } authToken objAuth = new authToken(); if (!objAuth.user_isLogin) { objRet.ret = "no"; objRet.err_code = "0001"; objRet.message = "尚未登入,請登入後使用"; json.WriteObject(context.Response.OutputStream, objRet); return; } string type = (context.Request["type"] == null) ? "" : context.Request["type"].ToString(); string myIP = globalClass.GetIPAddress(); if (myIP == "::1") { myIP = "127.0.0.1"; } Boolean isAllow = false; if (myIP == "127.0.0.1") { isAllow = true; } string myIP_2 = myIP.Substring(0, myIP.LastIndexOf('.')); if (myIP_2 == "60.251.161") { isAllow = true; } //isAllow = false; if (isAllow == false) { objRet.ret = "no"; objRet.err_code = "0002"; objRet.message = "IP錯誤無法操作!"; json.WriteObject(context.Response.OutputStream, objRet); return; } if (type == "") { objRet.ret = "no"; objRet.err_code = "0003"; objRet.message = "無type!"; json.WriteObject(context.Response.OutputStream, objRet); return; } if (type == "all") { conn.Execute("delete from babyRec where babyRec_createdate <= '2025/3/31 23:59:59' "); conn.Execute("delete from babyData where babyData_createdate <= '2025/3/31 23:59:59' "); conn.Execute("delete from lineUser where lineUser_createdate <= '2025/3/31 23:59:59' "); } if (type == "babyRec") { conn.Execute("delete from babyRec where babyRec_createdate <= '2025/3/31 23:59:59' "); } if (type == "babyData") { conn.Execute("delete from babyData where babyData_createdate <= '2025/3/31 23:59:59' "); conn.Execute("delete from babyRec where babyRec_createdate <= '2025/3/31 23:59:59' "); } objRet.ret = "yes"; json.WriteObject(context.Response.OutputStream, objRet); return; } public bool IsReusable { get { return false; } } public class result { public string ret = "no"; public string err_code = "0000"; public string message = ""; } } }