1.增加日報表查詢檢查
2.延長 station, sensor 存取時間
This commit is contained in:
parent
5c9e6e725a
commit
a9caa7d01c
@ -135,6 +135,19 @@ namespace solarApp.Model
|
||||
public double AdivB_C { get; set; }
|
||||
public int periodDay_B { get; set; }
|
||||
public double CsubstrctionB { get; set; }
|
||||
public int hasData { get; set; }
|
||||
}
|
||||
|
||||
public class inv_reportDay
|
||||
{
|
||||
public int PowerStationId { get; set; }
|
||||
public string report_date { get; set; }
|
||||
public double inv_01 { get; set; }
|
||||
public double inv_02 { get; set; }
|
||||
public double inv_03 { get; set; }
|
||||
public double inv_04 { get; set; }
|
||||
public double inv_05 { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class ck_inv_day_detail1
|
||||
|
||||
@ -177,10 +177,10 @@ where crdDate between '" + date1 + "' and '" + date2 + "' and a.inverterid = '"
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
conn.Open();
|
||||
string sql = @$"select PowerStationId, station_code, station_name, dataRows as dataRows_A, invCT as invCT_B, periodCT AdivB_C, periodDay periodDay_B, (periodCT - periodDay) CsubstrctionB from
|
||||
conn.Open(); //select PowerStationId, station_code, station_name, dataRows as 'Inv資料量A', invCT as 'Inv建立量B', periodCT 'B/A', periodDay periodDay_B, (periodCT - periodDay) '差異量', hasData '日報表' from
|
||||
string sql = @$"select PowerStationId, station_code, station_name, dataRows as dataRows_A, invCT as invCT_B, periodCT AdivB_C, periodDay periodDay_B, (periodCT - periodDay) CsubstrctionB, hasData from
|
||||
(
|
||||
select a.PowerStationId, station_code, station_name, b.ct dataRows, a.ct invCT, ifnull(round((b.ct / a.ct), 2), 0) periodCT, (DATEDIFF('{date2}' , '{date1}') + 1) periodDay
|
||||
select a.PowerStationId, station_code, station_name, b.ct dataRows, a.ct invCT, ifnull(round((b.ct / a.ct), 2), 0) periodCT, (DATEDIFF('{date2}' , '{date1}') + 1) periodDay, c.hasData
|
||||
from
|
||||
( -- 每個電站的 inv 數量
|
||||
select b.id PowerStationId, b.`name` station_name, left(inverterid, 11) station_code, count(*) ct
|
||||
@ -194,6 +194,12 @@ where crdDate between '" + date1 + "' and '" + date2 + "' and a.inverterid = '"
|
||||
where a.crddate between '{date1}' and '{date2}'
|
||||
group by a.PowerStationId , left(crddate, 7)
|
||||
)b on a.PowerStationId = b.PowerStationId
|
||||
left join
|
||||
(
|
||||
select powerstationid, sum(case when inv_02 is not null then 1 else 0 end) hasData from report_invday
|
||||
where left(report_date, 10) between '{date1}' and '{date2}' and hour(report_date) = 11
|
||||
group by powerstationid
|
||||
)c on a.PowerStationId = c.PowerStationId
|
||||
)x ";
|
||||
List<ck_inv_day> ds = conn.Query<ck_inv_day>(sql).AsList<ck_inv_day>();
|
||||
conn.Close();
|
||||
@ -201,6 +207,20 @@ where crdDate between '" + date1 + "' and '" + date2 + "' and a.inverterid = '"
|
||||
}
|
||||
}
|
||||
|
||||
public List<inv_reportDay> get_reportDay(string powerstationID, string date1, string date2)
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
conn.Open();
|
||||
string sql = @$"select powerstationid, report_date, inv_01, inv_02, inv_03, inv_04, inv_05 from report_invday
|
||||
where PowerStationId = '{powerstationID}' and left(report_date, 10) between '{date1}' and '{date2}'
|
||||
order by report_date ";
|
||||
List<inv_reportDay> ds = conn.Query<inv_reportDay>(sql).AsList<inv_reportDay>();
|
||||
conn.Close();
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
|
||||
public List<ck_inv_day_detail1> get_ck_invDay_detail1(string powerstationID, string date1, string date2)
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
|
||||
@ -91,7 +91,15 @@ namespace solarApp.Service
|
||||
delete from sensoravg_history_hour where left(`TIMESTAMP`, 10) = @date1 and PowerStationID = @powerStationID;
|
||||
delete from sensoravg_history_day where left(`TIMESTAMP`, 10) = @date1 and PowerStationID = @powerStationID;
|
||||
delete from sensoravg_history_month where left(`TIMESTAMP`, 7) = left(@date1, 7) and PowerStationID = @powerStationID;";
|
||||
var ds = conn.Execute(sql, new { date1 = _date1 , PowerStationID = _powerStationID });
|
||||
//var ds = conn.Execute(sql, new { date1 = _date1 , PowerStationID = _powerStationID });
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
conn.Close();
|
||||
}
|
||||
result = true;
|
||||
@ -234,7 +242,15 @@ namespace solarApp.Service
|
||||
//MySqlCommand cmd = new MySqlCommand(sql, conn);
|
||||
//cmd.Parameters()
|
||||
//cmd.ExecuteNonQuery();
|
||||
conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
#endregion hour
|
||||
|
||||
#region day
|
||||
@ -254,7 +270,12 @@ namespace solarApp.Service
|
||||
and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1 and Irradiance <> 0 #需要過濾 0 的數值
|
||||
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d')
|
||||
)b on a.reportdate = b.reportdate";
|
||||
conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
#endregion day
|
||||
|
||||
#region month 如果跨月 會有2筆資料
|
||||
@ -278,7 +299,12 @@ namespace solarApp.Service
|
||||
and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = @date1 and Irradiance <> 0 #需要過濾 0 的數值
|
||||
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m')
|
||||
)b on a.reportdate = b.reportdate";
|
||||
conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1.Substring(0,7) });
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1.Substring(0,7) });
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1.Substring(0, 7));
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
#endregion month
|
||||
|
||||
#region Sensor 1~50 hour
|
||||
@ -295,7 +321,12 @@ namespace solarApp.Service
|
||||
from " + _siteDB + ".s" + _siteID01 + @"_sensorAvg
|
||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1
|
||||
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H');";
|
||||
conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
// conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
//日照計 update
|
||||
sql = string.Empty;
|
||||
@ -310,7 +341,14 @@ namespace solarApp.Service
|
||||
)b on a.powerStationID = b.powerStationID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d %H:%i') = b.reportdate
|
||||
set a." + item.colname + " = b.irrAvg;";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(sql)) conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
if (!string.IsNullOrEmpty(sql)) {
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -328,7 +366,12 @@ namespace solarApp.Service
|
||||
from solar_master.sensoravg_history_hour
|
||||
where powerStationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1
|
||||
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d');";
|
||||
conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
//日照計 update
|
||||
sql = string.Empty;
|
||||
@ -343,7 +386,15 @@ namespace solarApp.Service
|
||||
)b on a.powerStationID = b.powerStationID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = b.reportdate
|
||||
set a." + item.colname + " = b.irrAvg;";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(sql)) conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
if (!string.IsNullOrEmpty(sql))
|
||||
{
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -363,7 +414,12 @@ namespace solarApp.Service
|
||||
from solar_master.sensoravg_history_day
|
||||
where powerStationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = @date1
|
||||
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m');";
|
||||
conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1.Substring(0, 7) });
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1.Substring(0, 7) });
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1.Substring(0, 7));
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
//日照計 update
|
||||
sql = string.Empty;
|
||||
@ -378,8 +434,15 @@ namespace solarApp.Service
|
||||
)b on a.powerStationID = b.powerStationID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m') = b.reportdate
|
||||
set a." + item.colname + " = b.irrAvg;";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(sql)) conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1.Substring(0, 7)});
|
||||
|
||||
if (!string.IsNullOrEmpty(sql))
|
||||
{
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1.Substring(0, 7)});
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1.Substring(0, 7));
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
}
|
||||
#endregion
|
||||
|
||||
conn.Close();
|
||||
|
||||
@ -55,7 +55,16 @@ namespace solarApp.Service
|
||||
delete from power_station_history_hour where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1;
|
||||
delete from power_station_history_day where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1;
|
||||
delete from power_station_history_month where powerstationID = @powerStationID and left(`TIMESTAMP`, 7) = left(@date1, 7) ;";
|
||||
var ds = conn.Execute(sql, new { date1 = _date1, powerStationID = _powerStationID });
|
||||
//var ds = conn.Execute(sql, new { date1 = _date1, powerStationID = _powerStationID });
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
conn.Close();
|
||||
}
|
||||
result = true;
|
||||
@ -71,12 +80,20 @@ namespace solarApp.Service
|
||||
{
|
||||
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
_siteID = siteID;
|
||||
_date1 = date1;
|
||||
try
|
||||
{
|
||||
get_siteInfo();
|
||||
clearData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
insert_station();
|
||||
result = true;
|
||||
}
|
||||
@ -187,8 +204,15 @@ namespace solarApp.Service
|
||||
GROUP BY lb.PowerStationId
|
||||
) c ON a.siteID = c.siteID
|
||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and a.SITEID = @siteID ";
|
||||
int ct = conn.Execute(sql, new { date1 = _date1, siteID = _siteID });
|
||||
|
||||
//int ct = conn.Execute(sql, new { date1 = _date1, siteID = _siteID });
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.Parameters.AddWithValue("@siteID", _siteID);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
#endregion hour
|
||||
|
||||
#region day
|
||||
@ -236,7 +260,12 @@ namespace solarApp.Service
|
||||
WHERE ps.Code = @siteID
|
||||
GROUP BY lb.PowerStationId
|
||||
) c ON a.siteID = c.siteID";
|
||||
conn.Execute(sql, new { date1 = _date1, siteID = _siteID });
|
||||
// conn.Execute(sql, new { date1 = _date1, siteID = _siteID });
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.Parameters.AddWithValue("@siteID", _siteID);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
#endregion day
|
||||
|
||||
#region month
|
||||
@ -280,7 +309,13 @@ namespace solarApp.Service
|
||||
WHERE ps.Code = @siteID
|
||||
GROUP BY lb.PowerStationId
|
||||
) c ON a.siteID = c.siteID";
|
||||
conn.Execute(sql, new { date1 = _date1.Substring(0, 7), siteID = _siteID, powerStationID = _powerStationID });
|
||||
//conn.Execute(sql, new { date1 = _date1.Substring(0, 7), siteID = _siteID, powerStationID = _powerStationID });
|
||||
cmd.Parameters.AddWithValue("@date1", _date1.Substring(0, 7));
|
||||
cmd.Parameters.AddWithValue("@siteID", _siteID);
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
#endregion month
|
||||
|
||||
|
||||
@ -249,13 +249,21 @@ namespace solarApp
|
||||
var ds = invSvc.get_ck_invDay_list(date1, date2);
|
||||
gv_rpt_invDay.DataSource = ds;
|
||||
gv_rpt_invDay.Columns[0].Width = 60;
|
||||
gv_rpt_invDay.Columns[1].Width = 70;
|
||||
gv_rpt_invDay.Columns[2].Width = 80;
|
||||
gv_rpt_invDay.Columns[1].Width = 80;
|
||||
gv_rpt_invDay.Columns[2].Width = 100;
|
||||
gv_rpt_invDay.Columns[3].Width = 90;
|
||||
gv_rpt_invDay.Columns[3].HeaderText = "資料量";
|
||||
gv_rpt_invDay.Columns[4].Width = 90;
|
||||
gv_rpt_invDay.Columns[5].Width = 90;
|
||||
gv_rpt_invDay.Columns[6].Width = 90;
|
||||
gv_rpt_invDay.Columns[7].Width = 90;
|
||||
gv_rpt_invDay.Columns[4].HeaderText = "Inv建立";
|
||||
//gv_rpt_invDay.Columns[5].Width = 90;
|
||||
//gv_rpt_invDay.Columns[5].HeaderText = "日期間";
|
||||
gv_rpt_invDay.Columns[5].Visible = false;
|
||||
gv_rpt_invDay.Columns[6].Width = 80;
|
||||
gv_rpt_invDay.Columns[6].HeaderText = "日區間";
|
||||
gv_rpt_invDay.Columns[7].Width = 80;
|
||||
gv_rpt_invDay.Columns[7].HeaderText = "差異量";
|
||||
gv_rpt_invDay.Columns[8].Width = 80;
|
||||
gv_rpt_invDay.Columns[8].HeaderText = "日報";
|
||||
|
||||
}
|
||||
|
||||
@ -271,20 +279,34 @@ namespace solarApp
|
||||
}
|
||||
|
||||
private void gv_rpt_invDay_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
|
||||
{
|
||||
if (e.RowIndex > 0)
|
||||
{
|
||||
string powerStationID = gv_rpt_invDay.Rows[e.RowIndex].Cells[0].Value.ToString();
|
||||
// MessageBox.Show(powerStationID);
|
||||
|
||||
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
||||
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
||||
get_inv_svc invSvc = new get_inv_svc();
|
||||
var ds = invSvc.get_ck_invDay_detail1( powerStationID, date1, date2);
|
||||
if (e.ColumnIndex != 8)
|
||||
{
|
||||
var ds = invSvc.get_ck_invDay_detail1(powerStationID, date1, date2);
|
||||
gv_inv_detail.DataSource = ds;
|
||||
gv_inv_detail.Columns[0].Width = 60;
|
||||
gv_inv_detail.Columns[1].Width = 160; //invID
|
||||
gv_inv_detail.Columns[2].Width = 80;
|
||||
gv_inv_detail.Columns[3].Width = 90;
|
||||
|
||||
} else
|
||||
{ // 日報
|
||||
var ds = invSvc.get_reportDay(powerStationID, date1, date2);
|
||||
gv_inv_detail.DataSource = ds;
|
||||
gv_inv_detail.Columns[0].Width = 60;
|
||||
gv_inv_detail.Columns[1].Width = 80; //report_date
|
||||
gv_inv_detail.Columns[2].Width = 70;
|
||||
gv_inv_detail.Columns[3].Width = 70;
|
||||
gv_inv_detail.Columns[4].Width = 70;
|
||||
gv_inv_detail.Columns[5].Width = 70;
|
||||
gv_inv_detail.Columns[6].Width = 70;
|
||||
}
|
||||
}
|
||||
//switch (e.ColumnIndex)
|
||||
//{
|
||||
// case 0:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user