Ejemplo n.º 1
0
        private void fetchClick(object sender, RoutedEventArgs e)
        {
            string dbQuery = "SELECT * FROM " + sensorLocation + " WHERE '" + dayBefore + "' < time" + " and time < '" + dayAfter + "'";

            try
            {
                JObject parseResults    = JObject.Parse(NetworkClass.serverResponse(dbQuery));
                JArray  jsonArray       = (JArray)parseResults.SelectToken("points");
                JArray  jsonArrayLabels = (JArray)parseResults.SelectToken("columns");

                textBoxOut.Text = dbQuery;

                fetchGraph.RemoveGraph();
                fetchGraph.AddData(ref jsonArray, ref jsonArrayLabels);
                fetchGraph.PlotGraph();
                fetchGraph.SetStatistics(true);

                fetchTime.Text = "Fetch Time: " + DateTime.Now.ToString("yyyy-MM-dd h:mm:ss tt");
                //h:mm:ss tt
            }
            catch (Exception)
            {
                MessageBox.Show("Fetch Error, Try Again");
                textBoxOut.Text = dbQuery;
            }
        }
Ejemplo n.º 2
0
        private void consoleKeyPressed(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key.ToString() == "Return")
            {
                if (consoleInBox.Text == "clr")
                {
                    consoleOutBox.Text = "";
                    consoleInBox.Text  = "";
                }
                if (consoleInBox.Text != "") // Processing only non-empty strings
                {
                    try
                    {
                        consoleOutBox.Text += ">" + consoleInBox.Text.ToUpper() + "\n";

                        JObject parseResults = JObject.Parse(NetworkClass.serverResponse(consoleInBox.Text));
                        JArray  jsonArray    = (JArray)parseResults.SelectToken("columns");

                        // Saving input for the history reference
                        consoleHistory.Insert(moduloCounter % HISTORY_LIMIT, consoleInBox.Text);
                        moduloCounter++;
                        historyCounter = consoleHistory.Count;

                        // This part of the code properly displays the data in the console window
                        int rowCount = jsonArray.Count;

                        for (int i = 0; i < jsonArray.Count; i++)
                        {
                            if (i == 0)
                            {
                                consoleOutBox.Text += jsonArray[i].ToString() + "\t\t\t";
                            }
                            else
                            {
                                consoleOutBox.Text += jsonArray[i].ToString() + "\t\t\t";
                            }
                        }

                        jsonArray           = (JArray)parseResults.SelectToken("points");
                        consoleOutBox.Text += "\n";

                        for (int i = 0; i < jsonArray.Count; i++)
                        {
                            for (int j = 0; j < rowCount; j++)
                            {
                                if (j == 0)
                                {
                                    consoleOutBox.Text += PlottingClass.UnixTimeConverter(Convert.ToDouble(jsonArray[i][j].ToString())).ToString() + "\t\t\t";
                                }
                                else
                                {
                                    consoleOutBox.Text += jsonArray[i][j].ToString() + "\t\t\t";
                                }
                            }

                            consoleOutBox.Text += "\n";
                        }

                        consoleOutBox.Text += "\n";
                        consoleInBox.Text   = "";
                    }
                    catch (Exception)
                    {
                        consoleOutBox.Text += "UNRECOGNIZED COMMAND\n\n";

                        // Saving input for the history reference
                        consoleHistory.Insert(moduloCounter % HISTORY_LIMIT, consoleInBox.Text);
                        moduloCounter++;
                        historyCounter    = consoleHistory.Count;
                        consoleInBox.Text = "";
                    }
                }
            }
        }