移動天氣更新至 winform

This commit is contained in:
cesar liu 2022-07-14 18:38:39 +08:00
parent 003efa79f6
commit e83c7fe4fa
6 changed files with 224 additions and 16 deletions

View File

@ -1063,6 +1063,11 @@ namespace SolarPower.Models.PowerStation
public string Inv_inveter { get; set; }
public string Station { get; set; }
public string Sensor { get; set; }
public string ctAvg { get; set; }
public string ctInv_site { get; set; }
public string ctInv_inveter { get; set; }
public string ctStation { get; set; }
public string ctSensor { get; set; }
}
}

View File

@ -2126,7 +2126,7 @@ namespace SolarPower.Repository.Implement
{
var sql = $"SELECT * FROM {db_name}.{table_name} WHERE {where}";
result = await conn.QueryFirstOrDefaultAsync<A>(sql);
result = await conn.QueryFirstOrDefaultAsync<A>(sql, commandTimeout: 600);
}
catch (Exception exception)
{
@ -2158,7 +2158,7 @@ namespace SolarPower.Repository.Implement
FROM {table_name} WHERE DATE_FORMAT(FROM_UNIXTIME(timestamp / 1000), '%Y-%m-%d %H') = @DateTime
";
result = await conn.QueryFirstOrDefaultAsync<PowerStationHistory>(sql, new { DateTime = dateTime });
result = await conn.QueryFirstOrDefaultAsync<PowerStationHistory>(sql, new { DateTime = dateTime }, commandTimeout: 600);
}
catch (Exception exception)
{
@ -6147,10 +6147,10 @@ namespace SolarPower.Repository.Implement
{
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
(SELECT count(*) ctAvg, a.SITEID AS Avg FROM {dbname}.s{code}01_sensoravg a ORDER BY a.ID DESC LIMIT 1) a,
(SELECT count(*) ctInv_site, 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 count(*) ctStation, a.SITEID AS Station FROM {dbname}.s{code}01_station a ORDER BY a.ID DESC LIMIT 1) c,
(SELECT count(*) ctSensor, a.SITEID AS Sensor FROM {dbname}.s{code}01_sensor a ORDER BY a.ID DESC LIMIT 1) d
";
resule = await conn.QueryFirstOrDefaultAsync<Check4table>(sql);

View File

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace solarApp.Model
{
class weather_model
{
#region
public class FieldsItem
{
public string Id { get; set; }
public string Type { get; set; }
}
public class Result
{
public string Resource_id { get; set; }
public List<FieldsItem> Fields { get; set; }
}
public class Time
{
public string ObsTime { get; set; }
}
public class WeatherElementItem
{
public string ElementName { get; set; }
public string ElementValue { get; set; }
public List<TimeItem> Time { get; set; }
}
public class Parameter//氣象預報(opendata取資料)
{
public string ParameterName { get; set; }
public string ParameterValue { get; set; }
public string ParameterUnit { get; set; }
}
public class TimeItem//氣象預報(opendata取資料)
{
public string StartTime { get; set; }
public string EndTime { get; set; }
public Parameter Parameter { get; set; }
}
public class ParameterItem
{
public string ParameterName { get; set; }
public string ParameterValue { get; set; }
}
public class LocationItem
{
public string Lat { get; set; }
public string Lon { get; set; }
public string LocationName { get; set; }
public string StationId { get; set; }
public Time Time { get; set; }
public List<WeatherElementItem> WeatherElement { get; set; }
public List<ParameterItem> Parameter { get; set; }
}
public class Records
{
public string DatasetDescription { get; set; }
public List<LocationItem> Location { get; set; }
}
public class Root2 //氣象觀測(主要)(opendata取資料)
{
public string Success { get; set; }
public Result Result { get; set; }
public Records Records { get; set; }
}
#endregion
}
}

View File

@ -35,6 +35,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_archive_One = new System.Windows.Forms.Button();
this.bt_lackStation = new System.Windows.Forms.Button();
this.bt_sensor_lackData = new System.Windows.Forms.Button();
this.bt_updateInstantValue = new System.Windows.Forms.Button();
@ -80,7 +81,8 @@ namespace solarApp
this.tbUserName = new System.Windows.Forms.TextBox();
this.btSendMail = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.bt_archive_One = new System.Windows.Forms.Button();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.button1 = new System.Windows.Forms.Button();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
@ -96,6 +98,7 @@ namespace solarApp
this.splitContainer2.SuspendLayout();
this.panel2.SuspendLayout();
this.gbox.SuspendLayout();
this.tabPage3.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
@ -103,6 +106,7 @@ namespace solarApp
this.tabControl1.Appearance = System.Windows.Forms.TabAppearance.Buttons;
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Controls.Add(this.tabPage3);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
@ -158,6 +162,16 @@ namespace solarApp
this.splitContainer1.SplitterWidth = 10;
this.splitContainer1.TabIndex = 0;
//
// bt_archive_One
//
this.bt_archive_One.Location = new System.Drawing.Point(10, 850);
this.bt_archive_One.Name = "bt_archive_One";
this.bt_archive_One.Size = new System.Drawing.Size(166, 57);
this.bt_archive_One.TabIndex = 16;
this.bt_archive_One.Text = "時間區間/單電站";
this.bt_archive_One.UseVisualStyleBackColor = true;
this.bt_archive_One.Click += new System.EventHandler(this.bt_archive_One_Click);
//
// bt_lackStation
//
this.bt_lackStation.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
@ -645,15 +659,26 @@ namespace solarApp
this.btSendMail.UseVisualStyleBackColor = true;
this.btSendMail.Click += new System.EventHandler(this.btSendMail_Click);
//
// bt_archive_One
// tabPage3
//
this.bt_archive_One.Location = new System.Drawing.Point(10, 850);
this.bt_archive_One.Name = "bt_archive_One";
this.bt_archive_One.Size = new System.Drawing.Size(166, 57);
this.bt_archive_One.TabIndex = 16;
this.bt_archive_One.Text = "時間區間/單電站";
this.bt_archive_One.UseVisualStyleBackColor = true;
this.bt_archive_One.Click += new System.EventHandler(this.bt_archive_One_Click);
this.tabPage3.Controls.Add(this.button1);
this.tabPage3.Location = new System.Drawing.Point(4, 31);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
this.tabPage3.Size = new System.Drawing.Size(1774, 918);
this.tabPage3.TabIndex = 2;
this.tabPage3.Text = "tabPage3";
this.tabPage3.UseVisualStyleBackColor = true;
//
// button1
//
this.button1.Location = new System.Drawing.Point(99, 41);
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_1);
//
// fmArchive
//
@ -683,6 +708,7 @@ namespace solarApp
this.panel2.PerformLayout();
this.gbox.ResumeLayout(false);
this.gbox.PerformLayout();
this.tabPage3.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -739,5 +765,7 @@ namespace solarApp
private System.Windows.Forms.TextBox tbReceiver;
private System.Windows.Forms.Label lbMsgTitle;
private System.Windows.Forms.Button bt_archive_One;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.Button button1;
}
}

View File

@ -8,6 +8,7 @@ using System.Net.Mail;
using System.Text;
using System.Windows.Forms;
using solarApp.Service;
using solarApp.Model;
namespace solarApp
{
@ -637,5 +638,101 @@ namespace solarApp
richTextBox1.AppendText(Environment.NewLine + System.DateTime.Now.ToShortTimeString() + " " + result.ToString());
}
}
private void button1_Click_1(object sender, EventArgs e)
{
//#region 氣象觀測(取資料)
//try
//{
// logger.LogInformation("【CalcPowerStationJob】【開始取得氣象觀測】");
// var client = new HttpClient();
// var UVUri = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/O-A0003-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&elementName=TIME,TEMP";
// System.Net.Http.HttpResponseMessage response = client.GetAsync(UVUri).Result;
// String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString();
// observation = JsonConvert.DeserializeObject<Root2>(jsonUVs);
// logger.LogInformation("【CalcPowerStationJob】【取得成功氣象觀測】");
//}
//catch (Exception ex)
//{
// //logger.LogError("【CalcPowerStationJob】【取得失敗氣象觀測】");
// //logger.LogError("【{0}】{1}", "CalcPowerStationJob", ex.Message);
// observation = null;
//}
//#endregion
//foreach (var powerStation in powerStations)
//{
// #region 確認是否有觀測站(沒有則新增)
// try
// {
// if (powerStation.WeathersStationId == null)
// {
// var weatherStationId = "";
// double shortLocation = 9999;
// foreach (var Location in observation.Records.Location)
// {
// if (powerStation.Coordinate != null)
// {
// var powerLocation = powerStation.Coordinate.Split(',');
// double p1 = Convert.ToDouble(powerLocation[0]);
// double p2 = Convert.ToDouble(powerLocation[1]);
// double dLat = Convert.ToDouble(Location.Lat);
// double dLon = Convert.ToDouble(Location.Lon);
// double x = Math.Pow(p1 - dLat, 2);
// double y = Math.Pow(p2 - dLon, 2);
// var nowLocation = Math.Sqrt(x + y);
// //var nowLocation = Math.Sqrt(Math.Pow(Convert.ToDouble(powerLocation[0])
// // - Convert.ToDouble(Location.Lat), 2)
// // + Math.Pow(Convert.ToDouble(powerLocation[1])
// // - Convert.ToDouble(Location.Lon), 2)
// // );
// if (nowLocation < shortLocation)
// {
// shortLocation = nowLocation;
// weatherStationId = Location.StationId;
// calcPowerStation.TodayWeatherTemp = Convert.ToDouble(Location.WeatherElement[0].ElementValue);
// }
// }
// }
// calcPowerStation.WeathersStationId = weatherStationId;
// }
// WeatherObservation weatherObservation = new WeatherObservation();
// if (powerStation.WeathersStationId != null && observation != null)
// {
// foreach (var Location in observation.Records.Location)
// {
// if (Location.StationId == powerStation.WeathersStationId)
// {
// calcPowerStation.TodayWeatherTemp = Convert.ToDouble(Location.WeatherElement[0].ElementValue);
// weatherObservation.PowerStationId = powerStation.Id;
// weatherObservation.Temp = Convert.ToDouble(Location.WeatherElement[0].ElementValue);
// weatherObservation.ObsTime = !string.IsNullOrEmpty(Location.Time.ObsTime) ? Convert.ToInt32(Location.Time.ObsTime.Substring(0, 4)) >= 1971 ? Location.Time.ObsTime : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
// calcPowerStation.WeathersStationId = powerStation.WeathersStationId;
// break;
// }
// }
// weatherObservations.Add(weatherObservation);
// }
// logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的天氣預報的資訊】", powerStation.Code, dateTime);
// var weather = await powerStationRepository.SelectNowWeather(powerStation.CityId);
// logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的天氣預報的資訊】", powerStation.Code, dateTime);
// if (weather != null)
// {
// calcPowerStation.TodayWeather = weather.WeatherKey;
// calcPowerStation.RateOfRain = weather.PoP;
// }
// }
// catch (Exception ex)
// {
// logger.LogError("【CalcPowerStationJob】【取得失敗電站[{0}]在{1}的天氣預報的資訊】", powerStation.Code, dateTime);
// logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message);
// }
// #endregion
//}
}
}
}

View File

@ -8,7 +8,6 @@
<ItemGroup>
<EmbeddedResource Remove="fmExcel.resx" />
<EmbeddedResource Remove="fmMain.resx" />
<EmbeddedResource Remove="fmTest.resx" />
</ItemGroup>