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 AddVariableForm : Form { #region Initialization public AddVariableForm() { InitializeComponent(); } public AddVariableForm(string input_name, object input_value) { InitializeComponent(); double _tempDbl; TXT_Name.Text = input_name; if (double.TryParse(input_value.ToString(), out _tempDbl)) { TXT_VALUE_NUMERIC.Text = _tempDbl.ToString() ; SetupSelectComboBox(COMBO_VARIABLE_TYPE, "numeric"); } else { SetupSelectComboBox(COMBO_VARIABLE_TYPE, "boolean"); SetupSelectComboBox(COMBO_VALUE_BOOLEAN, input_value.ToString()); } } public 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 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; double _tempDouble; if (!double.TryParse(_senderBox.Text, out _tempDouble)) { 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) { char c = (char)e.KeyValue; 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 Switch Boolean and Numeric Entry Boxes private void COMBO_VARIABLE_TYPE_SelectedIndexChanged(object sender, EventArgs e) { CheckEnableStateVariableType(); } private void CheckEnableStateVariableType() { if (COMBO_VARIABLE_TYPE.SelectedItem.ToString().ToLower() == "boolean") { COMBO_VALUE_BOOLEAN.Enabled = true; TXT_VALUE_NUMERIC.Enabled = false; } else if (COMBO_VARIABLE_TYPE.SelectedItem.ToString().ToLower() == "numeric") { COMBO_VALUE_BOOLEAN.Enabled = false; TXT_VALUE_NUMERIC.Enabled = true; } } #endregion #region Cancel Button Clicked private void BTN_CANCEL_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } #endregion #region OK Button Clicked private void BTN_SAVE_Click(object sender, EventArgs e) { double _tempDbl; if (TXT_Name.Text == "" || !double.TryParse(TXT_VALUE_NUMERIC.Text, out _tempDbl) || COMBO_VALUE_BOOLEAN.SelectedItem == null) { (new ErrorForm("Invalid Item", "One of the items you selected is invalid.")).ShowDialog(); return; } if (COMBO_VARIABLE_TYPE.SelectedItem.ToString().ToLower() == "boolean") { if (COMBO_VALUE_BOOLEAN.SelectedItem == null) { (new ErrorForm("Invalid Item", "You have selected a boolean object, but have not selected an intial value.")).ShowDialog(); return; } } this.DialogResult = DialogResult.OK; } #endregion #region Get Info Back public List GetVariableInfoBack() { double _tempDbl; if (TXT_Name.Text == "" || !double.TryParse(TXT_VALUE_NUMERIC.Text, out _tempDbl) || COMBO_VALUE_BOOLEAN.SelectedItem == null) { (new ErrorForm("Invalid Item", "One of the items you selected is invalid.")).ShowDialog(); } if (COMBO_VARIABLE_TYPE.SelectedItem.ToString().ToLower() == "boolean") { if (COMBO_VALUE_BOOLEAN.SelectedItem == null) { (new ErrorForm("Invalid Item", "You have selected a boolean object, but have not selected an intial value.")).ShowDialog(); } return new List(new object[] { (object)TXT_Name.Text, (object)COMBO_VALUE_BOOLEAN.SelectedItem.ToString() }); } _tempDbl = double.Parse(TXT_VALUE_NUMERIC.Text); return new List(new object[] { (object)TXT_Name.Text, (object)_tempDbl }); this.Close(); } #endregion private void BTN_HELP_NAME_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Variable", "Name"); } private void BTN_HELP_VALUE_NUMERIC_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Variable", "Value Numeric"); } private void BTN_HELP_VALUE_BOOL_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Variable", "Value Boolean"); } private void BTN_VARIABLE_TYPE_Click(object sender, EventArgs e) { GlobalStaticClass.FireHelpEvent("Add Variable", "Value Type"); } } }