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 Speech_CustomQueryForm : Form { private List _responses = new List(); public Speech_CustomQueryForm() { InitializeComponent(); } private void COMBO_MONITOR_TYPE_SelectedValueChanged(object sender, EventArgs e) { COMBO_ID.Items.Clear(); COMBO_ID.SelectedText = ""; COMBO_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_ID.Enabled = true; COMBO_ID.Items.AddRange(_possibilites.ToArray()); COMBO_ID.Text = ""; COMBO_ID.Text = _possibilites[0]; } } private void TXT_ADD_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) { string _toAdd = ((TextBox)sender).Text; if (sender == TXT_Q_B) { LIST_Q_B.Items.Add(_toAdd); } else if (sender == TXT_Q_M) { LIST_Q_M.Items.Add(_toAdd); } else if (sender == TXT_Q_E) { LIST_Q_E.Items.Add(_toAdd); } ((TextBox)sender).Clear(); } } private void DELETE_ITEM(object sender, EventArgs e) { ListBox _l = null; if (sender == BTN_DEL_Q_B) { _l = LIST_Q_B; } else if (sender == BTN_DEL_Q_M) { _l = LIST_Q_M; } else if (sender == BTN_DEL_Q_E) { _l = LIST_Q_E; } if (_l != null && _l.SelectedIndices.Count > 0) { _l.Items.RemoveAt(_l.SelectedIndices[0]); } else if (sender == BTN_DEL_R && LIST_R.SelectedIndices.Count > 0) { LIST_R.Items.RemoveAt(LIST_R.SelectedIndices[0]); _responses.RemoveAt(LIST_R.SelectedIndices[0]); } } public string GET_MONITOR_TYPE() { return COMBO_TYPE.Text; } public string GET_MONITOR_ID() { return COMBO_ID.Text; } public List GET_Query_Beginnings() { return returnItemsFromList(LIST_Q_B); } public List GET_Query_Middles() { return returnItemsFromList(LIST_Q_M); } public List GET_Query_Endings() { return returnItemsFromList(LIST_Q_E); } public List GET_Responses() { return _responses; } private List returnItemsFromList(ListBox _lb) { List _r = new List(); for (int i = 0; i < _lb.Items.Count; i++) { _r.Add(_lb.Items[i].ToString()); } return _r; } private void BTN_ADD_R_Click(object sender, EventArgs e) { _responses.Add(new GlobalStaticClass.Speech_Response(TXT_R_B.Text, TXT_R_E.Text)); LIST_R.Items.Add(TXT_R_B.Text + " ### " + TXT_R_E.Text); } private void BTN_SAVE_Click(object sender, EventArgs e) { if (_responses.Count == 0) { (new ErrorForm("No Responses", "There must be at least 1 response for this custom query.")).ShowDialog(); this.DialogResult = DialogResult.None; return; } if (LIST_Q_B.Items.Count + LIST_Q_E.Items.Count + LIST_Q_M.Items.Count == 0) { (new ErrorForm("No Queries", "There must be at least 1 query section for this custom query.")).ShowDialog(); this.DialogResult = DialogResult.None; return; } if (COMBO_TYPE.Text == "") { (new ErrorForm("No Type Selected", "You must select a type to monitor")).ShowDialog(); this.DialogResult = DialogResult.None; return; } if (COMBO_ID.Text == "") { (new ErrorForm("No ID Selected", "You must select an instance of a " + COMBO_TYPE.Text + " to monitor")).ShowDialog(); this.DialogResult = DialogResult.None; return; } } } }