/// <summary> /// Method for saving to an excel spreadsheet /// uses filename and all custom chart options as parameters fro the processing application /// processing application called to actually save the chart /// </summary> /// <param name="filename">Filename for the chart as a string</param> private void SaveCustomChart(String filename) { Chamber c = GetCustomChartPickerValue(); DateTime startDate = GetStartDatePickerValue(); DateTime endDate = GetEndDatePickerValue(); Boolean averageValues = GetCustomChartAverage(); if (ValidateDates(startDate, endDate)) { String args = "produceGraph " + c.ID + " \"" + startDate.ToString("yyyy-MM-dd HH:mm:ss") + "\" \"" + endDate.ToString("yyyy-MM-dd HH:mm:ss") + "\" " + averageValues + " true \"" + filename + "\""; if (DeserialiseProcessorOutput(CallProcessor(args), true)) { String message = "Chart saved to " + filename; String caption = "Info"; MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show(message, caption, buttons); } else { String message = "Error saving chart to " + filename; String caption = "Error"; MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show(message, caption, buttons); } } else { String message = "Start date cannot be after end date"; String caption = "Error"; MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show(message, caption, buttons); } }
/// <summary> /// updates all field in form /// </summary> private void UpdateFields() { Chamber c = (Chamber)chamberIDPicker.SelectedValue; newChamberName.Text = c.Name; newChamberDescription.Text = c.Description; }
/// <summary> /// Method to handle form submission. Valiedates input then calls processing application /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void submitButton_Click(object sender, EventArgs e) { Sensor s; int sensorID = 0; if (sensorPicker.SelectedValue != null) { s = (Sensor)sensorPicker.SelectedValue; sensorID = s.ID; } String sensorName = sensorNameBox.Text; String sensorAddress = sensorIPBox.Text; String sensorType = typePicker.SelectedIndex.ToString(); String sensorScale = scaleBox.Text; String sensorOffset = offsetBox.Text; Chamber chamber = (Chamber)chamberPicker.SelectedValue; String sensorPort = portBox.Text; String sensorRegister = (registerPicker.SelectedIndex + 1).ToString(); Boolean sensorEnabled = enabledBox.Checked; String args = ""; if (ValidateInput(sensorPort, sensorType, sensorScale, sensorOffset, sensorRegister, chamber, sensorAddress)) { if (editExistingButton.Checked == true) { args = "editSensor " + sensorID.ToString() + " \"" + sensorName + "\" " + sensorEnabled.ToString() + " " + sensorType + " " + chamber.ID.ToString() + " \"" + sensorAddress + "\" " + sensorPort + " " + sensorRegister + " " + sensorScale + " " + sensorOffset; } else { args = "addSensor \"" + sensorAddress + "\" " + sensorPort + " " + sensorType + " " + chamber.ID.ToString() + " " + sensorRegister + " " + sensorScale + " " + sensorOffset + " \"" + sensorName + "\" " + sensorEnabled.ToString(); } Boolean success = DeserialiseProcessorOutput(CallProcessor(args)); if (success) { String message = "Success"; String caption = "Success"; MessageBoxButtons btns = MessageBoxButtons.OK; DialogResult result = MessageBox.Show(message, caption, btns); if (result == DialogResult.OK) { this.Dispose(); } } else { String message = "An error has occured with the processing application"; String caption = "Error"; MessageBoxButtons btns = MessageBoxButtons.OK; MessageBox.Show(message, caption, btns); } } }
/// <summary> /// Method to get a chamber object for a given ID /// </summary> /// <param name="id">integer value for the chamber ID</param> /// <returns>returns the chamber object, null if chamber does not exist</returns> private Chamber GetChamberByID(int id) { Chamber toReturn = null; for (int i = 0; i < chambers.Length; i++) { if (chambers[i].ID == id) { toReturn = chambers[i]; } } return(toReturn); }
/// <summary> /// method to return chamber object for a given ID /// </summary> /// <param name="chamberID">the integer ID of the chamber to search for</param> /// <returns>the chamber object if it exists, null if chamber does not exist</returns> private Chamber GetChamberByID(int chamberID) { Chamber c = null; for (int i = 0; i < chambers.Length; i++) { if (chambers[i].ID.Equals(chamberID)) { c = chambers[i]; } } return(c); }
/// <summary> /// Method for refreshing the live chart. /// calls the processing application and calls the method for setting the chart data /// </summary> private void RefreshLiveChart() { DataSet[] liveChartData = null; Chamber c = GetLiveChartPickerValue(); DateTime endDate = DateTime.Now; DateTime startDate = endDate.AddHours(-liveChartRange); Boolean averageValues = GetLiveChartAverage(); String processorArgs = "produceGraph " + c.ID + " \"" + startDate.ToString("yyyy-MM-dd HH:mm:ss") + "\" \"" + endDate.ToString("yyyy-MM-dd HH:mm:ss") + "\" " + averageValues + " false"; liveChartData = DeserialiseProcessorOutput(CallProcessor(processorArgs)); if (liveChartData != null || liveChartData.Length != 0) { this.SetLiveChart(liveChartData); } }
/// <summary> /// Method for updating the custom chart /// calls processing application and converts output into dataset /// dataset is passed to method which sets the custom chart data /// </summary> private void UpdateCustomChart() { DataSet[] customChartData = null; Chamber c = (Chamber)GetCustomChartPickerValue(); DateTime startDate = GetStartDatePickerValue(); DateTime endDate = GetEndDatePickerValue(); Boolean averageValues = GetCustomChartAverage(); String args = "produceGraph " + c.ID + " \"" + startDate.ToString("yyyy-MM-dd HH:mm:ss") + "\" \"" + endDate.ToString("yyyy-MM-dd HH:mm:ss") + "\" " + averageValues.ToString().ToLower() + " false"; customChartData = DeserialiseProcessorOutput(CallProcessor(args)); if (customChartData != null) { SetCustomChart(customChartData); } }
/// <summary> /// Validates custom chart options then calls chart update function /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void updateButton_Click(object sender, EventArgs e) { DataSet[] customChartData = null; Chamber c = (Chamber)GetCustomChartPickerValue(); DateTime startDate = GetStartDatePickerValue(); DateTime endDate = GetEndDatePickerValue(); Boolean averageValues = GetCustomChartAverage(); if (ValidateDates(startDate, endDate)) { String args = "produceGraph " + c.ID + " \"" + startDate.ToString("yyyy-MM-dd HH:mm:ss") + "\" \"" + endDate.ToString("yyyy-MM-dd HH:mm:ss") + "\" " + averageValues.ToString().ToLower() + " false"; Task customChartTask = new Task(() => UpdateCustomChart()); customChartTask.Start(); } else { String message = "Start date cannot be after end date"; String caption = "Error"; MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show(message, caption, buttons); } }
/// <summary> /// Method for validating form input. /// checks valid IP address /// checks for positive, integer port value /// checks for parsable scale and offset values /// </summary> /// <param name="sensorPort"> the value of the sensor port input box</param> /// <param name="sensorType">the value of the sensor type input box</param> /// <param name="sensorScale">the value of the sensor scale input box</param> /// <param name="sensorOffset">the value of the sensor offset input box</param> /// <param name="sensorRegister">the value of the sensor register picker</param> /// <param name="chamber">the value of the chamber selection box</param> /// <param name="sensorAddress">the value of the sensor IP address input box</param> /// <returns>returns true if all values are valid</returns> private Boolean ValidateInput(String sensorPort, String sensorType, String sensorScale, String sensorOffset, String sensorRegister, Chamber chamber, String sensorAddress) { int register = 0; int type = 0; int port = 0; try { port = int.Parse(sensorPort); type = int.Parse(sensorType); double.Parse(sensorScale); double.Parse(sensorOffset); register = int.Parse(sensorRegister); System.Net.IPAddress.Parse(sensorAddress); }catch (Exception e) { MessageBoxButtons btns = MessageBoxButtons.OK; String caption = "Error"; MessageBox.Show(e.Message, caption, btns); return(false); } if (register > 0 && register <= 8 && type >= 0 && type <= 3 && chamber != null && port > 0) { return(true); } else { return(false); } }
/// <summary> /// Action after submit button is clicked. Processing application called to delete currently selected item /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void submitButton_Click(object sender, EventArgs e) { if (deleteChamberOption.Checked == true) { Chamber c = (Chamber)toDeletePicker.SelectedValue; String message = "This action will delete all sensors and sensor data associated with" + c.Name + ", Continue?"; String caption = "Warning"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result = MessageBox.Show(message, caption, buttons); if (result == DialogResult.Yes) { if (DeserialiseProcessorOutput(CallProcessor("removeChamber " + c.ID))) { String message2 = "Success"; String caption2 = "Success"; MessageBoxButtons buttons2 = MessageBoxButtons.OK; DialogResult result2 = MessageBox.Show(message2, caption2, buttons2); if (result2 == DialogResult.OK) { this.Dispose(); } } else { String message2 = "An error has occured with the processing application"; String caption2 = "Error"; MessageBoxButtons buttons2 = MessageBoxButtons.OK; MessageBox.Show(message2, caption2, buttons2); } } } else { Sensor s = (Sensor)toDeletePicker.SelectedValue; String message = "This action will delete all data associated with" + s.Description + ", Continue?"; String caption = "Warning"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result = MessageBox.Show(message, caption, buttons); if (result == DialogResult.Yes) { if (DeserialiseProcessorOutput(CallProcessor("removeSensor " + s.ID))) { String message2 = "Success"; String caption2 = "Success"; MessageBoxButtons buttons2 = MessageBoxButtons.OK; DialogResult result2 = MessageBox.Show(message2, caption2, buttons2); if (result2 == DialogResult.OK) { this.Dispose(); } } else { String message2 = "An error has occured with the processing application"; String caption2 = "Error"; MessageBoxButtons buttons2 = MessageBoxButtons.OK; MessageBox.Show(message2, caption2, buttons2); } } } }