Click here to Skip to main content
15,886,724 members
Articles / Productivity Apps and Services / Microsoft Office

XML/XSLT Word Report Generator

Rate me:
Please Sign up or sign in to vote.
3.80/5 (6 votes)
11 Jan 2009CPOL4 min read 123.3K   2.6K   84  
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.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WordReportGenerator
{
   /// <summary>
   /// ������� ��� ��������� ����������� ������������ �������
   /// </summary>
   [AttributeUsage(AttributeTargets.Property, Inherited = true)]
   class DynamicPropertyFilterAttribute : Attribute
   {
      string _propertyName;

      /// <summary>
      /// �������� ��������, �� �������� ����� �������� ���������  
      /// </summary>
      public string PropertyName
      {
         get { return _propertyName; }
      }

      string _showOn;

      /// <summary>
      /// �������� �������� �� �������� ������� ��������� 
      /// (����� �������, ���� ���������), ��� ������� ��������, �
      /// �������� �������� �������, ����� ������. 
      /// </summary>
      public string ShowOn
      {
         get { return _showOn; }
      }

      /// <summary>
      /// �����������  
      /// </summary>
      /// <param name="propName">�������� ��������, �� �������� ����� �������� ���������</param>
      /// <param name="value">�������� ��������, ����� �������, ���� ���������, ��� ������� ��������, �
      /// �������� �������� �������, ����� ������.</param>
      public DynamicPropertyFilterAttribute(string propName, string value)
      {
         _propertyName = propName;
         _showOn = value;
      }
   }

   /// <summary>
   /// ������� ����� ��� ��������, �������������� ������������ 
   /// ����������� ������� � PropertyGrid
   /// </summary>
   public class FilterablePropertyBase : ICustomTypeDescriptor
   {

      protected PropertyDescriptorCollection
      GetFilteredProperties(Attribute[] attributes)
      {
         PropertyDescriptorCollection pdc
         = TypeDescriptor.GetProperties(this, attributes, true);
         PropertyDescriptorCollection finalProps = 
            new PropertyDescriptorCollection(new PropertyDescriptor[0]);

         foreach (PropertyDescriptor pd in pdc)
         {
            bool include = false;
            bool Dynamic = false;
            foreach (Attribute a in pd.Attributes)
            {
               if (a is DynamicPropertyFilterAttribute)
               {
                  Dynamic = true;

                  DynamicPropertyFilterAttribute
                  dpf = (DynamicPropertyFilterAttribute)a;
                  PropertyDescriptor temp = pdc[dpf.PropertyName];

                  if (dpf.ShowOn.IndexOf(temp.GetValue(this).ToString()) > -1)
                  {
                     include = true;
                  }
               }
            }

            if (!Dynamic || include)
               finalProps.Add(pd);
         }

         return finalProps;
      }

      #region ICustomTypeDescriptor Members

      public TypeConverter GetConverter()
      {
         return TypeDescriptor.GetConverter(this, true);
      }

      public EventDescriptorCollection GetEvents(Attribute[] attributes)
      {
         return TypeDescriptor.GetEvents(this, attributes, true);
      }

      EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
      {
         return TypeDescriptor.GetEvents(this, true);
      }

      public string GetComponentName()
      {
         return TypeDescriptor.GetComponentName(this, true);
      }

      public object GetPropertyOwner(PropertyDescriptor pd)
      {
         return this;
      }

      public AttributeCollection GetAttributes()
      {
         return TypeDescriptor.GetAttributes(this, true);
      }

      public PropertyDescriptorCollection GetProperties(
         Attribute[] attributes)
      {
         return GetFilteredProperties(attributes);
      }

      PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
      {
         return GetFilteredProperties(new Attribute[0]);
      }

      public object GetEditor(Type editorBaseType)
      {
         return TypeDescriptor.GetEditor(this, editorBaseType, true);
      }

      public PropertyDescriptor GetDefaultProperty()
      {
         return TypeDescriptor.GetDefaultProperty(this, true);
      }

      public EventDescriptor GetDefaultEvent()
      {
         return TypeDescriptor.GetDefaultEvent(this, true);
      }

      public string GetClassName()
      {
         return TypeDescriptor.GetClassName(this, true);
      }

      #endregion

   }

}

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)


Written By
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

Comments and Discussions