115 lines
4.0 KiB
C#
115 lines
4.0 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>
|
|
/// babyHistory 的摘要描述
|
|
/// </summary>
|
|
public class babyHistory : 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 line_uid = (context.Request["line_uid"] == null) ? "" : context.Request["line_uid"].ToString();
|
|
string babyData_uid = (context.Request["babyData_uid"] == null) ? "" : context.Request["babyData_uid"].ToString();
|
|
string start = (context.Request["start"] == null) ? "" : context.Request["start"].ToString();
|
|
string end = (context.Request["end"] == null) ? "" : context.Request["end"].ToString();
|
|
|
|
lineUser lineUser = conn.QueryFirstOrDefault<lineUser>("select * from lineUser where line_uid = @line_uid", new { line_uid = line_uid });
|
|
|
|
if (lineUser == null)
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "2002";
|
|
objRet.message = "無此line_uid的資料!";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
babyData babyData = conn.QueryFirstOrDefault<babyData>("select * from babyData where line_uid = @line_uid and babyData_uid = @babyData_uid", new { line_uid = line_uid, babyData_uid = babyData_uid });
|
|
|
|
if (babyData == null) {
|
|
objRet.ret = "no";
|
|
objRet.err_code = "3004";
|
|
objRet.message = "沒有此babyData資料!";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
int minNum = 0;
|
|
int maxNum = 120;
|
|
|
|
if (start != "") {
|
|
try
|
|
{
|
|
minNum = int.Parse(start) * 12;
|
|
}
|
|
catch {
|
|
|
|
}
|
|
}
|
|
|
|
if (end != "") {
|
|
try
|
|
{
|
|
maxNum = int.Parse(end) * 12;
|
|
}
|
|
catch {
|
|
|
|
}
|
|
}
|
|
|
|
List<babyRec> babyRecs = conn.Query<babyRec>("select * from babyRec where line_uid = @line_uid and babyData_uid = @babyData_uid and babyRec_monthLastRec = 'Y' order by babyRec_months", new { line_uid = line_uid, babyData_uid = babyData_uid }).ToList();
|
|
|
|
foreach (babyRec rec in babyRecs) {
|
|
height_data height_Data = new height_data();
|
|
height_Data.babyRec_height = rec.babyRec_height;
|
|
height_Data.babyRec_months = rec.babyRec_months;
|
|
height_Data.babyRec_yearMonthStr = rec.babyRec_yearMonthStr;
|
|
height_Data.babyRec_middleHeight = rec.babyRec_middleHeight;
|
|
|
|
objRet.datas.Add(height_Data);
|
|
}
|
|
|
|
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 List<height_data> datas = new List<height_data>();
|
|
}
|
|
|
|
public class height_data
|
|
{
|
|
public double babyRec_height = 0;
|
|
public double babyRec_middleHeight = 0;
|
|
public string babyRec_yearMonthStr = "";
|
|
public int babyRec_months = 0;
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |