private void ListBox_Drop(object sender, DragEventArgs e) { DataSourceVariable d = e.Data.GetData(typeof(DataSourceVariable)) as DataSourceVariable; IList list = this.ItemsSource as IList; if (d != null) { list.Add(d); } }
public virtual void TextBox_Drop(object sender, DragEventArgs e) { string[] formats = e.Data.GetFormats(); object sourcedata = e.Data.GetData(formats[0]) as object; DataSourceVariable var = sourcedata as DataSourceVariable; int curcursorpos = this.SelectionStart; //23Feb2017 saving it beacuse it is getting lost after running insert() this.Text = this.Text.Insert(this.SelectionStart, var.Name); //23Feb2017 this.AppendText(var.Name); this.SelectionStart = curcursorpos + var.Name.Length; //23Feb2017 move the cursor to the end of the text that was just inserted. }
private void TextBox_DragOver(object sender, DragEventArgs e) { string[] formats = e.Data.GetFormats(); DataSourceVariable sourcedata = e.Data.GetData(formats[0]) as DataSourceVariable; if (sourcedata != null) { e.Effects = DragDropEffects.Copy; } e.Handled = true; }
private void ListBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DataSourceVariable data = GetDataFromListBox(this, e.GetPosition(this)) as DataSourceVariable; if (data != null) { DragDropEffects effs = DragDrop.DoDragDrop(this, data, DragDropEffects.Move); if (effs == DragDropEffects.Move) { IList lst = this.ItemsSource as IList; lst.Remove(data); } } }
private void TextBox_DragOver(object sender, DragEventArgs e) { // if ((AutoVar == false) && (BSkyCanvas.sourceDrag == (ListBox)sender)) e.Effects = DragDropEffects.None; // //else //// e.Effects = null != e.Data.GetData(typeof(object)) ? DragDropEffects.Move : DragDropEffects.None; //02/24/2013 //Added by Aaron //THis ensures that the move icon is displayed when dragging and dropping within the same listbox //If we are not dragging and dropping within the same listbox, the copy icon is displayed //if ((AutoVar == true) && (BSkyCanvas.sourceDrag == (ListBox)sender)) e.Effects = DragDropEffects.Move; //Added 10/19/2013 //Added the code below to support listboxes that only allow a pre-specified number of items or less // //System.Windows.Forms.DialogResult diagResult; //double result = -1; string[] formats = e.Data.GetFormats(); DataSourceVariable sourcedata = e.Data.GetData(formats[0]) as DataSourceVariable; //Added 04/03/2014 //If I highlight and drag something in a textbox to the textbox itself the application will hand //Allow drop isenabled on a textbox so there is nothing that prevents me from draging text in one textbox to another if (sourcedata == null) { e.Effects = DragDropEffects.None; e.Handled = true; return; } //BSky.Controls.filter f=new filter(); //Added by Aaron 09/02/2013 //Added code below to check filters when dragging and dropping // e.Effects = DragDropEffects.Copy; // else e.Effects = DragDropEffects.Copy; // //else e.Effects = DragDropEffects.Move; // e.Effects = DragDropEffects.Copy; e.Handled = true; }
public virtual void TextBox_Drop(object sender, DragEventArgs e) { // int selindex = 0; string[] formats = e.Data.GetFormats(); DataSourceVariable sourcedata = e.Data.GetData(formats[0]) as DataSourceVariable; //txtCommand.Text = txtCommand.Text.Insert(txtCommand.SelectionStart, "{" + o.Name + "}"); //this.Text = this.Text.Insert(this.SelectionStart, sourcedata.Name); //selindex = this.SelectionStart; //selindex = this.Text.Length; //this.Text = this.Text.Insert(selindex, sourcedata.Name); //this.ScrollToEnd(); //this.Focus(); this.AppendText(sourcedata.Name); // this.SelectionStart = this.Text.Length; this.ScrollToEnd(); //this.Focus(); //this.ScrollToCaret(); // txt. }
//Added by Aaron 10/02/2015 //The function checkIfAggregateOptionExists checks all the items within the target listbox looking to see if the user //has already selected the aggregate option public bool checkIfAggregateOptionExists(DragDropListForSummarize target, DataSourceVariable sourceitem, string functionName) { string aggregateFunction = ""; int count = 0; int i = 0; DataSourceVariable ds = null; //bool retval = false; aggregateFunction = functionName + "(" + sourceitem.Name + ")"; // target.ite count = target.ItemsCount; foreach (object obj in target.Items) { ds = obj as DataSourceVariable; if (ds.XName == aggregateFunction) { return(true); } //else return false; } return(false); }
public UAReturn RefreshDataset_old(ServerDataSource dataSource)//25Mar2013 refresh on new row added by compute { UAReturn result = new UAReturn() { Success = false }; if (true)//dispatcher.GetErrorText().Contains(BSky.Statistics.R.RService.RCommandReturn.Success)) { logService.WriteToLogLevel("GetColnames Start:", LogLevelEnum.Info); //Get matrix columns string subCommand = RCommandStrings.GetDataFrameColumnNames(dataSource); object colnames = dispatcher.EvaluateToObject(subCommand, false); string[] columnNames = null;//var columnNames = new string[] { "aaa", "bbb" }; Type retType = colnames.GetType(); if (retType.Name == "String[]")//for multicols { columnNames = (String[])colnames; } else if (retType.Name == "String")//for single col { columnNames = new string[1]; columnNames[0] = (String)colnames; } else { return new UAReturn() { Success = false }; } logService.WriteToLogLevel("GetColnames End", LogLevelEnum.Info); logService.WriteToLogLevel("Get Max factor start", LogLevelEnum.Info); //maximum factors allowed object maxf = (getMaxFactors(dataSource)); int mxf;//sym.AsInteger()[0]; bool parseSuccess = int.TryParse(maxf.ToString(), out mxf); dataSource.MaxFactors = parseSuccess ? mxf : 40; //Hardcoded Default max factor count //int.Parse(maxf.ToString()); logService.WriteToLogLevel("Get Max factor end", LogLevelEnum.Info); dataSource.Variables.Clear(); int rowcount = GetRowCount(dataSource);//31Dec2014 int columnindex = 1; foreach (object s in columnNames) { logService.WriteToLogLevel("Get Col Prop start : " + s.ToString(), LogLevelEnum.Info); object resobj = GetColProp(dataSource, s.ToString()).SimpleTypeData; object[] cprops = (object[])resobj; logService.WriteToLogLevel("Get Col Prop end : " + s.ToString(), LogLevelEnum.Info); logService.WriteToLogLevel("Set Col Prop start : " + s.ToString(), LogLevelEnum.Info); DataSourceVariable var = new DataSourceVariable() { Name = s.ToString(), Label = cprops[2].ToString(), DataType = GetCovertedDataType(cprops[1].ToString()), Measure = DataColumnMeasureEnum.Scale, Width = 4, Decimals = 0, Columns = 8, MissType = cprops[5].ToString(), RowCount = rowcount //GetVectorLength(dataSource, s.ToString()) //factormapList = new List<FactorMap>()//17Apr2014 }; logService.WriteToLogLevel("Set Col Prop end : " + s.ToString(), LogLevelEnum.Info); logService.WriteToLogLevel("Get-Set Col factors start : " + s.ToString(), LogLevelEnum.Info); //uadatasets$lst$ added by Anil in following two bool isfactors = (bool)dispatcher.EvaluateToObject(string.Format("is.factor({0}[,{1}])", dataSource.Name, columnindex), false);//is.factor(uadatasets$lst${0}[,{1}]) if (isfactors) { //(DataColumnMeasureEnum)Enum.Parse(typeof(DataColumnMeasureEnum), GetMeasure(dataSource, s.ToString())); bool isOrdered = (bool)dispatcher.EvaluateToObject(string.Format("is.ordered({0}[,{1}])", dataSource.Name, columnindex), false);//is.ordered(uadatasets$lst${0}[,{1}]) if (isOrdered) var.Measure = DataColumnMeasureEnum.Ordinal; else var.Measure = DataColumnMeasureEnum.Nominal; // default is set in above para which will be overwritten in this line if its factor type //reading all levels/factors object tempO = (object)GetFactorValues(dataSource, s.ToString()).SimpleTypeData; if (tempO != null) { if (tempO.GetType().Name.Equals("String[]"))//tempO.GetType().IsArray) { string[] vals = tempO as string[]; var.Values.AddRange(vals);//adding all values to list } else if (tempO.GetType().Name.Equals("String")) { string vals = tempO as string; var.Values.Add(vals);//adding all values to list } else { //some other unexpected type was returned in tempO. //can print an error message here. string[] charfactors = (tempO as SymbolicExpression).AsCharacter().ToArray(); var.Values.AddRange(charfactors);//adding all values to list } } } logService.WriteToLogLevel("Get-Set Col factors end : " + s.ToString(), LogLevelEnum.Info); logService.WriteToLogLevel("Get-Set Col Missing start : " + s.ToString(), LogLevelEnum.Info); if (!(var.MissType == "none")) { object tempObj = (object)GetMissingValues(dataSource, s.ToString()).SimpleTypeData; if (tempObj != null) { double[] misval; if (tempObj.GetType().Name.Equals("Double[]"))// (tempObj.GetType().IsArray) { misval = tempObj as double[]; foreach (double mv in misval) var.Missing.Add(mv.ToString()); } else if (tempObj.GetType().Name.Equals("Double")) { double misvalue = (double)tempObj; var.Missing.Add(misvalue.ToString()); } else { //some other unexpected type was returned in tempO. //can print an error message here. var.Missing.Add("");//adding blank } } } else { string misval = "none"; var.Missing.Add(misval); } logService.WriteToLogLevel("Get-Set Col Missing end : " + s.ToString(), LogLevelEnum.Info); logService.WriteToLogLevel("Get-Set others start : " + s.ToString(), LogLevelEnum.Info); if (dataSource.Extension == "rdata")// if filetype is RDATA. { if (cprops[9].ToString() != "-2146826288") var.Width = Int32.Parse(cprops[9].ToString()); if (cprops[10].ToString() != "-2146826288") var.Decimals = Int32.Parse(cprops[10].ToString()); if (cprops[11].ToString() != "-2146826288") var.Columns = UInt32.Parse(cprops[11].ToString()); } try { ////////// Alignment //////////// if (cprops[6].ToString() == "-2146826288") cprops[6] = "Left"; DataColumnAlignmentEnum alignVal = (DataColumnAlignmentEnum)Enum.Parse(typeof(DataColumnAlignmentEnum), cprops[6].ToString()); if (Enum.IsDefined(typeof(DataColumnAlignmentEnum), alignVal)) var.Alignment = alignVal; else var.Alignment = DataColumnAlignmentEnum.Left; var.Role = DataColumnRole.Input;// Role is not used, I guess, so 'if' is commented above } catch (ArgumentException) { //Console.WriteLine("Not a member of the enumeration."); logService.WriteToLogLevel("Not a member of enum(Alignment) ", LogLevelEnum.Error); } logService.WriteToLogLevel("Get-Set others end : " + s.ToString(), LogLevelEnum.Info); dataSource.Variables.Add(var); columnindex++; dataSource.RowCount = Math.Max(dataSource.RowCount, dataSource.Variables.Last().RowCount); } result.Datasource = dataSource; result.Success = true; this.DataSources.Add(dataSource); } return result; }
private void removeVarGridVariable() { IAnalyticsService analyticServ = LifetimeService.Instance.Container.Resolve<IAnalyticsService>(); analyticServ.removeVargridColumn(delcolname, ds.Name);//removing R side //renumbering renumberRowHeader(variableGrid); //remove var in UI side datasets DataSourceVariable dsv = new DataSourceVariable(); dsv = ds.Variables.ElementAt(delvarindex); ds.Variables.Remove(dsv); //refresh refreshDataGrid(); }
void InspectBinding_Executed() { CommonFunctions cf = new CommonFunctions(); InspectDialog window = new InspectDialog(); System.Windows.Forms.DialogResult result; //Added by Aaron 05/11/2014 //Clearing up chainopen canvas as we are starting from a Blank Slate when ever we are inspecting a dialog //We alsodo it when we finish inspecting the dialog BSkyCanvas.chainOpenCanvas.Clear(); System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog(); dialog.Filter = "Xaml Document (*.bsky)|*.bsky"; result = dialog.ShowDialog(); object obj; string nameOfFile; if (result == System.Windows.Forms.DialogResult.OK) { string xamlfile = string.Empty, outputfile = string.Empty; cf.SaveToLocation(@dialog.FileName, Path.GetTempPath(), out xamlfile, out outputfile); if (!string.IsNullOrEmpty(xamlfile)) { FileStream stream = System.IO.File.Open(Path.Combine(Path.GetTempPath(), Path.GetFileName(xamlfile)), FileMode.Open); //FileStream stream = File.Open(Path.Combine(Path.GetTempPath(), xamlfile,FileMode.Open); try { //Added by Aaron 11/24/2013 //The line below is important as when the dialog editor is launched for some reason and I DONT know why //BSKYCanvas is invoked from the controlfactor and hence dialogMode is true, we need to reset BSkyCanvas.dialogMode = false; obj = XamlReader.Load(stream); //Added by Aaron 04/13/2014 //There are 3 conditions here, when I launch dialog editor //1. The first thing I do is open an existing dialog. Chainopencanvas.count=0 //2. I have an existing dialog open and I click open again. Chainopencanvas.count=2. The first dialog is empty as I clean the existing canvas and open a new one //3. I hit new the first time I open dialogeditor and then I hit open. Again,Chainopencanvas.count=2. The first dialog is empty as I clean the existing canvas and open a new one //The chainopencanvas at this point has 2 entries, one with an empty canvas as we have removed all the children //the other with the dialog we just opened //we remove the empty one //if (BSkyCanvas.chainOpenCanvas.Count > 1) // BSkyCanvas.chainOpenCanvas.RemoveAt(0); // 11/18/2012, code inserted by Aaron to display the predetermined variable list BSkyCanvas canvasobj; canvasobj = obj as BSkyCanvas; BSkyCanvas.chainOpenCanvas.Add(canvasobj); BSkyCanvas.previewinspectMode = true; //Added by Aaron 12/08/2013 //if (canvasobj.Command == true) c1ToolbarStrip1.IsEnabled = false; //else c1ToolbarStrip1.IsEnabled = true; //Added by Aaron 11/21/2013 //Added line below to enable checking of properties in behaviour.cs i.e. propertyname and control name in dialog //editor mode to make sure that the property names are generated correctly // BSkyCanvas.dialogMode = true; //Added 04/07/2013 //The properties like outputdefinition are not set for firstCanvas //The line below sets it // firstCanvas = canvasobj; foreach (UIElement child in canvasobj.Children) { // Code below has to be written as we have saved BSKYvariable list with rendervars=False. //BSKyvariablelist has already been created with the default constructore and we need to //do some work to point the itemsource properties to the dummy variables we create if (child.GetType().Name == "BSkyVariableList") { List <DataSourceVariable> preview = new List <DataSourceVariable>(); DataSourceVariable var1 = new DataSourceVariable(); var1.Name = "var1"; var1.DataType = DataColumnTypeEnum.Numeric; var1.Width = 4; var1.Decimals = 0; var1.Label = "var1"; var1.Alignment = DataColumnAlignmentEnum.Left; var1.Measure = DataColumnMeasureEnum.Scale; var1.ImgURL = "../Resources/scale.png"; // var1.ImgURL = "C:/Users/Aiden/Downloads/Client/libs/BSky.Controls/Resources/scale.png"; DataSourceVariable var2 = new DataSourceVariable(); var2.Name = "var2"; var2.DataType = DataColumnTypeEnum.Character; var2.Width = 4; var2.Decimals = 0; var2.Label = "var2"; var2.Alignment = DataColumnAlignmentEnum.Left; var2.Measure = DataColumnMeasureEnum.Nominal;; var2.ImgURL = "../Resources/nominal.png"; DataSourceVariable var3 = new DataSourceVariable(); var3.Name = "var3"; var3.DataType = DataColumnTypeEnum.Character; var3.Width = 4; var3.Decimals = 0; var3.Label = "var3"; var3.Alignment = DataColumnAlignmentEnum.Left; var3.Measure = DataColumnMeasureEnum.Ordinal; var3.ImgURL = "../Resources/ordinal.png"; preview.Add(var1); preview.Add(var2); preview.Add(var3); BSkyVariableList temp; temp = child as BSkyVariableList; // 12/25/2012 //renderVars =TRUE meanswe will render var1, var2 and var3 as listed above. This means that we are in the Dialog designer temp.renderVars = false; temp.ItemsSource = preview; } //Added by Aaron 04/06/2014 //Code below ensures that when the dialog is opened in dialog editor mode, the IsEnabled from //the base class is set to true. This ensures that the control can never be disabled in dialog editor mode //Once the dialog is saved, the Enabled property is saved to the base ISEnabled property to make sure that //the proper state of the dialog is saved //if (child is IBSkyEnabledControl) //{ // IBSkyEnabledControl bskyCtrl = child as IBSkyEnabledControl; // bskyCtrl.Enabled = bskyCtrl.IsEnabled; // bskyCtrl.IsEnabled = true; //} } // subCanvasCount = GetCanvasObjectCount(obj as BSkyCanvas); // BSkyControlFactory.SetCanvasCount(subCanvasCount); // OpenCanvas(obj); //Aaron 01/12/2013 //This stores the file name so that we don't have to display the file save dialog on file save and we can save to the file directly; nameOfFile = @dialog.FileName; //01/26/2013 Aaron //Setting the title of the window //Title = nameOfFile; //Aaron: Commented this on 12/15 // myCanvas.OutputDefinition = Path.Combine(Path.GetTempPath(), outputfile); //Aaron 01/26/2013 //Making sure saved is set to true as soon as you open the dialog. // saved = true; //Aaron //02/10/2013 //Added code below to ensure that the RoutedUICommand gets fired correctly and the menu items under file and Dialog (top level menu items) //are properly opened and closed // c1ToolbarStrip1.IsEnabled = true; // CanClose = true; // CanSave = true; //this.Focus(); // window.Template = obj as FrameworkElement; BSkyCanvas cs = obj as BSkyCanvas; System.Windows.Forms.PropertyGrid CanvasPropertyGrid; // window.CanvasPropHost = obj as BSkyCanvas; CanvasPropertyGrid = window.CanvasPropHost.Child as System.Windows.Forms.PropertyGrid; // window.CanvasHost.Child = obj as BSkyCanvas; window.Template = cs; CanvasPropertyGrid.SelectedObject = obj as BSkyCanvas; window.setSizeOfPropertyGrid(); window.Width = cs.Width + 20; // window.CanvasHost.Width = cs.Width; // window.CanvasHost.Height = cs.Height; // window.Height = cs.Height + 200+80; //CanvasPropertyGrid.Refresh(); // Aaron //03/05/2012 //Making the preview window a fixed size window // if (obj.GetType().Name == "BSkyCanvas") window.ResizeMode = ResizeMode.NoResize; stream.Close(); window.ShowDialog(); BSkyCanvas.previewinspectMode = false; //Added by Aaron 05/11/2014 //Clearing up chainopen canvas as we are starting from a Blank Slate when ever we are inspecting a dialog //We alsodo it when we finish inspecting the dialog BSkyCanvas.chainOpenCanvas.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show(BSky.GlobalResources.Properties.Resources.CantOpenFile); } // ******************************************************************************************************* //gencopy(); //Aaron 11/25/2012, the line below needs to be uncommented once the serialization issue is addressed with Anil // string xaml = GetXamlforpreview(); //string xaml = GetXaml(); //************************************************************************************************* } }
public UAReturn RefreshDataset(ServerDataSource dataSource)//04Mar2015 refresh on new row added by compute { UAReturn result = new UAReturn() { Success = false }; if (true)//dispatcher.GetErrorText().Contains(BSky.Statistics.R.RService.RCommandReturn.Success)) { //Get matrix columns string subCommand = RCommandStrings.GetDataFrameColumnNames(dataSource); object colnames = dispatcher.EvaluateToObject(subCommand, false); //if colnames are null. Because we were unable to open the dataset because of any reason. if (colnames == null) { CloseDataset(dataSource); result.Success = false; result.Error = "Error Opening Dataset."; return result; } //if colnames are duplicate then we dont load the dataset and show error message. Also we clean R if (isDuplicateColnames(colnames)) { CloseDataset(dataSource); result.Success = false; result.Error = "Dulicate Column Names in Dataset"; return result; } if (colnames != null) { string[] columnNames = null;//var columnNames = new string[] { "aaa", "bbb" }; Type retType = colnames.GetType(); if (retType.Name == "String[]")//for multicols { columnNames = (String[])colnames; } else if (retType.Name == "String")//for single col { columnNames = new string[1]; columnNames[0] = (String)colnames; } else { return new UAReturn() { Success = false }; } //maximum factors allowed object maxf = (getMaxFactors(dataSource)); //sym = maxf as SymbolicExpression; int mxf;//sym.AsInteger()[0]; bool parseSuccess = int.TryParse(maxf.ToString(), out mxf); dataSource.MaxFactors = parseSuccess ? mxf : 40; //Hardcoded Default max factor count //int.Parse(maxf.ToString()); dataSource.Variables.Clear(); int rowcount = GetRowCount(dataSource);//31Dec2014 int columnindex = 1; SymbolicExpression symex = null; foreach (object s in columnNames) { symex = dispatcher.EvaluateToSymExp(string.Format("UAgetColProperties(dataSetNameOrIndex='{0}', colNameOrIndex={1}, asClass=FALSE)", dataSource.Name, columnindex)); GenericVector gv = symex.AsList(); string colclass = dispatcher.RawEvaluateGetstring(string.Format("class({0}[[{1}]])", dataSource.Name, columnindex));//,true); if (colclass == null) { colclass = ""; } string lab = (gv[2] != null && gv[2].AsCharacter() != null && gv[2].AsCharacter()[0] != null) ? gv[2].AsCharacter()[0].ToString() : string.Empty; DataColumnTypeEnum dtyp = (gv[1] != null && gv[1].AsCharacter() != null && gv[1].AsCharacter()[0] != null) ? GetCovertedDataType(gv[1].AsCharacter()[0].ToString()) : DataColumnTypeEnum.Character; string mistyp = (gv[5] != null && gv[5].AsCharacter() != null && gv[5].AsCharacter()[0] != null) ? gv[5].AsCharacter()[0].ToString() : string.Empty; DataSourceVariable var = new DataSourceVariable() { Name = s.ToString(), Label = lab, DataType = dtyp, DataClass = colclass, Measure = DataColumnMeasureEnum.Scale, Width = 4, Decimals = 0, Columns = 8, MissType = mistyp, RowCount = rowcount //GetVectorLength(dataSource, s.ToString()) }; if (symex != null) { //if (gv.Length == 1) { ////Set Measure switch (gv[7].AsCharacter()[0].ToString()) { case "factor": var.Measure = DataColumnMeasureEnum.Nominal; break; case "ordinal": var.Measure = DataColumnMeasureEnum.Ordinal; break; default: if(var.DataType == DataColumnTypeEnum.Character) //02Jun2015 treating "character" type as Nominal in UI. In R its not factor { var.Measure = DataColumnMeasureEnum.Nominal; } else var.Measure = DataColumnMeasureEnum.Scale; break; } CharacterVector cv = gv[3].AsCharacter(); string[] vals = cv.ToArray(); if (vals != null && vals.Length > 0) { if (vals.Length > 1) { var.Values.AddRange(vals);//more than 1 strings } else if (vals[0].Trim().Length > 0) { var.Values.Add(vals[0]);//1 string } } if (!(var.MissType == "none")) { CharacterVector cvv = gv[3].AsCharacter(); string[] misvals = cvv.ToArray(); if (misvals != null && misvals.Length > 0) { if (misvals.Length > 1) { var.Missing.AddRange(misvals);//more than 1 strings } else if (misvals[0].Trim().Length > 0) { var.Missing.Add(misvals[0]);//1 string } } } else { string misval = "none"; var.Missing.Add(misval); } } } if (dataSource.Extension == "rdata")// if filetype is RDATA. { if (gv[9].AsCharacter() != null && gv[9].AsCharacter()[0].ToString() != "-2146826288") var.Width = Int32.Parse(gv[9].AsCharacter()[0].ToString()); if (gv[10].AsCharacter() != null && gv[10].AsCharacter()[0].ToString() != "-2146826288") var.Decimals = Int32.Parse(gv[10].AsCharacter()[0].ToString()); if (gv[11].AsCharacter() != null && gv[11].AsCharacter()[0].ToString() != "-2146826288") var.Columns = UInt32.Parse(gv[11].AsCharacter()[0].ToString()); } try { ////////// Alignment //////////// //logService.WriteToLogLevel("Get-Set Alignment start : " + s.ToString(), LogLevelEnum.Info); string align = gv[6].AsCharacter()[0].ToString(); if (align == "-2146826288") align = "Left"; DataColumnAlignmentEnum alignVal = (DataColumnAlignmentEnum)Enum.Parse(typeof(DataColumnAlignmentEnum), align); if (Enum.IsDefined(typeof(DataColumnAlignmentEnum), alignVal)) var.Alignment = alignVal; else var.Alignment = DataColumnAlignmentEnum.Left; var.Role = DataColumnRole.Input;// Role is not used, I guess, so 'if' is commented above //logService.WriteToLogLevel("Get-Set Alignment start : " + s.ToString(), LogLevelEnum.Info); } catch (ArgumentException) { logService.WriteToLogLevel("Not a member of enum(Alignment) ", LogLevelEnum.Error); } dataSource.Variables.Add(var); columnindex++; dataSource.RowCount = Math.Max(dataSource.RowCount, dataSource.Variables.Last().RowCount); } result.Datasource = dataSource; result.Success = true; this.DataSources.Add(dataSource); } else // no need of this 'else' unless you want to put custom error message in result { } } return result; }
// Aaron 09/02/2013 //Modified the command to check for filters on drag and drop //the drag over command provides visible indication of whether you can drag and drop an item over the control //If e.Effects =DragDropEffects.Move you can move the item, if e.Effects = DragDropEffects.Copy you can copy //If e.Effects =DragDropEffects.None, you cannot do anything AND THE DRAG AND DROP TERMINATES. THE function ListBox_Drop is not called private void ListBox_DragOver(object sender, DragEventArgs e) { // if ((AutoVar == false) && (BSkyCanvas.sourceDrag == (ListBox)sender)) e.Effects = DragDropEffects.None; // //else //// e.Effects = null != e.Data.GetData(typeof(object)) ? DragDropEffects.Move : DragDropEffects.None; //02/24/2013 //Added by Aaron //THis ensures that the move icon is displayed when dragging and dropping within the same listbox //If we are not dragging and dropping within the same listbox, the copy icon is displayed //if ((AutoVar == true) && (BSkyCanvas.sourceDrag == (ListBox)sender)) e.Effects = DragDropEffects.Move; //Added 10/19/2013 //Added the code below to support listboxes that only allow a pre-specified number of items or less // string[] formats = e.Data.GetFormats(); DataSourceVariable sourcedata = e.Data.GetData(formats[0]) as DataSourceVariable; //Added 04/03/2014 //If I highlight and drag something in a textbox and drag and drop to the variable list the application will hang //In code below I check whether sourcedata is of type datasource variable. If it is not, I drag allow the drop if (sourcedata == null) { e.Effects = DragDropEffects.None; e.Handled = true; return; } System.Windows.Forms.DialogResult diagResult; double result = -1; if (this.maxNoOfVariables != string.Empty && this.maxNoOfVariables != null) { try { result = Convert.ToDouble(this.maxNoOfVariables); //Console.WriteLine("Converted '{0}' to {1}.", this.maxNoOfVariables, result); } catch (FormatException) { diagResult = System.Windows.Forms.MessageBox.Show("An invalid value has been entered for the maximum number of variables in the destination 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 destination variable list", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question); } if (this.ItemsCount == result) { e.Effects = DragDropEffects.None; e.Handled = true; return; } } //BSky.Controls.filter f=new filter(); //Added by Aaron 09/02/2013 //Added code below to check filters when dragging and dropping // bool filterResults = CheckForFilter(sourcedata); if (!filterResults) { e.Effects = DragDropEffects.None; e.Handled = true; return; } if ((BSkyCanvas.sourceDrag == (ListBox)sender)) { e.Effects = DragDropEffects.Move; } else { e.Effects = DragDropEffects.Copy; } // else e.Effects = DragDropEffects.Copy; // //else e.Effects = DragDropEffects.Move; // e.Effects = DragDropEffects.Copy; e.Handled = true; }
//public virtual bool CheckForFilter(object o) //{ // return true; //} //Aaron 09/12/2013 //commented the lines above to change the virtual bool function to a non virtual function //commented the override in BSkySourceList public bool CheckForFilter(object o) { //01/07/2013 Aaron //changed the if condition below from !base.Autovar to base.Autovar //Autovar = true means I am auromatrcally populating variables, also means its the source list //Aaron 03/31/2013 Autovar =true means that its the target and not the source //Aaron 09/03/2013 //Commented the 2 lines below. This is becuase we are calling this functionwhen the source variable list is loaded //and also when you are dragging a source variable to a target or a source variable from target back to source // if (base.AutoVar) // return true; DataSourceVariable var = o as DataSourceVariable; double result; bool dataresult = false; bool measureresult = false; bool isdouble; switch (var.DataType) { case DataColumnTypeEnum.Character: if (Filter.Contains("String")) { dataresult = true; } break; case DataColumnTypeEnum.Numeric: case DataColumnTypeEnum.Double: case DataColumnTypeEnum.Integer: //case DataColumnTypeEnum.Int: if (Filter.Contains("Numeric")) { dataresult = true; } break; //08Feb2016 following Date and Logical code added case DataColumnTypeEnum.Date: case DataColumnTypeEnum.POSIXct: case DataColumnTypeEnum.POSIXlt: if (Filter.Contains("Date")) { dataresult = true; } break; case DataColumnTypeEnum.Logical: if (Filter.Contains("Logical")) { dataresult = true; } break; } if (!dataresult) { return(false); } switch (var.Measure) { case DataColumnMeasureEnum.Nominal: if (Filter.Contains("Nominal")) { if (nomlevels != "" && nomlevels != null) { //var.Values.Count) isdouble = Double.TryParse(nomlevels, out result); //Added by Aaron on 10/19/2013 //decremented the count by 1 to reflect the fact that var.values.count is one more than the //expected number of levels to handle the .that we add in the grid so that users ca if ((var.Values.Count - 1) == result) { measureresult = true; } else { measureresult = false; } break; } measureresult = true; measureresult = true; } break; case DataColumnMeasureEnum.Ordinal: if (Filter.Contains("Ordinal")) { if (ordlevels != "" && nomlevels != null) { //var.Values.Count) isdouble = Double.TryParse(ordlevels, out result); if ((var.Values.Count - 1) == result) { measureresult = true; } else { measureresult = false; } break; } measureresult = true; } break; case DataColumnMeasureEnum.Scale: if (Filter.Contains("Scale")) { measureresult = true; } break; case DataColumnMeasureEnum.String: //05Feb2017 if (Filter.Contains("String")) { measureresult = true; } break; case DataColumnMeasureEnum.Date: //08Feb2017 if (Filter.Contains("Date")) { measureresult = true; } break; case DataColumnMeasureEnum.Logical: //08Feb2017 if (Filter.Contains("Logical")) { measureresult = true; } break; } return(measureresult); }
public virtual void ListBox_Drop(object sender, DragEventArgs e) { string functionName; bool doesAggOptionExist = false; string[] formats = e.Data.GetFormats(); int firstpos = 0; int lastpos = 0; bool filterResults = false; //BSkyCanvas.destDrag = (ListBox)sender; //The code below disables drag and drop on the source list, added June 16th int destindex, i, j, sourceindex, noofitems; //object[] newlist =null; //Aaron Modified 11/04 if (AutoVar == false && this == BSkyCanvas.sourceDrag) { e.Effects = DragDropEffects.None; return; } if (formats.Length > 0) { object sourcedata = e.Data.GetData(formats[0]) as object; ListCollectionView list = this.ItemsSource as ListCollectionView; if (sourcedata != null) { //Soure and destination are different if (this != BSkyCanvas.sourceDrag) { //Added by Aaron 07/22/2015 if (list.IndexOf(sourcedata) < 0) { //Added by Aaron 07/22/2015 //a dragdrop list class has a property summary control. This indicates that it is used //in a summary control. If this is true, i have to prefix the variable name by the //function name in the combo box //if (this.summaryCtrl == true) //{ functionName = getFunctionFromComboBox(); DataSourceVariable ds = sourcedata as DataSourceVariable; if (functionName != "asc") { ds.XName = functionName + "(" + ds.RName + ")"; } else { ds.XName = ds.RName; } //ds.XName = functionName + "(" + ds.RName + ")"; list.AddNewItem(ds); list.CommitNew(); //} //else //{ //Added by Aaron 07/22/2015 //If I am moving the variable back from a drag drop that is associated with a summary control, I need to remove the sumarizing function //if (BSkyCanvas.sourceDrag is DragDropListForSummarize) //{ // DataSourceVariable ds1 = sourcedata as DataSourceVariable; // firstpos = ds1.Name.IndexOf(@"("); // lastpos = ds1.Name.IndexOf(@")"); // ds1.XName = ds1.XName.Substring(firstpos+1, (lastpos - (firstpos+1))); //} // list.AddNewItem(sourcedata); // list.CommitNew(); //} //this.SelectedItem = d; //e.Effects = DragDropEffects.All; this.ScrollIntoView(sourcedata);//AutoScroll } else { //Check if the aggregate option is already present functionName = getFunctionFromComboBox(); doesAggOptionExist = checkIfAggregateOptionExists(this, sourcedata as DataSourceVariable, functionName); DataSourceVariable ds = sourcedata as DataSourceVariable; if (!doesAggOptionExist) { DataSourceVariable newds = new DataSourceVariable(); //31Jul2016 9:43AM :Anil: line will not work as we moved RNAME out of the Name property in DataSource: newds.Name = ds.RName; //RName can support A.2 as col name newds.RName = ds.RName; //Anil: This fixes: 31Jul2016 9:43AM newds.XName = ds.XName; newds.DataType = ds.DataType; newds.DataClass = ds.DataClass; newds.Width = ds.Width; newds.Decimals = ds.Decimals; newds.Label = ds.Label; newds.Values = ds.Values; newds.Missing = ds.Missing; newds.MissType = ds.MissType; newds.Columns = ds.Columns; newds.Measure = ds.Measure; newds.ImgURL = ds.ImgURL; filterResults = this.CheckForFilter(newds); if (filterResults) { if (functionName != "asc") { newds.XName = functionName + "(" + newds.RName + ")"; } else { newds.XName = newds.RName; } //newds.XName = functionName + "(" + ds.RName + ")"; list.AddNewItem(newds); list.CommitNew(); this.ScrollIntoView(newds);//AutoScroll } // else // { // invalidVars.Add(vInputList.SelectedItems[i]); // } } } //Aaron 09/11/2013 Commented 2 lines below //else // e.Effects = DragDropEffects.None; //this.UnselectAll(); //02/24 Aaron //This is to signify that since the source and destination are different, we have finished the copy. //We will go back to the initiation of the drag and drop to see if the source needs to be removed or kept // in the source listbox. This will be determined by the value of movevariables property e.Effects = DragDropEffects.Copy; this.SelectedItem = sourcedata; Focus(); } //The source and the destination are the same i.e. the target variable else { object destdata = GetDataFromListBox(this, e.GetPosition(this)) as object; if (destdata == sourcedata) { return; } destindex = list.IndexOf(destdata); noofitems = list.Count; object[] newlist = new object[noofitems]; sourceindex = list.IndexOf(sourcedata); if (destindex != sourceindex) { //This is the case of move to the end if (destindex == -1) { for (i = 0; i < noofitems; i++) { if (i == sourceindex) { while (i <= (noofitems - 2)) { newlist[i] = list.GetItemAt(i + 1); i = i + 1; } newlist[i] = list.GetItemAt(sourceindex); i = i + 1; } else { newlist[i] = list.GetItemAt(i); } } } //End of move to the end else { if (destindex < sourceindex) { for (i = 0; i < noofitems; i++) { j = i; if (i == destindex) { newlist[i] = list.GetItemAt(sourceindex); i = i + 1; while (j < noofitems) { if (j != sourceindex) { newlist[i] = list.GetItemAt(j); i = i + 1; } j = j + 1; } } else { newlist[i] = list.GetItemAt(i); } } } ////End when sourceindex > destindex else if (sourceindex < destindex) //I have tested this { for (i = 0; i < noofitems; i++) { j = i; if (i == sourceindex) { j = j + 1; while (i < noofitems) { if (i == destindex) { newlist[i] = list.GetItemAt(sourceindex); i = i + 1; } else { newlist[i] = list.GetItemAt(j); j = j + 1; i = i + 1; } } } else { newlist[i] = list.GetItemAt(i); } } //End of for loop } //end of destindex > sourceindex //end of else if } //end of else //End of the case move to end } //end of case destindex !=source index if (list.IsAddingNew) { list.CommitNew(); } for (i = 0; i < noofitems; i++) { list.Remove(newlist[i]); } for (i = 0; i < noofitems; i++) { list.AddNewItem(newlist[i]); list.CommitNew(); //this.ScrollIntoView(newlist[i]);//AutoScroll } list.Refresh(); this.SelectedItem = sourcedata; //02/24 Aaron //This is to signify that since the source and destination is the same, we have performed a move e.Effects = DragDropEffects.Move; } //end of source and destination and the same (target listbox } //sourcedata |=null } //formats.length >0 }
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 override void BSkyBaseButtonCtrl_Click(object sender, RoutedEventArgs e) { double maxnoofvars = 0; int noSelectedItems = 0; int i = 0; System.Windows.Forms.DialogResult diagResult; string varList = ""; 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 <object> invalidVars = new List <object>(); //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; string newvar = ""; //Checking whether variables moved are allowed by the destination filter //validVars meet filter requirements //invalidVars don't meet filter requirements 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 move 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; } if (noSelectedItems > 1) { diagResult = System.Windows.Forms.MessageBox.Show("You need to select 1 variable at a time to specify polynomial critera", "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; } } object objspin = GetResource(TextBoxForpolynomialOrder); if (objspin == null || (!(objspin is BSkySpinnerCtrl))) { MessageBox.Show("Unable to associate this polynomial control with a Spinner control on the same canvas, you must specify a spinner control"); return; } //If there are valid variables then move them BSkySpinnerCtrl spin = objspin as BSkySpinnerCtrl; // IList<DataSourceVariable> Items = new List<DataSourceVariable>(); List <DataSourceVariable> Items = new List <DataSourceVariable>(); DataSourceVariable inputVar = vInputList.SelectedItems[0] as DataSourceVariable; int polynomialdegree = Int32.Parse(spin.text.Text); int startingpolynomialdegree = 1; bool itemIsInTarget = false; //Lets say the degree of the polynomial is 4, so engine^4, then we need to add //I(engine^4) and I(engine^3) and I(engine^2) and I(engine^1) //Now if you add I(engine^5), only I(engine^5) should be added as I(engine^4) are already there while (polynomialdegree != 0) { newvar = "I(" + inputVar.Name + "^" + startingpolynomialdegree + ")"; //Preferred way DataSourceVariable ds = new DataSourceVariable(); ds.XName = newvar; ds.Name = newvar; ds.RName = newvar; 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; if (vTargetList.ItemsCount == 0) { Items.Add(ds); } else { foreach (DataSourceVariable obj in vTargetList.Items) { if (obj.RName == ds.RName) { itemIsInTarget = true; } } if (!itemIsInTarget) { Items.Add(ds); } } polynomialdegree = polynomialdegree - 1; startingpolynomialdegree = startingpolynomialdegree + 1; itemIsInTarget = false; } //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 if (Items.Count != 0) { vTargetList.AddItems(Items); vTargetList.ScrollIntoView(Items[0]); } // Added by Aaron 06/09/2020 // We will never remove the variable being moved from the source variable list // 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); } }
//bool committedVarCell = false; private void variableGrid_CommittingEdit(object sender, DataGridEndingEditEventArgs e) { //if (committedVarCell) //{ // e.Cancel = true; // return; //} //committedVarCell = true; // //on cell Edit and clicking elsewhere gives the info about edited cell List<string> colLevels = null; string cellVal = variableGrid.CurrentCell.Text;//eg..Male or Female string cellValue = cellVal != null ? cellVal.Replace("'", @"\'").Replace("\"", @"\'") : string.Empty; //string cellValue = cellVal != null ? cellVal.Replace("'", @"\'") : string.Empty; if (cellValue == null || cellValue.Trim().Length < 1) //Do not create new variable row if variable name is not provided { //method1 variableGrid.RemoveRow(variableGrid.CurrentRow.Index); //variableGrid.RaiseEvent(); return; } //rowid = variableGrid.CurrentCell.Row.DataItem.ToString();//eg..gender // should be captured when we click on cell string colid = variableGrid.CurrentCell.Column.Header.ToString();//eg..Label switch (e.Column.Name) { case "Name": break; case "DataType": if (colid.Equals("DataType")) colid = "Type"; // colid must match with R side property name. Else it will not work //MessageBox.Show(selectedData); if (cellValue.Equals("String")) cellValue = "character"; if (cellValue.Equals("Numeric") || cellValue.Equals("Int") || cellValue.Equals("Float") || cellValue.Equals("Double")) cellValue = "numeric"; if (cellValue.Equals("Bool")) cellValue = "logical"; break; case "Width": break; case "Decimals": break; case "Label": break; case "Values": colid = "Levels"; // "Levels" new property name in R code break; case "Missing": break; case "Columns": break; case "Alignment": colid = "Align"; // "Align" new property name in R code C1.WPF.DataGrid.DataGridComboBoxColumn col = e.Column as C1.WPF.DataGrid.DataGridComboBoxColumn; C1.WPF.C1ComboBox combo = e.EditingElement as C1.WPF.C1ComboBox; string value = combo.Text; break; case "Measure": colLevels = getLevels(); break; case "Role": break; default: break; } ///// Modifying R side Dataset //////// IAnalyticsService analyticServ = LifetimeService.Instance.Container.Resolve<IAnalyticsService>(); if (rowid == null)//new row { int rowindex = 0;//variableGrid.CurrentRow.Index; string datagridcolval = ".";//default value for new col in datagrid view. // add new row cellValue is new colname analyticServ.addNewVariable(cellValue, datagridcolval, rowindex, ds.Name); //// Insert on UI side dataset /// DataSourceVariable var = new DataSourceVariable(); // string RecCount = (this.Variables.Count + 1).ToString();//add 1 because its 0 based // int insertrowindex = variableGrid.SelectedIndex; var.Name = cellValue; //////// Check Problem for manually appending new Var at the end DS.Variables.Add(var); //this.Variables.Insert(rowindex, var); //DS.Variables.Insert(rowindex, var);//one more refresh needed. I guess //renumberRowHeader(variableGrid); } else {//edit existing row UAReturn retval = analyticServ.EditVarGrid(ds.Name, rowid, colid, cellValue, colLevels); retval.Success = true; ///08Jul2013 Show Error/Warning in output window if any. //if (retval != null && retval.Data != null) // SendErrorWarningToOutput(retval); } //variableGrid. = cellValue; //MessageBox.Show("[R:"+rowid + "] [C:" + colid + "] [V:" + cellValue + "] [DS:" + ds.Name+"]"); ds.Changed = true; if (e.Column.Name.Equals("Name")) refreshDataGrid(); //arrangeVarGridCols();//rearrange the var-grid cols }
private void variableGrid_BeginningNewRow(object sender, DataGridBeginningNewRowEventArgs e) { //int curRowindex = variableGrid.CurrentRow.Index; DataSourceVariable var = new DataSourceVariable(); //string RecCount = (this.Variables.Count + 1).ToString();//add 1 because its 0 based string varname = "newvar"; //getRightClickRowIndex(); int rowindex = variableGrid.SelectedIndex; //checking duplicate var names foreach (DataSourceVariable dsv in this.Variables) { varname = "newvar" + varcount.ToString(); if (dsv.Name == varname) varcount++; } var.Name = varname; var.Label = varname; IAnalyticsService analyticServ = LifetimeService.Instance.Container.Resolve<IAnalyticsService>(); analyticServ.addNewVariable(var.Name, ".", rowindex + 1, ds.Name); this.Variables.Insert(rowindex, var); DS.Variables.Insert(rowindex, var);//one more refresh needed. I guess renumberRowHeader(variableGrid); ds.Changed = true; refreshDataGrid(); }
private void _deleteVar_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Do you want to delete variable?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { DataSourceVariable var = new DataSourceVariable(); //getRightClickRowIndex(); int rowindex = variableGrid.SelectedIndex; //var.Name = "accid"; //this.Variables.Remove(var); variableGrid.RemoveRow(rowindex);//two things .grid remove UI dataset side remove. third is R side remove variableGrid.Refresh(); // renumberRowHeader(); //not required. I guess automatically handeled by RemoveRow() above. ds.Changed = true; //this.Variables.Remove(rowindex); //refreshDataGrid(); } }
private void _insertNewVarAtEnd_Click(object sender, RoutedEventArgs e) { DataSourceVariable var = new DataSourceVariable(); //string RecCount = (this.Variables.Count + 1).ToString();//add 1 because its 0 based string varname = "newvar"; //getRightClickRowIndex(); int rowindex = Variables.Count;// variableGrid.SelectedIndex; //checking duplicate var names do { varname = "newvar" + varcount.ToString(); varcount++; } while (this.Variables.Contains(varname)); var.Name = varname; var.Label = varname; IAnalyticsService analyticServ = LifetimeService.Instance.Container.Resolve<IAnalyticsService>(); analyticServ.addNewVariable(var.Name, ".", rowindex + 1, ds.Name); this.Variables.Insert(rowindex, var); DS.Variables.Insert(rowindex, var);//one more refresh needed. I guess renumberRowHeader(variableGrid); ds.Changed = true; refreshDataGrid(); }
public override void BSkyBaseButtonCtrl_Click(object sender, RoutedEventArgs e) { double maxnoofvars = 0; int noSelectedItems = 0; int i = 0; System.Windows.Forms.DialogResult diagResult; string varList = ""; 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 <object> invalidVars = new List <object>(); //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; string newvar = ""; //Checking whether variables moved are allowed by the destination filter //validVars meet filter requirements //invalidVars don't meet filter requirements 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 nesting control", "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; } if (noSelectedItems > 1) { diagResult = System.Windows.Forms.MessageBox.Show("You need to select 1 variable at a time from the source variable list to specify a nested effect. You have more than 1 variable selected in the source 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.SelectedItems.Count > 1) { diagResult = System.Windows.Forms.MessageBox.Show("You need to select 1 variable from the source variable list and 1 variable from the target variable to specify a nested effect. You have more than 1 variable selected in the target variable list.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question); return; } if (vTargetList.SelectedItems.Count == 0) { diagResult = System.Windows.Forms.MessageBox.Show("You need to select 1 variable from the source variable list and 1 variable from the target variable to specify a nested effect. The target variable list is empty. You need to add a variable to the target variable list and then create a nested effect.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question); return; } 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; } } DataSourceVariable inputVar = vInputList.SelectedItems[0] as DataSourceVariable; // vTargetList.ItemsSource //vTargetList.ItemsSource //Preferred ListCollectionView temp; temp = vTargetList.ItemsSource as ListCollectionView; int selectedIndex = 0; selectedIndex = vTargetList.SelectedIndex; int count = vTargetList.ItemsCount; for (i = 0; i < count; i++) { validVars.Add(vTargetList.Items[i]); } ListCollectionView lcw = vTargetList.ItemsSource as ListCollectionView; foreach (object obj in validVars) { lcw.Remove(obj); } DataSourceVariable ds = validVars[selectedIndex] as DataSourceVariable; // DataSourceVariable ds = preview[index] as DataSourceVariable; //DataSourceVariable ds = new DataSourceVariable(); newvar = inputVar.Name + "(" + ds.Name + ")"; ds.XName = newvar; ds.Name = newvar; ds.RName = newvar; 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[selectedIndex] = ds; // vTargetList.ItemsSource = preview; // validVars.Add(ds as object); // vTargetList.AddItems(validVars); // vInputList.SelectedItems[i] // validVars.Add(vInputList.SelectedItems[1]); 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.ScrollIntoView(validVars[selectedIndex]); 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); } }
private DataRow GetDataTable(DataColumn dataColumn, string tableText, string pattern, Dictionary <string, string> formatStrings, DataRow[] rows, DataTable table) { pattern = string.Empty; IVariable var = (IVariable)this.Context.GetVariable(dataColumn.ColumnName); if (var != null) { if (var.VarType == VariableType.DataSource || var.VarType == VariableType.DataSourceRedefined) { formatStrings.TryGetValue(var.Name, out pattern); } else { tableText = "Defined"; } } else { //tableText = "Defined"; var = new DataSourceVariable(dataColumn.ColumnName, DataType.Unknown); } DataRow row = table.NewRow(); if ( this.Context.CurrentRead != null && this.Context.CurrentRead.IsEpi7ProjectRead && this.Context.CurrentProject.Views.Exists(this.Context.CurrentRead.Identifier) && this.Context.CurrentProject.Views[this.Context.CurrentRead.Identifier].Fields.Exists(var.Name) ) { Epi.Fields.Field field = this.Context.CurrentProject.Views[this.Context.CurrentRead.Identifier].Fields[var.Name]; if (field is FieldWithSeparatePrompt) { row[ColumnNames.PROMPT] = ((FieldWithSeparatePrompt)field).PromptText; } else { row[ColumnNames.PROMPT] = var.PromptText; } //Fiexes for Issue: 943 if (field.FieldType.ToString() == MetaFieldType.Checkbox.ToString()) { row[ColumnNames.FIELDTYPE] = "Checkbox"; } else { row[ColumnNames.FIELDTYPE] = field.FieldType.ToString(); } } else { row[ColumnNames.PROMPT] = var.PromptText; if (var.VarType == VariableType.Permanent) { row[ColumnNames.FIELDTYPE] = var.DataType.ToString(); } else { if (this.Context.DataSet.Tables.Contains("output")) { row[ColumnNames.FIELDTYPE] = GetVariableType(this.Context.DataSet.Tables["output"].Columns[var.Name].DataType.ToString()); } else { row[ColumnNames.FIELDTYPE] = var.DataType.ToString(); } } } row[ColumnNames.VARIABLE] = var.Name; row[ColumnNames.FORMATVALUE] = pattern; row[ColumnNames.SPECIALINFO] = var.VarType.ToString(); row[ColumnNames.TABLE] = tableText; // table.Rows.Add(row); return(row); }