Пример #1
0
        /// <summary>
        /// Occurs when user press "Enter" on edited grid row.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataGridCollectionViewSource_CommittingEdit(object sender, DataGridItemCancelEventArgs e)
        {
            try
            {
                if (_isEditeStart && !string.IsNullOrEmpty(_selectedProfileName))
                {
                    ReportInfo editedInfo = App.Current.ReportGenerator.GetReportInfo(_selectedProfileName);
                    if (null != editedInfo)
                    {
                        Debug.Assert(!editedInfo.IsPredefined);

                        ReportDataWrapper selectedItem = xceedGridReports.CurrentItem as ReportDataWrapper;

                        string templatePath = ReportsGenerator.GetNewTemplatePath(selectedItem.Name, editedInfo.TemplatePath);

                        string fileSrcName  = ReportsGenerator.GetTemplateAbsolutelyPath(editedInfo.TemplatePath);
                        string fileDestName = ReportsGenerator.GetTemplateAbsolutelyPath(templatePath);
                        File.Move(fileSrcName, fileDestName);

                        _selectedProfileName = editedInfo.Name = selectedItem.Name;
                        ReportDataWrapper.StartTemplatePath = templatePath;
                        ReportDataWrapper.StartTemplateName = _selectedProfileName;
                        editedInfo.TemplatePath             = templatePath;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                App.Current.Messenger.AddError(ex.Message);
            }

            _isEditeStart = false;
            e.Handled     = true;
        }
Пример #2
0
        /// <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();
        }
Пример #3
0
        public override ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context)
        {
            // not empty check
            bool isObjectEmpty = true;

            if (null != value)
            {
                isObjectEmpty = string.IsNullOrEmpty(value.ToString().Trim());
            }
            if (isObjectEmpty)
            {
                return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateEmptyName")));
            }

            // unique name check
            string name = value.ToString();

            if (!string.IsNullOrEmpty(ReportDataWrapper.StartTemplateName))
            {
                if (0 == string.Compare(ReportDataWrapper.StartTemplateName, name, true))
                {
                    return(ValidationResult.ValidResult);
                }
            }

            ReportsGenerator     generator      = App.Current.ReportGenerator;
            ICollection <string> presentedNames = generator.GetPresentedNames(true);

            foreach (string nameTemplate in presentedNames)
            {
                if (0 == string.Compare(nameTemplate, name, true))
                {
                    return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateNotUniqueName")));
                }
            }

            // normal length check
            bool   isLong       = false;
            string templatePath = ReportsGenerator.GetNewTemplatePath(name, ReportDataWrapper.StartTemplatePath);
            string fileName     = null;

            try
            {
                fileName = ReportsGenerator.GetTemplateAbsolutelyPath(templatePath);
                new FileInfo(fileName);
            }
            catch (PathTooLongException)
            {
                isLong = true;
            }
            catch (Exception)
            {
            }

            if (isLong)
            {
                return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateLongName")));
            }

            // valid name check
            if (!FileHelpers.ValidateFilepath(fileName))
            {
                return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateInvalidName")));
            }

            return(ValidationResult.ValidResult);
        }