From 9ced5c70abc6fc67d2bd17df499285c3a55000e5 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Tue, 18 Jan 2022 18:28:59 +0800 Subject: [PATCH] =?UTF-8?q?debug=20Inv=20=E6=AD=B8=E6=AA=94=E8=B6=85?= =?UTF-8?q?=E6=99=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Program.cs | 2 + solarApp/Service/procInvSvc.cs | 104 ++++++++++++++++++++++++--------- solarApp/fmTest.Designer.cs | 73 +++++++++++++++++++++++ solarApp/fmTest.cs | 49 ++++++++++++++++ solarApp/fmTest.resx | 60 +++++++++++++++++++ 5 files changed, 262 insertions(+), 26 deletions(-) create mode 100644 solarApp/fmTest.Designer.cs create mode 100644 solarApp/fmTest.cs create mode 100644 solarApp/fmTest.resx diff --git a/solarApp/Program.cs b/solarApp/Program.cs index 4533ef9..000fd3c 100644 --- a/solarApp/Program.cs +++ b/solarApp/Program.cs @@ -28,6 +28,8 @@ namespace solarApp Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new fmExcel()); Application.Run(new fmArchive()); + + //Application.Run(new fmTest()); //Application.Run(new fmMain()); Log.CloseAndFlush(); diff --git a/solarApp/Service/procInvSvc.cs b/solarApp/Service/procInvSvc.cs index 169400c..c3241f2 100644 --- a/solarApp/Service/procInvSvc.cs +++ b/solarApp/Service/procInvSvc.cs @@ -191,7 +191,14 @@ namespace solarApp.Service WHERE left(crdTime, 10) = @date1; # 2. add index ALTER TABLE del_Inv_day_" + _powerStationID + @"_s1 ADD INDEX `temp_index` (crdTime, inverterid);"; - int ct = conn.Execute(sql, new { date1 = _date1 }); + //int ct = conn.Execute(sql, new { date1 = _date1 }); + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + cmd.CommandTimeout = 180; + cmd.Parameters.AddWithValue("@date1", _date1); + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); + cmd.Parameters.Clear(); sql = @" INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP) @@ -253,9 +260,15 @@ namespace solarApp.Service - var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); + //var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); + cmd.Parameters.AddWithValue("@date1", _date1); + cmd.Parameters.AddWithValue("@PowerStationID", _powerStationID); + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); + cmd.Parameters.Clear(); + cmd.Dispose(); - if (_logger != null) + if (_logger != null) _logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器15min補償", _siteID, _date1); } catch (Exception ex) @@ -349,12 +362,19 @@ namespace solarApp.Service from sensor_history_hour where powerstationID = " + _powerStationID + @" and DATE_FORMAT(`TIMESTAMP`, '%Y-%m-%d') = @date1 )irr on a.reportDate = irr.reportDate; "; - int ct = conn.Execute(sql, new { date1 = _date1 }); + //int ct = conn.Execute(sql, new { date1 = _date1 }); + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + cmd.CommandTimeout = 180; + cmd.Parameters.AddWithValue("@date1", _date1); + cmd.Parameters.AddWithValue("@PowerStationID", _powerStationID); + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); + cmd.Parameters.Clear(); - - //# 3. insert ans - sql = @$" + //# 3. insert ans + sql = @$" INSERT INTO solar_master.inverter_history_hour(`powerStationID`, `INVERTERID`, `TIMESTAMP`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `KWH`, `TODAYKWH`, `TOTALKWH`, `Irradiance`, `PR`, `DCKW`, `ACKW`, `KWHKWP`) select `powerStationID`, a.`INVERTERID`, a.`reportDate`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `KWH`, `TODAYKWH`, `TOTALKWH`, `irr`, inv_pr.`PR`, `DCKW`, `ACKW`, `KWHKWP` from Inv_day_" + _powerStationID + @"_s2 a left JOIN( -- 取得整點值PR @@ -364,13 +384,17 @@ namespace solarApp.Service GROUP BY left(crdTime, 13), inv.INVERTERID ) inv_pr ON a.reportDate = inv_pr.reportDate AND a.INVERTERID = inv_pr.INVERTERID;"; - ct = conn.Execute(sql, new { date1 = _date1 }); - if (_logger != null) + //ct = conn.Execute(sql, new { date1 = _date1 }); + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); + if (_logger != null) _logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器hour補償", _siteID, _date1); ss = @$"DROP TABLE IF EXISTS del_Inv_day_" + _powerStationID + @"_s1; "; - conn.Execute(ss); - } + //conn.Execute(ss); + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); + } catch (Exception ex) { @@ -423,9 +447,18 @@ namespace solarApp.Service from sensor_history_day a where powerstationID = @powerstationID and DATE_FORMAT(a.TIMESTAMP, '%Y-%m-%d') = @date1 and Irradiance <> 0 limit 1 )irr on a.reportDate = irr.reportDate ;"; - conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); + // conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + cmd.CommandTimeout = 180; + cmd.Parameters.AddWithValue("@date1", _date1); + cmd.Parameters.AddWithValue("@PowerStationID", _powerStationID); + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); + cmd.Parameters.Clear(); + cmd.Dispose(); - if (_logger != null) + if (_logger != null) _logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器day補償", _siteID, _date1); } catch (Exception ex) @@ -478,9 +511,17 @@ namespace solarApp.Service from sensor_history_month a where powerstationID = @powerstationID and DATE_FORMAT(a.TIMESTAMP, '%Y-%m') = @date1 and Irradiance <> 0 )irr on a.reportDate = irr.reportDate ;"; - conn.Execute(sql, new { date1 = _date1.Substring(0, 7), PowerStationID = _powerStationID }); + //conn.Execute(sql, new { date1 = _date1.Substring(0, 7), PowerStationID = _powerStationID }); + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + cmd.CommandTimeout = 180; + cmd.Parameters.AddWithValue("@date1", _date1.Substring(0, 7)); + cmd.Parameters.AddWithValue("@PowerStationID", _powerStationID); + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); + cmd.Parameters.Clear(); - if (_logger != null) + if (_logger != null) { _logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器month補償", _siteID, _date1); } @@ -522,10 +563,9 @@ namespace solarApp.Service using (MySqlConnection conn = new MySqlConnection(Connection1)) { conn.Open(); - string ss = @$"delete from report_invday where powerstationid = {_powerStationID} and left(report_date, 10) = '{_date1}'"; - conn.Execute(ss); - - string sql = string.Empty; + string sql = @$"delete from report_invday where powerstationid = {_powerStationID} and left(report_date, 10) = '{_date1}'"; + conn.Execute(sql); + #region get SQL try { @@ -535,7 +575,7 @@ namespace solarApp.Service } #region 建立 temp table - ss = @$"DROP TABLE IF EXISTS temp_invDay{_powerStationID}_s1; + sql = @$"DROP TABLE IF EXISTS temp_invDay{_powerStationID}_s1; CREATE TABLE temp_invDay{_powerStationID}_s1 select a.`TIMESTAMP` report_date, a.powerstationId, a.INVERTERID, a.kwh , round(TODAYKWH, 6) TODAYKWH, round(KWHKWP, 6) KWHKWP, round(PR, 6) PR @@ -543,7 +583,12 @@ CREATE TABLE temp_invDay{_powerStationID}_s1 WHERE powerstationid = {_powerStationID} and crdDate = '{_date1}'; # 2. add index ALTER TABLE `temp_invDay{_powerStationID}_s1` ADD INDEX `temp_indexs1` (report_date, inverterid);"; - conn.Execute(ss); + //conn.Execute(ss); + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + cmd.CommandTimeout = 180; + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); #endregion #region 先新增 inv_no01 @@ -571,8 +616,10 @@ from temp_invDay{_powerStationID}_s1 a join ) d on a.powerStationid = d.powerStationid and a.`report_date` = d.report_date where a.inverterid = '{inv01}' # right(a.inverterid, 4) = '0001' GROUP BY left(a.report_date, 13) - order by a.report_date ;"; - conn.Execute(sql); + order by a.report_date ;"; + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); + // conn.Execute(sql); #endregion #region inv_02 之後的 kwh @@ -628,10 +675,15 @@ set a.inv_02 = b.inv_02 "); #region insert report_invDay sb_column.Clear(); sql = sb.ToString() + sb_select.ToString() + sb_update_columns.ToString(); - conn.Execute(sql); + + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); + //conn.Execute(sql); - ss = @$"DROP TABLE IF EXISTS temp_invDay{_powerStationID}_s1; "; - conn.Execute(ss); + sql = @$"DROP TABLE IF EXISTS temp_invDay{_powerStationID}_s1; "; + //conn.Execute(ss); + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); #endregion if (_logger != null) diff --git a/solarApp/fmTest.Designer.cs b/solarApp/fmTest.Designer.cs new file mode 100644 index 0000000..52d1969 --- /dev/null +++ b/solarApp/fmTest.Designer.cs @@ -0,0 +1,73 @@ + +namespace solarApp +{ + partial class fmTest + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(53, 75); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(94, 29); + this.button1.TabIndex = 0; + this.button1.Text = "button1"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // richTextBox1 + // + this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Right; + this.richTextBox1.Location = new System.Drawing.Point(313, 0); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.Size = new System.Drawing.Size(701, 643); + this.richTextBox1.TabIndex = 1; + this.richTextBox1.Text = ""; + // + // fmTest + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 19F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1014, 643); + this.Controls.Add(this.richTextBox1); + this.Controls.Add(this.button1); + this.Name = "fmTest"; + this.Text = "fmTest"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.RichTextBox richTextBox1; + } +} \ No newline at end of file diff --git a/solarApp/fmTest.cs b/solarApp/fmTest.cs new file mode 100644 index 0000000..0dba28f --- /dev/null +++ b/solarApp/fmTest.cs @@ -0,0 +1,49 @@ +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace solarApp +{ + public partial class fmTest : Form + { + public fmTest() + { + InitializeComponent(); + } + + private void button1_Click(object sender, EventArgs e) + { + IsProgramInstalled("") ; + } + + public bool IsProgramInstalled(string programDisplayName) + { + + Console.WriteLine(string.Format("Checking install status of: {0}", programDisplayName)); + foreach (var item in Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall").GetSubKeyNames()) + { + + object programName = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + item).GetValue("DisplayName"); + + //Console.WriteLine(programName); + //if (!string.IsNullOrEmpty(programName.ToString())) + if (!(programName == null)) + { + richTextBox1.AppendText(programName.ToString() + Environment.NewLine); + if (string.Equals(programName, programDisplayName)) + { + Console.WriteLine("Install status: INSTALLED"); + return true; + } + } + } + Console.WriteLine("Install status: NOT INSTALLED"); + return false; + } + } +} diff --git a/solarApp/fmTest.resx b/solarApp/fmTest.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/solarApp/fmTest.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file