Foxtable(狐表)用户栏目专家坐堂 → 如何利用列名进行自定义表达式计算


  共有3574人关注过本帖树形打印复制链接

主题:如何利用列名进行自定义表达式计算

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/9/15 16:32:00 [显示全部帖子]

DataColChanged事件

 

'If e.DataRow.IsNull("应发工资公式") Then
'e.DataRow("应发工资") = Nothing
'Else
'e.DataRow("应发工资") = Eval2(e.DataRow("应发工资公式"),e.DataRow)
'End If
'


If e.DataRow.IsNull("应发工资公式") Then
    e.DataRow("应发工资") = Nothing
Else
    Dim str As String = e.DataRow("应发工资公式")
    For Each dc As DataCol In e.DataTable.DataCols
        str = str.replace("[" & dc.name & "]", dc.name).Replace(dc.name, "[" & dc.name & "]")
    Next
    If TryEval(str, e.DataRow) Then
        e.DataRow("应发工资") = Eval2(str,e.DataRow)
    Else
        msgbox("公式错误")
    End If
End If


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/9/17 16:13:00 [显示全部帖子]

If e.DataRow.IsNull("费用计算式") Then
    e.DataRow("金额") = Nothing
Else
    Dim str As String = e.DataRow("费用计算式")
    For Each dc As DataCol In e.DataTable.DataCols
        str = str.replace("[" & dc.name & "]", dc.name).Replace(dc.name, "[" & dc.name & "]")
    Next
    For Each dr As DataRow In e.DataTable.Select("项目编号 = '" & e.DataRow("项目编号") & "'")
        Dim fymc = dr("费用名称")
        If fymc <> "" Then
            str = str.replace("[" & fymc & "]", fymc).Replace(fymc, dr("金额"))
        End If
    Next
    If TryEval(str, e.DataRow) Then
        e.DataRow("金额") = Eval2(str,e.DataRow)
    Else
        msgbox("公式错误")
    End If
End If

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/9/24 21:26:00 [显示全部帖子]

 控件不能直接绑定列【费用汇总.费用计算式

 

 如果要赋值,请在窗口关闭的时候给表列赋值。


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/9/27 9:30:00 [显示全部帖子]

If e.DataRow.IsNull("费用计算式") = False Then
    Dim str As String = e.DataRow("费用计算式")
    Dim dr As DataRow
    Dim pattern As String = "{.+?}"
    Dim rgx = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
    For Each  match As System.Text.RegularExpressions.Match In rgx.Matches(str)
        dr = e.DataTable.Find("序号='" & match.Value.trim("{","}") & "'")
        If dr IsNot Nothing Then
            str = str.replace(match.Value, dr("金额"))
        End If
    Next
    pattern = "\[.+?\]"
    rgx = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
    For Each  match As System.Text.RegularExpressions.Match In rgx.Matches(str)
        str = str.replace(match.Value, e.DataRow(match.Value.trim("[","]")))
    Next
    If TryEval(str, e.DataRow) Then
        e.DataRow("金额") = Eval2(str,e.DataRow)
    Else
        msgbox("公式错误")
    End If
End If

[此贴子已经被作者于2017/9/28 15:38:42编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/9/28 13:09:00 [显示全部帖子]

项目发上来测试。


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/9/28 14:52:00 [显示全部帖子]

            rgx = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
            For Each  match As System.Text.RegularExpressions.Match In rgx.Matches(str)
                str = "监理单位审核_" & str.replace(match.Value, e.DataRow(match.Value.trim("[","]"))).Replace("监理单位审核_", "")
            Next

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/9/28 15:40:00 [显示全部帖子]

            pattern = "\[.+?\]"
            rgx = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
            For Each  match As System.Text.RegularExpressions.Match In rgx.Matches(str)
                str = str.replace(match.Value, e.DataRow("监理单位审核_" & match.Value.Replace("监理单位审核_", "").trim("[","]")))
            Next

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/9/28 16:35:00 [显示全部帖子]

测试没问题。

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/9/28 16:51:00 [显示全部帖子]

1、修改列以后才会重新统计;

 

2、贴出你修改后的代码。


 回到顶部