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(); getSensorSvc sensorSvc = new getSensorSvc(); 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); dtSelect_sensor1.Value = DateTime.Today.AddDays(-7); dtSelect_sensor2.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; lbSiteName_sensor.Text = lbSiteName_inv.Text; lbSiteDB_sensor.Text = lbSiteDB_inv.Text; lbSiteID_sensor.Text = lbSiteID_inv.Text; //顯示 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)); } } /// /// 顯示 Inventer 提供選擇 /// /// /// 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 = "..."; } /// /// 電站 /// /// /// 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, lbSiteID_inv.Text.Substring(0, 9)); gv_web_station_month.DataSource = stationSvc.get_web_station_month(date1.Substring(0, 7), date2.Substring(0, 7), lbSiteID_inv.Text.Substring(0, 9)); lbMsg_station.Text = " done " + System.DateTime.Now.ToShortTimeString(); } private void btSearch_sensor_Click(object sender, EventArgs e) { string date1 = dtSelect_sensor1.Value.ToString("yyyy-MM-dd"); string date2 = dtSelect_sensor2.Value.ToString("yyyy-MM-dd"); gv_fic_sensor_raw.DataSource = sensorSvc.get_sensor_raw(date1, lbSiteDB_inv.Text, lbSiteID_inv.Text); gv_fic_sensor_hour.DataSource = sensorSvc.get_sensor_raw_hour(date1, lbSiteDB_inv.Text, lbSiteID_inv.Text.Substring(0, 11)); gv_web_sensor_hour.DataSource = sensorSvc.get_web_sensor_hour(date1, lbSiteID_inv.Text.Substring(0, 09)); gv_web_sensor_day.DataSource = sensorSvc.get_web_sensor_day(date1, date2, lbSiteID_inv.Text.Substring(0, 09)); gv_web_sensor_month.DataSource = sensorSvc.get_web_sensor_month(date1.Substring(0, 7), date2.Substring(0, 7), lbSiteID_inv.Text.Substring(0, 09)); } } }