using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; using DevExpress.XtraCharts; using Nevron.Chart; using Nevron.Chart.Windows; using Nevron.GraphicsCore; namespace WindowsFormsApplication16 { public partial class Form1 : Form { float env1Sen3, env1Sen2, env1Sen5, env1Sen1, env1Sen4; float env2Sen3, env2Sen2, env2Sen5, env2Sen1, env2Sen4; float env3Sen3, env3Sen2, env3Sen5, env3Sen1, env3Sen4; float env4Sen3, env4Sen2, env4Sen5, env4Sen1, env4Sen4; float env5Sen3, env5Sen2, env5Sen5, env5Sen1, env5Sen4; float env6Sen3, env6Sen2, env6Sen5, env6Sen1, env6Sen4; float env7Sen3, env7Sen2, env7Sen5, env7Sen1, env7Sen4; float env8Sen3, env8Sen2, env8Sen5, env8Sen1, env8Sen4; float env9Sen3, env9Sen2, env9Sen5, env9Sen1, env9Sen4; // float Sen3, Sen2, Sen5, Sen1, Sen4; string env1Sen3Value, env1Sen2Value, env1Sen1Value, env1Sen4Value, env1Sen5Value; string env2Sen3Value, env2Sen2Value, env2Sen1Value, env2Sen4Value, env2Sen5Value; string env3Sen3Value, env3Sen2Value, env3Sen1Value, env3Sen4Value, env3Sen5Value; string env4Sen3Value, env4Sen2Value, env4Sen1Value, env4Sen4Value, env4Sen5Value; string env5Sen3Value, env5Sen2Value, env5Sen1Value, env5Sen4Value, env5Sen5Value; string env6Sen3Value, env6Sen2Value, env6Sen1Value, env6Sen4Value, env6Sen5Value; string env7Sen3Value, env7Sen2Value, env7Sen1Value, env7Sen4Value, env7Sen5Value; string env8Sen3Value, env8Sen2Value, env8Sen1Value, env8Sen4Value, env8Sen5Value; string env9Sen3Value, env9Sen2Value, env9Sen1Value, env9Sen4Value, env9Sen5Value; //string Sen3Value, Sen2Value, Sen1Value, Sen4Value, Sen5Value; byte Timer1Count = 1, n; //68, string myConnectionString = "server=localhost;database=test1;uid=root;pwd=;"; string myConnectionString1 = "server=192.168.0.200;database=env1;uid=Admin1Env;pwd=AdminEnv1;"; string myConnectionString2 = "server=192.168.0.200;database=env2;uid=Admin2Env;pwd=AdminEnv2;"; string myConnectionString3 = "server=192.168.0.200;database=env3;uid=Admin3Env;pwd=AdminEnv3;"; string myConnectionString4 = "server=192.168.0.200;database=env4;uid=Admin4Env;pwd=AdminEnv4;"; string myConnectionString5 = "server=192.168.0.200;database=env5;uid=Admin5Env;pwd=AdminEnv5;"; string myConnectionString6 = "server=192.168.0.200;database=env6;uid=Admin6Env;pwd=AdminEnv6;"; string myConnectionString7 = "server=192.168.0.200;database=env7;uid=Admin7Env;pwd=AdminEnv7;"; string myConnectionString8 = "server=192.168.0.200;database=env8;uid=Admin8Env;pwd=AdminEnv8;"; string myConnectionString9 = "server=192.168.0.200;database=env9;uid=Admin9Env;pwd=AdminEnv9;"; private void chartControl1_Click(object sender, EventArgs e) { } private void ShowTemp(object sender, EventArgs e) { MySqlConnection connection = new MySqlConnection(myConnectionString1); connection.Open(); try { MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource1.DataSource = ds; dataGridView1.DataSource = ds.Tables[0].DefaultView; this.dataGridView1.Sort(this.dataGridView1.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView1.Rows.Count; int first = dataGridView1.Rows.Count - nRowIndex; dataGridView1.Rows[first].Selected = true; if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen1Value = dataGridView1.Rows[first].Cells[2].Value.ToString(); env1Sen1 = float.Parse(env1Sen1Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen2Value = dataGridView1.Rows[first].Cells[3].Value.ToString(); env1Sen2 = float.Parse(env1Sen2Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen3Value = dataGridView1.Rows[first].Cells[4].Value.ToString(); env1Sen3 = float.Parse(env1Sen3Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen4Value = dataGridView1.Rows[first].Cells[5].Value.ToString(); env1Sen4 = float.Parse(env1Sen4Value); } } catch (Exception) { throw; } finally { if (connection.State == ConnectionState.Open) { connection.Clone(); } } //open second connection MySqlConnection connection2 = new MySqlConnection(myConnectionString2); // connection.Open(); try { MySqlCommand cmd = connection2.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource2.DataSource = ds; dataGridView2.DataSource = ds.Tables[0].DefaultView; this.dataGridView2.Sort(this.dataGridView2.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView2.Rows.Count; int first = dataGridView2.Rows.Count - nRowIndex; dataGridView2.Rows[first].Selected = true; if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen1Value = dataGridView2.Rows[first].Cells[2].Value.ToString(); env2Sen1 = float.Parse(env2Sen1Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen2Value = dataGridView2.Rows[first].Cells[3].Value.ToString(); env2Sen2 = float.Parse(env2Sen2Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen3Value = dataGridView2.Rows[first].Cells[4].Value.ToString(); env2Sen3 = float.Parse(env2Sen3Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen4Value = dataGridView2.Rows[first].Cells[5].Value.ToString(); env2Sen4 = float.Parse(env2Sen4Value); } } catch (Exception) { throw; } finally { if (connection2.State == ConnectionState.Open) { connection2.Clone(); } } MySqlConnection connection3 = new MySqlConnection(myConnectionString3); // connection.Open(); try { MySqlCommand cmd = connection3.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource3.DataSource = ds; dataGridView3.DataSource = ds.Tables[0].DefaultView; this.dataGridView3.Sort(this.dataGridView3.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView3.Rows.Count; int first = dataGridView3.Rows.Count - nRowIndex; dataGridView3.Rows[first].Selected = true; if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen1Value = dataGridView3.Rows[first].Cells[2].Value.ToString(); env3Sen1 = float.Parse(env3Sen1Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen2Value = dataGridView3.Rows[first].Cells[3].Value.ToString(); env3Sen2 = float.Parse(env3Sen2Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen3Value = dataGridView3.Rows[first].Cells[4].Value.ToString(); env3Sen3 = float.Parse(env3Sen3Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen4Value = dataGridView3.Rows[first].Cells[5].Value.ToString(); env3Sen4 = float.Parse(env3Sen4Value); } } catch (Exception) { throw; } finally { if (connection3.State == ConnectionState.Open) { connection3.Clone(); } } MySqlConnection connection4 = new MySqlConnection(myConnectionString4); // connection.Open(); try { MySqlCommand cmd = connection4.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource4.DataSource = ds; dataGridView4.DataSource = ds.Tables[0].DefaultView; this.dataGridView4.Sort(this.dataGridView4.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView4.Rows.Count; int first = dataGridView4.Rows.Count - nRowIndex; dataGridView4.Rows[first].Selected = true; if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen1Value = dataGridView4.Rows[first].Cells[2].Value.ToString(); env4Sen1 = float.Parse(env4Sen1Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen2Value = dataGridView4.Rows[first].Cells[3].Value.ToString(); env4Sen2 = float.Parse(env4Sen2Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen3Value = dataGridView4.Rows[first].Cells[4].Value.ToString(); env4Sen3 = float.Parse(env4Sen3Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen4Value = dataGridView4.Rows[first].Cells[5].Value.ToString(); env4Sen4 = float.Parse(env4Sen4Value); } } catch (Exception) { throw; } finally { if (connection4.State == ConnectionState.Open) { connection4.Clone(); } } /*MySqlConnection connection5 = new MySqlConnection(myConnectionString5); // connection.Open(); try { MySqlCommand cmd = connection5.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource5.DataSource = ds; dataGridView5.DataSource = ds.Tables[0].DefaultView; this.dataGridView5.Sort(this.dataGridView5.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView5.Rows.Count; int first = dataGridView5.Rows.Count - nRowIndex; dataGridView5.Rows[first].Selected = true; if (dataGridView5.Rows[first].Cells[2].Value != null) { env5Sen1Value = dataGridView5.Rows[first].Cells[2].Value.ToString(); env5Sen1 = float.Parse(env5Sen1Value); } if (dataGridView5.Rows[first].Cells[2].Value != null) { env5Sen2Value = dataGridView5.Rows[first].Cells[3].Value.ToString(); env5Sen2 = float.Parse(env5Sen2Value); } if (dataGridView5.Rows[first].Cells[2].Value != null) { env5Sen3Value = dataGridView5.Rows[first].Cells[4].Value.ToString(); env5Sen3 = float.Parse(env5Sen3Value); } if (dataGridView5.Rows[first].Cells[2].Value != null) { env5Sen4Value = dataGridView5.Rows[first].Cells[5].Value.ToString(); env5Sen4 = float.Parse(env5Sen4Value); } } catch (Exception) { throw; } finally { if (connection5.State == ConnectionState.Open) { connection5.Clone(); } } MySqlConnection connection6 = new MySqlConnection(myConnectionString6); // connection.Open(); try { MySqlCommand cmd = connection6.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource6.DataSource = ds; dataGridView6.DataSource = ds.Tables[0].DefaultView; this.dataGridView6.Sort(this.dataGridView6.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView6.Rows.Count; int first = dataGridView6.Rows.Count - nRowIndex; dataGridView6.Rows[first].Selected = true; if (dataGridView6.Rows[first].Cells[2].Value != null) { env6Sen1Value = dataGridView6.Rows[first].Cells[2].Value.ToString(); env6Sen1 = float.Parse(env6Sen1Value); } if (dataGridView6.Rows[first].Cells[2].Value != null) { env6Sen2Value = dataGridView6.Rows[first].Cells[3].Value.ToString(); env6Sen2 = float.Parse(env6Sen2Value); } if (dataGridView6.Rows[first].Cells[2].Value != null) { env6Sen3Value = dataGridView6.Rows[first].Cells[4].Value.ToString(); env6Sen3 = float.Parse(env6Sen3Value); } if (dataGridView6.Rows[first].Cells[2].Value != null) { env6Sen4Value = dataGridView6.Rows[first].Cells[5].Value.ToString(); env6Sen4 = float.Parse(env6Sen4Value); } } catch (Exception) { throw; } finally { if (connection6.State == ConnectionState.Open) { connection6.Clone(); } } MySqlConnection connection7 = new MySqlConnection(myConnectionString7); // connection.Open(); try { MySqlCommand cmd = connection7.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource7.DataSource = ds; dataGridView7.DataSource = ds.Tables[0].DefaultView; this.dataGridView7.Sort(this.dataGridView7.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView7.Rows.Count; int first = dataGridView7.Rows.Count - nRowIndex; dataGridView7.Rows[first].Selected = true; if (dataGridView7.Rows[first].Cells[2].Value != null) { env7Sen1Value = dataGridView7.Rows[first].Cells[2].Value.ToString(); env7Sen1 = float.Parse(env7Sen1Value); } if (dataGridView7.Rows[first].Cells[2].Value != null) { env7Sen2Value = dataGridView7.Rows[first].Cells[3].Value.ToString(); env7Sen2 = float.Parse(env7Sen2Value); } if (dataGridView7.Rows[first].Cells[2].Value != null) { env7Sen3Value = dataGridView7.Rows[first].Cells[4].Value.ToString(); env7Sen3 = float.Parse(env7Sen3Value); } if (dataGridView7.Rows[first].Cells[2].Value != null) { env7Sen4Value = dataGridView7.Rows[first].Cells[5].Value.ToString(); env7Sen4 = float.Parse(env7Sen4Value); } } catch (Exception) { throw; } finally { if (connection7.State == ConnectionState.Open) { connection7.Clone(); } } MySqlConnection connection8 = new MySqlConnection(myConnectionString8); // connection.Open(); try { MySqlCommand cmd = connection8.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource8.DataSource = ds; dataGridView8.DataSource = ds.Tables[0].DefaultView; this.dataGridView8.Sort(this.dataGridView8.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView8.Rows.Count; int first = dataGridView8.Rows.Count - nRowIndex; dataGridView8.Rows[first].Selected = true; if (dataGridView8.Rows[first].Cells[2].Value != null) { env8Sen1Value = dataGridView8.Rows[first].Cells[2].Value.ToString(); env8Sen1 = float.Parse(env8Sen1Value); } if (dataGridView8.Rows[first].Cells[2].Value != null) { env8Sen2Value = dataGridView8.Rows[first].Cells[3].Value.ToString(); env8Sen2 = float.Parse(env8Sen2Value); } if (dataGridView8.Rows[first].Cells[2].Value != null) { env8Sen3Value = dataGridView8.Rows[first].Cells[4].Value.ToString(); env8Sen3 = float.Parse(env8Sen3Value); } if (dataGridView8.Rows[first].Cells[2].Value != null) { env8Sen4Value = dataGridView8.Rows[first].Cells[5].Value.ToString(); env8Sen4 = float.Parse(env8Sen4Value); } } catch (Exception) { throw; } finally { if (connection8.State == ConnectionState.Open) { connection8.Clone(); } } MySqlConnection connection9 = new MySqlConnection(myConnectionString9); // connection.Open(); try { MySqlCommand cmd = connection9.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource9.DataSource = ds; dataGridView9.DataSource = ds.Tables[0].DefaultView; this.dataGridView9.Sort(this.dataGridView9.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView9.Rows.Count; int first = dataGridView9.Rows.Count - nRowIndex; dataGridView9.Rows[first].Selected = true; if (dataGridView9.Rows[first].Cells[2].Value != null) { env9Sen1Value = dataGridView9.Rows[first].Cells[2].Value.ToString(); env9Sen1 = float.Parse(env9Sen1Value); } if (dataGridView9.Rows[first].Cells[2].Value != null) { env9Sen2Value = dataGridView9.Rows[first].Cells[3].Value.ToString(); env9Sen2 = float.Parse(env9Sen2Value); } if (dataGridView9.Rows[first].Cells[2].Value != null) { env9Sen3Value = dataGridView9.Rows[first].Cells[4].Value.ToString(); env9Sen3 = float.Parse(env9Sen3Value); } if (dataGridView9.Rows[first].Cells[2].Value != null) { env9Sen4Value = dataGridView9.Rows[first].Cells[5].Value.ToString(); env9Sen4 = float.Parse(env9Sen4Value); } } catch (Exception) { throw; } finally { if (connection9.State == ConnectionState.Open) { connection9.Clone(); } } */ nChartControl1.Settings.ShapeRenderingMode = ShapeRenderingMode.None; nChartControl1.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl1.Controller.Tools.Add(new NTrackballTool()); nChartControl1.AutoRefresh = true; // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Temperature"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.FillStyle = new NColorFillStyle(Color.Gray); // setup chart NChart chart = nChartControl1.Charts[0]; chart.Enable3D = true; chart.Width = 60.0f; chart.Depth = 60.0f; chart.Height = 25.0f; chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted); chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyTopLeft); // setup axes NOrdinalScaleConfigurator ordinalScale = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator; ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); ordinalScale.DisplayDataPointsBetweenTicks = false; ordinalScale = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.Depth).ScaleConfigurator; ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, true); ordinalScale.DisplayDataPointsBetweenTicks = false; // add the surface series NGridSurfaceSeries surface = (NGridSurfaceSeries)chart.Series.Add(SeriesType.GridSurface); surface.Name = "Surface"; surface.Legend.Mode = SeriesLegendMode.SeriesLogic; surface.SyncPaletteWithAxisScale = false; surface.PaletteSteps = 8; surface.ValueFormatter.FormatSpecifier = "0.00"; //clear series surface.Data.Clear(); //Update data surface.Data.SetGridSize(3, 3); surface.Data.SetValue(0, 0, 0); surface.Data.SetValue(0, 1, 0); surface.Data.SetValue(0, 2, 0); surface.Data.SetValue(1, 0, 0); surface.Data.SetValue(1, 1, 10); surface.Data.SetValue(1, 2, 0); surface.Data.SetValue(2, 0, 0); surface.Data.SetValue(2, 1, 0); surface.Data.SetValue(2, 2, 0); } private void ShowHumidity(object sender, EventArgs e) { MySqlConnection connection = new MySqlConnection(myConnectionString1); connection.Open(); try { MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource1.DataSource = ds; dataGridView1.DataSource = ds.Tables[0].DefaultView; this.dataGridView1.Sort(this.dataGridView1.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView1.Rows.Count; int first = dataGridView1.Rows.Count - nRowIndex; dataGridView1.Rows[first].Selected = true; if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen1Value = dataGridView1.Rows[first].Cells[2].Value.ToString(); env1Sen1 = float.Parse(env1Sen1Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen2Value = dataGridView1.Rows[first].Cells[3].Value.ToString(); env1Sen2 = float.Parse(env1Sen2Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen3Value = dataGridView1.Rows[first].Cells[4].Value.ToString(); env1Sen3 = float.Parse(env1Sen3Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen4Value = dataGridView1.Rows[first].Cells[5].Value.ToString(); env1Sen4 = float.Parse(env1Sen4Value); } } catch (Exception) { throw; } finally { if (connection.State == ConnectionState.Open) { connection.Clone(); } } MySqlConnection connection2 = new MySqlConnection(myConnectionString2); // connection.Open(); try { MySqlCommand cmd = connection2.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource2.DataSource = ds; dataGridView2.DataSource = ds.Tables[0].DefaultView; this.dataGridView2.Sort(this.dataGridView2.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView2.Rows.Count; int first = dataGridView2.Rows.Count - nRowIndex; dataGridView2.Rows[first].Selected = true; if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen1Value = dataGridView2.Rows[first].Cells[2].Value.ToString(); env2Sen1 = float.Parse(env2Sen1Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen2Value = dataGridView2.Rows[first].Cells[3].Value.ToString(); env2Sen2 = float.Parse(env2Sen2Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen3Value = dataGridView2.Rows[first].Cells[4].Value.ToString(); env2Sen3 = float.Parse(env2Sen3Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen4Value = dataGridView2.Rows[first].Cells[5].Value.ToString(); env2Sen4 = float.Parse(env2Sen4Value); } } catch (Exception) { throw; } finally { if (connection2.State == ConnectionState.Open) { connection2.Clone(); } } MySqlConnection connection3 = new MySqlConnection(myConnectionString3); // connection.Open(); try { MySqlCommand cmd = connection3.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource3.DataSource = ds; dataGridView3.DataSource = ds.Tables[0].DefaultView; this.dataGridView3.Sort(this.dataGridView3.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView3.Rows.Count; int first = dataGridView3.Rows.Count - nRowIndex; dataGridView3.Rows[first].Selected = true; if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen1Value = dataGridView3.Rows[first].Cells[2].Value.ToString(); env3Sen1 = float.Parse(env3Sen1Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen2Value = dataGridView3.Rows[first].Cells[3].Value.ToString(); env3Sen2 = float.Parse(env3Sen2Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen3Value = dataGridView3.Rows[first].Cells[4].Value.ToString(); env3Sen3 = float.Parse(env3Sen3Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen4Value = dataGridView3.Rows[first].Cells[5].Value.ToString(); env3Sen4 = float.Parse(env3Sen4Value); } } catch (Exception) { throw; } finally { if (connection3.State == ConnectionState.Open) { connection3.Clone(); } } MySqlConnection connection4 = new MySqlConnection(myConnectionString4); // connection.Open(); try { MySqlCommand cmd = connection4.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource4.DataSource = ds; dataGridView4.DataSource = ds.Tables[0].DefaultView; this.dataGridView4.Sort(this.dataGridView4.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView4.Rows.Count; int first = dataGridView4.Rows.Count - nRowIndex; dataGridView4.Rows[first].Selected = true; if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen1Value = dataGridView4.Rows[first].Cells[2].Value.ToString(); env4Sen1 = float.Parse(env4Sen1Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen2Value = dataGridView4.Rows[first].Cells[3].Value.ToString(); env4Sen2 = float.Parse(env4Sen2Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen3Value = dataGridView4.Rows[first].Cells[4].Value.ToString(); env4Sen3 = float.Parse(env4Sen3Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen4Value = dataGridView4.Rows[first].Cells[5].Value.ToString(); env4Sen4 = float.Parse(env4Sen4Value); } } catch (Exception) { throw; } finally { if (connection4.State == ConnectionState.Open) { connection4.Clone(); } } nChartControl2.Settings.ShapeRenderingMode = ShapeRenderingMode.None; nChartControl2.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl2.Controller.Tools.Add(new NTrackballTool()); // set a chart title NLabel title = nChartControl2.Labels.AddHeader("Temperature"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.FillStyle = new NColorFillStyle(Color.Gray); // setup chart NChart chart = nChartControl2.Charts[0]; chart.Enable3D = true; chart.Width = 60.0f; chart.Depth = 60.0f; chart.Height = 25.0f; chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted); chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyTopLeft); // setup axes NOrdinalScaleConfigurator ordinalScale = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator; ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); ordinalScale.DisplayDataPointsBetweenTicks = false; ordinalScale = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.Depth).ScaleConfigurator; ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, true); ordinalScale.DisplayDataPointsBetweenTicks = false; // add the surface series NGridSurfaceSeries surface = (NGridSurfaceSeries)chart.Series.Add(SeriesType.GridSurface); surface.Name = "Surface"; surface.Legend.Mode = SeriesLegendMode.SeriesLogic; surface.SyncPaletteWithAxisScale = false; surface.PaletteSteps = 8; surface.ValueFormatter.FormatSpecifier = "0.00"; surface.Data.SetGridSize(3, 3); surface.Data.SetValue(0, 0, 0); surface.Data.SetValue(0, 1, 0); surface.Data.SetValue(0, 2, 0); surface.Data.SetValue(1, 0, 0); surface.Data.SetValue(1, 1, 10); surface.Data.SetValue(1, 2, 0); surface.Data.SetValue(2, 0, 0); surface.Data.SetValue(2, 1, 0); surface.Data.SetValue(2, 2, 0); } private void ShowBrightness(object sender, EventArgs e) { MySqlConnection connection = new MySqlConnection(myConnectionString1); connection.Open(); try { MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource1.DataSource = ds; dataGridView1.DataSource = ds.Tables[0].DefaultView; this.dataGridView1.Sort(this.dataGridView1.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView1.Rows.Count; int first = dataGridView1.Rows.Count - nRowIndex; dataGridView1.Rows[first].Selected = true; if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen1Value = dataGridView1.Rows[first].Cells[2].Value.ToString(); env1Sen1 = float.Parse(env1Sen1Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen2Value = dataGridView1.Rows[first].Cells[3].Value.ToString(); env1Sen2 = float.Parse(env1Sen2Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen3Value = dataGridView1.Rows[first].Cells[4].Value.ToString(); env1Sen3 = float.Parse(env1Sen3Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen4Value = dataGridView1.Rows[first].Cells[5].Value.ToString(); env1Sen4 = float.Parse(env1Sen4Value); } } catch (Exception) { throw; } finally { if (connection.State == ConnectionState.Open) { connection.Clone(); } } MySqlConnection connection2 = new MySqlConnection(myConnectionString2); // connection.Open(); try { MySqlCommand cmd = connection2.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource2.DataSource = ds; dataGridView2.DataSource = ds.Tables[0].DefaultView; this.dataGridView2.Sort(this.dataGridView2.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView2.Rows.Count; int first = dataGridView2.Rows.Count - nRowIndex; dataGridView2.Rows[first].Selected = true; if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen1Value = dataGridView2.Rows[first].Cells[2].Value.ToString(); env2Sen1 = float.Parse(env2Sen1Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen2Value = dataGridView2.Rows[first].Cells[3].Value.ToString(); env2Sen2 = float.Parse(env2Sen2Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen3Value = dataGridView2.Rows[first].Cells[4].Value.ToString(); env2Sen3 = float.Parse(env2Sen3Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen4Value = dataGridView2.Rows[first].Cells[5].Value.ToString(); env2Sen4 = float.Parse(env2Sen4Value); } } catch (Exception) { throw; } finally { if (connection2.State == ConnectionState.Open) { connection2.Clone(); } } MySqlConnection connection3 = new MySqlConnection(myConnectionString3); // connection.Open(); try { MySqlCommand cmd = connection3.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource3.DataSource = ds; dataGridView3.DataSource = ds.Tables[0].DefaultView; this.dataGridView3.Sort(this.dataGridView3.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView3.Rows.Count; int first = dataGridView3.Rows.Count - nRowIndex; dataGridView3.Rows[first].Selected = true; if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen1Value = dataGridView3.Rows[first].Cells[2].Value.ToString(); env3Sen1 = float.Parse(env3Sen1Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen2Value = dataGridView3.Rows[first].Cells[3].Value.ToString(); env3Sen2 = float.Parse(env3Sen2Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen3Value = dataGridView3.Rows[first].Cells[4].Value.ToString(); env3Sen3 = float.Parse(env3Sen3Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen4Value = dataGridView3.Rows[first].Cells[5].Value.ToString(); env3Sen4 = float.Parse(env3Sen4Value); } } catch (Exception) { throw; } finally { if (connection3.State == ConnectionState.Open) { connection3.Clone(); } } MySqlConnection connection4 = new MySqlConnection(myConnectionString4); // connection.Open(); try { MySqlCommand cmd = connection4.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource4.DataSource = ds; dataGridView4.DataSource = ds.Tables[0].DefaultView; this.dataGridView4.Sort(this.dataGridView4.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView4.Rows.Count; int first = dataGridView4.Rows.Count - nRowIndex; dataGridView4.Rows[first].Selected = true; if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen1Value = dataGridView4.Rows[first].Cells[2].Value.ToString(); env4Sen1 = float.Parse(env4Sen1Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen2Value = dataGridView4.Rows[first].Cells[3].Value.ToString(); env4Sen2 = float.Parse(env4Sen2Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen3Value = dataGridView4.Rows[first].Cells[4].Value.ToString(); env4Sen3 = float.Parse(env4Sen3Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen4Value = dataGridView4.Rows[first].Cells[5].Value.ToString(); env4Sen4 = float.Parse(env4Sen4Value); } } catch (Exception) { throw; } finally { if (connection4.State == ConnectionState.Open) { connection4.Clone(); } } nChartControl3.Settings.ShapeRenderingMode = ShapeRenderingMode.None; nChartControl3.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl3.Controller.Tools.Add(new NTrackballTool()); // set a chart title NLabel title = nChartControl3.Labels.AddHeader("Brightness"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.FillStyle = new NColorFillStyle(Color.Gray); // setup chart NChart chart = nChartControl3.Charts[0]; chart.Enable3D = true; chart.Width = 60.0f; chart.Depth = 60.0f; chart.Height = 25.0f; chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted); chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyTopLeft); // setup axes NOrdinalScaleConfigurator ordinalScale = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator; ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); ordinalScale.DisplayDataPointsBetweenTicks = false; ordinalScale = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.Depth).ScaleConfigurator; ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, true); ordinalScale.DisplayDataPointsBetweenTicks = false; // add the surface series NGridSurfaceSeries surface = (NGridSurfaceSeries)chart.Series.Add(SeriesType.GridSurface); surface.Name = "Surface"; surface.Legend.Mode = SeriesLegendMode.SeriesLogic; surface.SyncPaletteWithAxisScale = false; surface.PaletteSteps = 8; surface.ValueFormatter.FormatSpecifier = "0.00"; surface.Data.SetGridSize(3, 3); surface.Data.SetValue(0, 0, 0); surface.Data.SetValue(0, 1, 0); surface.Data.SetValue(0, 2, 0); surface.Data.SetValue(1, 0, 0); surface.Data.SetValue(1, 1, 10); surface.Data.SetValue(1, 2, 0); surface.Data.SetValue(2, 0, 0); surface.Data.SetValue(2, 1, 0); surface.Data.SetValue(2, 2, 0); } private void ShowOccupancy(object sender, EventArgs e) { MySqlConnection connection = new MySqlConnection(myConnectionString1); connection.Open(); try { MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource1.DataSource = ds; dataGridView1.DataSource = ds.Tables[0].DefaultView; this.dataGridView1.Sort(this.dataGridView1.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView1.Rows.Count; int first = dataGridView1.Rows.Count - nRowIndex; dataGridView1.Rows[first].Selected = true; if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen1Value = dataGridView1.Rows[first].Cells[2].Value.ToString(); env1Sen1 = float.Parse(env1Sen1Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen2Value = dataGridView1.Rows[first].Cells[3].Value.ToString(); env1Sen2 = float.Parse(env1Sen2Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen3Value = dataGridView1.Rows[first].Cells[4].Value.ToString(); env1Sen3 = float.Parse(env1Sen3Value); } if (dataGridView1.Rows[first].Cells[2].Value != null) { env1Sen4Value = dataGridView1.Rows[first].Cells[5].Value.ToString(); env1Sen4 = float.Parse(env1Sen4Value); } } catch (Exception) { throw; } finally { if (connection.State == ConnectionState.Open) { connection.Clone(); } } MySqlConnection connection2 = new MySqlConnection(myConnectionString2); // connection.Open(); try { MySqlCommand cmd = connection2.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource2.DataSource = ds; dataGridView2.DataSource = ds.Tables[0].DefaultView; this.dataGridView2.Sort(this.dataGridView2.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView2.Rows.Count; int first = dataGridView2.Rows.Count - nRowIndex; dataGridView2.Rows[first].Selected = true; if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen1Value = dataGridView2.Rows[first].Cells[2].Value.ToString(); env2Sen1 = float.Parse(env2Sen1Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen2Value = dataGridView2.Rows[first].Cells[3].Value.ToString(); env2Sen2 = float.Parse(env2Sen2Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen3Value = dataGridView2.Rows[first].Cells[4].Value.ToString(); env2Sen3 = float.Parse(env2Sen3Value); } if (dataGridView2.Rows[first].Cells[2].Value != null) { env2Sen4Value = dataGridView2.Rows[first].Cells[5].Value.ToString(); env2Sen4 = float.Parse(env2Sen4Value); } } catch (Exception) { throw; } finally { if (connection2.State == ConnectionState.Open) { connection2.Clone(); } } MySqlConnection connection3 = new MySqlConnection(myConnectionString3); // connection.Open(); try { MySqlCommand cmd = connection3.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource3.DataSource = ds; dataGridView3.DataSource = ds.Tables[0].DefaultView; this.dataGridView3.Sort(this.dataGridView3.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView3.Rows.Count; int first = dataGridView3.Rows.Count - nRowIndex; dataGridView3.Rows[first].Selected = true; if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen1Value = dataGridView3.Rows[first].Cells[2].Value.ToString(); env3Sen1 = float.Parse(env3Sen1Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen2Value = dataGridView3.Rows[first].Cells[3].Value.ToString(); env3Sen2 = float.Parse(env3Sen2Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen3Value = dataGridView3.Rows[first].Cells[4].Value.ToString(); env3Sen3 = float.Parse(env3Sen3Value); } if (dataGridView3.Rows[first].Cells[2].Value != null) { env3Sen4Value = dataGridView3.Rows[first].Cells[5].Value.ToString(); env3Sen4 = float.Parse(env3Sen4Value); } } catch (Exception) { throw; } finally { if (connection3.State == ConnectionState.Open) { connection3.Clone(); } } MySqlConnection connection4 = new MySqlConnection(myConnectionString4); // connection.Open(); try { MySqlCommand cmd = connection4.CreateCommand(); cmd.CommandText = "Select * FROM table1"; MySqlDataAdapter adap = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); this.bindingSource4.DataSource = ds; dataGridView4.DataSource = ds.Tables[0].DefaultView; this.dataGridView4.Sort(this.dataGridView4.Columns["id"], ListSortDirection.Descending); int nRowIndex = dataGridView4.Rows.Count; int first = dataGridView4.Rows.Count - nRowIndex; dataGridView4.Rows[first].Selected = true; if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen1Value = dataGridView4.Rows[first].Cells[2].Value.ToString(); env4Sen1 = float.Parse(env4Sen1Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen2Value = dataGridView4.Rows[first].Cells[3].Value.ToString(); env4Sen2 = float.Parse(env4Sen2Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen3Value = dataGridView4.Rows[first].Cells[4].Value.ToString(); env4Sen3 = float.Parse(env4Sen3Value); } if (dataGridView4.Rows[first].Cells[2].Value != null) { env4Sen4Value = dataGridView4.Rows[first].Cells[5].Value.ToString(); env4Sen4 = float.Parse(env4Sen4Value); } } catch (Exception) { throw; } finally { if (connection4.State == ConnectionState.Open) { connection4.Clone(); } } nChartControl4.Settings.ShapeRenderingMode = ShapeRenderingMode.None; nChartControl4.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl4.Controller.Tools.Add(new NTrackballTool()); // set a chart title NLabel title = nChartControl4.Labels.AddHeader("Occupancy"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.FillStyle = new NColorFillStyle(Color.Gray); // setup chart NChart chart = nChartControl4.Charts[0]; chart.Enable3D = true; chart.Width = 60.0f; chart.Depth = 60.0f; chart.Height = 25.0f; chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted); chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyTopLeft); // setup axes NOrdinalScaleConfigurator ordinalScale = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator; ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); ordinalScale.DisplayDataPointsBetweenTicks = false; ordinalScale = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.Depth).ScaleConfigurator; ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, true); ordinalScale.DisplayDataPointsBetweenTicks = false; // add the surface series NGridSurfaceSeries surface = (NGridSurfaceSeries)chart.Series.Add(SeriesType.GridSurface); surface.Name = "Surface"; surface.Legend.Mode = SeriesLegendMode.SeriesLogic; surface.SyncPaletteWithAxisScale = false; surface.PaletteSteps = 8; surface.ValueFormatter.FormatSpecifier = "0.00"; surface.Data.SetGridSize(3, 3); surface.Data.SetValue(0, 0, 0); surface.Data.SetValue(0, 1, 0); surface.Data.SetValue(0, 2, 0); surface.Data.SetValue(1, 0, 0); surface.Data.SetValue(1, 1, 10); surface.Data.SetValue(1, 2, 0); surface.Data.SetValue(2, 0, 0); surface.Data.SetValue(2, 1, 0); surface.Data.SetValue(2, 2, 0); } public Form1() { InitializeComponent(); this.Load += Form1_Load; } private void Form1_Load(object sender, EventArgs e) { System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); timer2.Interval = (2000); timer2.Tick += new EventHandler(timer2_Tick); timer2.Start(); timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { Timer1Count--; //Timer1Count //this.Invoke(new EventHandler(DisplayTimer1)); if (n == 20) { timer1.Enabled = false; timer1.Interval = 1000; timer1.Enabled = true; } if (Timer1Count == 0) { Timer1Count = 10; this.Invoke(new EventHandler(ShowTemp)); this.Invoke(new EventHandler(ShowHumidity)); this.Invoke(new EventHandler(ShowBrightness)); this.Invoke(new EventHandler(ShowOccupancy)); } } private void timer2_Tick(object sender, EventArgs e) { //Update the 4 chart nChartControl1.Refresh(); nChartControl2.Refresh(); nChartControl3.Refresh(); nChartControl4.Refresh(); } } }