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
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.ComponentModel;
using System.Text;

namespace WordReportGenerator
{

   public class PropertySorter : ExpandableObjectConverter
   {
      #region ������
      public override bool GetPropertiesSupported(ITypeDescriptorContext context)
      {
         return true;
      }

      /// <summary>
      /// ���������� ������������� ������ �������
      /// </summary>
      public override PropertyDescriptorCollection GetProperties(
         ITypeDescriptorContext context, object value, Attribute[] attributes)
      {
         PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(value, attributes);
         ArrayList orderedProperties = new ArrayList();
         foreach (PropertyDescriptor pd in pdc)
         {
            Attribute attribute = pd.Attributes[typeof(PropertyOrderAttribute)];
            if (attribute != null)
            {
               // ������� ���� - ���������� ����� �/� �� ����
               PropertyOrderAttribute poa = (PropertyOrderAttribute)attribute;
               orderedProperties.Add(new PropertyOrderPair(pd.Name, poa.Order));
            }
            else
            {
               // �������� ��� - ������� ��� 0
               orderedProperties.Add(new PropertyOrderPair(pd.Name, 0));
            }
         }

         // ��������� �� Order-�
         orderedProperties.Sort();

         // ��������� ������ ���� �������
         ArrayList propertyNames = new ArrayList();
         foreach (PropertyOrderPair pop in orderedProperties)
         {
            propertyNames.Add(pop.Name);
         }

         // ����������
         return pdc.Sort((string[])propertyNames.ToArray(typeof(string)));
      }
      #endregion
   }

   #region PropertyOrder Attribute
   /// <summary>
   /// ������� ��� ������� ����������
   /// </summary>
   [AttributeUsage(AttributeTargets.Property)]
   public class PropertyOrderAttribute : Attribute
   {
      private int _order;
      public PropertyOrderAttribute(int order)
      {
         _order = order;
      }

      public int Order
      {
         get { return _order; }
      }
   }
   #endregion

   #region PropertyOrderPair
   /// <summary>
   /// ���� ���/����� �/� � ����������� �� ������
   /// </summary>
   public class PropertyOrderPair : IComparable
   {
      private int _order;
      private string _name;
      public string Name
      {
         get { return _name; }
      }

      public PropertyOrderPair(string name, int order)
      {
         _order = order;
         _name = name;
      }

      /// <summary>
      /// ���������� ����� ���������
      /// </summary>
      public int CompareTo(object obj)
      {
         int otherOrder = ((PropertyOrderPair)obj)._order;
         if (otherOrder == _order)
         {
            // ���� Order ���������� - ��������� �� ������
            string otherName = ((PropertyOrderPair)obj)._name;
            return string.Compare(_name, otherName);
         }
         else if (otherOrder > _order)
         {
            return -1;
         }
         return 1;
      }
   }
   #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)

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 | Mobile
Web01 | 2.8.140721.1 | Last Updated 11 Jan 2009
Article Copyright 2009 by Sam Safonov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid