none
CrmDateTime这个类型到底该怎么用? RRS feed

  • 问题

  • 我现在有2个CrmDateTime时间类型,我想再工作流里面相减,请问到底该怎么操作呢?具体代码如下?请大家帮我指正:
     [CrmWorkflowActivity("The Exist Time", "Check")]
        public  partial class wfLeadTest : SequenceActivity
        {
            public static DependencyProperty CreatTimeProperty = DependencyProperty.Register("CreatTime", typeof(CrmDateTime), typeof(wfLeadTest));

            [CrmInput("CreatTime")]
            [CrmDefault("1900-1-1")]
            public CrmDateTime CreatTime
            {
                get { return (CrmDateTime)GetValue(CreatTimeProperty); }
                set { SetValue(CreatTimeProperty, value); }
            }
            public static DependencyProperty ResultProperty = DependencyProperty.Register("Result", typeof(CrmNumber), typeof(wfLeadTest));

            [CrmOutput("Result")]
            public CrmNumber Result
            {
                get { return (CrmNumber)GetValue(ResultProperty); }
                set { SetValue(ResultProperty, value); }
            }

            /// <summary>
            /// The Execute method is called by the workflow runtime to execute an activity.
            /// </summary>
            /// <param name="executionContext"> The context for the activity</param>
            /// <returns></returns>
            protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
            {
                TimeSpan ts = Convert.ToDateTime(CrmDateTime.Now.Value) - Convert.ToDateTime(this.CreatTime.Value);
                this.Result = new CrmNumber(Convert.ToInt32(ts.Days.ToString()));
                return ActivityExecutionStatus.Closed;
            }


    梅小虎
    2009年4月9日 8:52

答案

  • 改成以下看看:

    TimeSpan ts = DateTime.Now - this.CreatTime.Value;
    this.Result = new CrmNumber(ts.Days);



    Darren Liu | 刘嘉鸿 | MS CRM MVP | English Blog: http://msdynamicscrm-e.blogspot.com | Chinese Blog: http://liudarren.spaces.live.com
    • 已标记为答案 梅小虎 2009年4月13日 2:02
    2009年4月10日 4:54
    版主
  •  protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
            {
                TimeSpan ts = Convert.ToDateTime(CrmDateTime.Now.Value) - Convert.ToDateTime(this.CreatTime.Value);
                this.Result = new CrmNumber()
                this.Result.value=int.parse(ts.Days.ToString());
                return ActivityExecutionStatus.Closed;
            }
    杭州-天天(Eirc Yang) cnblog:http://www.cnblogs.com/ericqyang/ igooya:http://www.igooya.cn/space.php?uid=1&op=bbs QQ:270760489 MSN:yqing630@hotmail.com
    • 已标记为答案 梅小虎 2009年4月13日 2:02
    2009年4月10日 6:09

全部回复

  • 改成以下看看:

    TimeSpan ts = DateTime.Now - this.CreatTime.Value;
    this.Result = new CrmNumber(ts.Days);



    Darren Liu | 刘嘉鸿 | MS CRM MVP | English Blog: http://msdynamicscrm-e.blogspot.com | Chinese Blog: http://liudarren.spaces.live.com
    • 已标记为答案 梅小虎 2009年4月13日 2:02
    2009年4月10日 4:54
    版主
  •  protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
            {
                TimeSpan ts = Convert.ToDateTime(CrmDateTime.Now.Value) - Convert.ToDateTime(this.CreatTime.Value);
                this.Result = new CrmNumber()
                this.Result.value=int.parse(ts.Days.ToString());
                return ActivityExecutionStatus.Closed;
            }
    杭州-天天(Eirc Yang) cnblog:http://www.cnblogs.com/ericqyang/ igooya:http://www.igooya.cn/space.php?uid=1&op=bbs QQ:270760489 MSN:yqing630@hotmail.com
    • 已标记为答案 梅小虎 2009年4月13日 2:02
    2009年4月10日 6:09