From 886e1aa450676217e4cfb44537767c250dd6fe9d Mon Sep 17 00:00:00 2001 From: Kai Date: Mon, 28 Jun 2021 14:01:34 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=96=B0=E5=A2=9E=E5=B8=B3=E8=99=9F?= =?UTF-8?q?=E5=AF=84=E9=80=81=E4=BF=A1=E4=BB=B6=202.=20=E9=BB=9E=E5=9C=96?= =?UTF-8?q?=E6=94=BE=E5=A4=A7=20part1=203.=20=E9=81=8B=E7=B6=AD=E4=BD=9C?= =?UTF-8?q?=E6=A5=AD=E8=A8=98=E9=8C=84=20=E6=97=A5=E6=9C=9F=E7=AF=84?= =?UTF-8?q?=E5=9C=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Controllers/LoginController.cs | 2 +- SolarPower/Controllers/OperationController.cs | 5 -- SolarPower/Controllers/UserController.cs | 21 ++++++-- SolarPower/Models/Operation.cs | 2 + .../Implement/OperationRepository.cs | 54 ++++++++++++++----- .../Views/Operation/OperationRecord.cshtml | 50 ++++++++++++++--- .../PowerStation/PowerStationEdit.cshtml | 4 +- .../Views/PowerStation/_DeviceSetting.cshtml | 6 +-- .../Views/PowerStation/_UploadImage.cshtml | 2 +- SolarPower/Views/Shared/_Layout.cshtml | 9 +++- SolarPower/wwwroot/js/image.zoom.js | 49 +++++++++++++++++ 11 files changed, 167 insertions(+), 37 deletions(-) create mode 100644 SolarPower/wwwroot/js/image.zoom.js diff --git a/SolarPower/Controllers/LoginController.cs b/SolarPower/Controllers/LoginController.cs index e4b5df8..c543559 100644 --- a/SolarPower/Controllers/LoginController.cs +++ b/SolarPower/Controllers/LoginController.cs @@ -144,7 +144,7 @@ namespace SolarPower.Controllers UpdatePassword update = new UpdatePassword() { - Password = edFunction.GetSHA256Encryption(newPassword), + Password = newPassword, UpdatedBy = user.Id, Id = user.Id }; diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index f5f0635..a0f1a6f 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -334,11 +334,6 @@ namespace SolarPower.Controllers try { - //if (!IsPlatformLayer(myUser.Role.Layer)) - //{ //如果只是身分公司管理員 或 公司使用者,就只能看自己公司的資料 - // post.SelectedCompanyId = myUser.CompanyId; - //} - recodes = await operationRepository.GetAllRecodeByFilterAsync(post); foreach (var recode in recodes) diff --git a/SolarPower/Controllers/UserController.cs b/SolarPower/Controllers/UserController.cs index ea85dc8..8c133cb 100644 --- a/SolarPower/Controllers/UserController.cs +++ b/SolarPower/Controllers/UserController.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using SolarPower.Models; using SolarPower.Models.User; using SolarPower.Repository.Interface; +using SolarPower.Services.Interface; using System; using System.Collections.Generic; using System.Data; @@ -20,10 +21,13 @@ namespace SolarPower.Controllers { private readonly IUserRepository userRepository; + private readonly ISendEmailService sendEmailService; private string logoPath = "/upload/company_logo/"; - public UserController(IUserRepository userRepository) : base() + public UserController(IUserRepository userRepository, + ISendEmailService sendEmailService) : base() { this.userRepository = userRepository; + this.sendEmailService = sendEmailService; } public IActionResult Index() @@ -299,8 +303,7 @@ namespace SolarPower.Controllers const string chars = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789"; string random_password = new string(Enumerable.Repeat(chars, 8).Select(s => s[random.Next(chars.Length)]).ToArray()); - //TODO 新增的密碼要寄信 - random_password = edFunction.GetSHA256Encryption(random_password); + var newPassword = edFunction.GetSHA256Encryption(random_password); user = new User() { @@ -308,7 +311,7 @@ namespace SolarPower.Controllers Name = post.Name, Email = post.Email, Account = post.Account, - Password = random_password, + Password = newPassword, RoleId = post.RoleId, Phone = post.Phone, CreatedBy = myUser.Id, @@ -328,6 +331,16 @@ namespace SolarPower.Controllers await userRepository.AddAsync(user, properties); + var sendSubject = "新增帳號成功"; + var sendContent = $"您的新密碼為:{random_password}"; + + List recipientEmails = new List() + { + user.Email + }; + + sendEmailService.Send(recipientEmails, sendSubject, sendContent); + apiResult.Code = "0000"; apiResult.Msg = "儲存成功"; #endregion diff --git a/SolarPower/Models/Operation.cs b/SolarPower/Models/Operation.cs index 3564efc..fd93849 100644 --- a/SolarPower/Models/Operation.cs +++ b/SolarPower/Models/Operation.cs @@ -212,6 +212,8 @@ namespace SolarPower.Models public List PowerStationIds { get; set; } //電站編號 public byte WorkType { get; set; } //工作項目 public string Range { 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 f047d97..63099ce 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -58,12 +58,12 @@ namespace SolarPower.Repository.Implement } } - public async Task> OperationPlanTable(List id,int Type) + public async Task> OperationPlanTable(List id, int Type) { List result; var count = 0; string Wheresql = "oc.PowerStationId = "; - if( id.Count > 0 ) + if (id.Count > 0) { foreach (int too in id) { @@ -78,13 +78,13 @@ namespace SolarPower.Repository.Implement } count++; } - + } else { Wheresql += "0"; } - + using (IDbConnection conn = this._databaseHelper.GetConnection()) { try @@ -106,7 +106,7 @@ namespace SolarPower.Repository.Implement 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(); } @@ -215,15 +215,19 @@ namespace SolarPower.Repository.Implement WHERE opr.Deleted = 0 AND ps.Id IN @PowerStationIds"; + if (!string.IsNullOrEmpty(filter.Range)) + { + filter.StartTime = filter.Range.Split('-')[0]; + filter.EndTime = filter.Range.Split('-')[1]; + + sql += " AND opr.StartTime <= @EndDate"; + sql += " AND opr.EndTime >= @StartDate"; + } + if (filter.WorkType > 0) { - filter.WorkType -= 1; + filter.WorkType -= 1; sql += @" AND opr.WorkType = @WorkType"; - - if (!string.IsNullOrEmpty(filter.Range)) - { - - } } else { @@ -239,9 +243,33 @@ namespace SolarPower.Repository.Implement WHERE opr.Deleted = 0 AND ps.Id IN @PowerStationIds AND opr.WorkType = 2"; + if (!string.IsNullOrEmpty(filter.Range)) + { + filter.StartTime = filter.Range.Split('-')[0]; + filter.EndTime = filter.Range.Split('-')[1]; + + sql += " AND opr.StartTime <= @EndDate"; + sql += " AND opr.EndTime >= @StartDate"; + } + else + { + var today = DateTime.Now.ToString("yyyy-MM-dd"); + var dateLimit = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd"); + + sql += $" AND opr.CreatedAt BETWEEN '{dateLimit} 00:00:00' AND '{today} 23:59:59'"; + + //sql += $" AND opr.StartTime <= {today}"; + //sql += $" AND opr.EndTime >= {dateLimit}"; + } } - result = (await conn.QueryAsync(sql, filter)).ToList(); + result = (await conn.QueryAsync(sql, + new { + PowerStationIds = filter.PowerStationIds, + WorkType = filter.WorkType, + StartDate = filter.StartTime, + EndDate = filter.EndTime + })).ToList(); var sql_file = "SELECT * FROM operation_record_file WHERE Deleted = 0 AND RecordId = @RecordId"; foreach (var x in result) @@ -278,7 +306,7 @@ namespace SolarPower.Repository.Implement result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); - if(result != null) + if (result != null) { //取得圖片 or 檔案 var sql_file = @"SELECT * FROM operation_record_file WHERE Deleted = 0 AND RecordId = @RecordId"; diff --git a/SolarPower/Views/Operation/OperationRecord.cshtml b/SolarPower/Views/Operation/OperationRecord.cshtml index d502d86..ab7f743 100644 --- a/SolarPower/Views/Operation/OperationRecord.cshtml +++ b/SolarPower/Views/Operation/OperationRecord.cshtml @@ -29,11 +29,11 @@
- +
- +
@@ -241,6 +241,7 @@ var Allids = new Array(0);//全部縣市 var Allpowerids = new Array(0);//全部電站 var Type = 0; // 項目 + var datepicker; //#region Array.Remove Array.prototype.remove = function (val) { @@ -252,14 +253,28 @@ //#endregion $(function () { - $('input[id="example-date"]').daterangepicker({ + //#region Date Picker + datepicker = $('#date-range').daterangepicker({ + autoUpdateInput: false, + locale: { format: 'YYYY/MM/DD' }, opens: 'left' }, function (start, end, label) { - console.log("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD')); + @*console.log("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));*@ }); + $('#date-range').on('apply.daterangepicker', function (ev, picker) { + $(this).val(picker.startDate.format('YYYY/MM/DD') + ' - ' + picker.endDate.format('YYYY/MM/DD')); + $(this).trigger('change'); + }); + + $('#date-range').on('cancel.daterangepicker', function (ev, picker) { + $(this).val(''); + $(this).trigger('change'); + }); + + //#endregion + //#region 預設載入該使用者可以選擇的電站 - //#region 載入縣市 var Nurl = "/PowerStation/GetSolarCitySummary"; $.post(Nurl, function (rel) { if (rel.code != "0000") { @@ -306,7 +321,6 @@ }) }) //#endregion - //#endregion //#region 切換電站時,載入該電站運維人員 $("#power_station_select_modal").change(function () { @@ -417,7 +431,7 @@ "data": function (d) { d.PowerStationIds = powerids; d.WorkType = Type; - d.Range = $('#company_taxIDNumber').val(); + d.Range = $('#date-range').val(); }, "dataSrc": function (rel) { if (rel.data.code == "9999") { @@ -453,6 +467,12 @@ } //#endregion + //#region 改變日期 + $('#date-range').on('change', function () { + operationRecodeTable.ajax.reload(); + }); + //#endregion + //#region 新增維修單 function AddRecode() { selected_id = 0; @@ -852,5 +872,21 @@ }, 'json'); } //#endregion + + //#region 查詢近30天 + function ChangeDate30() { + var today = new Date(); + var dateLimit = new Date(new Date().setDate(today.getDate() - 30)); + + var today_format = today.toISOString().slice(0, 10).replace(/-/g, "/"); + var dateLimit_format = dateLimit.toISOString().slice(0, 10).replace(/-/g, "/"); + + datepicker.data('daterangepicker').setStartDate(dateLimit_format); + datepicker.data('daterangepicker').setEndDate(today_format); + + $('#date-range').val(dateLimit_format + ' - ' + today_format); + $('#date-range').trigger('change'); + } + //#endregion } \ No newline at end of file diff --git a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml index c27e117..1f2f3f3 100644 --- a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml +++ b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml @@ -436,7 +436,7 @@ powerStationSingleLineCard = $("#power-station-image-card > .row"); powerStationSingleLineCard.empty(); rel.data.forEach(function (value, index) { - CreatePowerStationSingleLineBox(powerStationSingleLineCard, value); + CreatePowerStationImageBox(powerStationSingleLineCard, value); }); }, 'json'); @@ -1794,7 +1794,7 @@ function CreatePowerStationImageBox(dom, value) { var str = '
' + '
' + - '...' + + '...' + '' + '' + '' + diff --git a/SolarPower/Views/PowerStation/_DeviceSetting.cshtml b/SolarPower/Views/PowerStation/_DeviceSetting.cshtml index e35ba31..1749c57 100644 --- a/SolarPower/Views/PowerStation/_DeviceSetting.cshtml +++ b/SolarPower/Views/PowerStation/_DeviceSetting.cshtml @@ -37,7 +37,7 @@
-
+
@@ -66,7 +66,7 @@ -
+
@@ -101,7 +101,7 @@ -
+
diff --git a/SolarPower/Views/PowerStation/_UploadImage.cshtml b/SolarPower/Views/PowerStation/_UploadImage.cshtml index 9d5610a..4d0c770 100644 --- a/SolarPower/Views/PowerStation/_UploadImage.cshtml +++ b/SolarPower/Views/PowerStation/_UploadImage.cshtml @@ -11,7 +11,7 @@
-
+
diff --git a/SolarPower/Views/Shared/_Layout.cshtml b/SolarPower/Views/Shared/_Layout.cshtml index 12bcb77..43de41b 100644 --- a/SolarPower/Views/Shared/_Layout.cshtml +++ b/SolarPower/Views/Shared/_Layout.cshtml @@ -1094,6 +1094,13 @@
+ + + @@ -1116,11 +1123,11 @@ + - @*各頁面的JavaScript*@ @RenderSection("Scripts", required: false) diff --git a/SolarPower/wwwroot/js/image.zoom.js b/SolarPower/wwwroot/js/image.zoom.js new file mode 100644 index 0000000..f413f0f --- /dev/null +++ b/SolarPower/wwwroot/js/image.zoom.js @@ -0,0 +1,49 @@ +(function () { + +}); + +$(".img-zoom-div").on("click", "img.img-zoom", function () { + var _this = $(this);//將當前的pimg元素作為_this傳入函式 + imgShow("#img-zoom-outer-div", "#innerdiv", "#bigimg", _this); +}); + +function imgShow(outerdiv, innerdiv, bigimg, _this) { + var src = _this.attr("src");//獲取當前點選的pimg元素中的src屬性 + $(bigimg).attr("src", src);//設定#bigimg元素的src屬性 + + /*獲取當前點選圖片的真實大小,並顯示彈出層及大圖*/ + $(_this).attr("src", src).on("load", function () { + var windowW = $(window).width();//獲取當前視窗寬度 + var windowH = $(window).height();//獲取當前視窗高度 + var realWidth = this.width;//獲取圖片真實寬度 + var realHeight = this.height;//獲取圖片真實高度 + var imgWidth, imgHeight; + //var scale = 0.8;//縮放尺寸,當圖片真實寬度和高度大於視窗寬度和高度時進行縮放 + + var scale = 1440 / realWidth; //放大圖片到1440p + + if (realHeight > windowH * scale) {//判斷圖片高度 + imgHeight = windowH * scale;//如大於視窗高度,圖片高度進行縮放 + imgWidth = imgHeight / realHeight * realWidth;//等比例縮放寬度 + if (imgWidth > windowW * scale) {//如寬度扔大於視窗寬度 + imgWidth = windowW * scale;//再對寬度進行縮放 + } + } else if (realWidth > windowW * scale) {//如圖片高度合適,判斷圖片寬度 + imgWidth = windowW * scale;//如大於視窗寬度,圖片寬度進行縮放 + imgHeight = imgWidth / realWidth * realHeight;//等比例縮放高度 + } else {//如果圖片真實高度和寬度都符合要求,高寬不變 + imgWidth = realWidth; + imgHeight = realHeight; + } + $(bigimg).css("width", imgWidth);//以最終的寬度對圖片縮放 + + var w = (windowW - imgWidth) / 2;//計算圖片與視窗左邊距 + var h = (windowH - imgHeight) / 2;//計算圖片與視窗上邊距 + $(innerdiv).css({ "top": h, "left": w });//設定#innerdiv的top和left屬性 + $(outerdiv).fadeIn("fast");//淡入顯示#outerdiv及.pimg + }); + + $(outerdiv).click(function () {//再次點選淡出消失彈出層 + $(this).fadeOut("fast"); + }); +} \ No newline at end of file