Ejemplo n.º 1
0
        private void _btnApply_Click(object sender, System.EventArgs e)
        {
            // get selected style
            ReportStyle style = _list.SelectedItem as ReportStyle;

            if (style != null && _designer != null && _designer.Report != null)
            {
                // save state, apply to report, repaint
                _designer.UndoSaveState();
                style.Apply(_designer.Report);
                _designer.Invalidate();

                // this is the new 'current' style
                _owner._defaultStyleName = style.Name;
            }
        }
Ejemplo n.º 2
0
        // create report based on current user selections
        // note: at this point _rpt.DataSource is already set
        private void CreateReport()
        {
            // set report name
            _rpt.ReportName = _txtReportName.Text.Trim();

            // set up data source
            DataSource ds = _rpt.DataSource;

            ds.ConnectionString = _dsPicker.ConnectionString;
            ds.RecordSource     = _dsPicker.RecordSource;

            // get schema and field template list
            _schema    = _rpt.DataSource.DataSourceInfo;
            _fieldList = BuildFieldTemplateList();

            // set up layout object
            Layout lo = _rpt.Layout;

            lo.Orientation = (_btnLandscape.Checked)
                ? OrientationEnum.Landscape
                : OrientationEnum.Portrait;

            lo.Width = lo.PageSize.Width - lo.MarginLeft - lo.MarginRight;
            double width = lo.Width;

            // create report groups
            foreach (string s in _lstGroups.Items)
            {
                SortEnum sort = (IsFieldNumber(s)) ? SortEnum.Descending : SortEnum.Ascending;
                Group    g    = _rpt.Groups.Add(s, s, sort);
                g.KeepTogether            = KeepTogetherEnum.KeepFirstDetail;
                g.OutlineLabel.Expression = s;
                // Make group header/footer visible (they are not by default, have no idea why):
                g.SectionFooter.Visible = true;
                g.SectionFooter.Visible = true;
            }

            // special handling for label reports
            if (_btnLabels.Checked)
            {
                ListViewItem lvi = (_lvLabels.SelectedItems.Count > 0)
                    ? _lvLabels.SelectedItems[0]
                    : _lvLabels.Items[0];
                ReportLabel lbl = (ReportLabel)lvi.Tag;
                BuildDetail(lbl);
                return;
            }

            // build report header (1 field)
            Section section = _rpt.Sections[SectionTypeEnum.Header];

            section.Visible = true;
            section.Height  = 800;

            section.Fields.Add(
                MakeTextField("titleLbl",
                              _txtReportName.Text,
                              FIELD_OFFSET, 200, width, 600, FieldAlignEnum.LeftMiddle));

            // build page footer (2 fields)
            section         = _rpt.Sections[SectionTypeEnum.PageFooter];
            section.Visible = true;
            section.Height  = 500;

            section.Fields.Add(
                MakeTextField("ftrLeft",
                              new ScriptObjectValue()
            {
                Expression = "Now()"
            },
                              FIELD_OFFSET, 30, width / 2, 300, FieldAlignEnum.LeftTop));

            section.Fields.Add(
                MakeTextField("ftrRight",
                              new ScriptObjectValue()
            {
                Expression = Strings.ReportWizard.PageOfPagesText
            },
                              width / 2, 30, width / 2, 300, FieldAlignEnum.RightTop));

            // build other sections (these vary with selected layout)
            BuildPageHeader();
            for (int i = 0; i < _rpt.Groups.Count; i++)
            {
                BuildGroupHeader(i);
            }
            BuildDetail();

            // all done, apply selected style
            ReportStyle style = _lbStyles.SelectedItem as ReportStyle;

            if (style != null)
            {
                style.Apply(_rpt);
            }
        }