Eric's Blog

有需求才有进步

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;

namespace IS
{
    public class AccountPreCreate: IPlugin
    {
       public void Execute(IPluginExecutionContext context)
       {
           // Verify we have an entity to work with
           if (context.InputParameters.Properties.Contains("Target") &&              context.InputParameters.Properties["Target"] is DynamicEntity)
           {
              // Obtain the target business entity from the input parmameters.
              DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties["Target"];
              // Verify that the entity represents an account.
              if (entity.Name == EntityName.account.ToString())
              {
                  // Generate a new Account Number
                  Random rndgen = new Random();
                  StringProperty accountNumber = new StringProperty("accountnumber", rndgen.Next().ToString());
                  entity.Properties.Add(accountNumber);
              }
           }
       }
    }
}
posted on 2008-03-31 20:46  Eric.Chai  阅读(196)  评论(0编辑  收藏  举报