104 lines
3.7 KiB
C#
104 lines
3.7 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;
|
|
|
|
namespace abbott_2024_event.webapi
|
|
{
|
|
/// <summary>
|
|
/// tempKeyQuery 的摘要描述
|
|
/// </summary>
|
|
public class tempKeyQuery : 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";
|
|
context.Response.AddHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
string temp_key = (context.Request["temp_key"] == null) ? "" : context.Request["temp_key"].ToString();
|
|
|
|
if (temp_key == "")
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "3001";
|
|
objRet.message = "沒有temp_key!";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
babyRec tmpRec = conn.QueryFirstOrDefault<babyRec>("select * from babyRec where babyRec_key = @babyRec_key", new { babyRec_key = temp_key });
|
|
|
|
if (tmpRec == null)
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "3002";
|
|
objRet.message = "沒有此temp_key資料!";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
string babyData_uid = tmpRec.babyData_uid;
|
|
|
|
babyData tmpData = conn.QueryFirstOrDefault<babyData>("select * from babyData where babyData_uid = @babyData_uid", new { babyData_uid = babyData_uid });
|
|
|
|
if (tmpData == null)
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "3003";
|
|
objRet.message = "沒有此babyData資料!";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
objRet.baby_data.babyData_uid = tmpData.babyData_uid;
|
|
objRet.baby_data.baby_name = tmpData.babyData_name;
|
|
objRet.baby_data.baby_gender = tmpData.babyData_sexual;
|
|
objRet.baby_data.baby_birthday = tmpData.babyData_birthday.ToString("yyyy/MM/dd");
|
|
objRet.baby_data.baby_age = tmpRec.babyRec_yearMonthStr;
|
|
objRet.baby_data.baby_height = tmpRec.babyRec_height;
|
|
objRet.baby_data.average_height = tmpRec.babyRec_middleHeight;
|
|
objRet.baby_data.baby_inpercent = tmpRec.babyRec_inpercent;
|
|
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 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 string babyData_uid { get; set; } = "";
|
|
|
|
public string baby_name { get; set; } = "";
|
|
public string baby_gender { get; set; } = "";
|
|
public double baby_inpercent { get; set; } = 0;
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |