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 AddMultiImageForm : Form { public GlobalStaticClass.FusionImage_MultiImage CurrentMultiImage = new GlobalStaticClass.FusionImage_MultiImage(); public int CurrentImageIndex = -1; public AddMultiImageForm() { InitializeComponent(); TXT_NAME.Text = GlobalStaticClass.FusionImage_MultiImage.GetUniqueName(); CHECKLIST_PAGES.Items.Clear(); for (int i = 0; i < GlobalStaticClass._Global_List_Graphics_PageList.Count; i++) { CHECKLIST_PAGES.Items.Add(((int)(i + 1)).ToString()); } UpdateForm(); } public AddMultiImageForm(GlobalStaticClass.FusionImage_MultiImage inputMulti) { InitializeComponent(); CurrentMultiImage = inputMulti; for (int i = 0; i < CurrentMultiImage._ImageList.Count; i++) { if (CurrentMultiImage._ImageList[i]._image == CurrentMultiImage._image) { CurrentImageIndex = i; break; } } TXT_NAME.Text = CurrentMultiImage._name; TXT_SHOWSIZE_WIDTH.Text = CurrentMultiImage._width.ToString(); TXT_SHOWSIZE_HEIGHT.Text = CurrentMultiImage._height.ToString(); TXT_LOCATION_X.Text = CurrentMultiImage._x.ToString(); TXT_LOCATION_Y.Text = CurrentMultiImage._y.ToString(); TXT_ROTATION.Text = CurrentMultiImage._rotation.ToString(); TXT_Z_ORDER.Text = CurrentMultiImage._z_order.ToString(); COMBO_MONITOR_TYPE.Text = CurrentMultiImage._monitor_type; COMBO_MONITOR_TYPE.SelectedText = CurrentMultiImage._monitor_type; for (int i = 0; i < COMBO_MONITOR_TYPE.Items.Count; i++) { if (COMBO_MONITOR_TYPE.Items[i].ToString().ToLower() == CurrentMultiImage._monitor_type.ToLower()) { COMBO_MONITOR_TYPE.SelectedIndex = i; break; } } COMBO_MONITOR_TYPE_SelectedValueChanged(COMBO_MONITOR_TYPE, null); COMBO_MONITOR_ID.Enabled = true; COMBO_MONITOR_ID.Text = CurrentMultiImage._monitor_id; COMBO_MONITOR_ID.SelectedText = CurrentMultiImage._monitor_id; for (int i = 0; i < COMBO_MONITOR_ID.Items.Count; i++) { if (COMBO_MONITOR_ID.Items[i].ToString().ToLower() == CurrentMultiImage._monitor_id.ToLower()) { COMBO_MONITOR_ID.SelectedIndex = i; break; } } CHECKLIST_PAGES.Items.Clear(); for (int i = 0; i < GlobalStaticClass._Global_List_Graphics_PageList.Count; i++) { CHECKLIST_PAGES.Items.Add(((int)(i + 1)).ToString()); } 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, CurrentMultiImage._pages.Contains(_pageParse - 1)); } } UpdateForm(); } public void UpdateForm() { bool enableBTNs = true; if (CurrentImageIndex < 0 || CurrentImageIndex >= CurrentMultiImage._ImageList.Count) { enableBTNs = false; TXT_VALUE_MAX.Text = "0.0"; TXT_VALUE_MIN.Text = "0.0"; } else { enableBTNs = true; TXT_VALUE_MAX.Text = CurrentMultiImage._ImageList[CurrentImageIndex]._high.ToString(); TXT_VALUE_MIN.Text = CurrentMultiImage._ImageList[CurrentImageIndex]._low.ToString(); } BTN_IMAGE_DELETE.Enabled = enableBTNs; BTN_IMAGE_LOADIMAGE.Enabled = enableBTNs; BTN_IMAGE_NEXT.Enabled = enableBTNs; BTN_IMAGE_PREVIOUS.Enabled = enableBTNs; BTN_SAVE.Enabled = enableBTNs; TXT_VALUE_MAX.Enabled = enableBTNs; TXT_VALUE_MIN.Enabled = enableBTNs; LBL_IMAGE_OF_IMAGE.Text = (CurrentImageIndex + 1) + "/" + CurrentMultiImage._ImageList.Count.ToString(); if (CurrentImageIndex >= 0 && CurrentImageIndex < CurrentMultiImage._ImageList.Count && CurrentMultiImage._ImageList[CurrentImageIndex]._image != null) { CurrentMultiImage._image = CurrentMultiImage._ImageList[CurrentImageIndex]._image; PICT_PREVIEW.BackgroundImage = CurrentMultiImage._image; if (CurrentMultiImage._image.Size.Width > PICT_PREVIEW.Size.Width || CurrentMultiImage._image.Size.Height > PICT_PREVIEW.Size.Height) { PICT_PREVIEW.BackgroundImageLayout = ImageLayout.Zoom; } else { PICT_PREVIEW.BackgroundImageLayout = ImageLayout.Center; } } else { PICT_PREVIEW.BackgroundImage = new Bitmap(PICT_PREVIEW.Width, PICT_PREVIEW.Height); } } private void BTN_SAVE_Click(object sender, EventArgs e) { SaveCurrentImageInfo(); if (CurrentMultiImage._ImageList.Count > 0 && CurrentImageIndex >= 0 && CurrentImageIndex < CurrentMultiImage._ImageList.Count && CurrentMultiImage._ImageList[CurrentImageIndex]._image != null) { CurrentMultiImage._image = CurrentMultiImage._ImageList[CurrentImageIndex]._image; } else { this.DialogResult = DialogResult.None; (new ErrorForm("No Images", "A Multi Image must have at least 1 image loaded")).ShowDialog(); return; } if (!float.TryParse(TXT_ROTATION.Text, out CurrentMultiImage._rotation) || !float.TryParse(TXT_Z_ORDER.Text, out CurrentMultiImage._z_order) || !int.TryParse(TXT_LOCATION_X.Text, out CurrentMultiImage._x) || !int.TryParse(TXT_LOCATION_Y.Text, out CurrentMultiImage._y) || !int.TryParse(TXT_SHOWSIZE_WIDTH.Text, out CurrentMultiImage._width) || !int.TryParse(TXT_SHOWSIZE_HEIGHT.Text, out CurrentMultiImage._height)) { this.DialogResult = DialogResult.None; (new ErrorForm("Numeric Parse Error", "Error Parsing numeric data")).ShowDialog(); return; } if (CurrentMultiImage._width <= 0 || CurrentMultiImage._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 (TXT_NAME.Text == null || TXT_NAME.Text == "") { this.DialogResult = DialogResult.None; (new ErrorForm("Name Error", "This Multi-Image must have a name")).ShowDialog(); return; } else { CurrentMultiImage._name = TXT_NAME.Text; } List _possibleTypes = new List(new string[] { "variable", "digital output", "analogue input" }); if (!_possibleTypes.Contains(COMBO_MONITOR_TYPE.Text.ToLower())) { this.DialogResult = DialogResult.None; (new ErrorForm("Monitor Type Error", "The Monitor Type is not valid.")).ShowDialog(); return; } else { CurrentMultiImage._monitor_type = COMBO_MONITOR_TYPE.Text.ToLower(); } if(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 (CurrentMultiImage._monitor_type) { 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 "digital output": { foreach (GlobalStaticClass._GlobalDigitalOutputClass _doc in GlobalStaticClass._Global_List_DigitalOutputs) { if (_doc.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 digital outputs.")).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) { CurrentMultiImage._monitor_id = COMBO_MONITOR_ID.Text.ToLower(); } 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)); } } CurrentMultiImage._pages = new List(tempPages.ToArray()); this.DialogResult = DialogResult.OK; } private void BTN_CANCEL_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private void BTN_IMAGE_LOADIMAGE_Click(object sender, EventArgs e) { AddImageForm _tempAIF = null; if (CurrentMultiImage._ImageList[CurrentImageIndex]._image != null && CurrentMultiImage._ImageList[CurrentImageIndex]._path != null) { _tempAIF = new AddImageForm(CurrentMultiImage._ImageList[CurrentImageIndex]._image, CurrentMultiImage._ImageList[CurrentImageIndex]._path); } else { _tempAIF = new AddImageForm(); } if (_tempAIF.ShowDialog() == DialogResult.OK) { CurrentMultiImage._ImageList[CurrentImageIndex]._image = _tempAIF.IMAGE_BITMAP; CurrentMultiImage._ImageList[CurrentImageIndex]._path = _tempAIF.IMAGE_PATH; UpdateForm(); } this.DialogResult = DialogResult.None; } private void BTN_IMAGE_PREVIOUS_Click(object sender, EventArgs e) { SaveCurrentImageInfo(); if (CurrentImageIndex > 0) { CurrentImageIndex--; TXT_VALUE_MIN.Text = CurrentMultiImage._ImageList[CurrentImageIndex]._low.ToString(); TXT_VALUE_MAX.Text = CurrentMultiImage._ImageList[CurrentImageIndex]._high.ToString(); } UpdateForm(); } private void BTN_IMAGE_NEXT_Click(object sender, EventArgs e) { SaveCurrentImageInfo(); if (CurrentImageIndex < CurrentMultiImage._ImageList.Count -1) { CurrentImageIndex++; TXT_VALUE_MIN.Text = CurrentMultiImage._ImageList[CurrentImageIndex]._low.ToString(); TXT_VALUE_MAX.Text = CurrentMultiImage._ImageList[CurrentImageIndex]._high.ToString(); } UpdateForm(); } private void BTN_IMAGE_DELETE_Click(object sender, EventArgs e) { CurrentMultiImage._ImageList.RemoveAt(CurrentImageIndex); CurrentImageIndex--; if (CurrentMultiImage._ImageList.Count > 0 && CurrentImageIndex < 0) { CurrentImageIndex = 0; } UpdateForm(); } private void BTN_IMAGE_LOADFOLDER_Click(object sender, EventArgs e) { FolderBrowserDialog _FB = new FolderBrowserDialog(); _FB.RootFolder = Environment.SpecialFolder.Desktop; _FB.SelectedPath = Application.StartupPath; if (_FB.ShowDialog() == DialogResult.OK) { AutoMultiImageLoadForm _FB_AutoForm = new AutoMultiImageLoadForm(); if (_FB_AutoForm.ShowDialog() == DialogResult.OK) { float _max = _FB_AutoForm._max; float _min = _FB_AutoForm._min; CurrentMultiImage._ImageList.Clear(); string[] AllFiles = System.IO.Directory.GetFiles((_FB.SelectedPath)); List supportedFileExtensions = new List(new string[] { "png", "bmp", "jpg", "gif" }); List AllFilesToOpen = new List(); foreach (string CurrentFile in AllFiles) { string[] currentFileExtensionArray = CurrentFile.Split(new char[] { '.' }); if (currentFileExtensionArray.Length != 2) { continue; } string currentFileExtension = currentFileExtensionArray[1]; if (!supportedFileExtensions.Contains(currentFileExtension)) { continue; } AllFilesToOpen.Add(CurrentFile); } float _step = (_max - _min) / (float)AllFilesToOpen.Count; for (int i = 0; i < AllFilesToOpen.Count; i++) { float my_min = _min + (_step * i); float my_max = _min + (_step * (i + 1)); CurrentMultiImage.AddImageToList(AllFilesToOpen[i], (Bitmap)Image.FromFile(AllFilesToOpen[i]), my_min, my_max); } if (CurrentImageIndex >= CurrentMultiImage._ImageList.Count) { CurrentImageIndex = CurrentMultiImage._ImageList.Count - 1; } else if (CurrentImageIndex < 0) { CurrentImageIndex = 0; } UpdateForm(); } } } private void BTN_IMAGE_ADD_Click(object sender, EventArgs e) { SaveCurrentImageInfo(); CurrentImageIndex++; CurrentMultiImage.AddImageToList("", null); TXT_VALUE_MAX.Text = "0.0"; TXT_VALUE_MIN.Text = "0.0"; UpdateForm(); } public void SaveCurrentImageInfo() { if (CurrentImageIndex >= 0 && CurrentImageIndex < CurrentMultiImage._ImageList.Count) { float.TryParse(TXT_VALUE_MIN.Text, out CurrentMultiImage._ImageList[CurrentImageIndex]._low); float.TryParse(TXT_VALUE_MAX.Text, out CurrentMultiImage._ImageList[CurrentImageIndex]._high); } } #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_VALUE_MIN || sender == TXT_VALUE_MAX || sender == TXT_ROTATION) { 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 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 "digital output": { foreach (GlobalStaticClass._GlobalDigitalOutputClass _do in GlobalStaticClass._Global_List_DigitalOutputs) { _possibilites.Add(_do.id); } } break; case "analogue input": { foreach (GlobalStaticClass._GlobalAnalogueInputClass _ain in GlobalStaticClass._Global_List_AnalogueInputs) { _possibilites.Add(_ain.id); } } 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]; } } } }