From 636ca21e3ba4cc7de459e5d135b0c7cb363a99af Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Mon, 1 Nov 2021 09:50:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=B3=87=E6=96=99=E5=8C=AF=E5=85=A5=20-=20?= =?UTF-8?q?=E6=97=A5=E5=A0=B1=E8=A1=A8=E5=8C=AF=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Service/excelHelper.cs | 100 ++++++++++++++++++- solarApp/fmExcel.Designer.cs | 36 ++++--- solarApp/fmExcel.cs | 164 ++++++++++++++++++++++++++++++++ 3 files changed, 288 insertions(+), 12 deletions(-) diff --git a/solarApp/Service/excelHelper.cs b/solarApp/Service/excelHelper.cs index 8bd34b5..8c4dc2a 100644 --- a/solarApp/Service/excelHelper.cs +++ b/solarApp/Service/excelHelper.cs @@ -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("1").ToString() + "' ,'" + + row.Field("2").ToString() + "' ,'" + + row.Field("3").ToString() + "' ,'" + + row.Field("4").ToString() + "' ,'" + + row.Field("5").ToString() + "' ,'" + + row.Field("6").ToString() + "' ,'" + + row.Field("7").ToString() + "' ,'" + + row.Field("8").ToString() + "' ,'" + + row.Field("9").ToString() + "' ,'" + + row.Field("10").ToString() + "' ,'" + + row.Field("11").ToString() + "' ,'" + + row.Field("12").ToString() + "' ,'" + + row.Field("13").ToString() + "' ,'" + + row.Field("14").ToString() + "' ,'" ++ row.Field("15").ToString() + "', '" ++ row.Field("Column1").ToString() + "', now());"); if (i % 10 == 0) { diff --git a/solarApp/fmExcel.Designer.cs b/solarApp/fmExcel.Designer.cs index c59d8b3..15b80bb 100644 --- a/solarApp/fmExcel.Designer.cs +++ b/solarApp/fmExcel.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/solarApp/fmExcel.cs b/solarApp/fmExcel.cs index c6a9a2c..8861cd0 100644 --- a/solarApp/fmExcel.cs +++ b/solarApp/fmExcel.cs @@ -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(""); + + } } } From 55dcb0e3a7a101f991b4bd75d0207cca4737d8d2 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Mon, 1 Nov 2021 17:32:20 +0800 Subject: [PATCH 2/3] =?UTF-8?q?debug=20-=20=E6=BA=AB=E5=BA=A6=E5=80=BC?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E5=B0=8F=E6=95=B8=E9=BB=9E=E9=99=90?= =?UTF-8?q?=E5=88=B6=204=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Service/procSensorSvc.cs | 2 +- solarApp/fmArchive.Designer.cs | 135 +++++++++++++----------------- 2 files changed, 61 insertions(+), 76 deletions(-) diff --git a/solarApp/Service/procSensorSvc.cs b/solarApp/Service/procSensorSvc.cs index e1ec277..e4c307d 100644 --- a/solarApp/Service/procSensorSvc.cs +++ b/solarApp/Service/procSensorSvc.cs @@ -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 diff --git a/solarApp/fmArchive.Designer.cs b/solarApp/fmArchive.Designer.cs index c0fe1a2..397770b 100644 --- a/solarApp/fmArchive.Designer.cs +++ b/solarApp/fmArchive.Designer.cs @@ -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); From c2385524322b5213c8644488f557483c006a2fea Mon Sep 17 00:00:00 2001 From: b110212000 Date: Tue, 2 Nov 2021 10:13:36 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E9=9B=BB=E7=AB=99=E6=AA=A2=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PowerStationController.cs | 48 +++++++++++++++++-- SolarPower/Models/PowerStation.cs | 8 ++++ .../Implement/PowerStationRepository.cs | 30 ++++++++++++ .../Interface/IPowerStationRepository.cs | 1 + 4 files changed, 83 insertions(+), 4 deletions(-) diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 14da6a4..5482d63 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -3231,6 +3231,7 @@ namespace SolarPower.Controllers catch (Exception exception) { apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } @@ -3252,16 +3253,54 @@ namespace SolarPower.Controllers } else { - await powerStationRepository.StationStatus(Id,1); - await powerStationRepository.StationStatus(Id, 1, powerStation.SiteDB + "."); - apiResult.Msg = "電站啟用成功"; - apiResult.Code = "0000"; + var sitecheck = await powerStationRepository.Check4table(powerStation.Code, powerStation.SiteDB); + if(powerStation.Code != sitecheck.Avg && sitecheck.Avg != null) + { + status.Add($"s{powerStation.Code}01_avg SITEID錯誤"); + } + if (powerStation.Code != sitecheck.Inv_site && sitecheck.Inv_site != null) + { + status.Add($"s{powerStation.Code}01_inv SITEID錯誤"); + } + if (powerStation.Code + "01" != sitecheck.Inv_inveter.Substring(0,11) && sitecheck.Inv_inveter != null) + { + status.Add($"s{powerStation.Code}01_Inv inveter格式錯誤"); + } + if (powerStation.Code != sitecheck.Station && sitecheck.Station != null) + { + status.Add($"s{powerStation.Code}01_station SITEID錯誤"); + } + if (powerStation.Code != sitecheck.Sensor && sitecheck.Sensor != null) + { + status.Add($"s{powerStation.Code}01_sensor SITEID錯誤"); + } + if(sitecheck.Inv_inveter != null) + { + if (sitecheck.Inv_inveter.Length != 15) + { + status.Add($"s{powerStation.Code}01_Inv inveter格式錯誤"); + } + } + + if(status.Count > 0) + { + apiResult.Code = "0099"; + apiResult.Data = status; + } + else + { + await powerStationRepository.StationStatus(Id, 1); + await powerStationRepository.StationStatus(Id, 1, powerStation.SiteDB + "."); + apiResult.Msg = "電站啟用成功"; + apiResult.Code = "0000"; + } } } catch (Exception exception) { apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } @@ -3285,6 +3324,7 @@ namespace SolarPower.Controllers catch (Exception exception) { apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index 8815df8..4d2e793 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -1051,5 +1051,13 @@ namespace SolarPower.Models.PowerStation public string Site_id { get; set; } public string InverterId { get; set; } } + public class Check4table + { + public string Avg { get; set; } + public string Inv_site { get; set; } + public string Inv_inveter { get; set; } + public string Station { get; set; } + public string Sensor { get; set; } + } } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 1e91b32..7a9fe6d 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -5803,6 +5803,36 @@ namespace SolarPower.Repository.Implement } } + public async Task Check4table(string code,string dbname) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + var resule = new Check4table(); + try + { + + var sql = $@"SELECT * FROM + (SELECT a.SITEID AS Avg FROM {dbname}.s{code}01_sensoravg a ORDER BY a.ID DESC LIMIT 1) a, + (SELECT a.SITEID AS Inv_site,a.INVERTERID as Inv_inveter FROM {dbname}.s{code}01_inv a ORDER BY a.ID DESC LIMIT 1) b, + (SELECT a.SITEID AS Station FROM {dbname}.s{code}01_station a ORDER BY a.ID DESC LIMIT 1) c, + (SELECT a.SITEID AS Sensor FROM {dbname}.s{code}01_sensor a ORDER BY a.ID DESC LIMIT 1) d + "; + resule = await conn.QueryFirstOrDefaultAsync(sql); + + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + + return resule; + } + } } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 8b585a9..0b6eee3 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -607,5 +607,6 @@ namespace SolarPower.Repository.Interface Task StationStatus(int stationId, int status, string subDB = ""); Task UpdateInvStatus(string siteDB, List codes, List inverterIds = null, byte status = 0); Task> GetInvStatusErr(List codes); + Task Check4table(string code, string dbname); } }