以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 从字符串“”到类型date的转换无效 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=91251) |
|||||||||
-- 作者:13388123666 -- 发布时间:2016/10/5 14:57:00 -- 从字符串“”到类型date的转换无效 Dim Customer As WinForm.ComboBox = e.Form.Controls("客户代码") Dim StartDate As WinForm.DateTimePicker = e.Form.Controls("开始日期") Dim EndDate As WinForm.DateTimePicker = e.Form.Controls("结束日期") Dim bd1 As New SQLGroupTableBuilder("统计表1","工序完工明细") bd1.C Dim dt1 As fxDataSource bd1.Groups.AddDef("产品代码") bd1.Totals.AddExp("制壳重量","case when 工序 = \'制壳\' then 数量 * 组件数*单件重量 else 0 end") \'对制壳重量进行统计 bd1.Totals.AddExp("浇注重量","case when 工序 = \'浇注\' then 数量 * 组件数*单件重量 else 0 end") \'对浇注重量进行统计 If StartDate.Value <> "" And EndDate.Value <> "" Then If Customer.Value = "" Then bd1.Filter = "日期 >= \'" & StartDate.Value & "\' And 日期 <= \'" & EndDate.Value & "\'" Else bd1.Filter = "SubString(产品代码,1,3) = \'" & Customer.Value & "\' And 日期 >= \'" & StartDate.Value & "\' And 日期 <= \'" & EndDate.Value & "\'" End If Else If Customer.Value = "" Then bd1.Filter = "" Else bd1.Filter = "SubString(产品代码,1,3) = \'" & Customer.Value & "\'" End If End If dt1 = bd1.BuildDataSource() 运行时,出错提示“ 字符串“”到类型date的转换无效 ”。曾经尝试把datetimepicker控件改进textbox, 可以执行,但输入不方便,请问以上代码该做何调整。谢谢 |
|||||||||
-- 作者:狐狸爸爸 -- 发布时间:2016/10/5 21:52:00 -- If StartDate.Value <> "" And EndDate.Value <> "" Then 改为: If StartDate.Value Isnot Nothing And EndDate.Value isnot nothing Then
|
|||||||||
-- 作者:13388123666 -- 发布时间:2016/10/7 14:22:00 -- 谢谢,问题解决,过程中还遇到一个问题,数据加载后统计是相当快的,但进行后台统计的时候,耗时相当长(几分钟),代码如下: Dim StartDate As WinForm.DateTimePicker = e.Form.Controls("StartDate") Dim EndDate As WinForm.DateTimePicker = e.Form.Controls("EndDate") If StartDate.Value IsNot Nothing And EndDate.Value IsNot Nothing Then For Each dr As DataRow In DataTables("产品收发存").DataRows dr("期初_数量") = DataTables("产品入库明细").SQLCompute("Sum(数量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'完工入库\' and 日期 < \'" & StartDate.Value & "\'") + DataTables("产品入库明细").Compute("Sum(数量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'外协入库\' and 日期 < \'" & StartDate.Value & "\'") - DataTables("出库明细").Compute("Sum(实交数量)","[产品代码] = \'" & dr("产品代码") & "\' and 制单日期 < \'" & StartDate.Value & "\'") dr("期初_重量") = DataTables("产品入库明细").SQLCompute("Sum(数量*单件重量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'完工入库\' and 日期 < \'" & StartDate.Value & "\'") + DataTables("产品入库明细").Compute("Sum(数量*单件重量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'外协入库\' and 日期 < \'" & StartDate.Value & "\'") - DataTables("出库明细").Compute("Sum(重量)","[产品代码] = \'" & dr("产品代码") & "\' and 制单日期 < \'" & StartDate.Value & "\'") dr("期初_金额") = DataTables("产品入库明细").SQLCompute("Sum(数量*单价)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'完工入库\' and 日期 < \'" & StartDate.Value & "\'") + DataTables("产品入库明细").Compute("Sum(数量*单价)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'外协入库\' and 日期 < \'" & StartDate.Value & "\'") - DataTables("出库明细").Compute("Sum(金额)","[产品代码] = \'" & dr("产品代码") & "\' and 制单日期 < \'" & StartDate.Value & "\'") dr("入库_数量") = DataTables("产品入库明细").SQLCompute("Sum(数量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'完工入库\' and 日期 >= \'" & StartDate.Value & "\' and 日期 <= \'" & EndDate.Value & "\'") + DataTables("产品入库明细").SQLCompute("Sum(数量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'外协入库\' and 日期 >= \'" & StartDate.Value & "\' and 日期 <= \'" & EndDate.Value & "\'") dr("入库_重量") = DataTables("产品入库明细").SQLCompute("Sum(数量*单件重量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'完工入库\' and 日期 >= \'" & StartDate.Value & "\' and 日期 <= \'" & EndDate.Value & "\'") + DataTables("产品入库明细").SQLCompute("Sum(数量*单件重量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'外协入库\' and 日期 >= \'" & StartDate.Value & "\' and 日期 <= \'" & EndDate.Value & "\'") dr("入库_金额") = DataTables("产品入库明细").SQLCompute("Sum(数量*单价)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'完工入库\' and 日期 >= \'" & StartDate.Value & "\' and 日期 <= \'" & EndDate.Value & "\'") + DataTables("产品入库明细").SQLCompute("Sum(数量*单价)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'外协入库\' and 日期 >= \'" & StartDate.Value & "\' and 日期 <= \'" & EndDate.Value & "\'") dr("出库_数量") = DataTables("出库明细").SQLCompute("Sum(实交数量)","[产品代码] = \'" & dr("产品代码") & "\' and 制单日期 >= \'" & StartDate.Value & "\' and 制单日期 <= \'" & EndDate.Value & "\'") dr("出库_重量") = DataTables("出库明细").SQLCompute("Sum(实交数量*单件重量)","[产品代码] = \'" & dr("产品代码") & "\' and 制单日期 >= \'" & StartDate.Value & "\' and 制单日期 <= \'" & EndDate.Value & "\'") dr("出库_金额") = DataTables("出库明细").SQLCompute("Sum(实交数量*单价)","[产品代码] = \'" & dr("产品代码") & "\' and 制单日期 >= \'" & StartDate.Value & "\' and 制单日期 <= \'" & EndDate.Value & "\'") dr("期末_数量") = dr("期初_数量") + dr("入库_数量") - dr("出库_数量") dr("期末_重量") = dr("期初_重量") + dr("入库_重量") - dr("出库_重量") dr("期末_金额") = dr("期初_金额") + dr("入库_金额") - dr("出库_金额") Next Else For Each dr As DataRow In DataTables("产品收发存").DataRows dr("入库_数量") = DataTables("产品入库明细").SQLCompute("Sum(数量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'完工入库\'") + DataTables("产品入库明细").SQLCompute("Sum(数量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'外协入库\'") dr("入库_重量") = DataTables("产品入库明细").SQLCompute("Sum(数量*单件重量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'完工入库\'") + DataTables("产品入库明细").SQLCompute("Sum(数量*单件重量)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'外协入库\'") dr("入库_金额") = DataTables("产品入库明细").SQLCompute("Sum(数量*单价)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'完工入库\'") + DataTables("产品入库明细").SQLCompute("Sum(数量*单价)","[产品代码] = \'" & dr("产品代码") & "\' and 工序 = \'外协入库\'") dr("出库_数量") = DataTables("出库明细").SQLCompute("Sum(实交数量)","[产品代码] = \'" & dr("产品代码") & "\'") dr("出库_重量") = DataTables("出库明细").SQLCompute("Sum(实交数量*单件重量)","[产品代码] = \'" & dr("产品代码") & "\'") dr("出库_金额") = DataTables("出库明细").SQLCompute("Sum(实交数量*单价)","[产品代码] = \'" & dr("产品代码") & "\'") dr("期末_数量") = dr("入库_数量") - dr("出库_数量") dr("期末_重量") = dr("入库_重量") - dr("出库_重量") dr("期末_金额") = dr("入库_金额") - dr("出库_金额") Next End If 请问,上述代码的问题出在哪里,需要怎么改进?
|
|||||||||
-- 作者:有点蓝 -- 发布时间:2016/10/7 14:34:00 -- 代码么有问题,SQLCompute肯定慢,还是在循环中计算 1、加载后计算 2、用存储过程或者sql在数据库中计算好再一次性把结果提取出来
|
|||||||||
-- 作者:13388123666 -- 发布时间:2016/10/7 17:39:00 -- 好的,谢谢您啦 |
|||||||||
-- 作者:13388123666 -- 发布时间:2016/10/9 18:16:00 -- 我用以下代码生成一个统计表,但最终想得到年度的合格率对比分析,请问有什么办法吗? Dim bd1 As New SQLCrossTableBuilder("统计表1","出库明细") bd1.C Dim dt1 As fxDataSource bd1.VGroups.AddDef("制单日期",DateGroupEnum.Year,"年") bd1.HGroups.AddDef("客户代码") bd1.Totals.AddExp("发货重量","实交数量 * 单件重量") dt1 = bd1.BuildDataSource() Dim bd2 As New SQLCrossTableBuilder("统计表2","退废明细") bd2.C Dim dt2 As fxDataSource bd2.VGroups.AddDef("日期",DateGroupEnum.Year,"年") bd2.HGroups.AddDef("客户代码") bd2.Totals.AddExp("退废重量","(IsNull([退废原因_可挽救],0) + IsNull([退废原因_黑皮],0) + IsNull([退废原因_缩松],0) + IsNull([退废原因_气孔],0) + IsNull([退废原因_夹渣],0) + IsNull([退废原因_变形],0)) * 单件重量") dt2 = bd2.BuildDataSource() dt1.Combine("客户代码",dt2,"客户代码") Tables("质量年度分析_Table1").DataSource = dt1 想用得到的统计结果来生成下表,请问能达成吗?谢谢!
|
|||||||||
-- 作者:有点蓝 -- 发布时间:2016/10/10 8:27:00 -- 可以的,参考:http://www.foxtable.com/webhelp/scr/2305.htm |
|||||||||
-- 作者:13388123666 -- 发布时间:2016/10/10 9:38:00 -- 进销存用参考的方法没有问题,但这种要对统计结果进行再计算,新组成的列名称应该如何写,弄不明白,试了很多次都不行。我现在只有把统计的结果输出为Excel格式,再进行退废率的统计。
|
|||||||||
-- 作者:有点蓝 -- 发布时间:2016/10/10 10:00:00 -- 看7楼,列名自己喜欢什么名称就用什么名称 Tables("窗口1_Table1").DataSource = dt1 \'将统计结果绑定到Table
With DataTables("窗口1_Table1").DataCols \'用表达式列计算库存数据 .Add("库存_数量",Gettype(Integer), "IsNull([进货_数量],0) - ISNULL([销售_数量],0) - ISNULL([退货_数量],0)") .Add("库存_金额",Gettype(Double), "[库存_数量] /[进货_数量] * [进货_金额]") End With |
|||||||||
-- 作者:13388123666 -- 发布时间:2016/10/10 10:33:00 -- Dim bd1 As New SQLCrossTableBuilder("统计表1","出库明细") dt1 = bd1.BuildDataSource() Dim bd2 As New SQLCrossTableBuilder("统计表2","退废明细") dt1.Combine("客户代码",dt2,"客户代码") Tables("质量年度分析_Table1").DataSource = dt1 代码这样做后,得到上述的结果,代码错在哪里呢?
|