Foxtable(狐表)用户栏目专家坐堂 → 在哪里加入判断条件才严谨


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

主题:在哪里加入判断条件才严谨

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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
在哪里加入判断条件才严谨  发帖心情 Post By:2015/12/7 11:13:00 [显示全部帖子]

有这么一个提交按钮 代码如下 现在要先判断表"客服跟单"所选"订单状态"列是"配送妥投"才能加载到"回单异常"表 如果不是 msgbox(订单未处理完成") e.cancel=true

 

 

Dim Cols1() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","司机","车牌","车型","车数","出车日期","异常描述","处理结果","责任方"}
    Dim Cols2() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","司机","车牌","车型","车数","出车日期","异常描述","处理结果","责任方"}
    Dim count As Integer = 0
    Dim ls As new List(of Row)
    Dim dic As new Dictionary (Of DataRow, Row)
    systemready = False
    For Each r As Row In Tables("客服跟单").GetCheckedRows
        Dim filter As String = "1=1"
        For Each dc As String In Cols1
            If r.IsNull(dc) Then
                filter &= " and " & dc & " is null"
            Else
                Dim c As Col = Tables("回单异常").Cols(dc)
                If c.IsNumeric Then
                    filter &= " and " & dc & " = " & r(dc)
                ElseIf c.IsBoolean Then
                    If r(dc) = True Then
                        filter &= " and " & dc & " = true"
                    Else
                        filter &= " and " & dc & " = false"
                    End If
                ElseIf c.IsDate Then
                    filter &= " and " & dc & " = #" & r(dc) & "#"
                Else
                    filter &= " and " & dc & " = '" & r(dc) & "'"
                End If
            End If
        Next
        Dim dr As DataRow = DataTables("回单异常").find(filter)
        If dr Is Nothing Then
            ls.Add(r)
            count += 1
        Else
            dic.add(dr, r)
        End If
       
    Next
   
    Dim p As WinForm.ProgressBar
    p = e.Form.Controls("ProgressBar1")
    If ls.count > 0 Then
        p.Visible = True
        p.Maximum =  ls.Count - 1 '设置最大值
        p.Minimum = 0 '设置最小值
        p.Value = 0 '设置当前值
    End If
    Dim idx As Integer = 0
    DataTables("回单异常").StopRedraw
    For Each r As Row In ls
        Dim dr As DataRow = DataTables("回单异常").AddNew
        For i As Integer = 0 To Cols1.Length -1
            If r.IsNull(Cols1(i)) Then
                dr(Cols2(i)) = Nothing
            Else
                dr(Cols2(i)) = r(Cols1(i))
               
            End If
           
        Next
        idx += 1
        p.Value = idx
    Next
    For Each key As DataRow In dic.Keys
        Dim r As Row = dic(key)
        Dim dr As DataRow = key
        For i As Integer = 0 To Cols1.Length -1
            If r.IsNull(Cols1(i)) Then
                dr(Cols2(i)) = Nothing
            Else
                dr(Cols2(i)) = r(Cols1(i))
            End If
        Next
    Next
   
    DataTables("回单异常").ResumeRedraw
    p.Visible = False
   
    systemready = True
    msgbox("共有 "& count &" 条数据提交至回单" )
    Tables("客服跟单").save
    Tables("客服跟单").ClearCheckedRows


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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/12/7 13:28:00 [显示全部帖子]

按照您的指导 我加了判断 选中三行 其中两行订单状态是:配送妥投 一行是:配送在途

msgbox有提示 代码依然往下执行 最终由两行数据提交到回单异常 但都是空值 代码:

Dim Cols1() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","司机","车牌","车型","车数","出车日期","异常描述","处理结果","责任方"}
Dim Cols2() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","司机","车牌","车型","车数","出车日期","异常描述","处理结果","责任方"}
Dim count As Integer = 0
Dim ls As new List(of Row)
Dim dic As new Dictionary (Of DataRow, Row)
systemready = False
For Each r As Row In Tables("客服跟单").GetCheckedRows
    If r("订单状态") = "配送妥投" Then
        Dim filter As String = "1=1"
        For Each dc As String In Cols1
            If r.IsNull(dc) Then
                filter &= " and " & dc & " is null"
            Else
                Dim c As Col = Tables("回单异常").Cols(dc)
                If c.IsNumeric Then
                    filter &= " and " & dc & " = " & r(dc)
                ElseIf c.IsBoolean Then
                    If r(dc) = True Then
                        filter &= " and " & dc & " = true"
                    Else
                        filter &= " and " & dc & " = false"
                    End If
                ElseIf c.IsDate Then
                    filter &= " and " & dc & " = #" & r(dc) & "#"
                Else
                    filter &= " and " & dc & " = '" & r(dc) & "'"
                End If
            End If
        Next
       
        Dim dr As DataRow = DataTables("回单异常").find(filter)
        If dr Is Nothing Then
            ls.Add(r)
            count += 1
        Else
            dic.add(dr, r)
        End If
    Else
        msgbox("订单未处理完成")
        e.cancel=True
    End If 
Next

Dim p As WinForm.ProgressBar
p = e.Form.Controls("ProgressBar1")
If ls.count > 0 Then
    p.Visible = True
    p.Maximum =  ls.Count - 1 '设置最大值
    p.Minimum = 0 '设置最小值
    p.Value = 0 '设置当前值
End If
Dim idx As Integer = 0
DataTables("回单异常").StopRedraw
For Each r As Row In ls
    Dim dr As DataRow = DataTables("回单异常").AddNew
    For i As Integer = 0 To Cols1.Length -1
        If r.IsNull(Cols1(i)) Then
            dr(Cols2(i)) = Nothing
        Else
            dr(Cols2(i)) = r(Cols1(i))
           
        End If
       
    Next
    idx += 1
    p.Value = idx
Next
For Each key As DataRow In dic.Keys
    Dim r As Row = dic(key)
    Dim dr As DataRow = key
    For i As Integer = 0 To Cols1.Length -1
        If r.IsNull(Cols1(i)) Then
            dr(Cols2(i)) = Nothing
        Else
            dr(Cols2(i)) = r(Cols1(i))
        End If
    Next
Next

 

DataTables("回单异常").ResumeRedraw
p.Visible = False

systemready = True
msgbox("共有 "& count &" 条数据提交至回单" )
Tables("客服跟单").save
Tables("客服跟单").ClearCheckedRows


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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/12/7 16:31:00 [显示全部帖子]

还是上传实例吧 我改了没有效果 另外我还发现一个问题  在调度配载窗口 如果不小心点中了列字段,(有时候会,然后所有行会选中 ,然后计算 )有时候又不会 怎样才能点中列头时不等同于选中所有行

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目4_201512071536.zip


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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/12/7 17:18:00 [显示全部帖子]

呃 我也才发现 可以了 另外那个问题要怎样解决?

空行怎样不给默认值 或者在提交的时候 不加载空行?

 


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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/12/8 9:44:00 [显示全部帖子]

请问那个全局代码我要写在哪里

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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/12/8 11:16:00 [显示全部帖子]

这段导入代码 导入的时候少一条数据,我这么改数据完整 但是第二次第三次导,每一次都有十七条数据可以重复导入

Dim dlg As new OpenFileDialog
If dlg.ShowDialog = DialogResult.OK Then
    Dim App As New MSExcel.Application
    try
        Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName)
        Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets("计划表")
        Dim Rg As MSExcel.Range = Ws.UsedRange
        Dim ary = rg.value
       
        Tables("配载订单").ResumeRedraw()
        Tables("配载订单").StopRedraw()
        Dim nms() As  String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","承运商","司机","车牌","车数","车型","出车日期"}
        Dim count As Integer = 0
        Dim ls As new List(of Integer)
        Dim dic As new Dictionary (Of DataRow, Integer)
       
        For n As Integer = 2 To ws.UsedRange.Rows.Count
           
            Dim filter As String = "1=1"
            For m As Integer = 0 To nms.length-1
                Dim vl As object = ary(n,m+1)
                Dim dc As String = nms(m)
                Dim c As Col = Tables("配载订单").Cols(dc)
                If vl = Nothing Then
                    filter &= " and " & dc & " is null"
                Else
                    If c.IsNumeric Then
                       
                        filter &= " and " & dc & " >= " & vl - 0.0001 & " and " & dc & " <= " & vl + 0.0001
                       
                    ElseIf c.IsBoolean Then
                        If vl = True Then
                            filter &= " And " & dc & " = true"
                        Else
                            filter &= " and " & dc & " = false"
                        End If
                    ElseIf c.IsDate Then
                       
                        Dim d As Date
                        If Date.TryParse(vl, d)
                            filter &= " and " & dc & " = #" & d.Date & "#"
                        End If
                       
                    Else
                       
                        filter &= " and " & dc & " = '" & vl & "'"
                       
                    End If
                End If
            Next
            Dim dr As DataRow = DataTables("配载订单").find(filter)
            If dr Is Nothing Then
                output.show(filter)
                ls.Add(n)
                count += 1
            Else
                dic.add(dr, n)
            End If
        Next
        For Each n As Integer In ls
           
            Dim r As  Row = Tables("配载订单").AddNew()
            For  m As  Integer = 0 To nms.Length - 1
                If ary(n,m+1) = Nothing Then
                    r(nms(m)) = Nothing
                Else
                    If Tables("配载订单").Cols(nms(m)).IsDate Then
                        Dim d As Date
                        If Date.TryParse(ary(n,m+1), d)
                            r(nms(m)) = d
                        End If
                    Else
                        r(nms(m)) = ary(n,m+1)
                    End If
                End If
               
            Next
           
        Next
        Tables("配载订单").ResumeRedraw()
        msgbox("共有 "& count &" 条数据导入" )
       
    catch ex As exception
        msgbox(ex.message)
    finally
        app.quit
    End try
End If

Tables("配载订单").save
e.Form.Controls("提示").Text = "正在导入,请稍后..."
Application.DoEvents()
e.Form.Controls("提示").Text = "已经导入完成."
e.Form.TimerInterval = 5000
e.Form.TimerEnabled = True

 

实例就是昨天上传的例子

 


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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/12/8 11:27:00 [显示全部帖子]

在您电脑上没事吗 ?

 


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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/12/8 11:28:00 [显示全部帖子]

我试了好多次 第二次导入同一张表起 都可以再重复导入17条数据

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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/12/8 11:34:00 [显示全部帖子]


图片点击可在新窗口打开查看此主题相关图片如下:2015-12-08_113637.jpg
图片点击可在新窗口打开查看


 


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


加好友 发短信
等级:一尾狐 帖子:412 积分:2665 威望:0 精华:0 注册:2015/10/2 23:48:00
  发帖心情 Post By:2015/12/8 11:41:00 [显示全部帖子]

另外我还发现 按住鼠标左键拖动 复选框不跟着联动了 

 


 回到顶部
总数 13 1 2 下一页