檢核查詢OK

This commit is contained in:
JiaHao Liu 2021-08-06 11:04:32 +08:00
parent b61174614a
commit d86ea03916
6 changed files with 654 additions and 305 deletions

View File

@ -32,7 +32,7 @@ namespace solarApp.Model
public class web_station_hour
{
// public string siteid { get; set; }
public string siteid { get; set; }
public string reportdate { get; set; }
public double KWH { get; set; }
public double TODAYKWH { get; set; }
@ -48,7 +48,7 @@ namespace solarApp.Model
public class web_station_day
{
// public string siteid { get; set; }
public string siteid { get; set; }
public string reportdate { get; set; }
public double TODAYKWH { get; set; }
public double TOTALKWH { get; set; }
@ -56,4 +56,13 @@ namespace solarApp.Model
public double SOLARHOUR { get; set; }
public double kwhkwp { get; set; }
}
public class station_list
{
public string id { get; set; }
public string CompanyID { get; set; }
public string SiteID { get; set; }
public string SiteDB { get; set; }
public string SiteName { get; set; }
}
}

View File

@ -18,14 +18,15 @@ namespace solarApp.Service
/// <param name="reportDate"></param>
/// <param name="invID"></param>
/// <returns></returns>
public List<raw_inv> Get_rawInv(string reportDate, string invID)
public List<raw_inv> Get_rawInv(string reportDate, string invID, string siteDB, string siteID)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
//string sql = @"select ID, TIMESTAMP, SITEID, SITETYPE, CONTROLLERID, INVERTERID, SN, AC1V, AC1A, AC1W, AC1F, AC1WH, AC2V, AC2A, AC2W, AC2F, AC2WH, AC3V, AC3A, AC3W, AC3F, AC3WH, ACRUNTIME, DC1V, DC1A, DC1W, DC1WH, DC2V, DC2A, DC2W, DC2WH, DC3V, DC3A, DC3W, DC3WH, DC4V, DC4A, DC4W, DC4WH, DC5V, DC5A, DC5W, DC5WH, DCRUNTIME, WH, TODAYKWH, TOTALKWH, PR, RA1, RA2, RA3, RA4, RA5
// from solar_com0002.s02202000101_inv order by id desc limit 100; ";
string sql = @"select id , reportdate, inverterid, WH, TODAYKWH, TOTALKWH, PR, RA1 from v_inv_temp where left(reportdate, 10) = '" + reportDate + "' and inverterid = '" + invID + "'";
string sql = @"select id , FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, inverterid, WH,round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH,round(PR, 2) PR, RA1
from " + siteDB + ".s" + siteID + @"_inv where left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 10) = '" + reportDate + "' and inverterid = '" + invID + "'";
//List<raw_inv> ds = conn.Query<raw_inv>(sql, new { kind = kind }).ToList();
List<raw_inv> ds = conn.Query<raw_inv>(sql).AsList<raw_inv>();
@ -39,7 +40,7 @@ namespace solarApp.Service
/// <param name="reportDate"></param>
/// <param name="invID"></param>
/// <returns></returns>
public List<raw_inv_hour> get_Inv_rawAvg(string reportDate, string invID)
public List<raw_inv_hour> get_Inv_rawAvg(string reportDate, string invID, string siteDB, string siteID)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
@ -50,16 +51,15 @@ namespace solarApp.Service
// "group by left(reportdate, 13), inverterid"; //round(avg(PR), 2) PR,
string sql = @" select a.reportdate, a.inverterid, a.KWH, b.TODAYKWH, b.TOTALKWH, b.PR, a.count from
(
select left(reportdate, 13)reportdate, inverterid
select left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 13)reportdate, inverterid
,round((sum(WH)/1000), 2) KWH, count(*) count
from v_inv_temp
where left(reportdate, 10) = '" + reportDate + "' and inverterid = '" + invID + @"'
group by left(reportdate, 13), inverterid
from " + siteDB + ".s" + siteID + @"_inv
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = '" + reportDate + "' and inverterid = '" + invID + @"'
group by left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'), 13), inverterid
)a join (
select reportdate, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, inverterid, round(PR, 2) PR
from v_inv_temp
where left(reportdate, 10) = '" + reportDate + @"' and right(reportdate, 2) = '55' and inverterid = '" + invID + @"'
select FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, round(TODAYKWH, 2) TODAYKWH, round(TOTALKWH, 2) TOTALKWH, inverterid, round(PR, 2) PR
from " + siteDB + ".s" + siteID + @"_inv
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = '" + reportDate + @"' and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'), 2) = '55' and inverterid = '" + invID + @"'
)b on a.reportdate = left(b.reportdate, 13) and a.inverterid = b.inverterid ";
List<raw_inv_hour> ds = conn.Query<raw_inv_hour>(sql).AsList<raw_inv_hour>();
conn.Close();
@ -86,19 +86,45 @@ namespace solarApp.Service
}
}
public List<web_inv_hour> get_web_Inv_day(string reportDate, string invID)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @"select `TIMESTAMP` reportdate, inverterid, KWH, TODAYKWH, TOTALKWH, round(PR, 2) PR
from inverter_history_day where left(`TIMESTAMP`, 10) = '" + reportDate + "' and inverterid = '" + invID + "' ";
List<web_inv_hour> ds = conn.Query<web_inv_hour>(sql).AsList<web_inv_hour>();
conn.Close();
return ds;
}
}
public List<web_inv_hour> get_web_Inv_month(string reportDate, string invID)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @"select `TIMESTAMP` reportdate, inverterid, KWH, TODAYKWH, TOTALKWH, round(PR, 2) PR
from inverter_history_month where left(`TIMESTAMP`, 7) = '" + reportDate + "' and inverterid = '" + invID + "' ";
List<web_inv_hour> ds = conn.Query<web_inv_hour>(sql).AsList<web_inv_hour>();
conn.Close();
return ds;
}
}
/// <summary>
///
/// </summary>
/// <param name="reportDate"></param>
/// <param name="invID"></param>
/// <returns></returns>
public List<web_inv_list> get_Inv_list()
public List<web_inv_list> get_Inv_list(string siteDB, string siteID)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @"select dbname, inverterid from v_company_inv";
List<web_inv_list> ds = conn.Query<web_inv_list>(sql).AsList<web_inv_list>();
string sql = @"select dbname, inverterid from v_company_inv where dbname = @siteDB and left(inverterid, 9) = @siteID";
List<web_inv_list> ds = conn.Query<web_inv_list>(sql, new { siteDB = siteDB, siteID = siteID }).AsList<web_inv_list>();
conn.Close();
return ds;
}

View File

@ -14,27 +14,29 @@ namespace solarApp.Service
public class getStationSvc
{
string Connection1 = ConfigurationManager.ConnectionStrings["mySql"].ConnectionString;
public List<raw_statino> get_station_raw(string reportDate)
/// <summary>
/// 電站 Raw Data
/// </summary>
/// <param name="reportDate"></param>
/// <param name="siteDB"></param>
/// <param name="siteID"></param>
/// <returns></returns>
public List<raw_statino> get_station_raw(string reportDate, string siteDB, string siteID)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @"select id , reportdate, siteid, KWH, TODAYKWH, TOTALKWH, PR, SOLARHOUR, kwhkwp
from v_station_temp
where siteid = '022020001' and left(reportdate, 10) = @reportDate";
string sql = @"select id , FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, siteid, round(KWH, 3) KWH, round(TODAYKWH, 3) TODAYKWH,
round(TOTALKWH, 3)TOTALKWH, round(PR, 3) PR, round(TODAYKWH, 3)SOLARHOUR , round(kwhkwp, 3) kwhkwp
from " + siteDB + ".s" + siteID + @"_station
where left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'), 10) = @reportDate";
List<raw_statino> ds = conn.Query<raw_statino>(sql, new { reportDate = reportDate }).AsList<raw_statino>();
conn.Close();
return ds;
}
}
/// <summary>
/// 電站每天平均 from RawData
/// </summary>
/// <param name="date1"></param>
/// <param name="date2"></param>
/// <returns></returns>
public List<raw_station_day> get_station_rawAvg(string date1, string date2)
#region 使 view
public List<raw_station_day> create_v_station_inv(string date1, string date2)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
@ -43,13 +45,43 @@ namespace solarApp.Service
round((max(PR)), 2) PR, round((max(SOLARHOUR)), 2) SOLARHOUR, round((max(KWHKWP)), 2) KWHKWP, count(*) count
from v_station_temp
where left(reportdate, 10) between @date1 and @date2
group by siteid, left(reportdate, 10)";
group by siteid, left(reportdate, 10)";
List<raw_station_day> ds = conn.Query<raw_station_day>(sql, new { date1 = date1, date2 = date2 }).AsList<raw_station_day>();
conn.Close();
return ds;
}
}
#endregion
/// <summary>
/// 電站每天平均 from RawData
/// </summary>
/// <param name="date1"></param>
/// <param name="date2"></param>
/// <returns></returns>
public List<raw_station_day> get_station_rawAvg(string date1, string date2, string siteDB, string siteID)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
//string sql = @" select siteid, left(reportdate, 10) reportdate, round((sum(KWH)), 2) KWH, round((max(TODAYKWH)), 2) TODAYKWH, round((max(TOTALKWH)), 2) TOTALKWH,
// round((max(PR)), 2) PR, round((max(SOLARHOUR)), 2) SOLARHOUR, round((max(KWHKWP)), 2) KWHKWP, count(*) count
// from v_station_temp
// where left(reportdate, 10) between @date1 and @date2
// group by siteid, left(reportdate, 10)";
string sql = @" select siteid, left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'), 10) reportdate, round((sum(KWH)), 2) KWH, round((max(TODAYKWH)), 2) TODAYKWH, round((max(TOTALKWH)), 2) TOTALKWH,
round((max(PR)), 2) PR, round((max(SOLARHOUR)), 2) SOLARHOUR, round((max(KWHKWP)), 2) KWHKWP, count(*) count
from " + siteDB+ ".s"+ siteID + @"_station
where left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'), 10) between @date1 and @date2
group by siteid, left(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'), 10)";
List<raw_station_day> ds = conn.Query<raw_station_day>(sql, new { date1 = date1, date2 = date2 }).AsList<raw_station_day>();
conn.Close();
return ds;
}
}
/// <summary>
/// web 呈現值 station - hour
/// </summary>
@ -88,5 +120,36 @@ namespace solarApp.Service
return ds;
}
}
public List<web_station_hour> get_web_station_month(string date1, string date2)
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, siteid, round(TOTALKWH, 2) TOTALKWH, round(PR, 3) PR, round(KWHKWP, 3) KWHKWP, money
from power_station_history_month where left(`TIMESTAMP`, 7) between @date1 and @date2 ";
List<web_station_hour> ds = conn.Query<web_station_hour>(sql, new { date1 = date1, date2 = date2 }).AsList<web_station_hour>();
conn.Close();
return ds;
}
}
/// <summary>
/// 取得電站資訊
/// </summary>
/// <returns></returns>
public List<station_list> get_station_list()
{
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open(); // 01 控制器編號
string sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName
from power_station
where id in (1, 8)";
List<station_list> ds = conn.Query<station_list>(sql).AsList<station_list>();
conn.Close();
return ds;
}
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace solarApp.Service
{
//static class myHelper
//{
//}
public static class ListHelper
{
public static string ToSiteTable(this IList<String> list)
{
return string.Join(", ", list.ToArray());
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -23,13 +23,17 @@ namespace solarApp
private async void button1_Click(object sender, EventArgs e)
{
lbMsg_inv.Text = "loading ... ";
string date1 = dtselect_inv.Value.ToString("yyyy-MM-dd");
gv_fic_inv_raw.DataSource = inv_svc.Get_rawInv(date1, lbInverterID.Text, lbSiteDB_inv.Text, lbSiteID_inv.Text);
gv_fic_inv_hour.DataSource = inv_svc.get_Inv_rawAvg(date1, lbInverterID.Text, lbSiteDB_inv.Text, lbSiteID_inv.Text);
gv_web_inv_hour.DataSource = inv_svc.get_web_Inv_hour(date1, lbInverterID.Text);
gv_web_inv_day.DataSource = inv_svc.get_web_Inv_day(date1, lbInverterID.Text);
gv_web_inv_month.DataSource = inv_svc.get_web_Inv_month( date1.Substring(0, 7), lbInverterID.Text);
gv_fic_inv_raw.DataSource = inv_svc.Get_rawInv(dtselect_inv.Value.ToString("yyyy-MM-dd"), lbInverterID.Text);
gv_fic_inv_hour.DataSource = inv_svc.get_Inv_rawAvg(dtselect_inv.Value.ToString("yyyy-MM-dd"), lbInverterID.Text);
gv_web_inv_hour.DataSource = inv_svc.get_web_Inv_hour(dtselect_inv.Value.ToString("yyyy-MM-dd"), lbInverterID.Text);
lbMsg_inv.Text = " done " + System.DateTime.Now.ToShortTimeString();
}
@ -40,13 +44,58 @@ namespace solarApp
dtselect_station2.Value = DateTime.Today.AddDays(-1);
dtselect_inv.Value = DateTime.Today.AddDays(-1);
Cursor.Current = Cursors.Default;
add_inv_list();
// Cursor.Current = Cursors.Default;
tabControl1.SelectedTab = tabControl1.TabPages[1];
#region
int i = 0;
var site_list = stationSvc.get_station_list();
foreach (var item in site_list)
{
RadioButton rb = new RadioButton();
rb.Name = item.SiteID;
rb.Text = item.SiteName;
rb.Tag = item.SiteDB;
rb.Font = new Font(Font.FontFamily, 22);
rb.AutoSize = true;
rb.CheckedChanged += new EventHandler(rb_site_CheckedChanged);
fp_site.Controls.Add(rb);
if (i == 0) rb.Checked = true;
i++;
}
#endregion
#region list
//add_inv_list();
#endregion
}
void add_inv_list() {
//fp_inv
var inv_list = inv_svc.get_Inv_list();
private void rb_site_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb.Checked)
{
lbSiteDB_inv.Text = rb.Tag.ToString();
lbSiteName_inv.Text = rb.Text;
lbSiteID_inv.Text = rb.Name;
//顯示 table name on label
lbSiteRaw.Text = lbSiteName_inv.Text + " "+ lbSiteDB_inv.Text + ".s" + lbSiteID_inv.Text + "_Station";
lbInvRaw.Text = lbSiteName_inv.Text + " " + lbSiteDB_inv.Text + ".s" + lbSiteID_inv.Text + "_Inv";
add_inv_list(lbSiteDB_inv.Text, lbSiteID_inv.Text.Substring(0, 9));
}
}
/// <summary>
/// 顯示 Inventer 提供選擇
/// </summary>
/// <param name="siteDB"></param>
/// <param name="siteID"></param>
void add_inv_list(string siteDB, string siteID) {
fp_inv.Controls.Clear();
var inv_list = inv_svc.get_Inv_list(siteDB, siteID);
int i = 0;
foreach (var item in inv_list)
{
@ -62,75 +111,6 @@ namespace solarApp
}
}
void init_GridView() {
// Create an unbound DataGridView by declaring a column count.
//gv_fic_inv_raw.ColumnCount = 6;
//// Set the column header style.
//DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
////columnHeaderStyle.BackColor = Color.Beige;
////columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);
////dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
//// Set the column header names.
//gv_fic_inv_raw.Columns[0].Name = "INVERTERID";
//gv_fic_inv_raw.Columns[1].Name = "reportdate";
//gv_fic_inv_raw.Columns[2].Name = "WH";
//gv_fic_inv_raw.Columns[3].Name = "TODAYKWH";
//gv_fic_inv_raw.Columns[4].Name = "TOTALKWH";
//gv_fic_inv_raw.Columns[5].Name = "PR";
//DataGridViewColumn newCol1 = new DataGridViewColumn(); // add a column to the grid
//DataGridViewCell cell = new DataGridViewCell(); //Specify which type of cell in this column
//newCol.CellTemplate = cell;
for (int i = 0; i < 6; i++)
{
DataGridViewColumn newCol = new DataGridViewColumn(); // add a column to the grid
DataGridViewCell cell = new DataGridViewTextBoxCell(); //Specify which type of cell in this column
newCol.CellTemplate = cell;
switch (i)
{
case 0:
newCol.HeaderText = "INVERTERID";
newCol.Name = "INVERTERID";
newCol.Visible = true;
newCol.Width = 40; break;
case 1:
newCol.HeaderText = "reportdate";
newCol.Name = "reportdate";
newCol.Visible = true;
newCol.Width = 40; break;
case 2:
newCol.HeaderText = "WH";
newCol.Name = "WH";
newCol.Visible = true;
newCol.Width = 40; break;
case 3:
newCol.HeaderText = "TODAYKWH";
newCol.Name = "TODAYKWH";
newCol.Visible = true;
newCol.Width = 40; break;
case 4:
newCol.HeaderText = "TOTALKWH";
newCol.Name = "TOTALKWH";
newCol.Visible = true;
newCol.Width = 40; break;
case 5:
newCol.HeaderText = "PR";
newCol.Name = "PR";
newCol.Visible = true;
newCol.Width = 40; break;
case 6:
newCol.HeaderText = "ct";
newCol.Name = "ct";
newCol.Visible = false;
newCol.Width = 40; break;
}
gv_fic_inv_raw.Columns.Add(newCol);
}
}
private void radio_inv_click(object sender, EventArgs e)
{
@ -158,10 +138,6 @@ namespace solarApp
//}
}
private void fmMain_Shown(object sender, EventArgs e)
{
}
private void dtselect_ValueChanged(object sender, EventArgs e)
{
@ -180,30 +156,18 @@ namespace solarApp
string date1 = dtselect_station1.Value.ToString("yyyy-MM-dd");
string date2 = dtselect_station2.Value.ToString("yyyy-MM-dd");
gv_fic_station_raw.DataSource = stationSvc.get_station_raw(date1);
gv_fic_station_raw.DataSource = stationSvc.get_station_raw(date1, lbSiteDB_inv.Text, lbSiteID_inv.Text);
gv_fic_station_day.DataSource = stationSvc.get_station_rawAvg(date1, date2);
gv_fic_station_day.DataSource = stationSvc.get_station_rawAvg(date1, date2, lbSiteDB_inv.Text, lbSiteID_inv.Text);
gv_web_station_hour.DataSource = stationSvc.get_web_station_hour( date1 );
gv_web_station_day.DataSource = stationSvc.get_web_station_day(date1, date2);
gv_web_station_month.DataSource = stationSvc.get_web_station_month(date1.Substring(0, 7), date2.Substring(0, 7));
lbMsg_station.Text = " done " + System.DateTime.Now.ToShortTimeString();
}
private void dtselect_station_ValueChanged(object sender, EventArgs e)
{
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
private void label12_Click(object sender, EventArgs e)
{
}
}
}
}