diff --git a/App_Code/dbClass.cs b/App_Code/dbClass.cs index e0e1b0c..b2ec5fb 100644 --- a/App_Code/dbClass.cs +++ b/App_Code/dbClass.cs @@ -6,6 +6,65 @@ using System.Collections.Generic; using System.Linq; using System.Web; +public class babyDataRecView3 +{ + [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 string line_phone { get; set; } = ""; + public DateTime lineUser_createdate { get; set; } = DateTime.Now; + public DateTime lineUser_modifydate { get; set; } = DateTime.Now; + public string babyData_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; + public DateTime babyData_lastTestDate { get; set; } = DateTime.Now; + public string babyRec_uid { get; set; } = ""; + public string babyRec_key { 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_monthLastRec { get; set; } = "N"; + public string babyRec_newestRec { get; set; } = "N"; + public string babyRec_yearMonthStr { get; set; } = ""; + + public string utm_source { get; set; } = ""; + public string utm_medium { get; set; } = ""; + public string utm_campaign { get; set; } = ""; + public string utm_term { get; set; } = ""; + public string utm_content { get; set; } = ""; + + public string rec_source { get; set; } = ""; + public string rec_medium { get; set; } = ""; + public string rec_campaign { get; set; } = ""; + public string rec_term { get; set; } = ""; + public string rec_content { get; set; } = ""; + + public DateTime babyRec_createdate { get; set; } = DateTime.Now; +} + +public class lineUserUid +{ + [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 string line_phone { get; set; } = ""; + public DateTime lineUser_modifydate { get; set; } = DateTime.Now; +} [Table("babyDataRecView")] public class babyDataRecView2 diff --git a/BackEnd/api/exportExcel.ashx.cs b/BackEnd/api/exportExcel.ashx.cs index 068cf6f..b00d1ea 100644 --- a/BackEnd/api/exportExcel.ashx.cs +++ b/BackEnd/api/exportExcel.ashx.cs @@ -69,7 +69,7 @@ namespace abbott_2024_event.BackEnd.api string filiterString = ""; - filiterString += " Where A.babyRec_uid = B.babyRec_uid and A.babyData_bindedLine = 'Y' and A.babyRec_newestRec = 'Y' and A.babyRec_recdate >= '" + dateStart.ToString("yyyy/MM/dd") + "' and A.babyRec_recdate <= '" + dateEnd.ToString("yyyy/MM/dd HH:mm:ss") + "' "; + filiterString += " Where A.babyRec_uid = B.babyRec_uid and A.babyData_bindedLine = 'Y' and A.babyRec_newestRec = 'Y' and A.babyData_lastTestDate >= '" + dateStart.ToString("yyyy/MM/dd") + "' and A.babyData_lastTestDate <= '" + dateEnd.ToString("yyyy/MM/dd HH:mm:ss") + "' "; if (gender != "%") { diff --git a/BackEnd/api/exportRawExcel.ashx b/BackEnd/api/exportRawExcel.ashx new file mode 100644 index 0000000..aead1d6 --- /dev/null +++ b/BackEnd/api/exportRawExcel.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="exportRawExcel.ashx.cs" Class="abbott_2024_event.BackEnd.api.exportRawExcel" %> diff --git a/BackEnd/api/exportRawExcel.ashx.cs b/BackEnd/api/exportRawExcel.ashx.cs new file mode 100644 index 0000000..942011f --- /dev/null +++ b/BackEnd/api/exportRawExcel.ashx.cs @@ -0,0 +1,231 @@ +using System; +using System.Web; +using NPOI; +//using NPOI.SS.UserModel; +using NPOI.HPSF; +using NPOI.HSSF; +using NPOI.HSSF.UserModel; +using NPOI.POIFS; +using NPOI.Util; +using System.IO; +using System.Runtime.Serialization.Json; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System.Web.SessionState; +using System.Collections.Generic; +using System.Data; +using System.Text; +using System.Data.SqlClient; +using System.Runtime.Remoting; +using Dapper; +using System.Linq; +using NPOI.SS.Formula.Functions; +using System.Web.UI.WebControls; + +namespace abbott_2024_event.BackEnd.api +{ + /// + /// exportRawExcel 的摘要描述 + /// + public class exportRawExcel : IHttpHandler + { + SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString")); + public authToken authToken; + public void ProcessRequest(HttpContext context) + { + authToken objAuth = new authToken(); + + if (!objAuth.user_isLogin) + { + context.Response.Write("尚未登入,請登入後使用"); + return; + } + + string start = (context.Request["start"] == null) ? "" : context.Request["start"].ToString(); + string end = (context.Request["end"] == null) ? "" : context.Request["end"].ToString(); + string gender = (context.Request["gender"] == null) ? "" : context.Request["gender"].ToString(); + string min_age = (context.Request["min_age"] == null) ? "" : context.Request["min_age"].ToString(); + string max_age = (context.Request["max_age"] == null) ? "" : context.Request["max_age"].ToString(); + + DateTime dateStart; + DateTime dateEnd; + + try + { + dateStart = DateTime.Parse(start); + dateEnd = DateTime.Parse(end + " 23:59:59"); + } + catch + { + context.Response.Write("測驗起訖日錯誤"); + return; + } + + if (gender != "%" && gender != "M" && gender != "F") + { + + context.Response.Write("性別代碼錯誤!"); + return; + } + + string filiterString = ""; + + filiterString += " Where A.babyRec_uid = B.babyRec_uid and A.babyData_bindedLine = 'Y' and A.babyRec_newestRec = 'Y' and A.babyData_lastTestDate >= '" + dateStart.ToString("yyyy/MM/dd") + "' and A.babyData_lastTestDate <= '" + dateEnd.ToString("yyyy/MM/dd HH:mm:ss") + "' "; + + if (gender != "%") + { + filiterString += " and A.babyData_sexual = '" + gender + "' "; + } + + filiterString += " and A.babyRec_months >= " + (int.Parse(min_age) * 12).ToString() + " and A.babyRec_months <= " + (int.Parse(max_age) * 12).ToString(); + + List lineUserUids = conn.Query("select distinct A.lineUser_sn, A.lineUser_uid, A.line_uid, A.line_displayName, A.line_phone, A.lineUser_modifydate from babyDataRecView A, babyRec B " + filiterString + " order by lineUser_modifydate desc ").ToList(); + + + HSSFWorkbook workbook = new HSSFWorkbook(); + MemoryStream ms = new MemoryStream(); + HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet(); + HSSFRow headerRow = (HSSFRow)sheet.CreateRow(0); + + headerRow.CreateCell(0).SetCellValue("Line Uid"); + headerRow.CreateCell(1).SetCellValue("媽媽姓名"); + headerRow.CreateCell(2).SetCellValue("電話"); + headerRow.CreateCell(3).SetCellValue("寶寶姓名"); + headerRow.CreateCell(4).SetCellValue("寶寶性別"); + headerRow.CreateCell(5).SetCellValue("生日"); + headerRow.CreateCell(6).SetCellValue("測驗日期"); + headerRow.CreateCell(7).SetCellValue("測驗時年齡"); + headerRow.CreateCell(8).SetCellValue("寶寶身高"); + headerRow.CreateCell(9).SetCellValue("寶寶成長百分比"); + headerRow.CreateCell(10).SetCellValue("成為會員utm_source"); + headerRow.CreateCell(11).SetCellValue("成為會員utm_medium"); + headerRow.CreateCell(12).SetCellValue("成為會員utm_campaign"); + headerRow.CreateCell(13).SetCellValue("成為會員utm_content"); + headerRow.CreateCell(14).SetCellValue("成為會員utm_term"); + headerRow.CreateCell(15).SetCellValue("寶寶紀錄utm_source"); + headerRow.CreateCell(16).SetCellValue("寶寶紀錄utm_medium"); + headerRow.CreateCell(17).SetCellValue("寶寶紀錄utm_campaign"); + headerRow.CreateCell(18).SetCellValue("寶寶紀錄utm_content"); + headerRow.CreateCell(19).SetCellValue("寶寶紀錄utm_term"); + headerRow.CreateCell(20).SetCellValue("資料建立時間"); + + int pageNum = 1; + + foreach (lineUserUid lineUserUid in lineUserUids) { + List babyDataRecViews = conn.Query("select A.*, B.utm_source as rec_source, B.utm_medium as rec_medium, B.utm_campaign as rec_campaign, B.utm_content as rec_content, B.utm_term as rec_term, B.babyRec_createdate from babyDataRecView A, babyRec B Where A.babyRec_uid = B.babyRec_uid and A.lineUser_uid = @lineUser_uid order by babyData_uid, babyRec_recdate desc ", new { lineUser_uid = lineUserUid.lineUser_uid }).ToList(); + + foreach (babyDataRecView3 view in babyDataRecViews) { + string baby_gender = ""; + + if (view.babyData_sexual == "M") + { + baby_gender = "男"; + } + else + { + baby_gender = "女"; + } + string inpercent = ""; + + + switch ((int)view.babyRec_inpercent) + { + case 3: + { + inpercent = "低於3%"; + break; + } + case 15: + { + inpercent = "3~14%"; + break; + } + case 25: + { + inpercent = "15~49%"; + break; + } + case 50: + { + inpercent = "15~49%"; + break; + } + case 75: + { + inpercent = "50%以上 "; + break; + } + case 85: + { + inpercent = "50%以上 "; + break; + } + case 97: + { + inpercent = "50%以上 "; + break; + } + case 100: + { + inpercent = "50%以上 "; + break; + } + + } + + HSSFRow excelRow = (HSSFRow)sheet.CreateRow(pageNum); + excelRow.CreateCell(0).SetCellValue(view.line_uid); + excelRow.CreateCell(1).SetCellValue(view.line_displayName); + excelRow.CreateCell(2).SetCellValue(view.line_phone); + excelRow.CreateCell(3).SetCellValue(view.babyData_name); + excelRow.CreateCell(4).SetCellValue(baby_gender); + excelRow.CreateCell(5).SetCellValue(view.babyData_birthday.ToString("yyyy/MM/dd")); + excelRow.CreateCell(6).SetCellValue(view.babyRec_recdate.ToString("yyyy/MM/dd")); + excelRow.CreateCell(7).SetCellValue(view.babyRec_yearMonthStr); + excelRow.CreateCell(8).SetCellValue(view.babyRec_height); + excelRow.CreateCell(9).SetCellValue(inpercent); + excelRow.CreateCell(10).SetCellValue(view.utm_source); + excelRow.CreateCell(11).SetCellValue(view.utm_medium); + excelRow.CreateCell(12).SetCellValue(view.utm_campaign); + excelRow.CreateCell(13).SetCellValue(view.utm_content); + excelRow.CreateCell(14).SetCellValue(view.utm_term); + excelRow.CreateCell(15).SetCellValue(view.rec_source); + excelRow.CreateCell(16).SetCellValue(view.rec_medium); + excelRow.CreateCell(17).SetCellValue(view.rec_campaign); + excelRow.CreateCell(18).SetCellValue(view.rec_content); + excelRow.CreateCell(19).SetCellValue(view.rec_term); + excelRow.CreateCell(20).SetCellValue(view.babyRec_createdate.ToString("yyyy/MM/dd HH:mm:ss")); + + pageNum++; + } + + + } + + for (int j = 0; j <= 20; j++) + { + sheet.AutoSizeColumn(j); + sheet.SetColumnWidth(j, sheet.GetColumnWidth(j) * 17 / 10); + } + + + + workbook.Write(ms); + ms.Flush(); + + string fileName = HttpUtility.UrlEncode("測驗者寶寶 Raw Data_" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls", Encoding.UTF8); + context.Response.ContentType = "application/vnd.ms-excel;charset=utf-8"; + context.Response.AddHeader("Content-Disposition", String.Format("attachment;filename=" + fileName + ";filename*=utf-8''" + fileName)); + //context.Response.ContentType = "application/vnd.ms-excel;charset=utf-8"; + context.Response.BinaryWrite(ms.ToArray()); + } + + public bool IsReusable + { + get + { + return false; + } + } + } +} \ No newline at end of file diff --git a/BackEnd/api/userList.ashx.cs b/BackEnd/api/userList.ashx.cs index a55b5e7..7987273 100644 --- a/BackEnd/api/userList.ashx.cs +++ b/BackEnd/api/userList.ashx.cs @@ -85,7 +85,7 @@ namespace abbott_2024_event.BackEnd.api string filiterString = ""; - filiterString += " Where babyData_bindedLine = 'Y' and babyRec_newestRec = 'Y' and babyRec_recdate >= '" + dateStart.ToString("yyyy/MM/dd") + "' and babyRec_recdate <= '" + dateEnd.ToString("yyyy/MM/dd HH:mm:ss") + "' "; + filiterString += " Where babyData_bindedLine = 'Y' and babyRec_newestRec = 'Y' and babyData_lastTestDate >= '" + dateStart.ToString("yyyy/MM/dd") + "' and babyData_lastTestDate <= '" + dateEnd.ToString("yyyy/MM/dd HH:mm:ss") + "' "; if (gender != "%") { filiterString += " and babyData_sexual = '" + gender + "' "; diff --git a/BackEnd/assets/javascript/custom/userList.js b/BackEnd/assets/javascript/custom/userList.js index b1d53e6..c9e423d 100644 --- a/BackEnd/assets/javascript/custom/userList.js +++ b/BackEnd/assets/javascript/custom/userList.js @@ -47,6 +47,21 @@ $(document).ready(function () { window.open(url); }); + $('#raw_btn').click(function () { + if (confirm("注意事項:Raw Data因為資料龐大,會依據選擇的時間範圍,下載等待時間可能會好幾分鐘以上!")) { + + var start = $("#startDate").val(); + var end = $("#endDate").val(); + var gender = $("#gender_select").val(); + var min_age = $("#age_start").val(); + var max_age = $("#age_end").val(); + + var url = "api/exportRawExcel.ashx?start=" + start + "&end=" + end + "&gender=" + gender + "&min_age=" + min_age + "&max_age=" + max_age; + window.open(url); + + } + }); + $('#delBabyBtn').click(function () { if (confirm('確定要刪除此筆寶寶的所有資料?')) { diff --git a/BackEnd/userList.aspx b/BackEnd/userList.aspx index 1846a41..49eb99b 100644 --- a/BackEnd/userList.aspx +++ b/BackEnd/userList.aspx @@ -66,7 +66,7 @@ -
+
-
- -
-
- -
-
+
+    +   
+
@@ -249,5 +250,5 @@ - + diff --git a/abbott_2024_event.csproj b/abbott_2024_event.csproj index 4f78544..62836ca 100644 --- a/abbott_2024_event.csproj +++ b/abbott_2024_event.csproj @@ -26458,6 +26458,7 @@ + @@ -26497,6 +26498,9 @@ exportExcel.ashx + + exportRawExcel.ashx + importTestBaby.ashx diff --git a/bin/abbott_2024_event.dll b/bin/abbott_2024_event.dll index eb52607..3cd7a46 100644 Binary files a/bin/abbott_2024_event.dll and b/bin/abbott_2024_event.dll differ diff --git a/bin/app.publish/bin/abbott_2024_event.dll b/bin/app.publish/bin/abbott_2024_event.dll index eb52607..ae19ad6 100644 Binary files a/bin/app.publish/bin/abbott_2024_event.dll and b/bin/app.publish/bin/abbott_2024_event.dll differ