This commit is contained in:
b110212000 2021-11-02 10:13:47 +08:00
commit dfd99fdf45
7 changed files with 390 additions and 125 deletions

View File

@ -2215,6 +2215,9 @@ ALTER TABLE `power_station_exception`
-- 新增太陽能電站網址
INSERT INTO `solar_power_test`.`variable` (`Name`, `Value`, `Remark`) VALUES ('WebSiteUrl', 'http://green.fic.com.tw/', '太陽能電站管理系統網址');
-- 修改[減碳量計算公式]參數值
UPDATE `solar_master`.`variable` SET `Value`='0.509' WHERE `Id`=2;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

View File

@ -177,13 +177,13 @@
</li>
}
@if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin
|| ViewBag.auths.Contains("StationOverview_UpToDate")
|| ViewBag.auths.Contains("StationOverview_Info")
|| ViewBag.auths.Contains("StationOverview_InverterInfo")
|| ViewBag.auths.Contains("StationOverview_Inverter")
|| ViewBag.auths.Contains("StationOverview_History")
|| ViewBag.auths.Contains("StationOverview_Exception")
|| ViewBag.auths.Contains("StationOverview_OperationRecord"))
|| ViewBag.auths.Contains("StationOverview_UpToDate")
|| ViewBag.auths.Contains("StationOverview_Info")
|| ViewBag.auths.Contains("StationOverview_InverterInfo")
|| ViewBag.auths.Contains("StationOverview_Inverter")
|| ViewBag.auths.Contains("StationOverview_History")
|| ViewBag.auths.Contains("StationOverview_Exception")
|| ViewBag.auths.Contains("StationOverview_OperationRecord"))
{
<li class="@(ViewData["MainNum"] == "1" && ViewData["SubNum"] == "2" ? "active" : "")">
<a asp-controller="StationOverview" asp-action="Index" title="電站總覽" data-filter-tags="utilities disabled item">
@ -196,13 +196,13 @@
}
<!-- Example of open and active states -->
@if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin
|| ViewBag.auths.Contains("StationOverview_UpToDate")
|| ViewBag.auths.Contains("StationOverview_Info")
|| ViewBag.auths.Contains("StationOverview_InverterInfo")
|| ViewBag.auths.Contains("StationOverview_Inverter")
|| ViewBag.auths.Contains("StationOverview_History")
|| ViewBag.auths.Contains("StationOverview_Exception")
|| ViewBag.auths.Contains("StationOverview_OperationRecord"))
|| ViewBag.auths.Contains("StationOverview_UpToDate")
|| ViewBag.auths.Contains("StationOverview_Info")
|| ViewBag.auths.Contains("StationOverview_InverterInfo")
|| ViewBag.auths.Contains("StationOverview_Inverter")
|| ViewBag.auths.Contains("StationOverview_History")
|| ViewBag.auths.Contains("StationOverview_Exception")
|| ViewBag.auths.Contains("StationOverview_OperationRecord"))
{
<li class="@(ViewData["MainNum"] == "2" ? "active open" : "")">
<a href="javascript:void(0);" title="電站資訊" data-filter-tags="category">
@ -244,9 +244,9 @@
</li>
}
@if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin
|| ViewBag.auths.Contains("AnalysisStationCombine")
|| ViewBag.auths.Contains("AnalysisStationInfo")
|| ViewBag.auths.Contains("AnalysisInverter"))
|| ViewBag.auths.Contains("AnalysisStationCombine")
|| ViewBag.auths.Contains("AnalysisStationInfo")
|| ViewBag.auths.Contains("AnalysisInverter"))
{
<li class="@(ViewData["MainNum"] == "3" ? "active open" : "")">
<a href="#" title="交叉分析" data-filter-tags="category">
@ -282,10 +282,10 @@
</li>
}
@if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin
|| ViewBag.auths.Contains("StationReport")
|| ViewBag.auths.Contains("ElectricitySoldRecord")
|| ViewBag.auths.Contains("PowerGeneration")
|| ViewBag.auths.Contains("NoticeSchedule"))
|| ViewBag.auths.Contains("StationReport")
|| ViewBag.auths.Contains("ElectricitySoldRecord")
|| ViewBag.auths.Contains("PowerGeneration")
|| ViewBag.auths.Contains("NoticeSchedule"))
{
<li class="@(ViewData["MainNum"] == "4" ? "active open" : "")">
<a href="#" title="報表查詢" data-filter-tags="category">
@ -348,22 +348,7 @@
</ul>
</li>
}
@if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("PowerStationManager"))
{
<li class="@(ViewData["MainNum"] == "8" ? "active open" : "")">
<a href="#" title="電站管理" data-filter-tags="category">
<i class="fal fa-cogs"></i>
<span class="nav-link-text" data-i18n="nav.category">電站管理</span>
</a>
<ul>
<li class="@(ViewData["MainNum"] == "8" && ViewData["SubNum"].ToString() == "1" ? "active" : "")">
<a asp-controller="PowerStation" asp-action="Index" title="電站管理" data-filter-tags="utilities disabled item">
<span class="nav-link-text" data-i18n="nav.utilities_disabled_item">電站管理</span>
</a>
</li>
</ul>
</li>
}
@if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("Operation") || ViewBag.auths.Contains("OperationRecord"))
{
<li class="@(ViewData["MainNum"] == "6" ? "active open" : "")">
@ -392,6 +377,22 @@
</ul>
</li>
}
@if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("PowerStationManager"))
{
<li class="@(ViewData["MainNum"] == "8" ? "active open" : "")">
<a href="#" title="電站管理" data-filter-tags="category">
<i class="fal fa-cogs"></i>
<span class="nav-link-text" data-i18n="nav.category">電站管理</span>
</a>
<ul>
<li class="@(ViewData["MainNum"] == "8" && ViewData["SubNum"].ToString() == "1" ? "active" : "")">
<a asp-controller="PowerStation" asp-action="Index" title="電站管理" data-filter-tags="utilities disabled item">
<span class="nav-link-text" data-i18n="nav.utilities_disabled_item">電站管理</span>
</a>
</li>
</ul>
</li>
}
@if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("Company") || ViewBag.auths.Contains("User") || ViewBag.auths.Contains("Role") || ViewBag.auths.Contains("User"))@*TODO修改定時任務權限*@
{

View File

@ -132,7 +132,105 @@ values( '"
values( '"
+ station_name + "' ,'"
+ fname + "' ,'"
+ inverterID + "' , now() );");
+ inverterID + "' , now() );");
if (i % 10 == 0)
{
conn.Execute(ss.ToString());
ss.Clear();
}
i++;
}
if (ss.Length > 0)
{
conn.Execute(ss.ToString());
ss.Clear();
}
conn.Clone();
}
return result;
}
public bool insert_dailyReport2DB(string[] filename, string station_name)
{
bool result = false;
StringBuilder ss = new StringBuilder();
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
int i = 0;
foreach (var fullfileName in filename)
{
string[] ff = fullfileName.Split("\\");
string fname = string.Empty;
fname += ff[ff.Length - 1]; //只抓最後的檔名
//string inverterID = string.Empty;
//string[] str = fname.Split("_");
//inverterID = str[str.Length - 3] + "_" + str[str.Length - 2];
//str = inverterID.Split(" ");
//inverterID = str[str.Length - 1];
fname = fullfileName.Replace("\\", "/");
//if (fullfileName == "D:AUO台中太平inverter110") {
// str[0] = "123";
//}
// ss.Append(@"insert into `solar_import`.`auo_file_list`( `station_name`, `filename`, inverterid, `inser_date`)
//values( '"
// + station_name + "' ,'"
// + fname + "' ,'"
// + inverterID + "' , now() );");
ss.Append(@"insert into `solar_import`.`iPVita_file_list`( `station_name`, `filename`, inverterid, `inser_date`)
values( '"
+ station_name + "' ,'"
+ fname + "' ,'' , now() );");
if (i % 10 == 0)
{
conn.Execute(ss.ToString());
ss.Clear();
}
i++;
}
if (ss.Length > 0)
{
conn.Execute(ss.ToString());
ss.Clear();
}
conn.Clone();
}
return result;
}
public bool insert_dailyReport2DB(DataTable dt, string filename)
{
bool result = false;
StringBuilder ss = new StringBuilder();
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
conn.Open();
int i = 0;
foreach (DataRow row in dt.Rows)
{
//ss.Append(@"INSERT INTO solar_import.auo_taiping(`No.`, `雲端收到時間`, `資料取得時間`, `交流電壓`, `交流電流`, `交流功率`, `溫度`, `累積發電量`, `頻率`, `狀態`, saveDate, filename, inverterID)
ss.Append(@"INSERT INTO solar_import.iPVita_temp (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, insertDate)
values( '"
+ row.Field<string>("1").ToString() + "' ,'"
+ row.Field<string>("2").ToString() + "' ,'"
+ row.Field<string>("3").ToString() + "' ,'"
+ row.Field<string>("4").ToString() + "' ,'"
+ row.Field<string>("5").ToString() + "' ,'"
+ row.Field<string>("6").ToString() + "' ,'"
+ row.Field<string>("7").ToString() + "' ,'"
+ row.Field<string>("8").ToString() + "' ,'"
+ row.Field<string>("9").ToString() + "' ,'"
+ row.Field<string>("10").ToString() + "' ,'"
+ row.Field<string>("11").ToString() + "' ,'"
+ row.Field<string>("12").ToString() + "' ,'"
+ row.Field<string>("13").ToString() + "' ,'"
+ row.Field<string>("14").ToString() + "' ,'"
+ row.Field<string>("15").ToString() + "', '"
+ row.Field<string>("Column1").ToString() + "', now());");
if (i % 10 == 0)
{

View File

@ -213,7 +213,7 @@ namespace solarApp.Service
sql = @"insert into sensor_history_hour( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust)
select a.powerstationID, a.reportdate, ifnull(b.irrAvg, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust from
(
select @powerStationID powerstationID, FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, avg(" + modelTempCol + @") Temperature,
select @powerStationID powerstationID, FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, round(avg(" + modelTempCol + @"), 4) Temperature,
avg(" + evnTempCol + @") envTemperature, avg(" + humCol + @") humidity, avg(" + windCol + @") Vane, avg(" + dustCol + @") Dust
from " + _siteDB + ".s" + _siteID01 + @"_sensorAvg
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1

View File

@ -32,6 +32,7 @@ namespace solarApp
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.bt_meter = new System.Windows.Forms.Button();
this.lbmsg = new System.Windows.Forms.Label();
this.dtSelect2 = new System.Windows.Forms.DateTimePicker();
this.bt_archive = new System.Windows.Forms.Button();
@ -50,7 +51,6 @@ namespace solarApp
this.lbSiteID_sensor = new System.Windows.Forms.Label();
this.lbSiteName_sensor = new System.Windows.Forms.Label();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.bt_meter = new System.Windows.Forms.Button();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
@ -68,20 +68,18 @@ namespace solarApp
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Margin = new System.Windows.Forms.Padding(2);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(1386, 752);
this.tabControl1.Size = new System.Drawing.Size(1782, 953);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.splitContainer1);
this.tabPage1.Location = new System.Drawing.Point(4, 27);
this.tabPage1.Margin = new System.Windows.Forms.Padding(2);
this.tabPage1.Location = new System.Drawing.Point(4, 31);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(2);
this.tabPage1.Size = new System.Drawing.Size(1378, 721);
this.tabPage1.Padding = new System.Windows.Forms.Padding(3, 3, 3, 3);
this.tabPage1.Size = new System.Drawing.Size(1774, 918);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
this.tabPage1.UseVisualStyleBackColor = true;
@ -89,8 +87,7 @@ namespace solarApp
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(2, 2);
this.splitContainer1.Margin = new System.Windows.Forms.Padding(2);
this.splitContainer1.Location = new System.Drawing.Point(3, 3);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
@ -113,36 +110,44 @@ namespace solarApp
//
this.splitContainer1.Panel2.Controls.Add(this.dataGridView1);
this.splitContainer1.Panel2.Controls.Add(this.panel1);
this.splitContainer1.Size = new System.Drawing.Size(1374, 717);
this.splitContainer1.SplitterDistance = 233;
this.splitContainer1.SplitterWidth = 8;
this.splitContainer1.Size = new System.Drawing.Size(1768, 912);
this.splitContainer1.SplitterDistance = 299;
this.splitContainer1.SplitterWidth = 10;
this.splitContainer1.TabIndex = 0;
//
// bt_meter
//
this.bt_meter.Location = new System.Drawing.Point(156, 786);
this.bt_meter.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.bt_meter.Name = "bt_meter";
this.bt_meter.Size = new System.Drawing.Size(135, 56);
this.bt_meter.TabIndex = 11;
this.bt_meter.Text = "Meter歸檔";
this.bt_meter.UseVisualStyleBackColor = true;
this.bt_meter.Click += new System.EventHandler(this.bt_meter_Click);
//
// lbmsg
//
this.lbmsg.AutoSize = true;
this.lbmsg.Location = new System.Drawing.Point(7, 410);
this.lbmsg.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbmsg.Location = new System.Drawing.Point(10, 569);
this.lbmsg.Name = "lbmsg";
this.lbmsg.Size = new System.Drawing.Size(16, 15);
this.lbmsg.Size = new System.Drawing.Size(20, 19);
this.lbmsg.TabIndex = 10;
this.lbmsg.Text = "~";
//
// dtSelect2
//
this.dtSelect2.Location = new System.Drawing.Point(7, 429);
this.dtSelect2.Margin = new System.Windows.Forms.Padding(2);
this.dtSelect2.Location = new System.Drawing.Point(10, 593);
this.dtSelect2.Name = "dtSelect2";
this.dtSelect2.Size = new System.Drawing.Size(114, 23);
this.dtSelect2.Size = new System.Drawing.Size(145, 27);
this.dtSelect2.TabIndex = 9;
//
// bt_archive
//
this.bt_archive.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.bt_archive.Location = new System.Drawing.Point(7, 651);
this.bt_archive.Margin = new System.Windows.Forms.Padding(2);
this.bt_archive.Location = new System.Drawing.Point(9, 846);
this.bt_archive.Name = "bt_archive";
this.bt_archive.Size = new System.Drawing.Size(219, 56);
this.bt_archive.Size = new System.Drawing.Size(282, 61);
this.bt_archive.TabIndex = 8;
this.bt_archive.Text = "單日歸檔";
this.bt_archive.UseVisualStyleBackColor = true;
@ -152,10 +157,9 @@ namespace solarApp
//
this.bt_clear_sensor.Enabled = false;
this.bt_clear_sensor.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.bt_clear_sensor.Location = new System.Drawing.Point(3, 466);
this.bt_clear_sensor.Margin = new System.Windows.Forms.Padding(2);
this.bt_clear_sensor.Location = new System.Drawing.Point(10, 635);
this.bt_clear_sensor.Name = "bt_clear_sensor";
this.bt_clear_sensor.Size = new System.Drawing.Size(105, 35);
this.bt_clear_sensor.Size = new System.Drawing.Size(135, 44);
this.bt_clear_sensor.TabIndex = 7;
this.bt_clear_sensor.Text = "clear data";
this.bt_clear_sensor.UseVisualStyleBackColor = true;
@ -165,10 +169,9 @@ namespace solarApp
//
this.bt_clear_station.Enabled = false;
this.bt_clear_station.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.bt_clear_station.Location = new System.Drawing.Point(3, 545);
this.bt_clear_station.Margin = new System.Windows.Forms.Padding(2);
this.bt_clear_station.Location = new System.Drawing.Point(10, 735);
this.bt_clear_station.Name = "bt_clear_station";
this.bt_clear_station.Size = new System.Drawing.Size(105, 35);
this.bt_clear_station.Size = new System.Drawing.Size(135, 44);
this.bt_clear_station.TabIndex = 6;
this.bt_clear_station.Text = "clear data";
this.bt_clear_station.UseVisualStyleBackColor = true;
@ -178,10 +181,9 @@ namespace solarApp
//
this.bt_clear_inv.Enabled = false;
this.bt_clear_inv.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.bt_clear_inv.Location = new System.Drawing.Point(3, 506);
this.bt_clear_inv.Margin = new System.Windows.Forms.Padding(2);
this.bt_clear_inv.Location = new System.Drawing.Point(10, 686);
this.bt_clear_inv.Name = "bt_clear_inv";
this.bt_clear_inv.Size = new System.Drawing.Size(105, 35);
this.bt_clear_inv.Size = new System.Drawing.Size(135, 44);
this.bt_clear_inv.TabIndex = 5;
this.bt_clear_inv.Text = "clear data";
this.bt_clear_inv.UseVisualStyleBackColor = true;
@ -191,27 +193,24 @@ namespace solarApp
//
this.fp_site.Dock = System.Windows.Forms.DockStyle.Top;
this.fp_site.Location = new System.Drawing.Point(0, 0);
this.fp_site.Margin = new System.Windows.Forms.Padding(2);
this.fp_site.Name = "fp_site";
this.fp_site.Size = new System.Drawing.Size(233, 380);
this.fp_site.Size = new System.Drawing.Size(299, 530);
this.fp_site.TabIndex = 4;
//
// dtSelect1
//
this.dtSelect1.Location = new System.Drawing.Point(7, 384);
this.dtSelect1.Margin = new System.Windows.Forms.Padding(2);
this.dtSelect1.Location = new System.Drawing.Point(10, 536);
this.dtSelect1.Name = "dtSelect1";
this.dtSelect1.Size = new System.Drawing.Size(114, 23);
this.dtSelect1.Size = new System.Drawing.Size(145, 27);
this.dtSelect1.TabIndex = 3;
this.dtSelect1.ValueChanged += new System.EventHandler(this.dtSelect_ValueChanged);
//
// bt_site
//
this.bt_site.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.bt_site.Location = new System.Drawing.Point(119, 545);
this.bt_site.Margin = new System.Windows.Forms.Padding(2);
this.bt_site.Location = new System.Drawing.Point(159, 735);
this.bt_site.Name = "bt_site";
this.bt_site.Size = new System.Drawing.Size(105, 35);
this.bt_site.Size = new System.Drawing.Size(135, 44);
this.bt_site.TabIndex = 2;
this.bt_site.Text = "Site 歸檔";
this.bt_site.UseVisualStyleBackColor = true;
@ -220,10 +219,9 @@ namespace solarApp
// bt_Inv
//
this.bt_Inv.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.bt_Inv.Location = new System.Drawing.Point(117, 506);
this.bt_Inv.Margin = new System.Windows.Forms.Padding(2);
this.bt_Inv.Location = new System.Drawing.Point(156, 686);
this.bt_Inv.Name = "bt_Inv";
this.bt_Inv.Size = new System.Drawing.Size(105, 35);
this.bt_Inv.Size = new System.Drawing.Size(135, 44);
this.bt_Inv.TabIndex = 1;
this.bt_Inv.Text = "Inv 歸檔";
this.bt_Inv.UseVisualStyleBackColor = true;
@ -232,10 +230,9 @@ namespace solarApp
// bt_Sensor
//
this.bt_Sensor.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.bt_Sensor.Location = new System.Drawing.Point(117, 466);
this.bt_Sensor.Margin = new System.Windows.Forms.Padding(2);
this.bt_Sensor.Location = new System.Drawing.Point(156, 635);
this.bt_Sensor.Name = "bt_Sensor";
this.bt_Sensor.Size = new System.Drawing.Size(105, 35);
this.bt_Sensor.Size = new System.Drawing.Size(135, 44);
this.bt_Sensor.TabIndex = 0;
this.bt_Sensor.Text = "Sensor 歸檔";
this.bt_Sensor.UseVisualStyleBackColor = true;
@ -245,12 +242,11 @@ namespace solarApp
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.Location = new System.Drawing.Point(0, 99);
this.dataGridView1.Margin = new System.Windows.Forms.Padding(2);
this.dataGridView1.Location = new System.Drawing.Point(0, 125);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowHeadersWidth = 51;
this.dataGridView1.RowTemplate.Height = 29;
this.dataGridView1.Size = new System.Drawing.Size(1133, 618);
this.dataGridView1.Size = new System.Drawing.Size(1459, 787);
this.dataGridView1.TabIndex = 1;
//
// panel1
@ -262,18 +258,16 @@ namespace solarApp
this.panel1.Controls.Add(this.lbSiteName_sensor);
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Margin = new System.Windows.Forms.Padding(2);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(1133, 99);
this.panel1.Size = new System.Drawing.Size(1459, 125);
this.panel1.TabIndex = 0;
//
// btVerifyData
//
this.btVerifyData.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.btVerifyData.Location = new System.Drawing.Point(494, 6);
this.btVerifyData.Margin = new System.Windows.Forms.Padding(2);
this.btVerifyData.Location = new System.Drawing.Point(635, 8);
this.btVerifyData.Name = "btVerifyData";
this.btVerifyData.Size = new System.Drawing.Size(123, 35);
this.btVerifyData.Size = new System.Drawing.Size(158, 44);
this.btVerifyData.TabIndex = 12;
this.btVerifyData.Text = "檢核結果";
this.btVerifyData.UseVisualStyleBackColor = true;
@ -283,9 +277,10 @@ namespace solarApp
//
this.lbSiteDB_sensor.AutoSize = true;
this.lbSiteDB_sensor.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.lbSiteDB_sensor.Location = new System.Drawing.Point(38, 15);
this.lbSiteDB_sensor.Location = new System.Drawing.Point(49, 19);
this.lbSiteDB_sensor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lbSiteDB_sensor.Name = "lbSiteDB_sensor";
this.lbSiteDB_sensor.Size = new System.Drawing.Size(62, 19);
this.lbSiteDB_sensor.Size = new System.Drawing.Size(79, 24);
this.lbSiteDB_sensor.TabIndex = 11;
this.lbSiteDB_sensor.Text = "Site_DB";
this.lbSiteDB_sensor.Click += new System.EventHandler(this.lbSiteDB_sensor_Click);
@ -294,9 +289,10 @@ namespace solarApp
//
this.lbSiteID_sensor.AutoSize = true;
this.lbSiteID_sensor.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.lbSiteID_sensor.Location = new System.Drawing.Point(156, 15);
this.lbSiteID_sensor.Location = new System.Drawing.Point(201, 19);
this.lbSiteID_sensor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lbSiteID_sensor.Name = "lbSiteID_sensor";
this.lbSiteID_sensor.Size = new System.Drawing.Size(57, 19);
this.lbSiteID_sensor.Size = new System.Drawing.Size(72, 24);
this.lbSiteID_sensor.TabIndex = 10;
this.lbSiteID_sensor.Text = "Site_ID";
//
@ -304,40 +300,29 @@ namespace solarApp
//
this.lbSiteName_sensor.AutoSize = true;
this.lbSiteName_sensor.Font = new System.Drawing.Font("Microsoft JhengHei UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.lbSiteName_sensor.Location = new System.Drawing.Point(280, 15);
this.lbSiteName_sensor.Location = new System.Drawing.Point(360, 19);
this.lbSiteName_sensor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lbSiteName_sensor.Name = "lbSiteName_sensor";
this.lbSiteName_sensor.Size = new System.Drawing.Size(84, 19);
this.lbSiteName_sensor.Size = new System.Drawing.Size(107, 24);
this.lbSiteName_sensor.TabIndex = 9;
this.lbSiteName_sensor.Text = "Site_Name";
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 27);
this.tabPage2.Margin = new System.Windows.Forms.Padding(2);
this.tabPage2.Location = new System.Drawing.Point(4, 31);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(2);
this.tabPage2.Size = new System.Drawing.Size(1378, 721);
this.tabPage2.Padding = new System.Windows.Forms.Padding(3, 3, 3, 3);
this.tabPage2.Size = new System.Drawing.Size(1774, 918);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
this.tabPage2.UseVisualStyleBackColor = true;
//
// bt_meter
//
this.bt_meter.Location = new System.Drawing.Point(117, 585);
this.bt_meter.Name = "bt_meter";
this.bt_meter.Size = new System.Drawing.Size(105, 44);
this.bt_meter.TabIndex = 11;
this.bt_meter.Text = "Meter歸檔";
this.bt_meter.UseVisualStyleBackColor = true;
this.bt_meter.Click += new System.EventHandler(this.bt_meter_Click);
//
// fmArchive
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 19F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1386, 752);
this.ClientSize = new System.Drawing.Size(1782, 953);
this.Controls.Add(this.tabControl1);
this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "fmArchive";
this.Text = "fmArchive";
this.Load += new System.EventHandler(this.fmArchive_Load);

View File

@ -42,6 +42,7 @@ namespace solarApp
this.panel1 = new System.Windows.Forms.Panel();
this.lbSiteName_sensor = new System.Windows.Forms.Label();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.bt_sun_yadong = new System.Windows.Forms.Button();
this.bt_sun_taoyuan = new System.Windows.Forms.Button();
this.bt_gong34 = new System.Windows.Forms.Button();
this.bt_AUO_aimai = new System.Windows.Forms.Button();
@ -50,7 +51,7 @@ namespace solarApp
this.rt1 = new System.Windows.Forms.RichTextBox();
this.tb1 = new System.Windows.Forms.TabPage();
this.tabControl = new System.Windows.Forms.TabControl();
this.bt_sun_yadong = new System.Windows.Forms.Button();
this.bt_dailyReport = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
@ -98,7 +99,7 @@ namespace solarApp
this.bt_archive.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.bt_archive.Location = new System.Drawing.Point(3, 640);
this.bt_archive.Name = "bt_archive";
this.bt_archive.Size = new System.Drawing.Size(282, 100);
this.bt_archive.Size = new System.Drawing.Size(226, 60);
this.bt_archive.TabIndex = 8;
this.bt_archive.Text = "單日歸檔";
this.bt_archive.UseVisualStyleBackColor = true;
@ -201,6 +202,7 @@ namespace solarApp
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.BackColor = System.Drawing.Color.PaleGoldenrod;
this.splitContainer1.Panel1.Controls.Add(this.bt_dailyReport);
this.splitContainer1.Panel1.Controls.Add(this.bt_sun_yadong);
this.splitContainer1.Panel1.Controls.Add(this.bt_sun_taoyuan);
this.splitContainer1.Panel1.Controls.Add(this.bt_gong34);
@ -223,6 +225,17 @@ namespace solarApp
this.splitContainer1.SplitterWidth = 10;
this.splitContainer1.TabIndex = 0;
//
// bt_sun_yadong
//
this.bt_sun_yadong.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.bt_sun_yadong.Location = new System.Drawing.Point(5, 576);
this.bt_sun_yadong.Name = "bt_sun_yadong";
this.bt_sun_yadong.Size = new System.Drawing.Size(213, 47);
this.bt_sun_yadong.TabIndex = 14;
this.bt_sun_yadong.Text = "太陽能光電-亞東觀音";
this.bt_sun_yadong.UseVisualStyleBackColor = true;
this.bt_sun_yadong.Click += new System.EventHandler(this.bt_sun_yadong_Click);
//
// bt_sun_taoyuan
//
this.bt_sun_taoyuan.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
@ -312,16 +325,16 @@ namespace solarApp
this.tabControl.Size = new System.Drawing.Size(1782, 853);
this.tabControl.TabIndex = 1;
//
// bt_sun_yadong
// bt_dailyReport
//
this.bt_sun_yadong.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.bt_sun_yadong.Location = new System.Drawing.Point(5, 576);
this.bt_sun_yadong.Name = "bt_sun_yadong";
this.bt_sun_yadong.Size = new System.Drawing.Size(213, 47);
this.bt_sun_yadong.TabIndex = 14;
this.bt_sun_yadong.Text = "太陽能光電-亞東觀音";
this.bt_sun_yadong.UseVisualStyleBackColor = true;
this.bt_sun_yadong.Click += new System.EventHandler(this.bt_sun_yadong_Click);
this.bt_dailyReport.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.bt_dailyReport.Location = new System.Drawing.Point(5, 706);
this.bt_dailyReport.Name = "bt_dailyReport";
this.bt_dailyReport.Size = new System.Drawing.Size(237, 74);
this.bt_dailyReport.TabIndex = 15;
this.bt_dailyReport.Text = "daily_report 太陽能光電-桃園全虹";
this.bt_dailyReport.UseVisualStyleBackColor = true;
this.bt_dailyReport.Click += new System.EventHandler(this.bt_dailyReport_Click);
//
// fmExcel
//
@ -369,5 +382,6 @@ namespace solarApp
private System.Windows.Forms.Button bt_gong34;
private System.Windows.Forms.Button bt_sun_taoyuan;
private System.Windows.Forms.Button bt_sun_yadong;
private System.Windows.Forms.Button bt_dailyReport;
}
}

View File

@ -555,5 +555,169 @@ namespace solarApp
csvSvc.taoYuan_insertHour2DB(ref dt, "sun_yadong");
MessageBox.Show("OK");
}
protected void ImporExcel_dailyReport(string site_name)
{
string fname = "";
//OpenFileDialog fdlg = new OpenFileDialog();
//fdlg.Title = "Excel File Dialog";
//fdlg.InitialDirectory = @"d:\";
//fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
//fdlg.FilterIndex = 2;
//fdlg.RestoreDirectory = true;
string[] fileEntries = new string[0];
Array.Clear(fileEntries, 0, fileEntries.Length);
//取得選取檔案的路徑
string dir;//= Path.GetDirectoryName(fname);
using (var fbd = new FolderBrowserDialog())
{
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
//dir = Path.GetDirectoryName(fname);
//fileEntries = Directory.GetFiles(fbd.SelectedPath);
fileEntries = Directory.GetFiles(fbd.SelectedPath, "*.*", SearchOption.AllDirectories);
MessageBox.Show("Files found: " + fileEntries.Length.ToString(), "Message");
}
}
// 取得路徑下所有檔案
//string[] fileEntries = System.IO.Directory.GetFiles(dir); //D:\temp\AUO\台中太平\台中太平\inverter
//string[] fileEntries = Directory.GetFiles(@"D:\AUO\台中太平\inverter", "*.*", SearchOption.AllDirectories);
// dt.Column = colCount;
solarApp.Service.excelHelper xlsSvc = new Service.excelHelper();
System.Data.DataTable dt = new System.Data.DataTable();
DataColumn mydc;
bool isFirst = true; bool isFirstData = true;
int x = 0;
#region save file list
//xlsSvc.insertFile2DB(fileEntries, site_name);
xlsSvc.insert_dailyReport2DB(fileEntries, site_name);
#endregion
foreach (string fullfileName in fileEntries)
{
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (fullfileName.Contains("~$")) { rt1.AppendText("\n -- contain ~$ in filename: " + fullfileName.ToString()); continue; }
Microsoft.Office.Interop.Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(fullfileName);
Microsoft.Office.Interop.Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Microsoft.Office.Interop.Excel.Range xlRange = xlWorksheet.UsedRange;
//dataGridView1.ColumnCount = colCount;
//dataGridView1.RowCount = rowCount;
string[] ff = fullfileName.Split("\\");
string filename = string.Empty;
filename += ff[ff.Length-1].Replace(".xlsx", ""); //只抓最後的檔名
rt1.AppendText(filename.ToString() + " ");
rt1.SelectionStart = rt1.Text.Length;
rt1.ScrollToCaret();
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
for (int i = 1; i <= rowCount; i++)
{
#region dt add column
if (isFirst)
{
for (int j = 1; j <= colCount; j++)
{
int col = 0;
col = j;
mydc = new DataColumn(col.ToString());
dt.Columns.Add(mydc);
isFirst = false;
}
mydc = new DataColumn("dataDate");
dt.Columns.Add("");
}
#endregion
DataRow row = dt.NewRow();
//只需要 10個欄位的版本 ---------------------------------
//if (colCount != 10) {
// rt1.AppendText("\n -- unable read file: " + fullfileName.ToString());
// break;
//}
for (int j = 0; j <= colCount-1; j++)
{
if (isFirstData) // 第一筆資料為 欄位名稱
{
Microsoft.Office.Interop.Excel.Range range = xlRange.Cells[i, j+1] as Microsoft.Office.Interop.Excel.Range;
row[j] = range.Value.ToString();
if (j == 15) isFirstData = false;
}
// else if (i == 1) continue;// 第二個檔案之後的 firstRow 不需要, start from 1
else //從第二個檔案 開始都從第二個 row 開始
{
Microsoft.Office.Interop.Excel.Range range = xlRange.Cells[i, j+1] as Microsoft.Office.Interop.Excel.Range;
if (string.IsNullOrEmpty(range.Value) || string.IsNullOrWhiteSpace(range.Value))
MessageBox.Show("got it!");
//string ss = range.Value.ToString();
//ss = ss.Replace("[", "").Replace("]", "");
row[j] = range.Value.ToString();
}
if (j == colCount)
{
if (string.IsNullOrEmpty(row[j].ToString()) || string.IsNullOrWhiteSpace(row[j].ToString()))
MessageBox.Show("empty!");
}
}//欄位 for
if (string.IsNullOrEmpty(row[5].ToString()) || string.IsNullOrWhiteSpace(row[5].ToString()))
{
MessageBox.Show("empty!");
}
else
{
if (i == 1) continue;// 第二個檔案之後的 firstRow 不需要, start from 1
else
{
//最後一個欄位:日期
row[row.ItemArray.Length-1] = filename;
dt.Rows.Add(row);
}
}
}
//release com objects to fully kill excel process from running in the background
Marshal.ReleaseComObject(xlRange);
Marshal.ReleaseComObject(xlWorksheet);
//close and release
xlWorkbook.Close();
Marshal.ReleaseComObject(xlWorkbook);
//quit and release
xlApp.Quit();
Marshal.ReleaseComObject(xlApp);
//if (x ==3) break;
//string[] str = filename.Split("_");
//string inverterID = str[str.Length - 3] + "_" + str[str.Length - 2];
//str = inverterID.Split(" ");
//inverterID = str[str.Length - 1];
xlsSvc.insert_dailyReport2DB(dt, filename);
dt.Rows.Clear();
x++;
}
//cleanup
GC.Collect();
GC.WaitForPendingFinalizers();
dataGridView1.DataSource = dt;
//MessageBox.Show(" dt.Rows.Count = " + dt.Rows.Count.ToString());
MessageBox.Show(" ok ");
//rule of thumb for releasing com objects:
// never use two dots, all COM objects must be referenced and released individually
// ex: [somthing].[something].[something] is bad
}
private void bt_dailyReport_Click(object sender, EventArgs e)
{
ImporExcel_dailyReport("");
}
}
}