K3 装配日志(BOS插件)

在这里插入图片描述
主要的难点一是计算时长,因为如果是跨中午休息时间,是要扣减的,但如果开始时间或结束时间在中午休息时间段内,不扣减,这个调试了老久,差点放弃只接通过勾选来扣减了;二是根据装配时间判断作息时间是夏令还是冬令,这个影响时长的计算。
BOS单据简单设置下,看代码:
在这里插入图片描述

 
'定义 BillEvent 接口. 必须具有的声明, 以此来获得事件
Private WithEvents m_BillInterface  As BillEvent
Private timetype As Integer
Private currentday As Date
Private currentdate As Variant
 
Public Sub Show(ByVal oBillInterface As Object)
 
    'BillEvent 接口实现
    '注意: 此方法必须存在, 请勿修改
    Set m_BillInterface = oBillInterface
 
End Sub

Private Sub Class_Terminate()
 
    '释放接口对象
    '注意: 此方法必须存在, 请勿修改
    Set m_BillInterface = Nothing

End Sub


Private Sub m_BillInterface_AddNewRow(ByVal Index As Integer, ByVal NewRow As Long)
 ''新增行同样先初始化开始和结束时间
 Dim currentday As Date
 Dim nrow As Integer
 Dim rows As Integer
 
' rows = m_BillInterface.Data("page2").Size '获取总行数
 nrow = NewRow
 currentday = Date
 currentdate = currentday - 1 & " " & VBA.CDate("00:00:00")
 

m_BillInterface.SetFieldValue "Ftime", CDate(currentdate), nrow
m_BillInterface.SetFieldValue "Ftime1", CDate(currentdate), nrow
End Sub

'新增单据时,工作时间段按装配日期判断是夏令时还是冬令时
Private Sub m_BillInterface_AfterNewBill()

 Dim skey As String
 Dim sValue As String
 Dim dtValue As Date

 skey = m_BillInterface.TableInfo("Map")("fdate") '获取KEY值
 sValue = m_BillInterface.Data("page1")(skey)("FFLD") '获取字段数值

 
 If Len(sValue) > 0 Then
   dtValue = CDate(sValue) '转换成日期
 End If
 
 '判断当月份是5至10月之间的为夏令时,其他为冬令时
 If Month(dtValue) >= 5 And Month(dtValue) <= 10 Then
' MsgBox "夏令时"
 m_BillInterface.SetFieldValue "FComboBox", 0 '测试单据中是FComboBox1
 timetype = 0
 Else
 m_BillInterface.SetFieldValue "FComboBox", 1
 timetype = 1
' MsgBox "冬令时"
 End If
 
 

 
 ''先初始化开始和结束时间

 currentday = Date
 currentdate = currentday - 1 & " " & VBA.CDate("00:00:00")
 
m_BillInterface.SetFieldValue "FDate", CDate(currentday - 1)
m_BillInterface.SetFieldValue "Ftime", CDate(currentdate)
m_BillInterface.SetFieldValue "Ftime1", CDate(currentdate)
m_BillInterface.SetFieldValue "FDecimal", "0"
'm_BillInterface.BillEntrys(1).MaxRows = 500 '最大行设为500
 
End Sub
'当装配日期变更时,判断是夏令时还是冬令时
Private Sub m_BillInterface_Change(ByVal dct As KFO.IDictionary, ByVal dctFld As KFO.IDictionary, ByVal Col As Long, ByVal Row As Long, Cancel As Boolean)



'方法二

Dim oHeads As K3ClassEvents.BillHeads '单据头集合
Dim oHead As K3ClassEvents.BillHead '单据头对象
Dim oEntrys As K3ClassEvents.BillEntrys '单据体集合
Dim oEntry As K3ClassEvents.BillEntry '单据体对象
Dim oFields As K3ClassEvents.BOSFields '字段集合
Dim oField As K3ClassEvents.BOSField '字段
Dim dtValue As Date
Dim skey As String
Dim sValue As String
Dim startDate As Date
Dim endDate As Date
Dim duration As Single
Dim diffDay As Integer
Dim startH As Integer, startMi As Integer, endH As Integer, endMi As Integer
Dim OvertimeType As Integer
 
Dim starttime As Variant
Dim endtime As Variant
Dim time1 As Variant, time2 As Variant, time3 As Variant
 
 
Set oHeads = m_BillInterface.BillHeads
Set oEntrys = m_BillInterface.BillEntrys
Set oHead = oHeads(1) '第一个单据头
Set oEntry = oEntrys(1) '第一个单据体

'获取字段值


Set oFields = oHead.BOSFields
Set oField = oFields("Fdate")

 If Len(oField.Value) > 0 Then
   dtValue = CDate(oField.Value) '转换成日期
 End If

Set oFields = oHead.BOSFields
Set oField = oFields("FComboBox")

 '判断当月份是5至10月之间的为夏令时,其他为冬令时
 If Month(dtValue) >= 5 And Month(dtValue) <= 10 Then
' MsgBox "夏令时"
 oField.Value = 0
 timetype = 0
 Else
 oField.Value = 1
 timetype = 1
' MsgBox "冬令时"
 End If
 
 


''单据体中判断开始和结束时间,是否跨中午,并计算时长(Mi)
'

With m_BillInterface


If Row = .Data("page2").Size Then  '判断当前行是否最后一行

    '开始时间
    skey = .TableInfo("Map")("Ftime") '获取KEY值
    sValue = .Data("page2")(Row)(skey)("FFLD")   '获取单据体字段数值

     If Len(sValue) > 0 Then
       startDate = CDate(sValue) '转换成日期
     End If
     startH = Hour(startDate)
     startMi = Minute(startDate)

    '结束时间
    skey = .TableInfo("Map")("Ftime1") '获取KEY值
    sValue = .Data("page2")(Row)(skey)("FFLD")   '获取单据体字段数值

     If Len(sValue) > 0 Then
       endDate = CDate(sValue) '转换成日期
     End If
     endH = Hour(endDate)
     endMi = Minute(endDate)
     
    '中午加班标识
    skey = .TableInfo("Map")("FCheckBox") '获取KEY值
    sValue = .Data("page2")(Row)(skey)("FFLD")   '获取单据体字段数值
    OvertimeType = VBA.CInt(sValue)
    
     
   starttime = TimeSerial(startH, startMi, 0)
   endtime = TimeSerial(endH, endMi, 0)
  


''   ,时间段跨中午时,扣减中午休息时间,“中午加班”复选框打勾,则不扣减
     '日期差
'    diffDay = DateDiff("d", startDate, endDate)
  
    If endH > 0 Or (endH = 0 And endMi > 0) Then '判断只有结束时间的小时大于0时才进行计算
  
   If startDate > endDate Then
     MsgBox "结束时间不能小与开始时间", vbOKOnly, "提示"
     GoTo out
   End If
  
    If timetype = 0 Then '夏

 
'设置中午休息时间
     time1 = TimeSerial(11, 29, 59)
     time2 = TimeSerial(13, 0, 1)
     
     If starttime > time1 And endtime < time2 Then '在休息时间内的
       result = MsgBox("请确认是否是加班时间", vbYesNo, "提示")
       If result = 6 Then 'yes
       duration = (endDate - startDate) * 60 * 24
       .SetFieldValue "FDecimal", duration
       .SetFieldValue "FDecimal1", duration / 60
       .SetFieldValue "FCheckBox", 1
       ElseIf result = 7 Then 'no
       m_BillInterface.SetFieldValue "Ftime1", CDate(currentdate)
       GoTo out
       End If
     ElseIf starttime <= time1 And endtime >= time2 Then '跨休息时间的,要扣减
     
      duration = (endDate - startDate) * 60 * 24 - 90
       .SetFieldValue "FDecimal", duration
       .SetFieldValue "FDecimal1", duration / 60
'       MsgBox "扣减"
       .SetFieldValue "FCheckBox", 0
     Else '其他情况的 比如开始或结束时间在休息时间段内的
        duration = (endDate - startDate) * 60 * 24
       .SetFieldValue "FDecimal", duration
       .SetFieldValue "FDecimal1", duration / 60
       .SetFieldValue "FCheckBox", 0
     End If
     

        
    ElseIf timetype = 1 Then  '冬

'设置中午休息时间
     time1 = TimeSerial(11, 29, 59)
     time2 = TimeSerial(12, 30, 1)
     
     If starttime > time1 And endtime < time2 Then '在休息时间内的
       result = MsgBox("请确认是否是加班时间", vbYesNo, "提示")
       If result = 6 Then 'yes
       duration = (endDate - startDate) * 60 * 24
       .SetFieldValue "FDecimal", duration
       .SetFieldValue "FDecimal1", duration / 60
       .SetFieldValue "FCheckBox", 1
       ElseIf result = 7 Then 'no
       m_BillInterface.SetFieldValue "Ftime1", CDate(currentdate)
       GoTo out
       End If
     ElseIf starttime <= time1 And endtime >= time2 Then '跨休息时间的,要扣减
     
      duration = (endDate - startDate) * 60 * 24 - 60
       .SetFieldValue "FDecimal", duration
       .SetFieldValue "FDecimal1", duration / 60
'       MsgBox "扣减"
       .SetFieldValue "FCheckBox", 0
     Else '其他情况的 比如开始或结束时间在休息时间段内的
        duration = (endDate - startDate) * 60 * 24
       .SetFieldValue "FDecimal", duration
       .SetFieldValue "FDecimal1", duration / 60
       .SetFieldValue "FCheckBox", 0
     End If
     




'
'    End If
'''   '直接通过“中午加班”来判断是否扣减
'''    If OvertimeType = 1 Then '中午加班不扣减
'''        duration = (endDate - startDate) * 60 * 24
'''         .SetFieldValue "FDecimal", duration
'''    ElseIf OvertimeType = 0 Then
'''       If timetype = 0 Then  '夏
'''         duration = (endDate - startDate) * 60 * 24 - 90
'''         .SetFieldValue "FDecimal", duration
'''       ElseIf timetype = 1 Then  '冬
'''         duration = (endDate - startDate) * 60 * 24 - 60
'''         .SetFieldValue "FDecimal", duration
'''
'''    End If
'''


    End If
  End If
    
    

End If

End With


out:
End Sub





  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值