Добрый день. Подскажите пожалуйста. У меня такая задача : есть мой объект new_platpor, который является дочерним от счета (invoice). На форме объета new_platpor есть поле new_chet (это и есть родительский счет). Хочу найти все new_platpor, у которых родительским является один и тот же счет, просуммировать их суммы (new_summa) и вывести на форму счета в поле (plsum). При этом ,если эта сумма превысит общую сумму счета, то поругаться и не сохранить мой new_platpor.
1. Регистрировать плагин на создание new_platpor?
2. Как отменить сохранение new_platpor и поругаться ?
3. Большие сомнения как найти мои объекты с одинаковыми счетами .. Я пытаюсь считать из поля new_chet номер, счета, а потом найти все new_platpor, которые ссылаютя на счета с таким номером..
4. Не знаю как правильно обращаться к своим объектам..Visual Studio ругается
Текст всего этого безобразия, пока выглядит так :
try
{
ICrmService crmService = context.CreateCrmService(true);
decimal sum = ((CrmMoney)entity.Properties["new_summa"]).Value;
String new_invoicenumber = "";
decimal itog ;
if (entity.Properties.Contains("new_chet"))
{
ColumnSet cs = new ColumnSet();
Lookup regarding = (Lookup)entity.Properties["new_chet"];
cs.Attributes.Add("invoicenumber");
invoice _invoice = (invoice)crmService.Retrieve(EntityName.invoice.ToString(), regarding.Value, cs);
if (_invoice == null || _invoice.invoicenumber == null)
{
return;
}
else
{
new_invoicenumber = _invoice.invoicenumber;
}
}
QueryByAttribute query = new QueryByAttribute();
query.ColumnSet = new AllColumns();
query.EntityName = EntityName.new_platpor.ToString();
query.Attributes = new string[] { "new_chet" };
query.Values = new string[] { new_invoicenumber };
BusinessEntityCollection retrieved = crmService.RetrieveMultiple(query);
itog= 0;
foreach (new_platpor oplata in retrieved.BusinessEntities)
{
itog = oplata.new_sum + itog;
// crmService.Update(oplata);
}
sum=sum + itog;
//______________________________________
QueryByAttribute mquery = new QueryByAttribute();
mquery.ColumnSet = new AllColumns();
mquery.EntityName = EntityName.invoice.ToString();
mquery.Attributes = new string[] { "invoicenumber" };
mquery.Values = new string[] { new_invoicenumber };
BusinessEntityCollection mretrieved = crmService.RetrieveMultiple(query);
foreach (invoice inv in mretrieved.BusinessEntities)
{
if ((decimal)inv.totalamount.Value < sum) {
// надо как-то поругаться..и не дать сохранить
}
((CrmMoney)entity.Properties["plsum"]).Value=sum;
crmService.Update(inv);
}
//________________________________________
}