以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]用于前台代码改后台执行后出错 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=73024) |
-- 作者:huangfanzi -- 发布时间:2015/8/11 10:29:00 -- [求助]用于前台代码改后台执行后出错 先上图: 我点红框中审核后,出现错误, 当我把卷号后面加上一个字母后,就不报错了,当然这样做是不对的,会造成计算错误 此主题相关图片如下:qq截图3.jpg 下图是工序合并表的样子 投料量计算的代码来源于半年前有点甜版主帮我写的,以下是当时的帖子: http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=62939&authorid=0&page=0&star=2 以下是代码: \'投料量计算模块 If e.DataTable.datacols.Contains("审核") AndAlso e.DataTable.datacols.Contains("工序") Then If e.DataCol.Name = "审核" Then Dim drs As List(Of DataRow) = _dt工序合并表.SQLS elect("母卷号 = \'" & e.DataRow("母卷号") & "\'", "", "卷号,起始时间") If drs.Count = 0 Then ElseIf drs.Count=1 Then drs(0)("投料量")=drs(0)("重量") For i As Integer = 0 To drs.Count - 1 drs(i)("成材率") = drs(i)("重量") / drs(i)("投料量") Next Else drs(0)("投料量")=drs(0)("重量") Dim tll As Double = drs(0)("重量") Dim dic As New Dictionary(Of String, Double()) Dim Dic_dr As new Dictionary(of DataRow, Double) For i As Integer = 1 To drs.Count - 1 If drs(i)("卷号") = drs(i-1)("卷号") Dic_dr.Add(drs(i), tll) Else Dim str As String = drs(i)("卷号").Substring(0,drs(i)("卷号").length - 1) If dic.ContainsKey(str) = False Then Dim fdr As DataRow = _dt工序合并表.SQLFind("卷号 = \'" & str & "\'", "起始时间") If fdr IsNot Nothing Then Dim drs_temp As List(of DataRow) = _dt工序合并表.SQLSelect("substring(卷号,1," & drs(i)("卷号").Length - 1 & ") = \'" & fdr("卷号") & "\' and len(卷号) = " & drs(i)("卷号").Length, "卷号") Dim zl As Double = drs_temp(0)("重量") For j As Integer = 1 To drs_temp.Count - 1 If drs_temp(j)("卷号") <> drs_temp(j-1)("卷号") Then zl += drs_temp(j)("重量") End If Next dic.Add(str, new Double(){zl, tll}) Else tll = drs(i)("重量") Dic_dr.Add(drs(i), tll) Continue For End If End If tll = drs(i)("重量") / dic(str)(0) * dic(str)(1) Dic_dr.Add(drs(i), tll) End If Next For Each dr As DataRow In dic_dr.Keys dr("投料量") = dic_dr(dr) Next For i As Integer = 0 To drs.Count - 1 drs(i)("成材率") = drs(i)("重量") / drs(i)("投料量") Next End If _dt工序合并表.SQLUpdate(drs) End If End If [此贴子已经被作者于2015/8/11 10:33:25编辑过]
|
-- 作者:大红袍 -- 发布时间:2015/8/11 10:33:00 -- 加入msgbox判断哪里出错。 http://www.foxtable.com/help/topics/1485.htm
|
-- 作者:huangfanzi -- 发布时间:2015/8/11 10:40:00 -- 看到了1与2,看不到3,说明是从2后开始出错,由于有点甜版主给我写的代码用了字典,这方面的代码看不懂,请大红袍老师帮我看看,谢谢! If dic.ContainsKey(str) = False Then Dim fdr As DataRow = _dt工序合并表.SQLFind("卷号 = \'" & str & "\'", "起始时间") If fdr IsNot Nothing Then MessageBox.Show("1") Dim drs_temp As List(of DataRow) = _dt工序合并表.SQLSelect("substring(卷号,1," & drs(i)("卷号").Length - 1 & ") = \'" & fdr("卷号") & "\' and len(卷号) = " & drs(i)("卷号").Length, "卷号") MessageBox.Show("2") Dim zl As Double = drs_temp(0)("重量") For j As Integer = 1 To drs_temp.Count - 1 MessageBox.Show("3") If drs_temp(j)("卷号") <> drs_temp(j-1)("卷号") Then zl += drs_temp(j)("重量") End If Next dic.Add(str, new Double(){zl, tll}) Else tll = drs(i)("重量") Dic_dr.Add(drs(i), tll) Continue For End If End If |
-- 作者:大红袍 -- 发布时间:2015/8/11 10:57:00 -- 说明 drs_temp 的值,是空值,没有查到数据
加判断
If drs_temp.Count > 0 Then Dim zl As Double = drs_temp(0)("重量") For j As Integer = 1 To drs_temp.Count - 1
[此贴子已经被作者于2015/8/11 10:57:12编辑过]
|
-- 作者:huangfanzi -- 发布时间:2015/8/11 11:47:00 -- 老师我搞定了,问题出在SQLSelect的语法结构与Select不同,用了排序必须要有TOP Top: 可选参数,指定返回的行数 Sort: 可选参数,指定查询顺序,和Top配合使用。 Dim drs_temp As List(of DataRow) = _dt工序合并表.SQLSelect("substring(卷号,1," & drs(i)("卷号").Length - 1 & ") = \'" & fdr("卷号") & "\' and len(卷号) = " & drs(i)("卷号").Length, "","卷号")
[此贴子已经被作者于2015/8/11 11:47:48编辑过]
|