示例#1
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            // select XML file to use as a data source
            // (in this sample, should be a report definition file)
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.FileName = "*.xml";
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // load XML document
            XmlDocument doc = new XmlDocument();

            doc.Load(dlg.FileName);

            // create dummy report definition with a single field (report names)
            _c1r.Clear();
            Section s = _c1r.Sections[SectionTypeEnum.Detail];

            s.Visible = true;
            s.Height  = 400;
            Field f = s.Fields.Add("fld", "Name", 0, 0, 6000, 300);

            f.Calculated = true;

            // create custom data source using XPath
            // in this case, the data source will have one 'record' per report definition
            // in the file, and each record will contain the report information
            XmlDataSource xds = new XmlDataSource(doc.SelectNodes("Reports/Report"));

            // assign custom data source to report control and show the report
            _c1r.DataSource.Recordset = xds;
            _ppv.Document             = _c1r;
        }
示例#2
0
        private void RenderEmployees()
        {
            Field f;

            // prevent reentrant calls
            if (c1r.IsBusy)
            {
                return;
            }

            // initialize control
            c1r.Clear();                            // clear any existing fields
            c1r.Font.Name  = "Tahoma";              // set default font for all controls
            c1r.Font.Size  = 9;
            c1r.ReportName = "Employees";

            // initialize DataSource
            DataSource ds = c1r.DataSource;

            ds.ConnectionString =
                @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
                Environment.GetFolderPath(Environment.SpecialFolder.Personal) +
                @"\ComponentOne Samples\Common\c1nwind.mdb";
            ds.RecordSource = "Employees";

            // initialize Layout
            Layout l = c1r.Layout;

            l.Orientation = OrientationEnum.Portrait;
            l.Width       = 6.5 * 1440;       // 8.5 - margins

            // create a report header
            Section s = c1r.Sections[SectionTypeEnum.Header];

            s.Height    = 1440;
            s.Visible   = true;
            s.BackColor = Color.FromArgb(200, 200, 200);
            f           = s.Fields.Add("FldTitle", "Employees Report", 0, 0, 8000, 1440);
            f.Font.Size = 24;
            f.Font.Bold = true;
            f.ForeColor = Color.FromArgb(0, 0, 100);

            // create a page footer
            s             = c1r.Sections[SectionTypeEnum.PageFooter];
            s.Height      = 500;
            s.Visible     = true;
            f             = s.Fields.Add("FldFtrLeft", @"""Employees: Printed on "" & Now", 0, 0, 4000, 300);
            f.Calculated  = true;
            f             = s.Fields.Add("FldFtrRight", @"""Page "" & Page & "" of "" & Pages", 4000, 0, 4000, 300);
            f.Calculated  = true;
            f.Align       = FieldAlignEnum.RightTop;
            f.Width       = c1r.Layout.Width - f.Left;
            f             = s.Fields.Add("FldLine", "", 0, 0, c1r.Layout.Width, 20);
            f.LineSlant   = LineSlantEnum.NoSlant;
            f.BorderStyle = BorderStyleEnum.Solid;
            f.BorderColor = Color.FromArgb(0, 0, 100);

            // create a page header with field labels
            s             = c1r.Sections[SectionTypeEnum.PageHeader];
            s.Height      = 500;
            s.Visible     = true;
            c1r.Font.Bold = true;
            f             = s.Fields.Add("LblID", "ID", 0, 50, 400, 300);
            f.Align       = FieldAlignEnum.RightTop;
            f             = s.Fields.Add("LblFirstName", "First", 500, 50, 900, 300);
            f             = s.Fields.Add("LblLastName", "Last", 1500, 50, 900, 300);
            f             = s.Fields.Add("LblTitle", "Title", 2500, 50, 2400, 300);
            f             = s.Fields.Add("LblTitle", "Notes", 5000, 50, 8000, 300);
            c1r.Font.Bold = false;
            f             = s.Fields.Add("FldLine", "", 0, 400, c1r.Layout.Width, 20);
            f.LineSlant   = LineSlantEnum.NoSlant;
            f.LineWidth   = 50;
            f.BorderStyle = BorderStyleEnum.Solid;
            f.BorderColor = Color.FromArgb(100, 100, 100);

            // create the detail section
            s             = c1r.Sections[SectionTypeEnum.Detail];
            s.Height      = 330;
            s.Visible     = true;
            f             = s.Fields.Add("FldID", "EmployeeID", 0, 0, 400, 300);
            f.Calculated  = true;
            f             = s.Fields.Add("FldFirstName", "FirstName", 500, 0, 900, 300);
            f.Calculated  = true;
            f             = s.Fields.Add("FldLastName", "LastName", 1500, 0, 900, 300);
            f.Calculated  = true;
            f             = s.Fields.Add("FldTitle", "Title", 2500, 0, 2400, 300);
            f.Calculated  = true;
            f             = s.Fields.Add("FldNotes", "Notes", 5000, 0, 8000, 300);
            f.Width       = c1r.Layout.Width - f.Left;
            f.Calculated  = true;
            f.CanGrow     = true;
            f.Font.Size   = 6;
            f.Align       = FieldAlignEnum.JustTop;
            f             = s.Fields.Add("FldLine", "", 0, 310, c1r.Layout.Width, 20);
            f.LineSlant   = LineSlantEnum.NoSlant;
            f.BorderStyle = BorderStyleEnum.Solid;
            f.BorderColor = Color.FromArgb(100, 100, 100);

            if (chkGroup.Checked)
            {
                // group employees by country, in ascending order
                Group grp = c1r.Groups.Add("GrpCountry", "Country", SortEnum.Ascending);
                s             = grp.SectionHeader;
                s.Height      = 500;
                s.Visible     = true;
                f             = s.Fields.Add("CtlCountry", "Country", 0, 0, c1r.Layout.Width, 500);
                f.Calculated  = true;
                f.Align       = FieldAlignEnum.LeftMiddle;
                f.Font.Bold   = true;
                f.Font.Size   = 12;
                f.BorderStyle = BorderStyleEnum.Solid;
                f.BorderColor = Color.FromArgb(0, 0, 150);
                f.BackStyle   = BackStyleEnum.Opaque;
                f.BackColor   = Color.FromArgb(150, 150, 220);
                f.MarginLeft  = 100;

                // sort employees by first name within each country
                c1r.Groups.Add("GrpName", "FirstName", SortEnum.Ascending);
            }

            // render the report into the PrintPreviewControl
            _ppv.Document = c1r;
            // _ppv.InvalidatePreview(); -- no need to render if shown in C1 preview control
        }
示例#3
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            // clear report
            _c1r.Clear();
            _c1r.ReportName        = "Images";
            _c1r.Font              = new Font("Tahoma", 9);
            _c1r.Layout.MarginLeft = 600;

            // configure detail section
            Section   section = _c1r.Sections[SectionTypeEnum.Detail];
            Rectangle rc      = new Rectangle(0, 0, 1600, 1200);

            section.Height  = rc.Height;
            section.Visible = true;
            section.CanGrow = true;

            // add fields
            FieldCollection fc = section.Fields;

            // create ID field
            Field f = fc.Add("fldID", "ID", rc);

            f.Align       = FieldAlignEnum.LeftTop;
            f.Calculated  = true;
            f.BorderStyle = BorderStyleEnum.Solid;

            // create file name field
            rc.Offset(rc.Width + 100, 0);
            f             = fc.Add("fldFileName", "FileName", rc);
            f.Align       = FieldAlignEnum.LeftTop;
            f.WordWrap    = true;
            f.Calculated  = true;
            f.BorderStyle = BorderStyleEnum.Solid;

            // create 1st image field (directly from db)
            rc.Offset(rc.Width + 100, 0);
            rc.Width       = 4000;
            rc.Height      = 4000;
            f              = fc.Add("fldImage", "Image", rc);
            f.Picture      = "Image";
            f.PictureAlign = PictureAlignEnum.Zoom;
            f.BorderStyle  = BorderStyleEnum.Solid;

            // create 2nd image field (laoded from file at render time)
            rc.Offset(rc.Width + 100, 0);
            f = fc.Add("fldFileImage", "", rc);
            f.PictureAlign = PictureAlignEnum.Zoom;
            f.BorderStyle  = BorderStyleEnum.Solid;

            // use script to set Picture property at render time:
            // this takes the iamge filename from the 'fldFileName' calculated field.
            section.OnPrint = "fldFileImage.Picture = fldFileName";

            // set data source
            _c1r.DataSource.Recordset = _dt;

            // show it
            C1.Win.C1Preview.C1PrintPreviewDialog dlg = new C1.Win.C1Preview.C1PrintPreviewDialog();
            dlg.Document = _c1r;
            dlg.ShowDialog();
        }
示例#4
0
        // build report to show all fields in a flex control
        private void BuildReportDefinition()
        {
            // initialize report
            _c1r.Clear();
            _c1r.Layout.Orientation = OrientationEnum.Landscape;
            _c1r.Layout.MarginLeft  = 500;

            // add header section
            Section s = _c1r.Sections[SectionTypeEnum.Header];

            s.Visible = true;
            s.Height  = 700;
            Field f = s.Fields.Add("fldTitle", "Flex-based report", 0, 0, 4000, 700);

            f.Font = new Font("Tahoma", 14, FontStyle.Bold);

            // add page header and detail sections
            Section sHdr = _c1r.Sections[SectionTypeEnum.PageHeader];

            sHdr.Visible = true;
            sHdr.Height  = 400;

            Section sDtl = _c1r.Sections[SectionTypeEnum.Detail];

            sDtl.Visible = true;
            sDtl.Height  = 100;
            sDtl.CanGrow = true;

            // populate header and detail sections
            Font      fntHdr = new Font("Tahoma", 8, FontStyle.Bold | FontStyle.Underline);
            Font      fntDtl = new Font("Tahoma", 8, FontStyle.Regular);
            Rectangle rc     = new Rectangle(0, 0, (int)sDtl.Height, 0);

            foreach (Column col in _flex.Cols)
            {
                // calculate field rectangle in twips
                rc.Width = col.WidthDisplay * 1440 / 96 + 200;

                // create field in page header section
                rc.Height   = (int)sHdr.Height;
                f           = sHdr.Fields.Add("fh" + col.Name, col.Name, rc);
                f.Font      = fntHdr;
                f.ForeColor = Color.Navy;
                f.Align     = FieldAlignEnum.LeftBottom;

                // create field in detail section
                rc.Height    = (int)sDtl.Height;
                f            = sDtl.Fields.Add("fd" + col.Name, col.Name, rc);
                f.Font       = fntDtl;
                f.Calculated = true;
                f.CanGrow    = true;
                f.Format     = col.Format;

                // move on to next field
                rc.Offset(rc.Width, 0);
                if (rc.Left > 10 * 1440)
                {
                    break;
                }
            }

            // assign data source
            _c1r.DataSource.Recordset = new FlexDataSource(_flex);
        }
示例#5
0
        private void CreateReport(string reportTitle)
        {
            // clear any existing reports
            //
            _c1r.Clear();

            // set new report name
            //
            _c1r.ReportName = reportTitle;

            // initialize layout
            //
            _c1r.Layout.Orientation = OrientationEnum.Landscape;

            // create data source object and assign it to new report
            // (in this case, the DataSource is a DataView object)
            //
            DataView dv = CreateDataSource(8, 200);

            _c1r.DataSource.Recordset = dv;

            // add a group
            // (sort data by region)
            //
            _c1r.Groups.Add("Region Group", "Region", SortEnum.Ascending);

            // initialize group header section
            //
            Section ghdr = _c1r.Sections[SectionTypeEnum.GroupHeader1];

            ghdr.Height    = 600;                               // twips
            ghdr.Visible   = true;                              // make new section visible
            ghdr.BackColor = Color.DarkBlue;                    // give section a solid background
            ghdr.Repeat    = true;                              // repeat after page breaks

            // add group header fields
            //
            _c1r.Font = new Font("Arial", 12, FontStyle.Bold);
            Field f = ghdr.Fields.Add("grpHdr", "Region & \" Region Data\"", new Rectangle(50, 0, 4000, 600));

            f.Calculated = true;
            f.ForeColor  = Color.White;
            f.Align      = FieldAlignEnum.LeftBottom;

            // initialize page header section
            //
            Section shdr = _c1r.Sections[SectionTypeEnum.PageHeader];

            shdr.Height  = 1200;                                        // twips
            shdr.Visible = true;                                        // make new section visible

            // add page header fields
            //

            // report title
            _c1r.Font = new Font("Arial", 14, FontStyle.Bold | FontStyle.Italic);
            shdr.Fields.Add("rptName", _c1r.ReportName, new Rectangle(0, 0, 8000, 400));

            // page number
            _c1r.Font    = new Font("Arial", 9, FontStyle.Bold);
            f            = shdr.Fields.Add("pgNum", "\"Page \" & Page", new Rectangle(9000, 0, 1000, 300));
            f.Calculated = true;

            // initialize detail section
            //
            Section sdtl = _c1r.Sections[SectionTypeEnum.Detail];

            sdtl.Height  = 300;
            sdtl.Visible = true;

            // initialize script
            // (data values are between 100 and 1000)
            //
            string script = "", scriptFmt = "";

            if (_script)
            {
                script    = "MinVal = 300\nMaxVal = 700\n";
                scriptFmt =
                    "{0}.ForeColor = rgb(50,0,0)\n" +
                    "if {0}.Value < MinVal then {0}.ForeColor = rgb(150,0,0)\n" +
                    "if {0}.Value > MaxVal then {0}.ForeColor = rgb(0,150,0)\n";
            }

            // create report fields
            //
            int       fldCtr = 0;
            Rectangle rc     = new Rectangle(0, 0, 1000, 300);

            foreach (DataColumn col in dv.Table.Columns)
            {
                // add page header labels
                rc.Height    = (int)shdr.Height;
                _c1r.Font    = new Font("Arial", 10, FontStyle.Bold);
                f            = shdr.Fields.Add(col.ColumnName + "Hdr", col.ColumnName, rc);
                f.Calculated = false;
                f.ForeColor  = Color.LightGray;
                f.Align      = (col.DataType == typeof(int))
                                        ? FieldAlignEnum.RightBottom
                                        : FieldAlignEnum.LeftBottom;

                // add detail field (note square brackets since field names have spaces)
                rc.Height = (int)sdtl.Height;
                _c1r.Font = new Font("Arial", 9);
                string fldName = string.Format("fld{0}", fldCtr++);
                f            = sdtl.Fields.Add(fldName, "[" + col.ColumnName + "]", rc);
                f.Calculated = true;

                // if this field is numeric, add script
                if (_script)
                {
                    if (col.DataType == typeof(int))
                    {
                        script += string.Format(scriptFmt, fldName);
                    }
                }

                // move on to the next field
                rc.Offset(rc.Width, 0);
            }

            // assign script to detail section OnPrint event
            // (after fields have been evaluated)
            //
            if (_script)
            {
                sdtl.OnPrint = script;
            }

            // save report definition (for debugging only)
            //
            // _c1r.Save(@"c:\test.xml");
        }