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 AddDigitialOutputForm : Form { #region Initialize public AddDigitialOutputForm() { InitializeComponent(); SetupBrainCombo(); } public AddDigitialOutputForm(string input_name, string input_brain, int input_port, string input_state) { InitializeComponent(); SetupBrainCombo(); TXT_Name.Text = input_name; TXT_Port.Text = input_port.ToString(); for (int i = 0; i < COMBO_ConnectedTo.Items.Count; i++) { if (COMBO_ConnectedTo.Items[i].ToString().ToLower() == input_brain.ToLower()) { COMBO_ConnectedTo.Text = COMBO_ConnectedTo.Items[i].ToString(); COMBO_ConnectedTo.SelectedIndex = i; break; } } for (int i = 0; i < COMBO_Default.Items.Count; i++) { if (COMBO_Default.Items[i].ToString().ToLower() == input_state.ToLower()) { COMBO_Default.Text = COMBO_Default.Items[i].ToString(); COMBO_Default.SelectedIndex = i; break; } } this.Text = "Edit Digital Output"; } private void SetupBrainCombo() { foreach (GlobalStaticClass._GlobalBrainClass _tempBrainClass in GlobalStaticClass._Global_List_Brains) { COMBO_ConnectedTo.Items.Add(_tempBrainClass._humanName); } COMBO_ConnectedTo.SelectedIndex = 0; } #endregion #region Verify Name Field is Valid private void Leave_VerifyNameIsValid(object sender, EventArgs e) { try { TextBox _senderBox = (TextBox)sender; if (_senderBox.Text == "") { ErrorForm _tempErrorForm = new ErrorForm("Invalid 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 Port TextBox public void Leave_VerifyTXTIsValid(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 _tempIntOut; if (TXT_Name.Text == "") { (new ErrorForm("Invalid Name", "The entered name is not valid")).ShowDialog(); return; } if (!int.TryParse(TXT_Port.Text, out _tempIntOut)) { (new ErrorForm("Invalid Port", "The entered port is not valid")).ShowDialog(); return; } if (COMBO_ConnectedTo.SelectedItem == null) { (new ErrorForm("Invalid Fusion Brain", "Please select a Fusion Brain from the dropdown menu")).ShowDialog(); return; } if (COMBO_Default.SelectedItem == null) { (new ErrorForm("Invalid Default State", "Please select a Default State from the dropdown menu")).ShowDialog(); return; } this.DialogResult = DialogResult.OK; } #endregion #region Get Digital Output Data public List GetDigitalOutputData() { int _tempIntOut; if (TXT_Name.Text == "" || !int.TryParse(TXT_Port.Text, out _tempIntOut) || COMBO_ConnectedTo.SelectedItem == null || COMBO_Default.SelectedItem == null) { return null; } return new List(new object[] { (object)TXT_Name.Text, (object)_tempIntOut, (object)COMBO_ConnectedTo.SelectedItem, (object)COMBO_Default.SelectedItem}); } #endregion #region Help private void BTN_HELP_NAME_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Digital Output", "Name"); } private void BTN_HELP_CONNECTEDTO_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Digital Output", "Connected To"); } private void BTN_HELP_PORT_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Digital Output", "Port"); } private void BTN_HELP_DEFAULTSTATE_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Digital Output", "Default State"); } #endregion } }