From ed0db28b1f9457307952c048d4f0c0813d021be4 Mon Sep 17 00:00:00 2001 From: backuppc Date: Thu, 10 Jul 2025 17:40:31 +0900 Subject: [PATCH] dashboard --- Project/Web/Controller/DashBoardController.cs | 88 +++++++++++++++++++ Project/Web/Controller/HomeController.cs | 4 + Project/Web/wwwroot/DashBoard/index.html | 77 ++++++++++++++-- SubProject/FCOMMON/DataBaseManager.cs | 25 ++++++ 4 files changed, 189 insertions(+), 5 deletions(-) diff --git a/Project/Web/Controller/DashBoardController.cs b/Project/Web/Controller/DashBoardController.cs index 86ff028..9aa8a63 100644 --- a/Project/Web/Controller/DashBoardController.cs +++ b/Project/Web/Controller/DashBoardController.cs @@ -1,6 +1,7 @@ using FCOMMON; using Newtonsoft.Json; using System; +using System.Data; using System.Linq; using System.Net.Http; using System.Security.Cryptography; @@ -38,6 +39,77 @@ namespace Project.Web.Controllers } + [HttpGet] + public HttpResponseMessage GetHolydayRequestCount() + { + + try + { + var cn = DBM.getCn(); + + var sql = "select count(*) from EETGW_HolydayRequest" + + " where gcode = @gcode" + + " and conf = 0"; + + cn.Open(); + + var cmd = new System.Data.SqlClient.SqlCommand(sql, cn); + cmd.Parameters.Add("gcode", SqlDbType.VarChar).Value = FCOMMON.info.Login.gcode; + var cnt1 = (int)cmd.ExecuteScalar(); + cn.Dispose(); + + var response = new + { + HOLY = cnt1, + Message = string.Empty, + }; + return CreateJsonResponse(response); + } + catch (Exception ex) + { + var response = new + { + HOLY = 0, + Message = ex.Message, + }; + return CreateJsonResponse(response); + } + + + } + + + + [HttpGet] + public HttpResponseMessage GetPurchaseWaitCount() + { + + try + { + FCOMMON.DBM.GetPurchaseWaitCount(FCOMMON.info.Login.gcode, out int cnt1, out int cnt2); + var response = new + { + NR = cnt1, + CR = cnt2, + Message = string.Empty, + }; + return CreateJsonResponse(response); + } + catch (Exception ex) + { + var response = new + { + NR = 0, + CR = 0, + Message = ex.Message, + }; + return CreateJsonResponse(response); + } + + + } + + [HttpGet] public HttpResponseMessage GetUserGroups() @@ -131,5 +203,21 @@ namespace Project.Web.Controllers return resp; } + private HttpResponseMessage CreateJsonResponse(object data) + { + var json = JsonConvert.SerializeObject(data, new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore + }); + + return new HttpResponseMessage() + { + Content = new StringContent( + json, + System.Text.Encoding.UTF8, + "application/json") + }; + } + } } diff --git a/Project/Web/Controller/HomeController.cs b/Project/Web/Controller/HomeController.cs index c3b3a71..f7ef2d2 100644 --- a/Project/Web/Controller/HomeController.cs +++ b/Project/Web/Controller/HomeController.cs @@ -134,6 +134,10 @@ namespace Project.Web.Controllers return CreateJsonResponse(response); } + + + + [HttpGet] public HttpResponseMessage CheckLoginStatus() { diff --git a/Project/Web/wwwroot/DashBoard/index.html b/Project/Web/wwwroot/DashBoard/index.html index b9ec525..0f4cd52 100644 --- a/Project/Web/wwwroot/DashBoard/index.html +++ b/Project/Web/wwwroot/DashBoard/index.html @@ -105,7 +105,8 @@ -
+
+
@@ -151,12 +152,12 @@
- +
-

구매요청

-

0

+

구매요청(NR)

+

0

@@ -165,6 +166,23 @@
+ + +
+
+
+

구매요청(CR)

+

0

+
+
+ + + +
+
+
+ +
@@ -270,6 +288,52 @@ }); } + // 구매요청 데이터 Ajax 업데이트 + function updatePurchaseCount() { + showLoading(); + fetch('http://127.0.0.1:9000/DashBoard/GetPurchaseWaitCount') + .then(response => response.json()) + .then(data => { + if (data) { + // NR 구매요청 카운트 업데이트 + if (data.NR !== undefined) { + animateNumberChange('purchaseCountNR', data.NR); + } + + // CR 구매요청 카운트 업데이트 + if (data.CR !== undefined) { + animateNumberChange('purchaseCountCR', data.CR); + } + } + hideLoading(); + }) + .catch(error => { + console.error('구매요청 데이터 업데이트 중 오류 발생:', error); + hideLoading(); + }); + } + + // 휴가요청 데이터 Ajax 업데이트 + function updateHolydayRequestCount() { + showLoading(); + fetch('http://127.0.0.1:9000/DashBoard/GetHolydayRequestCount') + .then(response => response.json()) + .then(data => { + if (data) { + // NR 구매요청 카운트 업데이트 + if (data.HOLY !== undefined) { + animateNumberChange('leaveRequestCount', data.HOLY); + } + } + hideLoading(); + }) + .catch(error => { + console.error('휴가요청 데이터 업데이트 중 오류 발생:', error); + hideLoading(); + }); + } + + // 숫자 애니메이션 function animateNumberChange(elementId, newValue) { const element = document.getElementById(elementId); @@ -300,11 +364,14 @@ // 페이지 로드 시 데이터 업데이트 updateLeaveCount(); updateHolidayList(); - + updatePurchaseCount(); + updateHolydayRequestCount(); // 30초마다 데이터 새로고침 setInterval(() => { updateLeaveCount(); updateHolidayList(); + updatePurchaseCount(); + updateHolydayRequestCount(); }, 30000); diff --git a/SubProject/FCOMMON/DataBaseManager.cs b/SubProject/FCOMMON/DataBaseManager.cs index 3084990..d56132a 100644 --- a/SubProject/FCOMMON/DataBaseManager.cs +++ b/SubProject/FCOMMON/DataBaseManager.cs @@ -19,6 +19,31 @@ namespace FCOMMON return cn; } + public static void GetPurchaseWaitCount(string gcode,out int cnt1,out int cnt2) + { + cnt1 = 0; + cnt2 = 0; + var cn = getCn(); + var sql1 = "select count(*) from Purchase where gcode = @gcode" + + " and state like '--%'" + + " and pdate >= @date"; + + var sql2 = "select count(*) from EETGW_PurchaseCR where gcode = @gcode" + + " and state like '--%'" + + " and pdate >= @date"; + + cn.Open(); + + var cmd = new System.Data.SqlClient.SqlCommand(sql1, cn); + cmd.Parameters.Add("gcode", SqlDbType.VarChar).Value = gcode; + cmd.Parameters.Add("date", SqlDbType.VarChar).Value = DateTime.Now.AddYears(-1).ToShortDateString(); + cnt1 = (int)cmd.ExecuteScalar(); + cmd.CommandText = sql2; + cnt2 = (int)cmd.ExecuteScalar(); + cn.Dispose(); + + } + public static UserModel GetUserInfo(string uid) {