示例#1
0
 public void insertFrequency(FrequencySettings fs)
 {
     try
     {
         connection = new SqlConnection(connectionStringPrime);
         if (connection.State != ConnectionState.Open)
         {
             connection.Open();
         }
         command             = new SqlCommand(QueryBuilder.procInsertFreq, connection);
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.Add(new SqlParameter(QueryBuilder.procParamInsertFreqDate, String.Format("{0:yyyy-MM-dd HH:mm:ss}", fs.FreqDate)));
         command.Parameters.Add(new SqlParameter(QueryBuilder.procParamInsertFreqValue, fs.Frequency));
         command.ExecuteNonQuery();
     }
     catch (Exception)
     {
         FileHandler   file  = new FileHandler("FileError.csv");
         List <string> error = new List <string>();
         error.Add("A Critical error occurred at:" + DateTime.UtcNow.ToShortDateString());
         file.WriteToTxt(error);
     }
     finally
     {
         connection.Close();
     }
 }
示例#2
0
        public async Task SetFrequencySettingsAsync(FrequencySettings settings, OnSetFrequencySettingsDelegate onSetFrequencySettings)
        {
            _frequencySettingsToSet = settings ?? throw new ArgumentNullException(nameof(settings));
            _onSetFrequencySettings = onSetFrequencySettings ?? throw new ArgumentNullException(nameof(onSetFrequencySettings));

            // Checking if frequency settings changed
            _getFrequencyCommand.SetResponseDelegate(OnGetFrequencyResponse_SetFrequencyPathway);
            _getFrequencyCommand.SendGetFrequencyCommand();
        }
示例#3
0
        private void btnSaveTimeInterval_Click(object sender, EventArgs e)
        {
            int    timeInterval = Convert.ToInt32(nudTimeInterval.Value);
            string message      = "Are you sure you want to change the time interval to " + timeInterval + " minutes ?";

            if (MessageBox.Show(message, "Change Time Interval", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                FrequencySettings frequencySettings = new FrequencySettings(DateTime.Now, timeInterval);
                frequencySettings.newFrequency();

                string successMessage = "The time interval has been successfully changed. You will now receive new data for all sensors in " + timeInterval + " minute intervals.";
                MessageBox.Show(successMessage, "Successful Update of Time Interval", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#4
0
        private void frmMainDashboard_Load(object sender, EventArgs e)
        {
            btnDashboard.BackColor = Color.FromArgb(58, 131, 79);

            FrequencySettings frequency = new FrequencySettings();

            // Display the current data retrieval interval as default value in the numeric
            // spinner.
            nudTimeInterval.Value       = frequency.getFrequency();
            btnSaveTimeInterval.Visible = false;

            t = new System.Threading.Thread(DoThisAllTheTime);
            t.Start();

            timer.Start();
            continueThread = true;
        }
示例#5
0
        public List <FrequencySettings> getAllFrequencySettings()
        {
            int y = 0, m = 0, d = 0;
            List <FrequencySettings> freqs = new List <FrequencySettings>();
            DataTable data = readDataFromDB("SELECT * FROM [dbo].[tblUpdateFrequency]");

            foreach (DataRow item in data.Rows)
            {
                string[] dateSections = item["FreqSetDate"].ToString().Split('-');
                y = Convert.ToInt32(dateSections[0]);
                m = Convert.ToInt32(dateSections[1]);
                d = Convert.ToInt32(dateSections[2]);
                DateTime          date = new DateTime(y, m, d);
                FrequencySettings fs   = new FrequencySettings(date, Convert.ToInt32(item["Frequency"].ToString()));
                freqs.Add(fs);
            }
            return(freqs);
        }
        public frmTankSensorTemplate(List <Sensor> sensors)
        {
            InitializeComponent();

            foreach (Sensor item in sensors)
            {
                lblTankName.Text = item.Location.ToUpper() + " - Live Graphs";
                if (item.Type == "Temperature")
                {
                    chartTemperature.Series.Add(item.Location.ToUpper());
                    chartTemperature.Series[item.Location.ToUpper()].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
                    chartTemperature.Series[item.Location.ToUpper()].Color     = Color.Red;


                    List <SensorReading> allReadings = new List <SensorReading>();
                    SensorReading        reading     = new SensorReading();
                    allReadings = reading.getDayReadings(item);

                    int currentfrequency = 0;

                    FrequencySettings frequencySettings = new FrequencySettings();
                    currentfrequency = frequencySettings.getFrequency() * 60;

                    List <SensorReading> readingInTimeInterval = new List <SensorReading>();

                    foreach (SensorReading read in allReadings)
                    {
                        int time = read.Date.Minute;
                        if (time % (currentfrequency / 60) == 0)
                        {
                            readingInTimeInterval.Add(read);
                        }
                    }

                    foreach (SensorReading readInterval in readingInTimeInterval)
                    {
                        chartTemperature.ChartAreas[0].AxisY.Minimum = Convert.ToDouble(readInterval.ReadingVal);
                        chartTemperature.Series[item.Location.ToUpper()].Points.AddY(Convert.ToDouble(readInterval.ReadingVal));
                    }
                }

                if (item.Type == "pH")
                {
                    chartPH.Series.Add(item.Location.ToUpper());
                    chartPH.Series[item.Location.ToUpper()].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
                    chartPH.Series[item.Location.ToUpper()].Color     = Color.DarkBlue;

                    List <SensorReading> allReadings = new List <SensorReading>();
                    SensorReading        reading     = new SensorReading();
                    allReadings = reading.getDayReadings(item);

                    int currentfrequency = 0;

                    FrequencySettings frequencySettings = new FrequencySettings();
                    currentfrequency = frequencySettings.getFrequency() * 60;

                    List <SensorReading> readingInTimeInterval = new List <SensorReading>();

                    foreach (SensorReading read in allReadings)
                    {
                        int time = read.Date.Minute;
                        if (time % (currentfrequency / 60) == 0)
                        {
                            readingInTimeInterval.Add(read);
                        }
                    }

                    foreach (SensorReading readInterval in readingInTimeInterval)
                    {
                        chartPH.ChartAreas[0].AxisY.Minimum = Convert.ToDouble(readInterval.ReadingVal);
                        chartPH.Series[item.Location.ToUpper()].Points.AddY(Convert.ToDouble(readInterval.ReadingVal));
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// DoThisAllTheTime()
        /// This method is used to sync the text file with the database. Every minute it checks whether
        /// new sensor readings have been written to the text files and if new readings occured then those readings
        /// will be added to the database.
        ///
        /// While the new readings are being written to the database it also checks to see if the readings
        /// are still within the specified critical ranges. If the readings fall outside of the critical
        /// range then an email is send to notify the users.
        /// </summary>
        public void DoThisAllTheTime()
        {
            int               currentfrequency  = 0;
            Sensor            sensor            = new Sensor();
            List <Sensor>     allSensors        = sensor.getAllSensors();
            FrequencySettings frequencySettings = new FrequencySettings();

            currentfrequency = frequencySettings.getFrequency() * 60; // change to seconds

            while (continueThread)
            {
                //you need to use Invoke because the new thread can't access the UI elements directly
                MethodInvoker mi = delegate() { this.Text = DateTime.Now.ToString(); };
                this.Invoke(mi);

                if (second % 60 == 0) // write sensor readings in database from textfile each minute
                {
                    foreach (Sensor item in allSensors)
                    {
                        SensorReading reading = new SensorReading();
                        reading.newSensorReading(item);
                    }
                }

                if (second % currentfrequency == 0)
                {
                    foreach (Sensor item in allSensors)
                    {
                        List <SensorReading> allReadings = new List <SensorReading>(); // retrieve a list of sensor readings in 24 hour period

                        SensorReading reading = new SensorReading();
                        allReadings = reading.getDayReadings(item);

                        List <SensorReading> readingInTimeInterval = new List <SensorReading>();
                        Notifications        notify = new Notifications();
                        decimal topValue            = notify.getTopvalue(item.SensorID);
                        decimal bottomValue         = notify.getBottomValue(item.SensorID);

                        foreach (SensorReading read in allReadings)
                        {
                            int time = read.Date.Minute;
                            if (time % (currentfrequency / 60) == 0)
                            {
                                readingInTimeInterval.Add(read);
                            }
                        }

                        foreach (SensorReading readInInterval in readingInTimeInterval)
                        {
                            if (readInInterval.ReadingVal < bottomValue)
                            {
                                Contact       contact   = new Contact();
                                List <string> allEmails = contact.getEmailsToReceiveNotification(item.SensorID); // get list of emails for this sensor

                                foreach (string mail in allEmails)
                                {
                                    notify.mailNotifcation(mail, item.Location, item.SensorName, "Bottom", (bottomValue - readInInterval.ReadingVal));
                                }
                            }

                            if (readInInterval.ReadingVal > topValue)
                            {
                                Contact       contact   = new Contact();
                                List <string> allEmails = contact.getEmailsToReceiveNotification(item.SensorID); // get list of emails for this sensor

                                foreach (string mail in allEmails)
                                {
                                    notify.mailNotifcation(mail, item.Location, item.SensorName, "Top", (readInInterval.ReadingVal - topValue));
                                }
                            }
                        }
                    }
                }
            }
        }