Click here to Skip to main content
12,293,601 members (59,768 online)
Click here to Skip to main content

Stats

84.6K views
2.3K downloads
82 bookmarked
Posted

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.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)

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

You may also be interested in...

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