DynamicEntity postImageEntity = (DynamicEntity)context.PostEntityImages["PostImage"]; if (postImageEntity != null)
{ Guid new_accountId = Guid.Empty;
decimal new_book_credit = 0M;
CrmDateTime new_expiry_date = new CrmDateTime(DateTime.Now.ToString()); int new_status = ; //状态
if (postImageEntity.Properties.Contains("new_status"))
{
new_status = ((Picklist)postImageEntity.Properties["new_status"]).Value;
} //经销商GUID
if (postImageEntity.Properties.Contains("new_account"))
{
new_accountId = ((Lookup)postImageEntity.Properties["new_account"]).Value;
} decimal new_credit_line = 0M;
decimal new_remaining_credits = 0M; //ColumnSet cols = new ColumnSet(new string[] { "new_credit_line", "new_remaining_credits" });
//account acc_entity = (account)crmService.Retrieve("account", new_accountId, cols);//这里和CRM2011不一样,
返回的为BusinessEntity,并且这里只能取account得系统字段的值。 //查询条件
QueryExpression query = new QueryExpression();
query.EntityName = "account";
query.ColumnSet = new ColumnSet();
query.ColumnSet.AddColumns(new string[] { "new_credit_line", "new_remaining_credits" }); //条件表达式
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "accountid";
condition.Values = new string[] { new_accountId.ToString() }; //筛选
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions.Add(condition);
query.Criteria.Filters.Add(filter); //查询
RetrieveMultipleRequest request = new RetrieveMultipleRequest();
request.Query = query;
request.ReturnDynamicEntities = true; //响应
RetrieveMultipleResponse response = (RetrieveMultipleResponse)crmService.Execute(request);
BusinessEntityCollection entityCollection = response.BusinessEntityCollection; if (entityCollection.BusinessEntities.Count == ) return; DynamicEntity acc_entity = (DynamicEntity)entityCollection.BusinessEntities[]; //期初信用额度
if (acc_entity.Properties.Contains("new_credit_line"))
{
new_credit_line = cu.RoundDecimal(((CrmMoney)acc_entity.Properties["new_credit_line"]).Value);
} //剩余信用额度
if (acc_entity.Properties.Contains("new_remaining_credits"))
{
new_remaining_credits = cu.RoundDecimal(((CrmMoney)acc_entity.Properties["new_remaining_credits"]).Value);
} cu.WriteLog("new_remaining_credits:" + new_remaining_credits);
//赊销额度
if (postImageEntity.Properties.Contains("new_book_credit"))
{
new_book_credit = cu.RoundDecimal(((CrmMoney)postImageEntity.Properties["new_book_credit"]).Value);
}
cu.WriteLog("new_book_credit:" + new_book_credit);
//赊销变更效期
if (postImageEntity.Properties.Contains("new_expiry_date"))
{
new_expiry_date = ((CrmDateTime)postImageEntity.Properties["new_expiry_date"]);
} DynamicEntity accountEntity = new DynamicEntity("account"); if (!string.IsNullOrEmpty(new_book_credit.ToString()))
{
//信用额度
accountEntity.Properties.Add(new CrmMoneyProperty("new_credit_line", new CrmMoney(cu.RoundDecimal(new_book_credit))));
} if (!string.IsNullOrEmpty(new_expiry_date.ToString()))
{
//信用额度截止日期
accountEntity.Properties.Add(new CrmDateTimeProperty("new_expiration_date", new_expiry_date));
} decimal totalnew_credit_line = 0M;
decimal totalnew_remaining_credits = 0M; if (string.IsNullOrEmpty(new_credit_line.ToString()))
{
new_credit_line = 0M;
} if (string.IsNullOrEmpty(new_book_credit.ToString()))
{
new_book_credit = 0M;
} //经销商【期初信用额度】= 起初的经销商【期初信用额度】 + 【赊销额度】
totalnew_credit_line = new_credit_line + new_book_credit; //经销商【剩余信用额度】= 起初的经销商【剩余信用额度】 + 【赊销额度】
totalnew_remaining_credits = new_remaining_credits + new_book_credit; //期初信用额度
accountEntity.Properties.Add(new CrmMoneyProperty("new_credit_line", new CrmMoney(totalnew_credit_line))); //剩余信用额度
accountEntity.Properties.Add(new CrmMoneyProperty("new_remaining_credits", new CrmMoney(totalnew_remaining_credits))); if (new_accountId != Guid.Empty)
{
accountEntity.Properties.Add(new KeyProperty("accountid", new Key(new_accountId)));
} if (new_status == )
{
crmService.Update(accountEntity);//更新操作
}
}