Dim dr As DataRow = e.DataRow
Select Case e.DataCol.Name
Case "离职日期"
If dr.Isnull("离职日期")=False Then
Dim pr As DataRow = dr.GetParentRow("员工清单")
If pr IsNot Nothing Then
Dim y,m,d As Integer
Dim dt1 As Date = pr("入职时间")
Dim dt2 As Date = dr("离职日期")
DateYMD(dt1,dt2,y,m,d)
dr("工作年数")=y
dr("工作月数")=y*12+m
'---------------------------------计算服装折旧-------------------------------------------------
Dim drs As List(of DataRow) = DataTables("工服管理").SQLSelect("员工编号='" & dr("员工编号") & "' and 参与计算=1")
Dim sumTotal As Decimal
For Each r As DataRow In drs
Select Case r("新旧")
Case "新"
Dim y1,m1,d1 As Integer
Dim dt_1 As Date = r("领用日期")
Dim dt_2 As Date = dr("离职日期")
DateYMD(dt_1,dt_2,y1,m1,d1)
m1=m1+IIF(D1>=15,1,0)
If y1>=2 Then
sumTotal = sumTotal+ 0
ElseIf y1*12+m1<3 Then
sumTotal = sumTotal+ 100+r("干洗费")*r("数量")
Else
sumTotal =sumTotal+(r("月折旧额")*(r("折旧月数")-(y1*12+m1)))
End If
Case "旧"
Dim y1,m1,d1 As Integer
Dim dt_1 As Date = r("领用日期")
Dim dt_2 As Date = dr("离职日期")
DateYMD(dt_1,dt_2,y1,m1,d1)
m1=m1+IIF(D1>=15,1,0)
If y1>=1 Then
sumTotal = sumTotal+ 0
Else
sumTotal =sumTotal+(r("月折旧额")*(r("折旧月数")-(y1*12+m1)))
End If
End Select
Next
sumTotal = Math.round(sumTotal,2)
dr("服装折旧")=sumTotal
'---------------------------------计算培训扣款-------------------------------------------------
Dim drs1 As List(of DataRow) = DataTables("培训管理").SQLSelect("员工编号='" & dr("员工编号") & "' and 参与计算=1")
Dim studyTotal As Decimal
For Each r As DataRow In drs1
Dim y2,m2,d2 As Integer
Dim dtStart As Date = r("签约结束日期")
Dim dtEnd As Date = dr("离职日期")
DateYMD(dtStart,dtEnd,y2,m2,d2)
m2=m2+IIF(d2>=15,1,0)
If y2*12+m2<=0 Then
studyTotal = studyTotal+ 0
Else
studyTotal =studyTotal+(y2*12+m2)*(r("培训费用")/r("合同月数"))
End If
Next
studyTotal = Math.round(studyTotal,2)
dr("培训扣款")=studyTotal
End If
Else
dr("工作年数")=Nothing
dr("工作月数")=Nothing
dr("服装折旧")=Nothing
dr("培训扣款")=Nothing
End If
End Select