以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]在职时间和在职月数计算[已解决] (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=33977) |
-- 作者:lipiti -- 发布时间:2013/5/28 10:49:00 -- [求助]在职时间和在职月数计算[已解决] [求助]在职时间和在职月数计算[已解决] 现在用以下代码可以正确计算在职员工的,在职在职时间和在职月数。大家帮忙看看以下满足需求,需要怎么来修改代码,谢谢! 现在需要改成: 1.如果员工状态为在职,【今天日期】减去【入职日期】 2.如果员工状态为离职,【离职日期】减去【入职日期】 Select Case e. DataCol .name Case "入职日期" If e .DataRow . IsNull( "入职日期" ) Then e .DataRow ( "在职时间" ) = Nothing e .DataRow ( "在职月数" ) = Nothing Else Dim y,m,d As Integer Dim dt1 As Date = e .DataRow ( "入职日期" ) Dim dt2 As Date = Date .Today () DateYMD(e.DataRow("入职日期"),Date.Today,y,m,d) e.DataRow("在职时间") = y & "年" & m & "月" & d & "日" e .DataRow ( "在职月数" ) = ( dt2 . Year - dt1 . Year ) * 12 + dt2 . Month - dt1 . Month End If End Select [此贴子已经被作者于2013-5-28 12:41:58编辑过]
|
-- 作者:Bin -- 发布时间:2013/5/28 10:57:00 -- Select Case e. DataCol .name Case "入职日期" Select Case e. DataRow("员工状态") case "在职" If e .DataRow . IsNull( "入职日期" ) Then e .DataRow ( "在职时间" ) = Nothing e .DataRow ( "在职月数" ) = Nothing Else Dim y,m,d As Integer Dim dt1 As Date = e .DataRow ( "入职日期" ) Dim dt2 As Date = Date .Today () DateYMD(e.DataRow("入职日期"),Date.Today,y,m,d) e.DataRow("在职时间") = y & "年" & m & "月" & d & "日" e .DataRow ( "在职月数" ) = ( dt2 . Year - dt1 . Year ) * 12 + dt2 . Month - dt1 . Month End If case "离职" If e .DataRow . IsNull( "入职日期" ) Then e .DataRow ( "在职时间" ) = Nothing e .DataRow ( "在职月数" ) = Nothing Else Dim y,m,d As Integer Dim dt1 As Date = e .DataRow ( "入职日期" ) Dim dt2 As Date = Date .Today () 这部分就不用我写了吧? End If End Select End Select |
-- 作者:lipiti -- 发布时间:2013/5/28 12:41:00 -- Select Case e. DataCol .name Case "入职日期" Select Case e. DataRow("员工状态") Case "在职" If e .DataRow . IsNull( "入职日期" ) Then e .DataRow ( "在职时间" ) = Nothing e .DataRow ( "在职月数" ) = Nothing Else Dim y,m,d As Integer Dim dt1 As Date = e .DataRow ( "入职日期" ) Dim dt2 As Date = Date .Today () DateYMD(e.DataRow("入职日期"),Date.Today,y,m,d) e.DataRow("在职时间") = y & "年" & m & "月" & d & "日" e .DataRow ( "在职月数" ) = ( dt2 . Year - dt1 . Year ) * 12 + dt2 . Month - dt1 . Month End If Case "离职" If e .DataRow . IsNull( "入职日期" ) Then e .DataRow ( "在职时间" ) = Nothing e .DataRow ( "在职月数" ) = Nothing Else Dim y,m,d As Integer Dim dt1 As Date = e .DataRow ( "入职日期" ) Dim dt2 As Date = e .DataRow ( "离职日期" ) DateYMD(e.DataRow("入职日期"),e.DataRow("离职日期"),y,m,d) e.DataRow("在职时间") = y & "年" & m & "月" & d & "日" e .DataRow ( "在职月数" ) = ( dt2 . Year - dt1 . Year ) * 12 + dt2 . Month - dt1 . Month End If End Select End Select |
-- 作者:lipiti -- 发布时间:2013/5/28 12:42:00 -- 谢谢 Bin 帮忙,已解决! |
-- 作者:don -- 发布时间:2013/5/28 12:48:00 -- 定義了又不用,豈非只封官,不給權嗎: Dim dt1 As Date = e .DataRow ( "入职日期" ) Dim dt2 As Date = e .DataRow ( "离职日期" ) DateYMD(e.DataRow("入职日期"),e.DataRow("离职日期"),y,m,d) ======> DateYMD(dt1,dt2,y,m,d)
|
-- 作者:don -- 发布时间:2013/5/28 13:06:00 -- 簡化下吧: Select Case e.DataCol.name Case "入职日期" Dim y,m,d As Integer Dim dt1,dt2 As Date Dim dr1 As DataRow = e.DataRow If dr1.IsNull("入职日期") Then dr1("在职时间") = Nothing dr1("在职月数") = Nothing Else Select Case dr1("员工状态") Case "在职","离职" dt1 = dr1("入职日期") dt2 = iif(dr1("员工状态")= "在职",Date.Today(),dr1("离职日期")) DateYMD(dt1,dt2,y,m,d) dr1("在职时间") = y & "年" & m & "月" & d & "日" dr1("在职月数") = y*12 + m End Select End If End Select [此贴子已经被作者于2013-5-28 13:12:06编辑过]
|
-- 作者:lipiti -- 发布时间:2013/5/28 13:47:00 -- 谢谢 don 精简代码。 |