using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace FCC_Uber_MDX_Configurator { public partial class AddLoggingForm : Form { #region Initialization public AddLoggingForm() { InitializeComponent(); SetupInitialization(); this.Update(); } public AddLoggingForm(string input_name, string input_monitor_type, string input_monitor_id, string input_record_timer, string input_record_object, string input_default_state, string input_holdopen, string input_store_before_dump, string input_data_name, string input_file_name) { InitializeComponent(); SetupInitialization(); TXT_Name.Text = input_name; TXT_DATANAME.Text = input_data_name; TXT_LOGFILENAME.Text = input_file_name; TXT_STOREBEFOREDUMP.Text = input_store_before_dump; if (!SetupSelectComboBox(COMBO_MONITORTYPE, input_monitor_type) || !SetupSelectComboBox(COMBO_MONITORID, input_monitor_id) || !SetupSelectComboBox(COMBO_RECORDOBJECT, input_record_object) || !SetupSelectComboBox(COMBO_TIMER, input_record_timer) || !SetupSelectComboBox(COMBO_DEFAULTSTATE, input_default_state) || !SetupSelectComboBox(COMBO_HOLDSTREAMOPEN, input_holdopen)) { //There was an error... } this.Update(); } public static bool SetupSelectComboBox(ComboBox input_comboBox, string input_searchItem) { for (int i = 0; i < input_comboBox.Items.Count; i++) { if (input_comboBox.Items[i].ToString().ToLower() == input_searchItem.ToLower()) { input_comboBox.Text = input_comboBox.Items[i].ToString(); input_comboBox.SelectedIndex = i; return true; } } return false; } #endregion #region Setup Combo Boxes public void SetupInitialization() { COMBO_MONITORID.Items.Clear(); foreach (GlobalStaticClass._GlobalDigitalOutputClass _DO in GlobalStaticClass._Global_List_DigitalOutputs) { COMBO_MONITORID.Items.Add(_DO.id); } foreach (GlobalStaticClass._GlobalAnalogueInputClass _AI in GlobalStaticClass._Global_List_AnalogueInputs) { COMBO_MONITORID.Items.Add(_AI.id); } foreach (GlobalStaticClass._GlobalVariableClass _VAR in GlobalStaticClass._Global_List_Variables) { COMBO_MONITORID.Items.Add(_VAR._id); } COMBO_MONITORID.SelectedIndex = 0; } #endregion #region Verify Text Field is Valid private void Leave_VerifyTXTIsNotEmpty(object sender, EventArgs e) { try { TextBox _senderBox = (TextBox)sender; if (_senderBox.Text == "") { ErrorForm _tempErrorForm = new ErrorForm(_senderBox.Name, "The value you entered is not valid"); _tempErrorForm.ShowDialog(); _senderBox.Focus(); } } catch (Exception) { ErrorForm _tempErrorForm = new ErrorForm("Unknown Error", "There was an unexpected untraceable error caught in the application. If you can reproduce this error, please let me know at FusionControlCentre@gmail.com"); _tempErrorForm.ShowDialog(); } } #endregion #region Verify a Number is entered in TextBox public void Leave_VerifyTXTHasAValidNumber(object sender, EventArgs e) { try { TextBox _senderBox = (TextBox)sender; int _tempInt; if (!int.TryParse(_senderBox.Text, out _tempInt)) { ErrorForm _tempErrorForm = new ErrorForm(_senderBox.Name, "The value you entered is not valid"); _tempErrorForm.ShowDialog(); _senderBox.Focus(); } } catch (Exception) { ErrorForm _tempErrorForm = new ErrorForm("Unknown Error", "There was an unexpected untraceable error caught in the application. If you can reproduce this error, please let me know at FusionControlCentre@gmail.com"); _tempErrorForm.ShowDialog(); } } #endregion #region Verify Textboxes Only get Number Inputs private void KeyDown_IsANumber(object sender, KeyEventArgs e) { if (!char.IsDigit((char)e.KeyValue) && e.KeyData != Keys.Back && e.KeyData != Keys.Left && e.KeyData != Keys.Right && e.KeyData != Keys.Decimal && e.KeyValue != 190 && !e.KeyCode.Equals(Keys.NumPad0) && !e.KeyCode.Equals(Keys.NumPad1) && !e.KeyCode.Equals(Keys.NumPad2) && !e.KeyCode.Equals(Keys.NumPad3) && !e.KeyCode.Equals(Keys.NumPad4) && !e.KeyCode.Equals(Keys.NumPad5) && !e.KeyCode.Equals(Keys.NumPad6) && !e.KeyCode.Equals(Keys.NumPad7) && !e.KeyCode.Equals(Keys.NumPad8) && !e.KeyCode.Equals(Keys.NumPad9)) { e.SuppressKeyPress = true; } return; } #endregion #region Verify a Proper Item has Been Selected in Combo Box private void Leave_VerifyCOMBOIsValid(object sender, EventArgs e) { try { ComboBox _senderBox = (ComboBox)sender; if (!_senderBox.Items.Contains(_senderBox.Text)) { (new ErrorForm(_senderBox.Name, "The value you selected or entered is not valid")).ShowDialog(); _senderBox.Focus(); _senderBox.SelectedIndex = 0; } } catch (Exception) { ErrorForm _tempErrorForm = new ErrorForm("Unknown Error", "There was an unexpected untraceable error caught in the application. If you can reproduce this error, please let me know at FusionControlCentre@gmail.com"); _tempErrorForm.ShowDialog(); } } #endregion #region Cancel Button Clicked private void BTN_CANCEL_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } #endregion #region Save Button Clicked private void BTN_SAVE_Click(object sender, EventArgs e) { int _tempHistory; if (TXT_DATANAME.Text == "" || TXT_LOGFILENAME.Text == "" || TXT_Name.Text == "" || TXT_STOREBEFOREDUMP.Text == "" || !int.TryParse(TXT_STOREBEFOREDUMP.Text, out _tempHistory)) { (new ErrorForm("Invalid Text", "One of the text areas has an invalid entry")).ShowDialog(); return; } if(COMBO_DEFAULTSTATE.SelectedItem == null || COMBO_HOLDSTREAMOPEN.SelectedItem == null || COMBO_MONITORID.SelectedItem == null || COMBO_MONITORTYPE.SelectedItem == null || COMBO_RECORDOBJECT.SelectedItem == null || COMBO_TIMER.SelectedItem == null) { (new ErrorForm("Invalid Combo Selection", "One of the drop down boxes has an invalid entry")).ShowDialog(); return; } bool isFound = false; switch (COMBO_MONITORTYPE.SelectedItem.ToString().ToLower()) { case "digital output": { for (int i = 0; i < GlobalStaticClass._Global_List_DigitalOutputs.Count; i++) { if (GlobalStaticClass._Global_List_DigitalOutputs[i].id.ToLower() == COMBO_MONITORID.SelectedItem.ToString().ToLower()) { isFound = true; break; } } } break; case "analogue input": { for (int i = 0; i < GlobalStaticClass._Global_List_AnalogueInputs.Count; i++) { if (GlobalStaticClass._Global_List_AnalogueInputs[i].id.ToLower() == COMBO_MONITORID.SelectedItem.ToString().ToLower()) { isFound = true; break; } } } break; case "variable": { for (int i = 0; i < GlobalStaticClass._Global_List_Variables.Count; i++) { if (GlobalStaticClass._Global_List_Variables[i]._id.ToLower() == COMBO_MONITORID.SelectedItem.ToString().ToLower()) { isFound = true; break; } } } break; default: //Error break; } if (!isFound) { (new ErrorForm("Inconsistant Type", "The ID to monitor [" + COMBO_MONITORID.SelectedItem.ToString() + "] was not found in the collection of " + COMBO_MONITORTYPE.SelectedItem.ToString() + "'s.")).ShowDialog(); return; } this.DialogResult = DialogResult.OK; } #endregion #region Get the Data Back public List GetTheLogDataBack() { int _tempHistory; if (TXT_DATANAME.Text == "" || TXT_LOGFILENAME.Text == "" || TXT_Name.Text == "" || TXT_STOREBEFOREDUMP.Text == "" || !int.TryParse(TXT_STOREBEFOREDUMP.Text, out _tempHistory)) { (new ErrorForm("Invalid Text", "One of the text areas has an invalid entry")).ShowDialog(); return null; } if (COMBO_DEFAULTSTATE.SelectedItem == null || COMBO_HOLDSTREAMOPEN.SelectedItem == null || COMBO_MONITORID.SelectedItem == null || COMBO_MONITORTYPE.SelectedItem == null || COMBO_RECORDOBJECT.SelectedItem == null || COMBO_TIMER.SelectedItem == null) { (new ErrorForm("Invalid Combo Selection", "One of the drop down boxes has an invalid entry")).ShowDialog(); return null; } return new List(new object[] { (object)TXT_Name.Text, (object)COMBO_MONITORTYPE.SelectedItem, (object)COMBO_MONITORID.SelectedItem, (object)COMBO_TIMER.SelectedItem, (object)COMBO_RECORDOBJECT.SelectedItem, (object)COMBO_DEFAULTSTATE.SelectedItem, (object)COMBO_HOLDSTREAMOPEN.SelectedItem, (object)_tempHistory, (object)TXT_DATANAME.Text, (object)TXT_LOGFILENAME.Text }); } #endregion #region Help private void BTN_HELP_NAME_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Logging", "Name"); } private void BTN_HELP_MONITORTYPE_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Logging", "Monitor Type"); } private void BTN_HELP_MONITORID_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Logging", "Monitor ID"); } private void BTN_HELP_TIMER_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Logging", "Record Timer"); } private void BTN_HELP_RECORDOBJECT_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Logging", "Record Object"); } private void BTN_DEFAULTSTATE_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Logging", "Default State"); } private void BTN_HELP_HOLDSTREAMOPEN_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Logging", "Hold Stream Open"); } private void BTN_HELP_STOREBEFOREDUMP_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Logging", "Store Before Dump"); } private void BTN_HELP_DATANAME_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Logging", "Data Name"); } private void BTN_HELP_LOGFILENAME_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Logging", "File Name"); } #endregion } }