private void cbDataSets_Click(object sender, EventArgs e) { MySqlDataReader reader; string showQuery = "show tables"; try { MySqlCommand msc = new MySqlCommand(showQuery, DBUtils.conn); cbDataSets.Items.Clear(); TableNames.Clear(); reader = msc.ExecuteReader(); while (reader.Read()) { cbDataSets.Items.Add(reader.GetString(0)); TableNames.Add(reader.GetString(0)); } reader.Close(); } catch (InvalidOperationException exc) { MSG.Show(this, "Please enable server connection", exc.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning, logger); } catch (Exception exc) { MSG.Show(this, exc.ToString(), exc.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, logger); } }
private void cbTimeFrom_Click(object sender, EventArgs e) { //SELECT `Timestamp` FROM `trends_data` WHERE 1 MySqlDataReader reader; string showQuery = "Timestamp` FROM `trends_data` WHERE 1"; MySqlCommand msc = new MySqlCommand(showQuery, DBUtils.conn); try { if (DBUtils.OpenConnection(lbStatus, logger)) { cbVariables.Items.Clear(); variables.Clear(); reader = msc.ExecuteReader(); while (reader.Read()) { //dtFrom.Items.Add(reader.GetString(0)); } } } catch { MSG.Show(this, "Please enable server connection", MessageBoxButtons.OK, MessageBoxIcon.Warning, logger); } }
void addVariable() { MySqlDataReader reader; //string showQuery = "Select * From variables_data"; string showQuery = "SELECT DISTINCT variables_data.ID, variables_data.name, variables_data.Description FROM variables_data INNER JOIN trends_data ON variables_data.ID = trends_data.ID WHERE trends_data.Value = ANY(SELECT VALUE From variables_data)"; uint id; string name; string desc; MySqlCommand msc = new MySqlCommand(showQuery, DBUtils.conn); try { if (DBUtils.OpenConnection(lbStatus, logger)) { cbVariables.Items.Clear(); variables.Clear(); reader = msc.ExecuteReader(); while (reader.Read()) { id = reader.GetUInt32(0); name = reader.GetString(1); desc = reader.GetString(2); cbVariables.Items.Add(name); variables.Add(new Variable(id, name, desc)); } } } catch (Exception exc) { //MetroMessageBox.Show(this, "Please enable server connection", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, 100); MSG.Show(this, exc.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, logger); } }
public void MainChart_KeyPress(object sender, KeyEventArgs e) { var chart = (Chart)sender; var xAxis = chart.ChartAreas[0].AxisX; var yAxis = chart.ChartAreas[0].AxisY; switch (e.KeyCode) { case Keys.Up: yAxis.ScaleView.Position += 100; break; case Keys.Down: break; case Keys.Left: MSG.Show(this, "Do you want clear all?", MessageBoxButtons.YesNo, MessageBoxIcon.Information, logger); break; case Keys.Right: break; default: break; } }
private void cbVariables_Click(object sender, EventArgs e) { if (dTimer.Enabled) { MSG.Show(this, "Please stop the timer", MessageBoxButtons.OK, MessageBoxIcon.Warning, logger); } else { full_data.Clear(); data.Clear(); lbTimer.Text = "Start the timer"; addVariable(); } }
private void ExecuteQuery(string query) { try { MySqlCommand msc = new MySqlCommand(query, DBUtils.conn); if (DBUtils.OpenConnection(lbStatus, logger)) { MainChart.Series[selected].BorderWidth = 3; MainChart.Series[selected].LegendText = selected; MainChart.Series[selected].ChartType = chartType; cbVariables.Items.Clear(); MySqlDataReader reader = msc.ExecuteReader(); c++; while (reader.Read()) { current_data.Add(reader.GetDateTime(1)); data.Add(reader.GetDouble(0)); } for (int i = 0; i < current_data.Count; i++) { if (!full_data.Contains(current_data[i])) { full_data.Add(current_data[i]); //MainChart.Series[selected].Points.AddY(data[i]); MainChart.Series[selected].Points.AddY(data[i]); } else { MainChart.Series[selected].Points.AddY(data[i]); //MainChart.Series[selected].Points.AddY(data[i]); } } current_data.Clear(); reader.Close(); } } catch (Exception exc) { MSG.Show(this, exc.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, logger); } }
private void cbTimeFrom_Click(object sender, EventArgs e) { //SELECT `Timestamp` FROM `trends_data` WHERE 1 string showQuery = "SELECT Timestamp` FROM `trends_data` WHERE 1"; MySqlCommand msc = new MySqlCommand(showQuery, DBUtils.conn); try { if (DBUtils.OpenConnection(lbStatus, logger)) { cbVariables.Items.Clear(); } } catch { MSG.Show(this, "Please enable server connection", MessageBoxButtons.OK, MessageBoxIcon.Warning, logger); } }
private void MainChart_MouseMove(object sender, MouseEventArgs e) { try { if (MainChart.Series.Count > 0) { lbPoint.Visible = true; if (MainChart.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) >= MainChart.ChartAreas[0].AxisX.Minimum && MainChart.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) <= MainChart.ChartAreas[0].AxisX.Maximum && MainChart.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) >= MainChart.ChartAreas[0].AxisY.Minimum && MainChart.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) <= MainChart.ChartAreas[0].AxisX.Maximum) { lbPoint.Text = "X:" + Math.Round(MainChart.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X)).ToString(); lbPoint.Text += " Y:" + Math.Round(MainChart.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y)).ToString(); } } else { lbPoint.Visible = false; } } catch (Exception exc) { MSG.Show(this, exc.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, logger); } }
private void ShowRows(string query) { using (MySqlDataAdapter adapter = new MySqlDataAdapter(query, DBUtils.conn)) { try { MySqlDataReader r; DataSet ds = new DataSet(); adapter.Fill(ds); mainGrid.DataSource = ds.Tables[0]; r = adapter.SelectCommand.ExecuteReader(); switch (cbDataSets.SelectedItem.ToString()) { case "actions_data": while (r.Read()) { ActionData actionData = new ActionData(r.GetDateTime(0), r.GetInt32(1), r.GetString(2)); ActionList.Add(actionData); } break; case "messages_data": while (r.Read()) { MessageData messageData = new MessageData(r.GetDateTime(0), r.GetInt32(1), r.GetInt32(2), r.GetInt32(3), r.GetString(4)); MessageList.Add(messageData); } break; case "recipes": while (r.Read()) { Recipe reciep = new Recipe(r.GetUInt32(0), r.GetString(1), r.GetDateTime(2), r.GetFloat(3), r.GetFloat(4), r.GetFloat(5), r.GetString(6)); ReciepList.Add(reciep); } break; case "trends_day": case "trends_hour": case "trends_minute": case "trends_data": while (r.Read()) { Trend trend = new Trend(r.GetUInt32(0), r.GetDateTime(1), r.GetFloat(2), r.GetInt16(3)); TrendList.Add(trend); } break; case "variables_data": while (r.Read()) { Variable variable = new Variable(r.GetUInt32(0), r.GetString(1), r.GetString(2)); VariableList.Add(variable); } break; default: break; } r.Close(); } catch (Exception exc) { MSG.Show(this, exc.ToString(), exc.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, logger); } } }
private void btnSave_Click(object sender, EventArgs e) { string fileName; if (cbDataSets.SelectedItem != null) { switch (cbDataSets.SelectedItem.ToString()) { case "actions_data": fileName = @"C:\Users\alex2\Desktop\Practice_saves_files\actions_data_Save.txt"; using (StreamWriter fs = new StreamWriter(fileName)) { fs.Write(JsonConvert.SerializeObject(ActionList)); } MessageBox.Show("information saved to file 'actions_data_Save'"); break; case "messages_data": fileName = @"C:\Users\alex2\Desktop\Practice_saves_files\messages_data_Save.txt"; using (StreamWriter fs = new StreamWriter(fileName)) { fs.Write(JsonConvert.SerializeObject(MessageList)); } MessageBox.Show("information saved to file 'messages_data_Save'"); break; case "recipes": fileName = @"C:\Users\alex2\Desktop\Practice_saves_files\recipes_Save.txt"; using (StreamWriter fs = new StreamWriter(fileName)) { fs.Write(JsonConvert.SerializeObject(ReciepList)); } MessageBox.Show("information saved to file 'recipes_Save'"); break; case "trends_day": case "trends_hour": case "trends_minute": case "trends_data": fileName = @"C:\Users\alex2\Desktop\Practice_saves_files\trends_data_Save.txt"; using (StreamWriter fs = new StreamWriter(fileName)) { fs.Write(JsonConvert.SerializeObject(TrendList)); } MessageBox.Show("information saved to file 'trends_data_Save'"); break; case "variables_data": fileName = @"C:\Users\alex2\Desktop\Practice_saves_files\variables_data_Save.txt"; using (StreamWriter fs = new StreamWriter(fileName)) { fs.Write(JsonConvert.SerializeObject(VariableList)); } MessageBox.Show("information saved to file 'variables_data_Save.txt'"); break; default: break; } } else { MSG.Show(this, "Please, choose table", MessageBoxButtons.OK, MessageBoxIcon.Warning, logger); } }
private void MainChart_MouseWheel(object sender, MouseEventArgs e) { var chart = MainChart; var xAxis = chart.ChartAreas[0].AxisX; var yAxis = chart.ChartAreas[0].AxisY; double xMin = xAxis.ScaleView.ViewMinimum; double xMax = xAxis.ScaleView.ViewMaximum; double yMin = yAxis.ScaleView.ViewMinimum; double yMax = yAxis.ScaleView.ViewMaximum; double IntervalX = chart.ChartAreas[0].AxisX.Maximum; double IntervalY = chart.ChartAreas[0].AxisY.Maximum; try { if (numberOfZoom < 5) { if (e.Delta < 0 && numberOfZoom > 0) // Scrolled down. { double posXStart = Math.Round(xAxis.PixelPositionToValue(e.Location.X) - IntervalX * 2 / Math.Pow(2, numberOfZoom)); double posXFinish = Math.Round(xAxis.PixelPositionToValue(e.Location.X) + IntervalX * 2 / Math.Pow(2, numberOfZoom)); double posYStart = Math.Round(yAxis.PixelPositionToValue(e.Location.Y) - IntervalY * 2 / Math.Pow(2, numberOfZoom)); double posYFinish = Math.Round(yAxis.PixelPositionToValue(e.Location.Y) + IntervalY * 2 / Math.Pow(2, numberOfZoom)); if (posXStart < 0) { posXStart = 0; } if (posYStart < 0) { posYStart = 0; } if (posYFinish > yAxis.Maximum) { posYFinish = yAxis.Maximum; } if (posXFinish > xAxis.Maximum) { posYFinish = xAxis.Maximum; } xAxis.ScaleView.Zoom(posXStart, posXFinish); yAxis.ScaleView.Zoom(posYStart, posYFinish); numberOfZoom--; } else if (e.Delta < 0 && numberOfZoom == 0) //Last scrolled dowm { yAxis.ScaleView.ZoomReset(); xAxis.ScaleView.ZoomReset(); } else if (e.Delta > 0) // Scrolled up. { double posXStart = Math.Round(xAxis.PixelPositionToValue(e.Location.X) - IntervalX / Math.Pow(2, numberOfZoom)); double posXFinish = Math.Round(xAxis.PixelPositionToValue(e.Location.X) + IntervalX / Math.Pow(2, numberOfZoom)); double posYStart = Math.Round(yAxis.PixelPositionToValue(e.Location.Y) - IntervalY / Math.Pow(2, numberOfZoom)); double posYFinish = Math.Round(yAxis.PixelPositionToValue(e.Location.Y) + IntervalY / Math.Pow(2, numberOfZoom)); xAxis.ScaleView.Zoom(posXStart, (int)posXFinish); yAxis.ScaleView.Zoom(posYStart, (int)posYFinish); numberOfZoom++; } else { yAxis.ScaleView.ZoomReset(); xAxis.ScaleView.ZoomReset(); numberOfZoom = 0; return; } } else { if (e.Delta > 0) { DialogResult dr = MetroMessageBox.Show(this, "So much zoom, do you want reset scale?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information, 100); if (dr == DialogResult.Yes) { yAxis.ScaleView.ZoomReset(); xAxis.ScaleView.ZoomReset(); numberOfZoom = 0; } else if (dr == DialogResult.No) { double posXStart = Math.Round(xAxis.PixelPositionToValue(e.Location.X) - IntervalX * 2 / Math.Pow(2, numberOfZoom)); double posXFinish = Math.Round(xAxis.PixelPositionToValue(e.Location.X) + IntervalX * 2 / Math.Pow(2, numberOfZoom)); double posYStart = Math.Round(yAxis.PixelPositionToValue(e.Location.Y) - IntervalY * 2 / Math.Pow(2, numberOfZoom)); double posYFinish = Math.Round(yAxis.PixelPositionToValue(e.Location.Y) + IntervalY * 2 / Math.Pow(2, numberOfZoom)); if (posXStart < 0) { posXStart = 0; } if (posYStart < 0) { posYStart = 0; } if (posYFinish > yAxis.Maximum) { posYFinish = yAxis.Maximum; } if (posXFinish > xAxis.Maximum) { posYFinish = xAxis.Maximum; } xAxis.ScaleView.Zoom(posXStart, posXFinish); yAxis.ScaleView.Zoom(posYStart, posYFinish); numberOfZoom--; } } if (e.Delta < 0) { return; } } } catch { MSG.Show(this, "Error in zoom", MessageBoxButtons.OK, MessageBoxIcon.Error, logger); } }
private void BuildingChart(string selected, string timeFormat) { MySqlDataReader reader; if (graphs.Count >= MAX) { DialogResult dr = MetroMessageBox.Show(this, "So mush sensors, do you want clear all?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information, 100); if (dr == DialogResult.Yes) { graphs.Clear(); MainChart.Series.Clear(); } else if (dr == DialogResult.No) { return; } } string query = "SELECT value, timeStamp FROM `variables_data` INNER JOIN `trends_data` ON variables_data.ID = trends_data.ID WHERE variables_data.Name = \"" + selected + "\" AND value > 0;"; MySqlCommand msc = new MySqlCommand(query, DBUtils.conn); try { MainChart.ChartAreas[0].AxisX.Interval = 1; MainChart.ChartAreas[0].AxisX.IntervalOffset = 1; MainChart.Series.Add(selected); MainChart.Series[selected].BorderWidth = 3; MainChart.Series[selected].LegendText = selected; MainChart.Series[selected].ChartType = chartType; MainChart.ChartAreas[0].CursorX.IsUserEnabled = true; MainChart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; MainChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; MainChart.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true; MainChart.ChartAreas[0].CursorY.IsUserEnabled = true; MainChart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; MainChart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; MainChart.ChartAreas[0].AxisY.ScrollBar.IsPositionedInside = true; cbVariables.Items.Clear(); reader = msc.ExecuteReader(); while (reader.Read()) { switch (timeFormat) { //YOU MUST TO CHANGE SECONDS IN TOTAL_SECONDS -> EACH CASE case "Year": MainChart.Series[0].XValueType = ChartValueType.DateTime; MainChart.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Years; MainChart.Series[selected].Points.AddXY(reader.GetDateTime(1), reader.GetDouble(0)); break; case "Month": MainChart.Series[0].XValueType = ChartValueType.DateTime; MainChart.ChartAreas[0].AxisX.LabelStyle.Format = "yyyy MM"; MainChart.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Months; MainChart.Series[selected].Points.AddXY(reader.GetDateTime(1), reader.GetDouble(0)); break; case "Day": MainChart.Series[0].XValueType = ChartValueType.DateTime; MainChart.ChartAreas[0].AxisX.LabelStyle.Format = "dd MMMM"; MainChart.Series[selected].Points.AddXY(reader.GetDateTime(1), reader.GetDouble(0)); break; case "Hour": MainChart.Series[0].XValueType = ChartValueType.Time; MainChart.ChartAreas[0].AxisX.LabelStyle.Format = "hh:mm"; //double hour = (int)reader.GetDateTime(1).TimeOfDay.TotalHours; //hour += Math.Round((reader.GetDateTime(1).TimeOfDay.TotalHours * 100) % 100 * 0.6) * 0.01; MainChart.Series[selected].Points.AddXY(reader.GetDateTime(1), reader.GetDouble(0)); break; case "Minute": MainChart.ChartAreas[0].AxisX.Minimum = DateTime.Now.AddDays(-8).Minute; //MainChart.ChartAreas[0].AxisX.Maximum = DateTime.Now.Minute; MainChart.Series[0].XValueType = ChartValueType.Time; MainChart.Series[selected].Points.AddXY(reader.GetDateTime(1).TimeOfDay.TotalMinutes, reader.GetDouble(0)); break; case "Second": MainChart.Series[0].XValueType = ChartValueType.Time; MainChart.Series[selected].Points.AddXY(reader.GetDateTime(1).TimeOfDay.TotalSeconds, reader.GetDouble(0)); break; case "Date": MainChart.Series[0].XValueType = ChartValueType.DateTime; MainChart.ChartAreas[0].AxisX.LabelStyle.Format = "dd MMMM"; MainChart.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Auto; MainChart.Series[selected].Points.AddXY(reader.GetDateTime(1).Date, reader.GetDouble(0)); break; case "Iterations": MainChart.Series[0].XValueType = ChartValueType.Int32; MainChart.Series[selected].Points.AddY(reader.GetDouble(0)); break; default: break; } } reader.Close(); } catch (Exception exc) { MSG.Show(this, exc.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, logger); } }