K3 装配日志(BOS插件)V2

在这里插入图片描述
对原来的方案进行了一些改进
(原方案详见K3 装配日志(BOS插件)
改进的地方
1、开始和结束时间初始化不是在加载新单时执行,而是在判断“物料编码”是否为空时加载
2、增加了一个时间方案,原来开始时间和结束时间是长日期字段,后来想想现实中一天一登记的话没必要用长日期字段。

代码如下:

 
'定义 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 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)

'''方法一
'' 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 "FComboBox1", 0
'' Else
'' m_BillInterface.SetFieldValue "FComboBox1", 1
''' MsgBox "冬令时"
'' End If
'''''''''''''''

'方法二

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
 
 




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)
  


''判断“物料编码”是否为空,如果不为空,则给开始和结束时间赋值
Set oFields = oEntry.BOSFields
Set oField = oFields("FBase2")
sValue = oField.Value

If sValue <> "" And startDate = "00:00:00" Then
    m_BillInterface.SetFieldValue "Ftime", CDate(currentdate)
End If
If sValue <> "" And endDate = "00:00:00" Then
    m_BillInterface.SetFieldValue "Ftime1", CDate(currentdate)
End If

'''''''''''''''''''''''''''''''''''''



''''''''''''''''''''''''''''''''''''''
'''''时间方案

    '起始时间
    skey = .TableInfo("Map")("FTimeOnly") '获取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")("FTimeOnly1") '获取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)
  


''判断“物料编码”是否为空,如果不为空,则给开始和结束时间赋值
Set oFields = oEntry.BOSFields
Set oField = oFields("FBase2")
sValue = oField.Value

If sValue <> "" And startDate = "00:00:00" Then
    m_BillInterface.SetFieldValue "FTimeOnly", "00:00:00"
End If
If sValue <> "" And endDate = "00:00:00" Then
    m_BillInterface.SetFieldValue "FTimeOnly1", "00:00:00"
End If

'''''''''''''''''''''''''''''''''''''




'''''时间段跨中午时,扣减中午休息时间,“中午加班”复选框打勾,则不扣减
     '日期差
'    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





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值