1.歸檔流程 - 獨立立昌

2.報表匯出功能, Null 異常修復
This commit is contained in:
jiahao 2023-09-02 09:17:48 +08:00
parent 9475fff227
commit 02e0245c92
10 changed files with 2017 additions and 1844 deletions

View File

@ -484,9 +484,30 @@ namespace SolarPower.Controllers
if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆(總計),不須取值
{
vForDataCount++;
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();
object vv = "";
avghour = Convert.ToString( dbody["tothour"]) ?? "NaN";
avgKWHKWP = Convert.ToString(dbody["KWHKWP"]) ?? "NaN";
avgKWHKWP = Convert.ToString(dbody["dayKWH"]) ?? "NaN";
//if (dbody.TryGetValue("tothour", out vv))
// avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString();
//else
// avghour = "NaN";
//if (dbody.TryGetValue("KWHKWP", out vv))
// avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString();
//else
// avgKWHKWP = "NaN";
//if (dbody.TryGetValue("dayKWH", out vv))
// avgKWHKWP = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString();
//else
// avgKWHKWP = "NaN";
//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 = dbody["monthmoneyone"] == null ? "0" : dbody["monthmoneyone"].ToString();

View File

@ -331,7 +331,7 @@ namespace solarApp.Service
{
//System.Diagnostics.Debug.WriteLine("【ArchiveRowData】[搬移資料失敗】");
TimeSpan duration = DateTime.Now - dt_start1;
arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID}_station", $"{_siteDB}_history.s{_siteID}_station", "1", ex.Message, "0", conn, null);
arclog.insert_log(_powerStationID, @$"move raw s1-{move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID}_station", $"{_siteDB}_history.s{_siteID}_station", "1", ex.Message, "0", conn, null);
throw ex;
}
@ -366,7 +366,7 @@ namespace solarApp.Service
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_inv的七月前資料寫入至{_siteDB}_history.s{_siteID}_inv【寫入成功】於{dateTime}");
// log
TimeSpan duration = DateTime.Now - dt_start1;
arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_inv", $"{_siteDB}_history.s{_siteID01}_inv", "0", "", rowCT.ToString(), conn, null);
arclog.insert_log(_powerStationID, @$"move raw s1 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_inv", $"{_siteDB}_history.s{_siteID01}_inv", "0", "", rowCT.ToString(), conn, null);
//arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd);
dt_start1 = DateTime.Now;
@ -375,12 +375,12 @@ namespace solarApp.Service
rowCT = conn.Execute(for_delete_inv, commandTimeout: 6000);
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_sensoravg搬移至{_siteDB}_history.s{_siteID}_sensoravg【搬移資料成功】於{dateTime} 共 {delete_inv.ToString()} 筆");
duration = DateTime.Now - dt_start1;
arclog.insert_log(_powerStationID, "delete raw s2", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_inv", "", "0", "", rowCT.ToString(), conn, null);
arclog.insert_log(_powerStationID, @$"delete raw s2 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_inv", "", "0", "", rowCT.ToString(), conn, null);
}
catch (Exception ex)
{
TimeSpan duration = DateTime.Now - dt_start1;
arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_station", $"{_siteDB}_history.s{_siteID01}_station", "1", ex.Message, "0", conn, null);
arclog.insert_log(_powerStationID, @$"move raw s1 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_station", $"{_siteDB}_history.s{_siteID01}_station", "1", ex.Message, "err", conn, null);
//arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd);
throw ex;
}
@ -411,20 +411,20 @@ namespace solarApp.Service
int rowCT = conn.Execute(for_insert_sensoravg, commandTimeout: 600);
// log
TimeSpan duration = DateTime.Now - dt_start1;
arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", $"{_siteDB}_history.s{_siteID01}_sensoravg", "0", "", rowCT.ToString(), conn, null);
arclog.insert_log(_powerStationID, @$"move raw s1 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", $"{_siteDB}_history.s{_siteID01}_sensoravg", "0", "", rowCT.ToString(), conn, null);
dt_start1 = DateTime.Now;
string for_delete_sensoravg = $@"DELETE FROM {_siteDB}.s{_siteID01}_sensoravg WHERE LEFT(crdTime, 7) < '{move_month}'";
rowCT = conn.Execute(for_delete_sensoravg, commandTimeout: 600);
duration = DateTime.Now - dt_start1;
arclog.insert_log(_powerStationID, "delete raw s2", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", "", "0", "", rowCT.ToString(), conn, null);
arclog.insert_log(_powerStationID, @$"delete raw s2 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", "", "0", "", rowCT.ToString(), conn, null);
}
catch (Exception ex)
{
TimeSpan duration = DateTime.Now - dt_start1;
arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", $"{_siteDB}_history.s{_siteID01}_sensoravg", "1", ex.Message, "0", conn, null);
arclog.insert_log(_powerStationID, @$"move raw s1 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", $"{_siteDB}_history.s{_siteID01}_sensoravg", "1", ex.Message, "0", conn, null);
throw;
}

View File

@ -194,13 +194,36 @@ namespace solarApp.Service
string sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName
from power_station
where deleted = 0 and `status`= 1
ORDER BY GeneratingCapacity ";
ORDER BY id ";
// id <> 14";and id > 24
List<station_list> ds = conn.Query<station_list>(sql).AsList<station_list>();
conn.Close();
return ds;
}
}
public List<station_list> get_station_list32(bool include32)
{
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 deleted = 0 and `status`= 1 and id <> 32 ";
if (include32)
{
sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName
from power_station
where deleted = 0 and `status`= 1 and id = 32";
}
// id <> 14";and id > 24
List<station_list> ds = conn.Query<station_list>(sql).AsList<station_list>();
conn.Close();
return ds;
}
}
public List<PowerStation> get_powerStation()
{
using (MySqlConnection conn = new MySqlConnection(Connection1))

View File

@ -562,7 +562,7 @@ namespace solarApp.Service
}
catch (Exception ex)
{
arclog.insert_log(_powerStationID, "sensor step1 ", 0, "sensor_history_", "insert sensor error", "0", "", "", conn, cmd);
arclog.insert_log(_powerStationID, "sensor step1 ", 0, "sensor_history_", "insert sensor error", "err", "", "", conn, cmd);
//throw ex;
}
@ -628,7 +628,7 @@ namespace solarApp.Service
}
catch (Exception ex)
{
arclog.insert_log(_powerStationID, "sensor step1 irrDayHour", 0, "sensor_history_", "sensor_history_hour error", "0", "", "", conn, cmd);
arclog.insert_log(_powerStationID, "sensor step1 irrDayHour", 0, "sensor_history_", "sensor_history_hour error", "err", "", "", conn, cmd);
//throw ex;
}
conn.Close();
@ -716,7 +716,7 @@ namespace solarApp.Service
catch (Exception ex)
{
//throw ex;
arclog.insert_log(_powerStationID, "sensor step1 meter_hour", 0, "meter_history_hour", "meter_history_hour error", "0", "", "", conn, null);
arclog.insert_log(_powerStationID, "sensor step1 meter_hour", 0, "meter_history_hour", "meter_history_hour error", "err", "", "", conn, null);
}
conn.Close();
}

File diff suppressed because it is too large Load Diff

View File

@ -338,27 +338,37 @@ namespace solarApp
private void bt_archive_Click(object sender, EventArgs e)
{
var site_list = stationSvc.get_station_list();
var site_list = stationSvc.get_station_list32(false); // 不含 32
//var site_list = stationSvc.get_station_list32(true); // 不含 32
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
procSensorSvc sensorSvc = new procSensorSvc();
procInvSvc invSvc = new procInvSvc();
procStationSvc siteSvc = new procStationSvc();
archiveRawData(site_list, date1, date2, sensorSvc, invSvc, siteSvc);
//單獨製作 32
site_list = stationSvc.get_station_list32(true); // 不含 32
archiveRawData(site_list, date1, date2, sensorSvc, invSvc, siteSvc);
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 完成!";
}
private void archiveRawData(List<station_list> site_list, string date1, string date2, procSensorSvc sensorSvc, procInvSvc invSvc, procStationSvc siteSvc)
{
foreach (var item in site_list)
{
//RadioButton rb = new RadioButton();
//rb.Name = item.SiteID;
//rb.Text = item.SiteName;
//rb.Tag = item.SiteDB;
//foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
//{
// sensorSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
// invSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
// siteSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
//}
RadioButton rb = new RadioButton();
rb.Name = item.SiteID;
rb.Text = item.SiteName;
rb.Tag = item.SiteDB;
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
{
sensorSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
invSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
siteSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
}
}
sensorSvc.isFirst = true;
foreach (var item in site_list)
@ -371,8 +381,6 @@ namespace solarApp
invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
}
}
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 完成!";
}
private void bt_clear_sensor_Click(object sender, EventArgs e)
@ -481,7 +489,8 @@ namespace solarApp
gv_inv_detail.Columns[1].Width = 160; //invID
gv_inv_detail.Columns[2].Width = 80;
gv_inv_detail.Columns[3].Width = 90;
} else
}
else
{ // 日報
var ds = invSvc.get_reportDay(powerStationID, date1, date2);
gv_inv_detail.DataSource = ds;
@ -764,7 +773,8 @@ namespace solarApp
richTextBox1.AppendText(Environment.NewLine + System.DateTime.Now.ToString() + " " + result.ToString());
}
else {
else
{
richTextBox1.AppendText(Environment.NewLine + System.DateTime.Now.ToShortTimeString() + " " + result.ToString());
}
}

View File

@ -1,4 +1,64 @@
<root>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">

File diff suppressed because it is too large Load Diff

View File

@ -125,7 +125,8 @@ namespace solarApp
/// </summary>
/// <param name="siteDB"></param>
/// <param name="siteID"></param>
void add_inv_list(string siteDB, string siteID) {
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;

View File

@ -1,4 +1,64 @@
<root>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">