У меня вопрос, связанный с проблемой CRM DateTime. В форме возможности есть настраиваемое поле DateTime (Дата подачи тендера), которое отображается в форме «Только дата». И другое строковое поле (Дата тендера), которое изменяет дату при изменении даты подачи тендера. Допустим... Дата подачи тендера 29.06.2011 12:00:00 Дата тендера должна быть 29.06.2012
Я создаю плагин для Create Post-operation и Update Pre-operation. Я извлекаю TenderSubDate.Day, Month и Year.
Часовой пояс Crm: (GMT+08:00) Куала-Лумпур, Сингапур, затем хочу изменить (GMT-06:00) центральное время (США и Канада).
Проблема в том, что когда я обновляю дату тендера на основе даты подачи тендера, программа возвращает на один день меньше или больше, чем дополнительная дата тендера. Скажем..
Первый секнарио
Дата подачи тендерных предложений 29.06.2012 12:00:00.
Программа возвращает 28/06/2012(ошибочно, должно быть 29/06/2012)
Второй секнарио
Дата подачи тендерных предложений 08.01.2012 12:00:00.
Программа возвращает 32/07/2012 (ошибочно, должно быть 08/01/2012)
что мне делать в моей программе. пожалуйста, дайте мне некоторое представление. Вот мой код плагина
public class TenderSubDateChange : IPlugin
{
#region Class Level Variables
//IServiceProvider _serviceProvider;
//IOrganizationServiceFactory _serviceFactory = null;
//IOrganizationService _service = null;
//IPluginExecutionContext _context = null;
Entity _target = null;
Entity _preImage = null;
Entity _postImage = null;
Guid _currentUser;
#endregion
#region IPlugin Members
public void Execute(IServiceProvider serviceProvider)
{
try
{
string message = null;
IPluginExecutionContext _context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
#region Organization Services
// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(_context.UserId);
#endregion
var ServiceContext = new OrganizationServiceContext(service);
_currentUser = _context.UserId;
message = _context.MessageName.ToLower();
if (message == "create")//message == "create" ||
{
if (_context.InputParameters.Contains("Target") && _context.InputParameters["Target"] != null)
_target = (Entity)_context.InputParameters["Target"];
if (_context.PreEntityImages.Contains("PreImage") && _context.PreEntityImages["PreImage"] != null)
_preImage = (Entity)_context.PreEntityImages["PreImage"];
if (_context.PostEntityImages.Contains("PostImage") && _context.PostEntityImages["PostImage"] != null)
_postImage = (Entity)_context.PostEntityImages["PostImage"];
DateTime hm_tenderdate;
if (_target.Attributes.Contains("hm_tendersubmissiondate"))
{
hm_tenderdate = (DateTime)_target.Attributes["hm_tendersubmissiondate"];
_target.Attributes["hm_tendersubdate"] = (hm_tenderdate.Day) + "/" + hm_tenderdate.Month + "/" + hm_tenderdate.Year;
service.Update(_target);
}
}
if (message == "update")//message == "create" ||
{
if (_context.InputParameters.Contains("Target") && _context.InputParameters["Target"] != null)
_target = (Entity)_context.InputParameters["Target"];
if (_context.PreEntityImages.Contains("PreImage") && _context.PreEntityImages["PreImage"] != null)
_preImage = (Entity)_context.PreEntityImages["PreImage"];
if (_context.PostEntityImages.Contains("PostImage") && _context.PostEntityImages["PostImage"] != null)
_postImage = (Entity)_context.PostEntityImages["PostImage"];
DateTime hm_tenderdate;
if (_target.Attributes.Contains("hm_tendersubmissiondate"))
{
hm_tenderdate = (DateTime)_target.Attributes["hm_tendersubmissiondate"];
_target.Attributes["hm_tendersubdate"] = (hm_tenderdate.Day) + "/" + hm_tenderdate.Month + "/" + hm_tenderdate.Year;
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message, ex);
}
}
#endregion
}