public HPMWIColumn(HPMColumn column, int type) { m_Column = column; m_Type = type; }
static void DoExport() { HPMUniqueID projId = HPMUtilities.FindProject(projectName); if (viewType == EHPMReportViewType.AgileBacklog) projId = SessionManager.Instance.Session.ProjectUtilGetBacklog(projId); else if (viewType == EHPMReportViewType.AllBugsInProject) projId = SessionManager.Instance.Session.ProjectUtilGetQA(projId); if (projId != null) { HPMString findString; if (searchSpec == SearchSpec.Report) { HPMUniqueID reportUserId = HPMUtilities.FindUser(reportUserName); if (reportUserId == null) throw new ArgumentException("Could not find the user " + reportUserName); HPMReport report = HPMUtilities.FindReport(projId, reportUserId, reportName); if (report == null) throw new ArgumentException("Could not find the report " + reportName + " for user " + reportUserName + " in project " + projectName); findString = SessionManager.Instance.Session.UtilConvertReportToFindString(report, projId, viewType); } else { findString = findQuery.Replace('\'', '"'); } HPMFindContext findContext = new HPMFindContext(); HPMFindContextData data = SessionManager.Instance.Session.UtilPrepareFindContext(findString, projId, viewType, findContext); HPMTaskEnum items = SessionManager.Instance.Session.TaskFind(data, EHPMTaskFindFlag.None); ExcelWriter excelWriter = new ExcelWriter(); if (items.m_Tasks.Length > 0) { EHPMProjectGetDefaultActivatedNonHidableColumnsFlag flag; if (viewType == EHPMReportViewType.ScheduleMainProject) flag = EHPMProjectGetDefaultActivatedNonHidableColumnsFlag.ScheduledMode; else if (viewType == EHPMReportViewType.AgileMainProject) flag = EHPMProjectGetDefaultActivatedNonHidableColumnsFlag.AgileMode; else flag = EHPMProjectGetDefaultActivatedNonHidableColumnsFlag.None; EHPMProjectDefaultColumn[] nonHidableColumns = SessionManager.Instance.Session.ProjectGetDefaultActivatedNonHidableColumns(projId, flag).m_Columns; if (viewType == EHPMReportViewType.ScheduleMainProject || viewType == EHPMReportViewType.AgileMainProject || viewType == EHPMReportViewType.AgileBacklog) { Array.Resize(ref nonHidableColumns, nonHidableColumns.Length + 1); nonHidableColumns[nonHidableColumns.Length - 1] = EHPMProjectDefaultColumn.ItemStatus; } EHPMProjectDefaultColumn[] activeBuiltinColumns = SessionManager.Instance.Session.ProjectGetDefaultActivatedColumns(projId).m_Columns; HPMProjectCustomColumnsColumn[] activeCustomColumns = SessionManager.Instance.Session.ProjectCustomColumnsGet(projId).m_ShowingColumns; ExcelWriter.Row row = excelWriter.AddRow(); foreach (EHPMProjectDefaultColumn builtinCol in nonHidableColumns) row.AddCell(HPMUtilities.GetColumnName(builtinCol)); foreach (EHPMProjectDefaultColumn builtinCol in activeBuiltinColumns) row.AddCell(HPMUtilities.GetColumnName(builtinCol)); foreach (HPMProjectCustomColumnsColumn customColumn in activeCustomColumns) row.AddCell(HPMUtilities.GetColumnName(projId, customColumn)); HPMColumnTextOptions options = new HPMColumnTextOptions(); options.m_bForDisplay = true; foreach (HPMUniqueID item in items.m_Tasks) { string description = SessionManager.Instance.Session.TaskGetDescription(item); HPMUniqueID itemRef; if (viewType == EHPMReportViewType.ScheduleMainProject || viewType == EHPMReportViewType.AgileMainProject) { itemRef = SessionManager.Instance.Session.TaskGetProxy(item); if (!itemRef.IsValid()) itemRef = SessionManager.Instance.Session.TaskGetMainReference(item); } else { itemRef = SessionManager.Instance.Session.TaskGetMainReference(item); } row = excelWriter.AddRow(); foreach (EHPMProjectDefaultColumn builtinCol in nonHidableColumns) { HPMColumn column = new HPMColumn(); column.m_ColumnType = EHPMColumnType.DefaultColumn; column.m_ColumnID = (uint)builtinCol; row.AddCell(SessionManager.Instance.Session.TaskRefGetColumnText(itemRef, column, options)); } foreach (EHPMProjectDefaultColumn builtinCol in activeBuiltinColumns) { HPMColumn column = new HPMColumn(); column.m_ColumnType = EHPMColumnType.DefaultColumn; column.m_ColumnID = (uint)builtinCol; row.AddCell(SessionManager.Instance.Session.TaskRefGetColumnText(itemRef, column, options)); } foreach (HPMProjectCustomColumnsColumn customColumn in activeCustomColumns) { string displayString; string dbValue = SessionManager.Instance.Session.TaskGetCustomColumnData(item, SessionManager.Instance.Session.UtilGetColumnHash(customColumn)); if (customColumn.m_Type == EHPMProjectCustomColumnsColumnType.DateTime || customColumn.m_Type == EHPMProjectCustomColumnsColumnType.DateTimeWithTime) { ulong ticksSince1970 = SessionManager.Instance.Session.UtilDecodeCustomColumnDateTimeValue(dbValue)*10; DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddTicks((long)ticksSince1970); if (customColumn.m_Type == EHPMProjectCustomColumnsColumnType.DateTime) displayString = dateTime.ToShortDateString(); else displayString = dateTime.ToString(); } else if (customColumn.m_Type == EHPMProjectCustomColumnsColumnType.Resources) { displayString =""; HPMResourceDefinitionList resourceList = SessionManager.Instance.Session.UtilDecodeCustomColumnResourcesValue(dbValue); for (int i = 0; i < resourceList.m_Resources.Length; i += 1) { HPMResourceDefinition resourceDefinition = resourceList.m_Resources[i]; switch (resourceDefinition.m_GroupingType) { case EHPMResourceGroupingType.AllProjectMembers: displayString += "All Project Members"; break; case EHPMResourceGroupingType.Resource: displayString += HPMUtilities.GetUserName(resourceDefinition.m_ID); break; case EHPMResourceGroupingType.ResourceGroup: displayString += HPMUtilities.GetGroupName(resourceDefinition.m_ID); break; } if (i < resourceList.m_Resources.Length - 1) displayString += ", "; } } else if (customColumn.m_Type == EHPMProjectCustomColumnsColumnType.DropList) { displayString = HPMUtilities.DecodeDroplistValue(dbValue, customColumn.m_DropListItems); } else if (customColumn.m_Type == EHPMProjectCustomColumnsColumnType.MultiSelectionDropList) { displayString = ""; string[] dbValues = dbValue.Split(new char[] { ';' }); for (int i = 0; i < dbValues.Length; i += 1) { displayString += HPMUtilities.DecodeDroplistValue(dbValues[i], customColumn.m_DropListItems); if (i < dbValues.Length - 1) displayString += ", "; } } else displayString = dbValue; row.AddCell(displayString); } } } excelWriter.SaveAsOfficeOpenXml(outputFileName); } else throw new ArgumentException("Could not find the project " + projectName); }
/// <summary> /// Add all columns from a Hansoft project to GridView. /// </summary> private void AddColumns(GridView gView, TabContainer multilineTabs, HPMUniqueID projectID, string project) { CommandField editfield = new CommandField(); editfield.ShowEditButton = true; editfield.ShowDeleteButton = true; editfield.ShowCancelButton = true; editfield.ShowSelectButton = true; editfield.UpdateText = "Save"; gView.Columns.Add(editfield); List<HPMWIColumn> columns = new List<HPMWIColumn>(); HPMProjectCustomColumns customColumns = m_VirtSession.ProjectCustomColumnsGet(projectID); HPMProjectDefaultColumns defaultColumns = m_VirtSession.ProjectGetDefaultActivatedColumns(projectID); HPMProjectDefaultColumns nonHidableDefaultColumns = m_VirtSession.ProjectGetDefaultActivatedNonHidableColumns(projectID, EHPMProjectGetDefaultActivatedNonHidableColumnsFlag.AgileMode | EHPMProjectGetDefaultActivatedNonHidableColumnsFlag.ScheduledMode); foreach (EHPMProjectDefaultColumn defaultColumn in nonHidableDefaultColumns.m_Columns) { HPMColumnDescription description = AddDefaultColumn(gView, multilineTabs, projectID, defaultColumn, project); HPMColumn column = new HPMColumn(); column.m_ColumnType = EHPMColumnType.DefaultColumn; column.m_ColumnID = (uint)defaultColumn; columns.Add(new HPMWIColumn(column, (int)description.m_CriteriaDataType)); } foreach (EHPMProjectDefaultColumn defaultColumn in defaultColumns.m_Columns) { HPMColumnDescription description = AddDefaultColumn(gView, multilineTabs, projectID, defaultColumn, project); HPMColumn column = new HPMColumn(); column.m_ColumnType = EHPMColumnType.DefaultColumn; column.m_ColumnID = (uint)defaultColumn; columns.Add(new HPMWIColumn(column, (int)description.m_CriteriaDataType)); } foreach (HPMProjectCustomColumnsColumn customColumn in customColumns.m_ShowingColumns) { AddCustomColumn(gView, multilineTabs, projectID, customColumn, project); HPMColumn column = new HPMColumn(); column.m_ColumnType = EHPMColumnType.CustomColumn; column.m_ColumnID = customColumn.m_Hash; columns.Add(new HPMWIColumn(column, (int)customColumn.m_Type)); } BoundField idField = new BoundField(); idField.Visible = false; idField.DataField = "_ID"; SetColumns(project, columns); }
private HPMColumnDescription AddDefaultColumn(GridView gView, TabContainer multilineContainer, HPMUniqueID projectID, EHPMProjectDefaultColumn defaultColumn, string project) { HPMColumn column = new HPMColumn(); column.m_ColumnType = EHPMColumnType.DefaultColumn; column.m_ColumnID = (uint)defaultColumn; HPMColumnDescription columnDescription = m_VirtSession.UtilGetColumnDescription(column); HPMUntranslatedString columnNameUntr = m_VirtSession.UtilGetColumnName(defaultColumn); HPMString columnName = m_VirtSession.LocalizationTranslateString(m_VirtSession.LocalizationGetDefaultLanguage(), columnNameUntr); bool isReadOnly = columnDescription.m_bReadOnly; if (defaultColumn == EHPMProjectDefaultColumn.LinkedTo) isReadOnly = true; if ((defaultColumn == EHPMProjectDefaultColumn.DetailedDescription) || (defaultColumn == EHPMProjectDefaultColumn.StepsToReproduce)) { AddMultilineTab(project, multilineContainer, columnName, Convert.ToString((uint)defaultColumn), isReadOnly); return columnDescription; } if (defaultColumn == EHPMProjectDefaultColumn.Comments) { AddMultilineTabComments(project, multilineContainer, columnName, Convert.ToString((uint)defaultColumn), isReadOnly); return columnDescription; } if (defaultColumn == EHPMProjectDefaultColumn.OriginallyCreatedBy) columnDescription.m_CriteriaDataType = EHPMFindCriteriaDataType.Text; if (defaultColumn == EHPMProjectDefaultColumn.MilestoneTag) columnDescription.m_CriteriaDataType = EHPMFindCriteriaDataType.Droplist; switch (columnDescription.m_CriteriaDataType) { case EHPMFindCriteriaDataType.Integer: case EHPMFindCriteriaDataType.Float: case EHPMFindCriteriaDataType.Date: case EHPMFindCriteriaDataType.GeneralCondition: case EHPMFindCriteriaDataType.Text: { BoundField textfield = new BoundField(); string id = Convert.ToString((uint)defaultColumn); textfield.HeaderText = columnName; textfield.AccessibleHeaderText = id; textfield.SortExpression = id; textfield.DataField = id; textfield.ReadOnly = isReadOnly; gView.Columns.Add(textfield); } break; case EHPMFindCriteriaDataType.Droplist: { string id = Convert.ToString((uint)defaultColumn); var values = new Dictionary<HPMUInt32, HPMString>(); HPMColumnData Data = m_VirtSession.UtilGetColumnData(projectID, defaultColumn); // used to determine width of column int longestString = 0; foreach (HPMUInt32 DataItem in Data.m_DataItems) { HPMUntranslatedString DataItemTextUntranslated = m_VirtSession.UtilGetColumnDataItemFormatted(projectID, defaultColumn, DataItem); HPMString DataItemText = m_VirtSession.LocalizationTranslateString(m_VirtSession.LocalizationGetDefaultLanguage(), DataItemTextUntranslated); if (DataItemText.Length > longestString) longestString = DataItemText.Length; values.Add(DataItem, DataItemText); } // add some space to column width longestString = longestString * 30; TemplateField listfield = new TemplateField(); listfield.SortExpression = id; listfield.HeaderText = columnName; listfield.AccessibleHeaderText = id; bool isNumeric = true; if ((defaultColumn == EHPMProjectDefaultColumn.BugStatus) || (defaultColumn == EHPMProjectDefaultColumn.MilestoneTag) || (defaultColumn == EHPMProjectDefaultColumn.CommittedToSprint)) isNumeric = false; listfield.ItemTemplate = new HPMGridViewTemplate(ListItemType.Item, HPMGridViewTemplateType.DropDownList, id, id, values, isReadOnly, isNumeric); listfield.EditItemTemplate = new HPMGridViewTemplate(ListItemType.EditItem, HPMGridViewTemplateType.DropDownList, id, id, values, isReadOnly, isNumeric); listfield.ItemStyle.Width = longestString; listfield.ItemStyle.Wrap = false; gView.Columns.Add(listfield); } break; case EHPMFindCriteriaDataType.MultiSelectDroplist: { string id = Convert.ToString((uint)defaultColumn); HPMUniqueID projectid = m_VirtSession.UtilGetRealProjectIDFromProjectID(projectID); bool addResourceGroups = (defaultColumn == EHPMProjectDefaultColumn.AssignedTo) ? false : true; var values = GetResources(projectid, addResourceGroups); TemplateField listfield = new TemplateField(); listfield.SortExpression = id; listfield.HeaderText = columnName; listfield.AccessibleHeaderText = id; listfield.ItemTemplate = new HPMGridViewTemplate(ListItemType.Item, HPMGridViewTemplateType.CheckBoxList, id, id, values, isReadOnly, false); listfield.EditItemTemplate = new HPMGridViewTemplate(ListItemType.EditItem, HPMGridViewTemplateType.CheckBoxList, id, id, values, isReadOnly, false); gView.Columns.Add(listfield); } break; } return columnDescription; }