AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Разработка
CRM
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 08.05.2009, 12:17   #15  
a33ik is offline
a33ik
Чайный пьяница
Аватар для a33ik
MCP
MCBMSS
Злыдни
Соотечественники
Most Valuable Professional
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
3,243 / 896 (36) +++++++
Регистрация: 02.07.2008
Адрес: Greenville, SC
Lightbulb
Подчистил код плагина. Попробуйте это:

Код:
using System;
using System.Collections.Generic;
using Microsoft.Win32;
using Microsoft.Crm.Sdk.Query;
// Microsoft Dynamics CRM namespaces
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.SdkTypeProxy.Metadata;
using System.Text;
namespace Crm.Plugins
{
    public class MyPlugin : IPlugin
    {
        private string _secureInformation;
        private string _unsecureInformation;
        public MyPlugin(string unsecureInfo, string secureInfo)
        {
            _secureInformation = secureInfo;
            _unsecureInformation = unsecureInfo;
        }
        public void Execute(IPluginExecutionContext context)
        {
            DynamicEntity entity = null;
            if (context.InputParameters.Properties.Contains(ParameterName.Target) && context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)
            {
                entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
            }
            else
            {
                return;
            }

            try
            {
                ICrmService crmService = context.CreateCrmService(true);

                decimal sum = ((CrmMoney)entity.Properties["new_esum"]).Value;
                String new_productname = "";

                if (entity.Properties.Contains("productid"))
                {
                    ColumnSet cs = new ColumnSet();
                    Lookup regarding = (Lookup)entity.Properties["productid"];
                    cs.Attributes.Add("name");
                    product _product = (product)crmService.Retrieve(EntityName.product.ToString(), regarding.Value, cs);
                    if (_product == null || _product.name == null)
                    {
                        return;
                    }
                    else
                    {
                        new_productname = _product.name;
                    }
                }

                QueryByAttribute query = new QueryByAttribute();
                query.ColumnSet = new AllColumns();
                query.EntityName = EntityName.productpricelevel.ToString();
                query.Attributes = new string[] { "productidname" };
                query.Values = new string[] { new_productname };

                BusinessEntityCollection retrieved = crmService.RetrieveMultiple(query);

                foreach (DynamicEntity product in retrieved.BusinessEntities)
                {
                    product["amount"] = new CrmDecimal(sum);
                    crmService.Update(product);
                }
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                throw new InvalidPluginExecutionException(String.Format("An error occurred in the {0} plug-in.", this.GetType().ToString()), ex);
            }
        }
    }
}
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством.

Подписывайтесь на мой блог, twitter и YouTube канал.
Пользуйтесь моим Ultimate Workflow Toolkit
Теги
c#, plugin, pluginregistrationtool, регистрация

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
CRM DE LA CREME! Three Top Tips for CRM 4.0 Plugin Development Blog bot Dynamics CRM: Blogs 0 13.08.2009 15:05
haditeo: Is it possible to register different event handlers in only one assembly to be registered in Dynamics CRM Plugin ? Blog bot Dynamics CRM: Blogs 0 13.08.2009 15:05
a33ik: Plugin for copying notes and attachements from lead to contact whis is converted from lead for Microsoft Dynamics CRM 4.0 Blog bot Dynamics CRM: Blogs 0 10.07.2009 17:05
Ronald Lemmen: Plugin registration tools for Visual Studio 2005 Blog bot Dynamics CRM: Blogs 0 17.04.2009 01:05
PlugIn ImageEntity Konstantin Katsovich Dynamics CRM: Разработка 3 16.01.2009 17:35

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 18:13.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.