From d3daf7ea56aafe1e9cd2fe2c7c3cc119ceb9acc7 Mon Sep 17 00:00:00 2001 From: Kai Date: Mon, 13 Sep 2021 18:32:17 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=8A=A0=E5=85=A5meter=20=E6=8C=89?= =?UTF-8?q?=E9=88=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Service/procSensorSvc.cs | 24 +++++- solarApp/fmArchive.Designer.cs | 125 ++++++++++++++++++------------ solarApp/fmArchive.cs | 8 ++ 3 files changed, 107 insertions(+), 50 deletions(-) diff --git a/solarApp/Service/procSensorSvc.cs b/solarApp/Service/procSensorSvc.cs index 4be01f5..e1ec277 100644 --- a/solarApp/Service/procSensorSvc.cs +++ b/solarApp/Service/procSensorSvc.cs @@ -387,6 +387,26 @@ namespace solarApp.Service return result; } + public bool archiveMeterData(string siteID, string date1) + { + + bool result = false; + try + { + _siteID = siteID; + _date1 = date1; + get_siteInfo(); + //clearMeterData(); + insert_meter(); + result = true; + } + catch (Exception ex) + { + throw ex; + } + return result; + } + bool insert_meter() { bool result = false; using (MySqlConnection conn = new MySqlConnection(Connection1)) @@ -395,7 +415,7 @@ namespace solarApp.Service try { //先判斷是否存在 meter - string ss = $@"SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = '" + _siteDB + "' AND table_name = 's" + _siteID01 + "' "; + string ss = $@"SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = '" + _siteDB + "' AND table_name = 's" + _siteID01 + "_meter' "; List ds_meter = conn.Query(ss, new { siteID = _siteID01 }).AsList(); if (ds_meter.Count == 0) return false; @@ -413,7 +433,7 @@ namespace solarApp.Service ) m1 LEFT JOIN ( -- 取得整點值INPUT_KWH, OUTPUT_KWH SELECT FROM_UNIXTIME(m.timestamp / 1000, '%Y-%m-%d %H') AS `timestamp`, m.METERID, m.INPUT_KWH AS INPUT_KWH, m.OUTPUT_KWH AS OUTPUT_KWH - FROM " + _siteDB + ".s" + _siteID01 + @" m + FROM " + _siteDB + ".s" + _siteID01 + @"_meter m WHERE LEFT(FROM_UNIXTIME(m.timestamp / 1000, '%Y-%m-%d %H'), 10) = @date1 AND RIGHT(FROM_UNIXTIME(m.timestamp / 1000, '%Y-%m-%d %H'), 2) = '55' ) m2 ON m1.timestamp = m2.timestamp AND m1.METERID = m2.METERID;"; diff --git a/solarApp/fmArchive.Designer.cs b/solarApp/fmArchive.Designer.cs index 386e929..c0fe1a2 100644 --- a/solarApp/fmArchive.Designer.cs +++ b/solarApp/fmArchive.Designer.cs @@ -50,6 +50,7 @@ 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(); @@ -67,18 +68,20 @@ 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(1782, 953); + this.tabControl1.Size = new System.Drawing.Size(1386, 752); this.tabControl1.TabIndex = 0; // // tabPage1 // this.tabPage1.Controls.Add(this.splitContainer1); - this.tabPage1.Location = new System.Drawing.Point(4, 31); + this.tabPage1.Location = new System.Drawing.Point(4, 27); + this.tabPage1.Margin = new System.Windows.Forms.Padding(2); this.tabPage1.Name = "tabPage1"; - this.tabPage1.Padding = new System.Windows.Forms.Padding(3); - this.tabPage1.Size = new System.Drawing.Size(1774, 918); + this.tabPage1.Padding = new System.Windows.Forms.Padding(2); + this.tabPage1.Size = new System.Drawing.Size(1378, 721); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "tabPage1"; this.tabPage1.UseVisualStyleBackColor = true; @@ -86,12 +89,14 @@ namespace solarApp // splitContainer1 // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer1.Location = new System.Drawing.Point(3, 3); + this.splitContainer1.Location = new System.Drawing.Point(2, 2); + this.splitContainer1.Margin = new System.Windows.Forms.Padding(2); this.splitContainer1.Name = "splitContainer1"; // // splitContainer1.Panel1 // this.splitContainer1.Panel1.BackColor = System.Drawing.SystemColors.ActiveCaption; + this.splitContainer1.Panel1.Controls.Add(this.bt_meter); this.splitContainer1.Panel1.Controls.Add(this.lbmsg); this.splitContainer1.Panel1.Controls.Add(this.dtSelect2); this.splitContainer1.Panel1.Controls.Add(this.bt_archive); @@ -108,33 +113,36 @@ namespace solarApp // this.splitContainer1.Panel2.Controls.Add(this.dataGridView1); this.splitContainer1.Panel2.Controls.Add(this.panel1); - this.splitContainer1.Size = new System.Drawing.Size(1768, 912); - this.splitContainer1.SplitterDistance = 300; - this.splitContainer1.SplitterWidth = 10; + this.splitContainer1.Size = new System.Drawing.Size(1374, 717); + this.splitContainer1.SplitterDistance = 233; + this.splitContainer1.SplitterWidth = 8; this.splitContainer1.TabIndex = 0; // // lbmsg // this.lbmsg.AutoSize = true; - this.lbmsg.Location = new System.Drawing.Point(15, 591); + this.lbmsg.Location = new System.Drawing.Point(7, 410); + this.lbmsg.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.lbmsg.Name = "lbmsg"; - this.lbmsg.Size = new System.Drawing.Size(20, 19); + this.lbmsg.Size = new System.Drawing.Size(16, 15); this.lbmsg.TabIndex = 10; this.lbmsg.Text = "~"; // // dtSelect2 // - this.dtSelect2.Location = new System.Drawing.Point(15, 616); + this.dtSelect2.Location = new System.Drawing.Point(7, 429); + this.dtSelect2.Margin = new System.Windows.Forms.Padding(2); this.dtSelect2.Name = "dtSelect2"; - this.dtSelect2.Size = new System.Drawing.Size(145, 27); + this.dtSelect2.Size = new System.Drawing.Size(114, 23); 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(9, 825); + this.bt_archive.Location = new System.Drawing.Point(7, 651); + this.bt_archive.Margin = new System.Windows.Forms.Padding(2); this.bt_archive.Name = "bt_archive"; - this.bt_archive.Size = new System.Drawing.Size(282, 71); + this.bt_archive.Size = new System.Drawing.Size(219, 56); this.bt_archive.TabIndex = 8; this.bt_archive.Text = "單日歸檔"; this.bt_archive.UseVisualStyleBackColor = true; @@ -144,9 +152,10 @@ 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(10, 663); + 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.Name = "bt_clear_sensor"; - this.bt_clear_sensor.Size = new System.Drawing.Size(135, 44); + this.bt_clear_sensor.Size = new System.Drawing.Size(105, 35); this.bt_clear_sensor.TabIndex = 7; this.bt_clear_sensor.Text = "clear data"; this.bt_clear_sensor.UseVisualStyleBackColor = true; @@ -156,9 +165,10 @@ 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(10, 763); + 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.Name = "bt_clear_station"; - this.bt_clear_station.Size = new System.Drawing.Size(135, 44); + this.bt_clear_station.Size = new System.Drawing.Size(105, 35); this.bt_clear_station.TabIndex = 6; this.bt_clear_station.Text = "clear data"; this.bt_clear_station.UseVisualStyleBackColor = true; @@ -168,9 +178,10 @@ 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(10, 713); + 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.Name = "bt_clear_inv"; - this.bt_clear_inv.Size = new System.Drawing.Size(135, 44); + this.bt_clear_inv.Size = new System.Drawing.Size(105, 35); this.bt_clear_inv.TabIndex = 5; this.bt_clear_inv.Text = "clear data"; this.bt_clear_inv.UseVisualStyleBackColor = true; @@ -180,24 +191,27 @@ 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(300, 553); + this.fp_site.Size = new System.Drawing.Size(233, 380); this.fp_site.TabIndex = 4; // // dtSelect1 // - this.dtSelect1.Location = new System.Drawing.Point(15, 559); + this.dtSelect1.Location = new System.Drawing.Point(7, 384); + this.dtSelect1.Margin = new System.Windows.Forms.Padding(2); this.dtSelect1.Name = "dtSelect1"; - this.dtSelect1.Size = new System.Drawing.Size(145, 27); + this.dtSelect1.Size = new System.Drawing.Size(114, 23); 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(159, 763); + this.bt_site.Location = new System.Drawing.Point(119, 545); + this.bt_site.Margin = new System.Windows.Forms.Padding(2); this.bt_site.Name = "bt_site"; - this.bt_site.Size = new System.Drawing.Size(135, 44); + this.bt_site.Size = new System.Drawing.Size(105, 35); this.bt_site.TabIndex = 2; this.bt_site.Text = "Site 歸檔"; this.bt_site.UseVisualStyleBackColor = true; @@ -206,9 +220,10 @@ 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(157, 713); + this.bt_Inv.Location = new System.Drawing.Point(117, 506); + this.bt_Inv.Margin = new System.Windows.Forms.Padding(2); this.bt_Inv.Name = "bt_Inv"; - this.bt_Inv.Size = new System.Drawing.Size(135, 44); + this.bt_Inv.Size = new System.Drawing.Size(105, 35); this.bt_Inv.TabIndex = 1; this.bt_Inv.Text = "Inv 歸檔"; this.bt_Inv.UseVisualStyleBackColor = true; @@ -217,9 +232,10 @@ 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(157, 663); + this.bt_Sensor.Location = new System.Drawing.Point(117, 466); + this.bt_Sensor.Margin = new System.Windows.Forms.Padding(2); this.bt_Sensor.Name = "bt_Sensor"; - this.bt_Sensor.Size = new System.Drawing.Size(135, 44); + this.bt_Sensor.Size = new System.Drawing.Size(105, 35); this.bt_Sensor.TabIndex = 0; this.bt_Sensor.Text = "Sensor 歸檔"; this.bt_Sensor.UseVisualStyleBackColor = true; @@ -229,11 +245,12 @@ 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, 125); + this.dataGridView1.Location = new System.Drawing.Point(0, 99); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(2); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.RowHeadersWidth = 51; this.dataGridView1.RowTemplate.Height = 29; - this.dataGridView1.Size = new System.Drawing.Size(1458, 787); + this.dataGridView1.Size = new System.Drawing.Size(1133, 618); this.dataGridView1.TabIndex = 1; // // panel1 @@ -245,16 +262,18 @@ 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(1458, 125); + this.panel1.Size = new System.Drawing.Size(1133, 99); 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(635, 7); + this.btVerifyData.Location = new System.Drawing.Point(494, 6); + this.btVerifyData.Margin = new System.Windows.Forms.Padding(2); this.btVerifyData.Name = "btVerifyData"; - this.btVerifyData.Size = new System.Drawing.Size(158, 44); + this.btVerifyData.Size = new System.Drawing.Size(123, 35); this.btVerifyData.TabIndex = 12; this.btVerifyData.Text = "檢核結果"; this.btVerifyData.UseVisualStyleBackColor = true; @@ -264,10 +283,9 @@ 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(49, 19); - this.lbSiteDB_sensor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lbSiteDB_sensor.Location = new System.Drawing.Point(38, 15); this.lbSiteDB_sensor.Name = "lbSiteDB_sensor"; - this.lbSiteDB_sensor.Size = new System.Drawing.Size(79, 24); + this.lbSiteDB_sensor.Size = new System.Drawing.Size(62, 19); this.lbSiteDB_sensor.TabIndex = 11; this.lbSiteDB_sensor.Text = "Site_DB"; this.lbSiteDB_sensor.Click += new System.EventHandler(this.lbSiteDB_sensor_Click); @@ -276,10 +294,9 @@ 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(200, 19); - this.lbSiteID_sensor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lbSiteID_sensor.Location = new System.Drawing.Point(156, 15); this.lbSiteID_sensor.Name = "lbSiteID_sensor"; - this.lbSiteID_sensor.Size = new System.Drawing.Size(72, 24); + this.lbSiteID_sensor.Size = new System.Drawing.Size(57, 19); this.lbSiteID_sensor.TabIndex = 10; this.lbSiteID_sensor.Text = "Site_ID"; // @@ -287,29 +304,40 @@ 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(360, 19); - this.lbSiteName_sensor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lbSiteName_sensor.Location = new System.Drawing.Point(280, 15); this.lbSiteName_sensor.Name = "lbSiteName_sensor"; - this.lbSiteName_sensor.Size = new System.Drawing.Size(107, 24); + this.lbSiteName_sensor.Size = new System.Drawing.Size(84, 19); this.lbSiteName_sensor.TabIndex = 9; this.lbSiteName_sensor.Text = "Site_Name"; // // tabPage2 // - this.tabPage2.Location = new System.Drawing.Point(4, 31); + this.tabPage2.Location = new System.Drawing.Point(4, 27); + this.tabPage2.Margin = new System.Windows.Forms.Padding(2); this.tabPage2.Name = "tabPage2"; - this.tabPage2.Padding = new System.Windows.Forms.Padding(3); - this.tabPage2.Size = new System.Drawing.Size(1774, 918); + this.tabPage2.Padding = new System.Windows.Forms.Padding(2); + this.tabPage2.Size = new System.Drawing.Size(1378, 721); 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(9F, 19F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1782, 953); + this.ClientSize = new System.Drawing.Size(1386, 752); 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); @@ -351,5 +379,6 @@ namespace solarApp private System.Windows.Forms.Button bt_clear_sensor; private System.Windows.Forms.Label lbmsg; private System.Windows.Forms.DateTimePicker dtSelect2; + private System.Windows.Forms.Button bt_meter; } } \ No newline at end of file diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index ac22aa6..f8bd23e 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -179,5 +179,13 @@ namespace solarApp fmExcel fm = new fmExcel(); fm.Show(); } + + private void bt_meter_Click(object sender, EventArgs e) + { + string date1 = dtSelect1.Value.ToString("yyyy-MM-dd"); + procSensorSvc sensorSvc = new procSensorSvc(); + + sensorSvc.archiveMeterData(lbSiteID_sensor.Text.Substring(0, 9), date1); + } } }