下載EXCEL

This commit is contained in:
b110212000 2021-08-02 13:54:05 +08:00
parent cf48a1da16
commit ace768d6ad
4 changed files with 676 additions and 3 deletions

View File

@ -79,6 +79,17 @@ namespace SolarPower.Controllers
{ {
ApiResult<InvAndMoney> apiResult = new ApiResult<InvAndMoney>(); ApiResult<InvAndMoney> apiResult = new ApiResult<InvAndMoney>();
InvAndMoney inverter = new InvAndMoney(); InvAndMoney inverter = new InvAndMoney();
bool Showmoney;
if(post.Userid == 0)
{
Showmoney = myUser.Role.Auths.Contains("ShowMoney");
}
else
{
Showmoney = await powerStationRepository.CheckShowMoney(post.Userid);
}
try try
{ {
var powerStation = await powerStationRepository.GetOneAsync(post.PowerStation); var powerStation = await powerStationRepository.GetOneAsync(post.PowerStation);
@ -93,7 +104,7 @@ namespace SolarPower.Controllers
{ {
inverter.Inv[i] = "inv_" + inverter.Inv[i].Substring(inverter.Inv[i].Length - 4, 4); inverter.Inv[i] = "inv_" + inverter.Inv[i].Substring(inverter.Inv[i].Length - 4, 4);
} }
if (myUser.Role.Auths.Contains("ShowMoney")) if (Showmoney)
{ {
inverter.ShowMoney = 1; inverter.ShowMoney = 1;
}else }else
@ -183,7 +194,8 @@ namespace SolarPower.Controllers
FormType = postObject.FormType, FormType = postObject.FormType,
SearchType = postObject.SearchType, SearchType = postObject.SearchType,
Time = postObject.Time, Time = postObject.Time,
PowerStation = Convert.ToInt32(powerstationid.Value) PowerStation = Convert.ToInt32(powerstationid.Value),
Userid = postObject.Userid
}; };
var Formbody = GetForm(select_Table);//取body var Formbody = GetForm(select_Table);//取body
var Formhead = GetTableHead(select_Table);//取head var Formhead = GetTableHead(select_Table);//取head
@ -666,5 +678,514 @@ namespace SolarPower.Controllers
return apiResult; return apiResult;
} }
public string ExportExcelBackDownload(string post)
{
var postObject = JsonConvert.DeserializeObject<Excel>(post);
var workbook = new XSSFWorkbook();
#region excel設定
IFont font12 = workbook.CreateFont();
font12.FontName = "新細明體";
font12.FontHeightInPoints = 12;
ICellStyle style12 = workbook.CreateCellStyle();
style12.SetFont(font12);
style12.Alignment = HorizontalAlignment.Center;
style12.VerticalAlignment = VerticalAlignment.Center;
IFont font12Times = workbook.CreateFont();
font12Times.FontName = "Times New Roman";
font12Times.FontHeightInPoints = 12;
IFont font18 = workbook.CreateFont();
font18.FontName = "新細明體";
font18.FontHeightInPoints = 18;
font18.IsBold = true;
ICellStyle styleTitle18 = workbook.CreateCellStyle();
styleTitle18.SetFont(font18);
styleTitle18.Alignment = HorizontalAlignment.Center;
styleTitle18.VerticalAlignment = VerticalAlignment.Center;
ICellStyle styleLeft12 = workbook.CreateCellStyle();
styleLeft12.SetFont(font12);
styleLeft12.Alignment = HorizontalAlignment.Left;
styleLeft12.VerticalAlignment = VerticalAlignment.Center;
ICellStyle styleLine12 = workbook.CreateCellStyle();
styleLine12.SetFont(font12);
styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
styleLine12.VerticalAlignment = VerticalAlignment.Center;
styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
ICellStyle stylein12 = workbook.CreateCellStyle();
stylein12.SetFont(font12Times);
stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
stylein12.VerticalAlignment = VerticalAlignment.Center;
stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.WrapText = true;
#endregion
foreach (var powerstationid in postObject.PowerStation)
{
var sheet = workbook.CreateSheet(powerstationid.Name);
Select_table select_Table = new Select_table
{
FormType = postObject.FormType,
SearchType = postObject.SearchType,
Time = postObject.Time,
PowerStation = Convert.ToInt32(powerstationid.Value),
Userid = postObject.Userid
};
var Formbody = GetForm(select_Table);//取body
var Formhead = GetTableHead(select_Table);//取head
int RowPosition = 0;
switch (postObject.FormType)
{
case 0: //日報表
#region head //RowPosition = 0
IRow row = sheet.CreateRow(RowPosition);
ICell cell = row.CreateCell(0);
int index = 0;
cell.SetCellValue("Date");
cell.CellStyle = styleLine12;
sheet.SetColumnWidth(index, 4 * 160 * 8);
index++;
foreach (var head in Formhead.Result.Data.Inv)
{
cell = row.CreateCell(index);
cell.SetCellValue(head);
cell.CellStyle = styleLine12;
sheet.SetColumnWidth(index, 4 * 160 * 6);
index++;
}
List<string> lasthead = new List<string>()
{
"小時發電量(kWh)",
"小時發電量百分比(%)",
"小時平均日照度(W/㎡)",
"小時平均模組溫度(°C)"
};
if (Formhead.Result.Data.ShowMoney == 1)
{
lasthead.Add("小時售電金額(NTD)");
}
foreach (var head in lasthead)
{
cell = row.CreateCell(index);
cell.SetCellValue(head);
cell.CellStyle = styleLine12;
sheet.SetColumnWidth(index, 4 * 160 * 12);
index++;
}
#endregion
#region body //RowPosition = 1
RowPosition++;
var thour = ""; var tpr = ""; var tkwh = ""; var kWhkwp = ""; var ntd = ""; var ntdone = "";
foreach (dynamic body in Formbody.Result.Data)
{
index = 0;
var dbody = body as IDictionary<string, object>;
thour = Checknull(Math.Round(Convert.ToDouble(dbody["tothour"]), 2).ToString());
tpr = Checknull(Math.Round(Convert.ToDouble(dbody["pr"]), 2).ToString());
tkwh = Checknull(Math.Round(Convert.ToDouble(dbody["totKWH"]), 2).ToString());
kWhkwp = Checknull(Math.Round(Convert.ToDouble(dbody["totKWHKWP"]), 2).ToString());
ntd = Checknull(Math.Round(Convert.ToDouble(dbody["totmoney"]), 2).ToString());
double onemoney = Convert.ToDouble(ntd) / Convert.ToDouble(tkwh);
if (double.IsNaN(onemoney))
{
onemoney = 0;
}
ntdone = Checknull(Math.Round(onemoney, 2).ToString());
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
var b = dbody["report_date"].ToString();
cell.SetCellValue(b);
cell.CellStyle = styleLine12;
index++;
foreach (var head in Formhead.Result.Data.Inv)
{
cell = row.CreateCell(index);
cell.SetCellValue(dbody[head] == null ? "0" : dbody[head].ToString());
cell.CellStyle = styleLine12;
index++;
}
List<string> bodynames = new List<string>(){
"hourKWH",
"hourKWHp",
"irradiance",
"temperature"
};
if (Formhead.Result.Data.ShowMoney == 1)
{
bodynames.Add("hourmoney");
}
foreach (var bodyname in bodynames)
{
cell = row.CreateCell(index);
if (dbody[bodyname] == null)
{
cell.SetCellValue("0");
}
else
{
var c = dbody[bodyname].ToString();
cell.SetCellValue(c);
}
cell.CellStyle = styleLine12;
index++;
}
RowPosition++;
}
#endregion
#region //RowPosition = body + 2
RowPosition += 2;//空兩行
index = 0;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("日照小時:");
cell.CellStyle = styleLine12;
cell = row.CreateCell(1);
cell.SetCellValue(thour);
cell.CellStyle = styleLine12;
RowPosition++;
index = 0;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("kWH/kWP:");
cell.CellStyle = styleLine12;
cell = row.CreateCell(1);
cell.SetCellValue(kWhkwp);
cell.CellStyle = styleLine12;
RowPosition++;
index = 0;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("PR%:");
cell.CellStyle = styleLine12;
cell = row.CreateCell(1);
cell.SetCellValue(tpr);
cell.CellStyle = styleLine12;
RowPosition++;
index = 0;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("日發電量(kWh):");
cell.CellStyle = styleLine12;
cell = row.CreateCell(1);
cell.SetCellValue(tkwh);
cell.CellStyle = styleLine12;
RowPosition++;
if (Formhead.Result.Data.ShowMoney == 1)
{
index = 0;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("日售電金額(NTD):");
cell.CellStyle = styleLine12;
cell = row.CreateCell(1);
cell.SetCellValue(ntd);
cell.CellStyle = styleLine12;
RowPosition++;
index = 0;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("日售電單價(NTD):");
cell.CellStyle = styleLine12;
cell = row.CreateCell(1);
cell.SetCellValue(ntdone);
cell.CellStyle = styleLine12;
}
#endregion
break;
case 1: // 月報表
#region head //RowPosition = 0
IRow row2 = sheet.CreateRow(RowPosition);
ICell cell2 = row2.CreateCell(0);
int index2 = 0;
cell2.SetCellValue("Date");
cell2.CellStyle = styleLine12;
sheet.SetColumnWidth(index2, 4 * 160 * 8);
index2++;
foreach (var head in Formhead.Result.Data.Inv)
{
cell2 = row2.CreateCell(index2);
cell2.SetCellValue(head);
cell2.CellStyle = styleLine12;
sheet.SetColumnWidth(index2, 4 * 160 * 8);
index2++;
}
List<string> lasthead2 = new List<string>()
{
"日發電量(kWh)",
"日發電量百分比(%)",
"日照小時(hr)",
"kWH/kWP",
"PR%",
"日平均日照度(W/㎡)",
"日平均模組溫度(°C)"
};
if (Formhead.Result.Data.ShowMoney == 1)
{
lasthead2.Add("日售電金額(NTD)");
}
foreach (var head in lasthead2)
{
cell2 = row2.CreateCell(index2);
cell2.SetCellValue(head);
cell2.CellStyle = styleLine12;
sheet.SetColumnWidth(index2, 4 * 160 * 12);
index2++;
}
#endregion
#region body //RowPosition = 1
RowPosition++;
var avghour = "0"; var avgKWHKWP = "0"; var avgdayKWH = "0"; var monthKWH = "0"; var monthmoney = "0"; var monthmoneyone = "0";
var check_hire = false;
var sitedb = "";
foreach (dynamic body in Formbody.Result.Data)
{
index2 = 0;
var dbody = body as IDictionary<string, object>;
avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString();
avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString();
avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString();
monthKWH = dbody["monthKWH"] == null ? "0" : dbody["monthKWH"].ToString();
monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString();
monthmoneyone = (Convert.ToDouble(dbody["monthmoneyone"].ToString()) + Convert.ToDouble(monthmoneyone)).ToString();
if (dbody["SolarType"].ToString() == "1" && Formhead.Result.Data.ShowMoney == 1)//檢驗是否為租用
{
check_hire = true;
sitedb = dbody["SiteDB"].ToString();
}
row2 = sheet.CreateRow(RowPosition);
cell2 = row2.CreateCell(index2);
var b = dbody["report_date"].ToString();
cell2.SetCellValue(b);
cell2.CellStyle = styleLine12;
index2++;
foreach (var head in Formhead.Result.Data.Inv)
{
cell2 = row2.CreateCell(index2);
cell2.SetCellValue(dbody[head] == null ? "0" : dbody[head].ToString());
cell2.CellStyle = styleLine12;
index2++;
}
List<string> bodynames = new List<string>(){
"dayKWH",
"dayKWHp",
"tothour",
"KWHKWP",
"PR",
"irradiance",
"temperature"
};
if (Formhead.Result.Data.ShowMoney == 1)
{
bodynames.Add("soldmoney");
}
foreach (var bodyname in bodynames)
{
cell2 = row2.CreateCell(index2);
if (dbody[bodyname] == null)
{
cell2.SetCellValue("0");
}
else
{
var c = dbody[bodyname].ToString();
cell2.SetCellValue(c);
}
cell2.CellStyle = styleLine12;
index2++;
}
RowPosition++;
}
#endregion
#region //RowPosition = body + 2
RowPosition += 2;//空兩行
index = 0;
var Useday = Formbody.Result.Data.Count;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("日日照小時平均");
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("日kWH/kWP平均");
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("日發電量平均(kWh)");
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("月發電量(kWh)");
cell.CellStyle = styleLine12;
index++;
if (Formhead.Result.Data.ShowMoney == 1)
{
cell = row.CreateCell(index);
cell.SetCellValue("月售電金額(NTD)");
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("月售電單價(NTD)");
cell.CellStyle = styleLine12;
index++;
}
cell = row.CreateCell(index);
cell.SetCellValue("月售電天數");
cell.CellStyle = styleLine12;
index = 0;
RowPosition++;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(avghour) / Useday, 2));
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(avgKWHKWP) / Useday, 2));
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(avgdayKWH) / Useday, 2));
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(monthKWH);
cell.CellStyle = styleLine12;
index++;
if (Formhead.Result.Data.ShowMoney == 1)
{
cell = row.CreateCell(index);
cell.SetCellValue(monthmoney);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoneyone) / Useday, 2));
cell.CellStyle = styleLine12;
index++;
}
cell = row.CreateCell(index);
cell.SetCellValue(Useday);
cell.CellStyle = styleLine12;
#endregion
#region //RowPosition = 總量 + 2
if (check_hire == true)
{
RowPosition += 2;//空兩行
PsIdAndSiteDB set = new PsIdAndSiteDB()
{
PowerstationId = Convert.ToInt32(powerstationid.Value),
SiteDB = sitedb
};
var info = GetHireInfo(set);
index = 0;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue("出租人");
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("租金比例");
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("租金金額(未稅)");
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue("租金金額(含稅)");
cell.CellStyle = styleLine12;
foreach (var a in info.Result.Data)
{
RowPosition++;
index = 0;
row = sheet.CreateRow(RowPosition);
cell = row.CreateCell(index);
cell.SetCellValue(a.Landowner);
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(a.LeaseRate + "%");
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) * Convert.ToDouble(a.LeaseRate) / 100, 2).ToString());
cell.CellStyle = styleLine12;
index++;
cell = row.CreateCell(index);
cell.SetCellValue(Math.Round(Convert.ToDouble(monthmoney) * Convert.ToDouble(a.LeaseRate) / 100 * 1.05, 2).ToString());
cell.CellStyle = styleLine12;
index++;
}
}
#endregion
break;
}
}
var name = "";
if (postObject.FormType == 0)
{
name = "日";
}
else
{
name = "月";
}
var Datename = postObject.Time.Replace("-", "");
if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "report")))
{
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "report"));
}
if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "report", Datename)))
{
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "report", Datename));
}
var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "report", Datename, Datename + "_" + postObject.Userid + "_" + name + "報表.xlsx");
FileStream FS = new FileStream(n, FileMode.Create, FileAccess.Write);
workbook.Write(FS);
FS.Close();
return Path.Combine("report", Datename, Datename + "_" + postObject.Userid + "_" + name + "報表.xlsx");
}
} }
} }

View File

@ -30,6 +30,7 @@ namespace SolarPower.Models
public string Time { get; set; } public string Time { get; set; }
public int PowerStation { get; set; } public int PowerStation { get; set; }
public int FormType { get; set; } public int FormType { get; set; }
public int Userid { get; set; }
} }
public class Excel public class Excel
{ {
@ -37,6 +38,7 @@ namespace SolarPower.Models
public string Time { get; set; } public string Time { get; set; }
public int FormType { get; set; } public int FormType { get; set; }
public List<Excelpowerstation> PowerStation { get; set; } public List<Excelpowerstation> PowerStation { get; set; }
public int Userid { get; set; }
} }
public class Excelpowerstation public class Excelpowerstation
{ {

View File

@ -2340,6 +2340,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -2429,6 +2433,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -2458,6 +2466,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -2518,6 +2530,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -2649,6 +2665,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -2775,6 +2795,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -2799,6 +2823,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -2823,6 +2851,7 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally { conn.Close(); }
return result; return result;
} }
} }
@ -2895,6 +2924,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -2944,6 +2977,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3015,6 +3052,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3034,6 +3075,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3165,6 +3210,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3246,6 +3295,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3274,6 +3327,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3322,6 +3379,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3341,6 +3402,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3381,6 +3446,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3454,6 +3523,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3503,6 +3576,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3544,6 +3621,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3644,6 +3725,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3688,6 +3773,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3732,6 +3821,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3810,6 +3903,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3854,6 +3951,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -3897,6 +3998,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -4049,6 +4154,10 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result; return result;
} }
} }
@ -4125,8 +4234,48 @@ namespace SolarPower.Repository.Implement
{ {
throw exception; throw exception;
} }
finally
{
conn.Close();
}
return result;
}
}
public async Task<bool> CheckShowMoney(int userid)
{
bool result = true;
string J;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = @$"SELECT ap.AuthCode FROM user u
LEFT JOIN role_auth ra ON ra.Id = u.RoleId
LEFT JOIN auth_page ap ON ap.AuthCode = ra.AuthCode
WHERE u.Id = {userid} AND ap.AuthCode = 'J' ";
J = await conn.QueryFirstOrDefaultAsync<string>(sql);
if(J == null)
{
result = false;
}
else
{
result = true;
}
}
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
}
return result; return result;
} }
} }
} }
}

View File

@ -557,5 +557,6 @@ namespace SolarPower.Repository.Interface
Task<List<Device>> GetDeviceByPowerStationIdAndDeviceIds(string db_name, int powerStationId, List<string> deviceIds); Task<List<Device>> GetDeviceByPowerStationIdAndDeviceIds(string db_name, int powerStationId, List<string> deviceIds);
Task<dynamic> GetSensorAvgByDevices(string date, byte searchType, List<Device> devices); Task<dynamic> GetSensorAvgByDevices(string date, byte searchType, List<Device> devices);
Task<List<PowerStationHistory>> GetPowerStationHistory(string date, byte searchType, List<int> entities); Task<List<PowerStationHistory>> GetPowerStationHistory(string date, byte searchType, List<int> entities);
Task<bool> CheckShowMoney(int userid);
} }
} }