Пример #1
0
        /// <summary>
        /// Loads report template.
        /// </summary>
        /// <param name="nodeReport">Report template node.</param>
        /// <param name="isPredefined">Is predefined flag.</param>
        /// <returns>Report template info.</returns>
        private ReportInfo _LoadTemplate(XmlNode nodeReport, bool isPredefined)
        {
            ReportInfo info = null;
            try
            {
                string template = nodeReport.Attributes[ATTRIBUTE_NAME_FILEPATH].Value;
                if (File.Exists(ReportsGenerator.GetTemplateAbsolutelyPath(template)))
                {
                    string name = nodeReport.Attributes[ATTRIBUTE_NAME_NAME].Value;
                    ContextType context = (ContextType)Enum.Parse(typeof(ContextType), nodeReport.Attributes[ATTRIBUTE_NAME_CONTEXT].Value, true);
                    string description = _LoadDescription(nodeReport);
                    info = new ReportInfo(name, context, template, description, isPredefined,
                                          _LoadSubReports(nodeReport));
                }
            }
            catch
            {
                info = null;
            }

            return info;
        }
        /// <summary>
        /// Initiates report description.
        /// </summary>
        /// <param name="sourceFileName">Data source file full name.</param>
        /// <param name="reportName">Report name.</param>
        /// <param name="info">Report template info.</param>
        /// <returns>Created report description.</returns>
        ReportStateDescription _InitReportDescription(string sourceFileName,
                                                      string reportName,
                                                      ReportInfo info)
        {
            Debug.Assert(!string.IsNullOrEmpty(sourceFileName));
            Debug.Assert(!string.IsNullOrEmpty(reportName));
            Debug.Assert(null != info);

            var description = new ReportStateDescription();
            description.SourceFilePath = sourceFileName;
            description.ReportName = reportName;
            description.ReportInfo = info;
            description.Report = null;

            return description;
        }
        /// <summary>
        /// Duplicate button click handler.
        /// </summary>
        private void _DuplicateTemplate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ReportInfo selectedInfo = _GetSelectedInfo();
                if (null != selectedInfo)
                {
                    ReportsGenerator generator = App.Current.ReportGenerator;

                    // generate new name
                    string dir = Path.GetDirectoryName(selectedInfo.TemplatePath);

                    // create sub reports
                    List<SubReportInfo> subReports = new List<SubReportInfo>();
                    foreach (SubReportInfo subReport in selectedInfo.SubReports)
                    {
                        string subNameNew = _GetNameForDublicate(subReport.Name);
                        string subTemplatePath = ReportsGenerator.GetNewTemplatePath(subNameNew, subReport.TemplatePath);
                        SubReportInfo newSubReport = new SubReportInfo(subNameNew, subTemplatePath, subReport.Description,
                                                                       subReport.IsDefault, subReport.GroupId,
                                                                       subReport.IsVisible);
                        // copy template file for subreport template
                        _DuplicateReportFile(subReport.TemplatePath, newSubReport.TemplatePath);

                        subReports.Add(newSubReport);
                    }

                    // create new info
                    string nameNew = _GetNameForDublicate(selectedInfo.Name);
                    string templatePath = ReportsGenerator.GetNewTemplatePath(nameNew, selectedInfo.TemplatePath);
                    ReportInfo newInfo = new ReportInfo(nameNew, selectedInfo.Context, templatePath, selectedInfo.Description,
                                                        false, subReports);

                    // copy template file for template
                    _DuplicateReportFile(selectedInfo.TemplatePath, newInfo.TemplatePath);

                    generator.AddReportInfo(newInfo);
                    _itemToSelection = newInfo.Name;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                App.Current.Messenger.AddError(ex.Message);
            }

            _InitReportTable();
        }
        /// <summary>
        /// Gets report extended fields.
        /// </summary>
        /// <param name="info">Report template info.</param>
        /// <param name="extendedFields">Extended fields.</param>
        private void _GetReportExtendedFields(ReportInfo info, ref List<string> extendedFields)
        {
            Debug.Assert(null != info);
            Debug.Assert(null != extendedFields);

            _GetReportExtendedFields(info.TemplatePath, ref extendedFields);
            foreach (SubReportInfo subInfo in info.SubReports)
                _GetReportExtendedFields(subInfo.TemplatePath, ref extendedFields);
        }
        /// <summary>
        /// Checks report enforce splitted.
        /// </summary>
        /// <param name="reportInfo">Report template info to check.</param>
        /// <returns>TRUE if splitted needed.</returns>
        public bool IsReportEnforceSplitted(ReportInfo reportInfo)
        {
            Debug.Assert(null != reportInfo);

            bool isHardFieldPresent = false;
            ICollection<ReportInfo> reports =
                CommonHelpers.CreateCollectionWithOneObject(reportInfo);
            ICollection<string> extendedFields = GetReportsExtendedFields(reports);
            foreach (string hardField in _exporter.HardFields)
            {
                isHardFieldPresent = extendedFields.Contains(hardField);
                if (isHardFieldPresent)
                    break; // result founded
            }

            return isHardFieldPresent;
        }
        /// <summary>
        /// Adds report template info.
        /// </summary>
        /// <param name="info">New info to adding.</param>
        public void AddReportInfo(ReportInfo info)
        {
            Debug.Assert(null != info);

            // check name
            foreach (ReportInfo currentInfo in _reports.ReportInfos)
            {
                if (info.Name == currentInfo.Name)
                {
                    string text = App.Current.FindString("ReportTemplateNotUniqueName");
                    throw new ArgumentException(text); // exception
                }
            }

            // check file template present
            string reportTemplatePath = GetTemplateAbsolutelyPath(info.TemplatePath);
            if (!File.Exists(reportTemplatePath))
                throw new ArgumentException(); // exception

            _reports.ReportInfos.Add(info);
        }
            /// <summary>
            /// Initializes a new instance of the <c>CreateReportDescription</c> class.
            /// </summary>
            /// <param name="reportName">Name of report.</param>
            /// <param name="reportInfo">Information of report.</param>
            /// <param name="schedules">Schedules to report creation (1 schedule supported).</param>
            /// <param name="route">Route to report creation.</param>
            public CreateReportDescription(string reportName,
                                           ReportInfo reportInfo,
                                           ICollection<Schedule> schedules,
                                           Route route)
            {
                Debug.Assert(!string.IsNullOrEmpty(reportName));
                Debug.Assert(null != reportInfo);
                Debug.Assert(null != schedules);
                Debug.Assert(1 == schedules.Count);
                Debug.Assert(null != route);

                ReportName = reportName;
                ReportInfo = reportInfo;
                Schedules = schedules;
                Routes = CommonHelpers.CreateCollectionWithOneObject(route);
            }
 /// <summary>
 /// Initializes a new instance of the <c>CreateReportDescription</c> class.
 /// </summary>
 /// <param name="reportName">Name of report.</param>
 /// <param name="reportInfo">Information of report.</param>
 /// <param name="schedule">Schedule to report creation.</param>
 /// <param name="route">Route to report creation.</param>
 public CreateReportDescription(string reportName,
                                ReportInfo reportInfo,
                                Schedule schedule,
                                Route route)
     : this(reportName,
          reportInfo,
          CommonHelpers.CreateCollectionWithOneObject(schedule),
          route)
 {
 }