Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
        }