Показать сообщение отдельно
Старый 07.05.2009, 17:31   #10  
Elka is offline
Elka
Участник
Аватар для Elka
 
431 / 22 (1) +++
Регистрация: 02.12.2008
Адрес: г. Ростов-на-Дону
Спасибо большое за ссылки... У меня есть еще 2 вопроса ():
1)не знаю как получить значение из моего поля new_esum
2)Если я правильно понимаю , то BusinessEntityCollection retrieved = service.RetrieveMultiple(query);
в retrieved я получаю все позиции прайс-листа с нужным мне значением продукта.. как можно перебрать эти позиции() и присвоить им новое значение amount





publicvoid Execute(IPluginExecutionContext context)
{
DynamicEntity entity = null;
if (context.InputParameters.Properties.Contains(ParameterName.Target) &&
context.InputParameters.Properties[
ParameterName.Target] isDynamicEntity)
{
// Obtain the target business entity from the input parmameters.
entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
//______________________________
if (context.MessageName != MessageName.Update.ToString()
&& context.MessageName !=
MessageName.Create.ToString())
{
thrownewInvalidPluginExecutionException("Smth wrong with Update stage may be");
}
//___________________________
}
else
{
return;
}
try
{

ICrmService crmService = context.CreateCrmService(true);
//_________________________________________________________
//пытаюсь получить значение из моего поля new_esum (тип money)---
//
float sum = (float)entity.Properties["new_esum"];
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.ToString();
}
}
//ищу нужную позицию в прайс-листе
CrmService service = newCrmService();
service.Credentials = System.Net.
CredentialCache.DefaultCredentials;
// Create the query object.
QueryByAttribute query = newQueryByAttribute();
query.ColumnSet =
newAllColumns();
query.EntityName =
EntityName.productpricelevel.ToString();
// The query will retrieve all productpricelevel whose productidname is new_productname.
query.Attributes = newstring[] { "productidname" };
query.Values =
newstring[] { new_productname };
// Execute the retrieval.
// если правильно понимаю, получила все позиции прайс-листа с продуктом
//равным new_productname
BusinessEntityCollection retrieved = service.RetrieveMultiple(query);
// не знаю как перебрать значения и присвоить значение sum
// ((((
retrieved.Properties.Add(newStringProperty("amount", sum));



}