【分享】移动BOS-日期字段长日期与短日期转换
金蝶云社区-emily
emily
3人赞赏了该文章 3008次浏览 未经作者许可,禁止转载编辑于2018年08月29日 19:48:03

一、前言
1. 目前移动BOS只有日期字段,尚未提供长日期字段。
2. 原本日期字段与PC端是保持一致的(短日期格式),但是后来可能由于用户需求变更,在H5端(云之家)的日期字段变成了长日期格式。
3. 所以最近接触到比较多的提问,关于移动报表配置了日期关键字后查询不到数据问题,就是因为长日期导致,目前提供的解决方案是在脚本中处理将长日期重新修改为短日期。
如下图所示,开始时间保持日期字段默认值(长日期),结束时间使用脚本处理成短日期:
云之家图片20170620104808.png 
二、实现
1. 通过Python脚本实现(Python的好处就在方便快捷,不需要重新IIS)

  1. import clr

  2. clr.AddReference("System")

  3. clr.AddReference("System.Core")

  4. clr.AddReference("Kingdee.BOS")

  5. clr.AddReference("Kingdee.BOS.Core")

  6. clr.AddReference("Kingdee.BOS.Mobile")

  7. clr.AddReference("Kingdee.BOS.DataEntity")

  8. clr.AddReference("Kingdee.BOS.Contracts")

  9. from Kingdee.BOS import *

  10. from Kingdee.BOS.JSON import *

  11. from Kingdee.BOS.Mobile import  *

  12. from Kingdee.BOS.Core import *

  13. from Kingdee.BOS.Core.Const import *

  14. from Kingdee.BOS.Mobile.Metadata import *

  15. from Kingdee.BOS.Mobile.PlugIn.ControlModel import *

  16. from System import *

  17. from System.Collections.Generic import *

  18. from System.Linq import *


  19. def BeforeUpdateValue(e):

  20.         if (e.Key == "FStart" or e.Key == "FEnd")  and e.Value != "":

  21.                 val = e.Value.ToString();

  22.                 nVal = DateTime.Parse(val).Date;

  23.                 e.Value = nVal;

复制代码


2. 通过.Net脚本实现

  1. using System;

  2. using System.Collections.Generic;

  3. using System.Linq;

  4. using System.Text;

  5. using Kingdee.BOS.Mobile.PlugIn;

  6. using Kingdee.BOS.Util;


  7. namespace Kevin.Demo.Mobile

  8. {

  9.     public class Kevin_BD_A : AbstractMobilePlugin

  10.     {

  11.         public override void BeforeUpdateValue(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.BeforeUpdateValueEventArgs e)

  12.         {

  13.             base.BeforeUpdateValue(e);


  14.             if ((e.Key.EqualsIgnoreCase("FStart") || e.Key.EqualsIgnoreCase("FEnd")) && 

  15.                 !e.Value.IsNullOrEmptyOrWhiteSpace())

  16.             {

  17.                 var val = e.Value.ToString();

  18.                 var nVal = DateTime.Parse(val).Date;

  19.                 e.Value = nVal;

  20.             }

  21.         }

  22.     }

  23. }


复制代码


赞 3