将默认日期时间12:00 AM或12:00 PM覆盖为当前时间?

时间:2016-08-04 09:10:47

标签: customization acumatica

在我的图片中,我有SLA的DateTime和完成日期,而完成日期与SLA的值相同,但它允许用户添加或更改DateTime。当我在完成日期更改日期时间时,它获得默认值时间是12:00 PM或12:00 AM。有没有办法将默认时间更改为当前时间?如果用户更改用户区域设置格式会有什么影响吗?

enter image description here

这是我的UsrFinishDate默认值:

UsrFinishDate(新领域)

 [PXDBDate(PreserveTime = true)]
 [PXUIField(DisplayName="Finish Date")]
protected void CRCase_UsrFinishDate_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
    CRCase row = e.Row as CRCase;
    CRCaseExt rowExt = PXCache<CRCase>.GetExtension<CRCaseExt>(row);

    if (row == null || row.AssignDate == null) return;

    if (row.ClassID != null && row.Severity != null)
    {
        var severity = (CRClassSeverityTime)PXSelect<CRClassSeverityTime,
                       Where<CRClassSeverityTime.caseClassID, Equal<Required<CRClassSeverityTime.caseClassID>>,
                       And<CRClassSeverityTime.severity, Equal<Required<CRClassSeverityTime.severity>>>>>
                       .Select(Base, row.ClassID, row.Severity);
        if (severity != null && severity.TimeReaction != null)
        {
            e.NewValue = row.SLAETA;
            e.Cancel = true;
        }
    }

    if (row.Severity != null && row.ContractID != null)
    {
        var template = (Contract)PXSelect<Contract, Where<Contract.contractID, Equal<Required<CRCase.contractID>>>>.Select(Base, row.ContractID);
        if (template == null) return;

        var sla = (ContractSLAMapping)PXSelect<ContractSLAMapping,
                  Where<ContractSLAMapping.severity, Equal<Required<CRCase.severity>>,
                  And<ContractSLAMapping.contractID, Equal<Required<CRCase.contractID>>>>>
                  .Select(Base, row.Severity, template.TemplateID);
        if (sla != null && sla.Period != null)
        {
            e.NewValue = row.SLAETA;
            e.Cancel = true;
        }
    }
}

这是我的另一个事件rowSelected:

protected void CRCase_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
{
    var row = e.Row as CRCase;
    var oldRow = e.OldRow as CRCase;
    CRCaseExt rowExt = PXCache<CRCase>.GetExtension<CRCaseExt>(row);

    if (row == null || oldRow == null) return;

    if (row.OwnerID == null)
    {
        row.AssignDate = null;
        row.SLAETA = null;
        rowExt.UsrFinishDate = null;
    }
    else if (oldRow.OwnerID == null)
    {
        row.AssignDate = PXTimeZoneInfo.Now;
        if (row == null || row.AssignDate == null) return;

        if (row.ClassID != null && row.Severity != null)
        {
            var severity = (CRClassSeverityTime)PXSelect<CRClassSeverityTime,
                                Where<CRClassSeverityTime.caseClassID, Equal<Required<CRClassSeverityTime.caseClassID>>,
                                And<CRClassSeverityTime.severity, Equal<Required<CRClassSeverityTime.severity>>>>>.
                                Select(Base, row.ClassID, row.Severity);
            if (severity != null && severity.TimeReaction != null)
            {
                row.SLAETA = ((DateTime)row.AssignDate).AddMinutes((int)severity.TimeReaction);
                rowExt.UsrFinishDate = ((DateTime)row.AssignDate).AddMinutes((int)severity.TimeReaction);
            }
        }

        if (row.Severity != null && row.ContractID != null)
        {
            var template = (Contract)PXSelect<Contract, Where<Contract.contractID, Equal<Required<CRCase.contractID>>>>.Select(Base, row.ContractID);
            if (template == null) return;

            var sla = (ContractSLAMapping)PXSelect<ContractSLAMapping,
                              Where<ContractSLAMapping.severity, Equal<Required<CRCase.severity>>,
                              And<ContractSLAMapping.contractID, Equal<Required<CRCase.contractID>>>>>.
                              Select(Base, row.Severity, template.TemplateID);
            if (sla != null && sla.Period != null)
            {
                row.SLAETA = ((DateTime)row.AssignDate).AddMinutes((int)sla.Period);
                rowExt.UsrFinishDate = ((DateTime)row.AssignDate).AddMinutes((int)sla.Period);
            }
        }
    }
}

1 个答案:

答案 0 :(得分:2)

以下是我添加到案例屏幕的字段的定义,请注意我认为可能缺少的PreserveTime = true

public class CRCaseExt : PXCacheExtension<PX.Objects.CR.CRCase>
{
    #region UsrFinishDate

    [PXDBDate(PreserveTime = true)]
    [PXUIField(DisplayName = "Finish Date")]
    public virtual DateTime? UsrFinishDate { get; set; }
    public abstract class usrFinishDate : IBqlField { }

    #endregion
}

这是一种简单的方法来设置UsrFinishDate值更改时的当前时间。不要忘记为该字段设置CommitChanges

protected virtual void CRCase_UsrFinishDate_FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
{
    CRCase currentCase = (CRCase)e.Row;
    var caseExt = PXCache<CRCase>.GetExtension<CRCaseExt>(currentCase);
    if (caseExt == null)
    {
        return;
    }

    e.NewValue = new DateTime(caseExt.UsrFinishDate.Value.Year,
                                                caseExt.UsrFinishDate.Value.Month,
                                                caseExt.UsrFinishDate.Value.Day,
                                                DateTime.Now.Hour,
                                                DateTime.Now.Minute,
                                                DateTime.Now.Second);
}