Beispiel #1
0
        private void flexDesigner_CreateField(object sender, C1.Win.FlexReport.CreateFieldEventArgs e)
        {
            // NOTE: currently add field buttons are used as the keys for inserting fields,
            // i.e. button.Tag/Action are not used. Might want to change that.

            RibbonItem btn      = e.CreateFieldInfo as RibbonItem;
            FieldBase  newField = null;
            string     fldName  = GetUniqueFieldName();

            Action <FieldBase> setFieldBaseProps = (field_) =>
            {
                field_.Name   = fldName;
                field_.Left   = e.FieldBounds.Left;
                field_.Top    = e.FieldBounds.Top;
                field_.Width  = e.FieldBounds.Width;
                field_.Height = e.FieldBounds.Height;
            };

            // Select field type, create field:
            if (btn == rbtnFieldDataField)
            {
                TextField textField = new TextField();
                setFieldBaseProps(textField);
                e.SubSection.Fields.Add(textField);
                newField       = textField;
                textField.Text = _createInfo != null ? ("=" + _createInfo) : string.Empty;
            }
            else if (btn == rbtnFieldCalculated)
            {
                TextField calcField = new TextField();
                setFieldBaseProps(calcField);
                e.SubSection.Fields.Add(calcField);
                CommonFields.SetupField(_flexDesigner.Report, calcField, _createInfo);
                newField = calcField;
            }
            else if (btn == rbtnFieldParagraph)
            {
                ParagraphField paraField = new ParagraphField();
                setFieldBaseProps(paraField);
                e.SubSection.Fields.Add(paraField);
                newField = paraField;
                paraField.Content.Add(_createInfo != null ? ("=" + _createInfo) : string.Empty);
            }
            else if (btn == rbtnFieldRtf)
            {
                RtfField rtfField = new RtfField();
                setFieldBaseProps(rtfField);
                e.SubSection.Fields.Add(rtfField);
                newField      = rtfField;
                rtfField.Text = _createInfo != null ? ("=" + _createInfo) : string.Empty;
            }
            else if (btn == rbtnFieldCheckBox)
            {
                CheckBoxField cbField = new CheckBoxField();
                setFieldBaseProps(cbField);
                e.SubSection.Fields.Add(cbField);
                if (_createInfo != null)
                {
                    cbField.Value = "=" + _createInfo;
                    cbField.Text  = _createInfo;
                }
                newField = cbField;
            }
            else if (btn == rbtnFieldChart)
            {
                ChartField chartField = new ChartField();
                setFieldBaseProps(chartField);
                e.SubSection.Fields.Add(chartField);
                newField = chartField;
            }
#if MAP
            else if (btn == rbtnFieldMap)
            {
                var mapField = new MapField();
                setFieldBaseProps(mapField);
                e.SubSection.Fields.Add(mapField);
                mapField.InitLayout();
                newField = mapField;
            }
#endif
            else if (btn == rbtnFieldBarCode)
            {
                BarCodeField barcodeField = new BarCodeField();
                setFieldBaseProps(barcodeField);
                e.SubSection.Fields.Add(barcodeField);
                barcodeField.Text = _createInfo != null ? ("=" + _createInfo) : "BARCODE";
                // barcodeField.BarCode = C1.Win.C1Document.BarCodeEnum.Code39x; // this was set as default in C1Report designer
                newField = barcodeField;
            }
            else if (btn == rbtnFieldPicture)
            {
                ImageField imageField = new ImageField();
                setFieldBaseProps(imageField);
                e.SubSection.Fields.Add(imageField);
                imageField.Picture = _createInfo;
                newField           = imageField;
            }
            else if (btn == rbtnFieldShape)
            {
                ShapeField shapeField = new ShapeField();
                setFieldBaseProps(shapeField);
                e.SubSection.Fields.Add(shapeField);
                newField = shapeField;
            }
            else if (btn == rbtnFieldSubReport)
            {
                SubreportField subreportField = new SubreportField();
                setFieldBaseProps(subreportField);
                e.SubSection.Fields.Add(subreportField);
                foreach (ReportItem ri in _reportList.Items)
                {
                    if (ri.ToString() == _createInfo && ri.Report != _flexDesigner.Report)
                    {
                        subreportField.Subreport = ri.Report;
                        break;
                    }
                }
                newField = subreportField;
            }
            else if (btn == rbtnFieldLegacy)
            {
                Field legacyField = new Field();
                setFieldBaseProps(legacyField);
                e.SubSection.Fields.Add(legacyField);
                newField = legacyField;
            }
            else if (btn == rbtnFieldFlexChart)
            {
                FlexChartField flexChartField = new FlexChartField();
                setFieldBaseProps(flexChartField);
                flexChartField.Series.Add(new C1.Win.FlexReport.FlexChart.Series()
                {
                    Name        = "DefaultSeries",
                    Label       = "Count",
                    YExpression = "Count()"
                });
                e.SubSection.Fields.Add(flexChartField);
                newField = flexChartField;
            }
            else if (btn.Tag is Field) // custom field
            {
                Field customField = (Field)btn.Tag;
                setFieldBaseProps(customField);
                e.SubSection.Fields.Add(customField);
                newField = customField;
            }
            // else if (btn == rbtnFieldPageBreak) ....
            else
            {
                System.Diagnostics.Debug.Assert(false, "unknown field insert op");
            }

            // select the new field, zap creator
            _flexDesigner.UpdateFromReport();
            _flexDesigner.SelectField(newField, true, true);
            _flexDesigner.CreateFieldInfo = null;
            UpdateCreateFieldButtons(rbtnFieldArrow);
            UpdateUI(false);

            // update report list icons
            if (btn == rbtnFieldSubReport)
            {
                _reportList.UpdateIcons();
            }
        }