diff --git a/App_Code/dbClass.cs b/App_Code/dbClass.cs index bf4e9c0..9d6489a 100644 --- a/App_Code/dbClass.cs +++ b/App_Code/dbClass.cs @@ -6,6 +6,58 @@ using System.Collections.Generic; using System.Linq; using System.Web; +[Table("babyRec")] +public class babyRec +{ + [JsonIgnore] + [Key] + public int babyRec_sn { get; set; } = 0; + public string babyRec_uid { get; set; } = ""; + public string babyData_uid { get; set; } = ""; + public string babyRec_key { get; set; } = ""; + public string line_uid { get; set; } = ""; + public double babyRec_height { get; set; } = 0; + public double babyRec_inpercent { get; set; } = 0; + public double babyRec_middleHeight { get; set; } = 0; + public DateTime babyRec_recdate { get; set; } = DateTime.Now; + public int babyRec_recYear { get; set; } = 0; + public int babyRec_recMonth { get; set; } = 0; + public int babyRec_recDay { get; set; } = 0; + + public int babyRec_months { get; set; } = 0; + public string babyRec_yearMonthStr { get; set; } = ""; + public DateTime babyRec_createdate { get; set; } = DateTime.Now; +} + +[Table("babyData")] +public class babyData +{ + [JsonIgnore] + [Key] + public int babyData_sn { get; set; } = 0; + public string babyData_uid { get; set; } = ""; + public string line_uid { get; set; } = ""; + public string babyData_name { get; set; } = ""; + public DateTime babyData_birthday { get; set; } = DateTime.Now; + public string babyData_sexual { get; set; } = ""; + public string babyData_bindedLine { get; set; } = ""; + public DateTime babyData_createdate { get; set; } = DateTime.Now; + public DateTime babyData_bindeddate { get; set; } = DateTime.Now; +} + +[Table("lineUser")] +public class lineUser +{ + [JsonIgnore] + [Key] + public int lineUser_sn { get; set; } = 0; + public string lineUser_uid { get; set; } = ""; + public string line_uid { get; set; } = ""; + public string line_displayName { get; set; } = ""; + public DateTime lineUser_createdate { get; set; } = DateTime.Now; + public DateTime lineUser_modifydate { get; set; } = DateTime.Now; +} + [Table("login")] public class login { @@ -26,4 +78,45 @@ public class token public string token_isremember { get; set; } = ""; public DateTime token_createdate { get; set; } = DateTime.Now; public DateTime token_expireddate { get; set; } = DateTime.Now; -} \ No newline at end of file +} + +[Table("temp_m")] +public class temp_m +{ + [JsonIgnore] + [Key] + public string temp_month { get; set; } = ""; + public double temp_3 { get; set; } = 0; + public double temp_15 { get; set; } = 0; + public double temp_25 { get; set; } = 0; + public double temp_50 { get; set; } = 0; + public double temp_75 { get; set; } = 0; + public double temp_85 { get; set; } = 0; + public double temp_97 { get; set; } = 0; +} + +[Table("lenHeiTable")] +public class lenHeiTable +{ + [JsonIgnore] + [Key] + public int lenHeiTable_sn { get; set; } = 0; + public string lenHeiTable_sexual { get; set; } = ""; + public int lenHeiTable_month { get; set; } = 0; + public double lenHeiTable_minVal { get; set; } = 0; + public double lenHeiTable_maxVal { get; set; } = 0; + public int lenHeiTable_percent { get; set; } = 0; +} + +[Table("ipTable")] +public class ipTable +{ + [JsonIgnore] + [Key] + public int ipTable_sn { get; set; } = 0; + public string ipTable_address { get; set; } = ""; + public DateTime ipTable_createdate { get; set; } = DateTime.Now; + public DateTime ipTable_modifydate { get; set; } = DateTime.Now; + public string ipTable_create_user_uid { get; set; } = ""; +} + diff --git a/App_Code/globalClass.cs b/App_Code/globalClass.cs index db06070..bade81e 100644 --- a/App_Code/globalClass.cs +++ b/App_Code/globalClass.cs @@ -15,9 +15,83 @@ using System.Drawing; using System.IO; using System.Data.SqlClient; using System.Configuration; +using Org.BouncyCastle.Asn1.X509; public static class globalClass { + public static string YearMonthDiff(DateTime self, DateTime target) { + int years, months, days; + // 因為只需取量,不決定誰大誰小,所以如果self < target時要交換將大的擺前面 + if (self < target) + { + DateTime tmp = target; + target = self; + self = tmp; + } + + // 將年轉換成月份以便用來計算 + months = 12 * (self.Year - target.Year) + (self.Month - target.Month); + + // 如果天數要相減的量不夠時要向月份借天數補滿該月再來相減 + if (self.Day < target.Day) + { + months--; + days = DateTime.DaysInMonth(target.Year, target.Month) - target.Day + self.Day; + } + else + { + days = self.Day - target.Day; + } + + // 天數計算完成後將月份轉成年 + years = months / 12; + months = months % 12; + + return years.ToString() + "歲" + months.ToString() + "月"; + } + + public static int MonthDiff(DateTime self, DateTime target) + { + int years, months, days; + // 因為只需取量,不決定誰大誰小,所以如果self < target時要交換將大的擺前面 + if (self < target) + { + DateTime tmp = target; + target = self; + self = tmp; + } + + // 將年轉換成月份以便用來計算 + months = 12 * (self.Year - target.Year) + (self.Month - target.Month); + + // 如果天數要相減的量不夠時要向月份借天數補滿該月再來相減 + if (self.Day < target.Day) + { + months--; + days = DateTime.DaysInMonth(target.Year, target.Month) - target.Day + self.Day; + } + else + { + days = self.Day - target.Day; + } + + return months; + } + + public static string GetIPAddress() + { + System.Web.HttpContext context = System.Web.HttpContext.Current; + string sIPAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; + if (string.IsNullOrEmpty(sIPAddress)) + { + return context.Request.ServerVariables["REMOTE_ADDR"]; + } + else + { + string[] ipArray = sIPAddress.Split(new Char[] { ',' }); + return ipArray[0]; + } + } public static string CreateRandomCode(int Number) { string allChar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"; diff --git a/BackEnd/Login.aspx b/BackEnd/Login.aspx new file mode 100644 index 0000000..84961c5 --- /dev/null +++ b/BackEnd/Login.aspx @@ -0,0 +1,100 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="abbott_2024_event.BackEnd.Login" %> + + + + + + + + + + 後台登入 + + + + + + + + + + + + + + + + + +
+
+

+ + + + + + + + + Sign In +

+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ +
+ +
+ + + + + + + + + + + + + + + + diff --git a/BackEnd/Login.aspx.cs b/BackEnd/Login.aspx.cs new file mode 100644 index 0000000..fcdcf8f --- /dev/null +++ b/BackEnd/Login.aspx.cs @@ -0,0 +1,44 @@ +using Dapper; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace abbott_2024_event.BackEnd +{ + public partial class Login : System.Web.UI.Page + { + SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString")); + protected void Page_Load(object sender, EventArgs e) + { + string myIP = globalClass.GetIPAddress(); + + if (myIP == "::1") + { + myIP = "127.0.0.1"; + } + + Boolean isAllow = false; + + if (myIP == "127.0.0.1") + { + isAllow = true; + } + + ipTable ipTable = conn.QueryFirstOrDefault("select * from ipTable where ipTable_address = @ipTable_address", new { ipTable_address = myIP }); + + if (ipTable != null) { + isAllow = true; + } + + if (isAllow == false) + { + Response.Redirect("auth-error-v3.html"); + return; + } + } + } +} \ No newline at end of file diff --git a/BackEnd/Login.aspx.designer.cs b/BackEnd/Login.aspx.designer.cs new file mode 100644 index 0000000..06c73dc --- /dev/null +++ b/BackEnd/Login.aspx.designer.cs @@ -0,0 +1,17 @@ +//------------------------------------------------------------------------------ +// <自動產生> +// 這段程式碼是由工具產生的。 +// +// 變更這個檔案可能會導致不正確的行為,而且如果已重新產生 +// 程式碼,則會遺失變更。 +// +//------------------------------------------------------------------------------ + +namespace abbott_2024_event.BackEnd +{ + + + public partial class Login + { + } +} diff --git a/BackEnd/Main.Master b/BackEnd/Main.Master index 4c6da90..573b3b1 100644 --- a/BackEnd/Main.Master +++ b/BackEnd/Main.Master @@ -34,8 +34,7 @@ if (isCompact == true) document.querySelector('html').classList.add('preparing-compact-menu'); - - +
@@ -120,7 +119,10 @@ - + + @@ -153,7 +155,8 @@ - + +
diff --git a/BackEnd/Main.Master.cs b/BackEnd/Main.Master.cs index 9af5f60..5ad5e84 100644 --- a/BackEnd/Main.Master.cs +++ b/BackEnd/Main.Master.cs @@ -1,5 +1,7 @@ -using System; +using Dapper; +using System; using System.Collections.Generic; +using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; @@ -10,9 +12,39 @@ namespace abbott_2024_event.BackEnd public partial class Main : System.Web.UI.MasterPage { + SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString")); public authToken authToken; protected void Page_Load(object sender, EventArgs e) { + string myIP = globalClass.GetIPAddress(); + + if (myIP == "::1") + { + myIP = "127.0.0.1"; + } + + Boolean isAllow = false; + + if (myIP == "127.0.0.1") + { + isAllow = true; + } + + ipTable ipTable = conn.QueryFirstOrDefault("select * from ipTable where ipTable_address = @ipTable_address", new { ipTable_address = myIP }); + + if (ipTable != null) + { + isAllow = true; + } + + if (isAllow == false) + { + Response.Redirect("auth-error-v3.html"); + return; + } + + + authToken = new authToken(); if (authToken.user_isLogin == false) { diff --git a/BackEnd/Main.Master.designer.cs b/BackEnd/Main.Master.designer.cs index 79516e6..9a23679 100644 --- a/BackEnd/Main.Master.designer.cs +++ b/BackEnd/Main.Master.designer.cs @@ -14,15 +14,6 @@ namespace abbott_2024_event.BackEnd public partial class Main { - /// - /// head 控制項。 - /// - /// - /// 自動產生的欄位。 - /// 若要修改,請將欄位宣告從設計工具檔案移到程式碼後置檔案。 - /// - protected global::System.Web.UI.WebControls.ContentPlaceHolder head; - /// /// form1 控制項。 /// @@ -40,5 +31,14 @@ namespace abbott_2024_event.BackEnd /// 若要修改,請將欄位宣告從設計工具檔案移到程式碼後置檔案。 /// protected global::System.Web.UI.WebControls.ContentPlaceHolder ContentPlaceHolder1; + + /// + /// head 控制項。 + /// + /// + /// 自動產生的欄位。 + /// 若要修改,請將欄位宣告從設計工具檔案移到程式碼後置檔案。 + /// + protected global::System.Web.UI.WebControls.ContentPlaceHolder head; } } diff --git a/BackEnd/api/importTestData.ashx b/BackEnd/api/importTestData.ashx new file mode 100644 index 0000000..d732d4e --- /dev/null +++ b/BackEnd/api/importTestData.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="importTestData.ashx.cs" Class="abbott_2024_event.BackEnd.api.importTestData" %> diff --git a/BackEnd/api/importTestData.ashx.cs b/BackEnd/api/importTestData.ashx.cs new file mode 100644 index 0000000..9ea0925 --- /dev/null +++ b/BackEnd/api/importTestData.ashx.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Runtime.Serialization.Json; +using System.Web; +using System.Web.SessionState; +using Dapper; +using Dapper.Contrib.Extensions; + +namespace abbott_2024_event.BackEnd.api +{ + /// + /// importTestData 的摘要描述 + /// + public class importTestData : IHttpHandler + { + + + SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString")); + public void ProcessRequest(HttpContext context) + { + context.Response.ContentType = "text/plain"; + context.Response.Write("Hello World"); + + List tempList = conn.Query("select * from temp_f").ToList(); + + int intmonth = 0; + + foreach (temp_m tempm in tempList) { + + + double minVal = 0; + double maxVal = 0; + + for (int i = 1; i <= 8; i++) { + lenHeiTable newData = new lenHeiTable(); + + newData.lenHeiTable_month = intmonth; + newData.lenHeiTable_sexual = "F"; + + if (i == 1) { + maxVal = tempm.temp_3; + + newData.lenHeiTable_minVal = minVal; + newData.lenHeiTable_maxVal = maxVal; + newData.lenHeiTable_percent = 3; + + minVal = tempm.temp_3; + } + + if (i == 2) + { + maxVal = tempm.temp_15; + + newData.lenHeiTable_minVal = minVal; + newData.lenHeiTable_maxVal = maxVal; + newData.lenHeiTable_percent = 15; + + minVal = tempm.temp_15; + } + + if (i == 3) + { + maxVal = tempm.temp_25; + + newData.lenHeiTable_minVal = minVal; + newData.lenHeiTable_maxVal = maxVal; + newData.lenHeiTable_percent = 25; + + minVal = tempm.temp_25; + } + + if (i == 4) + { + maxVal = tempm.temp_50; + + newData.lenHeiTable_minVal = minVal; + newData.lenHeiTable_maxVal = maxVal; + newData.lenHeiTable_percent = 50; + + minVal = tempm.temp_50; + } + + if (i == 5) + { + maxVal = tempm.temp_75; + + newData.lenHeiTable_minVal = minVal; + newData.lenHeiTable_maxVal = maxVal; + newData.lenHeiTable_percent = 75; + + minVal = tempm.temp_75; + } + + if (i == 6) + { + maxVal = tempm.temp_85; + + newData.lenHeiTable_minVal = minVal; + newData.lenHeiTable_maxVal = maxVal; + newData.lenHeiTable_percent = 85; + + minVal = tempm.temp_85; + } + + if (i == 7) + { + maxVal = tempm.temp_97; + + newData.lenHeiTable_minVal = minVal; + newData.lenHeiTable_maxVal = maxVal; + newData.lenHeiTable_percent = 97; + + minVal = tempm.temp_97; + } + + if (i == 8) + { + maxVal = 999; + + newData.lenHeiTable_minVal = minVal; + newData.lenHeiTable_maxVal = maxVal; + newData.lenHeiTable_percent = 100; + + minVal = 0; + } + + conn.Insert(newData); + } + + intmonth++; + } + + + context.Response.ContentType = "text/plain"; + context.Response.Write("Hello World"); + + + } + + public bool IsReusable + { + get + { + return false; + } + } + } +} \ No newline at end of file diff --git a/BackEnd/api/ipList.ashx b/BackEnd/api/ipList.ashx new file mode 100644 index 0000000..0a20c72 --- /dev/null +++ b/BackEnd/api/ipList.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="ipList.ashx.cs" Class="abbott_2024_event.BackEnd.api.ipList" %> diff --git a/BackEnd/api/ipList.ashx.cs b/BackEnd/api/ipList.ashx.cs new file mode 100644 index 0000000..2c1d2a3 --- /dev/null +++ b/BackEnd/api/ipList.ashx.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Runtime.Serialization.Json; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System.Web.Services.Protocols; +using System.Security.Cryptography; +using System.Text; +using System.Web.SessionState; +using System.Data; +using System.IO.Compression; +using System.Data.SqlClient; +using Dapper; +using Dapper.Contrib.Extensions; + +namespace abbott_2024_event.BackEnd.api +{ + /// + /// ipList 的摘要描述 + /// + public class ipList : IHttpHandler, IReadOnlySessionState + { + SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString")); + 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(); + + string allowAnyIP = (context.Request["allow"] == null) ? "" : context.Request["allow"].ToString(); + string iplist = (context.Request["iplist"] == null) ? "[]" : context.Request["iplist"].ToString(); + string method = (context.Request["method"] == null) ? "" : context.Request["method"].ToString(); + + if (!objAuth.user_isLogin) + { + objRet.ret = "no"; + objRet.err_code = "0001"; + objRet.message = "尚未登入,請登入後使用"; + json.WriteObject(context.Response.OutputStream, objRet); + return; + } + + if (method == "") + { + objRet.ret = "no"; + objRet.err_code = "0003"; + objRet.message = "無method"; + json.WriteObject(context.Response.OutputStream, objRet); + return; + } + + if (method == "get") { + List ipTables = conn.Query("select * from ipTable").ToList(); + + foreach (ipTable ipTable in ipTables) { + objRet.ipList.Add(ipTable.ipTable_address); + } + objRet.ret = "yes"; + json.WriteObject(context.Response.OutputStream, objRet); + return; + } + + if (method == "edit") { + dynamic ipJsonObj; + + ipJsonObj = JValue.Parse(iplist); + + conn.Execute("delete ipTable"); + + foreach (string item in ipJsonObj) + { + if (item != "") { + ipTable newIp = new ipTable(); + newIp.ipTable_address = item; + newIp.ipTable_create_user_uid = "admin"; + conn.Insert(newIp); + } + } + + objRet.ret = "yes"; + json.WriteObject(context.Response.OutputStream, objRet); + return; + } + } + + public class result + { + public string ret = "no"; + public string err_code = "0000"; + public string message = ""; + public string allowAnyIP = "N"; + public List ipList = new List(); + } + + public bool IsReusable + { + get + { + return false; + } + } + } +} \ No newline at end of file diff --git a/BackEnd/auth-error-v3.html b/BackEnd/auth-error-v3.html new file mode 100644 index 0000000..002b8f8 --- /dev/null +++ b/BackEnd/auth-error-v3.html @@ -0,0 +1,99 @@ + + + + + + + + Error 404: Page not found | Looper - Bootstrap 4 Admin Theme + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ +
+
+

+ 4 4 +

+

Page not found!

+

Sorry, we've misplaced that URL or it's pointing to something that doesn't exist.

+ +
+
+
+
+ + + + + + + + + + + \ No newline at end of file diff --git a/BackEnd/ip-management.aspx b/BackEnd/ip-management.aspx new file mode 100644 index 0000000..5d4e57f --- /dev/null +++ b/BackEnd/ip-management.aspx @@ -0,0 +1,116 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/BackEnd/Main.Master" AutoEventWireup="true" CodeBehind="ip-management.aspx.cs" Inherits="abbott_2024_event.BackEnd.ip_management" %> + + + + + +
+ +
+ + + +
+

IP清單

+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+ + +
+ +
+ +
+
請在上方輸入可以存取的IP位置,每行一組IP。
+
+
+
+ +
+
+ +
+
+
+
+
+
diff --git a/BackEnd/ip-management.aspx.cs b/BackEnd/ip-management.aspx.cs new file mode 100644 index 0000000..c448ab6 --- /dev/null +++ b/BackEnd/ip-management.aspx.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace abbott_2024_event.BackEnd +{ + public partial class ip_management : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/BackEnd/ip-management.aspx.designer.cs b/BackEnd/ip-management.aspx.designer.cs new file mode 100644 index 0000000..32f2387 --- /dev/null +++ b/BackEnd/ip-management.aspx.designer.cs @@ -0,0 +1,17 @@ +//------------------------------------------------------------------------------ +// <自動產生> +// 這段程式碼是由工具產生的。 +// +// 變更這個檔案可能會導致不正確的行為,而且如果已重新產生 +// 程式碼,則會遺失變更。 +// +//------------------------------------------------------------------------------ + +namespace abbott_2024_event.BackEnd +{ + + + public partial class ip_management + { + } +} diff --git a/abbott_2024_event.csproj b/abbott_2024_event.csproj index acaf3c6..6123a8b 100644 --- a/abbott_2024_event.csproj +++ b/abbott_2024_event.csproj @@ -13152,7 +13152,10 @@ + + + @@ -13162,6 +13165,12 @@ + + importTestData.ashx + + + ipList.ashx + signin.ashx @@ -13172,6 +13181,20 @@ Index.aspx + + ip-management.aspx + ASPXCodeBehind + + + ip-management.aspx + + + Login.aspx + ASPXCodeBehind + + + Login.aspx + Main.Master ASPXCodeBehind @@ -13187,10 +13210,12 @@ Default.aspx + + babyData.ashx + - @@ -17653,6 +17678,8 @@ + + Web.config @@ -17660,6 +17687,7 @@ Web.config + 10.0 diff --git a/bin/abbott_2024_event.dll b/bin/abbott_2024_event.dll index efc80f2..cd3585a 100644 Binary files a/bin/abbott_2024_event.dll and b/bin/abbott_2024_event.dll differ diff --git a/webapi/babyData.ashx b/webapi/babyData.ashx new file mode 100644 index 0000000..671bfc2 --- /dev/null +++ b/webapi/babyData.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="babyData.ashx.cs" Class="abbott_2024_event.webapi.babyData" %> diff --git a/webapi/babyData.ashx.cs b/webapi/babyData.ashx.cs new file mode 100644 index 0000000..b3a3e22 --- /dev/null +++ b/webapi/babyData.ashx.cs @@ -0,0 +1,245 @@ +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; + +namespace abbott_2024_event.webapi +{ + /// + /// babyData 的摘要描述 + /// + public class babyDataAshx : IHttpHandler + { + SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString")); + public void ProcessRequest(HttpContext context) + { + result objRet = new result(); + DataContractJsonSerializer json = new DataContractJsonSerializer(objRet.GetType()); + context.Response.ContentType = "application/json;charset=utf-8"; + + string name = (context.Request["name"] == null) ? "" : context.Request["name"].ToString(); + string birthday = (context.Request["birthday"] == null) ? "" : context.Request["birthday"].ToString(); + string gender = (context.Request["gender"] == null) ? "" : context.Request["gender"].ToString(); + string height = (context.Request["height"] == null) ? "" : context.Request["height"].ToString(); + string line_uid = (context.Request["line_uid"] == null) ? "" : context.Request["line_uid"].ToString(); + string line_displayname = (context.Request["line_displayname"] == null) ? "" : context.Request["line_displayname"].ToString(); + string babyData_uid = (context.Request["babyData_uid"] == null) ? "" : context.Request["babyData_uid"].ToString(); + + + string babyRec_key = globalClass.CreateRandomCode(32); + + + string delSQLDatastring = string.Format("delete babyData where line_uid = '' and babyData_createdate <= '{0}'", DateTime.Now.AddDays(-5).ToString("yyyy/MM/dd 23:59:59")); + string delSQLRecstring = string.Format("delete babyRec where line_uid = '' and babyRec_createdate <= '{0}'", DateTime.Now.AddDays(-5).ToString("yyyy/MM/dd 23:59:59")); + + conn.Execute(delSQLDatastring); + conn.Execute(delSQLRecstring); + + + + if (babyData_uid == "" && name == "") { + objRet.ret = "no"; + objRet.err_code = "1001"; + objRet.message = "請輸入寶貝姓名!"; + + json.WriteObject(context.Response.OutputStream, objRet); + } + + DateTime dateBirthDay; + + if (babyData_uid == "") { + try + { + dateBirthDay = DateTime.Parse(birthday + " 23:59:59"); + } + catch (Exception ex) + { + objRet.ret = "no"; + objRet.err_code = "1002"; + objRet.message = "請輸入正確的寶貝生日!" + ex.Message; + + json.WriteObject(context.Response.OutputStream, objRet); + } + } + + + if (babyData_uid == "" && gender != "M" && gender != "F") { + objRet.ret = "no"; + objRet.err_code = "1003"; + objRet.message = "請輸入正確的寶貝性別!"; + + json.WriteObject(context.Response.OutputStream, objRet); + } + + double dblHeight; + + try + { + dblHeight = Double.Parse(height); + } + catch (Exception ex) { + objRet.ret = "no"; + objRet.err_code = "1004"; + objRet.message = "請輸入寶貝身高!" + ex.Message; + + json.WriteObject(context.Response.OutputStream, objRet); + } + + if (line_uid != null) { + lineUser lineUser = conn.QueryFirstOrDefault("select * from lineUser where line_uid = @line_uid", new { line_uid = line_uid }); + + if (lineUser != null) + { + if (line_displayname != lineUser.line_displayName && line_displayname != "") + { + lineUser.line_displayName = line_displayname; + lineUser.lineUser_modifydate = DateTime.Now; + conn.Update(lineUser); + } + + List babyDatas = conn.Query("select * from babyData where line_uid = @line_uid", new { line_uid = line_uid }).ToList(); + + if (babyDatas.Count > 0) { + objRet.more_data = "Y"; + } + } + else { + lineUser = new lineUser(); + + if (line_displayname == null) { + objRet.ret = "no"; + objRet.err_code = "1005"; + objRet.message = "請輸入Line Display Name!"; + + json.WriteObject(context.Response.OutputStream, objRet); + } + + lineUser.lineUser_uid = globalClass.CreateRandomCode(32); + lineUser.line_uid = line_uid; + lineUser.line_displayName = line_displayname; + + conn.Insert(lineUser); + + } + } + + babyData newBaby; + + if (babyData_uid == "") + { + babyData_uid = globalClass.CreateRandomCode(32); + + newBaby = new babyData(); + newBaby.babyData_uid = babyData_uid; + newBaby.babyData_birthday = DateTime.Parse(birthday + " 23:59:59"); + newBaby.babyData_name = name; + newBaby.babyData_sexual = gender; + + if (line_uid != "") + { + newBaby.line_uid = line_uid; + newBaby.babyData_bindedLine = "Y"; + newBaby.babyData_bindeddate = DateTime.Now; + } + + conn.Insert(newBaby); + } + else { + newBaby = conn.QueryFirstOrDefault("select * from babyData where babyData_uid = @babyData_uid", new { babyData_uid = babyData_uid }); + + if (newBaby == null) { + objRet.ret = "no"; + objRet.err_code = "1008"; + objRet.message = "無此babyData_uid的寶貝資料!"; + + json.WriteObject(context.Response.OutputStream, objRet); + } + + babyData_uid = newBaby.babyData_uid; + } + + + + babyRec newRec = new babyRec(); + newRec.babyData_uid = babyData_uid; + newRec.line_uid = line_uid; + newRec.babyRec_key = babyRec_key; + newRec.babyRec_recdate = DateTime.Now; + newRec.babyRec_uid = "r_" + globalClass.CreateRandomCode(32); + newRec.babyRec_recYear = newRec.babyRec_recdate.Year; + newRec.babyRec_recMonth = newRec.babyRec_recdate.Month; + newRec.babyRec_recDay = newRec.babyRec_recdate.Day; + newRec.babyRec_height = double.Parse(height); + newRec.babyRec_months = globalClass.MonthDiff(newBaby.babyData_birthday, newRec.babyRec_recdate); + newRec.babyRec_yearMonthStr = globalClass.YearMonthDiff(newBaby.babyData_birthday, newRec.babyRec_recdate); + + if (newRec.babyRec_months > 120) { + objRet.ret = "no"; + objRet.err_code = "1006"; + objRet.message = "寶貝年齡超過10歲,已過紀錄範圍!"; + + json.WriteObject(context.Response.OutputStream, objRet); + } + + if (line_uid != "") { + + } + + lenHeiTable objLenHei = conn.QueryFirstOrDefault("select * from lenHeiTable where lenHeiTable_sexual = @gender and lenHeiTable_month = @month and lenHeiTable_minVal < @height1 and lenHeiTable_maxVal >= @height2 ", new { gender = gender, month = newRec.babyRec_months, height1 = height, height2 = height}); + lenHeiTable objMidHei = conn.QueryFirstOrDefault("select * from lenHeiTable where lenHeiTable_sexual = @gender and lenHeiTable_month = @month and lenHeiTable_percent = 50", new { gender = gender, month=newRec.babyRec_months }); + + if (objLenHei == null) { + objRet.ret = "no"; + objRet.err_code = "1007"; + objRet.message = "無符合此身高年齡條件的數據!"; + + json.WriteObject(context.Response.OutputStream, objRet); + } + + newRec.babyRec_inpercent = objLenHei.lenHeiTable_percent; + newRec.babyRec_middleHeight = objMidHei.lenHeiTable_maxVal; + + conn.Insert(newRec); + + objRet.temp_key = babyRec_key; + objRet.baby_data.baby_birthday = birthday; + objRet.baby_data.baby_height = newRec.babyRec_height; + objRet.baby_data.baby_age = newRec.babyRec_yearMonthStr; + objRet.baby_data.average_height = newRec.babyRec_middleHeight; + objRet.ret = "yes"; + + json.WriteObject(context.Response.OutputStream, objRet); + } + + public class result + { + public string ret = "no"; + public string err_code = "0000"; + public string message = ""; + public string temp_key = ""; + public string more_data = "N"; + public baby baby_data = new baby(); + } + + public class baby + { + public string baby_birthday { get; set; } = ""; + public string baby_age { get; set; } = ""; + public double baby_height { get; set; } = 0.0; + public double average_height { get; set; } = 0.0; + } + + public bool IsReusable + { + get + { + return false; + } + } + } +} \ No newline at end of file