Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

XML/XSLT Word Report Generator

, 11 Jan 2009 CPOL
The tool is based on XML/XSLT, and allows a user to create a Word report from scratch, namely: construct SQL query, construct a WordML template, generate a document.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

using Shchurov.SqlWrapper;

namespace WordReportGenerator
{
    public class DAL : DataAccessLayerBase
    {
        public DM dm { get { return (DM)GetWrapped(); } }

        public DataSet ds = new DataSet();
        private int oid;

        //wordreports
        public Boolean init_wordreports = true;
        private Boolean isNewwordreports = false;
        private List<int> del_wordreports;
        public DataTable dt_wordreports;
        public BindingSource bs_wordreports;
        public DataRowView cwordreports
        {
            get { return (DataRowView)bs_wordreports.Current; }
        }

        public DAL() { }

        public void Fill(string dataMember)
        {
            if (init_wordreports)
            {
                dt_wordreports = new DataTable("dt_wordreports");
                del_wordreports = new List<int>();
            }

            dt_wordreports.Clear();
            dt_wordreports.Load(dm.SelectWordreports(0).CreateDataReader());
            if (init_wordreports)
            {
                dt_wordreports.Columns.Add("Ins", typeof(byte));
                dt_wordreports.Columns.Add("Upd", typeof(byte));

                ds.Tables.Add(dt_wordreports);
                bs_wordreports = new BindingSource(ds, "dt_wordreports");
                dt_wordreports.RowDeleting += new DataRowChangeEventHandler(dt_wordreports_RowDeleting);
                bs_wordreports.AddingNew += new System.ComponentModel.AddingNewEventHandler(bs_wordreports_AddingNew);
                bs_wordreports.PositionChanged += new EventHandler(bs_wordreports_PositionChanged);
                bs_wordreports.ListChanged += new System.ComponentModel.ListChangedEventHandler(bs_wordreports_ListChanged);
                init_wordreports = false;
            }
        }

        private void dt_wordreports_RowDeleting(object sender, DataRowChangeEventArgs e)
        {
            int oid;
            oid = e.Row["oid"].Equals(DBNull.Value) ? 0 : (Int32)e.Row["oid"];
            if (oid > 0)
                del_wordreports.Add(oid);
        }
        private void bs_wordreports_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
        {
            if (e.ListChangedType == System.ComponentModel.ListChangedType.ItemChanged && !isNewwordreports)
            {
                cwordreports["Upd"] = 1;
            }
        }
        private void bs_wordreports_PositionChanged(object sender, EventArgs e)
        {
            if (isNewwordreports)
            {
                cwordreports["Ins"] = 1;
                isNewwordreports = false;
            }
        }
        private void bs_wordreports_AddingNew(object sender, System.ComponentModel.AddingNewEventArgs e)
        {
            isNewwordreports = true;
        }

        public void Update(string dataMember)
        {
            dm.AutoCloseConnection = false;
            foreach (DataRowView drv in bs_wordreports)
            {
                if (!drv["Ins"].Equals(DBNull.Value) && (byte)drv["Ins"] == 1)
                {
                    oid = -1;
                    dm.InsertUpdateWordreports(ref oid,
                                            drv["isupdate"],
                                            drv["sql"].ToString(),
                                            drv["title"].ToString(),
                                            drv["wml"].ToString(),
                                            drv["xmlalias"].ToString(),
                                            drv["xmlfilename"].ToString(),
                                            drv["xmlns"].ToString(),
                                            drv["xsd"].ToString(),
                                            drv["xslt"].ToString());
                    drv["oid"] = oid;
                    drv["Ins"] = 0;
                }
                else if (!drv["Upd"].Equals(DBNull.Value) && (byte)drv["Upd"] == 1)
                {
                    oid = (Int32)drv["oid"];
                    dm.InsertUpdateWordreports(ref oid,
                                            drv["isupdate"],
                                            drv["sql"].ToString(),
                                            drv["title"].ToString(),
                                            drv["wml"].ToString(),
                                            drv["xmlalias"].ToString(),
                                            drv["xmlfilename"].ToString(),
                                            drv["xmlns"].ToString(),
                                            drv["xsd"].ToString(),
                                            drv["xslt"].ToString());
                    drv["Upd"] = 0;
                }
            }
            dm.AutoCloseConnection = true;
            try
            {
                foreach (int id in this.del_wordreports)
                    dm.DeleteWordreports(id);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            this.del_wordreports.Clear();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sam Safonov
Software Developer
Russian Federation Russian Federation
I have Master degree in Particle Physics. During my last several years I work as software developer.
 
Primary Interests
- c#, c++, php, java.
- scientific programming

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 11 Jan 2009
Article Copyright 2009 by Sam Safonov
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid