using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.IO.Ports;
using System.Data.OleDb;
using System.Threading;
namespace AlarmSystem2
{
public partial class mainForm : Form
{
public mainForm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 1000;
timer1.Start();
}
private void LoadDatabase()
{
string sql = "SELECT Pilar1, Pilar2, Pilar3, TIME FROM `testschema`.`testtable` ORDER BY ID desc LIMIT 1";
MySqlConnection con = new MySqlConnection("host=localhost;user=root;password=Settha15;database=testschema");
MySqlCommand cmd = new MySqlCommand(sql, con);
con.Open();
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
chartP1.Series["Pilar1"].Points.AddXY(reader.GetString("TIME"), reader.GetString("Pilar1"));
chartP2.Series["Pilar2"].Points.AddXY(reader.GetString("TIME"), reader.GetString("Pilar2"));
chartP3.Series["Pilar3"].Points.AddXY(reader.GetString("TIME"), reader.GetString("Pilar3"));
}
con.Close();
}
private void button3_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
LoadDatabase();
}
}
}