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 AddTextLabelForm : Form { public GlobalStaticClass.FusionFont_TextLabel CurrentTextLabel = new GlobalStaticClass.FusionFont_TextLabel(); public AddTextLabelForm() { SetUp(); } public AddTextLabelForm(GlobalStaticClass.FusionFont_TextLabel input_TextLabel) { CurrentTextLabel = input_TextLabel; SetUp(); 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, CurrentTextLabel._pages.Contains(_pageParse - 1)); } } for (int i = 0; i < COMBO_FONTS.Items.Count; i++) { if (COMBO_FONTS.Items[i].ToString().ToLower() == CurrentTextLabel._fontName.ToLower()) { COMBO_FONTS.SelectedIndex = i; COMBO_FONTS.Text = CurrentTextLabel._fontName; break; } } TXT_FONT_SIZE.Text = CurrentTextLabel._fontSize.ToString(); TXT_LOCATION_X.Text = CurrentTextLabel._x.ToString(); TXT_LOCATION_Y.Text = CurrentTextLabel._y.ToString(); TXT_NAME.Text = CurrentTextLabel._name; TXT_SHOWSIZE_HEIGHT.Text = CurrentTextLabel._height.ToString(); TXT_SHOWSIZE_WIDTH.Text = CurrentTextLabel._width.ToString(); TXT_TEXT.Text = CurrentTextLabel._text; TXT_DECIMALS_ORDER.Text = CurrentTextLabel._maxDecimals.ToString(); PANEL_COLOUR.BackColor = CurrentTextLabel._colour; COMBO_MONITOR_TYPE.Text = CurrentTextLabel._autoMonitor; COMBO_MONITOR_TYPE.SelectedText = CurrentTextLabel._autoMonitor; for (int i = 0; i < COMBO_MONITOR_TYPE.Items.Count; i++) { if (COMBO_MONITOR_TYPE.Items[i].ToString().ToLower() == CurrentTextLabel._autoMonitor.ToLower()) { COMBO_MONITOR_TYPE.SelectedIndex = i; break; } } COMBO_MONITOR_TYPE_SelectedValueChanged(COMBO_MONITOR_TYPE, null); if (CurrentTextLabel._autoMonitor.ToLower() != "none") { COMBO_MONITOR_ID.Enabled = true; } COMBO_MONITOR_ID.Text = CurrentTextLabel._autoMonitorTargetID; COMBO_MONITOR_ID.SelectedText = CurrentTextLabel._autoMonitorTargetID; for (int i = 0; i < COMBO_MONITOR_ID.Items.Count; i++) { if (COMBO_MONITOR_ID.Items[i].ToString().ToLower() == CurrentTextLabel._autoMonitorTargetID.ToLower()) { COMBO_MONITOR_ID.SelectedIndex = i; break; } } } public void SetUp() { InitializeComponent(); 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); } } #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_DECIMALS_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 == "") // Check name is taken here and when saving... { 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 Colour Panel Click private void PANEL_COLOUR_Click(object sender, EventArgs e) { ColourChoosingForm _cF = new ColourChoosingForm(CurrentTextLabel._colour); if (_cF.ShowDialog() == DialogResult.OK) { CurrentTextLabel._colour = _cF.ChosenColour; PANEL_COLOUR.BackColor = CurrentTextLabel._colour; } } #endregion 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 "none": { // Nada } break; 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; default: break; } COMBO_MONITOR_ID.Text = ""; TXT_DECIMALS_ORDER.Text = ""; TXT_DECIMALS_ORDER.Enabled = true; if (_possibilites.Count > 0) { COMBO_MONITOR_ID.Enabled = true; TXT_DECIMALS_ORDER.Enabled = true; TXT_DECIMALS_ORDER.Text = CurrentTextLabel._maxDecimals.ToString(); COMBO_MONITOR_ID.Items.AddRange(_possibilites.ToArray()); COMBO_MONITOR_ID.Text = _possibilites[0]; } } private void BTN_CANCEL_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private void BTN_SAVE_Click(object sender, EventArgs e) { //Check First if (TXT_NAME.Text == "") { this.DialogResult = DialogResult.None; (new ErrorForm("Label Name Error", "The name field is not valid")).ShowDialog(); return; } else { CurrentTextLabel._name = TXT_NAME.Text; } CurrentTextLabel._text = TXT_TEXT.Text; if (!int.TryParse(TXT_LOCATION_X.Text, out CurrentTextLabel._x) || !int.TryParse(TXT_LOCATION_Y.Text, out CurrentTextLabel._y)) { this.DialogResult = DialogResult.None; (new ErrorForm("Location Error", "The location field is not valid")).ShowDialog(); return; } if (!int.TryParse(TXT_SHOWSIZE_WIDTH.Text, out CurrentTextLabel._width) || !int.TryParse(TXT_SHOWSIZE_HEIGHT.Text, out CurrentTextLabel._height) || CurrentTextLabel._height <= 0 || CurrentTextLabel._width <= 0) { this.DialogResult = DialogResult.None; (new ErrorForm("Size Error", "The size field is not valid. Cannot have a width of 0 or a height of 0")).ShowDialog(); return; } if (!float.TryParse(TXT_FONT_SIZE.Text, out CurrentTextLabel._fontSize)) { this.DialogResult = DialogResult.None; (new ErrorForm("Font Size Error", "The font size field is not valid.")).ShowDialog(); return; } if (COMBO_FONTS.Text == null || COMBO_FONTS.Text == "") { this.DialogResult = DialogResult.None; (new ErrorForm("Font Name Error", "The font name is not valid.")).ShowDialog(); return; } else { bool isFoundFont = false; for (int i = 0; i < COMBO_FONTS.Items.Count; i++) { if (COMBO_FONTS.Items[i].ToString().ToLower() == COMBO_FONTS.Text.ToLower()) { CurrentTextLabel._fontName = COMBO_FONTS.Text; isFoundFont = true; break; } } if (!isFoundFont) { this.DialogResult = DialogResult.None; (new ErrorForm("Font Name Error", "The font name is not valid. Cannot find name in know font list")).ShowDialog(); return; } } CurrentTextLabel._colour = PANEL_COLOUR.BackColor; List _possibleTypes = new List(new string[] { "none", "variable", "analogue input" }); if (!_possibleTypes.Contains(COMBO_MONITOR_TYPE.Text.ToLower())) { this.DialogResult = DialogResult.None; (new ErrorForm("Monitor Type Error", "The Auto Monitor Type is not valid.")).ShowDialog(); return; } else { CurrentTextLabel._autoMonitor = COMBO_MONITOR_TYPE.Text.ToLower(); } if (CurrentTextLabel._autoMonitor.ToLower() != "none" && (COMBO_MONITOR_ID.Text == null || COMBO_MONITOR_ID.Text == "")) { this.DialogResult = DialogResult.None; (new ErrorForm("Monitor ID Error", "The Monitor ID is not valid.")).ShowDialog(); return; } bool isFound = false; switch (CurrentTextLabel._autoMonitor) { case "none": { isFound = true; break; } case "variable": { foreach (GlobalStaticClass._GlobalVariableClass _var in GlobalStaticClass._Global_List_Variables) { if (_var._id.ToLower() == COMBO_MONITOR_ID.Text.ToLower()) { isFound = true; break; } } if (!isFound) { this.DialogResult = DialogResult.None; (new ErrorForm("Monitor ID Error", "The Monitor ID was not found in the current list of variables.")).ShowDialog(); return; } } break; case "analogue input": { foreach (GlobalStaticClass._GlobalAnalogueInputClass _ain in GlobalStaticClass._Global_List_AnalogueInputs) { if (_ain.id.ToLower() == COMBO_MONITOR_ID.Text.ToLower()) { isFound = true; break; } } if (!isFound) { this.DialogResult = DialogResult.None; (new ErrorForm("Monitor ID Error", "The Monitor ID was not found in the current list of analogue inputs.")).ShowDialog(); return; } } break; default: break; //Error } if (isFound) { CurrentTextLabel._autoMonitorTargetID = COMBO_MONITOR_ID.Text.ToLower(); } if (CurrentTextLabel._autoMonitor != "none") { if (!int.TryParse(TXT_DECIMALS_ORDER.Text, out CurrentTextLabel._maxDecimals)) { this.DialogResult = DialogResult.None; (new ErrorForm("Z-Order Error", "The decimal precision field is not valid.")).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)); } } CurrentTextLabel._pages = new List(tempPages.ToArray()); CurrentTextLabel._image = new Bitmap(CurrentTextLabel._width, CurrentTextLabel._height); Graphics _gB = Graphics.FromImage(CurrentTextLabel._image); _gB.Clear(CurrentTextLabel._colour); _gB.Dispose(); //If Ok, then Save this.DialogResult = DialogResult.OK; } } }