FIC_Solar/solarApp/fmMain.cs
2021-08-06 11:04:32 +08:00

174 lines
6.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using solarApp.Service;
namespace solarApp
{
public partial class fmMain : Form
{
get_inv_svc inv_svc = new get_inv_svc();
getStationSvc stationSvc = new getStationSvc();
public fmMain()
{
InitializeComponent();
// init_GridView();
}
private async void button1_Click(object sender, EventArgs e)
{
lbMsg_inv.Text = "loading ... ";
string date1 = dtselect_inv.Value.ToString("yyyy-MM-dd");
gv_fic_inv_raw.DataSource = inv_svc.Get_rawInv(date1, lbInverterID.Text, lbSiteDB_inv.Text, lbSiteID_inv.Text);
gv_fic_inv_hour.DataSource = inv_svc.get_Inv_rawAvg(date1, lbInverterID.Text, lbSiteDB_inv.Text, lbSiteID_inv.Text);
gv_web_inv_hour.DataSource = inv_svc.get_web_Inv_hour(date1, lbInverterID.Text);
gv_web_inv_day.DataSource = inv_svc.get_web_Inv_day(date1, lbInverterID.Text);
gv_web_inv_month.DataSource = inv_svc.get_web_Inv_month( date1.Substring(0, 7), lbInverterID.Text);
lbMsg_inv.Text = " done " + System.DateTime.Now.ToShortTimeString();
}
private void fmMain_Load(object sender, EventArgs e)
{
dtselect_station1.Value = DateTime.Today.AddDays(-7);
dtselect_station2.Value = DateTime.Today.AddDays(-1);
dtselect_inv.Value = DateTime.Today.AddDays(-1);
// Cursor.Current = Cursors.Default;
tabControl1.SelectedTab = tabControl1.TabPages[1];
#region
int i = 0;
var site_list = stationSvc.get_station_list();
foreach (var item in site_list)
{
RadioButton rb = new RadioButton();
rb.Name = item.SiteID;
rb.Text = item.SiteName;
rb.Tag = item.SiteDB;
rb.Font = new Font(Font.FontFamily, 22);
rb.AutoSize = true;
rb.CheckedChanged += new EventHandler(rb_site_CheckedChanged);
fp_site.Controls.Add(rb);
if (i == 0) rb.Checked = true;
i++;
}
#endregion
#region list
//add_inv_list();
#endregion
}
private void rb_site_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb.Checked)
{
lbSiteDB_inv.Text = rb.Tag.ToString();
lbSiteName_inv.Text = rb.Text;
lbSiteID_inv.Text = rb.Name;
//顯示 table name on label
lbSiteRaw.Text = lbSiteName_inv.Text + " "+ lbSiteDB_inv.Text + ".s" + lbSiteID_inv.Text + "_Station";
lbInvRaw.Text = lbSiteName_inv.Text + " " + lbSiteDB_inv.Text + ".s" + lbSiteID_inv.Text + "_Inv";
add_inv_list(lbSiteDB_inv.Text, lbSiteID_inv.Text.Substring(0, 9));
}
}
/// <summary>
/// 顯示 Inventer 提供選擇
/// </summary>
/// <param name="siteDB"></param>
/// <param name="siteID"></param>
void add_inv_list(string siteDB, string siteID) {
fp_inv.Controls.Clear();
var inv_list = inv_svc.get_Inv_list(siteDB, siteID);
int i = 0;
foreach (var item in inv_list)
{
RadioButton rb = new RadioButton();
rb.Name = "rb" + item.inverterid;
rb.Text = item.inverterid;
//rb.Dock = DockStyle.Top;
rb.Width = 200;
rb.CheckedChanged += radio_inv_click;
if (i == 0) rb.Checked = true; //預設第一個勾選
fp_inv.Controls.Add(rb);
i++;
}
}
private void radio_inv_click(object sender, EventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb.Checked)
{
lbInverterID.Text = rb.Text;
lbMsg_inv.Text = "...";
}
}
private void gv_fic_inv_hour_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
//int rowindex = e.RowIndex; e.ColumnIndex
if (gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Value != null && !string.IsNullOrWhiteSpace(gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Value.ToString()))
{
if (gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Value.ToString() != "12")
{
gv_fic_inv_hour.Rows[e.RowIndex].Cells["count"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White };
}
}
//else
//{
// gv_fic_inv_hour.Rows[e.RowIndex].Cells[e.ColumnIndex].Style = gv_fic_inv_hour.DefaultCellStyle;
//}
}
private void dtselect_ValueChanged(object sender, EventArgs e)
{
lbMsg_inv.Text = "...";
}
/// <summary>
/// 電站
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void bt_find_station_Click(object sender, EventArgs e)
{
lbMsg_station.Text = "loading ... ";
string date1 = dtselect_station1.Value.ToString("yyyy-MM-dd");
string date2 = dtselect_station2.Value.ToString("yyyy-MM-dd");
gv_fic_station_raw.DataSource = stationSvc.get_station_raw(date1, lbSiteDB_inv.Text, lbSiteID_inv.Text);
gv_fic_station_day.DataSource = stationSvc.get_station_rawAvg(date1, date2, lbSiteDB_inv.Text, lbSiteID_inv.Text);
gv_web_station_hour.DataSource = stationSvc.get_web_station_hour( date1 );
gv_web_station_day.DataSource = stationSvc.get_web_station_day(date1, date2);
gv_web_station_month.DataSource = stationSvc.get_web_station_month(date1.Substring(0, 7), date2.Substring(0, 7));
lbMsg_station.Text = " done " + System.DateTime.Now.ToShortTimeString();
}
}
}