..
This commit is contained in:
parent
d2b386cc18
commit
196b00595a
@ -68,7 +68,6 @@ namespace SolarPower.Controllers
|
||||
UpdatedBy = myUser.Id,
|
||||
Kwh = post.Kwh,
|
||||
Money = post.Money,
|
||||
PowerstationId = post.PowerstationId,
|
||||
StartAt = post.StartAt
|
||||
};
|
||||
List<string> properties = new List<string>()
|
||||
@ -78,7 +77,6 @@ namespace SolarPower.Controllers
|
||||
"UpdatedBy",
|
||||
"Kwh",
|
||||
"Money",
|
||||
"PowerstationId",
|
||||
"StartAt"
|
||||
};
|
||||
await electricitySoldRecordRepository.Update(record, properties);
|
||||
@ -99,11 +97,18 @@ namespace SolarPower.Controllers
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> RecordTable(ElectricitySoldRecordTablePost info)
|
||||
{
|
||||
List<ElectricitySoldRecordTable> electricitySoldRecordTable = new List<ElectricitySoldRecordTable>();
|
||||
ApiResult<List<ElectricitySoldRecordTable>> apiResult = new ApiResult<List<ElectricitySoldRecordTable>>();
|
||||
try
|
||||
{
|
||||
if(info.StationId == null || info.Time == null)
|
||||
{
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
else
|
||||
{
|
||||
electricitySoldRecordTable = await electricitySoldRecordRepository.RecordTable(info);
|
||||
foreach (ElectricitySoldRecordTable a in electricitySoldRecordTable)
|
||||
@ -111,10 +116,12 @@ namespace SolarPower.Controllers
|
||||
a.Function = @"
|
||||
<button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'>修改</button>
|
||||
<button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'>刪除</button>";
|
||||
a.CreatedDay = Convert.ToDateTime(a.CreatedAt).ToString("yyyy-MM-dd");
|
||||
}
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = electricitySoldRecordTable;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
@ -129,5 +136,27 @@ namespace SolarPower.Controllers
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<ApiResult<ElectricitySoldRecord>> GetOnePowerStation(int id)
|
||||
{
|
||||
ApiResult<ElectricitySoldRecord> apiResult = new ApiResult<ElectricitySoldRecord>();
|
||||
ElectricitySoldRecord record = new ElectricitySoldRecord();
|
||||
try
|
||||
{
|
||||
record = await electricitySoldRecordRepository.GetOneAsync(id);
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = record;
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id);
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
using SolarPower.Helper;
|
||||
using Dapper;
|
||||
using SolarPower.Helper;
|
||||
using SolarPower.Models;
|
||||
using SolarPower.Repository.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -16,26 +18,61 @@ namespace SolarPower.Repository.Implement
|
||||
}
|
||||
public async Task<List<ElectricitySoldRecordTable>> RecordTable (ElectricitySoldRecordTablePost post)
|
||||
{
|
||||
List<ElectricitySoldRecordTable> a = new List<ElectricitySoldRecordTable>();
|
||||
|
||||
string sql = "";
|
||||
switch (post.SearchType)
|
||||
List<int> ids = new List<int>();
|
||||
foreach(var id in post.StationId)
|
||||
{
|
||||
//case 0:
|
||||
// post.Time.Replace("-","~").Replace("")
|
||||
// sql = "";
|
||||
// break;
|
||||
//case 1:
|
||||
// sql = "";
|
||||
// break;
|
||||
//case 2:
|
||||
// sql = "";
|
||||
// break;
|
||||
//case 3:
|
||||
// sql = "";
|
||||
// break;
|
||||
ids.Add(Convert.ToInt32(id.Value));
|
||||
}
|
||||
|
||||
|
||||
switch (post.SearchType)
|
||||
{
|
||||
case 0:
|
||||
post.Time = post.Time.Replace(" ", "");
|
||||
post.Time = post.Time.Replace("-", "~");
|
||||
post.Time = post.Time.Replace("/", "-");
|
||||
var time = post.Time.Split("~");
|
||||
sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es
|
||||
LEFT JOIN power_station ps ON es.PowerstationId = ps.Id
|
||||
WHERE es.StartAt BETWEEN '{time[0]}' AND '{time[1]}' AND es.PowerstationId IN @ids";
|
||||
break;
|
||||
case 1:
|
||||
post.Time = post.Time.Replace(" ", "");
|
||||
post.Time = post.Time.Replace("-", "~");
|
||||
post.Time = post.Time.Replace("/", "-");
|
||||
var time1 = post.Time.Split("~");
|
||||
sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es
|
||||
LEFT JOIN power_station ps ON es.PowerstationId = ps.Id
|
||||
WHERE es.StartAt BETWEEN '{time1[0]}' AND '{time1[1]}' AND es.PowerstationId IN @ids";
|
||||
sql = "";
|
||||
break;
|
||||
case 2:
|
||||
sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es
|
||||
LEFT JOIN power_station ps ON es.PowerstationId = ps.Id
|
||||
WHERE DATE_FORMAT(es.StartAt , '%Y-%m') = '{post.Time}' AND es.PowerstationId IN @ids";
|
||||
break;
|
||||
case 3:
|
||||
sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es
|
||||
LEFT JOIN power_station ps ON es.PowerstationId = ps.Id
|
||||
WHERE DATE_FORMAT(es.StartAt , '%Y') = '{post.Time}' AND es.PowerstationId IN @ids";
|
||||
break;
|
||||
}
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
List<ElectricitySoldRecordTable> a = new List<ElectricitySoldRecordTable>();
|
||||
try
|
||||
{
|
||||
a = (await conn.QueryAsync<ElectricitySoldRecordTable>(sql,new { ids = ids})).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,9 +243,10 @@
|
||||
<script>
|
||||
var searchType = 0;//搜尋條件(日,日區間,月,年)
|
||||
var datepicker;
|
||||
var timerange;//選取時間
|
||||
var timerange = "";//選取時間
|
||||
var selecterd_powerstationId = [];
|
||||
var selected_id;
|
||||
var RecordTable;
|
||||
//#region Date-Picker
|
||||
datepicker = $('#DateGettext').daterangepicker({
|
||||
autoUpdateInput: false,
|
||||
@ -287,6 +288,7 @@
|
||||
$('#DateGettext').val(dateLimit_format + ' - ' + today_format);
|
||||
$("#PowerStationId_modal").append($("<option />").val(0).text("請先選擇電站"));
|
||||
$("#PowerStationId_modal").attr("disabled", true);
|
||||
DataTable();
|
||||
})
|
||||
|
||||
//#region 左邊的搜索欄位
|
||||
@ -562,6 +564,7 @@
|
||||
},
|
||||
'createdRow': function (row, data, dataIndex) {
|
||||
$(row).attr('data-id', data.id);
|
||||
$(row).attr('powerstation-Name', data.powerStationName);
|
||||
},
|
||||
"ajax": {
|
||||
"url": "/ElectricitySoldRecord/RecordTable",
|
||||
@ -590,13 +593,47 @@
|
||||
}
|
||||
|
||||
function Searchform() {
|
||||
console.log(selecterd_powerstationId);
|
||||
if (searchType == 0 || searchType == 1) {
|
||||
timerange = $('#DateGettext').val();
|
||||
}
|
||||
else {
|
||||
timerange = $('#DateGet').val();
|
||||
}
|
||||
DataTable();
|
||||
RecordTable.ajax.reload();
|
||||
}
|
||||
|
||||
$('#RecordTable').on("click", "button.edit-btn", function () {
|
||||
$("#Operation-modal .modal-title").html("運維廠商資料 - 編輯");
|
||||
|
||||
selected_id = $(this).parents('tr').attr('data-id');
|
||||
var powerstationName = $(this).parents('tr').attr('powerstation-Name');
|
||||
//取得單一運維基本資料
|
||||
var url = "/ElectricitySoldRecord/GetOnePowerStation/";
|
||||
|
||||
var send_data = {
|
||||
Id: selected_id
|
||||
}
|
||||
|
||||
$.post(url, send_data, function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
return;
|
||||
}
|
||||
$('#PowerStationId_modal').empty();
|
||||
$("#PowerStationId_modal").attr("disabled", true);
|
||||
|
||||
$("#PowerStationId_modal").append($("<option />").val(999).text(powerstationName));
|
||||
|
||||
$("#StartTime_modal").val(rel.data.startAt);
|
||||
$("#BuyKwh_modal").val(rel.data.kwh);
|
||||
$("#EndTime_modal").val(rel.data.endAt);
|
||||
$("#Money_modal").val(rel.data.money);
|
||||
|
||||
$("#Record-modal").modal();
|
||||
}, 'json');
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user