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 GlobalPropertiesForm : Form { #region Initialize public GlobalPropertiesForm() { InitializeComponent(); SetupCurrentValues(); } #endregion #region Setup Current Values private void SetupCurrentValues() { TXT_AUTHOR.Text = GlobalStaticClass._GlobalPropertiesClass._author; string[] _tempVersions = GlobalStaticClass._GlobalPropertiesClass._versionRequired.Split(new char[] { '.' }); if (_tempVersions.Length != 4) { ErrorForm _tempErrorForm = new ErrorForm("Version Number", "The current version number is not parseable. The minimum Uber edition version number has been substituted instead."); _tempErrorForm.ShowDialog(); TXT_VERSION_0.Text = "3"; TXT_VERSION_1.Text = "0"; TXT_VERSION_2.Text = "0"; TXT_VERSION_3.Text = "0"; } else { TXT_VERSION_0.Text = _tempVersions[0]; TXT_VERSION_1.Text = _tempVersions[1]; TXT_VERSION_2.Text = _tempVersions[2]; TXT_VERSION_3.Text = _tempVersions[3]; } } #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 Number is entered in TextBox private 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 Author Field is Valid private void Leave_VerifyAuthorIsValid(object sender, EventArgs e) { try { TextBox _senderBox = (TextBox)sender; if (_senderBox.Text == "") { ErrorForm _tempErrorForm = new ErrorForm("Author's 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 Save Button Clicked private void BTN_SAVE_Click(object sender, EventArgs e) { try { if (TXT_AUTHOR.Text != null) { GlobalStaticClass._GlobalPropertiesClass._author = TXT_AUTHOR.Text; } else { ErrorForm _tempErrorForm = new ErrorForm("Author's Name", "The value you entered is not valid"); _tempErrorForm.ShowDialog(); return; } try { int[] _tempIntArray = new int[4]; if (!int.TryParse(TXT_VERSION_0.Text, out _tempIntArray[0]) || int.TryParse(TXT_VERSION_1.Text, out _tempIntArray[1]) || int.TryParse(TXT_VERSION_2.Text, out _tempIntArray[2]) || int.TryParse(TXT_VERSION_3.Text, out _tempIntArray[3])) { GlobalStaticClass._GlobalPropertiesClass._versionRequired = _tempIntArray[0] + "." + _tempIntArray[1] + "." + _tempIntArray[2] + "." + _tempIntArray[3]; } } catch (Exception) { ErrorForm _tempErrorForm = new ErrorForm("Version Parsing Error", "The version number is non-parceable"); _tempErrorForm.ShowDialog(); return; } } 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(); return; } this.DialogResult = DialogResult.OK; this.Close(); } #endregion #region Cancel Button Clicked private void BTN_CANCEL_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } #endregion } }