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 AddDisplayButtonForm : Form { public GlobalStaticClass.FusionImage_DisplayButton CurrentDisplayButton = new GlobalStaticClass.FusionImage_DisplayButton(); public AddDisplayButtonForm() { InitializeComponent(); CurrentDisplayButton._name = GlobalStaticClass.FusionImage_DisplayButton.GetUniqueName(); InitializeSetup(); UpdateForm(); TXT_NAME.Text = CurrentDisplayButton._name; } public AddDisplayButtonForm(GlobalStaticClass.FusionImage_DisplayButton input_displayButton) { InitializeComponent(); CurrentDisplayButton = input_displayButton; TXT_NAME.Text = CurrentDisplayButton._name; TXT_SHOWSIZE_WIDTH.Text = CurrentDisplayButton._width.ToString(); TXT_SHOWSIZE_HEIGHT.Text = CurrentDisplayButton._height.ToString(); TXT_LOCATION_X.Text = CurrentDisplayButton._x.ToString(); TXT_LOCATION_Y.Text = CurrentDisplayButton._y.ToString(); TXT_Z_ORDER.Text = CurrentDisplayButton._z_order.ToString(); TXT_FONT_SIZE.Text = CurrentDisplayButton._font_size.ToString(); TXT_PRIMARY.Text = CurrentDisplayButton._textPrimary; TXT_SECONDARY.Text = CurrentDisplayButton._textSecondary; TXT_DISABLED.Text = CurrentDisplayButton._textDisabled; TXT_TIME_DOWN.Text = CurrentDisplayButton._Time_down.ToString(); TXT_TIME_UP.Text = CurrentDisplayButton._Time_up.ToString(); PANEL_PRIMARY_COLOUR.BackColor = CurrentDisplayButton._textPrimaryColour; PANEL_SECONDARY_COLOUR.BackColor = CurrentDisplayButton._textSecondaryColour; PANEL_DISABLED_COLOUR.BackColor = CurrentDisplayButton._textDisabledColour; UpdateForm(); InitializeSetup(); for (int i = 0; i < CHECKLIST_PAGES.Items.Count; i++) { int _pageParse = -1; if (int.TryParse(CHECKLIST_PAGES.Items[i].ToString(), out _pageParse)) { CHECKLIST_PAGES.SetItemChecked(i, CurrentDisplayButton._pages.Contains(_pageParse - 1)); } } for (int i = 0; i < COMBO_FONTS.Items.Count; i++) { if (COMBO_FONTS.Items[i].ToString().ToLower() == CurrentDisplayButton._font_name.ToLower()) { COMBO_FONTS.SelectedIndex = i; COMBO_FONTS.Text = CurrentDisplayButton._font_name; break; } } } private void InitializeSetup() { CHECKLIST_PAGES.Items.Clear(); for (int i = 0; i < GlobalStaticClass._Global_List_Graphics_PageList.Count; i++) { CHECKLIST_PAGES.Items.Add(((int)(i + 1)).ToString()); } COMBO_FONTS.Items.Clear(); foreach (GlobalStaticClass.PseudoFusionFont _font in GlobalStaticClass._Global_List_Graphics_Fonts) { COMBO_FONTS.Items.Add(_font.font_name); } } public void UpdateForm() { bool isAllSetup = true; if (CurrentDisplayButton._image_Primary != null && CurrentDisplayButton._path_Primary != null) { PICT_PREVIEW_PRIMARY.BackgroundImage = CurrentDisplayButton._image_Primary; PICT_PREVIEW_PRIMARY.Update(); LBL_SIZE_PRIMARY.Text = CurrentDisplayButton._image_Primary.Width + " x " + CurrentDisplayButton._image_Primary.Height; } else { isAllSetup = false; LBL_SIZE_PRIMARY.Text = "### x ###"; } if (CurrentDisplayButton._image_Secondary != null && CurrentDisplayButton._path_Secondary != null) { PICT_PREVIEW_SECONDARY.BackgroundImage = CurrentDisplayButton._image_Secondary; PICT_PREVIEW_SECONDARY.Update(); LBL_SIZE_SECONDARY.Text = CurrentDisplayButton._image_Secondary.Width + " x " + CurrentDisplayButton._image_Secondary.Height; } else { isAllSetup = false; LBL_SIZE_SECONDARY.Text = "### x ###"; } if (CurrentDisplayButton._image_Pushed != null && CurrentDisplayButton._path_Pushed != null) { PICT_PREVIEW_PRIMARY_PUSHED.BackgroundImage = CurrentDisplayButton._image_Pushed; PICT_PREVIEW_PRIMARY_PUSHED.Update(); LBL_SIZE_PUSHED.Text = CurrentDisplayButton._image_Pushed.Width + " x " + CurrentDisplayButton._image_Pushed.Height; } else { isAllSetup = false; LBL_SIZE_PUSHED.Text = "### x ###"; } if (CurrentDisplayButton._image_Disabled != null && CurrentDisplayButton._path_Disabled != null) { PICT_PREVIEW_DISABLED.BackgroundImage = CurrentDisplayButton._image_Disabled; PICT_PREVIEW_DISABLED.Update(); LBL_SIZE_DISABLED.Text = CurrentDisplayButton._image_Disabled.Width + " x " + CurrentDisplayButton._image_Disabled.Height; } else { isAllSetup = false; LBL_SIZE_DISABLED.Text = "### x ###"; } if (CurrentDisplayButton._MyVote != null) { TXT_VOTE_WHATTODO.Text = GlobalStaticClass.FormatAllCapsString(CurrentDisplayButton._MyVote._WhatToDo.ToString()); TXT_VOTE_TARGETID.Text = GlobalStaticClass.FormatAllCapsString(CurrentDisplayButton._MyVote._TargetID); TXT_VOTE_PRIORITY.Text = GlobalStaticClass.FormatAllCapsString(CurrentDisplayButton._MyVote._Priority.ToString()); TXT_VOTE_OPINION.Text = GlobalStaticClass.FormatAllCapsString(CurrentDisplayButton._MyVote._VoteOpinion); } else { TXT_VOTE_WHATTODO.Text = ""; TXT_VOTE_TARGETID.Text = ""; TXT_VOTE_PRIORITY.Text = ""; TXT_VOTE_OPINION.Text = ""; } if (CurrentDisplayButton._MyVote_UPCLICK != null) { TXT_VOTE_WHATTODO_UP.Text = GlobalStaticClass.FormatAllCapsString(CurrentDisplayButton._MyVote_UPCLICK._WhatToDo.ToString()); TXT_VOTE_TARGETID_UP.Text = GlobalStaticClass.FormatAllCapsString(CurrentDisplayButton._MyVote_UPCLICK._TargetID); TXT_VOTE_PRIORITY_UP.Text = GlobalStaticClass.FormatAllCapsString(CurrentDisplayButton._MyVote_UPCLICK._Priority.ToString()); TXT_VOTE_OPINION_UP.Text = GlobalStaticClass.FormatAllCapsString(CurrentDisplayButton._MyVote_UPCLICK._VoteOpinion); } else { TXT_VOTE_WHATTODO_UP.Text = ""; TXT_VOTE_TARGETID_UP.Text = ""; TXT_VOTE_PRIORITY_UP.Text = ""; TXT_VOTE_OPINION_UP.Text = ""; } BTN_SAVE.Enabled = isAllSetup; } private void BTN_CANCEL_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private void BTN_SAVE_Click(object sender, EventArgs e) { CurrentDisplayButton._name = TXT_NAME.Text; if (!int.TryParse(TXT_LOCATION_X.Text, out CurrentDisplayButton._x) || !int.TryParse(TXT_LOCATION_Y.Text, out CurrentDisplayButton._y)) { (new ErrorForm("Invalid Location", "The Location for this Display Button is invalid")).ShowDialog(); return; } if (!int.TryParse(TXT_SHOWSIZE_WIDTH.Text, out CurrentDisplayButton._width) || !int.TryParse(TXT_SHOWSIZE_HEIGHT.Text, out CurrentDisplayButton._height)) { (new ErrorForm("Invalid Show Size", "The display at size for this Display Button is invalid")).ShowDialog(); return; } else { if (CurrentDisplayButton._width <= 0 || CurrentDisplayButton._height <= 0) { (new ErrorForm("Invalid Show Size", "The display at size for this Display Button is zero or negative which is invalid")).ShowDialog(); return; } } if (!int.TryParse(TXT_TIME_DOWN.Text, out CurrentDisplayButton._Time_down) || !int.TryParse(TXT_TIME_UP.Text, out CurrentDisplayButton._Time_up)) { (new ErrorForm("Invalid Minimum Time", "The minimum time between votes for this Display Button is invalid")).ShowDialog(); return; } else { if (CurrentDisplayButton._Time_down <= 0 || CurrentDisplayButton._Time_up <= 0) { (new ErrorForm("Invalid Minimum Time", "The minimum time between votes for this Display Button is zero or negative which is invalid")).ShowDialog(); return; } } if (!float.TryParse(TXT_Z_ORDER.Text, out CurrentDisplayButton._z_order)) { (new ErrorForm("Invalid Show Size", "The display at size for this Display Button is zero or negative which is invalid")).ShowDialog(); return; } if (!(CHECKLIST_PAGES.CheckedIndices.Count > 0)) { (new ErrorForm("Invalid Page", "There must be at least 1 visible page selected.")).ShowDialog(); return; } List tempPages = new List(); for (int i = 0; i < CHECKLIST_PAGES.CheckedItems.Count; i++) { int _tempI = -1; if (int.TryParse(CHECKLIST_PAGES.CheckedItems[i].ToString(), out _tempI)) { tempPages.Add((int)(_tempI - 1)); } } CurrentDisplayButton._pages = new List(tempPages.ToArray()); CurrentDisplayButton.default_state = COMBO_DEFAULT_STATE.Text; bool fontsAreAllSetup = true; if (COMBO_FONTS.SelectedItem != null && COMBO_FONTS.SelectedItem.ToString() != "") { CurrentDisplayButton._font_name = COMBO_FONTS.SelectedItem.ToString(); } else { fontsAreAllSetup = false; } float fontSizePlaceholder; if (float.TryParse(TXT_FONT_SIZE.Text, out fontSizePlaceholder)) { CurrentDisplayButton._font_size = TXT_FONT_SIZE.Text; } else { fontsAreAllSetup = false; } CurrentDisplayButton._textPrimary = TXT_PRIMARY.Text; CurrentDisplayButton._textSecondary = TXT_SECONDARY.Text; CurrentDisplayButton._textDisabled = TXT_DISABLED.Text; CurrentDisplayButton._textPrimaryColour = PANEL_PRIMARY_COLOUR.BackColor; CurrentDisplayButton._textSecondaryColour = PANEL_SECONDARY_COLOUR.BackColor; CurrentDisplayButton._textDisabledColour = PANEL_DISABLED_COLOUR.BackColor; if (TXT_PRIMARY.Text == "" && TXT_SECONDARY.Text == "" && TXT_DISABLED.Text == "") { CurrentDisplayButton._font_name = ""; CurrentDisplayButton._font_size = "0"; fontsAreAllSetup = true; } if (!fontsAreAllSetup) { (new ErrorForm("Invalid Font Setup", "The Font Settings for this Display Button are invalid")).ShowDialog(); return; } if (CurrentDisplayButton._image_Primary == null && CurrentDisplayButton._path_Primary == null) { (new ErrorForm("Invalid Primary Image", "The Primary Image for this Display Button is invalid")).ShowDialog(); return; } else { CurrentDisplayButton._image = CurrentDisplayButton._image_Primary; } if (CurrentDisplayButton._image_Secondary == null && CurrentDisplayButton._path_Secondary == null) { (new ErrorForm("Invalid Secondary Image", "The Secondary Image for this Display Button is invalid")).ShowDialog(); return; } if (CurrentDisplayButton._image_Pushed == null && CurrentDisplayButton._path_Pushed == null) { (new ErrorForm("Invalid Pushed Image", "The Pushed Image for this Display Button is invalid")).ShowDialog(); return; } if (CurrentDisplayButton._image_Disabled == null && CurrentDisplayButton._path_Disabled == null) { (new ErrorForm("Invalid Disabled Image", "The Disabled Image for this Display Button is invalid")).ShowDialog(); return; } if (CurrentDisplayButton._MyVote == null) { (new ErrorForm("Invalid Vote", "There is no Vote action for this display button so nothing will happen when it is clicked", true)).ShowDialog(); //return; } this.DialogResult = DialogResult.OK; } #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; } if (e.KeyData == Keys.Decimal || e.KeyValue == 190) { if (sender == TXT_Z_ORDER || sender == TXT_FONT_SIZE) { if (((TextBox)sender).Text.Contains(".")) { e.SuppressKeyPress = true; } } else { 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; double _tempDbl; if (!double.TryParse(_senderBox.Text, out _tempDbl)) { 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 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 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 private void BTN_LOADIMAGE_PRIMARY_Click(object sender, EventArgs e) { AddImageForm _tempAIF = null; if (CurrentDisplayButton._image_Primary != null && CurrentDisplayButton._path_Primary != null) { _tempAIF = new AddImageForm(CurrentDisplayButton._image_Primary, CurrentDisplayButton._path_Primary); } else { _tempAIF = new AddImageForm(); } if (_tempAIF.ShowDialog() == DialogResult.OK) { CurrentDisplayButton._image_Primary = _tempAIF.IMAGE_BITMAP; CurrentDisplayButton._path_Primary = _tempAIF.IMAGE_PATH; UpdateForm(); } this.DialogResult = DialogResult.None; } private void BTN_LOADIMAGE_DISABLED_Click(object sender, EventArgs e) { AddImageForm _tempAIF = null; if (CurrentDisplayButton._path_Disabled != null && CurrentDisplayButton._image_Disabled != null) { _tempAIF = new AddImageForm(CurrentDisplayButton._image_Disabled, CurrentDisplayButton._path_Disabled); } else { _tempAIF = new AddImageForm(); } if (_tempAIF.ShowDialog() == DialogResult.OK) { CurrentDisplayButton._image_Disabled = _tempAIF.IMAGE_BITMAP; CurrentDisplayButton._path_Disabled = _tempAIF.IMAGE_PATH; UpdateForm(); } this.DialogResult = DialogResult.None; } private void BTN_LOADIMAGE_PUSHED_Click(object sender, EventArgs e) { AddImageForm _tempAIF = null; if (CurrentDisplayButton._image_Pushed != null && CurrentDisplayButton._path_Pushed != null) { _tempAIF = new AddImageForm(CurrentDisplayButton._image_Pushed, CurrentDisplayButton._path_Pushed); } else { _tempAIF = new AddImageForm(); } if (_tempAIF.ShowDialog() == DialogResult.OK) { CurrentDisplayButton._image_Pushed = _tempAIF.IMAGE_BITMAP; CurrentDisplayButton._path_Pushed = _tempAIF.IMAGE_PATH; UpdateForm(); } this.DialogResult = DialogResult.None; } private void BTN_LOADIMAGE_SECONDARY_Click(object sender, EventArgs e) { AddImageForm _tempAIF = null; if (CurrentDisplayButton._image_Secondary != null && CurrentDisplayButton._path_Secondary != null) { _tempAIF = new AddImageForm(CurrentDisplayButton._image_Secondary, CurrentDisplayButton._path_Secondary); } else { _tempAIF = new AddImageForm(); } if (_tempAIF.ShowDialog() == DialogResult.OK) { CurrentDisplayButton._image_Secondary = _tempAIF.IMAGE_BITMAP; CurrentDisplayButton._path_Secondary = _tempAIF.IMAGE_PATH; UpdateForm(); } this.DialogResult = DialogResult.None; } private void LOAD_VOTE_Click(object sender, EventArgs e) { AddNewThenDo _tempNewThenDo = null; if (CurrentDisplayButton._MyVote == null) { _tempNewThenDo = new AddNewThenDo(); } else { _tempNewThenDo = new AddNewThenDo(CurrentDisplayButton._MyVote); } if (_tempNewThenDo.ShowDialog() == DialogResult.OK) { CurrentDisplayButton._MyVote = _tempNewThenDo.MyVote; UpdateForm(); } this.DialogResult = DialogResult.None; } private void LBL_SIZE_DISABLED_Click(object sender, EventArgs e) { if (CurrentDisplayButton._image_Disabled != null) { TXT_SHOWSIZE_WIDTH.Text = CurrentDisplayButton._image_Disabled.Width.ToString(); TXT_SHOWSIZE_HEIGHT.Text = CurrentDisplayButton._image_Disabled.Height.ToString(); } else { (new ErrorForm("No Disabled Image", "Cannot set size to disabled image size because image does not exist")).ShowDialog(); } } private void LBL_SIZE_PRIMARY_Click(object sender, EventArgs e) { if (CurrentDisplayButton._image_Primary != null) { TXT_SHOWSIZE_WIDTH.Text = CurrentDisplayButton._image_Primary.Width.ToString(); TXT_SHOWSIZE_HEIGHT.Text = CurrentDisplayButton._image_Primary.Height.ToString(); } else { (new ErrorForm("No Primary Image", "Cannot set size to primary image size because image does not exist")).ShowDialog(); } } private void LBL_SIZE_SECONDARY_Click(object sender, EventArgs e) { if (CurrentDisplayButton._image_Secondary != null) { TXT_SHOWSIZE_WIDTH.Text = CurrentDisplayButton._image_Secondary.Width.ToString(); TXT_SHOWSIZE_HEIGHT.Text = CurrentDisplayButton._image_Secondary.Height.ToString(); } else { (new ErrorForm("No Secondary Image", "Cannot set size to secondary image size because image does not exist")).ShowDialog(); } } private void LBL_SIZE_PUSHED_Click(object sender, EventArgs e) { if (CurrentDisplayButton._image_Pushed != null) { TXT_SHOWSIZE_WIDTH.Text = CurrentDisplayButton._image_Pushed.Width.ToString(); TXT_SHOWSIZE_HEIGHT.Text = CurrentDisplayButton._image_Pushed.Height.ToString(); } else { (new ErrorForm("No Pushed Image", "Cannot set size to pushed image size because image does not exist")).ShowDialog(); } } private void LOAD_VOTE_UP_Click(object sender, EventArgs e) { AddNewThenDo _tempNewThenDo = null; if (CurrentDisplayButton._MyVote_UPCLICK == null) { _tempNewThenDo = new AddNewThenDo(); } else { _tempNewThenDo = new AddNewThenDo(CurrentDisplayButton._MyVote_UPCLICK); } if (_tempNewThenDo.ShowDialog() == DialogResult.OK) { CurrentDisplayButton._MyVote_UPCLICK = _tempNewThenDo.MyVote; UpdateForm(); } this.DialogResult = DialogResult.None; } private void PANEL_PRIMARY_COLOUR_Click(object sender, EventArgs e) { ColourChoosingForm _cF = new ColourChoosingForm(CurrentDisplayButton._textPrimaryColour); if (_cF.ShowDialog() == DialogResult.OK) { CurrentDisplayButton._textPrimaryColour = _cF.ChosenColour; PANEL_PRIMARY_COLOUR.BackColor = CurrentDisplayButton._textPrimaryColour; } } private void PANEL_SECONDARY_COLOUR_Click(object sender, EventArgs e) { ColourChoosingForm _cF = new ColourChoosingForm(CurrentDisplayButton._textSecondaryColour); if (_cF.ShowDialog() == DialogResult.OK) { CurrentDisplayButton._textSecondaryColour = _cF.ChosenColour; PANEL_SECONDARY_COLOUR.BackColor = CurrentDisplayButton._textSecondaryColour; } } private void PANEL_DISABLED_COLOUR_Click(object sender, EventArgs e) { ColourChoosingForm _cF = new ColourChoosingForm(CurrentDisplayButton._textDisabledColour); if (_cF.ShowDialog() == DialogResult.OK) { CurrentDisplayButton._textDisabledColour = _cF.ChosenColour; PANEL_PRIMARY_COLOUR.BackColor = CurrentDisplayButton._textDisabledColour; } } } }