FIC_Solar/solarApp/fmMain.cs
2021-08-05 02:42:34 +08:00

210 lines
7.6 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 ... ";
gv_fic_inv_raw.DataSource = inv_svc.Get_rawInv(dtselect_inv.Value.ToString("yyyy-MM-dd"), lbInverterID.Text);
gv_fic_inv_hour.DataSource = inv_svc.get_Inv_rawAvg(dtselect_inv.Value.ToString("yyyy-MM-dd"), lbInverterID.Text);
gv_web_inv_hour.DataSource = inv_svc.get_web_Inv_hour(dtselect_inv.Value.ToString("yyyy-MM-dd"), 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;
add_inv_list();
}
void add_inv_list() {
//fp_inv
var inv_list = inv_svc.get_Inv_list();
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++;
}
}
void init_GridView() {
// Create an unbound DataGridView by declaring a column count.
//gv_fic_inv_raw.ColumnCount = 6;
//// Set the column header style.
//DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
////columnHeaderStyle.BackColor = Color.Beige;
////columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);
////dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
//// Set the column header names.
//gv_fic_inv_raw.Columns[0].Name = "INVERTERID";
//gv_fic_inv_raw.Columns[1].Name = "reportdate";
//gv_fic_inv_raw.Columns[2].Name = "WH";
//gv_fic_inv_raw.Columns[3].Name = "TODAYKWH";
//gv_fic_inv_raw.Columns[4].Name = "TOTALKWH";
//gv_fic_inv_raw.Columns[5].Name = "PR";
//DataGridViewColumn newCol1 = new DataGridViewColumn(); // add a column to the grid
//DataGridViewCell cell = new DataGridViewCell(); //Specify which type of cell in this column
//newCol.CellTemplate = cell;
for (int i = 0; i < 6; i++)
{
DataGridViewColumn newCol = new DataGridViewColumn(); // add a column to the grid
DataGridViewCell cell = new DataGridViewTextBoxCell(); //Specify which type of cell in this column
newCol.CellTemplate = cell;
switch (i)
{
case 0:
newCol.HeaderText = "INVERTERID";
newCol.Name = "INVERTERID";
newCol.Visible = true;
newCol.Width = 40; break;
case 1:
newCol.HeaderText = "reportdate";
newCol.Name = "reportdate";
newCol.Visible = true;
newCol.Width = 40; break;
case 2:
newCol.HeaderText = "WH";
newCol.Name = "WH";
newCol.Visible = true;
newCol.Width = 40; break;
case 3:
newCol.HeaderText = "TODAYKWH";
newCol.Name = "TODAYKWH";
newCol.Visible = true;
newCol.Width = 40; break;
case 4:
newCol.HeaderText = "TOTALKWH";
newCol.Name = "TOTALKWH";
newCol.Visible = true;
newCol.Width = 40; break;
case 5:
newCol.HeaderText = "PR";
newCol.Name = "PR";
newCol.Visible = true;
newCol.Width = 40; break;
case 6:
newCol.HeaderText = "ct";
newCol.Name = "ct";
newCol.Visible = false;
newCol.Width = 40; break;
}
gv_fic_inv_raw.Columns.Add(newCol);
}
}
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 fmMain_Shown(object sender, EventArgs e)
{
}
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);
gv_fic_station_day.DataSource = stationSvc.get_station_rawAvg(date1, date2);
gv_web_station_hour.DataSource = stationSvc.get_web_station_hour( date1 );
gv_web_station_day.DataSource = stationSvc.get_web_station_day(date1, date2);
lbMsg_station.Text = " done " + System.DateTime.Now.ToShortTimeString();
}
private void dtselect_station_ValueChanged(object sender, EventArgs e)
{
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
private void label12_Click(object sender, EventArgs e)
{
}
}
}