314 lines
13 KiB
C#
314 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using solarApp.Service;
|
|
|
|
namespace solarApp
|
|
{
|
|
public partial class fmArchive : Form
|
|
{
|
|
getStationSvc stationSvc = new getStationSvc();
|
|
public fmArchive()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void bt_inv_proc_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void bt_Sensor_Click(object sender, EventArgs e)
|
|
{
|
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
|
//procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1);
|
|
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
|
//procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1);
|
|
procSensorSvc sensorSvc = new procSensorSvc();
|
|
//invSvc._siteDB = lbSiteDB_sensor.Text;
|
|
//invSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9);
|
|
//invSvc._siteID01 = lbSiteID_sensor.Text;
|
|
//invSvc._date1 = date1;
|
|
//invSvc._date2 = date1;
|
|
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
|
|
{
|
|
//string d1 = day.ToString("yyyy-MM-dd");
|
|
sensorSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
|
}
|
|
//sensorSvc._siteDB = lbSiteDB_sensor.Text;
|
|
//sensorSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9);
|
|
//sensorSvc._siteID01 = lbSiteID_sensor.Text;
|
|
//sensorSvc._date1 = date1;
|
|
//sensorSvc._date2 = date1;
|
|
|
|
//sensorSvc.archiveData();
|
|
MessageBox.Show("OK");
|
|
}
|
|
|
|
private void fmArchive_Load(object sender, EventArgs e)
|
|
{
|
|
#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, 12);
|
|
rb.AutoSize = true;
|
|
rb.CheckedChanged += new EventHandler(rb_site_CheckedChanged);
|
|
fp_site.Controls.Add(rb);
|
|
if (i == 0) rb.Checked = true;
|
|
i++;
|
|
}
|
|
#endregion
|
|
// dtselect_station1.Value = DateTime.Today.AddDays(-1);
|
|
dtSelect1.Value = System.DateTime.Today.AddDays(-1);
|
|
dtSelect2.Value = System.DateTime.Today.AddDays(-1);
|
|
}
|
|
|
|
private void rb_site_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
RadioButton rb = sender as RadioButton;
|
|
if (rb.Checked)
|
|
{
|
|
lbSiteName_sensor.Text = rb.Text;
|
|
lbSiteDB_sensor.Text = rb.Tag.ToString();
|
|
lbSiteID_sensor.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";
|
|
//lbSensorRaw.Text = lbSiteName_inv.Text + " " + lbSiteDB_inv.Text + ".s" + lbSiteID_inv.Text + "_SensorAVG";
|
|
|
|
//add_inv_list(lbSiteDB_inv.Text, lbSiteID_inv.Text.Substring(0, 9));
|
|
}
|
|
}
|
|
|
|
private void btVerifyData_Click(object sender, EventArgs e)
|
|
{
|
|
fmMain fm = new fmMain();
|
|
fm.Show();
|
|
}
|
|
|
|
public IEnumerable<DateTime> EachDay(DateTime from, DateTime thru)
|
|
{
|
|
for (var day = from.Date; day.Date <= thru.Date; day = day.AddDays(1))
|
|
yield return day;
|
|
}
|
|
|
|
|
|
private void bt_Inv_Click(object sender, EventArgs e)
|
|
{
|
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
|
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
|
//procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1);
|
|
procInvSvc invSvc = new procInvSvc();
|
|
//invSvc._siteDB = lbSiteDB_sensor.Text;
|
|
//invSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9);
|
|
//invSvc._siteID01 = lbSiteID_sensor.Text;
|
|
//invSvc._date1 = date1;
|
|
//invSvc._date2 = date1;
|
|
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
|
|
{
|
|
//string d1 = day.ToString("yyyy-MM-dd");
|
|
invSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
|
}
|
|
//sensorSvc.archiveData();
|
|
MessageBox.Show("OK");
|
|
}
|
|
|
|
private void dtSelect_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
bt_clear_inv.Enabled = true;
|
|
bt_clear_station.Enabled = true;
|
|
bt_clear_sensor.Enabled = true;
|
|
bt_clear_inv.Text = "clear " + dtSelect1.Value.ToString("MM-dd");
|
|
bt_clear_station.Text = "clear " + dtSelect1.Value.ToString("MM-dd");
|
|
bt_clear_sensor.Text = "clear " + dtSelect1.Value.ToString("MM-dd");
|
|
}
|
|
|
|
private void bt_clear_inv_Click(object sender, EventArgs e)
|
|
{
|
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
|
//procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1);
|
|
procInvSvc invSvc = new procInvSvc();
|
|
invSvc._siteDB = lbSiteDB_sensor.Text;
|
|
invSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9);
|
|
invSvc._siteID01 = lbSiteID_sensor.Text;
|
|
invSvc._date1 = date1;
|
|
//invSvc._date2 = date1;
|
|
invSvc.clearData();
|
|
//sensorSvc.archiveData();
|
|
MessageBox.Show("OK");
|
|
}
|
|
|
|
private void bt_clear_station_Click(object sender, EventArgs e)
|
|
{
|
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
|
//procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1);
|
|
procStationSvc siteSvc = new procStationSvc();
|
|
siteSvc._siteDB = lbSiteDB_sensor.Text;
|
|
siteSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9);
|
|
siteSvc._siteID01 = lbSiteID_sensor.Text;
|
|
siteSvc._date1 = date1;
|
|
//siteSvc._date2 = date1;
|
|
siteSvc.clearData();
|
|
//sensorSvc.archiveData();
|
|
MessageBox.Show("OK");
|
|
}
|
|
|
|
private void bt_site_Click(object sender, EventArgs e)
|
|
{
|
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
|
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
|
//procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1);
|
|
procStationSvc siteSvc = new procStationSvc();
|
|
//invSvc._siteDB = lbSiteDB_sensor.Text;
|
|
//invSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9);
|
|
//invSvc._siteID01 = lbSiteID_sensor.Text;
|
|
//invSvc._date1 = date1;
|
|
//invSvc._date2 = date1;
|
|
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
|
|
{
|
|
//string d1 = day.ToString("yyyy-MM-dd");
|
|
siteSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
|
}
|
|
//sensorSvc.archiveData();
|
|
MessageBox.Show("OK");
|
|
}
|
|
|
|
private void bt_archive_Click(object sender, EventArgs e)
|
|
{
|
|
bt_Sensor.PerformClick();
|
|
bt_Inv.PerformClick();
|
|
bt_site.PerformClick();
|
|
}
|
|
|
|
private void bt_clear_sensor_Click(object sender, EventArgs e)
|
|
{
|
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
|
//procSensorSvc sensorSvc = new procSensorSvc(lbSiteDB_sensor.Text, lbSiteID_sensor.Text, date1, date1);
|
|
procSensorSvc sensorSvc = new procSensorSvc();
|
|
sensorSvc._siteDB = lbSiteDB_sensor.Text;
|
|
sensorSvc._siteID = lbSiteID_sensor.Text.Substring(0, 9);
|
|
sensorSvc._siteID01 = lbSiteID_sensor.Text;
|
|
sensorSvc._date1 = date1;
|
|
//sensorSvc._date2 = date1;
|
|
sensorSvc.clearData();
|
|
//sensorSvc.archiveData();
|
|
MessageBox.Show("OK");
|
|
}
|
|
|
|
private void lbSiteDB_sensor_Click(object sender, EventArgs e)
|
|
{
|
|
fmExcel fm = new fmExcel();
|
|
fm.Show();
|
|
|
|
}
|
|
|
|
private void bt_meter_Click(object sender, EventArgs e)
|
|
{
|
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
|
procSensorSvc sensorSvc = new procSensorSvc();
|
|
|
|
sensorSvc.archiveMeterData(lbSiteID_sensor.Text.Substring(0, 9), date1);
|
|
MessageBox.Show("OK");
|
|
}
|
|
|
|
private void bt_rpt_invDay_Click(object sender, EventArgs e)
|
|
{
|
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
|
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
|
procInvSvc invSvc = new procInvSvc();
|
|
|
|
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
|
|
{
|
|
invSvc.report_invDay(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
|
}
|
|
|
|
MessageBox.Show("OK");
|
|
}
|
|
|
|
private void bt_invDay_Click(object sender, EventArgs e)
|
|
{
|
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
|
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
|
get_inv_svc invSvc = new get_inv_svc();
|
|
var ds = invSvc.get_ck_invDay_list(date1, date2);
|
|
gv_rpt_invDay.DataSource = ds;
|
|
gv_rpt_invDay.Columns[0].Width = 60;
|
|
gv_rpt_invDay.Columns[1].Width = 70;
|
|
gv_rpt_invDay.Columns[2].Width = 80;
|
|
gv_rpt_invDay.Columns[3].Width = 90;
|
|
gv_rpt_invDay.Columns[4].Width = 90;
|
|
gv_rpt_invDay.Columns[5].Width = 90;
|
|
gv_rpt_invDay.Columns[6].Width = 90;
|
|
gv_rpt_invDay.Columns[7].Width = 90;
|
|
|
|
}
|
|
|
|
private void gv_rpt_invDay_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
|
{
|
|
if (gv_rpt_invDay.Rows[e.RowIndex].Cells["CsubstrctionB"].Value != null && !string.IsNullOrWhiteSpace(gv_rpt_invDay.Rows[e.RowIndex].Cells["CsubstrctionB"].Value.ToString()))
|
|
{
|
|
if (gv_rpt_invDay.Rows[e.RowIndex].Cells["CsubstrctionB"].Value.ToString() != "0")
|
|
{
|
|
gv_rpt_invDay.Rows[e.RowIndex].Cells["CsubstrctionB"].Style = new DataGridViewCellStyle { ForeColor = Color.Red, BackColor = Color.White };
|
|
}
|
|
}
|
|
}
|
|
|
|
private void gv_rpt_invDay_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
|
|
{
|
|
string powerStationID = gv_rpt_invDay.Rows[e.RowIndex].Cells[0].Value.ToString();
|
|
// MessageBox.Show(powerStationID);
|
|
|
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
|
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
|
get_inv_svc invSvc = new get_inv_svc();
|
|
var ds = invSvc.get_ck_invDay_detail1( powerStationID, date1, date2);
|
|
gv_inv_detail.DataSource = ds;
|
|
gv_inv_detail.Columns[0].Width = 60;
|
|
gv_inv_detail.Columns[1].Width = 160; //invID
|
|
gv_inv_detail.Columns[2].Width = 80;
|
|
gv_inv_detail.Columns[3].Width = 90;
|
|
|
|
//switch (e.ColumnIndex)
|
|
//{
|
|
// case 0:
|
|
// MessageBox.Show("这是第零列得");
|
|
// break;
|
|
// default:
|
|
// break;
|
|
//}
|
|
}
|
|
|
|
private void gv_inv_detail_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (gv_inv_detail.Columns.Count == 5) return;
|
|
|
|
string inverterID = gv_inv_detail.Rows[e.RowIndex].Cells[1].Value.ToString();
|
|
//MessageBox.Show(inverterID);
|
|
|
|
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
|
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
|
get_inv_svc invSvc = new get_inv_svc();
|
|
var ds = invSvc.get_ck_invDay_detail2(inverterID, date1, date2);
|
|
gv_inv_detail.DataSource = ds;
|
|
gv_inv_detail.Columns[0].Width = 60;
|
|
gv_inv_detail.Columns[1].Width = 150;
|
|
gv_inv_detail.Columns[2].Width = 80;
|
|
gv_inv_detail.Columns[3].Width = 100;
|
|
gv_inv_detail.Columns[4].Width = 80;
|
|
gv_inv_detail.Columns[5].Width = 80;
|
|
}
|
|
}
|
|
}
|