Esempio n. 1
0
        public void Button1_Click(object sender, EventArgs e)
        {
            DataTable Parent = new DataTable("P");

            Parent.Columns.Add(new DataColumn("id", typeof(int)));
            Parent.Columns.Add(new DataColumn("description", typeof(string)));

            DataTable Child = new DataTable("C"); //TableName is mandatory

            Child.Columns.Add(new DataColumn("id", typeof(int)));
            Child.Columns.Add(new DataColumn("parentID", typeof(int)));
            Child.Columns.Add(new DataColumn("description", typeof(string)));

            DataTable GrandChild = new DataTable("GRCH"); //TableName is mandatory

            GrandChild.Columns.Add(new DataColumn("id", typeof(int)));
            GrandChild.Columns.Add(new DataColumn("parentID", typeof(int)));
            GrandChild.Columns.Add(new DataColumn("description", typeof(string)));

            Parent.Rows.Add(new object[] { "1", "Parent 1" });
            Parent.Rows.Add(new object[] { "2", "Parent 2" });
            Parent.Rows.Add(new object[] { "3", "Parent 3" });

            Child.Rows.Add(new object[] { "1", "1", "Parent 1 Child 1" });
            Child.Rows.Add(new object[] { "2", "1", "Parent 1 Child 2" });
            Child.Rows.Add(new object[] { "3", "1", "Parent 1 Child 3" });

            Child.Rows.Add(new object[] { "4", "2", "Parent 2 Child 1" });
            Child.Rows.Add(new object[] { "5", "2", "Parent 2 Child 2" });
            Child.Rows.Add(new object[] { "6", "2", "Parent 2 Child 3" });

            GrandChild.Rows.Add(new object[] { "1", "1", "Parent 1 Child 1 Grand Child 1" });
            GrandChild.Rows.Add(new object[] { "2", "1", "Parent 1 Child 1 Grand Child 2" });
            GrandChild.Rows.Add(new object[] { "3", "1", "Parent 1 Child 1 Grand Child 3" });

            DocumentCreator dc = new DocumentCreator();

            dc.ScanStart += new ScanStartEventHandler(Dc_ScanStart);
            dc.AddDataTable(Parent);
            dc.AddDataTable(Child);
            dc.AddDataTable(GrandChild);
            dc.CreateDocument(_inputPath, _outputPath);

            if (!_unitTest)
            {
                Process.Start(_outputPath);
            }
        }
Esempio n. 2
0
        public void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                //Create a Dataset containing the required tables.
                DataSet MyData = LoadData();

                //DocumentCreator represents the API to the NTemplates engine, so we need to instantiate it
                dc = new DocumentCreator();

                //We need to make the DocumentCreator instance aware of the tables by ccalling the AddDataTable method
                //for each need table.
                foreach (DataTable dt in MyData.Tables)
                {
                    dc.AddDataTable(dt);
                }

                //We'are handling some events, so we need to define some event handlers
                dc.BeforeScanRecord += new BeforeScanRecordEventHandler(Dc_BeforeScanRecord);
                dc.ScanEnded        += new ScanEndedEventHandler(Dc_ScanEnded);

                //By calling the Add<Type> methods of DocumentCreator, we add variables to the
                //document creator memory space. We can use those for showing values in the report
                //itself or, we can use them for internal calculations.
                dc.AddDateTime("invDate", DateTime.Parse(_invoiceDate)); //Invoice date
                dc.AddDouble(_extprice, 0);                              //Line total (price * units)
                dc.AddDouble(_subtotal, 0);                              //Sum of all extPrices
                dc.AddDouble(_taxes, 0);                                 //Asume this is a calculated result
                dc.AddDouble(_total, 0);                                 // subtotal + taxes

                dc.AddString("title", "Powered by NTemplates");
                dc.AddString("address", "http://ntemplates.codeplex.com");

                //Finally, we command to create the document using one of the CreateDocument method overloads.
                //In this case, we are picking a template from a physical file on disc and generating the report
                //to a physical file too.

                dc.CreateDocument(_inputPath, _outputPath);
                if (!_unitTest)
                {
                    System.Diagnostics.Process.Start(_outputPath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }