Click here to Skip to main content
15,886,714 members
Articles / Database Development / SQL Server

Ready-to-use Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker

Rate me:
Please Sign up or sign in to vote.
4.84/5 (40 votes)
7 Sep 200613 min read 297.8K   4.6K   210  
This paper demonstrates an extensible mass emailing framework (Smart Mass Email SME). The demo implementation uses cutting edge .NET technologies available today such as C#, .NET 2.0, Microsoft® SQL Server 2005 Service Broker, MS Provider Pattern, Enterprise Library January 2006 etc.
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace SmartMassEmail.Entities.Validation
{
   /// <summary>
   /// A List of broken rules.
   /// </summary>
   [Serializable()]
   public class BrokenRulesList : BindingList<BrokenRule>
   {

      /// <summary>
      /// Returns the firstRule <see cref="BrokenRule" /> object
      /// corresponding to the specified property.
      /// </summary>
      /// <param name="property">The name of the property affected by the rule.</param>
      /// <returns>
      /// The firstRule BrokenRule object corresponding to the specified property, or null if 
      /// there are no rules defined for the property.
      /// </returns>
      public BrokenRule GetFirstBrokenRule(string property)
      {
         foreach (BrokenRule item in this)
            if (item.Property == property)
               return item;
         return null;
      }

      /// <summary>
      /// Internal contructor
      /// </summary>
      internal BrokenRulesList()
      {
         // limit creation to this assembly
      }

      /// <summary>
      /// Add a broken rule to the list
      /// </summary>
      /// <param name="rule"><see cref="ValidationRuleInfo"/> object containing the details about the rule.</param>
      internal void Add(ValidationRuleInfo rule)
      {
         Remove(rule);
         Add(new BrokenRule(rule));

      }

      /// <summary>
      /// Removes a broken rule from the list
      /// </summary>
      /// <param name="rule"><see cref="ValidationRuleInfo"/> object containing the details about the rule.</param>
      internal void Remove(ValidationRuleInfo rule)
      {
         
         for (int index = Count - 1; index >= 0; index--)
            if (this[index].RuleName == rule.RuleName)
            {
               RemoveAt(index);
               break;
            }

      }

		/// <summary>
      /// Returns a string containing all of the broken rule descriptions for the specified property.
      /// </summary>
      /// <param name="propertyName">The name of the property to get the errors for.</param>
      /// <returns>String of the error descriptions</returns>
      public string GetPropertyErrorDescriptions(string propertyName)
      {
         System.Text.StringBuilder errorDescription = new System.Text.StringBuilder();
         bool firstRule = true;
         foreach (BrokenRule item in this)
         {
            if (string.IsNullOrEmpty(propertyName) || item.Property.Equals(propertyName))
            {
               if (firstRule)
                  firstRule = false;
               else
                  errorDescription.Append(Environment.NewLine);

               errorDescription.Append(item.Description);
            }
         }

         return errorDescription.ToString();
      }

      /// <summary>
      /// Returns the description of each broken rule separated by a new line.
      /// </summary>
      public override string ToString()
      {
         return GetPropertyErrorDescriptions(null);
      }
   }
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Australia Australia
I have been awarded MVP (Visual C#) for year 2007, 2008, 2009. I am a Microsoft Certified Application Developer (C# .Net). I currently live in Melbourne, Australia. I am a co-founder and core developer of Pageflakes www.pageflakes.com and Founder of Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Simplexhub.
My BLOG http://www.geekswithblogs.net/shahed
http://msmvps.com/blogs/shahed/Default.aspx.

Comments and Discussions