/// <summary> /// For .Net choice control the columns added will always be DisplayMember & ValueMember /// </summary> /// <param name="dataType">.Net choice control's Attribute</param> /// <param name="itmList">Value Member List to get the .Net type from ctrls Atrribute(Magic type)</param> internal void AddColumns(StorageAttribute dataType, string[] itmList) { Type dnDataType = null; if (dataType == StorageAttribute.NUMERIC) { for (int i = 0; i < itmList.Length; i++) { dnDataType = DNConvert.getDefaultDotNetTypeForMagicType(itmList[i], dataType); if (dnDataType == typeof(Double)) { break; } } } else { dnDataType = DNConvert.getDefaultDotNetTypeForMagicType(null, dataType); } // ValueMember column of the DataTable must have the type of the LinkField if set, else // Data if set else unicode. MGDataColumn valMemCol = new MGDataColumn() { Name = GuiConstants.STR_VALUE_MEMBER, DataType = dnDataType }; MGDataColumn dispMemCol = new MGDataColumn() { Name = GuiConstants.STR_DISPLAY_MEMBER, DataType = typeof(String) }; // Add to the columns to the ColumList collection of the MGDataTable ColumnList = new List <MGDataColumn>(); ColumnList.Add(valMemCol); ColumnList.Add(dispMemCol); // Add the columns from the column list to the DataTable AddColumns(); }
/// <summary> /// Prepares a columns list. /// </summary> /// <param name="taskID"></param> /// <param name="taskVariableNamesString">task's variable (fields) names, comma delimted.</param> /// <param name="displayNamesString">display names (to be used as column names), comma delimted.</param> internal List <MGDataColumn> PrepareColumnsList(string taskID, String taskVariableNamesString, String displayNamesString) { ColumnList = new List <MGDataColumn>(); bool useTaskVariableNamesAsDisplayNames = false; StringBuilder invalidVariableNames = new StringBuilder(); List <string> taskVariableNames = CreateList(taskVariableNamesString); // task variables names. List <string> displayNames = null; if (displayNamesString.Length == 0 || displayNamesString.Equals("@")) { useTaskVariableNamesAsDisplayNames = true; } else //prepare display names { displayNames = CreateList(displayNamesString); if (displayNames.Count < taskVariableNames.Count) { int cnt = taskVariableNames.Count - displayNames.Count; // if display variable list is less than task vars list , add blank names for the remaining columns. // If we add empty string here, datagrid adds it's default names (like Column1, Column2 ...), to avoid this add single blank char. for (var j = 0; j < cnt; j++) { displayNames.Add(" "); } } } var task = (TaskBase)Manager.MGDataTable.GetTaskByID(taskID); // Prepare column list of task variables of required generation & all it's parents // as we support taskVariableNames from required task & it's parents as well. var allTasksColumnsList = new List <MGDataColumn>(); while (task != null) { var fieldsTable = task.DataView.GetFieldsTab(); for (var j = 0; j < fieldsTable.getSize(); j++) { var field = (Field)fieldsTable.getField(j); var newColumn = new MGDataColumn { Name = field.getVarName(), DataType = field.GetDefaultDotNetTypeForMagicType(), FldIdx = 0 }; allTasksColumnsList.Add(newColumn); } task = (TaskBase)task.GetTaskAncestor(1); } // prepare 'columnsList' with one column for each task's variable contained within 'taskVariableNamesString'. int i = 0; foreach (var taskVariableName in taskVariableNames) { bool variableFound = false; for (var j = 0; j < allTasksColumnsList.Count; j++) { if (taskVariableName == allTasksColumnsList[j].Name) { var newColumn = new MGDataColumn { Name = (useTaskVariableNamesAsDisplayNames ? allTasksColumnsList[j].Name : displayNames[i]), DataType = allTasksColumnsList[j].DataType }; ColumnList.Add(newColumn); variableFound = true; break; } } if (!variableFound) { if (invalidVariableNames.Length > 0) { invalidVariableNames.Append(','); } invalidVariableNames.Append(taskVariableName); } i++; } //error handling if (ColumnList.Count == 0) { Events.WriteErrorToLog(taskVariableNames.Count == 0 ? "DataViewToDNDataTable - No variables are specified." : String.Format("DataViewToDNDataTable - Illegal variables specified : {0}", taskVariableNamesString)); } else if (ColumnList.Count < taskVariableNames.Count) { Events.WriteErrorToLog(String.Format("DataViewToDNDataTable - Illegal variables specified : {0}", invalidVariableNames.ToString())); } return(ColumnList); }