using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions; namespace FCC_Uber_MDX_Configurator { public partial class AddNewEmailVoteForm : Form { public string _returnOptionString = ""; public string _returnToString = ""; public AddNewEmailVoteForm(string input_options, string input_to) { InitializeComponent(); if (input_to != "") { TXT_To.Text = input_to; } InterpretOptionString(input_options); } public void InterpretOptionString(string optionString) { string[] _opts = optionString.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries); if (_opts.Length >= 1) { TXT_Subject.Text = _opts[0]; if (_opts.Length >= 2) { TXT_Body_Beg.Text = _opts[1]; if (_opts.Length >= 3) { TXT_Body_End.Text = _opts[2]; if (_opts.Length >= 4) { COMBO_MONITORTYPE.Text = _opts[3]; if (_opts.Length >= 5) { COMBO_MONITOR_ID.Text = _opts[4]; } } } } } } private void COMBO_MONITOR_TYPE_SelectedValueChanged(object sender, EventArgs e) { COMBO_MONITOR_ID.Items.Clear(); COMBO_MONITOR_ID.SelectedText = ""; COMBO_MONITOR_ID.Enabled = false; ComboBox _combo = (ComboBox)sender; if (_combo.SelectedItem == null || _combo.SelectedItem.ToString() == "") { return; } List _possibilites = new List(); switch (_combo.SelectedItem.ToString().ToLower()) { case "variable": { foreach (GlobalStaticClass._GlobalVariableClass _var in GlobalStaticClass._Global_List_Variables) { _possibilites.Add(_var._id); } } break; case "analogue input": { foreach (GlobalStaticClass._GlobalAnalogueInputClass _ain in GlobalStaticClass._Global_List_AnalogueInputs) { _possibilites.Add(_ain.id); } } break; case "digital output": { foreach (GlobalStaticClass._GlobalDigitalOutputClass _doc in GlobalStaticClass._Global_List_DigitalOutputs) { _possibilites.Add(_doc.id); } } break; case "none": { _possibilites.Clear(); } break; default: break; } if (_possibilites.Count > 0) { COMBO_MONITOR_ID.Enabled = true; COMBO_MONITOR_ID.Items.AddRange(_possibilites.ToArray()); COMBO_MONITOR_ID.Text = ""; COMBO_MONITOR_ID.Text = _possibilites[0]; } } #region Verify a TextBox is not Blank private void Leave_VerifyTXTIsNotBlank(object sender, EventArgs e) { try { TextBox _senderBox = (TextBox)sender; if (_senderBox.Text == "") { throw new Exception(); } } catch (Exception) { ErrorForm _tempErrorForm = new ErrorForm("Empty Field", "This field cannot be left empty."); _tempErrorForm.ShowDialog(); } } #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 private void BTN_SAVE_Click(object sender, EventArgs e) { while (TXT_Body_Beg.Text.Contains("::")) { TXT_Body_Beg.Text = TXT_Body_Beg.Text.Replace("::", ":"); } while (TXT_Body_End.Text.Contains("::")) { TXT_Body_End.Text = TXT_Body_End.Text.Replace("::", ":"); } while(TXT_Subject.Text.Contains("::")) { TXT_Subject.Text = TXT_Subject.Text.Replace("::", ":"); } if (!Regex.IsMatch(TXT_To.Text, GlobalStaticClass.MatchEmailPattern)) { (new ErrorForm("Invalid Email", "The email address provided is not recognized as being valid")).ShowDialog(); TXT_To.Focus(); this.DialogResult = DialogResult.None; return; } _returnOptionString = TXT_Subject.Text + "::" + TXT_Body_Beg.Text + "::" + TXT_Body_End.Text + "::" + COMBO_MONITORTYPE.Text + "::" + COMBO_MONITOR_ID.Text; _returnToString = TXT_To.Text; this.DialogResult = DialogResult.OK; } } }