updates raw data

master
嘉祥 詹 2025-04-30 12:15:22 +08:00
parent 35410a5f04
commit 24ed35cf85
10 changed files with 323 additions and 12 deletions

View File

@ -6,6 +6,65 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web; 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")] [Table("babyDataRecView")]
public class babyDataRecView2 public class babyDataRecView2

View File

@ -69,7 +69,7 @@ namespace abbott_2024_event.BackEnd.api
string filiterString = ""; 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 != "%") if (gender != "%")
{ {

View File

@ -0,0 +1 @@
<%@ WebHandler Language="C#" CodeBehind="exportRawExcel.ashx.cs" Class="abbott_2024_event.BackEnd.api.exportRawExcel" %>

View File

@ -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
{
/// <summary>
/// exportRawExcel 的摘要描述
/// </summary>
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<lineUserUid> lineUserUids = conn.Query<lineUserUid>("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<babyDataRecView3> babyDataRecViews = conn.Query<babyDataRecView3>("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;
}
}
}
}

View File

@ -85,7 +85,7 @@ namespace abbott_2024_event.BackEnd.api
string filiterString = ""; 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 != "%") { if (gender != "%") {
filiterString += " and babyData_sexual = '" + gender + "' "; filiterString += " and babyData_sexual = '" + gender + "' ";

View File

@ -47,6 +47,21 @@ $(document).ready(function () {
window.open(url); 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 () { $('#delBabyBtn').click(function () {
if (confirm('確定要刪除此筆寶寶的所有資料?')) { if (confirm('確定要刪除此筆寶寶的所有資料?')) {

View File

@ -66,7 +66,7 @@
<option value="10">10歲</option> <option value="10">10歲</option>
</select> </select>
</div> </div>
<div class="col-md-2"> <div class="col-md-1">
<label for="age_end">年齡(迄)</label> <label for="age_end">年齡(迄)</label>
<select class="custom-select custom-select-sm" id="age_end" name="age_end" required=""> <select class="custom-select custom-select-sm" id="age_end" name="age_end" required="">
<option value="0">0歲</option> <option value="0">0歲</option>
@ -90,6 +90,10 @@
<label for="export_btn" style="display: block;">&nbsp; &nbsp;</label> <label for="export_btn" style="display: block;">&nbsp; &nbsp;</label>
<button type="button" class="btn btn-danger btn-sm" id="export_btn">匯出</button> <button type="button" class="btn btn-danger btn-sm" id="export_btn">匯出</button>
</div> </div>
<div class="col-md-1">
<label for="raw_btn" style="display: block;">&nbsp; &nbsp;</label>
<button type="button" class="btn btn-success btn-sm" id="raw_btn">Raw Data</button>
</div>
</div> </div>
<!-- /.form-row --> <!-- /.form-row -->
@ -149,22 +153,19 @@
<!-- .card-body --> <!-- .card-body -->
<div class="card-body"> <div class="card-body">
<div class="form-row"> <div class="form-row">
<div class="col-md-5" id="prm_project_serial"> <div class="col-md-6" id="prm_project_serial">
<!-- .form-group --> <!-- .form-group -->
<div class="form-group"> <div class="form-group">
<select id="baby_select" class="form-control"> <select id="baby_select" class="form-control">
</select> </select>
</div><!-- /.form-group --> </div><!-- /.form-group -->
</div> </div>
<div class="col-md-3" id="prm_project_serial2"> <div class="col-md-6" id="prm_project_serial2">
<button type="button" class="btn btn-primary ml-auto" id="downloadBtn">下載寶寶總數據</button> <button type="button" class="btn btn-primary ml-auto" id="downloadBtn">下載寶寶總數據</button>&nbsp;&nbsp;
</div> <button type="button" class="btn btn-primary ml-auto" id="editBabyBtn">修改寶寶資料</button>&nbsp;&nbsp;
<div class="col-md-2" >
<button type="button" class="btn btn-primary ml-auto" id="editBabyBtn">修改寶寶資料</button>
</div>
<div class="col-md-2" >
<button type="button" class="btn btn-danger ml-auto" id="delBabyBtn">刪除寶寶資料</button> <button type="button" class="btn btn-danger ml-auto" id="delBabyBtn">刪除寶寶資料</button>
</div> </div>
</div> </div>
<!-- .card --> <!-- .card -->
@ -249,5 +250,5 @@
<!-- /Modal --> <!-- /Modal -->
</asp:Content> </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server"> <asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
<script src="assets/javascript/custom/userList.js?v=28"></script> <script src="assets/javascript/custom/userList.js?v=29"></script>
</asp:Content> </asp:Content>

View File

@ -26458,6 +26458,7 @@
<Content Include="BackEnd\api\importTestBaby.ashx" /> <Content Include="BackEnd\api\importTestBaby.ashx" />
<Content Include="BackEnd\api\chgBabyData.ashx" /> <Content Include="BackEnd\api\chgBabyData.ashx" />
<Content Include="BackEnd\api\delBabyData.ashx" /> <Content Include="BackEnd\api\delBabyData.ashx" />
<Content Include="BackEnd\api\exportRawExcel.ashx" />
<None Include="Scripts\jquery-3.7.1.intellisense.js" /> <None Include="Scripts\jquery-3.7.1.intellisense.js" />
<Content Include="Redirect\Default.aspx" /> <Content Include="Redirect\Default.aspx" />
<Content Include="Scripts\jquery-3.7.1.js" /> <Content Include="Scripts\jquery-3.7.1.js" />
@ -26497,6 +26498,9 @@
<Compile Include="BackEnd\api\exportExcel.ashx.cs"> <Compile Include="BackEnd\api\exportExcel.ashx.cs">
<DependentUpon>exportExcel.ashx</DependentUpon> <DependentUpon>exportExcel.ashx</DependentUpon>
</Compile> </Compile>
<Compile Include="BackEnd\api\exportRawExcel.ashx.cs">
<DependentUpon>exportRawExcel.ashx</DependentUpon>
</Compile>
<Compile Include="BackEnd\api\importTestBaby.ashx.cs"> <Compile Include="BackEnd\api\importTestBaby.ashx.cs">
<DependentUpon>importTestBaby.ashx</DependentUpon> <DependentUpon>importTestBaby.ashx</DependentUpon>
</Compile> </Compile>

Binary file not shown.