我有一个与 CRM DateTime 问题有关的问题。在机会表单中具有自定义日期时间字段(投标提交日期),该字段显示在“仅日期”格式上。以及其他字符串字段(Tender Date),用于在 Tender 提交日期更改时修改日期。假设... 投标日期是 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:00am
程序返回28/06/2012(错误,应该是 29/06/2012)
第二种情况
投标提交日期为 1/08/2012 12:00:00am
程序返回32/07/2012(错误,应该是 1/08/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
}