public override void BSkyBaseButtonCtrl_Click(object sender, RoutedEventArgs e) { double maxnoofvars = 0; IEnumerable <IEnumerable <string> > permResult = null; int noSelectedItems = 0; int i = 0; System.Windows.Forms.DialogResult diagResult; List <string> listOfPermutations = new List <string>(); string message = ""; DataSourceVariable o; //Aaron 09/07/2013 //I had to use a list object as I could not create a variable size array object List <object> validVars = new List <object>(); List <string> invalidVars = new List <string>(); //Added by Aaron 12/24/2013 //You have the ability to move items to a textbox. When moving items to a textbox you don't have to check for filters //All we do is append the items selected separated by + into the textbox //We always copy the selected items to the textbox, items are never moved //We don't have to worry about tag //Destination is a BSkytargetlist noSelectedItems = vInputList.SelectedItems.Count; //Checking whether variables moved are allowed by the destination filter //validVars meet filter requirements //invalidVars don't meet filter requirements List <string> variableListForCombo = new List <string>(); if (vTargetList != null) { if (noSelectedItems == 0) { diagResult = System.Windows.Forms.MessageBox.Show("You need to select a variable from the source variable list before clicking the N Way interaction creator button", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question); return; } if (vTargetList.GetType().Name == "SingleItemList" && noSelectedItems > 1) { diagResult = System.Windows.Forms.MessageBox.Show("You cannot move more than 1 variable into a grouping variable list", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question); return; } //Added 10/19/2013 //Added the code below to support listboxes that only allow a pre-specified number of items or less //I add the number of preexisting items to the number of selected items and if it is greater than limit, I show an error if (vTargetList.maxNoOfVariables != string.Empty && vTargetList.maxNoOfVariables != null) { try { maxnoofvars = Convert.ToDouble(vTargetList.maxNoOfVariables); //Console.WriteLine("Converted '{0}' to {1}.", vTargetList.maxNoOfVariables, maxnoofvars); // diagResult = System.Windows.Forms.MessageBox.Show("An invalid value has been entered for the maximum number of variables in the destination variable list" , "Message", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question); } catch (FormatException) { diagResult = System.Windows.Forms.MessageBox.Show("An invalid value has been entered for the maximum number of variables in the target variable list", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question); } catch (OverflowException) { diagResult = System.Windows.Forms.MessageBox.Show("An invalid value has been entered for the maximum number of variables in the target variable list", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question); } if (maxnoofvars < (noSelectedItems + vTargetList.ItemsCount)) { //e.Effects = DragDropEffects.None; //e.Handled = true; message = "The target variable list cannot have more than " + vTargetList.maxNoOfVariables + " variable(s). Please reduce your selection or remove variables from the target list"; diagResult = System.Windows.Forms.MessageBox.Show(message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question); return; } } //System.Collections.IList <DataSourceVariable> variables = vTargetList.SelectedItems; object objspin = GetResource(ComboBoxForNWayInteraction); if (objspin == null || (!(objspin is BSkyNonEditableComboBox))) { MessageBox.Show("Unable to associate this N Way Interaction control with a non editable comboBox control on the same canvas, you must specify a non-editable combobox control"); return; } //If there are valid variables then move them BSkyNonEditableComboBox objCombo = objspin as BSkyNonEditableComboBox; string interaction = objCombo.SelectedItem as string; int interactionLevel = 0; //interactionLevel = Convert.ToInt32(interaction[0].ToString()); switch (interaction) { case "All 2 way": interactionLevel = 2; break; case "All 3 way": interactionLevel = 3; break; case "All 4 way": interactionLevel = 4; break; case "All 5 way": interactionLevel = 5; break; } string[] permutationsAsString = null; if (noSelectedItems < interactionLevel) { string printString = string.Format("You need to select {0} or more variables for a {0} way interaction", interactionLevel); MessageBox.Show(printString); return; } for (i = 0; i < noSelectedItems; i++) { DataSourceVariable var = vInputList.SelectedItems[i] as DataSourceVariable; variableListForCombo.Add(var.Name); } permutationsAsString = variableListForCombo.ToArray(); // permResult = GetPermutations(permutationsAsString, interactionLevel); permResult = Combinations(permutationsAsString, interactionLevel); string permutation = ""; foreach (IEnumerable <string> itm in permResult) { List <string> set = itm.ToList <string>(); permutation = set.Aggregate((m, n) => m + ":" + n); listOfPermutations.Add(permutation); } int numberOfItems = listOfPermutations.Count; int y = 0; DataSourceVariable inputVar = vInputList.SelectedItems[0] as DataSourceVariable; for (y = 0; y < numberOfItems; y++) { // newvar = inputVar.Name + "^" + spin.text.Text; //Preferred way DataSourceVariable ds = new DataSourceVariable(); ds.XName = listOfPermutations[y] as string; ds.Name = listOfPermutations[y] as string; ds.RName = listOfPermutations[y] as string; ds.Measure = inputVar.Measure; ds.DataType = inputVar.DataType; ds.Width = inputVar.Width; ds.Decimals = inputVar.Decimals; ds.Label = inputVar.Label; ds.Alignment = inputVar.Alignment; ds.ImgURL = inputVar.ImgURL; validVars.Add(ds as object); } vTargetList.AddItems(validVars); // The code below unselects everything vTargetList.UnselectAll(); //The code below selects all the items that are moved // vTargetList.SetSelectedItems(validVars); //vTargetList.SetSelectedItems(arr1); //Added by Aaron on 12/24/2012 to get the items moved scrolled into view //Added by Aaron on 12/24/2012. Value is 0 as you want to scroll to the top of the selected items vTargetList.ScrollIntoView(validVars[0]); //if (vInputList.MoveVariables) ////The compiler is not allowing me to use vInputList.Items.Remove() so I have to use ItemsSource //{ // ListCollectionView lcw = vInputList.ItemsSource as ListCollectionView; // foreach (object obj in validVars) lcw.Remove(obj); // } vTargetList.Focus(); } //Added by Aaron 07/22/2015 //This is a valid point //else //{ // vTargetList.AddItems(validVars); // //The code below unselects everything // vTargetList.UnselectAll(); // //The code below selects all the items that are moved // vTargetList.SetSelectedItems(validVars); // //Added by Aaron on 12/24/2012 to get the items moved scrolled into view // //Added by Aaron on 12/24/2012. Value is 0 as you want to scroll to the top of the selected items // vTargetList.ScrollIntoView(validVars[0]); //} //if (vInputList.MoveVariables) ////The compiler is not allowing me to use vInputList.Items.Remove() so I have to use ItemsSource //{ // ListCollectionView lcw = vInputList.ItemsSource as ListCollectionView; // foreach (object obj in validVars) lcw.Remove(obj); //} if (vTargetList != null) { vTargetList.Focus(); } //Added by Aaron 08/13/2014 //This is for the case that I am moving a variable year to a target list that already contains year //validvars.count is 0 as I have already detercted its in the target variable. I now want to high light it in the targetvariable if (validVars.Count == 0) { List <object> firstitem = new List <object>(); firstitem.Add(vInputList.SelectedItems[0]); if (vTargetList != null) { if (vTargetList.Items.Contains(vInputList.SelectedItems[0])) { vTargetList.SetSelectedItems(firstitem); vTargetList.Focus(); } } } //If there are variables that don't meet filter criteria, inform the user if (invalidVars.Count > 0) { string cantMove = string.Join(",", invalidVars.ToArray()); System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("The variable(s) \"" + cantMove + "\" cannot be moved, the destination variable list does not allow variables of that type", "Save Changes", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question); } }
public FrameworkElement CreateControl(string objtype) { FrameworkElement b = null; switch (objtype) { case "SourceListBox": //When invoked from the dialog creator, renderVars is set to true // CommonFunctions cf = new CommonFunctions(); b = new BSkySourceList(true, true); BSkySourceList c = b as BSkySourceList; // cf.DisplayNameGridProperty(c, "Type", "The source variable list displays all the variables in the active dataset."); // cf.DisplayNameGridProperty(c, "CanExecute", "Default value is True. This property controls whether the OK button on the dialog is enabled or disabled.If CanExecute =true for all controls on the dialog and contained sub-dialogs, the OK button is enabled, if CanExecute =false for any one control on the dialog or contained sub-dialogs, the OK button is disabled."); //cf.DisplayNameGridProperty(c, "SelectionChangeBehaviour", "Default is empty(no rule). Use this optional property to define rules that trigger property changes in this or other controls, based on the change in state of this variable list control."); // [Description("Default is empty(no rule). Use this optional property to define rules that trigger property changes in this or other controls, based on the change in state of this checkbox control. For example, if a user checks the checkbox, enable a textbox control to capture additional parameters. To define a rule, click in the property and click the elipses button.")] b.Width = 135; b.Height = 240; break; case "TargetListBox": b = new BSkyTargetList(false, true); BSkyTargetList c1 = b as BSkyTargetList; //CommonFunctions cf1 = new CommonFunctions(); //cf1.DisplayNameGridProperty(c1, "Type", "The target variable list contains the variables you want to analyze. Drag and drop the variables you want to analyze from the source variable list to one or more target variable lists."); //cf1.DisplayNameGridProperty(c1, "CanExecute", "Default value is True. This property controls whether the OK button on the dialog is enabled or disabled. If CanExecute =true for all controls on the dialog and contained sub-dialogs, the OK button is enabled, if CanExecute =false for any one control on the dialog or contained sub-dialogs, the OK button is disabled. For example, if a user adds a variable to this variable list, set the canexecute property to 'true', which enables the OK button on the dialog (remember to set another rule to set canexecute to false when All items are removed from this variable list and the value of the itemscount property is 0). This ensures that the dialog cannot be executed unless one or more items are dragged and dropped into this variable list control. To define a rule, click in the property and then click the elipses button."); //cf1.DisplayNameGridProperty(c1, "SelectionChangeBehaviour", "Default is empty(no rule). Use this optional property to define rules that trigger property changes in this or other controls, based on the change in state of this variable list control.For example, if a user adds a variable to this variable list, set the canexecute property to 'true', which enables the OK button on the dialog (remember to set another rule to set canexecute to false when All items are removed from this variable list and the value of the itemscount property is 0). This ensures that the dialog cannot be executed unless one or more items are dragged and dropped into this variable list control. To define a rule, click in the property and then click the elipses button."); b.Width = 135; b.Height = 240; break; case "Button": b = new BSkyButton(); b.Width = 100; b.Height = 30; break; case "textbox": b = new BSkyTextBox(); b.Width = 135; b.Height = 30; break; case "GrpBox": b = new BSkyGroupBox(); b.Width = 150; b.Height = 100; break; case "ChkBox": b = new BSkyCheckBox(); b.Width = 75; b.Height = 20; break; case "RdBtn": b = new BSkyRadioButton(); b.Width = 75; b.Height = 20; break; case "EditCombo": b = new BSkyEditableComboBox(); b.Width = 100; b.Height = 25; break; case "NonEditCombo": b = new BSkyNonEditableComboBox(); b.Width = 100; b.Height = 25; break; case "Label": b = new BSkyLabel(); b.Width = 50; b.Height = 25; break; case "MultiLabel": b = new BSkyMultiLineLabel(); b.Width = 100; b.Height = 25; break; case "Canvas": b = new BSkyCanvas(); BSkyCanvas.dialogMode = true; b.Width = 470; b.Height = 300; // b.Width = 0; // b.Height = 0; break; case "MoveButton": // b = new BSkyVariableMoveButton(true); b = new BSkyVariableMoveButton(); b.Width = 35; b.Height = 35; break; case "RadioGroup": b = new BSkyRadioGroup(); b.Width = 100; b.Height = 100; break; // Added by Aaron 03/31 case "Browse": b = new BSkyBrowse(); b.Width = 100; b.Height = 30; break; case "GroupingVariable": b = new BSkyGroupingVariable(); b.Width = 135; // BSkyGroupingVariable bc = b as BSkyGroupingVariable; // bc.oneItemList.Width = 100; // bc.Height = 50; b.Height = 30; break; case "gridForSymbols": // b = new BSkyScrollTextBox(); b = new BSkygridForSymbols(); //b.Width = 135; // BSkyGroupingVariable bc = b as BSkyGroupingVariable; // bc.oneItemList.Width = 100; // bc.Height = 50; //b.Height = 40; break; case "GridforCompute": // b = new BSkyScrollTextBox(); b = new BSkygridForCompute(); b.Width = 300; b.Height = 300; //b.Width = 135; // BSkyGroupingVariable bc = b as BSkyGroupingVariable; // bc.oneItemList.Width = 100; // bc.Height = 50; //b.Height = 40; break; case "ListBox": // b = new BSkyScrollTextBox(); b = new BSkyListBox(); b.Width = 135; b.Height = 120; // BSkyGroupingVariable bc = b as BSkyGroupingVariable; // bc.oneItemList.Width = 100; // bc.Height = 50; //b.Height = 40; break; case "SourceDatasetList": b = new BSkyListBoxwBorderForDatasets(true, true); b.Width = 135; b.Height = 120; // BSkyGroupingVariable bc = b as BSkyGroupingVariable; // bc.oneItemList.Width = 100; // bc.Height = 50; //b.Height = 40; break; case "DestinationDatasetList": b = new BSkyListBoxwBorderForDatasets(false, true); b.Width = 135; b.Height = 120; // BSkyGroupingVariable bc = b as BSkyGroupingVariable; // bc.oneItemList.Width = 100; // bc.Height = 50; //b.Height = 40; break; case "MasterListBox": // b = new BSkyScrollTextBox(); b = new BSkyMasterListBox(); b.Width = 135; b.Height = 120; // BSkyGroupingVariable bc = b as BSkyGroupingVariable; // bc.oneItemList.Width = 100; // bc.Height = 50; //b.Height = 40; break; case "AggregateCtrl": b = new BSkyAggregateCtrl(); b.Width = 235; b.Height = 335; // BSkyGroupingVariable bc = b as BSkyGroupingVariable; // bc.oneItemList.Width = 100; // bc.Height = 50; //b.Height = 40; break; case "SortCtrl": b = new BSkySortCtrl(); b.Width = 280; b.Height = 202; // BSkyGroupingVariable bc = b as BSkyGroupingVariable; // bc.oneItemList.Width = 100; // bc.Height = 50; //b.Height = 40; break; } //b.Name = GetName(objtype); return(b); }