Exemplo n.º 1
0
 public void SetReport(Report report)
 {
     _columns.Clear();
     lbxColumns.Items.Clear();
     List<NodeData> newColumns;
     _columnSet.GetColumnInfos(report, treeView, out newColumns);
     foreach (NodeData column in newColumns)
     {
         AddColumn(column);
     }
     cbxPivotReplicate.Checked = false;
     cbxPivotIsotopeLabel.Checked = false;
     var pivotReport = report as PivotReport;
     if (pivotReport != null)
     {
         var testColumns = pivotReport.Columns.Union(pivotReport.CrossTabValues).ToArray();
         foreach(var id in pivotReport.CrossTabHeaders)
         {
             if (PivotType.REPLICATE.GetCrosstabHeaders(testColumns).Contains(id))
             {
                 cbxPivotReplicate.Checked = true;
             }
             if (PivotType.ISOTOPE_LABEL.GetCrosstabHeaders(testColumns).Contains(id))
             {
                 cbxPivotIsotopeLabel.Checked = true;
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Used when loading a saved Report, this method figures out what to display in the UI.
        /// The saved Report just has the information necessary to execute the query, which 
        /// is the set of columns to query, and paired with the tables to query.
        /// This then needs to be transformed back into which columns in the big tree view were
        /// selected, and whether the "Pivot Results" checkbox was checked.
        /// </summary>
        public void GetColumnInfos(Report report, TreeView treeView, out List<NodeData> columnInfos)
        {
            // CONSIDER: Why have the base class?
            if (!(report is SimpleReport))
            {
                throw new InvalidOperationException(Resources.ColumnSet_GetColumnInfos_Unexpected_report_type);
            }
            SimpleReport simpleReport = (SimpleReport) report;
            columnInfos = new List<NodeData>();
            var allColumns = new List<ReportColumn>(simpleReport.Columns);
            var pivotReport = simpleReport as PivotReport;
            if (pivotReport != null)
            {
                allColumns.AddRange(pivotReport.CrossTabValues);
            }
            if (allColumns.Count == 0)
            {
                return;
            }
            var allTables = new HashSet<Type>(from reportColumn in allColumns
                                              select reportColumn.Table);

            Table table = MostManyTable;
            Identifier prefix = null;
            while (table != null)
            {
                if (allTables.Contains(table.PersistentClass) ||
                    allTables.Contains(table.ResultsClass) ||
                    allTables.Contains(table.ResultsSummaryClass))
                {
                    break;
                }
                if (table.Parent == null)
                {
                    string tableNames = string.Join(", ", (from reportTable in allTables // Not L10N
                                                           select reportTable.ToString()).ToArray());
                    throw new InvalidDataException(string.Format(Resources.ColumnSet_GetColumnInfos_Unable_to_find_table_for__0_, tableNames));
                }
                table = table.Parent.ParentTable;
                prefix = new Identifier(prefix, table.Name);
            }

            foreach (var unqualifiedId in allColumns)
            {
                Identifier identifier;
                TableType type = ReportColumn.GetTableType(unqualifiedId.Table);
                switch (type)
                {
                    case TableType.result:
                        identifier = JoinIds(prefix, unqualifiedId.Column, ToResultsIdentifier);
                        break;
                    case TableType.summary:
                        identifier = JoinIds(prefix, unqualifiedId.Column, ToResultsSummaryIdentifier);
                        break;
                    default:
                        identifier = JoinIds(prefix, unqualifiedId.Column);
                        break;
                }

                columnInfos.Add(FindNodeData(treeView, type, identifier));
            }
        }