Показать сообщение отдельно
Старый 12.05.2009, 17:47   #31  
Elka is offline
Elka
Участник
Аватар для Elka
 
431 / 22 (1) +++
Регистрация: 02.12.2008
Адрес: г. Ростов-на-Дону
Цитата:
Сообщение от a33ik Посмотреть сообщение
Каст - немного другое. Код плагина выкладывайте - плдскажу, где проблема.

Спасибо Вам большое !!

Вот код:

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
{
publicclassMyPlugin : IPlugin
{
privatestring _secureInformation;
privatestring _unsecureInformation;
public MyPlugin(string unsecureInfo, string secureInfo)
{
_secureInformation = secureInfo;
_unsecureInformation = unsecureInfo;
}
publicvoid Execute(IPluginExecutionContext context)
{
DynamicEntity entity = null;
if (context.InputParameters.Properties.Contains(ParameterName.Target) && context.InputParameters.Properties[ParameterName.Target] isDynamicEntity)
{
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 = newColumnSet();
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 = newQueryByAttribute();
query.ColumnSet =
newAllColumns();
query.EntityName =
EntityName.productpricelevel.ToString();
query.Attributes =
newstring[] { "productidname" };
query.Values =
newstring[] { new_productname };
BusinessEntityCollection retrieved = crmService.RetrieveMultiple(query);
foreach (DynamicEntity product in retrieved.BusinessEntities)
{
product[
"amount"] = newCrmDecimal(sum);
crmService.Update(product);
}
}
catch (System.Web.Services.Protocols.SoapException ex)
{
thrownewInvalidPluginExecutionException(String.Format("An error occurred in the {0} plug-in.", this.GetType().ToString()), ex);
}
}
}
}