示例#1
0
        internal ReportConfiguration CreateReport(string reportName)
        {
            if (string.IsNullOrWhiteSpace(reportName))
            {
                throw new ArgumentException("Argument is null or whitespace", nameof(reportName));
            }
            if (reportName.Length < 12)
            {
                throw new ArgumentException("Report name can'be less that 12 symbols", nameof(reportName));
            }
            // todo exception localizations
            // todo exception type
            if (!reportName.Substring(0, reportName.Length - 6).StartsWith(GroupName))
            {
                throw new ArgumentException($"{nameof(reportName)} is not from this group.");
            }

            var reportConfiguration = new ReportConfiguration
            {
                ReportName  = reportName,
                PrinterName = PrinterName,
                Duplex      = Duplex,
                PaperFormat = PaperFormat
            };

            if (Reports.Count > 0)
            {
                var first = Reports.First();
                if (Reports.All(configuration => configuration.PrinterName == first.PrinterName))
                {
                    reportConfiguration.PrinterName = first.PrinterName;
                }
                if (Reports.All(configuration => configuration.Duplex == first.Duplex))
                {
                    reportConfiguration.Duplex = first.Duplex;
                }
                if (Reports.All(configuration => configuration.PaperFormat == first.PaperFormat))
                {
                    reportConfiguration.PaperFormat = first.PaperFormat;
                }
            }

            Reports.Add(reportConfiguration);
            return(reportConfiguration);
        }