Exemple #1
0
        public EditorScriptItemCollection(C1FlexReport report, EditorScriptContextCollection contexts, C1FlexReportDesigner designer)
        {
            var ctxtName = EditorScriptContextBase.MakeContextName(report.DataSourceName, ScriptEditorContextKind.ReportScript);
            var context  = contexts.GetContext(ctxtName);

            Action <EditorScriptItem> addScriptItem = (si_) => this.Add(si_.Key, si_);

            // global script:
            addScriptItem(EditorScriptItem.FromObjectProperty(report, "GlobalScripts", context, true));

            // report event handlers:
            addScriptItem(EditorScriptItem.FromObjectProperty(report, "OnOpen", context, true));
            addScriptItem(EditorScriptItem.FromObjectProperty(report, "OnClose", context, true));
            addScriptItem(EditorScriptItem.FromObjectProperty(report, "OnNoData", context, true));
            addScriptItem(EditorScriptItem.FromObjectProperty(report, "OnPage", context, true));
            addScriptItem(EditorScriptItem.FromObjectProperty(report, "OnError", context, true));

            // Sections' event handlers:
            foreach (Section s in report.Sections)
            {
                addScriptItem(EditorScriptItem.FromObjectProperty(s, "OnFormat", context, true));
                addScriptItem(EditorScriptItem.FromObjectProperty(s, "OnPrint", context, true));
            }

            // Report fields' expressions:
            foreach (FieldBase f in report.Fields)
            {
                ScriptEditorExpressionInfo fieldEditorInfo = designer.GetScriptEditorExpressionInfo(f);
                if (fieldEditorInfo != null)
                {
                    addScriptItem(EditorScriptItem.FromObjectProperty(f, fieldEditorInfo.PropertyName, context, false));
                }
            }
        }
Exemple #2
0
        public EditorScriptContextCollection(Forms.ScriptEditorFormEx owner, C1FlexReport report, C1FlexReportDesigner designer)
        {
            _owner  = owner;
            _report = report;
            string name;

            foreach (var ds in report.DataSources)
            {
                // For each data source, we add 3 contexts:
                // - data handler
                // - regular report
                // - data filter
                string dsName = ds.Name;
                name = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.DataHandler);
                _contexts.Add(name, new EditorScriptDataHandlerContext(name, _report, ds, designer));
                name = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.ReportScript);
                _contexts.Add(name, new EditorScriptReportScriptContext(name, _report, ds, designer));
                name = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.DataView);
                _contexts.Add(name, new EditorScriptDataFilterContext(name, _report, ds, designer));
            }
            // 'report-only' context (currently used for parameter's allowed values collection edits):
            name = EditorScriptContextBase.MakeContextName(string.Empty, ScriptEditorContextKind.ReportScript);
            _contexts.Add(name, new EditorScriptReportScriptContext(name, _report, null, designer));
            // meta context for expressions that can only access parameters (currently only data sort definition),
            // also is used for cases when corresponding context was not found (patchy but will do for now):
            name = EditorScriptContextBase.MakeContextName(null, ScriptEditorContextKind.MetaView);
            _contexts.Add(name, new EditorScriptMetaViewContext(name, _report, designer));
        }
Exemple #3
0
        public EditorScriptContextBase GetContext(string name)
        {
            EditorScriptContextBase ret;

            _contexts.TryGetValue(name, out ret);
            if (ret == null)
            {
                // fallback context for invalid data source names:
                ret = _contexts[EditorScriptContextBase.MakeContextName(null, ScriptEditorContextKind.MetaView)];
            }
            return(ret);
        }
Exemple #4
0
        private void DoAddSortDefinition()
        {
            if (!cAddSort.Enabled)
            {
                return;
            }

            C1FlexReport report = _flexDesigner.Report;

            if (report == null)
            {
                return;
            }

            var ds = _dataTree.GetCurrentDataSource();

            if (ds == null)
            {
                return;
            }

            var                     contextName = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.MetaView);
            SortDefinition          sd          = null;
            Func <DataSource, bool> addSort     = (ds_) =>
            {
                sd = new SortDefinition();
                ds_.SortDefinitions.Add(sd);
                using (Forms.AddSortDefForm addForm = new Forms.AddSortDefForm(ds))
                {
                    if (addForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        sd.Expression = addForm.SortExpression;
                        sd.Direction  = addForm.Ascending ? SortDirection.Ascending : SortDirection.Descending;
                        return(true);
                    }
                    else
                    {
                        sd = null;
                        return(false);
                    }
                }
            };

            DoDataSourcesAction(addSort, ds);

            if (sd != null)
            {
                _dataTree.GoToSortDefinition(ds, sd);
            }
        }
Exemple #5
0
        private void DoAddCalculatedField()
        {
            if (!cAddCalculatedField.Enabled)
            {
                return;
            }

            C1FlexReport report = _flexDesigner.Report;

            if (report == null)
            {
                return;
            }

            var ds = _dataTree.GetCurrentDataSource();

            if (ds == null)
            {
                return;
            }

            var                     contextName = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.DataHandler);
            CalculatedField         cf          = null;
            Func <DataSource, bool> addField    = (ds_) =>
            {
                cf      = new CalculatedField();
                cf.Name = DesignerUtil.MakeUniqueName(ds_.CalculatedFields, "CalculatedField");
                ds_.CalculatedFields.Add(cf);
                object result;
                if (EditScriptInternal(ds_.ParentReport, contextName, null, cf, "Expression", null, true, out result))
                {
                    return(true);
                }
                cf = null;
                return(false);
            };

            DoDataSourcesAction(addField, ds);

            if (cf != null)
            {
                _dataTree.GoToCalculatedField(cf);
            }
        }
Exemple #6
0
        private void DoAddSortDefinition()
        {
            if (!cAddSort.Enabled)
            {
                return;
            }

            C1FlexReport report = _flexDesigner.Report;

            if (report == null)
            {
                return;
            }

            var ds = _dataTree.GetCurrentDataSource();

            if (ds == null)
            {
                return;
            }

            var                     contextName = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.MetaView);
            SortDefinition          sd          = null;
            Func <DataSource, bool> addSort     = (ds_) =>
            {
                sd = new SortDefinition();
                ds_.SortDefinitions.Add(sd);
                object result;
                if (EditScriptInternal(ds_.ParentReport, contextName, null, sd, "Expression", null, true, out result))
                {
                    return(true);
                }
                sd = null;
                return(false);
            };

            DoDataSourcesAction(addSort, ds);

            if (sd != null)
            {
                _dataTree.GoToSortDefinition(ds, sd);
            }
        }
Exemple #7
0
        private void DoScriptEditor()
        {
            C1FlexReport report = _flexDesigner.Report;

            if (report == null)
            {
                return;
            }

            var    state = _flexDesigner.Undo_CreateSavedState();
            object result;
            var    contextName = EditorScriptContextBase.MakeContextName(report.DataSourceName, ScriptEditorContextKind.ReportScript);

            if (EditScriptInternal(report, contextName, null, report, "GlobalScripts", null, false, out result))
            {
                _flexDesigner.Undo_PushSavedState(state);
            }
            else
            {
                _flexDesigner.Undo_DiscardSavedState(state);
            }
        }
Exemple #8
0
        private void DoDataTreeEdit()
        {
            var dataObject = _dataTree.SelectedDataObject;

            if (dataObject == null)
            {
                return;
            }

            if (dataObject is DataSource)
            {
                DoDataSourcesAction((Func <DataSource, bool>)DataSources_EditDataSource, (DataSource)dataObject);
                return;
            }

            _dataTree.EndInPlaceEdit();
            var undo = _flexDesigner.Undo_CreateSavedState();

            if (dataObject is CalculatedField)
            {
                var    cf          = (CalculatedField)dataObject;
                var    ds          = _dataTree.GetCurrentDataSource();
                var    contextName = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.DataHandler);
                object result;
                if (EditScriptInternal(ds.ParentReport, contextName, null, dataObject, "Expression", null, true, out result))
                {
                    _flexDesigner.Undo_PushSavedState(undo);
                    _flexDesigner.UpdateFromReport();
                    _dataTree.UpdateFromReport();
                }
                else
                {
                    _flexDesigner.Undo_DiscardSavedState(undo);
                }
            }
            else if (dataObject is SortDefinition)
            {
#if skip_dima // simplifying...
                var    sd          = (SortDefinition)dataObject;
                var    ds          = _dataTree.GetCurrentDataSource();
                var    contextName = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.MetaView);
                object result;
                if (EditScriptInternal(ds.ParentReport, contextName, null, dataObject, "Expression", null, true, out result))
                {
                    _flexDesigner.Undo_PushSavedState(undo);
                    _flexDesigner.UpdateFromReport();
                    _dataTree.UpdateFromReport();
                }
                else
                {
                    _flexDesigner.Undo_DiscardSavedState(undo);
                }
#else
                var sd = (SortDefinition)dataObject;
                var ds = _dataTree.GetCurrentDataSource();
                using (Forms.AddSortDefForm addForm = new Forms.AddSortDefForm(ds))
                {
                    addForm.SortExpression = sd.Expression;
                    addForm.Ascending      = sd.Direction.Value == SortDirection.Ascending;
                    if (addForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        sd.Expression = addForm.SortExpression;
                        sd.Direction  = addForm.Ascending ? SortDirection.Ascending : SortDirection.Descending;
                        _flexDesigner.Undo_PushSavedState(undo);
                        _flexDesigner.UpdateFromReport();
                        _dataTree.UpdateFromReport();
                    }
                    else
                    {
                        _flexDesigner.Undo_DiscardSavedState(undo);
                    }
                }
#endif
            }
            else
            {
                System.Diagnostics.Debug.Assert(false, "Do not know how to edit data object");
            }
            UpdateUI(true, true);
        }
Exemple #9
0
        private void DoCreateField(RibbonItem item)
        {
            if (item == rbtnFieldChart)
            {
                _flexDesigner.CreateFieldInfo = item;
                _createInfo = null;
            }
            else if (item == rbtnFieldFlexChart)
            {
                _flexDesigner.CreateFieldInfo = item;
                _createInfo = null;
            }
#if MAP
            else if (item == rbtnFieldMap)
            {
                _flexDesigner.CreateFieldInfo = item;
                _createInfo = null;
            }
#endif
            else if (item == rbtnFieldDataField || item == rbtnFieldRtf || item == rbtnFieldCheckBox || item == rbtnFieldBarCode ||
                     item == rbtnFieldShape || item == rbtnFieldLegacy || item == rbtnFieldParagraph || item == rbtnFieldLegacy)
            {
                _flexDesigner.CreateFieldInfo = item;
                _createInfo = null;
            }
            else if (item == rbtnFieldCalculated)
            {
                ValueHolder valueHolder = new ValueHolder()
                {
                    Value = string.Empty
                };
                var    contextName = EditorScriptContextBase.MakeContextName(_flexDesigner.Report.DataSourceName, ScriptEditorContextKind.ReportScript);
                object result;
                if (EditScriptInternal(_flexDesigner.Report, contextName, null, valueHolder, "Value", Strings.MainForm.NewCalcFieldExprName, true, out result))
                {
                    _createInfo = valueHolder.Value;
                    if (!string.IsNullOrEmpty(_createInfo))
                    {
                        _flexDesigner.CreateFieldInfo = item;
                    }
                }
                else
                {
                    _flexDesigner.CreateFieldInfo = null;
                    item = rbtnFieldArrow; // to reset Pressed
                }
            }
            else if (item == rbtnFieldPicture)
            {
                using (OpenFileDialog dlg = new OpenFileDialog())
                {
                    dlg.DereferenceLinks = true;
                    dlg.Filter           = Strings.MainForm.OpenImageFilter;
                    dlg.FileName         = "*.bmp;*.dib;*.ico;*.cur;*.gif;*.jpg;*.wmf;*.emf;*.png";
                    dlg.FilterIndex      = 0;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        _createInfo = dlg.FileName;
                        _flexDesigner.CreateFieldInfo = rbtnFieldPicture;
                    }
                    else
                    {
                        _flexDesigner.CreateFieldInfo = null;
                        item = rbtnFieldArrow; // to reset Pressed
                    }
                }
            }
            else if (item.Parent is RibbonDropDownBase)
            {
                _flexDesigner.CreateFieldInfo = item.Parent;
                _createInfo = ((RibbonButton)item).Text;
            }
            else if (item.Tag is Field)
            {
                _flexDesigner.CreateFieldInfo = item;
            }

            // NO else here on purpose:
            if (item == rbtnFieldArrow)
            {
                _flexDesigner.CancelMouseOperation();
                _flexDesigner.CreateFieldInfo = null;
                _createInfo = null;
            }
            // We keep the button that caused the action pressed for the duration of adding the field
            // (i.e. while mouse cursor is a cross), while un-pressing all other items:
            UpdateCreateFieldButtons(item);
            //
            if (item != rbtnFieldArrow)
            {
                _flexDesigner.DoCreateFieldWithMouse(_flexDesigner.CreateFieldInfo);
            }
        }