コード例 #1
0
        /// <summary>
        /// Adds a report element to the parent element
        /// </summary>
        /// <param name="root">Reference to the root XML document</param>
        /// <param name="outputTo">The output to option for the report</param>
        /// <param name="allowSpaceForHeaderAndFooter">True if the report has a header or a footer, otherwise false</param>
        /// <returns>A reference to the report element</returns>
        public static XmlElement AddReportElement(XmlDocument root, ReportOutputToOption outputTo, bool allowSpaceForHeaderAndFooter)
        {
            // Validate the arguments
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }
            if (outputTo == ReportOutputToOption.Unknown)
            {
                throw new ArgumentException($"{nameof(outputTo)} must be set to a specific paper size and orientation. {nameof(ReportOutputToOption.Unknown)} is not supported.", nameof(outputTo));
            }
            // allowSpaceForHeaderAndFooter does not require validation


            // Add the report element
            const string nodeName = "report";
            XmlElement   node     = root.CreateElement(nodeName);

            root.AppendChild(node);

            // Add the outputTo attribute
            const string outputToAttributeName = "outputTo";
            string       outputToValue         = GetReportOutputToAttributeValue(outputTo, allowSpaceForHeaderAndFooter);

            AddAttribute(node, root, outputToAttributeName, outputToValue, false);

            // Return the report element
            return(node);
        }
コード例 #2
0
        /// <summary>
        /// Gets the report outputTo attribute value for a specified output to option (using the standard page masters)
        /// </summary>
        /// <param name="outputTo">The output to option</param>
        /// <param name="allowSpaceForHeaderAndFooter">True if the report should allow space for a header or a footer, otherwise false</param>
        /// <returns>The report outputTo attribute value</returns>
        public static string GetReportOutputToAttributeValue(ReportOutputToOption outputTo, bool allowSpaceForHeaderAndFooter)
        {
            // Validate the arguments
            // outputTo does not require validation
            // allowSpaceForHeaderAndFooter does not require validation


            // Get the formatted value for the page size and orientation
            string formattedValue = null;

            switch (outputTo)
            {
            case ReportOutputToOption.A0Portrait:
                formattedValue = "A0Portrait";
                break;

            case ReportOutputToOption.A0Landscape:
                formattedValue = "A0Landscape";
                break;

            case ReportOutputToOption.A1Portrait:
                formattedValue = "A1Portrait";
                break;

            case ReportOutputToOption.A1Landscape:
                formattedValue = "A1Landscape";
                break;

            case ReportOutputToOption.A2Portrait:
                formattedValue = "A2Portrait";
                break;

            case ReportOutputToOption.A2Landscape:
                formattedValue = "A2Landscape";
                break;

            case ReportOutputToOption.A3Portrait:
                formattedValue = "A3Portrait";
                break;

            case ReportOutputToOption.A3Landscape:
                formattedValue = "A3Landscape";
                break;

            case ReportOutputToOption.A4Portrait:
                formattedValue = "A4Portrait";
                break;

            case ReportOutputToOption.A4Landscape:
                formattedValue = "A4Landscape";
                break;

            default:
                if (outputTo != ReportOutputToOption.Unknown)
                {
                    throw new ArgumentException($"Argument {nameof(outputTo)} contains an unsupported value.", nameof(outputTo));
                }

                break;
            }

            // If the paper size and orientation are set and the report should not allow space for a header or a footer
            if (outputTo != ReportOutputToOption.Unknown && !allowSpaceForHeaderAndFooter)
            {
                const string noHeaderOrFooter = "NoHeaderOrFooter";
                formattedValue += noHeaderOrFooter;
            }

            return(formattedValue);
        }