123 lines
4.9 KiB
C#
123 lines
4.9 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// chgBabyData 的摘要描述
|
|
/// </summary>
|
|
public class chgBabyData : 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 babyData_uid = (context.Request["babyData_uid"] == null) ? "" : context.Request["babyData_uid"].ToString();
|
|
string babyData_name = (context.Request["babyData_name"] == null) ? "" : context.Request["babyData_name"].ToString();
|
|
string babyData_sexual = (context.Request["babyData_sexual"] == null) ? "" : context.Request["babyData_sexual"].ToString();
|
|
|
|
babyData babyData = conn.QueryFirstOrDefault<babyData>("select * from babyData where babyData_uid = @babyData_uid", new { babyData_uid = babyData_uid });
|
|
|
|
if (babyData == null) {
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0002";
|
|
objRet.message = "查無此寶寶資料";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
}
|
|
|
|
string gender_change = "N";
|
|
|
|
if (babyData_sexual != babyData.babyData_sexual) {
|
|
gender_change = "Y";
|
|
}
|
|
|
|
babyData.babyData_name = babyData_name;
|
|
babyData.babyData_sexual = babyData_sexual;
|
|
|
|
conn.Update<babyData>(babyData);
|
|
|
|
if (gender_change == "Y") {
|
|
try
|
|
{
|
|
List<babyRec> babyRecs = conn.Query<babyRec>("select * from babyRec where babyData_uid = @babyData_uid", new { babyData_uid = babyData_uid }).ToList();
|
|
|
|
foreach (babyRec rec in babyRecs)
|
|
{
|
|
lenHeiTable objLenHei = conn.QueryFirstOrDefault<lenHeiTable>("select * from lenHeiTable where lenHeiTable_sexual = @gender and lenHeiTable_month = @month and lenHeiTable_minVal <= @height1 and lenHeiTable_maxVal > @height2 ", new { gender = babyData.babyData_sexual, month = rec.babyRec_months, height1 = rec.babyRec_height, height2 = rec.babyRec_height });
|
|
lenHeiTable objMidHei = conn.QueryFirstOrDefault<lenHeiTable>("select * from lenHeiTable where lenHeiTable_sexual = @gender and lenHeiTable_month = @month and lenHeiTable_percent = 50", new { gender = babyData.babyData_sexual, month = rec.babyRec_months });
|
|
rec.babyRec_inpercent = objLenHei.lenHeiTable_percent;
|
|
rec.babyRec_middleHeight = objMidHei.lenHeiTable_maxVal;
|
|
|
|
conn.Update<babyRec>(rec);
|
|
}
|
|
|
|
}
|
|
catch (Exception ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |