From cbd26e09a6755b9c3a556ef49c2c23d61144f8dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=82=E4=BB=BB=20=E6=9E=97?= Date: Tue, 22 Jun 2021 20:58:41 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E9=9B=BB=E7=AB=99=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E7=B8=A3=E5=B8=82nav=E9=83=A8=E5=88=86=E7=9A=84=E5=BE=8C?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PowerStationController.cs | 23 +++++++++++ SolarPower/Helper/DatabaseHelper.cs | 2 +- SolarPower/Models/PowerStation.cs | 10 +++++ .../Implement/PowerStationRepository.cs | 40 +++++++++++++++++++ .../Interface/IPowerStationRepository.cs | 11 ++++- SolarPower/Views/PowerStation/Index.cshtml | 25 +++++++++++- 6 files changed, 108 insertions(+), 3 deletions(-) diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index d504cb0..932bf4f 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -1220,5 +1220,28 @@ namespace SolarPower.Controllers return apiResult; } + + /// + /// 取得該使用者可看的所有電站分佈縣市以及各縣市電站數量 + /// + /// + public async Task>> GetSolarCitySummary() + { + ApiResult> apiResult = new ApiResult>(); + List solaramount = new List(); + try + { + apiResult.Code = "0000"; + solaramount = await powerStationRepository.GetSolarCitySummary(myUser); + apiResult.Data = solaramount; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } + + return apiResult; + } } } diff --git a/SolarPower/Helper/DatabaseHelper.cs b/SolarPower/Helper/DatabaseHelper.cs index 2e57aa3..e90b47b 100644 --- a/SolarPower/Helper/DatabaseHelper.cs +++ b/SolarPower/Helper/DatabaseHelper.cs @@ -37,7 +37,7 @@ namespace SolarPower.Helper var passwordStr = ed.DESDecrypt(dbConfig.Password); //var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; - var connStr = @"server=127.0.0.1;port=3308;database=solar_power;user=root;password=00000000;charset=utf8;"; + var connStr = @"server=127.0.0.1;port=3306;database=solar_power;user=root;password=000000;charset=utf8;"; this._connectionString = connStr; } diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index 96b733a..719f05a 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -364,4 +364,14 @@ namespace SolarPower.Models.PowerStation public string AlarmName { get; set; } } + /// + /// 電站縣市分佈 + /// + public class SolarCityAmount + { + public int CityId { get; set; } + public string City { get; set; } + public int Amount { get; set; } + } + } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 1f9c4b4..e8d386c 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.Json; +using SolarPower.Models; namespace SolarPower.Repository.Implement { @@ -809,5 +810,44 @@ namespace SolarPower.Repository.Implement } return Num; } + + public async Task> GetSolarCitySummary(MyUser User) + { + using IDbConnection conn = _databaseHelper.GetConnection(); + List solaramount = new List(); + conn.Open(); + var trans = conn.BeginTransaction(); + try + { + if (User.Role.Layer == 0 || User.Role.Layer == 1) + { + var sql = "SELECT city.Id AS CityId city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id GROUP BY power_station.CityId"; + solaramount = (await conn.QueryAsync(sql)).ToList(); + trans.Commit(); + } + else if (User.Role.Layer == 2) + { + var sql = "SELECT city.Id AS CityId city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id WHERE CompanyId = @CompanyId GROUP BY power_station.CityId ORDER BY power_station.CityId "; + solaramount = (await conn.QueryAsync(sql, new { CompanyId = User.CompanyId })).ToList(); + trans.Commit(); + } + else + { + var sql = "SELECT city.Id AS CityId city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id LEFT JOIN power_station_operation_personnel ON power_station.Id = power_station_operation_personnel.PowerStationId WHERE UserId = @UserId GROUP BY power_station.CityId ORDER BY power_station.CityId"; + solaramount = (await conn.QueryAsync(sql, new { UserId = User.Id })).ToList(); + trans.Commit(); + } + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + return solaramount; + } } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index bd3e555..cceadbf 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -1,4 +1,5 @@ -using SolarPower.Models.PowerStation; +using SolarPower.Models; +using SolarPower.Models.PowerStation; using SolarPower.Models.User; using System; using System.Collections.Generic; @@ -188,5 +189,13 @@ namespace SolarPower.Repository.Interface /// /// Task GetFinalSerialNumber(int PowerStationId, string Type); + + /// + /// 取得電站分佈縣市以及數量 + /// + /// + /// + Task> GetSolarCitySummary(MyUser User); + } } diff --git a/SolarPower/Views/PowerStation/Index.cshtml b/SolarPower/Views/PowerStation/Index.cshtml index e3c6b98..e743cce 100644 --- a/SolarPower/Views/PowerStation/Index.cshtml +++ b/SolarPower/Views/PowerStation/Index.cshtml @@ -410,7 +410,30 @@ $(function () { var localurl = this.location.href; - //電站區域Tab要佳LI + + //#region 電站區域Tab + + + var url = "/PowerStation/GetSolarCitySummary"; + $.post(url, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + else { + $.each(rel.data, function (index, val) { + //alert(val.city + val.amount); + }); + return; + } + + + }, 'json'); + + + //#endregion + + //電站區域 $('#templateAreaTab').find('li').attr('id', 'AreaTabnewtaipei').clone().appendTo($('#areaTab')); $('#AreaTabnewtaipei').find('a').attr('href', '#tab-newtaipei'); $('#AreaTabnewtaipei').find('a').attr('class', 'nav-link fs-lg px-4'); From f789f3dbbb37f3a22a12c2dabc95f4cf83bb3375 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Wed, 23 Jun 2021 09:30:50 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=AE=9A=E6=9C=9F=E8=A8=88=E7=95=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Controllers/OperationController.cs | 122 +++++++++++++----- SolarPower/Models/Operation.cs | 35 ++++- .../Implement/OperationRepository.cs | 32 ++++- .../Interface/IOperationRepository.cs | 2 + SolarPower/Views/Operation/Index.cshtml | 40 +++++- 5 files changed, 192 insertions(+), 39 deletions(-) diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index 593ee6a..688381f 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -67,41 +67,78 @@ namespace SolarPower.Controllers ApiResult apiResult = new ApiResult(); try { - var now = DateTime.Now.ToString("yyyy-MM-dd"); - var finalid = await operationRepository.GetCurrentSerialNumber("operation_plan_create", $"PowerStationId = {post.PowerStationId} AND CreatedAt LIKE '%{now}%'"); - var newSerialNumber = GetLastSerialNumber(finalid); - var OperationPlan = new OperationCreatePlan() + if(post.Id == 0) { - EmailType = post.EmailType, - ScheduleNum = post.ScheduleNum, - Description = post.Description, - WorkDay = post.WorkDay, - ScheduleType = post.ScheduleType, - SerialNumber = newSerialNumber, - StartTime = post.StartTime, - PowerStationId = post.PowerStationId, - Type = post.Type, - PlanId = DateTime.Now.ToString("yyyyMMdd") + newSerialNumber, - CreatedBy = myUser.Id - }; - List properties = new List() + var now = DateTime.Now.ToString("yyyy-MM-dd"); + var finalid = await operationRepository.GetCurrentSerialNumber("operation_plan_create", $"PowerStationId = {post.PowerStationId} AND CreatedAt LIKE '%{now}%'"); + var newSerialNumber = GetLastSerialNumber(finalid); + var OperationPlan = new OperationCreatePlan() + { + EmailType = post.EmailType, + ScheduleNum = post.ScheduleNum, + Description = post.Description, + WorkDay = post.WorkDay, + ScheduleType = post.ScheduleType, + SerialNumber = newSerialNumber, + StartTime = post.StartTime, + PowerStationId = post.PowerStationId, + Type = post.Type, + PlanId = DateTime.Now.ToString("yyyyMMdd") + newSerialNumber, + CreatedBy = myUser.Id + }; + List properties = new List() + { + "EmailType", + "ScheduleNum", + "Description", + "WorkDay", + "ScheduleType", + "SerialNumber", + "StartTime", + "PowerStationId", + "Type", + "PlanId", + "CreatedBy" + }; + await operationRepository.AddOperationPlan(OperationPlan, properties); + apiResult.Code = "0000"; + apiResult.Msg = "新增成功"; + } + else { - "EmailType", - "ScheduleNum", - "Description", - "WorkDay", - "ScheduleType", - "SerialNumber", - "StartTime", - "PowerStationId", - "Type", - "PlanId", - "CreatedBy" - }; - await operationRepository.AddOperationPlan(OperationPlan, properties); + var OperationPlan = new OperationCreatePlan() + { + Id = post.Id, + EmailType = post.EmailType, + ScheduleNum = post.ScheduleNum, + Description = post.Description, + WorkDay = post.WorkDay, + ScheduleType = post.ScheduleType, + StartTime = post.StartTime, + PowerStationId = post.PowerStationId, + Type = post.Type, + UpdateBy = myUser.Id + }; + List properties = new List() + { + "Id", + "EmailType", + "ScheduleNum", + "Description", + "WorkDay", + "ScheduleType", + "StartTime", + "PowerStationId", + "Type", + "UpdateBy" + }; + await operationRepository.UpdateOperationPlan(OperationPlan, properties); + apiResult.Code = "0000"; + apiResult.Msg = "編輯成功"; + } - apiResult.Code = "0000"; - apiResult.Msg = "新增成功"; + + } catch (Exception exception) { @@ -157,7 +194,7 @@ namespace SolarPower.Controllers a.Schedule = "每" + a.ScheduleNum.ToString() + "年"; } - a.StartTimeString = a.StartTime.ToString("yyyy-MM-dd"); + a.StartTimeString = a.StartTime; var crst = a.CreatedAt.Split(" "); a.CreateTimeString = crst[0]; @@ -233,5 +270,24 @@ namespace SolarPower.Controllers return apiResult; } + public async Task> GetOneOperationPlan(int Id) + { + ApiResult apiResult = new ApiResult(); + OperationCreatePlan operationCreatePlan = new OperationCreatePlan(); + try + { + apiResult.Code = "0000"; + operationCreatePlan = await operationRepository.GetOneOperation(Id); + apiResult.Data = operationCreatePlan; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + Id); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + return apiResult; + } } } diff --git a/SolarPower/Models/Operation.cs b/SolarPower/Models/Operation.cs index 4ddacba..956f386 100644 --- a/SolarPower/Models/Operation.cs +++ b/SolarPower/Models/Operation.cs @@ -26,16 +26,44 @@ namespace SolarPower.Models public string Text { get; set; } public string Value { get; set; } } + public class OperationCreatePlanModal : Created { + private string startTime = "", endTime = ""; public int Id { get; set; } public int PowerStationId { get; set; } public int Type { get; set; } public int ScheduleNum { get; set; } public int ScheduleType { get; set; } public int WorkDay { get; set; } - public DateTime StartTime { get; set; } - public DateTime EndTime { get; set; } + public string StartTime { + get + { + if (!string.IsNullOrEmpty(startTime)) + { + return Convert.ToDateTime(startTime).ToString("yyyy-MM-dd"); + } + else + { + return null; + } + } + set { startTime = value; } + } + public string EndTime { + get + { + if (!string.IsNullOrEmpty(endTime)) + { + return Convert.ToDateTime(endTime).ToString("yyyy-MM-dd"); + } + else + { + return null; + } + } + set { endTime = value; } + } public string Description { get; set; } public int EmailType { get; set; } } @@ -43,6 +71,9 @@ namespace SolarPower.Models { public string PlanId { get; set; } public string SerialNumber { get; set; } + private string updateAt; + public int UpdateBy { get; set; } //修改者 + public string UpdateAt { get { return Convert.ToDateTime(updateAt).ToString("yyyy-MM-dd HH:mm:ss"); } set { updateAt = value; } } //修改時間 } public class OperationPlanTable : OperationCreatePlan { diff --git a/SolarPower/Repository/Implement/OperationRepository.cs b/SolarPower/Repository/Implement/OperationRepository.cs index 063c5ad..6e46ac3 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -35,7 +35,6 @@ namespace SolarPower.Repository.Implement return result; } } - public async Task AddOperationPlan(OperationCreatePlan OperationPlan, List properties) { using (IDbConnection conn = _databaseHelper.GetConnection()) @@ -80,9 +79,11 @@ namespace SolarPower.Repository.Implement { try { - var sql = @$"SELECT *,ps.Name AS PowerStationName ,us.Name AS CreatedPerson FROM operation_plan_create oc LEFT JOIN power_station ps + var sql = @$"SELECT oc.Id,oc.PlanId,oc.PowerStationId,oc.Type, + oc.ScheduleNum,oc.ScheduleType,oc.WorkDay,oc.StartTime, + oc.EmailType,oc.Description,oc.CreatedAt,ps.Name AS PowerStationName ,us.Name AS CreatedPerson FROM operation_plan_create oc LEFT JOIN power_station ps ON oc.PowerStationId = ps.Id LEFT JOIN user us - ON us.Id = oc.CreatedBy WHERE {Wheresql} AND oc.Deleted = 0"; + ON us.Id = oc.CreatedBy WHERE ({Wheresql}) AND oc.Deleted = 0"; result = (await conn.QueryAsync(sql)).ToList(); } catch (Exception exception) @@ -116,5 +117,30 @@ namespace SolarPower.Repository.Implement return result; } } + public async Task UpdateOperationPlan(OperationCreatePlan OperationPlan, List properties) + { + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + var trans = conn.BeginTransaction(); + try + { + var sql = GenerateUpdateQuery(properties); + await conn.ExecuteAsync(sql, OperationPlan, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + + } + } } } diff --git a/SolarPower/Repository/Interface/IOperationRepository.cs b/SolarPower/Repository/Interface/IOperationRepository.cs index 284afb2..b4b7292 100644 --- a/SolarPower/Repository/Interface/IOperationRepository.cs +++ b/SolarPower/Repository/Interface/IOperationRepository.cs @@ -12,6 +12,8 @@ namespace SolarPower.Repository.Interface Task AddOperationPlan(OperationCreatePlan OperationPlan, List properties); Task> OperationPlanTable(List id); Task GetOneOperation(int id); + Task UpdateOperationPlan(OperationCreatePlan OperationPlan, List properties); + } } diff --git a/SolarPower/Views/Operation/Index.cshtml b/SolarPower/Views/Operation/Index.cshtml index a4d9d53..a82e2d8 100644 --- a/SolarPower/Views/Operation/Index.cshtml +++ b/SolarPower/Views/Operation/Index.cshtml @@ -357,8 +357,8 @@ //#region 儲存定時計畫資料 function SaveOperationPlan() { var url = "/Operation/SaveOperationPlan"; - var send_data = { + id: selected_id, PowerStationId: $("#operation_powerStationselect_modal").val(), Type: $("#operation_type_modal").val(), ScheduleNum: $("#operation_scheduleNum_modal").val(), @@ -413,6 +413,44 @@ }); }); //#endregion + //#region 取一筆定時計畫 + $('#OperationPlan_table').on("click", "button.edit-btn", function () { + $("#Operation-modal .modal-title").html("定時計劃 - 編輯"); + selected_id = $(this).parents('tr').attr('data-id'); + + //取得單一異常設定資料 + var url = "/Operation/GetOneOperationPlan/"; + + var send_data = { + id: selected_id + } + + + $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + $("#operation_powerStationselect_modal").val(rel.data.powerStationId); + $("#operation_type_modal").val(rel.data.type); + $("#operation_scheduleNum_modal").val(rel.data.scheduleNum); + $("#operation_scheduleType_modal").val(rel.data.scheduleType); + $("#operation_workDay_modal").val(rel.data.workDay); + var start = rel.data.startTime.split(' '); + $("#operation_startTime_modal").val(start[0]); + $("#operation_description_modal").val(rel.data.description); + $("#operation_emailType_modal").val(rel.data.emailType); + + var dat = new Date(start); + var day = new Date(dat.setDate(dat.getDate() + Number(rel.data.workDay))).toISOString().split("T"); + document.getElementById("operation_endTime_modal").innerHTML = day[0]; + + $("#Operation-modal").modal(); + }, 'json'); + + }); + //#endregion } \ No newline at end of file From 788de7f2aa2382dfb6c23896c7cbd0154df5ffc9 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Wed, 23 Jun 2021 09:44:23 +0800 Subject: [PATCH 3/6] =?UTF-8?q?Revert=20"=E5=AE=9A=E6=9C=9F=E8=A8=88?= =?UTF-8?q?=E7=95=AB"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f789f3dbbb37f3a22a12c2dabc95f4cf83bb3375. --- SolarPower/Controllers/OperationController.cs | 122 +++++------------- SolarPower/Models/Operation.cs | 35 +---- .../Implement/OperationRepository.cs | 32 +---- .../Interface/IOperationRepository.cs | 2 - SolarPower/Views/Operation/Index.cshtml | 40 +----- 5 files changed, 39 insertions(+), 192 deletions(-) diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index 688381f..593ee6a 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -67,78 +67,41 @@ namespace SolarPower.Controllers ApiResult apiResult = new ApiResult(); try { - if(post.Id == 0) + var now = DateTime.Now.ToString("yyyy-MM-dd"); + var finalid = await operationRepository.GetCurrentSerialNumber("operation_plan_create", $"PowerStationId = {post.PowerStationId} AND CreatedAt LIKE '%{now}%'"); + var newSerialNumber = GetLastSerialNumber(finalid); + var OperationPlan = new OperationCreatePlan() { - var now = DateTime.Now.ToString("yyyy-MM-dd"); - var finalid = await operationRepository.GetCurrentSerialNumber("operation_plan_create", $"PowerStationId = {post.PowerStationId} AND CreatedAt LIKE '%{now}%'"); - var newSerialNumber = GetLastSerialNumber(finalid); - var OperationPlan = new OperationCreatePlan() - { - EmailType = post.EmailType, - ScheduleNum = post.ScheduleNum, - Description = post.Description, - WorkDay = post.WorkDay, - ScheduleType = post.ScheduleType, - SerialNumber = newSerialNumber, - StartTime = post.StartTime, - PowerStationId = post.PowerStationId, - Type = post.Type, - PlanId = DateTime.Now.ToString("yyyyMMdd") + newSerialNumber, - CreatedBy = myUser.Id - }; - List properties = new List() - { - "EmailType", - "ScheduleNum", - "Description", - "WorkDay", - "ScheduleType", - "SerialNumber", - "StartTime", - "PowerStationId", - "Type", - "PlanId", - "CreatedBy" - }; - await operationRepository.AddOperationPlan(OperationPlan, properties); - apiResult.Code = "0000"; - apiResult.Msg = "新增成功"; - } - else + EmailType = post.EmailType, + ScheduleNum = post.ScheduleNum, + Description = post.Description, + WorkDay = post.WorkDay, + ScheduleType = post.ScheduleType, + SerialNumber = newSerialNumber, + StartTime = post.StartTime, + PowerStationId = post.PowerStationId, + Type = post.Type, + PlanId = DateTime.Now.ToString("yyyyMMdd") + newSerialNumber, + CreatedBy = myUser.Id + }; + List properties = new List() { - var OperationPlan = new OperationCreatePlan() - { - Id = post.Id, - EmailType = post.EmailType, - ScheduleNum = post.ScheduleNum, - Description = post.Description, - WorkDay = post.WorkDay, - ScheduleType = post.ScheduleType, - StartTime = post.StartTime, - PowerStationId = post.PowerStationId, - Type = post.Type, - UpdateBy = myUser.Id - }; - List properties = new List() - { - "Id", - "EmailType", - "ScheduleNum", - "Description", - "WorkDay", - "ScheduleType", - "StartTime", - "PowerStationId", - "Type", - "UpdateBy" - }; - await operationRepository.UpdateOperationPlan(OperationPlan, properties); - apiResult.Code = "0000"; - apiResult.Msg = "編輯成功"; - } + "EmailType", + "ScheduleNum", + "Description", + "WorkDay", + "ScheduleType", + "SerialNumber", + "StartTime", + "PowerStationId", + "Type", + "PlanId", + "CreatedBy" + }; + await operationRepository.AddOperationPlan(OperationPlan, properties); - - + apiResult.Code = "0000"; + apiResult.Msg = "新增成功"; } catch (Exception exception) { @@ -194,7 +157,7 @@ namespace SolarPower.Controllers a.Schedule = "每" + a.ScheduleNum.ToString() + "年"; } - a.StartTimeString = a.StartTime; + a.StartTimeString = a.StartTime.ToString("yyyy-MM-dd"); var crst = a.CreatedAt.Split(" "); a.CreateTimeString = crst[0]; @@ -270,24 +233,5 @@ namespace SolarPower.Controllers return apiResult; } - public async Task> GetOneOperationPlan(int Id) - { - ApiResult apiResult = new ApiResult(); - OperationCreatePlan operationCreatePlan = new OperationCreatePlan(); - try - { - apiResult.Code = "0000"; - operationCreatePlan = await operationRepository.GetOneOperation(Id); - apiResult.Data = operationCreatePlan; - } - catch (Exception exception) - { - apiResult.Code = "9999"; - apiResult.Msg = exception.ToString(); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + Id); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); - } - return apiResult; - } } } diff --git a/SolarPower/Models/Operation.cs b/SolarPower/Models/Operation.cs index 956f386..4ddacba 100644 --- a/SolarPower/Models/Operation.cs +++ b/SolarPower/Models/Operation.cs @@ -26,44 +26,16 @@ namespace SolarPower.Models public string Text { get; set; } public string Value { get; set; } } - public class OperationCreatePlanModal : Created { - private string startTime = "", endTime = ""; public int Id { get; set; } public int PowerStationId { get; set; } public int Type { get; set; } public int ScheduleNum { get; set; } public int ScheduleType { get; set; } public int WorkDay { get; set; } - public string StartTime { - get - { - if (!string.IsNullOrEmpty(startTime)) - { - return Convert.ToDateTime(startTime).ToString("yyyy-MM-dd"); - } - else - { - return null; - } - } - set { startTime = value; } - } - public string EndTime { - get - { - if (!string.IsNullOrEmpty(endTime)) - { - return Convert.ToDateTime(endTime).ToString("yyyy-MM-dd"); - } - else - { - return null; - } - } - set { endTime = value; } - } + public DateTime StartTime { get; set; } + public DateTime EndTime { get; set; } public string Description { get; set; } public int EmailType { get; set; } } @@ -71,9 +43,6 @@ namespace SolarPower.Models { public string PlanId { get; set; } public string SerialNumber { get; set; } - private string updateAt; - public int UpdateBy { get; set; } //修改者 - public string UpdateAt { get { return Convert.ToDateTime(updateAt).ToString("yyyy-MM-dd HH:mm:ss"); } set { updateAt = value; } } //修改時間 } public class OperationPlanTable : OperationCreatePlan { diff --git a/SolarPower/Repository/Implement/OperationRepository.cs b/SolarPower/Repository/Implement/OperationRepository.cs index 6e46ac3..063c5ad 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -35,6 +35,7 @@ namespace SolarPower.Repository.Implement return result; } } + public async Task AddOperationPlan(OperationCreatePlan OperationPlan, List properties) { using (IDbConnection conn = _databaseHelper.GetConnection()) @@ -79,11 +80,9 @@ namespace SolarPower.Repository.Implement { try { - var sql = @$"SELECT oc.Id,oc.PlanId,oc.PowerStationId,oc.Type, - oc.ScheduleNum,oc.ScheduleType,oc.WorkDay,oc.StartTime, - oc.EmailType,oc.Description,oc.CreatedAt,ps.Name AS PowerStationName ,us.Name AS CreatedPerson FROM operation_plan_create oc LEFT JOIN power_station ps + var sql = @$"SELECT *,ps.Name AS PowerStationName ,us.Name AS CreatedPerson FROM operation_plan_create oc LEFT JOIN power_station ps ON oc.PowerStationId = ps.Id LEFT JOIN user us - ON us.Id = oc.CreatedBy WHERE ({Wheresql}) AND oc.Deleted = 0"; + ON us.Id = oc.CreatedBy WHERE {Wheresql} AND oc.Deleted = 0"; result = (await conn.QueryAsync(sql)).ToList(); } catch (Exception exception) @@ -117,30 +116,5 @@ namespace SolarPower.Repository.Implement return result; } } - public async Task UpdateOperationPlan(OperationCreatePlan OperationPlan, List properties) - { - using (IDbConnection conn = _databaseHelper.GetConnection()) - { - conn.Open(); - var trans = conn.BeginTransaction(); - try - { - var sql = GenerateUpdateQuery(properties); - await conn.ExecuteAsync(sql, OperationPlan, trans); - - trans.Commit(); - } - catch (Exception exception) - { - trans.Rollback(); - throw exception; - } - finally - { - conn.Close(); - } - - } - } } } diff --git a/SolarPower/Repository/Interface/IOperationRepository.cs b/SolarPower/Repository/Interface/IOperationRepository.cs index b4b7292..284afb2 100644 --- a/SolarPower/Repository/Interface/IOperationRepository.cs +++ b/SolarPower/Repository/Interface/IOperationRepository.cs @@ -12,8 +12,6 @@ namespace SolarPower.Repository.Interface Task AddOperationPlan(OperationCreatePlan OperationPlan, List properties); Task> OperationPlanTable(List id); Task GetOneOperation(int id); - Task UpdateOperationPlan(OperationCreatePlan OperationPlan, List properties); - } } diff --git a/SolarPower/Views/Operation/Index.cshtml b/SolarPower/Views/Operation/Index.cshtml index a82e2d8..a4d9d53 100644 --- a/SolarPower/Views/Operation/Index.cshtml +++ b/SolarPower/Views/Operation/Index.cshtml @@ -357,8 +357,8 @@ //#region 儲存定時計畫資料 function SaveOperationPlan() { var url = "/Operation/SaveOperationPlan"; + var send_data = { - id: selected_id, PowerStationId: $("#operation_powerStationselect_modal").val(), Type: $("#operation_type_modal").val(), ScheduleNum: $("#operation_scheduleNum_modal").val(), @@ -413,44 +413,6 @@ }); }); //#endregion - //#region 取一筆定時計畫 - $('#OperationPlan_table').on("click", "button.edit-btn", function () { - $("#Operation-modal .modal-title").html("定時計劃 - 編輯"); - selected_id = $(this).parents('tr').attr('data-id'); - - //取得單一異常設定資料 - var url = "/Operation/GetOneOperationPlan/"; - - var send_data = { - id: selected_id - } - - - $.post(url, send_data, function (rel) { - if (rel.code != "0000") { - toast_error(rel.msg); - return; - } - - $("#operation_powerStationselect_modal").val(rel.data.powerStationId); - $("#operation_type_modal").val(rel.data.type); - $("#operation_scheduleNum_modal").val(rel.data.scheduleNum); - $("#operation_scheduleType_modal").val(rel.data.scheduleType); - $("#operation_workDay_modal").val(rel.data.workDay); - var start = rel.data.startTime.split(' '); - $("#operation_startTime_modal").val(start[0]); - $("#operation_description_modal").val(rel.data.description); - $("#operation_emailType_modal").val(rel.data.emailType); - - var dat = new Date(start); - var day = new Date(dat.setDate(dat.getDate() + Number(rel.data.workDay))).toISOString().split("T"); - document.getElementById("operation_endTime_modal").innerHTML = day[0]; - - $("#Operation-modal").modal(); - }, 'json'); - - }); - //#endregion } \ No newline at end of file From b102d2e46e3eb5860c75a8415e4f6592efa58801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=82=E4=BB=BB=20=E6=9E=97?= Date: Wed, 23 Jun 2021 09:31:33 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E9=9B=BB=E7=AB=99=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E5=8F=8A=E7=B8=A3=E5=B8=82=E5=88=86=E4=BD=88=E5=BE=8C=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Controllers/OperationController.cs | 2 +- .../Controllers/PowerStationController.cs | 23 ++++++++ .../Implement/PowerStationRepository.cs | 55 +++++++++++++++++-- .../Interface/IPowerStationRepository.cs | 15 +++++ SolarPower/Views/PowerStation/Index.cshtml | 27 +++++++-- 5 files changed, 113 insertions(+), 9 deletions(-) diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index 688381f..0650218 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -255,7 +255,7 @@ namespace SolarPower.Controllers return apiResult; } - await operationRepository.DeleteOneOtherTable(Id, "operation_plan_create"); + //await operationRepository.DeleteOneOtherTable(Id, "operation_plan_create"); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index d7d3ef8..16f33b7 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -1864,5 +1864,28 @@ namespace SolarPower.Controllers return apiResult; } + + /// + /// 取得該使用者可看的所有電站分佈縣市以及各縣市電站數量 + /// + /// + public async Task>> GetSolarByCity(List cityid) + { + ApiResult> apiResult = new ApiResult>(); + List solaramount = new List(); + try + { + apiResult.Code = "0000"; + solaramount = await powerStationRepository.GetSolarByCity(myUser, cityid); + apiResult.Data = solaramount; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } + + return apiResult; + } } } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 635dee1..2eae156 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -621,7 +621,7 @@ namespace SolarPower.Repository.Implement try { string sql = @$"SELECT * FROM variable WHERE name = @name"; - var json = await conn.QueryFirstOrDefaultAsync(sql, new { name = "Type" }); + var json = await conn.QueryFirstOrDefaultAsync(sql, new { name = "Type" }); Root jsonfor = JsonSerializer.Deserialize(json.value); foreach (Models.PowerStation.Type a in jsonfor.Type) { @@ -1286,19 +1286,19 @@ namespace SolarPower.Repository.Implement { if (User.Role.Layer == 0 || User.Role.Layer == 1) { - var sql = "SELECT city.Id AS CityId city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id GROUP BY power_station.CityId"; + var sql = "SELECT city.Id AS CityId, city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id GROUP BY power_station.CityId"; solaramount = (await conn.QueryAsync(sql)).ToList(); trans.Commit(); } else if (User.Role.Layer == 2) { - var sql = "SELECT city.Id AS CityId city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id WHERE CompanyId = @CompanyId GROUP BY power_station.CityId ORDER BY power_station.CityId "; + var sql = "SELECT city.Id AS CityId, city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id WHERE CompanyId = @CompanyId GROUP BY power_station.CityId ORDER BY power_station.CityId "; solaramount = (await conn.QueryAsync(sql, new { CompanyId = User.CompanyId })).ToList(); trans.Commit(); } else { - var sql = "SELECT city.Id AS CityId city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id LEFT JOIN power_station_operation_personnel ON power_station.Id = power_station_operation_personnel.PowerStationId WHERE UserId = @UserId GROUP BY power_station.CityId ORDER BY power_station.CityId"; + var sql = "SELECT city.Id AS CityId, city.Name AS City,COUNT(*) AS Amount FROM power_station LEFT JOIN city ON power_station.CityId = city.Id LEFT JOIN power_station_operation_personnel ON power_station.Id = power_station_operation_personnel.PowerStationId WHERE UserId = @UserId GROUP BY power_station.CityId ORDER BY power_station.CityId"; solaramount = (await conn.QueryAsync(sql, new { UserId = User.Id })).ToList(); trans.Commit(); } @@ -1314,5 +1314,52 @@ namespace SolarPower.Repository.Implement } return solaramount; } + public async Task> GetSolarByCity(MyUser User, List CityId) + { + using IDbConnection conn = _databaseHelper.GetConnection(); + List powerstation = new List(); + conn.Open(); + var trans = conn.BeginTransaction(); + try + { + var ids = ""; + foreach(var id in CityId) + { + ids = ids + id + ","; + } + if (ids.Length != 0) + { + ids = ids.Substring(0, ids.Length - 1); + } + if (User.Role.Layer == 0 || User.Role.Layer == 1) + { + var sql = "SELECT * FROM power_station WHERE CityId IN(@Ids)"; + powerstation = (await conn.QueryAsync(sql, new { Ids = ids })).ToList(); + trans.Commit(); + } + else if (User.Role.Layer == 2) + { + var sql = "SELECT * FROM power_station WHERE CityId IN(@Ids) AND CompanyId=@CompanyId"; + powerstation = (await conn.QueryAsync(sql, new { Ids = ids ,CompanyId = User.CompanyId })).ToList(); + trans.Commit(); + } + else + { + var sql = "SELECT power_station.* FROM power_station LEFT JOIN power_station_operation_personnel ON power_station.Id = power_station_operation_personnel.PowerStationId WHERE CityId IN(@Ids) AND Userid = @UserId"; + powerstation = (await conn.QueryAsync(sql, new { UserId = User.Id })).ToList(); + trans.Commit(); + } + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + return powerstation; + } } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 1020046..d9ab904 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -326,5 +326,20 @@ namespace SolarPower.Repository.Interface /// /// Task DeleteOnePowerStationSingleLine(int id, string db_name); + + /// + /// 取得電站分佈縣市以及數量 + /// + /// + /// + Task> GetSolarCitySummary(MyUser User); + + /// + /// 透過縣市取得電站卡片資訊 + /// + /// + /// + /// + Task> GetSolarByCity(MyUser User, List CityId); } } diff --git a/SolarPower/Views/PowerStation/Index.cshtml b/SolarPower/Views/PowerStation/Index.cshtml index a905838..a3f8fe4 100644 --- a/SolarPower/Views/PowerStation/Index.cshtml +++ b/SolarPower/Views/PowerStation/Index.cshtml @@ -414,15 +414,35 @@ //#region 電站區域Tab - var url = "/PowerStation/GetSolarCitySummary"; - $.post(url, function (rel) { + //var url = "/PowerStation/GetSolarCitySummary"; + //$.post(url, function (rel) { + // if (rel.code != "0000") { + // toast_error(rel.msg); + // return; + // } + // else { + // $.each(rel.data, function (index, val) { + // alert(val.city + val.amount); + // }); + // return; + // } + + + //}, 'json'); + + var url = "/PowerStation/GetSolarByCity"; + var ids = [1, 3]; + var send_data = { + cityid: ids + } + $.post(url, send_data, function (rel) { if (rel.code != "0000") { toast_error(rel.msg); return; } else { $.each(rel.data, function (index, val) { - //alert(val.city + val.amount); + alert(val.name); }); return; } @@ -430,7 +450,6 @@ }, 'json'); - //#endregion //電站區域 From 247ee4206688b82f38063c7d02582559b2fa6396 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Wed, 23 Jun 2021 10:57:45 +0800 Subject: [PATCH 5/6] =?UTF-8?q?recode=E8=A1=A8=E5=BB=BA=E7=AB=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Controllers/OperationController.cs | 147 +++++++++++++----- SolarPower/Helper/DatabaseHelper.cs | 2 +- SolarPower/Models/Operation.cs | 45 +++++- .../Implement/OperationRepository.cs | 55 ++++++- .../Interface/IOperationRepository.cs | 3 + SolarPower/Views/Operation/Index.cshtml | 43 ++++- 6 files changed, 254 insertions(+), 41 deletions(-) diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index 7767fd1..d9b6902 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -67,41 +67,98 @@ namespace SolarPower.Controllers ApiResult apiResult = new ApiResult(); try { - var now = DateTime.Now.ToString("yyyy-MM-dd"); - var finalid = await operationRepository.GetCurrentSerialNumber("operation_plan_create", $"PowerStationId = {post.PowerStationId} AND CreatedAt LIKE '%{now}%'"); - var newSerialNumber = GetLastSerialNumber(finalid); - var OperationPlan = new OperationCreatePlan() - { - EmailType = post.EmailType, - ScheduleNum = post.ScheduleNum, - Description = post.Description, - WorkDay = post.WorkDay, - ScheduleType = post.ScheduleType, - SerialNumber = newSerialNumber, - StartTime = post.StartTime, - PowerStationId = post.PowerStationId, - Type = post.Type, - PlanId = DateTime.Now.ToString("yyyyMMdd") + newSerialNumber, - CreatedBy = myUser.Id - }; - List properties = new List() - { - "EmailType", - "ScheduleNum", - "Description", - "WorkDay", - "ScheduleType", - "SerialNumber", - "StartTime", - "PowerStationId", - "Type", - "PlanId", - "CreatedBy" - }; - await operationRepository.AddOperationPlan(OperationPlan, properties); - apiResult.Code = "0000"; - apiResult.Msg = "新增成功"; + if (post.Id == 0) + { + var now = DateTime.Now.ToString("yyyy-MM-dd"); + var finalid = await operationRepository.GetCurrentSerialNumber("operation_plan_create", $"PowerStationId = {post.PowerStationId} AND CreatedAt LIKE '%{now}%'"); + var newSerialNumber = GetLastSerialNumber(finalid); + var OperationPlan = new OperationCreatePlan() + { + EmailType = post.EmailType, + ScheduleNum = post.ScheduleNum, + Description = post.Description, + WorkDay = post.WorkDay, + ScheduleType = post.ScheduleType, + SerialNumber = newSerialNumber, + StartTime = post.StartTime, + PowerStationId = post.PowerStationId, + Type = post.Type, + PlanId = DateTime.Now.ToString("yyyyMMdd") + newSerialNumber, + CreatedBy = myUser.Id + }; + List properties = new List() + { + "EmailType", + "ScheduleNum", + "Description", + "WorkDay", + "ScheduleType", + "SerialNumber", + "StartTime", + "PowerStationId", + "Type", + "PlanId", + "CreatedBy" + }; + await operationRepository.AddOperationPlan(OperationPlan, properties); + + var record = new PlanToRecord() + { + WorkType = post.Type, + PowerStationId = post.PowerStationId, + StartTime = post.StartTime, + CreatedBy = myUser.Id, + EndTime = post.EndTime + }; + List properties2 = new List() + { + "WorkType", + "PowerStationId", + "StartTime", + "CreatedBy", + "EndTime" + }; + await operationRepository.AddToRecord(record, properties2); + + apiResult.Code = "0000"; + apiResult.Msg = "新增成功"; + } + else + { + var OperationPlan = new OperationCreatePlan() + { + Id = post.Id, + EmailType = post.EmailType, + ScheduleNum = post.ScheduleNum, + Description = post.Description, + WorkDay = post.WorkDay, + ScheduleType = post.ScheduleType, + StartTime = post.StartTime, + PowerStationId = post.PowerStationId, + Type = post.Type, + UpdatedBy = myUser.Id + }; + List properties = new List() + { + "Id", + "EmailType", + "ScheduleNum", + "Description", + "WorkDay", + "ScheduleType", + "StartTime", + "PowerStationId", + "Type", + "UpdatedBy" + }; + await operationRepository.UpdateOperationPlan(OperationPlan, properties); + apiResult.Code = "0000"; + apiResult.Msg = "編輯成功"; + } + + + } catch (Exception exception) { @@ -157,7 +214,7 @@ namespace SolarPower.Controllers a.Schedule = "每" + a.ScheduleNum.ToString() + "年"; } - a.StartTimeString = a.StartTime.ToString("yyyy-MM-dd"); + a.StartTimeString = a.StartTime; var crst = a.CreatedAt.Split(" "); a.CreateTimeString = crst[0]; @@ -233,5 +290,25 @@ namespace SolarPower.Controllers return apiResult; } + + public async Task> GetOneOperationPlan(int Id) + { + ApiResult apiResult = new ApiResult(); + OperationCreatePlan operationCreatePlan = new OperationCreatePlan(); + try + { + apiResult.Code = "0000"; + operationCreatePlan = await operationRepository.GetOneOperation(Id); + apiResult.Data = operationCreatePlan; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + Id); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + return apiResult; + } } } diff --git a/SolarPower/Helper/DatabaseHelper.cs b/SolarPower/Helper/DatabaseHelper.cs index d417841..e9aed88 100644 --- a/SolarPower/Helper/DatabaseHelper.cs +++ b/SolarPower/Helper/DatabaseHelper.cs @@ -37,7 +37,7 @@ namespace SolarPower.Helper var passwordStr = ed.AESDecrypt(dbConfig.Password); //var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; - var connStr = @"server=127.0.0.1;port=3306;database=solar_power;user=root;password=000000;charset=utf8;"; + var connStr = @"server=127.0.0.1;port=3308;database=solar_power;user=root;password=00000000;charset=utf8;"; this._connectionString = connStr; } diff --git a/SolarPower/Models/Operation.cs b/SolarPower/Models/Operation.cs index 4ddacba..394dc1e 100644 --- a/SolarPower/Models/Operation.cs +++ b/SolarPower/Models/Operation.cs @@ -28,14 +28,43 @@ namespace SolarPower.Models } public class OperationCreatePlanModal : Created { + private string startTime = "", endTime = ""; public int Id { get; set; } public int PowerStationId { get; set; } public int Type { get; set; } public int ScheduleNum { get; set; } public int ScheduleType { get; set; } public int WorkDay { get; set; } - public DateTime StartTime { get; set; } - public DateTime EndTime { get; set; } + public string StartTime + { + get + { + if (!string.IsNullOrEmpty(startTime)) + { + return Convert.ToDateTime(startTime).ToString("yyyy-MM-dd"); + } + else + { + return null; + } + } + set { startTime = value; } + } + public string EndTime + { + get + { + if (!string.IsNullOrEmpty(endTime)) + { + return Convert.ToDateTime(endTime).ToString("yyyy-MM-dd"); + } + else + { + return null; + } + } + set { endTime = value; } + } public string Description { get; set; } public int EmailType { get; set; } } @@ -43,6 +72,10 @@ namespace SolarPower.Models { public string PlanId { get; set; } public string SerialNumber { get; set; } + + private string updatedAt; + public int UpdatedBy { get; set; } //修改者 + public string UpdatedAt { get { return Convert.ToDateTime(updatedAt).ToString("yyyy-MM-dd HH:mm:ss"); } set { updatedAt = value; } } //修改時間 } public class OperationPlanTable : OperationCreatePlan { @@ -56,4 +89,12 @@ namespace SolarPower.Models public string StartTimeString { get; set; } public string CreateTimeString { get; set; } } + + public class PlanToRecord : Created + { + public int PowerStationId { get; set; } + public int WorkType { get; set; } + public string StartTime { get; set; } + public string EndTime { get; set; } + } } diff --git a/SolarPower/Repository/Implement/OperationRepository.cs b/SolarPower/Repository/Implement/OperationRepository.cs index 063c5ad..529fd9b 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -80,7 +80,9 @@ namespace SolarPower.Repository.Implement { try { - var sql = @$"SELECT *,ps.Name AS PowerStationName ,us.Name AS CreatedPerson FROM operation_plan_create oc LEFT JOIN power_station ps + var sql = @$"SELECT oc.Id,oc.PlanId,oc.PowerStationId,oc.Type, + oc.ScheduleNum,oc.ScheduleType,oc.WorkDay,oc.StartTime, + oc.EmailType,oc.Description,oc.CreatedAt,ps.Name AS PowerStationName ,us.Name AS CreatedPerson FROM operation_plan_create oc LEFT JOIN power_station ps ON oc.PowerStationId = ps.Id LEFT JOIN user us ON us.Id = oc.CreatedBy WHERE {Wheresql} AND oc.Deleted = 0"; result = (await conn.QueryAsync(sql)).ToList(); @@ -116,5 +118,56 @@ namespace SolarPower.Repository.Implement return result; } } + + public async Task UpdateOperationPlan(OperationCreatePlan OperationPlan, List properties) + { + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + var trans = conn.BeginTransaction(); + try + { + var sql = GenerateUpdateQuery(properties); + await conn.ExecuteAsync(sql, OperationPlan, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + + } + } + + public async Task AddToRecord(PlanToRecord record, List properties2) + { + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + var trans = conn.BeginTransaction(); + try + { + string sql = GenerateInsertQueryWithCustomTable(properties2, "operation_record"); + await conn.ExecuteAsync(sql, record); + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + + } + } } } diff --git a/SolarPower/Repository/Interface/IOperationRepository.cs b/SolarPower/Repository/Interface/IOperationRepository.cs index 284afb2..8b492ac 100644 --- a/SolarPower/Repository/Interface/IOperationRepository.cs +++ b/SolarPower/Repository/Interface/IOperationRepository.cs @@ -12,6 +12,9 @@ namespace SolarPower.Repository.Interface Task AddOperationPlan(OperationCreatePlan OperationPlan, List properties); Task> OperationPlanTable(List id); Task GetOneOperation(int id); + Task UpdateOperationPlan(OperationCreatePlan OperationPlan, List properties); + Task AddToRecord(PlanToRecord record, List properties2); + } } diff --git a/SolarPower/Views/Operation/Index.cshtml b/SolarPower/Views/Operation/Index.cshtml index a4d9d53..e9e9ef8 100644 --- a/SolarPower/Views/Operation/Index.cshtml +++ b/SolarPower/Views/Operation/Index.cshtml @@ -1,5 +1,5 @@ @{ - ViewData["MainNum"] = "5"; + ViewData["MainNum"] = "6"; ViewData["SubNum"] = "1"; ViewData["Title"] = "運維管理"; } @@ -359,13 +359,14 @@ var url = "/Operation/SaveOperationPlan"; var send_data = { + id: selected_id, PowerStationId: $("#operation_powerStationselect_modal").val(), Type: $("#operation_type_modal").val(), ScheduleNum: $("#operation_scheduleNum_modal").val(), ScheduleType: $("#operation_scheduleType_modal").val(), WorkDay: $('#operation_workDay_modal').val(), StartTime: $("#operation_startTime_modal").val(), - EndTime: $("#operation_endTime_modal").val(), + EndTime: document.getElementById("operation_endTime_modal").innerHTML, Description: $("#operation_description_modal").val(), EmailType: $('#operation_emailType_modal').val() } @@ -413,6 +414,44 @@ }); }); //#endregion + //#region 取一筆定時計畫 + $('#OperationPlan_table').on("click", "button.edit-btn", function () { + $("#Operation-modal .modal-title").html("定時計劃 - 編輯"); + selected_id = $(this).parents('tr').attr('data-id'); + + //取得單一異常設定資料 + var url = "/Operation/GetOneOperationPlan/"; + + var send_data = { + id: selected_id + } + + + $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + $("#operation_powerStationselect_modal").val(rel.data.powerStationId); + $("#operation_type_modal").val(rel.data.type); + $("#operation_scheduleNum_modal").val(rel.data.scheduleNum); + $("#operation_scheduleType_modal").val(rel.data.scheduleType); + $("#operation_workDay_modal").val(rel.data.workDay); + var start = rel.data.startTime.split(' '); + $("#operation_startTime_modal").val(start[0]); + $("#operation_description_modal").val(rel.data.description); + $("#operation_emailType_modal").val(rel.data.emailType); + + var dat = new Date(start); + var day = new Date(dat.setDate(dat.getDate() + Number(rel.data.workDay))).toISOString().split("T"); + document.getElementById("operation_endTime_modal").innerHTML = day[0]; + + $("#Operation-modal").modal(); + }, 'json'); + + }); + //#endregion } \ No newline at end of file From b91ba96b360a0b3e34eba696477a404bba84348b Mon Sep 17 00:00:00 2001 From: b110212000 Date: Wed, 23 Jun 2021 10:59:10 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=BF=94=E5=93=A5=E5=88=A5=E7=BD=B5?= =?UTF-8?q?=E6=88=91=E5=8F=88=E6=8A=8AHelper=20Git=E4=B8=8A=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Helper/DatabaseHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SolarPower/Helper/DatabaseHelper.cs b/SolarPower/Helper/DatabaseHelper.cs index e9aed88..d417841 100644 --- a/SolarPower/Helper/DatabaseHelper.cs +++ b/SolarPower/Helper/DatabaseHelper.cs @@ -37,7 +37,7 @@ namespace SolarPower.Helper var passwordStr = ed.AESDecrypt(dbConfig.Password); //var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; - var connStr = @"server=127.0.0.1;port=3308;database=solar_power;user=root;password=00000000;charset=utf8;"; + var connStr = @"server=127.0.0.1;port=3306;database=solar_power;user=root;password=000000;charset=utf8;"; this._connectionString = connStr; }